1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Add wan http test to API

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-03-23 09:49:12 +01:00
parent 57934483b7
commit 27979c78d3
8 changed files with 125 additions and 12 deletions

View file

@ -174,11 +174,10 @@ _httping() {
ret=$(httping "${host}" \
-y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \
-c 1 \
-q
-c 1 2>&1
) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY"
fi
return
@ -187,11 +186,10 @@ _httping() {
ret=$(httping -l "${host}" \
-y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \
-c 1 \
-q
-c 1 2>&1
) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY"
fi
return
@ -370,12 +368,24 @@ while true; do
else
OMR_TRACKER_LIST_HOSTS="$OMR_TRACKER_LIST_HOSTS,$OMR_TRACKER_HOST"
fi
OMR_TRACKER_STATUS_MSG="check error"
fi
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
break
fi
elif [ "$server_ping" != false ] && [ "$OMR_TRACKER_TYPE" != "httping" ] && [ "$OMR_TRACKER_SERVER_HTTP_TEST" = "1" ]; then
serverip_ping=false
config_load openmptcprouter
config_foreach _httping_server server $OMR_TRACKER_DEVICE_IP
if [ "$serverip_ping" = false ]; then
OMR_TRACKER_STATUS_MSG="No access to server API"
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
break
fi
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
@ -454,16 +464,28 @@ while true; do
break
else
if [ "$OMR_TRACKER_LIST_HOSTS6" = "" ]; then
OMR_TRACKER_LIST_HOSTS="$OMR_TRACKER_HOST6"
OMR_TRACKER_LIST_HOSTS6="$OMR_TRACKER_HOST6"
else
OMR_TRACKER_LIST_HOSTS6="$OMR_TRACKER_LIST_HOSTS6,$OMR_TRACKER_HOST6"
fi
OMR_TRACKER_STATUS_MSG="check error"
fi
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
break
fi
elif [ "$server_ping" != false ] && [ "$OMR_TRACKER_TYPE" != "httping" ] && [ "$OMR_TRACKER_SERVER_HTTP_TEST" = "1" ]; then
serverip_ping=false
config_load openmptcprouter
config_foreach _httping_server server $OMR_TRACKER_DEVICE_IP
if [ "$serverip_ping" = false ]; then
OMR_TRACKER_STATUS_MSG="No access to server API"
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
break
fi
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"

View file

@ -23,6 +23,7 @@ config defaults 'defaults'
option interval_tries '1'
option type 'ping'
option wait_test '0'
option server_http_test '1'
option options ''
config proxy 'proxy'

View file

@ -15,7 +15,7 @@
_validate_section() {
local tmp_hosts=$hosts tmp_hosts6=$hosts6 tmp_timeout=$timeout tmp_tries=$tries
local tmp_interval=$interval tmp_interval_tries=$interval_tries tmp_options=$options tmp_type=$type tmp_enabled=$enabled tmp_wait_test=$wait_test
local tmp_interval=$interval tmp_interval_tries=$interval_tries tmp_options=$options tmp_type=$type tmp_enabled=$enabled tmp_wait_test=$wait_test tmp_server_http_test=$server_http_test
uci_validate_section omr-tracker "$1" "$2" \
'hosts:list(host)' \
@ -27,6 +27,7 @@ _validate_section() {
'wait_test:uinteger' \
'type:string:undef' \
'enabled:bool:1' \
'server_http_test:bool:1' \
'options:string'
[ -z "$hosts" ] && hosts=$tmp_hosts
@ -38,6 +39,7 @@ _validate_section() {
[ -z "$wait_test" ] && wait_test=$tmp_wait_test
[ -z "$options" ] && options=$tmp_options
[ "$type" = "undef" ] && type=${tmp_type:-ping}
[ -z "$server_http_test" ] && server_http_test=$tmp_server_http_test
[ -z "$enabled" ] && enabled=$tmp_enabled
}
@ -46,7 +48,7 @@ _launch_tracker() {
loopback|lan*|if0*) return;;
esac
local hosts hosts6 timeout tries interval interval_tries options type enabled wait_test ipv6 proto
local hosts hosts6 timeout tries interval interval_tries options type enabled wait_test ipv6 proto server_http_test
_validate_section "defaults" "defaults"
_validate_section "interface" "$1"
@ -84,6 +86,7 @@ _launch_tracker() {
procd_append_param env "OMR_TRACKER_IPV6=$ipv6"
procd_append_param env "OMR_TRACKER_PROTO=$proto"
procd_append_param env "OMR_TRACKER_WAIT_TEST=$wait_test"
procd_append_param env "OMR_TRACKER_SERVER_HTTP_TEST=$server_http_test"
procd_set_param limits nofile="51200 51200"
procd_set_param respawn 0 10 0
procd_set_param stderr 1
@ -268,7 +271,7 @@ start_service() {
}
service_triggers() {
procd_add_reload_trigger omr-tracker network shadowsocks-libev
procd_add_reload_trigger omr-tracker network shadowsocks-libev v2ray
}
reload_service() {

View file

@ -65,6 +65,13 @@ if [ "$(uci -q get omr-tracker.proxy.hosts | grep '176.103.130.130')" != "" ]; t
EOF
fi
if [ "$(uci -q get omr-tracker.proxy.hosts | grep '198.41.212.162')" = "" ]; then
uci -q batch <<-EOF >/dev/null
add_list omr-tracker.proxy.hosts='198.41.212.162'
commit omr-tracker
EOF
fi
if [ -z "$(uci -q get omr-tracker.defaults.hosts6)" ]; then
uci -q batch <<-EOF >/dev/null
add_list omr-tracker.defaults.hosts6='2606:4700:4700::1111'
@ -86,4 +93,11 @@ if [ "$(uci -q get omr-tracker.defaults.wait_test)" = "" ]; then
EOF
fi
if [ "$(uci -q get omr-tracker.defaults.server_http_test)" = "" ]; then
uci -q batch <<-EOF >/dev/null
set omr-tracker.defaults.server_http_test=1
commit omr-tracker
EOF
fi
exit 0