blob: 421980d09ddf0f8e5fab9ac928ac433a226bfb76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/bin/sh
SSH=/usr/bin/ssh
[ -x "$SSH" ] || {
echo "Cannot find executable $SSH." >&2
exit 1
}
. /lib/functions.sh
. ../netifd-proto.sh
init_proto "$@"
INCLUDE_ONLY=1
. ./ppp.sh
proto_pppossh_init_config() {
ppp_generic_init_config
config_add_string server sshuser ipaddr peeraddr ssh_options
config_add_array 'identity:list(string)'
config_add_int port use_hostdep
available=1
no_device=1
}
proto_pppossh_setup() {
local config="$1"
local iface="$2"
local user="$(id -nu)"
local home=$(sh -c "echo ~$user")
local server port sshuser ipaddr peeraddr ssh_options identity use_hostdep
local ip fn errmsg opts pty
json_get_vars port sshuser ipaddr peeraddr ssh_options use_hostdep
json_get_var server server && {
[ -z "$use_hostdep" ] && use_hostdep=1
for ip in $(resolveip -t 5 "$server"); do
if [ "$use_hostdep" -gt 0 ]; then
( proto_add_host_dependency "$config" "$ip" )
else
break
fi
done
}
[ -n "$ip" ] || errmsg="${errmsg}Could not resolve $server\n"
[ -n "$sshuser" ] || errmsg="${errmsg}Missing sshuser option\n"
json_get_values identity identity
[ -z "$identity" ] && identity="$home/.ssh/id_rsa $home/.ssh/id_dsa"
for fn in $identity; do
[ -f "$fn" ] && opts="$opts -i $fn"
done
[ -n "$opts" ] || errmsg="${errmsg}Cannot find valid identity file\n"
[ -n "$errmsg" ] && {
echo -ne "$errmsg" >&2
proto_setup_failed "$config"
exit 1
}
opts="$opts ${port:+-p $port}"
opts="$opts ${ssh_options}"
opts="$opts $sshuser@$server"
pty="exec env 'HOME=$home' $SSH $opts pppd nodetach notty noauth"
ppp_generic_setup "$config" noauth pty "$pty" "$ipaddr:$peeraddr"
}
proto_pppossh_teardown() {
ppp_generic_teardown "$@"
}
add_protocol pppossh
|