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.

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