Advertisement
Guest User

Untitled

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