-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy
executable file
·156 lines (146 loc) · 3.09 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#set -x
state=
cmd=
user=
dir=$(pwd)
disconnected=🔒
connected=🔑
get_var=
config_file=
proxy_on=
proxy_off=
proxy_state=
for i in $@; do
if [[ -z $get_var ]]; then
case $i in
-c)
get_var=config
;;
--config)
get_var=config
;;
-d)
get_var=dir
;;
--dir)
get_var=dir
;;
-s)
get_var=cmd
;;
--set)
get_var=cmd
;;
-u)
get_var=user
;;
--user)
get_var=user
;;
*)
;;
esac
else
case $get_var in
config)
config_file=$i
;;
dir)
dir=$i
;;
cmd)
cmd=$i
;;
user)
user=$i
;;
*)
;;
esac
get_var=
fi
done
if [[ -n $config_file ]]; then
while IFS= read -r line; do
line=${line%%#*}
line=$(echo $line | sed 's/^\s*//' | sed 's/\s*$//')
if [[ -n $line ]]; then
key=${line%%=*}
value=${line#*=}
key=$(echo $key | sed 's/^\s*//' | sed 's/\s*$//')
value=$(echo $value | sed 's/^\s*//' | sed 's/\s*$//')
#key=$(echo $line | cut -f1 -d'=' | sed 's/^\s*//' | sed 's/\s*$//')
#value=$(echo $line | cut -f2 -d'=' | sed 's/^\s*//' | sed 's/\s*$//')
case $key in
user)
user=$value
;;
proxy_on)
proxy_on=$value
;;
proxy_off)
proxy_off=$value
;;
proxy_state)
proxy_state=$value
;;
*)
;;
esac
fi
done < $config_file
fi
state=$(eval "$proxy_state")
#if [[ -z $cmd ]]; then
#BLOCK_BUTTON=1
#fi
case $BLOCK_BUTTON in
1)
#sudo $dir/proxy -c $config_file -d $dir --set on
eval "$proxy_on" > /dev/zero
state=1
;;
2)
if [[ -z $state ]]; then
eval "$proxy_on" > /dev/zero
state=1
else
eval "$proxy_off" > /dev/zero
state=
fi
;;
3)
#sudo $dir/proxy -c $config_file -d $dir --set off
eval "$proxy_off" > /dev/zero
state=
;;
4)
;;
5)
;;
6)
;;
7)
;;
*)
case $cmd in
on)
eval "$proxy_on" > /dev/zero
state=1
;;
off)
eval "$proxy_off" > /dev/zero
state=
;;
*)
;;
esac
;;
esac
if [[ -n $state ]]; then
result=$connected
else
result=$disconnected
fi
echo -n $result