-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSHServer.app
executable file
·73 lines (59 loc) · 1.52 KB
/
SSHServer.app
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
73
#!/ebrmain/bin/run_script
TRUSTED_CLIENT_IP=192.168.1.22
PORT=8222
read_cfg_file() {
while read x
do
x1=`echo $x|cut -d = -f 1|sed -e "s/[^a-zA-Z0-9_]//g"`
x2=`echo $x|cut -d = -f 2-`
eval ${2}${x1}='$x2'
done < $1 || false
}
ensure_network_connected() {
ifconfig eth0 > /dev/null 2>&1
if [ $? -eq 0 ]; then
return
fi
/ebrmain/bin/netagent status > /tmp/netagent_status_wb
read_cfg_file /tmp/netagent_status_wb netagent_
if [ "$netagent_nagtpid" -eq 0 ]; then
echo "Network now disabled"
/ebrmain/bin/dialog 5 "" @NeedInternet @Cancel @TurnOnWiFi
want_connect=$?
echo "want_connect=$want_connect"
if ! [ "$want_connect" = 2 ]; then
exit 1
fi
/ebrmain/bin/netagent net on
fi
/ebrmain/bin/netagent connect
}
ask_confirmation() {
running_process_id=$(pgrep -o dropbear)
if [ $? -eq 0 ]; then
DLG_MESSAGE="SSH server is running.
To you want to stop SSH server?"
dialog 2 "" "${DLG_MESSAGE}" @Cancel @OK
if [ $? -ne 2 ]; then
exit 1
else
kill -9 ${running_process_id}
exit 0
fi
fi
DLG_MESSAGE="SSH server about to start.
Note that it will accept unauthenticated connections on port ${PORT} from the ${TRUSTED_CLIENT_IP} IP address."
dialog 5 "" "${DLG_MESSAGE}" @Cancel @OK
if [ $? -ne 2 ]; then
exit 1
fi
}
run_server() {
dropbear -p ${PORT} -G ${TRUSTED_CLIENT_IP}
}
ask_confirmation
ensure_network_connected
run_server
# Local Variables:
# mode: sh;
# End: