shadowsocksr 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. #!/bin/sh /etc/rc.common
  2. #
  3. # Copyright (C) 2017 openwrt-ssr
  4. # Copyright (C) 2017 yushi studio <[email protected]>
  5. # Copyright (C) 2018 lean <[email protected]>
  6. #
  7. # This is free software, licensed under the GNU General Public License v3.
  8. # See /LICENSE for more information.
  9. #
  10. START=95
  11. STOP=15
  12. SERVICE_DAEMONIZE=1
  13. EXTRA_COMMANDS=rules
  14. MAXFD=32768
  15. NAME=shadowsocksr
  16. LOCK_FILE=/var/lock/${NAME}.lock
  17. CONFIG_FILE=/var/etc/${NAME}.json
  18. CONFIG_UDP_FILE=/var/etc/${NAME}_u.json
  19. CONFIG_SOCK5_FILE=/var/etc/${NAME}_s.json
  20. CONFIG_NETFLIX_FILE=/var/etc/${NAME}_n.json
  21. server_count=0
  22. redir_tcp=0
  23. redir_udp=0
  24. tunnel_enable=0
  25. local_enable=0
  26. kcp_enable_flag=0
  27. kcp_flag=0
  28. pdnsd_enable_flag=0
  29. switch_enable=0
  30. switch_server=$1
  31. CRON_FILE=/etc/crontabs/root
  32. threads=1
  33. uci_get_by_name() {
  34. local ret=$(uci get $NAME.$1.$2 2>/dev/null)
  35. echo ${ret:=$3}
  36. }
  37. uci_get_by_type() {
  38. local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
  39. echo ${ret:=$3}
  40. }
  41. uci_set_by_name() {
  42. uci set $NAME.$1.$2=$3 2>/dev/null
  43. uci commit $NAME
  44. }
  45. uci_set_by_type() {
  46. uci set $NAME.@$1[0].$2=$3 2>/dev/null
  47. uci commit $NAME
  48. }
  49. uci_get_by_cfgid() {
  50. local ret=$(uci show $NAME.@$1[0].$2 | awk -F '.' '{print $2}' 2>/dev/null)
  51. echo ${ret:=$3}
  52. }
  53. get_host_ip() {
  54. local host=$1
  55. local isip=""
  56. local ip=$host
  57. isip=$(echo $host | grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
  58. if [ -z "$isip" ]; then
  59. if [ "$host" != "${host#*:[0-9a-fA-F]}" ]; then
  60. ip=$host
  61. else
  62. local ip=$(resolveip -4 -t 3 $host | awk 'NR==1{print}')
  63. [ -z "$ip" ] && ip=$(wget -q -O- http://119.29.29.29/d?dn=$1 | awk -F ';' '{print $1}')
  64. fi
  65. fi
  66. echo ${ip:="ERROR"}
  67. }
  68. clean_log() {
  69. logsnum=$(cat /tmp/ssrplus.log 2>/dev/null | wc -l)
  70. [ "$logsnum" -gt 1000 ] && {
  71. echo "$(date "+%Y-%m-%d %H:%M:%S") 日志文件过长,清空处理!" >/tmp/ssrplus.log
  72. }
  73. }
  74. add_cron() {
  75. touch $CRON_FILE
  76. sed -i '/shadowsocksr/d' $CRON_FILE
  77. [ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/share/shadowsocksr/ssrplusupdate.sh >>/tmp/ssrplus.log 2>&1" >>$CRON_FILE
  78. crontab $CRON_FILE
  79. }
  80. del_cron() {
  81. sed -i '/shadowsocksr/d' $CRON_FILE
  82. sed -i '/ssrplus.log/d' $CRON_FILE
  83. /etc/init.d/cron restart
  84. clean_log
  85. }
  86. unlock() {
  87. failcount=1
  88. while [ "$failcount" -le 10 ]; do
  89. if [ -f "$LOCK_FILE" ]; then
  90. let "failcount++"
  91. sleep 1s
  92. [ "$failcount" -ge 10 ] && rm -f "$LOCK_FILE"
  93. else
  94. break
  95. fi
  96. done
  97. }
  98. find_bin() {
  99. case "$1" in
  100. ss) ret="/usr/bin/ss-redir" ;;
  101. ss-local) ret="/usr/bin/ss-local" ;;
  102. ssr) ret="/usr/bin/ssr-redir" ;;
  103. ssr-local) ret="/usr/bin/ssr-local" ;;
  104. ssr-server) ret="/usr/bin/ssr-server" ;;
  105. v2ray | vless) ret="/usr/bin/v2ray/v2ray" && [ ! -f "$ret" ] && ret="/usr/bin/v2ray" ;;
  106. xray) ret="/usr/bin/xray" ;;
  107. trojan) ret="/usr/sbin/trojan" ;;
  108. naiveproxy) ret="/usr/bin/naive" ;;
  109. socks5 | tun) ret="/usr/sbin/redsocks2" ;;
  110. esac
  111. echo $ret
  112. }
  113. gen_config_file() {
  114. local hostip=$(get_host_ip $(uci_get_by_name $1 server))
  115. if [ "$hostip" == "ERROR" ]; then
  116. hostip=$(uci_get_by_name $1 ip)
  117. else
  118. uci_set_by_name $1 ip $hostip
  119. fi
  120. [ "$2" == "0" -a "$kcp_flag" == "1" ] && hostip="127.0.0.1"
  121. case "$2" in
  122. 0) config_file=$CONFIG_FILE ;;
  123. 1) config_file=$CONFIG_UDP_FILE ;;
  124. 2) config_file=$CONFIG_NETFLIX_FILE ;;
  125. *) config_file=$CONFIG_SOCK5_FILE ;;
  126. esac
  127. if [ $(uci_get_by_name $1 fast_open 0) == "1" ]; then
  128. fastopen="true"
  129. else
  130. fastopen="false"
  131. fi
  132. local type=$(uci_get_by_name $1 type)
  133. case "$type" in
  134. ss)
  135. cat <<-EOF >$config_file
  136. {
  137. "server": "$hostip",
  138. "server_port": $(uci_get_by_name $1 server_port),
  139. "local_address": "0.0.0.0",
  140. "local_port": $3,
  141. "password": "$(uci_get_by_name $1 password)",
  142. "timeout": $(uci_get_by_name $1 timeout 60),
  143. "method": "$(uci_get_by_name $1 encrypt_method_ss)",
  144. "reuse_port": true,
  145. "fast_open": $fastopen
  146. }
  147. EOF
  148. local plugin=$(uci_get_by_name $1 plugin)
  149. if [ -n "$plugin" ]; then
  150. [ "$plugin" == "simple-obfs" ] && plugin="obfs-local"
  151. if [ -x "/usr/bin/$plugin" ]; then
  152. sed -i "s@$hostip\",@$hostip\",\n\"plugin\": \"$plugin\",\n\"plugin_opts\": \"$(uci_get_by_name $1 plugin_opts)\",@" $config_file
  153. else
  154. echo "$(date "+%Y-%m-%d %H:%M:%S") Warning!!! SIP003 plugin $plugin not found!!!" >>/tmp/ssrplus.log
  155. fi
  156. fi
  157. ;;
  158. ssr)
  159. cat <<-EOF >$config_file
  160. {
  161. "server": "$hostip",
  162. "server_port": $(uci_get_by_name $1 server_port),
  163. "local_address": "0.0.0.0",
  164. "local_port": $3,
  165. "password": "$(uci_get_by_name $1 password)",
  166. "timeout": $(uci_get_by_name $1 timeout 60),
  167. "method": "$(uci_get_by_name $1 encrypt_method)",
  168. "protocol": "$(uci_get_by_name $1 protocol)",
  169. "protocol_param": "$(uci_get_by_name $1 protocol_param)",
  170. "obfs": "$(uci_get_by_name $1 obfs)",
  171. "obfs_param": "$(uci_get_by_name $1 obfs_param)",
  172. "reuse_port": true,
  173. "fast_open": $fastopen
  174. }
  175. EOF
  176. ;;
  177. v2ray | vless)
  178. lua /usr/share/shadowsocksr/gen${type}config.lua $GLOBAL_SERVER tcp $(uci_get_by_name $1 local_port) >/var/etc/v2-ssr-retcp.json
  179. sed -i 's/\\//g' /var/etc/v2-ssr-retcp.json
  180. ;;
  181. xray)
  182. lua /usr/share/shadowsocksr/gen${type}config.lua $GLOBAL_SERVER tcp $(uci_get_by_name $1 local_port) >/var/etc/xray-ssr-retcp.json
  183. sed -i 's/\\//g' /var/etc/xray-ssr-retcp.json
  184. ;;
  185. trojan)
  186. lua /usr/share/shadowsocksr/gentrojanconfig.lua $GLOBAL_SERVER nat $(uci_get_by_name $1 local_port) >/var/etc/trojan-ssr-retcp.json
  187. sed -i 's/\\//g' /var/etc/trojan-ssr-retcp.json
  188. ;;
  189. naiveproxy)
  190. case "$2" in
  191. 0) PROTO="redir"; FILE_NAME="retcp" ;;
  192. 1) PROTO="redir"; FILE_NAME="netflix" ;;
  193. 2) PROTO="socks"; FILE_NAME="socksdns" ;;
  194. 3) PROTO="socks"; FILE_NAME="local" ;;
  195. esac
  196. cat <<-EOF >/var/etc/naive-ssr-$FILE_NAME.json
  197. {
  198. "listen": "$PROTO://0.0.0.0:$3",
  199. "proxy": "https://$(uci_get_by_name $1 username):$(uci_get_by_name $1 password)@$(uci_get_by_name $1 server):$(uci_get_by_name $1 server_port)",
  200. "concurrency": "${4:-1}"
  201. }
  202. EOF
  203. ;;
  204. esac
  205. }
  206. gen_service_file() {
  207. if [ $(uci_get_by_name $1 fast_open) == "1" ]; then
  208. fastopen="true"
  209. else
  210. fastopen="false"
  211. fi
  212. cat <<-EOF >$2
  213. {
  214. "server": "0.0.0.0",
  215. "server_port": $(uci_get_by_name $1 server_port),
  216. "password": "$(uci_get_by_name $1 password)",
  217. "timeout": $(uci_get_by_name $1 timeout 60),
  218. "method": "$(uci_get_by_name $1 encrypt_method)",
  219. "protocol": "$(uci_get_by_name $1 protocol)",
  220. "protocol_param": "$(uci_get_by_name $1 protocol_param)",
  221. "obfs": "$(uci_get_by_name $1 obfs)",
  222. "obfs_param": "$(uci_get_by_name $1 obfs_param)",
  223. "fast_open": $fastopen
  224. }
  225. EOF
  226. }
  227. gen_serv_include() {
  228. FWI=$(uci get firewall.shadowsocksr.path 2>/dev/null)
  229. [ -n "$FWI" ] || return 0
  230. if [ ! -f $FWI ]; then
  231. echo '#!/bin/sh' >$FWI
  232. fi
  233. extract_rules() {
  234. echo "*filter"
  235. iptables-save -t filter | grep SSR-SERVER-RULE | sed -e "s/^-A INPUT/-I INPUT/"
  236. echo 'COMMIT'
  237. }
  238. cat <<-EOF >>$FWI
  239. iptables-save -c | grep -v "SSR-SERVER" | iptables-restore -c
  240. iptables-restore -n <<-EOT
  241. $(extract_rules)
  242. EOT
  243. EOF
  244. }
  245. start_dns() {
  246. local ssr_dns="$(uci_get_by_type global pdnsd_enable 0)"
  247. local dnsstr="$(uci_get_by_type global tunnel_forward 8.8.4.4:53)"
  248. local dnsserver=$(echo "$dnsstr" | awk -F ':' '{print $1}')
  249. local dnsport=$(echo "$dnsstr" | awk -F ':' '{print $2}')
  250. start_pdnsd() {
  251. local usr_dns="$1"
  252. local usr_port="$2"
  253. [ -z "$usr_dns" ] && usr_dns="8.8.8.8"
  254. [ -z "$usr_port" ] && usr_port="53"
  255. [ -d /var/etc ] || mkdir -p /var/etc
  256. if [ ! -f "/var/pdnsd/pdnsd.cache" ]; then
  257. mkdir -p /var/pdnsd
  258. touch /var/pdnsd/pdnsd.cache
  259. chown -R nobody:nogroup /var/pdnsd
  260. fi
  261. cat <<-EOF >/var/etc/pdnsd.conf
  262. global{
  263. perm_cache=1024;
  264. cache_dir="/var/pdnsd";
  265. pid_file="/var/run/pdnsd.pid";
  266. run_as="nobody";
  267. server_ip=127.0.0.1;
  268. server_port=5335;
  269. status_ctl=on;
  270. query_method=tcp_only;
  271. min_ttl=1h;
  272. max_ttl=1w;
  273. timeout=10;
  274. neg_domain_pol=on;
  275. proc_limit=2;
  276. procq_limit=8;
  277. par_queries=1;
  278. }
  279. server{
  280. label="ssr-usrdns";
  281. ip=$usr_dns;
  282. port=$usr_port;
  283. timeout=6;
  284. uptest=none;
  285. interval=10m;
  286. purge_cache=off;
  287. }
  288. EOF
  289. /usr/sbin/pdnsd -c /var/etc/pdnsd.conf >/dev/null 2>&1 &
  290. }
  291. if [ "$ssr_dns" != "0" ]; then
  292. case "$run_mode" in
  293. gfw) ipset add gfwlist $dnsserver 2>/dev/null ;;
  294. oversea) ipset add oversea $dnsserver 2>/dev/null ;;
  295. *) ipset add ss_spec_wan_ac $dnsserver nomatch 2>/dev/null ;;
  296. esac
  297. fi
  298. case "$ssr_dns" in
  299. 1)
  300. start_pdnsd $dnsserver $dnsport
  301. pdnsd_enable_flag=1
  302. ;;
  303. 2)
  304. microsocks -i 127.0.0.1 -p 10802 ssr-dns >/dev/null 2>&1 &
  305. dns2socks 127.0.0.1:10802 $dnsserver:$dnsport 127.0.0.1:5335 -q >/dev/null 2>&1 &
  306. pdnsd_enable_flag=2
  307. ;;
  308. esac
  309. }
  310. start_redir_tcp() {
  311. local type=$(uci_get_by_name $GLOBAL_SERVER type)
  312. local bin=$(find_bin $type)
  313. redir_tcp=1
  314. [ ! -f "$bin" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:Can't find $bin program, can't start!" >>/tmp/ssrplus.log && redir_tcp=0 && return 1
  315. case "$(uci_get_by_name $GLOBAL_SERVER auth_enable)" in
  316. 1 | on | true | yes | enabled) ARG_OTA="-A" ;;
  317. *) ARG_OTA="" ;;
  318. esac
  319. local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0)
  320. if [ "$kcp_enable" == "1" ]; then
  321. [ ! -f "/usr/bin/kcptun-client" ] && return 1
  322. local kcp_str=$(/usr/bin/kcptun-client -v | grep kcptun | wc -l)
  323. [ "0" == "$kcp_str" ] && return 1
  324. local kcp_port=$(uci_get_by_name $GLOBAL_SERVER kcp_port)
  325. local server_port=$(uci_get_by_name $GLOBAL_SERVER server_port)
  326. local password=$(uci_get_by_name $GLOBAL_SERVER kcp_password)
  327. local kcp_param=$(uci_get_by_name $GLOBAL_SERVER kcp_param)
  328. [ "$password" != "" ] && password="--key "$password
  329. service_start /usr/bin/kcptun-client \
  330. -r $kcp_server:$kcp_port \
  331. -l :$server_port $password $kcp_param
  332. kcp_enable_flag=1
  333. fi
  334. if [ "$(uci_get_by_type global threads 0)" == "0" ]; then
  335. threads=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
  336. else
  337. threads=$(uci_get_by_type global threads)
  338. fi
  339. gen_config_file $GLOBAL_SERVER 0 $(uci_get_by_name $GLOBAL_SERVER local_port 1234) $threads
  340. case "$type" in
  341. ss | ssr)
  342. local last_config_file=$CONFIG_FILE
  343. local name="Shadowsocks"
  344. [ "$type" == "ssr" ] && name="ShadowsocksR"
  345. for i in $(seq 1 $threads); do
  346. $bin -c $CONFIG_FILE $ARG_OTA -f /var/run/ssr-retcp_$i.pid >/dev/null 2>&1
  347. done
  348. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$name $threads Threads Started!" >>/tmp/ssrplus.log
  349. ;;
  350. v2ray | vless)
  351. $bin -config /var/etc/v2-ssr-retcp.json >/dev/null 2>&1 &
  352. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  353. ;;
  354. xray)
  355. $bin -config /var/etc/xray-ssr-retcp.json >/dev/null 2>&1 &
  356. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  357. ;;
  358. trojan)
  359. for i in $(seq 1 $threads); do
  360. $bin --config /var/etc/trojan-ssr-retcp.json >/dev/null 2>&1 &
  361. done
  362. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$($bin --version 2>&1 | head -1) , $threads Threads Started!" >>/tmp/ssrplus.log
  363. ;;
  364. naiveproxy)
  365. $bin /var/etc/naive-ssr-retcp.json >/dev/null 2>&1 &
  366. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$($bin --version 2>&1 | head -1) , $threads Threads Started!" >>/tmp/ssrplus.log
  367. ;;
  368. socks5)
  369. /usr/share/shadowsocksr/genred2config.sh "/var/etc/redsocks-ssr-retcp.conf" socks5 tcp $(uci_get_by_name $GLOBAL_SERVER local_port) \
  370. $(get_host_ip $(uci_get_by_name $GLOBAL_SERVER server)) $(uci_get_by_name $GLOBAL_SERVER server_port) \
  371. $(uci_get_by_name $GLOBAL_SERVER auth_enable 0) $(uci_get_by_name $GLOBAL_SERVER username) $(uci_get_by_name $GLOBAL_SERVER password)
  372. for i in $(seq 1 $threads); do
  373. $bin -c /var/etc/redsocks-ssr-retcp.conf >/dev/null 2>&1
  374. done
  375. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:Socks5 REDIRECT/TPROXY $threads Threads Started!" >>/tmp/ssrplus.log
  376. ;;
  377. tun)
  378. /usr/share/shadowsocksr/genred2config.sh "/var/etc/redsocks-ssr-retcp.conf" vpn $(uci_get_by_name $GLOBAL_SERVER iface "br-lan") $(uci_get_by_name $GLOBAL_SERVER local_port)
  379. for i in $(seq 1 $threads); do
  380. $bin -c /var/etc/redsocks-ssr-retcp.conf >/dev/null 2>&1
  381. done
  382. echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:Network Tunnel REDIRECT $threads Threads Started!" >>/tmp/ssrplus.log
  383. ;;
  384. esac
  385. return 0
  386. }
  387. start_redir_udp() {
  388. if [ -n "$UDP_RELAY_SERVER" ]; then
  389. redir_udp=1
  390. local type=$(uci_get_by_name $UDP_RELAY_SERVER type)
  391. local bin=$(find_bin $type)
  392. [ ! -f "$bin" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:Can't find $bin program, can't start!" >>/tmp/ssrplus.log && redir_udp=0 && return 1
  393. case "$type" in
  394. ss | ssr)
  395. case "$(uci_get_by_name $UDP_RELAY_SERVER auth_enable)" in
  396. 1 | on | true | yes | enabled) ARG_OTA="-A" ;;
  397. *) ARG_OTA="" ;;
  398. esac
  399. local name="Shadowsocks"
  400. [ "$type" == "ssr" ] && name="ShadowsocksR"
  401. gen_config_file $UDP_RELAY_SERVER 1 $(uci_get_by_name $UDP_RELAY_SERVER local_port 1234)
  402. last_config_file=$CONFIG_UDP_FILE
  403. $bin -c $last_config_file $ARG_OTA -U -f /var/run/ssr-reudp.pid >/dev/null 2>&1
  404. echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:$name Started!" >>/tmp/ssrplus.log
  405. ;;
  406. v2ray | vless)
  407. lua /usr/share/shadowsocksr/gen${type}config.lua $UDP_RELAY_SERVER udp $(uci_get_by_name $UDP_RELAY_SERVER local_port) >/var/etc/v2-ssr-reudp.json
  408. sed -i 's/\\//g' /var/etc/v2-ssr-reudp.json
  409. $bin -config /var/etc/v2-ssr-reudp.json >/dev/null 2>&1 &
  410. echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  411. ;;
  412. xray)
  413. lua /usr/share/shadowsocksr/gen${type}config.lua $UDP_RELAY_SERVER udp $(uci_get_by_name $UDP_RELAY_SERVER local_port) >/var/etc/xray-ssr-reudp.json
  414. sed -i 's/\\//g' /var/etc/xray-ssr-reudp.json
  415. $bin -config /var/etc/xray-ssr-reudp.json >/dev/null 2>&1 &
  416. echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  417. ;;
  418. trojan)
  419. lua /usr/share/shadowsocksr/gentrojanconfig.lua $GLOBAL_SERVER client 10801 >/var/etc/trojan-ssr-reudp.json
  420. sed -i 's/\\//g' /var/etc/trojan-ssr-reudp.json
  421. $bin --config /var/etc/trojan-ssr-reudp.json >/dev/null 2>&1 &
  422. ipt2socks -U -b 0.0.0.0 -4 -s 127.0.0.1 -p 10801 -l $(uci_get_by_name $UDP_RELAY_SERVER local_port) >/dev/null 2>&1 &
  423. echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:$($bin --version 2>&1 | head -1) Started!" >>/tmp/ssrplus.log
  424. ;;
  425. naiveproxy)
  426. redir_udp=0
  427. echo "$(date "+%Y-%m-%d %H:%M:%S") $($bin --version | head -1) UDP TPROXY Relay not supported!" >>/tmp/ssrplus.log
  428. ;;
  429. socks5)
  430. /usr/share/shadowsocksr/genred2config.sh "/var/etc/redsocks-ssr-reudp.conf" socks5 udp $(uci_get_by_name $UDP_RELAY_SERVER local_port) \
  431. $(get_host_ip $(uci_get_by_name $UDP_RELAY_SERVER server)) $(uci_get_by_name $UDP_RELAY_SERVER server_port) \
  432. $(uci_get_by_name $UDP_RELAY_SERVER auth_enable 0) $(uci_get_by_name $UDP_RELAY_SERVER username) $(uci_get_by_name $UDP_RELAY_SERVER password)
  433. $bin -c /var/etc/redsocks-ssr-reudp.conf >/dev/null 2>&1
  434. echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:Socks5 REDIRECT/TPROXY Started!" >>/tmp/ssrplus.log
  435. ;;
  436. tun)
  437. redir_udp=0
  438. echo "$(date "+%Y-%m-%d %H:%M:%S") Network Tunnel UDP TPROXY Relay not supported!" >>/tmp/ssrplus.log
  439. ;;
  440. esac
  441. fi
  442. return 0
  443. }
  444. start_shunt() {
  445. if [ "$NETFLIX_SERVER" != "nil" ] && [ "$NETFLIX_SERVER" != "$GLOBAL_SERVER" ]; then
  446. local type=$(uci_get_by_name $NETFLIX_SERVER type)
  447. local bin=$(find_bin $type)
  448. [ ! -f "$bin" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:Can't find $bin program, can't start!" >>/tmp/ssrplus.log && return 1
  449. case "$type" in
  450. ss | ssr)
  451. local bin2=$(find_bin $type-local)
  452. [ ! -f "$bin2" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:Can't find $bin2 program, can't start!" >>/tmp/ssrplus.log && return 2
  453. local name="Shadowsocks"
  454. [ "$type" == "ssr" ] && name="ShadowsocksR"
  455. gen_config_file $NETFLIX_SERVER 2 4321
  456. gen_config_file $NETFLIX_SERVER 3 1088
  457. $bin -c /var/etc/shadowsocksr_n.json $ARG_OTA -f /var/run/ssr-netflix.pid >/dev/null 2>&1
  458. $bin2 -c /var/etc/shadowsocksr_s.json $ARG_OTA -f /var/run/ssr-socksdns.pid >/dev/null 2>&1
  459. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  460. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:$name Started!" >>/tmp/ssrplus.log
  461. ;;
  462. v2ray | vless)
  463. lua /usr/share/shadowsocksr/gen${type}config.lua $NETFLIX_SERVER tcp 4321 1088 >/var/etc/v2-ssr-netflix.json
  464. sed -i 's/\\//g' /var/etc/v2-ssr-netflix.json
  465. $bin -config /var/etc/v2-ssr-netflix.json >/dev/null 2>&1 &
  466. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  467. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  468. ;;
  469. xray)
  470. lua /usr/share/shadowsocksr/gen${type}config.lua $NETFLIX_SERVER tcp 4321 1088 >/var/etc/xray-ssr-netflix.json
  471. sed -i 's/\\//g' /var/etc/xray-ssr-netflix.json
  472. $bin -config /var/etc/xray-ssr-netflix.json >/dev/null 2>&1 &
  473. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  474. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  475. ;;
  476. trojan)
  477. lua /usr/share/shadowsocksr/gentrojanconfig.lua $NETFLIX_SERVER nat 4321 >/var/etc/trojan-ssr-netflix.json
  478. sed -i 's/\\//g' /var/etc/trojan-ssr-netflix.json
  479. $bin --config /var/etc/trojan-ssr-netflix.json >/dev/null 2>&1 &
  480. lua /usr/share/shadowsocksr/gentrojanconfig.lua $NETFLIX_SERVER client 1088 >/var/etc/trojan-ssr-socksdns.json
  481. sed -i 's/\\//g' /var/etc/trojan-ssr-socksdns.json
  482. $bin --config /var/etc/trojan-ssr-socksdns.json >/dev/null 2>&1 &
  483. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  484. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:$($bin --version 2>&1 | head -1) Started!" >>/tmp/ssrplus.log
  485. ;;
  486. naiveproxy)
  487. gen_config_file $NETFLIX_SERVER 1 4321
  488. $bin /var/etc/naive-ssr-netflix.json >/dev/null 2>&1 &
  489. gen_config_file $NETFLIX_SERVER 2 1088
  490. $bin /var/etc/naive-ssr-socksdns.json >/dev/null 2>&1 &
  491. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  492. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:$($bin --version | head -1) Started!" >>/tmp/ssrplus.log
  493. ;;
  494. socks5)
  495. /usr/share/shadowsocksr/genred2config.sh "/var/etc/redsocks-ssr-netflix.conf" socks5 tcp 4321 \
  496. $(get_host_ip $(uci_get_by_name $NETFLIX_SERVER server)) $(uci_get_by_name $NETFLIX_SERVER server_port) \
  497. $(uci_get_by_name $NETFLIX_SERVER auth_enable 0) $(uci_get_by_name $NETFLIX_SERVER username) $(uci_get_by_name $NETFLIX_SERVER password)
  498. $bin -c /var/etc/redsocks-ssr-netflix.conf >/dev/null 2>&1
  499. microsocks -i 127.0.0.1 -p 1088 ssr-socksdns >/dev/null 2>&1 &
  500. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  501. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:Socks5 Started!" >>/tmp/ssrplus.log
  502. ;;
  503. tun)
  504. /usr/share/shadowsocksr/genred2config.sh "/var/etc/redsocks-ssr-netflix.conf" vpn $(uci_get_by_name $NETFLIX_SERVER iface "br-lan") 4321
  505. $bin -c /var/etc/redsocks-ssr-netflix.conf >/dev/null 2>&1
  506. microsocks -i 127.0.0.1 -p 1088 ssr-socksdns >/dev/null 2>&1 &
  507. dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
  508. echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:Network Tunnel REDIRECT Started!" >>/tmp/ssrplus.log
  509. ;;
  510. esac
  511. fi
  512. return 0
  513. }
  514. start_local() {
  515. local local_server=$(uci_get_by_type socks5_proxy server nil)
  516. [ "$local_server" == "nil" ] && return 1
  517. [ "$local_server" == "same" ] && local_server=$GLOBAL_SERVER
  518. local type=$(uci_get_by_name $local_server type)
  519. local bin=$(find_bin $type)
  520. [ ! -f "$bin" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:Can't find $bin program, can't start!" >>/tmp/ssrplus.log && local_enable=0 && return 1
  521. case "$type" in
  522. ss | ssr)
  523. local name="Shadowsocks"
  524. local bin=$(find_bin $type-local)
  525. [ ! -f "$bin" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:Can't find $bin program, can't start!" >>/tmp/ssrplus.log && local_enable=0 && return 1
  526. [ "$type" == "ssr" ] && name="ShadowsocksR"
  527. gen_config_file $local_server 3 $(uci_get_by_type socks5_proxy local_port 1080)
  528. $bin -c $CONFIG_SOCK5_FILE -u -f /var/run/ssr-local.pid >/dev/null 2>&1
  529. echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$name Started!" >>/tmp/ssrplus.log
  530. ;;
  531. v2ray | vless)
  532. lua /usr/share/shadowsocksr/gen${type}config.lua $local_server tcp 0 $(uci_get_by_type socks5_proxy local_port 1080) >/var/etc/v2-ssr-local.json
  533. sed -i 's/\\//g' /var/etc/v2-ssr-local.json
  534. $bin -config /var/etc/v2-ssr-local.json >/dev/null 2>&1 &
  535. echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  536. ;;
  537. xray)
  538. lua /usr/share/shadowsocksr/gen${type}config.lua $local_server tcp 0 $(uci_get_by_type socks5_proxy local_port 1080) >/var/etc/xray-ssr-local.json
  539. sed -i 's/\\//g' /var/etc/xray-ssr-local.json
  540. $bin -config /var/etc/xray-ssr-local.json >/dev/null 2>&1 &
  541. echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
  542. ;;
  543. trojan)
  544. lua /usr/share/shadowsocksr/gentrojanconfig.lua $local_server client $(uci_get_by_type socks5_proxy local_port 1080) >/var/etc/trojan-ssr-local.json
  545. sed -i 's/\\//g' /var/etc/trojan-ssr-local.json
  546. $bin --config /var/etc/trojan-ssr-local.json >/dev/null 2>&1 &
  547. echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$($bin --version 2>&1 | head -1) Started!" >>/tmp/ssrplus.log
  548. ;;
  549. naiveproxy)
  550. gen_config_file $local_server 3 $(uci_get_by_type socks5_proxy local_port 1080)
  551. $bin /var/etc/naive-ssr-local.json >/dev/null 2>&1 &
  552. echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$($bin --version | head -1) Started!" >>/tmp/ssrplus.log
  553. ;;
  554. *)
  555. [ -e /proc/sys/net/ipv6 ] && local listenip='-i ::'
  556. microsocks $listenip -p $(uci_get_by_type socks5_proxy local_port 1080) ssr-local >/dev/null 2>&1 &
  557. echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$type Started!" >>/tmp/ssrplus.log
  558. ;;
  559. esac
  560. local_enable=1
  561. return 0
  562. }
  563. start_server() {
  564. SERVER_ENABLE=$(uci_get_by_type server_global enable_server 0)
  565. [ "$SERVER_ENABLE" == "0" ] && return 0
  566. server_service() {
  567. [ $(uci_get_by_name $1 enable 0) == "0" ] && return 1
  568. let server_count=server_count+1
  569. if [ "$server_count" == "1" ]; then
  570. if ! (iptables-save -t filter | grep SSR-SERVER-RULE >/dev/null); then
  571. iptables -N SSR-SERVER-RULE && \
  572. iptables -t filter -I INPUT -j SSR-SERVER-RULE
  573. fi
  574. fi
  575. if [ "$(uci_get_by_name $1 type ssr)" == "ssr" ]; then
  576. local bin=$(find_bin ssr-server)
  577. [ ! -f "$bin" ] && echo "$(date "+%Y-%m-%d %H:%M:%S") Server:Can't find $bin program, can't start!" >>/tmp/ssrplus.log && return 1
  578. gen_service_file $1 /var/etc/${NAME}_$server_count.json
  579. $(find_bin ssr-server) -c /var/etc/${NAME}_$server_count.json -u -f /var/run/ssr-server$server_count.pid >/dev/null 2>&1
  580. echo "$(date "+%Y-%m-%d %H:%M:%S") Server:ShadowsocksR Server$server_count Started!" >>/tmp/ssrplus.log
  581. else
  582. [ -e /proc/sys/net/ipv6 ] && local listenip='-i ::'
  583. microsocks $listenip -p $(uci_get_by_name $1 server_port) -1 -u $(uci_get_by_name $1 username) -P $(uci_get_by_name $1 password) ssr-server$server_count >/dev/null 2>&1 &
  584. echo "$(date "+%Y-%m-%d %H:%M:%S") Server:Socks5 Server$server_count Started!" >>/tmp/ssrplus.log
  585. fi
  586. iptables -t filter -A SSR-SERVER-RULE -p tcp --dport $(uci_get_by_name $1 server_port) -j ACCEPT
  587. iptables -t filter -A SSR-SERVER-RULE -p udp --dport $(uci_get_by_name $1 server_port) -j ACCEPT
  588. return 0
  589. }
  590. mkdir -p /var/run /var/etc
  591. config_load $NAME
  592. config_foreach server_service server_config
  593. gen_serv_include
  594. return 0
  595. }
  596. start_switch() {
  597. if [ "$(uci_get_by_type global enable_switch 0)" == "1" ]; then
  598. if [ -z "$switch_server" ]; then
  599. local switch_time=$(uci_get_by_type global switch_time)s
  600. local switch_timeout=$(uci_get_by_type global switch_timeout)
  601. service_start /usr/bin/ssr-switch start $switch_time $switch_timeout
  602. switch_enable=1
  603. fi
  604. fi
  605. }
  606. start_monitor() {
  607. if [ $(uci_get_by_type global monitor_enable 1) == "1" ]; then
  608. let total_count=server_count+redir_tcp+redir_udp+tunnel_enable+kcp_enable_flag+local_enable+pdnsd_enable_flag+switch_enable
  609. if [ $total_count -gt 0 ]; then
  610. service_start /usr/bin/ssr-monitor $server_count $redir_tcp $redir_udp $tunnel_enable $kcp_enable_flag $local_enable $pdnsd_enable_flag $switch_enable
  611. fi
  612. fi
  613. }
  614. check_server() {
  615. ENABLE_SERVER=$(uci_get_by_type global global_server nil)
  616. if [ "$ENABLE_SERVER" == "nil" ]; then
  617. return 1
  618. else
  619. local STYPE=$(uci_get_by_name $ENABLE_SERVER type nil)
  620. if [ "$STYPE" == "nil" ]; then
  621. local CFGID=$(uci_get_by_cfgid servers type nil)
  622. if [ "$CFGID" == "nil" ]; then
  623. uci_set_by_type global global_server 'nil'
  624. else
  625. uci_set_by_type global global_server $CFGID
  626. fi
  627. /etc/init.d/shadowsocksr restart
  628. fi
  629. fi
  630. }
  631. start_rules() {
  632. local server=$(get_host_ip $(uci_get_by_name $GLOBAL_SERVER server))
  633. if [ "$server" == "ERROR" ]; then
  634. server=$(uci_get_by_name $GLOBAL_SERVER ip)
  635. fi
  636. local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0)
  637. if [ $kcp_enable == "1" ]; then
  638. kcp_server=$server
  639. kcp_flag=1
  640. fi
  641. local local_port=$(uci_get_by_name $GLOBAL_SERVER local_port)
  642. local lan_ac_ips=$(uci_get_by_type access_control lan_ac_ips)
  643. local lan_ac_mode=$(uci_get_by_type access_control lan_ac_mode)
  644. local router_proxy=$(uci_get_by_type access_control router_proxy)
  645. if [ "$GLOBAL_SERVER" == "$UDP_RELAY_SERVER" -a "$kcp_flag" == "0" ]; then
  646. ARG_UDP="-u"
  647. elif [ -n "$UDP_RELAY_SERVER" ]; then
  648. ARG_UDP="-U"
  649. local udp_server=$(uci_get_by_name $UDP_RELAY_SERVER server)
  650. local udp_local_port=$(uci_get_by_name $UDP_RELAY_SERVER local_port)
  651. fi
  652. if [ -n "$lan_ac_ips" ]; then
  653. case "$lan_ac_mode" in
  654. w | W | b | B) local ac_ips="$lan_ac_mode$lan_ac_ips" ;;
  655. esac
  656. fi
  657. #deal gfw firewall rule
  658. local gfwmode=""
  659. case "$run_mode" in
  660. gfw) gfwmode="-g" ;;
  661. router) gfwmode="-r" ;;
  662. oversea) gfwmode="-c" ;;
  663. all) gfwmode="-z" ;;
  664. esac
  665. local dports=$(uci_get_by_type global dports 1)
  666. if [ $dports == "1" ]; then
  667. proxyport=" "
  668. else
  669. proxyport="-m multiport --dports 22,53,587,465,995,993,143,80,443,853"
  670. fi
  671. if [ "$NETFLIX_SERVER" != "nil" ]; then
  672. if [ "$NETFLIX_SERVER" != "$GLOBAL_SERVER" ]; then
  673. netflix="1"
  674. else
  675. netflix="2"
  676. fi
  677. else
  678. netflix="0"
  679. fi
  680. get_arg_out() {
  681. case "$(uci_get_by_type access_control router_proxy 1)" in
  682. 1) echo "-o" ;;
  683. 2) echo "-O" ;;
  684. esac
  685. }
  686. netflix_ip=$(get_host_ip $(uci_get_by_name $NETFLIX_SERVER server))
  687. if [ "$netflix_ip" == "ERROR" ]; then
  688. netflix_ip=$(uci_get_by_name $NETFLIX_SERVER ip)
  689. fi
  690. /usr/bin/ssr-rules \
  691. -s "$server" \
  692. -l "$local_port" \
  693. -S "$udp_server" \
  694. -L "$udp_local_port" \
  695. -a "$ac_ips" \
  696. -i "/etc/ssr/china_ssr.txt" \
  697. -b "$(uci_get_by_type access_control wan_bp_ips)" \
  698. -w "$(uci_get_by_type access_control wan_fw_ips)" \
  699. -B "$(uci_get_by_type access_control lan_bp_ips)" \
  700. -p "$(uci_get_by_type access_control lan_fp_ips)" \
  701. -G "$(uci_get_by_type access_control lan_gm_ips)" \
  702. -D "$proxyport" \
  703. -F "$netflix" \
  704. -N "$netflix_ip" \
  705. -M "$(uci_get_by_type global netflix_proxy 0)" \
  706. -I "/etc/ssr/netflixip.list" \
  707. $(get_arg_out) $gfwmode $ARG_UDP
  708. return $?
  709. }
  710. rules() {
  711. if [ "$GLOBAL_SERVER" == "nil" ]; then
  712. return 1
  713. fi
  714. mkdir -p /var/run /var/etc
  715. run_mode=$(uci_get_by_type global run_mode)
  716. UDP_RELAY_SERVER=$(uci_get_by_type global udp_relay_server)
  717. [ "$UDP_RELAY_SERVER" == "same" ] && UDP_RELAY_SERVER=$GLOBAL_SERVER
  718. if start_rules; then
  719. return 0
  720. else
  721. return 1
  722. fi
  723. }
  724. start() {
  725. [ -f "$LOCK_FILE" ] && exit 2
  726. touch "$LOCK_FILE"
  727. echo "-----------start-----------" >>/tmp/ssrplus.log
  728. if [ -z "$switch_server" ]; then
  729. GLOBAL_SERVER=$(uci_get_by_type global global_server nil)
  730. else
  731. GLOBAL_SERVER=$switch_server
  732. switch_enable=1
  733. fi
  734. NETFLIX_SERVER=$(uci_get_by_type global netflix_server nil)
  735. if [ "$NETFLIX_SERVER" == "same" ]; then
  736. NETFLIX_SERVER=$GLOBAL_SERVER
  737. fi
  738. mkdir -p /tmp/dnsmasq.d /tmp/dnsmasq.ssr
  739. cat <<-EOF >/tmp/dnsmasq.d/dnsmasq-ssr.conf
  740. conf-dir=/tmp/dnsmasq.ssr
  741. EOF
  742. if rules; then
  743. if start_redir_tcp; then
  744. start_redir_udp
  745. start_shunt
  746. start_switch
  747. start_dns
  748. add_cron
  749. if [ "$run_mode" == "oversea" ]; then
  750. cp -rf /etc/ssr/oversea_list.conf /tmp/dnsmasq.ssr/
  751. else
  752. cp -rf /etc/ssr/gfw_list.conf /tmp/dnsmasq.ssr/
  753. cp -rf /etc/ssr/gfw_base.conf /tmp/dnsmasq.ssr/
  754. fi
  755. /usr/share/shadowsocksr/gfw2ipset.sh $switch_server
  756. else
  757. /usr/bin/ssr-rules -f
  758. fi
  759. else
  760. awk '!/^$/&&!/^#/{printf("address=/%s/''\n",$0)}' /etc/ssr/deny.list >/tmp/dnsmasq.ssr/denylist.conf
  761. if [ "$(uci_get_by_type global adblock 0)" == "1" ]; then
  762. [ "$1" == "" ] && cp -f /etc/ssr/ad.conf /tmp/dnsmasq.ssr/
  763. if [ -f "/tmp/dnsmasq.ssr/ad.conf" ]; then
  764. for line in $(cat /etc/ssr/black.list); do sed -i "/$line/d" /tmp/dnsmasq.ssr/ad.conf; done
  765. for line in $(cat /etc/ssr/white.list); do sed -i "/$line/d" /tmp/dnsmasq.ssr/ad.conf; done
  766. for line in $(cat /etc/ssr/deny.list); do sed -i "/$line/d" /tmp/dnsmasq.ssr/ad.conf; done
  767. fi
  768. fi
  769. fi
  770. /etc/init.d/dnsmasq restart >/dev/null 2>&1
  771. start_server
  772. start_local
  773. start_monitor
  774. check_server
  775. clean_log
  776. echo "------------end------------" >>/tmp/ssrplus.log
  777. rm -f $LOCK_FILE
  778. }
  779. boot() {
  780. ulimit -n 65535
  781. (/usr/share/shadowsocksr/chinaipset.sh && sleep 3 && start >/dev/null 2>&1) &
  782. }
  783. stop() {
  784. unlock
  785. /usr/bin/ssr-rules -f
  786. local srulecount=$(iptables -L | grep SSR-SERVER-RULE | wc -l)
  787. if [ $srulecount -gt 0 ]; then
  788. iptables -F SSR-SERVER-RULE
  789. iptables -t filter -D INPUT -j SSR-SERVER-RULE
  790. iptables -X SSR-SERVER-RULE 2>/dev/null
  791. fi
  792. if [ -z "$switch_server" ]; then
  793. ps -w | grep -v "grep" | grep ssr-switch | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
  794. rm -f /var/lock/ssr-switch.lock
  795. killall -q -9 kcptun-client
  796. fi
  797. ps -w | grep -v "grep" | grep ssr-monitor | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
  798. ps -w | grep -v "grep" | grep "sleep $(uci_get_by_type global switch_time)s" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
  799. ps -w | grep -v "grep" | grep "sleep 30s" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
  800. killall -q -9 ss-redir ss-local obfs-local ssr-redir ssr-local ssr-server v2ray v2ray-plugin xray trojan naive microsocks ipt2socks dns2socks redsocks2 pdnsd
  801. rm -f /var/lock/ssr-monitor.lock
  802. if [ -f "/tmp/dnsmasq.d/dnsmasq-ssr.conf" ]; then
  803. rm -rf /tmp/dnsmasq.d/dnsmasq-ssr.conf /tmp/dnsmasq.ssr /tmp/dnsmasq.oversea
  804. /etc/init.d/dnsmasq restart >/dev/null 2>&1
  805. fi
  806. del_cron
  807. }