Advertisement
jekarl

LATCH status file

Nov 2nd, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.34 KB | None | 0 0
  1. #!/bin/bash
  2. applicationId="INSERT app ID HERE"
  3. secretkey="INSERT secret key HERE"
  4. LATCH="/root/home/latch.accounts"
  5. account=`grep "^$USER:" $LATCH |cut -d: -f2`
  6. if [ -z `echo "$account"|cut -d: -f2`  ]; then exit 0; fi
  7. URL="/api/0.6/status/$account"
  8. requestSignature+="GET\n"
  9. date=`date -u '+%Y-%m-%d %H:%M:%S'`
  10. requestSignature+="$date\n\n$URL"
  11. signed=`echo -en "$requestSignature" | openssl dgst -sha1 -hmac "$secretkey" -binary|sed -e 's|.*= \(.*\)|\1|g'`
  12. b64signed=`echo -n "$signed"|base64`
  13. auth_header="Authorization:11PATHS $applicationId $b64signed"
  14. date_header="X-11Paths-Date: $date"
  15. JSON=`wget -q --no-check-certificate -O - --header "$auth_header" --header "$date_header" "https://latch.elevenpaths.com$URL"`
  16. status=`echo -e "$JSON" | sed -e 's|.*status":"\(.*\)","name.*|\1|g'`
  17. ####Pid User login####
  18. Upid=`ps w | grep "sshd:" | grep -v grep | awk '{print $1}'`
  19. ####Check Internet status####
  20. WAN=`ping -w1 -c1 8.8.8.8 > /dev/null 2>&1 && echo "up" || echo "down" && exit 1`
  21. ####Check Firewall rules####
  22. FW=`iptables -L | grep "https"`
  23. ####Assign sequence value to $rules####
  24. if [[ -z "$FW" ]]; then
  25.     rules="0"
  26. else
  27.     rules="1"
  28. fi
  29. ####If Latch is blocked and Internet status is UP, do these sequences####
  30. if [ `echo "$status" | grep "off"` ] && [ `echo "$WAN" | grep "up"` ]; then
  31.            echo -e "Access blocked by LATCH" | tr -d '\r'
  32.             iptables -I INPUT -p tcp --dport 443 -j DROP
  33.             kill "$Upid" -9
  34. ####If Latch is unblocked, SSL rules are applied and WAN connection is up, do these sequence####
  35. elif [[ `echo "$status" | grep "on"` ]] && [[ `echo "$rules" | grep "1"` ]] && [[ `echo "$WAN" | grep "up"` ]]; then
  36.             iptables -D INPUT -p tcp --dport 443 -j DROP
  37. ####If Latch is unblocked, not SSL rules and WAN connection is up, do this sequence####
  38. elif [[ `echo "$status" | grep "on"` ]] && [[ `echo "$rules" | grep  "0"` ]] && [[ `echo "$WAN" | grep "up"` ]]; then
  39.             echo -e "Access allowed by LATCH" | tr -d '\r'
  40. ####If Latch is unblocked, SSL rules are applied and WAN connection is down, do this sequence####
  41. elif [[ `echo "$rules" | grep  "1"` ]] && [[ `echo "$WAN" | grep "down"` ]]; then
  42.             iptables -D INPUT -p tcp --dport 443 -j DROP
  43. else
  44. ####If wan connection is down, execute the command####
  45.  echo -e "Error LATCH or not Internet connection" | tr -d '\r'
  46.  exit 0;
  47. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement