travelmate: update 2.0.9-2
* fix another vpn corner case
* add support for javascript based captive portals (location.href)
Signed-off-by: Dirk Brenken <dev@brenken.org>
(cherry picked from commit 3ae7a46b82
)
This commit is contained in:
parent
86408bf662
commit
97ebbd0146
3 changed files with 20 additions and 16 deletions
|
@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
|
|||
|
||||
PKG_NAME:=travelmate
|
||||
PKG_VERSION:=2.0.9
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
PKG_LICENSE:=GPL-3.0-or-later
|
||||
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
||||
|
||||
|
|
|
@ -213,10 +213,10 @@ f_vpn() {
|
|||
fi
|
||||
done
|
||||
fi
|
||||
if [ -x "${trm_vpnpgm}" ] && [ -n "${vpn_service}" ] && [ -n "${vpn_iface}" ] && [ -f "${trm_ntpfile}" ]; then
|
||||
if [ -x "${trm_vpnpgm}" ] && [ -n "${vpn_service}" ] && [ -n "${vpn_iface}" ]; then
|
||||
if { [ "${vpn_action}" = "disable" ] && [ -f "${trm_vpnfile}" ]; } ||
|
||||
{ [ "${vpn}" = "1" ] && [ "${vpn_action%_*}" = "enable" ] && [ ! -f "${trm_vpnfile}" ]; } ||
|
||||
{ [ "${vpn}" != "1" ] && [ "${vpn_action%_*}" = "enable" ] && [ -f "${trm_vpnfile}" ]; }; then
|
||||
{ [ -f "${trm_ntpfile}" ] && { [ "${vpn}" = "1" ] && [ "${vpn_action%_*}" = "enable" ] && [ ! -f "${trm_vpnfile}" ]; } ||
|
||||
{ [ "${vpn}" != "1" ] && [ "${vpn_action%_*}" = "enable" ] && [ -f "${trm_vpnfile}" ]; }; }; then
|
||||
result="$(f_net)"
|
||||
if [ "${result}" = "net ok" ] || [ "${vpn_action}" = "disable" ]; then
|
||||
f_log "info" "vpn call '${vpn:-"0"}/${vpn_action}/${vpn_service}/${vpn_iface}'"
|
||||
|
@ -224,11 +224,6 @@ f_vpn() {
|
|||
rc="${?}"
|
||||
fi
|
||||
fi
|
||||
if [ "${vpn}" = "1" ] && [ "${vpn_action%_*}" = "enable" ] && [ "${rc}" = "0" ]; then
|
||||
: >"${trm_vpnfile}"
|
||||
elif [ "${vpn}" != "1" ] || [ "${vpn_action}" = "disable" ]; then
|
||||
rm -f "${trm_vpnfile}"
|
||||
fi
|
||||
[ -n "${rc}" ] && f_jsnup
|
||||
fi
|
||||
f_log "debug" "f_vpn ::: enabled: ${vpn:-"-"}, action: ${vpn_action}, service: ${vpn_service:-"-"}, iface: ${vpn_iface:-"-"}, rc: ${rc:-"-"}"
|
||||
|
@ -519,7 +514,7 @@ f_addsta() {
|
|||
# check net status
|
||||
#
|
||||
f_net() {
|
||||
local err_msg raw html_raw html_cp json_raw json_ec json_rc json_cp json_ed result="net nok"
|
||||
local err_msg raw json_raw html_raw html_cp js_cp json_ec json_rc json_cp json_ed result="net nok"
|
||||
|
||||
raw="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --header "Cache-Control: no-cache, no-store, must-revalidate, max-age=0" --write-out "%{json}" --silent --max-time $((trm_maxwait / 6)) "${trm_captiveurl}")"
|
||||
json_raw="${raw#*\{}"
|
||||
|
@ -534,8 +529,11 @@ f_net() {
|
|||
else
|
||||
if [ "${json_rc}" = "200" ] || [ "${json_rc}" = "204" ]; then
|
||||
html_cp="$(printf "%s" "${html_raw}" | awk 'match(tolower($0),/^.*<meta[ \t]+http-equiv=['\''"]*refresh.*[ \t;]url=/){print substr(tolower($0),RLENGTH+1)}' | awk 'BEGIN{FS="[:/]"}{printf "%s",$4;exit}')"
|
||||
js_cp="$(printf "%s" "${html_raw}" | awk 'match(tolower($0),/^.*location\.href=['\''"]*/){print substr(tolower($0),RLENGTH+1)}' | awk 'BEGIN{FS="[:/]"}{printf "%s",$4;exit}')"
|
||||
if [ -n "${html_cp}" ]; then
|
||||
result="net cp '${html_cp}'"
|
||||
elif [ -n "${js_cp}" ]; then
|
||||
result="net cp '${js_cp}'"
|
||||
else
|
||||
result="net ok"
|
||||
fi
|
||||
|
@ -556,7 +554,7 @@ f_net() {
|
|||
fi
|
||||
fi
|
||||
printf "%s" "${result}"
|
||||
f_log "debug" "f_net ::: fetch: ${trm_fetch}, timeout: $((trm_maxwait / 6)), cp (json/html): ${json_cp:-"-"}/${html_cp:-"-"}, result: ${result}, error (rc/msg): ${json_ec}/${err_msg:-"-"}, url: ${trm_captiveurl}, user_agent: ${trm_useragent}"
|
||||
f_log "debug" "f_net ::: fetch: ${trm_fetch}, timeout: $((trm_maxwait / 6)), cp (json/html/js): ${json_cp:-"-"}/${html_cp:-"-"}/${js_cp:-"-"}, result: ${result}, error (rc/msg): ${json_ec}/${err_msg:-"-"}, url: ${trm_captiveurl}, user_agent: ${trm_useragent}"
|
||||
}
|
||||
|
||||
# check interface status
|
||||
|
@ -642,12 +640,14 @@ f_check() {
|
|||
fi
|
||||
fi
|
||||
fi
|
||||
if [ "${trm_netcheck}" = "1" ] && [ "${result}" = "net nok" ]; then
|
||||
f_log "info" "uplink has no internet"
|
||||
if [ "${result}" = "net nok" ]; then
|
||||
f_vpn "disable"
|
||||
trm_ifstatus="${status}"
|
||||
f_jsnup
|
||||
break
|
||||
if [ "${trm_netcheck}" = "1" ]; then
|
||||
f_log "info" "uplink has no internet"
|
||||
trm_ifstatus="${status}"
|
||||
f_jsnup
|
||||
break
|
||||
fi
|
||||
fi
|
||||
trm_connection="${result:-"-"}/${trm_ifquality}"
|
||||
f_jsnup
|
||||
|
|
|
@ -23,6 +23,7 @@ trm_captiveurl="$(uci_get travelmate global trm_captiveurl "http://detectportal.
|
|||
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
|
||||
trm_logger="$(command -v logger)"
|
||||
trm_fetch="$(command -v curl)"
|
||||
trm_vpnfile="/var/state/travelmate.vpn"
|
||||
|
||||
f_net() {
|
||||
local json_rc result="net nok"
|
||||
|
@ -46,6 +47,7 @@ if [ "${vpn}" = "1" ] && [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" !=
|
|||
if [ "${vpn_status}" = "true" ]; then
|
||||
net_status="$(f_net)"
|
||||
if [ "${net_status}" = "net ok" ]; then
|
||||
: >"${trm_vpnfile}"
|
||||
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${vpn_service} client connection enabled" 2>/dev/null
|
||||
break
|
||||
fi
|
||||
|
@ -55,6 +57,7 @@ if [ "${vpn}" = "1" ] && [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" !=
|
|||
if [ "${vpn_service}" = "openvpn" ] && [ -x "/etc/init.d/openvpn" ]; then
|
||||
/etc/init.d/openvpn stop
|
||||
fi
|
||||
rm -f "${trm_vpnfile}"
|
||||
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${vpn_service} client connection can't be established" 2>/dev/null
|
||||
exit 1
|
||||
fi
|
||||
|
@ -66,5 +69,6 @@ elif { [ "${vpn}" != "1" ] && [ "${vpn_action}" = "enable" ]; } || [ "${vpn_acti
|
|||
if [ "${vpn_service}" = "openvpn" ] && [ -x "/etc/init.d/openvpn" ]; then
|
||||
/etc/init.d/openvpn stop
|
||||
fi
|
||||
rm -f "${trm_vpnfile}"
|
||||
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${vpn_service} client connection disabled" 2>/dev/null
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue