-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.sh
199 lines (183 loc) · 6.14 KB
/
server.sh
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#Check Root
[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; }
#CheckOS
if [ -n "$(grep 'Aliyun Linux release' /etc/issue)" -o -e /etc/redhat-release ];then
OS=CentOS
[ -n "$(grep ' 7\.' /etc/redhat-release)" ] && CentOS_RHEL_version=7
[ -n "$(grep ' 6\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release6 15' /etc/issue)" ] && CentOS_RHEL_version=6
[ -n "$(grep ' 5\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release5' /etc/issue)" ] && CentOS_RHEL_version=5
elif [ -n "$(grep 'Amazon Linux AMI release' /etc/issue)" -o -e /etc/system-release ];then
OS=CentOS
CentOS_RHEL_version=6
elif [ -n "$(grep bian /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Debian' ];then
OS=Debian
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Debian_version=$(lsb_release -sr | awk -F. '{print $1}')
elif [ -n "$(grep Deepin /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Deepin' ];then
OS=Debian
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Debian_version=$(lsb_release -sr | awk -F. '{print $1}')
elif [ -n "$(grep Ubuntu /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Ubuntu' -o -n "$(grep 'Linux Mint' /etc/issue)" ];then
OS=Ubuntu
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Ubuntu_version=$(lsb_release -sr | awk -F. '{print $1}')
[ -n "$(grep 'Linux Mint 18' /etc/issue)" ] && Ubuntu_version=16
else
echo "Does not support this OS, Please contact the author! "
kill -9 $$
fi
echo ""
echo "1.启动服务"
echo "2.停止服务"
echo "3.重启服务"
echo "4.查看日志"
echo "5.运行状态"
echo "6.修改DNS"
echo "7.开启用户WEB面板"
echo "8.关闭用户WEB面板"
echo "9.开/关服务端开机启动"
echo "10.检测服务器可用性"
echo "直接回车返回上级菜单"
while :; do echo
read -p "请选择: " serverc
[ -z "$serverc" ] && ssr && break
if [[ ! $serverc =~ ^[1-9]$ ]]; then
if [[ $serverc == 10 ]]; then
break
fi
echo "输入错误! 请输入正确的数字!"
else
break
fi
done
if [[ $serverc == 1 ]];then
bash /usr/local/shadowsocksr/logrun.sh
iptables-restore < /etc/iptables.up.rules
clear
echo "ShadowsocksR服务器已启动"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 2 ]];then
bash /usr/local/shadowsocksr/stop.sh
echo "ShadowsocksR服务器已停止"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 3 ]];then
bash /usr/local/shadowsocksr/stop.sh
bash /usr/local/shadowsocksr/logrun.sh
iptables-restore < /etc/iptables.up.rules
clear
echo "ShadowsocksR服务器已重启"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 4 ]];then
bash /usr/local/shadowsocksr/tail.sh
fi
if [[ $serverc == 5 ]];then
ps aux|grep server.py
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 6 ]];then
read -p "输入主要 DNS 服务器: " ifdns1
read -p "输入次要 DNS 服务器: " ifdns2
echo "nameserver $ifdns1" > /etc/resolv.conf
echo "nameserver $ifdns2" >> /etc/resolv.conf
echo "DNS 服务器已设置为 $ifdns1 $ifdns2"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 7 ]];then
while :; do echo
read -p "请输入自定义的WEB端口:" cgiport
if [[ "$cgiport" =~ ^(-?|\+?)[0-9]+(\.?[0-9]+)?$ ]];then
break
else
echo 'Input Error!'
fi
done
#Set Firewalls
if [[ ${OS} =~ ^Ubuntu$|^Debian$ ]];then
iptables-restore < /etc/iptables.up.rules
clear
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $cgiport -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $cgiport -j ACCEPT
iptables-save > /etc/iptables.up.rules
fi
if [[ ${OS} == CentOS ]];then
if [[ $CentOS_RHEL_version == 7 ]];then
iptables-restore < /etc/iptables.up.rules
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $cgiport -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $cgiport -j ACCEPT
iptables-save > /etc/iptables.up.rules
else
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $cgiport -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $cgiport -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
fi
fi
#Get IP
ip=`curl -m 10 -s http://members.3322.org/dyndns/getip`
clear
chmod -R 777 /usr/local/SSR-Bash-Python
cd /usr/local/SSR-Bash-Python/www
screen -dmS webcgi python -m CGIHTTPServer $cgiport
echo "WEB服务启动成功,请访问 http://${ip}:$cgiport"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 8 ]];then
cgipid=$(ps -ef|grep 'webcgi' |grep -v grep |awk '{print $2}')
kill -9 $cgipid
screen -wipe
clear
echo "WEB服务已关闭!"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 9 ]];then
if [[ ${OS} == Ubuntu || ${OS} == Debian ]];then
cat >/etc/init.d/ssr-bash-python <<EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: SSR-Bash_python
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SSR-Bash-Python
# Description: SSR-Bash-Python
### END INIT INFO
iptables-restore < /etc/iptables.up.rules
bash /usr/local/shadowsocksr/logrun.sh
EOF
chmod 755 /etc/init.d/ssr-bash-python
chmod +x /etc/init.d/ssr-bash-python
cd /etc/init.d
update-rc.d ssr-bash-python defaults 95
fi
if [[ ${OS} == CentOS ]];then
echo "
iptables-restore < /etc/iptables.up.rules
bash /usr/local/shadowsocksr/logrun.sh
" > /etc/rc.d/init.d/ssr-bash-python
chmod +x /etc/rc.d/init.d/ssr-bash-python
echo "/etc/rc.d/init.d/ssr-bash-python" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
echo "开机启动设置完成!"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
#The code by ToyoDAdoubi.GitHub:https://github.com/ToyoDAdoubi
if [[ $serverc == 10 ]];then
bash /usr/local/SSR-Bash-Python/SSRStatus.sh
bash /usr/local/SSR-Bash-Python/server.sh
fi