Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Forticlient SSL VPN Client launching script utilizing expect.
  4.  
  5. # --------------------------------------------
  6. # CONFIGURATION
  7.  
  8. # If empty - script will take some simple logic to locate appropriate binary.
  9. FORTICLIENT_PATH=""
  10.  
  11. # VPN Credentials
  12. VPN_HOST="host:10443"
  13. VPN_USER="username"
  14. VPN_PASS="password"
  15.  
  16. # --------------------------------------------
  17.  
  18. trap ctrl_c INT
  19.  
  20. function ctrl_c() {
  21. echo "Removing left-over files..."
  22. rm -f /tmp/expect
  23. }
  24.  
  25. if [[ $EUID -ne 0 ]]; then
  26. echo "This script must be run as root"
  27. exit 1
  28. fi
  29.  
  30. if [ -z "$FORTICLIENT_PATH" ]; then
  31. FORTICLIENT_PATH=`uname -r | grep -q 64 && echo $(locate forticlientsslvpn_cli | grep 64bit) || echo $(locate forticlientsslvpn_cli | grep 32bit)`
  32. if [ ! -f $FORTICLIENT_PATH ]; then
  33. echo "Tried to locate Forticlient SSL VPN Cli binary, but failed."
  34. echo "Specify it at variable FORTCLIENT_PATH"
  35. exit 1
  36. fi
  37. echo "Located Forticlient VPN Client at: $FORTICLIENT_PATH"
  38. fi
  39.  
  40. echo "Killing previous instances of Forticlient SSL VPN client..."
  41. killall -9 $(basename $FORTICLIENT_PATH) 2> /dev/null
  42.  
  43. cat << EOF > /tmp/expect
  44. #!/usr/bin/expect -f
  45. match_max 1000000
  46. set timeout -1
  47. spawn $FORTICLIENT_PATH --server $VPN_HOST --vpnuser $VPN_USER --keepalive
  48. expect "Password for VPN:"
  49. send -- "$VPN_PASS"
  50. send -- "\r"
  51.  
  52. expect "Would you like to connect to this server? (Y/N)"
  53. send -- "Y"
  54. send -- "\r"
  55.  
  56. expect "Clean up..."
  57. close
  58. EOF
  59.  
  60. chmod 500 /tmp/expect
  61. /usr/bin/expect -f /tmp/expect
  62.  
  63. rm -f /tmp/expect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement