vpn-name.sh.example 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # example VPN config script
  2. vpn_prepare()
  3. {
  4. example_ipaddr=192.168.0.1
  5. example_openvpn_port=1194
  6. example_openvpn_tundev="$(get_unused_tun_device)"
  7. [ -n "$example_openvpn_tundev" ] || die "Failed to get TUN device"
  8. example_openvpn_ca="/etc/openvpn/keys/example-ca.crt"
  9. example_openvpn_cert="/etc/openvpn/keys/example.crt"
  10. example_openvpn_key="/etc/openvpn/keys/example.key"
  11. example_openvpn_pid=
  12. example_openvpn_log="$(mktemp /tmp/example.openvpn.log.XXXXXX)"
  13. [ -w "$example_openvpn_log" ] || die "Failed to create example log"
  14. }
  15. vpn_stop()
  16. {
  17. openvpn_kill "example" "$example_openvpn_pid" \
  18. "$example_openvpn_log"
  19. example_openvpn_pid=
  20. }
  21. vpn_start()
  22. {
  23. openvpn --client \
  24. --dev "$example_openvpn_tundev" \
  25. --proto tcp \
  26. --remote "$example_ipaddr" "$example_openvpn_port" \
  27. --nobind \
  28. --ca "$example_openvpn_ca" \
  29. --cert "$example_openvpn_cert" \
  30. --key "$example_openvpn_key" \
  31. --remote-cert-tls server \
  32. --cipher BF-CBC \
  33. --keysize 128 \
  34. --auth SHA1 \
  35. --comp-lzo \
  36. --persist-key \
  37. --persist-tun \
  38. --verb 4 \
  39. --log "$example_openvpn_log" &
  40. example_openvpn_pid=$!
  41. openvpn_wait_connect "example" "$example_openvpn_pid" \
  42. "$example_openvpn_log"
  43. }
  44. vpn_destroy()
  45. {
  46. rm -f "$example_openvpn_log"
  47. }