-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy
executable file
·72 lines (64 loc) · 1.35 KB
/
proxy
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/bash
pid_file="/tmp/.vpn.pid"
port=3128
host="localhost"
user="root"
function usage() {
echo "$0 [start|stop|status]"
exit 0
}
function clean() {
rm -f $pid_file && echo "Removed PID" || echo "No pid found"
}
function start() {
if [[ -f $pid_file ]]
then
echo "Looks like pid file exists please remove it first: $pid_file"
exit 1
else
echo "Starting proxy..."
nohup ssh -T -N -D$port $user@$host >/dev/null 2>&1 &
pid=`ps -ef | grep ssh | grep $host | grep -v grep | awk '{print $2}'`
if [ $? == 0 ]
then
echo "Success pid: $pid, port: $port"
echo $pid > $pid_file
exit 0
else
echo "Failed"
exit 1
fi
fi
}
function stop() {
if [[ -f $pid_file ]]
then
echo "Stopping VPN"
pid=`awk '{print $1}' $pid_file`
echo "PID: $pid, stopping vpn"
kill -9 $pid >/dev/null 2>&1 && rm -f $pid_file && echo "VPN Stopped"
exit 0
else
echo "No pid file found"
exit 1
fi
}
function status() {
if [[ -f $pid_file ]]
then
pid=`awk '{print $1}' $pid_file`
echo "PID: $pid"
ps -ef | grep $pid | grep -v grep >/dev/null 2>&1 || clean
exit 0
else
echo "No pid file found"
exit 1
fi
}
case $1 in
start) start ;;
stop) stop ;;
status) status ;;
clean) clean ;;
*) usage ;;
esac