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.

88 lines
2.8 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. # migrate to standard config files
  34. [ -f "/etc/config/openconnect-user-cert-vpn-$config.pem" ] && mv "/etc/config/openconnect-user-cert-vpn-$config.pem" "/etc/openconnect/user-cert-vpn-$config.pem"
  35. [ -f "/etc/config/openconnect-user-key-vpn-$config.pem" ] && mv "/etc/config/openconnect-user-key-vpn-$config.pem" "/etc/openconnect/user-key-vpn-$config.pem"
  36. [ -f "/etc/config/openconnect-ca-vpn-$config.pem" ] && mv "/etc/config/openconnect-ca-vpn-$config.pem" "/etc/openconnect/ca-vpn-$config.pem"
  37. [ -f /etc/openconnect/user-cert-vpn-$config.pem ] && append cmdline "-c /etc/openconnect/user-cert-vpn-$config.pem"
  38. [ -f /etc/openconnect/user-key-vpn-$config.pem ] && append cmdline "--sslkey /etc/openconnect/user-key-vpn-$config.pem"
  39. [ -f /etc/openconnect/ca-vpn-$config.pem ] && {
  40. append cmdline "--cafile /etc/openconnect/ca-vpn-$config.pem"
  41. append cmdline "--no-system-trust"
  42. }
  43. [ -n "$serverhash" ] && {
  44. append cmdline " --servercert=$serverhash"
  45. append cmdline "--no-system-trust"
  46. }
  47. [ -n "$authgroup" ] && append cmdline "--authgroup $authgroup"
  48. [ -n "$username" ] && append cmdline "-u $username"
  49. [ -n "$password" ] && {
  50. umask 077
  51. pwfile="/var/run/openconnect-$config.passwd"
  52. echo "$password" > "$pwfile"
  53. append cmdline "--passwd-on-stdin"
  54. }
  55. [ -n "$token_mode" ] && append cmdline "--token-mode=$token_mode"
  56. [ -n "$token_secret" ] && append cmdline "--token-secret=$token_secret"
  57. proto_export INTERFACE="$config"
  58. logger -t openconnect "executing 'openconnect $cmdline'"
  59. if [ -f "$pwfile" ]; then
  60. proto_run_command "$config" /usr/sbin/openconnect-wrapper $pwfile $cmdline
  61. else
  62. proto_run_command "$config" /usr/sbin/openconnect $cmdline
  63. fi
  64. }
  65. proto_openconnect_teardown() {
  66. local config="$1"
  67. pwfile="/var/run/openconnect-$config.passwd"
  68. rm -f $pwfile
  69. logger -t openconnect "bringing down openconnect"
  70. proto_kill_command "$config" 2
  71. }
  72. add_protocol openconnect