1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 11:01:50 +00:00
openmptcprouter-feeds/omr-tracker/files/bin/omr-tracker-ss

69 lines
2.3 KiB
Text
Raw Normal View History

2018-05-09 09:15:43 +00:00
#!/bin/sh
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
name=$0
basename="$(basename $0)"
log() {
logger -p daemon.info -t "${basename}" "$@"
}
2018-08-24 11:34:09 +00:00
get_ip() {
2018-12-17 16:01:03 +00:00
uci -q set openmptcprouter.omr=router
uci -q set openmptcprouter.omr.detected_public_ipv4="$(wget -4 -qO- -T 3 http://ip.openmptcprouter.com)"
uci -q set openmptcprouter.omr.detected_ss_ipv4=$(curl -s -4 --socks5 "${proxy}" --max-time 3 http://ip.openmptcprouter.com)
2019-01-14 16:27:00 +00:00
if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" != "1" ]; then
uci -q set openmptcprouter.omr.detected_public_ipv6=$(wget -6 -qO- -T 3 http://ip.openmptcprouter.com)
2019-01-15 20:17:39 +00:00
# uci -q set openmptcprouter.omr.detected_ss_ipv6=$(curl -s -6 --socks5 "${proxy}" --max-time 3 http://ip.openmptcprouter.com)
2018-08-24 11:34:09 +00:00
fi
2018-12-17 16:01:03 +00:00
uci -q commit openmptcprouter.omr
2018-08-24 11:34:09 +00:00
}
timeout=${OMR_TRACKER_TIMEOUT:-5}
interval=${OMR_TRACKER_INTERVAL:-10}
2018-05-13 19:24:27 +00:00
retry=${OMR_TRACKER_TRIES:-4}
proxy=${OMR_TRACKER_PROXY:-127.0.0.1:1111}
hosts=${OMR_TRACKER_HOSTS:-1.1.1.1 1.0.0.1}
2018-05-13 19:24:27 +00:00
nodns=0
2018-05-09 09:15:43 +00:00
last=0
nocontact=""
2018-12-17 16:01:03 +00:00
uci -q set openmptcprouter.omr=router
uci -q set openmptcprouter.omr.shadowsocks=""
2018-08-24 11:34:09 +00:00
get_ip
2018-05-09 09:15:43 +00:00
while true; do
host="${hosts%% *}"
[ "$host" = "$hosts" ] || {
hosts="${hosts#* } $host"
}
2018-06-06 11:25:32 +00:00
if curl -s --socks5 "${proxy}" --max-time "${timeout}" "$host" &>/dev/null ; then
nocontact=""
2018-12-17 16:01:03 +00:00
[ "${last}" -ge "${retry}" ] || [ "$(uci -q get openmptcprouter.omr.shadowsocks)" = "" ] && {
2018-08-24 11:34:09 +00:00
log "Shadowsocks is up (can contact ${host})"
uci -q set openmptcprouter.omr.shadowsocks="up"
2018-12-17 16:01:03 +00:00
uci -q commit openmptcprouter.omr
2018-10-13 19:40:15 +00:00
}
if ! /etc/init.d/shadowsocks-libev rules_exist ; then
2018-10-13 11:53:54 +00:00
/etc/init.d/shadowsocks-libev rules_up 2> /dev/null
2018-10-13 19:40:15 +00:00
get_ip
fi
2019-01-14 16:27:00 +00:00
[ "$(uci -q get openmptcprouter.omr.detected_public_ipv4)" = "" ] || ([ "$(uci -q get openmptcprouter.settings.disable_ipv6)" != "1" ] && [ "$(uci -q get openmptcprouter.omr.detected_public_ipv6)" = "" ]) && get_ip
2018-06-06 11:25:32 +00:00
last=0
else
last=$((last + 1 ))
[ -z "$nocontact" ] && nocontact="$host" || nocontact="$nocontact, $host"
2018-10-26 14:48:21 +00:00
[ "${last}" -ge "${retry}" ] && {
2018-10-13 19:40:15 +00:00
if /etc/init.d/shadowsocks-libev rules_exist ; then
log "Shadowsocks is down (can't contact ${nocontact})"
uci -q set openmptcprouter.omr.shadowsocks="down"
2018-12-17 16:01:03 +00:00
uci -q commit openmptcprouter.omr
2018-10-13 19:40:15 +00:00
/etc/init.d/shadowsocks-libev rules_down 2> /dev/null
get_ip
fi
2018-06-06 11:25:32 +00:00
}
fi
2018-05-09 09:15:43 +00:00
sleep "${interval}"
done