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.

111 lines
3.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
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_int "mtu"
  9. proto_config_add_int "juniper"
  10. proto_config_add_string "interface"
  11. proto_config_add_string "username"
  12. proto_config_add_string "serverhash"
  13. proto_config_add_string "authgroup"
  14. proto_config_add_string "password"
  15. proto_config_add_string "password2"
  16. proto_config_add_string "token_mode"
  17. proto_config_add_string "token_secret"
  18. proto_config_add_string "token_script"
  19. proto_config_add_string "os"
  20. proto_config_add_string "csd_wrapper"
  21. no_device=1
  22. available=1
  23. }
  24. proto_openconnect_setup() {
  25. local config="$1"
  26. json_get_vars server port interface username serverhash authgroup password password2 token_mode token_secret token_script os csd_wrapper mtu juniper
  27. grep -q tun /proc/modules || insmod tun
  28. ifname="vpn-$config"
  29. logger -t openconnect "initializing..."
  30. logger -t "openconnect" "adding host dependency for $server at $config"
  31. for ip in $(resolveip -t 10 "$server"); do
  32. logger -t "openconnect" "adding host dependency for $ip at $config"
  33. proto_add_host_dependency "$config" "$ip" "$interface"
  34. done
  35. [ -n "$port" ] && port=":$port"
  36. cmdline="$server$port -i "$ifname" --non-inter --syslog --script /lib/netifd/vpnc-script"
  37. [ -n "$mtu" ] && cmdline="$cmdline --mtu $mtu"
  38. # migrate to standard config files
  39. [ -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"
  40. [ -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"
  41. [ -f "/etc/config/openconnect-ca-vpn-$config.pem" ] && mv "/etc/config/openconnect-ca-vpn-$config.pem" "/etc/openconnect/ca-vpn-$config.pem"
  42. [ -f /etc/openconnect/user-cert-vpn-$config.pem ] && append cmdline "-c /etc/openconnect/user-cert-vpn-$config.pem"
  43. [ -f /etc/openconnect/user-key-vpn-$config.pem ] && append cmdline "--sslkey /etc/openconnect/user-key-vpn-$config.pem"
  44. [ -f /etc/openconnect/ca-vpn-$config.pem ] && {
  45. append cmdline "--cafile /etc/openconnect/ca-vpn-$config.pem"
  46. append cmdline "--no-system-trust"
  47. }
  48. if [ "${juniper:-0}" -gt 0 ]; then
  49. append cmdline "--juniper"
  50. fi
  51. [ -n "$serverhash" ] && {
  52. append cmdline " --servercert=$serverhash"
  53. append cmdline "--no-system-trust"
  54. }
  55. [ -n "$authgroup" ] && append cmdline "--authgroup $authgroup"
  56. [ -n "$username" ] && append cmdline "-u $username"
  57. [ -n "$password" ] || [ "$token_mode" = "script" ] && {
  58. umask 077
  59. mkdir -p /var/etc
  60. pwfile="/var/etc/openconnect-$config.passwd"
  61. [ -n "$password" ] && {
  62. echo "$password" > "$pwfile"
  63. [ -n "$password2" ] && echo "$password2" >> "$pwfile"
  64. }
  65. [ "$token_mode" = "script" ] && {
  66. $token_script > "$pwfile" 2> /dev/null || {
  67. logger -t openconenct "Cannot get password from script '$token_script'"
  68. proto_setup_failed "$config"
  69. }
  70. }
  71. append cmdline "--passwd-on-stdin"
  72. }
  73. [ -n "$token_mode" -a "$token_mode" != "script" ] && append cmdline "--token-mode=$token_mode"
  74. [ -n "$token_secret" ] && append cmdline "--token-secret=$token_secret"
  75. [ -n "$os" ] && append cmdline "--os=$os"
  76. [ -n "$csd_wrapper" ] && [ -x "$csd_wrapper" ] && append cmdline "--csd-wrapper=$csd_wrapper"
  77. proto_export INTERFACE="$config"
  78. logger -t openconnect "executing 'openconnect $cmdline'"
  79. if [ -f "$pwfile" ]; then
  80. proto_run_command "$config" /usr/sbin/openconnect-wrapper $pwfile $cmdline
  81. else
  82. proto_run_command "$config" /usr/sbin/openconnect $cmdline
  83. fi
  84. }
  85. proto_openconnect_teardown() {
  86. local config="$1"
  87. pwfile="/var/etc/openconnect-$config.passwd"
  88. rm -f $pwfile
  89. logger -t openconnect "bringing down openconnect"
  90. proto_kill_command "$config" 2
  91. }
  92. add_protocol openconnect