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.

92 lines
3.0 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
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. proto_config_add_string "token_mode"
  13. proto_config_add_string "token_secret"
  14. proto_config_add_string "interface"
  15. no_device=1
  16. available=1
  17. }
  18. proto_openconnect_setup() {
  19. local config="$1"
  20. json_get_vars server port username serverhash authgroup password interface token_mode token_secret
  21. grep -q tun /proc/modules || insmod tun
  22. logger -t openconnect "initializing..."
  23. serv_addr=
  24. for ip in $(resolveip -t 10 "$server"); do
  25. ( proto_add_host_dependency "$config" "$ip" $interface )
  26. serv_addr=1
  27. done
  28. [ -n "$serv_addr" ] || {
  29. logger -t openconnect "Could not resolve server address: '$server'"
  30. sleep 60
  31. proto_setup_failed "$config"
  32. exit 1
  33. }
  34. [ -n "$port" ] && port=":$port"
  35. cmdline="$server$port -i vpn-$config --non-inter --syslog --script /lib/netifd/vpnc-script"
  36. # migrate to standard config files
  37. [ -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"
  38. [ -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"
  39. [ -f "/etc/config/openconnect-ca-vpn-$config.pem" ] && mv "/etc/config/openconnect-ca-vpn-$config.pem" "/etc/openconnect/ca-vpn-$config.pem"
  40. [ -f /etc/openconnect/user-cert-vpn-$config.pem ] && append cmdline "-c /etc/openconnect/user-cert-vpn-$config.pem"
  41. [ -f /etc/openconnect/user-key-vpn-$config.pem ] && append cmdline "--sslkey /etc/openconnect/user-key-vpn-$config.pem"
  42. [ -f /etc/openconnect/ca-vpn-$config.pem ] && {
  43. append cmdline "--cafile /etc/openconnect/ca-vpn-$config.pem"
  44. append cmdline "--no-system-trust"
  45. }
  46. [ -n "$serverhash" ] && {
  47. append cmdline " --servercert=$serverhash"
  48. append cmdline "--no-system-trust"
  49. }
  50. [ -n "$authgroup" ] && append cmdline "--authgroup $authgroup"
  51. [ -n "$username" ] && append cmdline "-u $username"
  52. [ -n "$password" ] && {
  53. umask 077
  54. mkdir -p /var/etc
  55. pwfile="/var/etc/openconnect-$config.passwd"
  56. echo "$password" > "$pwfile"
  57. append cmdline "--passwd-on-stdin"
  58. }
  59. [ -n "$token_mode" ] && append cmdline "--token-mode=$token_mode"
  60. [ -n "$token_secret" ] && append cmdline "--token-secret=$token_secret"
  61. proto_export INTERFACE="$config"
  62. logger -t openconnect "executing 'openconnect $cmdline'"
  63. if [ -f "$pwfile" ]; then
  64. proto_run_command "$config" /usr/sbin/openconnect-wrapper $pwfile $cmdline
  65. else
  66. proto_run_command "$config" /usr/sbin/openconnect $cmdline
  67. fi
  68. }
  69. proto_openconnect_teardown() {
  70. local config="$1"
  71. pwfile="/var/etc/openconnect-$config.passwd"
  72. rm -f $pwfile
  73. logger -t openconnect "bringing down openconnect"
  74. proto_kill_command "$config" 2
  75. }
  76. add_protocol openconnect