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.

94 lines
3.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
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 "password2"
  13. proto_config_add_string "token_mode"
  14. proto_config_add_string "token_secret"
  15. proto_config_add_string "interface"
  16. proto_config_add_string "os"
  17. proto_config_add_string "csd_wrapper"
  18. no_device=1
  19. available=1
  20. }
  21. proto_openconnect_setup() {
  22. local config="$1"
  23. json_get_vars server port username serverhash authgroup password password2 interface token_mode token_secret os csd_wrapper
  24. grep -q tun /proc/modules || insmod tun
  25. ifname="vpn-$config"
  26. logger -t openconnect "initializing..."
  27. logger -t "openconnect" "adding host dependency for $server at $config"
  28. for ip in $(resolveip -t 10 "$server"); do
  29. logger -t "openconnect" "adding host dependency for $ip at $config"
  30. proto_add_host_dependency "$config" "$ip"
  31. done
  32. [ -n "$port" ] && port=":$port"
  33. cmdline="$server$port -i "$ifname" --non-inter --syslog --script /lib/netifd/vpnc-script"
  34. # migrate to standard config files
  35. [ -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"
  36. [ -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"
  37. [ -f "/etc/config/openconnect-ca-vpn-$config.pem" ] && mv "/etc/config/openconnect-ca-vpn-$config.pem" "/etc/openconnect/ca-vpn-$config.pem"
  38. [ -f /etc/openconnect/user-cert-vpn-$config.pem ] && append cmdline "-c /etc/openconnect/user-cert-vpn-$config.pem"
  39. [ -f /etc/openconnect/user-key-vpn-$config.pem ] && append cmdline "--sslkey /etc/openconnect/user-key-vpn-$config.pem"
  40. [ -f /etc/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. mkdir -p /var/etc
  53. pwfile="/var/etc/openconnect-$config.passwd"
  54. echo "$password" > "$pwfile"
  55. [ -n "$password2" ] && echo "$password2" >> "$pwfile"
  56. append cmdline "--passwd-on-stdin"
  57. }
  58. [ -n "$token_mode" ] && append cmdline "--token-mode=$token_mode"
  59. [ -n "$token_secret" ] && append cmdline "--token-secret=$token_secret"
  60. [ -n "$os" ] && append cmdline "--os=$os"
  61. [ -n "$csd_wrapper" ] && [ -x "$csd_wrapper" ] && append cmdline "--csd-wrapper=$csd_wrapper"
  62. proto_export INTERFACE="$config"
  63. logger -t openconnect "executing 'openconnect $cmdline'"
  64. if [ -f "$pwfile" ]; then
  65. proto_run_command "$config" /usr/sbin/openconnect-wrapper $pwfile $cmdline
  66. else
  67. proto_run_command "$config" /usr/sbin/openconnect $cmdline
  68. fi
  69. }
  70. proto_openconnect_teardown() {
  71. local config="$1"
  72. pwfile="/var/etc/openconnect-$config.passwd"
  73. rm -f $pwfile
  74. logger -t openconnect "bringing down openconnect"
  75. proto_kill_command "$config" 2
  76. }
  77. add_protocol openconnect