Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- applicationId="INSERT app ID HERE"
- secretkey="INSERT secret key HERE"
- LATCH="/root/home/latch.accounts"
- account=`grep "^$USER:" $LATCH |cut -d: -f2`
- if [ -z `echo "$account"|cut -d: -f2` ]; then exit 0; fi
- URL="/api/0.6/status/$account"
- requestSignature+="GET\n"
- date=`date -u '+%Y-%m-%d %H:%M:%S'`
- requestSignature+="$date\n\n$URL"
- signed=`echo -en "$requestSignature" | openssl dgst -sha1 -hmac "$secretkey" -binary|sed -e 's|.*= \(.*\)|\1|g'`
- b64signed=`echo -n "$signed"|base64`
- auth_header="Authorization:11PATHS $applicationId $b64signed"
- date_header="X-11Paths-Date: $date"
- JSON=`wget -q --no-check-certificate -O - --header "$auth_header" --header "$date_header" "https://latch.elevenpaths.com$URL"`
- status=`echo -e "$JSON" | sed -e 's|.*status":"\(.*\)","name.*|\1|g'`
- ####Pid User login####
- Upid=`ps w | grep "sshd:" | grep -v grep | awk '{print $1}'`
- ####Check Internet status####
- WAN=`ping -w1 -c1 8.8.8.8 > /dev/null 2>&1 && echo "up" || echo "down" && exit 1`
- ####Check Firewall rules####
- FW=`iptables -L | grep "https"`
- ####Assign sequence value to $rules####
- if [[ -z "$FW" ]]; then
- rules="0"
- else
- rules="1"
- fi
- ####If Latch is blocked and Internet status is UP, do these sequences####
- if [ `echo "$status" | grep "off"` ] && [ `echo "$WAN" | grep "up"` ]; then
- echo -e "Access blocked by LATCH" | tr -d '\r'
- iptables -I INPUT -p tcp --dport 443 -j DROP
- kill "$Upid" -9
- ####If Latch is unblocked, SSL rules are applied and WAN connection is up, do these sequence####
- elif [[ `echo "$status" | grep "on"` ]] && [[ `echo "$rules" | grep "1"` ]] && [[ `echo "$WAN" | grep "up"` ]]; then
- iptables -D INPUT -p tcp --dport 443 -j DROP
- ####If Latch is unblocked, not SSL rules and WAN connection is up, do this sequence####
- elif [[ `echo "$status" | grep "on"` ]] && [[ `echo "$rules" | grep "0"` ]] && [[ `echo "$WAN" | grep "up"` ]]; then
- echo -e "Access allowed by LATCH" | tr -d '\r'
- ####If Latch is unblocked, SSL rules are applied and WAN connection is down, do this sequence####
- elif [[ `echo "$rules" | grep "1"` ]] && [[ `echo "$WAN" | grep "down"` ]]; then
- iptables -D INPUT -p tcp --dport 443 -j DROP
- else
- ####If wan connection is down, execute the command####
- echo -e "Error LATCH or not Internet connection" | tr -d '\r'
- exit 0;
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement