SHARE
TWEET

DD-WRT VPN.SH OpenVPN Client Script

yugandharv Jan 6th, 2015 (edited) 749 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Name: DD-WRT Startup script to connect to VPN.sh VPN service
  2. # Author: Yugandhar Veeramachaneni (www.capslocktrojan.com)
  3. # Date: 01/01/2015
  4. # Tested on: DD-WRT v24-sp2
  5. # Credits: Some part of the code reused from VyprVPN's script
  6.  
  7. #!/bin/sh
  8.  
  9. USERNAME="Your VPN.sh Username"
  10. PASSWORD="Your VPN.sh Password"
  11. PROTOCOL="tcp"
  12.  
  13. # Add - delete - edit servers. You can use multiple servers; Edit remote_server_ip and remote_port.
  14. # Usually, the port number is 443. Remote IP is the IP of the servers in various locations. Check your Client Area.
  15. REMOTE_SERVERS="
  16. remote remote_server_ip remote_port
  17. "
  18.  
  19. CA_CRT='-----BEGIN CERTIFICATE-----
  20. Paste the contents of CA.crt file here.
  21. -----END CERTIFICATE-----'
  22.  
  23. # Check if OpenVPN Client is disabled in the GUI. If not, disable it now.
  24. OPVPNENABLE=`nvram get openvpncl_enable | awk '$1 == "0" {print $1}'`
  25.  
  26. if [ "$OPVPNENABLE" != 0 ]; then
  27.    nvram set openvpncl_enable=0
  28.    nvram commit
  29. fi
  30.  
  31. sleep 10
  32. mkdir /tmp/vpn; cd /tmp/vpn
  33. echo -e "$USERNAME\n$PASSWORD" > auth.conf
  34. echo "$CA_CRT" > ca.crt
  35. echo "#!/bin/sh
  36. iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE" > route-up.sh
  37. echo "#!/bin/sh
  38. iptables -t nat -D POSTROUTING -o tun0 -j MASQUERADE" > route-down.sh
  39. chmod 644 ca.crt; chmod 600 auth.conf; chmod 700 route-up.sh route-down.sh
  40. sleep 10
  41. echo "client
  42. auth-user-pass /tmp/vpn/auth.conf
  43. management 127.0.0.1 5001
  44. management-log-cache 50
  45. dev tun
  46. proto $PROTOCOL
  47. comp-lzo adaptive
  48. fast-io
  49. script-security 2
  50. mtu-disc yes
  51. verb 3
  52. mute 5
  53. cipher bf-cbc
  54. auth sha1
  55. tun-mtu 1500
  56. resolv-retry infinite
  57. nobind
  58. persist-key
  59. persist-tun
  60. log-append vpn.log
  61. ca ca.crt
  62. status-version 3
  63. status status
  64. daemon
  65. $REMOTE_SERVERS" > vpn.conf
  66. ln -s /tmp/vpn/vpn.log /tmp/vpn.log
  67. ln -s /tmp/vpn/status /tmp/status
  68. (killall openvpn; openvpn --config /tmp/vpn/vpn.conf --route-up /tmp/vpn/route-up.sh --down /tmp/vpn/route-down.sh) &
  69. exit 0
RAW Paste Data
Top