You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . ../netifd-proto.sh
  4. init_proto "$@"
  5. proto_openconnect_init_config() {
  6. proto_config_add_string "server"
  7. proto_config_add_int "port"
  8. proto_config_add_string "username"
  9. proto_config_add_string "serverhash"
  10. proto_config_add_string "authgroup"
  11. proto_config_add_string "password"
  12. no_device=1
  13. available=1
  14. }
  15. proto_openconnect_setup() {
  16. local config="$1"
  17. json_get_vars server port username serverhash authgroup password vgroup token_mode token_secret
  18. grep -q tun /proc/modules || insmod tun
  19. logger -t openconnect "initializing..."
  20. serv_addr=
  21. for ip in $(resolveip -t 10 "$server"); do
  22. ( proto_add_host_dependency "$config" "$ip" )
  23. serv_addr=1
  24. done
  25. [ -n "$serv_addr" ] || {
  26. logger -t openconnect "Could not resolve server address: '$server'"
  27. sleep 60
  28. proto_setup_failed "$config"
  29. exit 1
  30. }
  31. [ -n "$port" ] && port=":$port"
  32. cmdline="$server$port -i vpn-$config --non-inter --syslog --script /lib/netifd/vpnc-script"
  33. [ -f /etc/openconnect/user-cert-vpn-$config.pem ] && append cmdline "-c /etc/openconnect/user-cert-vpn-$config.pem"
  34. [ -f /etc/openconnect/user-key-vpn-$config.pem ] && append cmdline "--sslkey /etc/openconnect/user-key-vpn-$config.pem"
  35. [ -f /etc/openconnect/ca-vpn-$config.pem ] && {
  36. append cmdline "--cafile /etc/openconnect/ca-vpn-$config.pem"
  37. append cmdline "--no-system-trust"
  38. }
  39. [ -n "$serverhash" ] && {
  40. append cmdline " --servercert=$serverhash"
  41. append cmdline "--no-system-trust"
  42. }
  43. [ -n "$authgroup" ] && append cmdline "--authgroup $authgroup"
  44. [ -n "$username" ] && append cmdline "-u $username"
  45. [ -n "$password" ] && {
  46. umask 077
  47. pwfile="/var/run/openconnect-$config.passwd"
  48. echo "$password" > "$pwfile"
  49. append cmdline "--passwd-on-stdin"
  50. }
  51. [ -n "$token_mode" ] && append cmdline "--token-mode=$token_mode"
  52. [ -n "$token_secret" ] && append cmdline "--token-secret=$token_secret"
  53. proto_export INTERFACE="$config"
  54. logger -t openconnect "executing 'openconnect $cmdline'"
  55. if [ -f "$pwfile" ]; then
  56. proto_run_command "$config" /usr/sbin/openconnect-wrapper $pwfile $cmdline
  57. else
  58. proto_run_command "$config" /usr/sbin/openconnect $cmdline
  59. fi
  60. }
  61. proto_openconnect_teardown() {
  62. local config="$1"
  63. pwfile="/var/run/openconnect-$config.passwd"
  64. rm -f $pwfile
  65. logger -t openconnect "bringing down openconnect"
  66. proto_kill_command "$config" 2
  67. }
  68. add_protocol openconnect