forked from fangqiuming/docker-sslocal
-
Notifications
You must be signed in to change notification settings - Fork 2
/
proxy
executable file
·88 lines (80 loc) · 2.01 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
#!/usr/bin/env bash
set -e
SS_SERVER_ADDRESS=
SS_SERVER_PORT=
SS_PASSWORD=
SS_ENCRYPTION_METHOD=salsa20
SOCKS5_PROXY_PORT=1080
HTTP_PROXY_PORT=8118
function logs_shadowsocks-client() {
docker logs -f shadowsocks-client
}
function rm_shadowsocks-client() {
docker rm -f shadowsocks-client &> /dev/null || true
}
function run_shadowsocks-client() {
docker rm -f shadowsocks-client &> /dev/null || true
docker run -d --name shadowsocks-client \
-p ${SOCKS5_PROXY_PORT}:1080 \
-p ${HTTP_PROXY_PORT}:8118 \
tedostrem/shadowsocks-client \
-b 0.0.0.0 \
-s ${SS_SERVER_ADDRESS} \
-p ${SS_SERVER_PORT} \
-l 1080 \
-k ${SS_PASSWORD} \
-m ${SS_ENCRYPTION_METHOD} &> /dev/null
}
function gproxy_on() {
gsettings set org.gnome.system.proxy.http host 'localhost'
gsettings set org.gnome.system.proxy.http port ${HTTP_PROXY_PORT}
gsettings set org.gnome.system.proxy.https host 'localhost'
gsettings set org.gnome.system.proxy.https port ${HTTP_PROXY_PORT}
gsettings set org.gnome.system.proxy.ftp host 'localhost'
gsettings set org.gnome.system.proxy.ftp port ${HTTP_PROXY_PORT}
gsettings set org.gnome.system.proxy mode 'manual'
}
function gproxy_off() {
gsettings set org.gnome.system.proxy mode 'none'
}
function proxy_on() {
echo "export http_proxy=localhost:${HTTP_PROXY_PORT} https_proxy=localhost:${HTTP_PROXY_PORT} no_proxy=localhost,127.0.0.0/8,::1"
}
function proxy_off() {
echo "unset http_proxy https_proxy"
}
if [ -z "$1" ];
then
echo "on,off,state,logs"
exit 0
fi
if [ "$1" == "on" ];
then
rm_shadowsocks-client
run_shadowsocks-client
proxy_on
gproxy_on
fi
if [ "$1" == "off" ];
then
rm_shadowsocks-client
proxy_off
gproxy_off
fi
if [ "$1" == "docker" ];
then
echo "--link shadowsocks-client -e http_proxy=shadowsocks-client:${HTTP_PROXY_PORT} -e https_proxy=shadowsocks-client:${HTTP_PROXY_PORT}"
fi
if [ "$1" == "logs" ];
then
logs_shadowsocks-client
fi
if [ "$1" == "state" ];
then
if [ "$(gsettings get org.gnome.system.proxy mode)" == "'manual'" ];
then
echo "ON"
else
echo "OFF"
fi
fi