Fixed ovpn check
This commit is contained in:
parent
d8c580b390
commit
930bb8cfeb
@ -210,19 +210,26 @@ return view.extend({
|
|||||||
]));
|
]));
|
||||||
|
|
||||||
if (st.openvpn) {
|
if (st.openvpn) {
|
||||||
var ovpnState = E('em', 'проверяю…');
|
var ovpnState = E('span', '—');
|
||||||
var otp = E('span', '—');
|
var otp = E('span', '—');
|
||||||
callOvpnStatus().then(function(o) {
|
var ovpnCheck = function() {
|
||||||
|
dom.content(ovpnState, E('em', 'проверяю…'));
|
||||||
|
return callOvpnStatus().then(function(o) {
|
||||||
dom.content(ovpnState, {
|
dom.content(ovpnState, {
|
||||||
up: E('strong', { 'style': 'color:green' }, 'туннель работает'),
|
up: E('strong', { 'style': 'color:green' }, 'туннель работает, ' + o.delay + ' мс'),
|
||||||
down: E('strong', { 'style': 'color:#c00' }, 'туннель не отвечает'),
|
down: [ E('strong', { 'style': 'color:#c00' }, 'туннель не отвечает'), ' ' + (o.message || '') ],
|
||||||
off: 'выключен'
|
off: 'выключен'
|
||||||
}[o.state] || o.state);
|
}[o.state] || o.state);
|
||||||
|
if (o.url)
|
||||||
|
ovpnState.appendChild(E('span', { 'class': 'cbi-value-description' }, [ ' — ', o.url ]));
|
||||||
dom.content(otp, o.otp ? o.otp + ' (ещё ' + o.otp_left + ' с)' : '—');
|
dom.content(otp, o.otp ? o.otp + ' (ещё ' + o.otp_left + ' с)' : '—');
|
||||||
}).catch(function(e) { dom.content(ovpnState, String(e)); });
|
}).catch(function(e) { dom.content(ovpnState, String(e)); });
|
||||||
|
};
|
||||||
|
ovpnCheck();
|
||||||
sections.push(section('OpenVPN', [
|
sections.push(section('OpenVPN', [
|
||||||
E('table', { 'class': 'table' }, [
|
E('table', { 'class': 'table' }, [
|
||||||
row('Состояние', ovpnState),
|
row('Состояние', [ ovpnState, ' ', E('button', { 'class': 'btn cbi-button cbi-button-action',
|
||||||
|
'click': ui.createHandlerFn(this, ovpnCheck) }, 'Проверить') ]),
|
||||||
row('OTP сейчас', otp)
|
row('OTP сейчас', otp)
|
||||||
]),
|
]),
|
||||||
E('div', { 'class': 'cbi-page-actions' }, [
|
E('div', { 'class': 'cbi-page-actions' }, [
|
||||||
@ -241,8 +248,7 @@ return view.extend({
|
|||||||
return callTsCheck().then(function(r) {
|
return callTsCheck().then(function(r) {
|
||||||
dom.content(tsState, {
|
dom.content(tsState, {
|
||||||
up: E('strong', { 'style': 'color:green' }, 'отвечает, ' + r.delay + ' мс'),
|
up: E('strong', { 'style': 'color:green' }, 'отвечает, ' + r.delay + ' мс'),
|
||||||
down: [ E('strong', { 'style': 'color:#c00' }, 'не отвечает'), ' ' + (r.message || '') ],
|
down: [ E('strong', { 'style': 'color:#c00' }, 'не отвечает'), ' ' + (r.message || '') ]
|
||||||
nourl: 'адрес для проверки не задан (Настройка → Tailscale)'
|
|
||||||
}[r.state] || r.state);
|
}[r.state] || r.state);
|
||||||
if (r.url)
|
if (r.url)
|
||||||
tsState.appendChild(E('span', { 'class': 'cbi-value-description' }, [ ' — ', r.url ]));
|
tsState.appendChild(E('span', { 'class': 'cbi-value-description' }, [ ' — ', r.url ]));
|
||||||
|
|||||||
58
luci/rpcd.sh
58
luci/rpcd.sh
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# status profile, nikki running, which features are on, kit version,
|
# status profile, nikki running, which features are on, kit version,
|
||||||
# mihomo API port/secret (dashboard link)
|
# mihomo API port/secret (dashboard link)
|
||||||
# ovpn_status OpenVPN state (up/down/off) + current OTP; slow (a delay test)
|
# ovpn_status OpenVPN state (up/down/off, delay to OVPN_CHECK_URL) + current OTP
|
||||||
# run start a whitelisted command as the background job
|
# run start a whitelisted command as the background job
|
||||||
# job the job's command, state, exit code and output
|
# job the job's command, state, exit code and output
|
||||||
# update_check latest kit commit on the git server vs the installed one
|
# update_check latest kit commit on the git server vs the installed one
|
||||||
@ -78,14 +78,39 @@ m_status() {
|
|||||||
json_dump
|
json_dump
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# delay_check <group> <VAR> <default url>: delay test of the group to the
|
||||||
|
# check URL (from common.env + profile env) through the mihomo API -> json fields
|
||||||
|
delay_check() {
|
||||||
|
prof=$(uci -q get nikki.config.profile)
|
||||||
|
prof=${prof#file:}
|
||||||
|
prof=${prof%.yaml}
|
||||||
|
url=$(envval "$2" "$prof")
|
||||||
|
# defaults: the same as set_defaults in mihomo-kit.sh
|
||||||
|
[ -n "$url" ] || url=$3
|
||||||
|
json_add_string url "$url"
|
||||||
|
sec=$(uci -q get nikki.mixin.api_secret)
|
||||||
|
res=$(curl -sS -m 12 ${sec:+-H "Authorization: Bearer $sec"} -G \
|
||||||
|
--data-urlencode "url=$url" --data-urlencode timeout=8000 \
|
||||||
|
"$(api_url)/proxies/$1/delay" 2>&1)
|
||||||
|
delay=$(jsonfilter -s "$res" -e '@.delay' 2>/dev/null)
|
||||||
|
if [ -n "$delay" ]; then
|
||||||
|
json_add_string state up
|
||||||
|
json_add_int delay "$delay"
|
||||||
|
else
|
||||||
|
json_add_string state down
|
||||||
|
json_add_string message "$(jsonfilter -s "$res" -e '@.message' 2>/dev/null || echo "$res")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
m_ovpn_status() {
|
m_ovpn_status() {
|
||||||
json_init
|
json_init
|
||||||
if [ -f "$NIKKI_DIR/bmstu.off" ]; then
|
if [ -f "$NIKKI_DIR/bmstu.off" ]; then
|
||||||
json_add_string state off
|
json_add_string state off
|
||||||
elif CHECK_TIMEOUT=8000 bmstu-otp.sh status 2>/dev/null | grep -q "tunnel is up"; then
|
|
||||||
json_add_string state up
|
|
||||||
else
|
else
|
||||||
json_add_string state down
|
prof=$(uci -q get nikki.config.profile)
|
||||||
|
prof=${prof#file:}
|
||||||
|
group=$(envval OVPN_GROUP "${prof%.yaml}")
|
||||||
|
delay_check "${group:-BMSTU}" OVPN_CHECK_URL https://eu.bmstu.ru
|
||||||
fi
|
fi
|
||||||
json_add_string otp "$(bmstu-otp.sh otp 2>/dev/null)"
|
json_add_string otp "$(bmstu-otp.sh otp 2>/dev/null)"
|
||||||
json_add_int otp_left "$((30 - $(date +%s) % 30))"
|
json_add_int otp_left "$((30 - $(date +%s) % 30))"
|
||||||
@ -272,31 +297,8 @@ m_config_set() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_ts_check() {
|
m_ts_check() {
|
||||||
prof=$(uci -q get nikki.config.profile)
|
|
||||||
prof=${prof#file:}
|
|
||||||
prof=${prof%.yaml}
|
|
||||||
url=$(envval TS_CHECK_URL "$prof")
|
|
||||||
# same default as set_defaults in mihomo-kit.sh
|
|
||||||
[ -n "$url" ] || url=http://100.69.216.50:8080
|
|
||||||
json_init
|
json_init
|
||||||
if [ -z "$url" ]; then
|
delay_check TAILSCALE TS_CHECK_URL http://100.69.216.50:8080
|
||||||
json_add_string state nourl
|
|
||||||
json_dump
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
json_add_string url "$url"
|
|
||||||
sec=$(uci -q get nikki.mixin.api_secret)
|
|
||||||
res=$(curl -sS -m 12 ${sec:+-H "Authorization: Bearer $sec"} -G \
|
|
||||||
--data-urlencode "url=$url" --data-urlencode timeout=8000 \
|
|
||||||
"$(api_url)/proxies/TAILSCALE/delay" 2>&1)
|
|
||||||
delay=$(jsonfilter -s "$res" -e '@.delay' 2>/dev/null)
|
|
||||||
if [ -n "$delay" ]; then
|
|
||||||
json_add_string state up
|
|
||||||
json_add_int delay "$delay"
|
|
||||||
else
|
|
||||||
json_add_string state down
|
|
||||||
json_add_string message "$(jsonfilter -s "$res" -e '@.message' 2>/dev/null || echo "$res")"
|
|
||||||
fi
|
|
||||||
json_dump
|
json_dump
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user