|
@@ -0,0 +1,98 @@
|
|
1
|
+#!/bin/sh
|
|
2
|
+. /lib/functions.sh
|
|
3
|
+. ../netifd-proto.sh
|
|
4
|
+init_proto "$@"
|
|
5
|
+
|
|
6
|
+proto_vpnc_init_config() {
|
|
7
|
+ proto_config_add_string "server"
|
|
8
|
+ proto_config_add_string "username"
|
|
9
|
+ proto_config_add_string "hexpasswd"
|
|
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
|
+ proto_config_add_string "passgroup"
|
|
16
|
+ proto_config_add_string "hexpassgroup"
|
|
17
|
+ proto_config_add_string "domain"
|
|
18
|
+ proto_config_add_string "vendor"
|
|
19
|
+ proto_config_add_string "natt_mode"
|
|
20
|
+ proto_config_add_string "dh_group"
|
|
21
|
+ proto_config_add_string "pfs"
|
|
22
|
+ proto_config_add_boolean "enable_single_des"
|
|
23
|
+ proto_config_add_boolean "enable_no_enc"
|
|
24
|
+ proto_config_add_int "mtu"
|
|
25
|
+ proto_config_add_string "local_addr"
|
|
26
|
+ proto_config_add_int "local_port"
|
|
27
|
+ proto_config_add_int "udp_port"
|
|
28
|
+ proto_config_add_int "dpd_idle"
|
|
29
|
+ proto_config_add_string "auth_mode"
|
|
30
|
+ proto_config_add_string "target_network"
|
|
31
|
+ no_device=1
|
|
32
|
+ available=1
|
|
33
|
+}
|
|
34
|
+
|
|
35
|
+proto_vpnc_setup() {
|
|
36
|
+ local config="$1"
|
|
37
|
+
|
|
38
|
+ json_get_vars server username hexpasswd authgroup password token_mode token_secret interface passgroup hexpassgroup domain vendor natt_mode dh_group pfs enable_single_des enable_no_enc mtu local_addr local_port udp_port dpd_idle auth_mode target_network
|
|
39
|
+
|
|
40
|
+ grep -q tun /proc/modules || insmod tun
|
|
41
|
+
|
|
42
|
+ logger -t vpnc "initializing..."
|
|
43
|
+ serv_addr=
|
|
44
|
+ for ip in $(resolveip -t 10 "$server"); do
|
|
45
|
+ ( proto_add_host_dependency "$config" "$ip" $interface )
|
|
46
|
+ serv_addr=1
|
|
47
|
+ done
|
|
48
|
+ [ -n "$serv_addr" ] || {
|
|
49
|
+ logger -t vpnc "Could not resolve server address: '$server'"
|
|
50
|
+ sleep 60
|
|
51
|
+ proto_setup_failed "$config"
|
|
52
|
+ exit 1
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ mkdir -p /var/etc
|
|
56
|
+ umask 077
|
|
57
|
+ pwfile="/var/etc/vpnc-$config.conf"
|
|
58
|
+ echo "IPSec gateway $server" > "$pwfile"
|
|
59
|
+ cmdline="--no-detach --pid-file /var/run/vpnc-$config.pid --ifname vpn-$config --non-inter --script /lib/netifd/vpnc-script $pwfile"
|
|
60
|
+
|
|
61
|
+ [ -f /etc/vpnc/ca-vpn-$config.pem ] && echo "CA-File /etc/vpnc/ca-vpn-$config.pem" >> "$pwfile"
|
|
62
|
+ [ -n "$hexpasswd" ] && echo "Xauth obfuscated password $hexpasswd" >> "$pwfile"
|
|
63
|
+ [ -n "$authgroup" ] && echo "IPSec ID $authgroup" >> "$pwfile"
|
|
64
|
+ [ -n "$username" ] && echo "Xauth username $username" >> "$pwfile"
|
|
65
|
+ [ -n "$password" ] && echo "Xauth password $password" >> "$pwfile"
|
|
66
|
+ [ -n "$passgroup" ] && echo "IPSec secret $passgroup" >> "$pwfile"
|
|
67
|
+ [ -n "$hexpassgroup" ] && echo "IPSec obfuscated secret $hexpassgroup" >> "$pwfile"
|
|
68
|
+ [ -n "$domain" ] && echo "Domain $domain" >> "$pwfile"
|
|
69
|
+ [ -n "$vendor" ] && echo "Vendor $vendor" >> "$pwfile"
|
|
70
|
+ [ -n "$natt_mode" ] && echo "NAT Traversal Mode $natt_mode" >> "$pwfile"
|
|
71
|
+ [ -n "$dh_group" ] && echo "IKE DH Group $dh_group" >> "$pwfile"
|
|
72
|
+ [ -n "$pfs" ] && echo "Perfect Forward Secrecy $pfs" >> "$pwfile"
|
|
73
|
+ [ "${enable_single_des:-0}" -gt 0 ] && echo "Enable Single DES" >> "$pwfile"
|
|
74
|
+ [ "${enable_no_enc:-0}" -gt 0 ] && echo "Enable no encryption" >> "$pwfile"
|
|
75
|
+ [ -n "$mtu" ] && echo "Interface MTU $mtu" >> "$pwfile"
|
|
76
|
+ [ -n "$local_addr" ] && echo "Local Addr $local_addr" >> "$pwfile"
|
|
77
|
+ [ -n "$local_port" ] && echo "Local Port $local_port" >> "$pwfile"
|
|
78
|
+ [ -n "$udp_port" ] && echo "Cisco UDP Encapsulation Port $udp_port" >> "$pwfile"
|
|
79
|
+ [ -n "$dpd_idle" ] && echo "DPD idle timeout (our side) $dpd_idle" >> "$pwfile"
|
|
80
|
+ [ -n "$auth_mode" ] && echo "IKE Authmode $auth_mode" >> "$pwfile"
|
|
81
|
+ [ -n "$target_network" ] && echo "IPSEC target network $target_network" >> "$pwfile"
|
|
82
|
+
|
|
83
|
+ proto_export INTERFACE="$config"
|
|
84
|
+ logger -t vpnc "executing 'vpnc $cmdline'"
|
|
85
|
+ proto_run_command "$config" /usr/sbin/vpnc $cmdline
|
|
86
|
+}
|
|
87
|
+
|
|
88
|
+proto_vpnc_teardown() {
|
|
89
|
+ local config="$1"
|
|
90
|
+
|
|
91
|
+ pwfile="/var/etc/vpnc-$config.conf"
|
|
92
|
+
|
|
93
|
+ rm -f $pwfile
|
|
94
|
+ logger -t vpnc "bringing down vpnc"
|
|
95
|
+ proto_kill_command "$config" 2
|
|
96
|
+}
|
|
97
|
+
|
|
98
|
+add_protocol vpnc
|