1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00
This commit is contained in:
suyuan 2025-02-03 16:53:27 +08:00 committed by GitHub
commit 40d12e68a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 93 additions and 4 deletions

View file

@ -127,6 +127,23 @@ _ping_server() {
fi
}
_ping_server_all() {
count_server() {
config_get disabled $1 disabled
config_get serverip $1 ip
if [ "$disabled" != "1" ] && [ -n "$serverip" ]; then
servers=true
fi
}
config_load openmptcprouter
config_foreach count_server server
if [ "$servers" = true ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }); do
config_foreach _ping_server server $intf
done
fi
}
_httping_server() {
local servername="$1"
[ -z "$servername" ] && return
@ -150,6 +167,24 @@ _httping_server() {
fi
}
_httping_server_all() {
count_server() {
config_get disabled $1 disabled
config_get serverip $1 ip
if [ "$disabled" != "1" ] && [ -n "$serverip" ]; then
servers=true
fi
}
config_load openmptcprouter
config_foreach count_server server
if [ "$servers" = true ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }); do
config_foreach _httping_server server $intf
done
fi
}
_ping() {
local host="$1"
[ -z "$host" ] && return
@ -445,7 +480,7 @@ while true; do
fi
[ -n "$(ip route show ${OMR_TRACKER_HOST} via ${OMR_TRACKER_DEVICE_GATEWAY} dev ${OMR_TRACKER_DEVICE} src ${OMR_TRACKER_DEVICE_IP})" ] && ip route del "$OMR_TRACKER_HOST" via "$OMR_TRACKER_DEVICE_GATEWAY" dev "$OMR_TRACKER_DEVICE" src "$OMR_TRACKER_DEVICE_IP" > /dev/null 2>&1
if $(exit $statusb); then
OMR_TRACKER_STATUS_MSG=""
#OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
else
if [ "$OMR_TRACKER_LIST_HOSTS" = "" ]; then
@ -456,11 +491,11 @@ while true; do
OMR_TRACKER_STATUS_MSG="check error"
fi
else
OMR_TRACKER_STATUS_MSG=""
#OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
fi
else
OMR_TRACKER_STATUS_MSG=""
#OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
fi
if [ "$serverip_ping" != false ] && [ "$OMR_TRACKER_STATUS" = "OK" ] && [ "$OMR_TRACKER_TYPE" != "httping" ] && [ "$OMR_TRACKER_SERVER_HTTP_TEST" = "1" ]; then
@ -469,12 +504,24 @@ while true; do
config_foreach _httping_server server $OMR_TRACKER_DEVICE_IP
if [ "$serverip_ping" = false ]; then
#OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG="No access to server API"
OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG No access to server API"
else
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_STATUS="OK"
break
fi
elif [ "$serverip_ping" = false ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
_ping_server_all
fi
if [ "$OMR_TRACKER_TYPE" = "httping" ]; then
_httping_server_all
fi
if [ "$server_ping" != false ] && [ "$servers" = true ]; then
OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG No answer from server"
OMR_TRACKER_STATUS="ERROR"
break
fi
fi
[ "$OMR_TRACKER_STATUS" = "OK" ] && break
elif ! $(exit $status); then
@ -580,6 +627,18 @@ while true; do
OMR_TRACKER_STATUS="OK"
break
fi
elif [ "$serverip_ping" = false ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
_ping_server_all
fi
if [ "$OMR_TRACKER_TYPE" = "httping" ]; then
_httping_server_all
fi
if [ "$server_ping" != false ] && [ "$servers" = true ]; then
OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG No answer from server"
OMR_TRACKER_STATUS="ERROR"
break
fi
fi
[ "$OMR_TRACKER_STATUS" = "OK" ] && break
elif ! $(exit $status); then

View file

@ -51,6 +51,16 @@ _login() {
else
auth=`curl --max-time 10 -s -k -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://[$server]:$serverport/token`
fi
if [ -z "$auth" ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }'); do
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
auth=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://$server:$serverport/token`
else
auth=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://[$server]:$serverport/token`
fi
[ -n "$auth" ] && break
done
fi
[ -z "$auth" ] && return
token="$(echo "$auth" | jsonfilter -q -e '@.access_token')"
uci -q set openmptcprouter.${servername}.token="$token"
@ -79,6 +89,16 @@ _get_json() {
else
result=`curl --max-time 10 -s -k -H "accept: application/json" -H "Authorization: Bearer $token" https://[$server]:$serverport/$route`
fi
if [ -z "$result" ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }'); do
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
result=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Authorization: Bearer $token" https://$server:$serverport/$route`
else
result=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Authorization: Bearer $token" https://[$server]:$serverport/$route`
fi
[ -n "$result" ] && break
done
fi
if [ "$(echo $result | grep 'Could not validate credentials')" ]; then
result=''
fi
@ -101,6 +121,16 @@ _set_json() {
else
result=`curl --max-time 10 -s -k -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://[$server]:$serverport/$route`
fi
if [ -z "$result" ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }'); do
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
result=`curl --max-time 10 -s -k --interface $intf -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://$server:$serverport/$route`
else
result=`curl --max-time 10 -s -k --interface $intf -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://[$server]:$serverport/$route`
fi
[ -n "$result" ] && break
done
fi
if [ "$(echo $result | grep 'Could not validate credentials')" ]; then
result=''
fi