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

@ -120,6 +120,13 @@ o:value("httping","httping")
o:value("dns","dns")
o:value("none","none")
o = s:option(Flag, "server_http_test", translate("Server http test"), translate("Check if connection work with http by sending a request to server"))
o.optional = false
o.rmempty = false
o.default = true
o.disabled = 0
o.enabled = 1
o = s:option(Flag, "mail_alert", translate("Mail alert"), translate("Send a mail when connection state change"))
o.optional = false
o.rmempty = false
@ -181,6 +188,13 @@ o:value("httping","httping")
o:value("dns","dns")
o:value("none","none")
o = s:option(Flag, "server_http_test", translate("Server http test"), translate("Check if connection work with http by sending a request to server"))
o.optional = false
o.rmempty = false
o.default = true
o.disabled = 0
o.enabled = 1
o = s:option(Flag, "mail_alert", translate("Mail alert"), translate("Send a mail when connection status change. You need to configure e-mail settings <a href=\"/cgi-bin/luci/admin/services/mail\">here</a>."))
o.optional = false
o.rmempty = false

View file

@ -240,7 +240,17 @@
<input type="checkbox" name="disablegwping" class="cbi-input-checkbox" value="1" <% if luci.model.uci.cursor():get("openmptcprouter","settings","disablegwping") == "1" then %>checked<% end %>>
<br />
<div class="cbi-value-description">
<%:Disable gateway ping status check%>
<%:Disable gateway ping check in status page%>
</div>
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title"><%:Disable server http test%></label>
<div class="cbi-value-field">
<input type="checkbox" name="disableserverhttptest" class="cbi-input-checkbox" value="1" <% if luci.model.uci.cursor():get("openmptcprouter","settings","disableserverhttptest") == "1" then %>checked<% end %>>
<br />
<div class="cbi-value-description">
<%:Disable HTTP test on Server API in status page%>
</div>
</div>
</div>

View file

@ -452,6 +452,7 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
var gw_ping = mArray.wans[i].gw_ping;
var gw_ping6 = mArray.wans[i].gw_ping6;
var server_ping = mArray.wans[i].server_ping;
var server_http = mArray.wans[i].server_http;
var ipv6_discover = mArray.wans[i].ipv6_discover;
var multipath_available = mArray.wans[i].multipath_available;
var multipath_state = mArray.wans[i].multipath_state;
@ -563,6 +564,10 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm
{
statusMessage += '<%:No Server ping response after 1 second%>' + '<br />';
}
if(server_http == 'DOWN' && mArray.openmptcprouter.service_addr !== "")
{
statusMessage += '<%:No Server http response after 1 second%>' + '<br />';
}
if (stat == 'Offline' && ipaddr != '' && ipaddr == mArray.wans[i].gateway)
{
statusMessage += '<%:Wan IP and gateway are identical%>' + '<br />';

View file

@ -836,6 +836,7 @@ function interfaces_status()
mArray.openmptcprouter["vps_hostname"] = "Server"
-- Get VPS info
local adminport = ""
ucic:foreach("openmptcprouter", "server", function(s)
local serverips = uci:get("openmptcprouter",s[".name"],"ip") or { "" }
local master = uci:get("openmptcprouter",s[".name"],"master") or "1"
@ -849,7 +850,7 @@ function interfaces_status()
if uci:get("openmptcprouter",s[".name"],"admin_error") == "1" then
mArray.openmptcprouter["vps_admin_error"] = true
end
local adminport = uci:get("openmptcprouter",s[".name"],"port") or "65500"
adminport = uci:get("openmptcprouter",s[".name"],"port") or "65500"
local token = uci:get("openmptcprouter",s[".name"],"token") or ""
if token ~= "" then
local vpsinfo_json = ""
@ -1120,6 +1121,7 @@ function interfaces_status()
local ipv6 = section["ipv6"] or "0"
local mac = section ["macaddr"] or ""
local itype = section ["type"] or ""
local state = section ["state"] or ""
--if not ipaddr or not gateway then return end
-- Don't show if0 in the overview
@ -1325,6 +1327,7 @@ function interfaces_status()
local latency = ""
local server_ping = ""
local server_http = ""
--if connectivity ~= "ERROR" and ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" and ipaddr ~= "" then
if ifname ~= "" and (gateway ~= "" or gateway6 ~= "") and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" and (ipaddr ~= "" or ip6addr ~= "") and connectivity ~= "ERROR" then
local serverip = mArray.openmptcprouter["service_addr"]
@ -1345,6 +1348,40 @@ function interfaces_status()
latency = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | cut -d '/' -s -f5 | cut -d '.' -f1"))
end
end
if adminport == "" then
adminport = "65500"
end
if server_ping == "UP" and uci:get("openmptcprouter", "settings", "disableserverhttptest") ~= "1" and ipaddr ~= "" and adminport ~= "" then
local server_http_result = ""
local server_http_test = ""
if mArray.openmptcprouter["service_addr_ip"] ~= "" then
server_http_test = sys.exec("httping -l " .. mArray.openmptcprouter["service_addr_ip"] .. ":" .. adminport .. " -y " .. ipaddr .. " -t 1 -c 1")
server_http_result = ut.trim(sys.exec("echo '" .. server_http_test .. "' | grep '100.00% failed'"))
if server_http_result ~= "" then
server_http = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
end
end
if mArray.openmptcprouter["service_addr_ip6"] ~= "" then
server_http_test = sys.exec("httping -l [" .. mArray.openmptcprouter["service_addr_ip6"] .. "]:" .. adminport .. " -y " .. ipaddr .. " -t 1 -c 1")
server_http_result = ut.trim(sys.exec("echo '" .. server_http_test .. "' | grep '100.00% failed'"))
if server_http_result ~= "" then
server_http = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
end
end
if server_http_result ~= "" then
server_http = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
end
end
end
local multipath_available = ""
@ -1443,6 +1480,11 @@ function interfaces_status()
rx = ut.trim(sys.exec("devstatus " .. ifname .. " | jsonfilter -e '@.statistics.rx_bytes'"))
tx = ut.trim(sys.exec("devstatus " .. ifname .. " | jsonfilter -e '@.statistics.tx_bytes'"))
end
if state == "down" then
connectivity = "ERROR"
end
local data = {
label = section["label"] or interface,
name = interface,
@ -1466,6 +1508,7 @@ function interfaces_status()
gw_ping = gw_ping,
gw_ping6 = gw_ping6,
server_ping = server_ping,
server_http = server_http,
ipv6_discover = ipv6_discover,
multipath_available = multipath_available,
multipath_state = current_multipath_state,
@ -1481,6 +1524,7 @@ function interfaces_status()
tx = tx,
zonewan = zonewan,
iftype = itype,
state = state,
}
if ifname ~= nil and ifname:match("^tun.*") then
table.insert(mArray.tunnels, data);

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