Browse Source

travelmate: update 2.0.2

* fix a vpn/iptables race condition
* remove needless dnsmasq dependency
* synchronize code-base of all auto-login scripts, due to
  COVID-19 restrictions all of them are still untested/WIP
* various small cleanups

Signed-off-by: Dirk Brenken <dev@brenken.org>
lilik-openwrt-22.03
Dirk Brenken 4 years ago
parent
commit
404dc5b101
No known key found for this signature in database GPG Key ID: 9D71CD547BFAE684
11 changed files with 159 additions and 96 deletions
  1. +3
    -3
      net/travelmate/Makefile
  2. +20
    -14
      net/travelmate/files/chs-hotel.login
  3. +16
    -4
      net/travelmate/files/db-bahn.login
  4. +23
    -8
      net/travelmate/files/generic-user-pass.login
  5. +19
    -13
      net/travelmate/files/h-hotels.login
  6. +3
    -3
      net/travelmate/files/travelmate.init
  7. +9
    -4
      net/travelmate/files/travelmate.mail
  8. +41
    -41
      net/travelmate/files/travelmate.sh
  9. +12
    -5
      net/travelmate/files/travelmate.vpn
  10. +1
    -1
      net/travelmate/files/travelmate_ntp.hotplug
  11. +12
    -0
      net/travelmate/files/wifionice.login

+ 3
- 3
net/travelmate/Makefile View File

@ -6,8 +6,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=travelmate
PKG_VERSION:=2.0.1
PKG_RELEASE:=2
PKG_VERSION:=2.0.2
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
@ -17,7 +17,7 @@ define Package/travelmate
SECTION:=net
CATEGORY:=Network
TITLE:=A wlan connection manager for travel router
DEPENDS:=+iwinfo +jshn +jsonfilter +curl +ca-bundle +dnsmasq
DEPENDS:=+iwinfo +jshn +jsonfilter +curl +ca-bundle
PKGARCH:=all
endef


+ 20
- 14
net/travelmate/files/chs-hotel.login View File

@ -3,26 +3,32 @@
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
domain="hotspot.internet-for-guests.com"
cmd="$(command -v curl)"
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
# curl check
#
if [ ! -x "${cmd}" ]
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
exit 1
. "/lib/functions.sh"
fi
trm_domain="hotspot.internet-for-guests.com"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_fetch="$(command -v curl)"
# initial get request to receive & extract valid security tokens
#
"${cmd}" "https://${domain}/logon/cgi/index.cgi" -c "/tmp/${domain}.cookie" -s -o /dev/null
if [ -r "/tmp/${domain}.cookie" ]
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait/6)) --cookie-jar "/tmp/${trm_domain}.cookie" --output /dev/null "https://${trm_domain}/logon/cgi/index.cgi"
if [ -r "/tmp/${trm_domain}.cookie" ]
then
lg_id="$(awk '/LGNSID/{print $7}' "/tmp/${domain}.cookie")"
ta_id="$(awk '/ta_id/{print $7}' "/tmp/${domain}.cookie")"
cl_id="$(awk '/cl_id/{print $7}' "/tmp/${domain}.cookie")"
rm -f "/tmp/${domain}.cookie"
lg_id="$(awk '/LGNSID/{print $7}' "/tmp/${trm_domain}.cookie")"
ta_id="$(awk '/ta_id/{print $7}' "/tmp/${trm_domain}.cookie")"
cl_id="$(awk '/cl_id/{print $7}' "/tmp/${trm_domain}.cookie")"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
fi
@ -31,7 +37,7 @@ fi
#
if [ -n "${lg_id}" ] && [ -n "${ta_id}" ] && [ -n "${cl_id}" ]
then
"${cmd}" "https://${domain}/logon/cgi/index.cgi" -H "Referer: https://${domain}/logon/cgi/index.cgi" -H "Cookie: LGNSID=${lg_id}; lang=en_US; use_mobile_interface=0; ta_id=${ta_id}; cl_id=${cl_id}" -H 'Connection: keep-alive' --data 'accept_termsofuse=&freeperperiod=1&device_infos=1125:2048:1152:2048' -s -o /dev/null
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "https://${trm_domain}/logon/cgi/index.cgi" --silent --connect-timeout $((trm_maxwait/6)) --header "Cookie: LGNSID=${lg_id}; lang=en_US; use_mobile_interface=0; ta_id=${ta_id}; cl_id=${cl_id}" --data "accept_termsofuse=&freeperperiod=1&device_infos=1125:2048:1152:2048" --output /dev/null "https://${trm_domain}/logon/cgi/index.cgi"
else
exit 3
fi

+ 16
- 4
net/travelmate/files/db-bahn.login View File

@ -3,6 +3,18 @@
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
fi
trm_domain="wifi.bahn.de"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
@ -16,7 +28,7 @@ trm_fetch="$(command -v curl)"
#
if [ -s "/tmp/${trm_domain}.cookie" ]
then
php_token="$(awk 'BEGIN{FS="[ ;]"}/^Set-Cookie:/{print $2}' "/tmp/${trm_domain}.cookie")"
sec_token="$(awk 'BEGIN{FS="[ ;]"}/^Set-Cookie:/{print $2}' "/tmp/${trm_domain}.cookie")"
location="$(awk '/^Location:/{print $2}' "/tmp/${trm_domain}.cookie")"
rm -f "/tmp/${trm_domain}.cookie"
else
@ -25,9 +37,9 @@ fi
# post request to subscribe to the portal API
#
if [ -n "${php_token}" ] && [ -n "${location}" ]
if [ -n "${sec_token}" ] && [ -n "${location}" ]
then
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --include --cookie-jar "/tmp/${trm_domain}.cookie" --header "Cookie: ${php_token}" --data "action=subscribe&type=one&connect_policy_accept=false&user_login=&user_password=&user_password_confirm=&email_address=&prefix=&phone=&policy_accept=false&gender=&interests=" --output /dev/null "https://${trm_domain}/portal_api.php"
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --include --cookie-jar "/tmp/${trm_domain}.cookie" --header "Cookie: ${sec_token}" --data "action=subscribe&type=one&connect_policy_accept=false&user_login=&user_password=&user_password_confirm=&email_address=&prefix=&phone=&policy_accept=false&gender=&interests=" --output /dev/null "https://${trm_domain}/portal_api.php"
else
exit 3
fi
@ -47,7 +59,7 @@ fi
#
if [ -n "${login}" ] && [ -n "${password}" ]
then
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --header "Cookie: ${php_token}" --data "action=authenticate&login=${login}&password=${password}&policy_accept=false&from_ajax=true&wispr_mode=false" "https://${trm_domain}/portal_api.php"
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --header "Cookie: ${sec_token}" --data "action=authenticate&login=${login}&password=${password}&policy_accept=false&from_ajax=true&wispr_mode=false" "https://${trm_domain}/portal_api.php"
else
exit 5
fi

+ 23
- 8
net/travelmate/files/generic-user-pass.login View File

@ -1,18 +1,33 @@
#!/bin/sh
# captive portal auto-login script template with credentials as parameters
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
cmd="$(command -v curl)"
url="http://example.com/"
success_string="Thank you!"
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
if [ ! -x "${cmd}" ]
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
exit 1
. "/lib/functions.sh"
fi
response="$("${cmd}" $url -d "username=${1}&password=${2}" \
--header "Content-Type:application/x-www-form-urlencoded" -s)"
trm_domain="example.com"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_fetch="$(command -v curl)"
user="${1}"
password="${2}"
success="Thank you!"
if [ -n "$(printf "%s" "${response}" | grep "${success_string}")" ]
# login with credentials
#
response="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait/6)) --data "username=${user}&password=${password}" --header "Content-Type:application/x-www-form-urlencoded" "http://${trm_domain}")"
if [ -n "$(printf "%s" "${response}" | grep "${success}")" ]
then
exit 0
else


+ 19
- 13
net/travelmate/files/h-hotels.login View File

@ -3,26 +3,32 @@
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
domain="hotspot.t-mobile.net"
cmd="$(command -v curl)"
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
# curl check
#
if [ ! -x "${cmd}" ]
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
exit 1
. "/lib/functions.sh"
fi
trm_domain="hotspot.t-mobile.net"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_fetch="$(command -v curl)"
# initial get request to receive & extract valid security tokens
#
"${cmd}" "https://${domain}/wlan/rest/freeLogin" -c "/tmp/${domain}.cookie" -s -o /dev/null
if [ -r "/tmp/${domain}.cookie" ]
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait/6)) --cookie-jar "/tmp/${trm_domain}.cookie" --output /dev/null "https://${trm_domain}/wlan/rest/freeLogin"
if [ -r "/tmp/${trm_domain}.cookie" ]
then
ses_id="$(awk '/JSESSIONID/{print $7}' "/tmp/${domain}.cookie")"
sec_id="$(awk '/DT_H/{print $7}' "/tmp/${domain}.cookie")"
ses_id="$(awk '/JSESSIONID/{print $7}' "/tmp/${trm_domain}.cookie")"
sec_id="$(awk '/DT_H/{print $7}' "/tmp/${trm_domain}.cookie")"
dev_id="$(sha256sum /etc/config/wireless | awk '{printf "%s",substr($1,1,13)}')"
rm -f "/tmp/${domain}.cookie"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
fi
@ -31,7 +37,7 @@ fi
#
if [ -n "${ses_id}" ] && [ -n "${sec_id}" ] && [ -n "${dev_id}" ]
then
"${cmd}" "https://${domain}/wlan/rest/freeLogin" -H "Referer: https://${domain}/TD/hotspot/H_Hotels/en_GB/index.html" -H "Cookie: JSESSIONID=${ses_id}; DT_DEV_ID=${dev_id}; DT_H=${sec_id}" -H 'Connection: keep-alive' --data "rememberMe=true" -s -o /dev/null
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "https://${trm_domain}/TD/hotspot/H_Hotels/en_GB/index.html" --silent --connect-timeout $((trm_maxwait/6)) --header "Cookie: JSESSIONID=${ses_id}; DT_DEV_ID=${dev_id}; DT_H=${sec_id}" --data "rememberMe=true" --output /dev/null "https://${trm_domain}/wlan/rest/freeLogin"
else
exit 3
fi

+ 3
- 3
net/travelmate/files/travelmate.init View File

@ -1,7 +1,7 @@
#!/bin/sh /etc/rc.common
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2016,2034,2039,2059,2086,2143,2181,2188
START=25
USE_PROCD=1
@ -25,7 +25,7 @@ boot()
start_service()
{
if [ "$("${trm_init}" enabled; printf "%u" ${?})" -eq "0" ]
if [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
then
procd_open_instance "travelmate"
procd_set_param command "${trm_script}" "${@}"
@ -69,7 +69,7 @@ status_service()
rtfile="$(uci_get travelmate global trm_rtfile "/tmp/trm_runtime.json")"
json_load_file "${rtfile}" >/dev/null 2>&1
json_select data >/dev/null 2>&1
if [ ${?} -eq 0 ]
if [ "${?}" = "0" ]
then
printf "%s\n" "::: travelmate runtime information"
json_get_keys keylist


+ 9
- 4
net/travelmate/files/travelmate.mail View File

@ -8,10 +8,15 @@
# Please note: you have to setup the package 'msmtp' before using this script
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
fi
. "/lib/functions.sh"
trm_debug="$(uci_get travelmate global trm_debug "0")"
trm_mailreceiver="$(uci_get travelmate global trm_mailreceiver)"
trm_mailprofile="$(uci_get travelmate global trm_mailprofile "trm_notify")"
@ -38,7 +43,7 @@ then
exit 1
fi
if [ "${trm_debug}" -eq "1" ]
if [ "${trm_debug}" = "1" ]
then
debug="--debug"
fi


+ 41
- 41
net/travelmate/files/travelmate.sh View File

@ -6,12 +6,11 @@
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
# set initial defaults
#
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
trm_ver="2.0.1"
trm_ver="2.0.2"
trm_enabled=0
trm_debug=0
trm_iface=""
@ -100,7 +99,7 @@ f_env()
# check 'enabled' option
#
if [ "${trm_enabled}" -ne "1" ]
if [ "${trm_enabled}" != "1" ]
then
f_log "info" "travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
/etc/init.d/travelmate stop
@ -131,14 +130,14 @@ f_env()
result="$("${trm_wpa}" -v${check} >/dev/null 2>&1; printf "%u" "${?}")"
if [ -z "${trm_wpaflags}" ]
then
if [ "${result}" -eq "0" ]
if [ "${result}" = "0" ]
then
trm_wpaflags="${check}: $(f_char 1)"
else
trm_wpaflags="${check}: $(f_char 0)"
fi
else
if [ "${result}" -eq "0" ]
if [ "${result}" = "0" ]
then
trm_wpaflags="$(f_trim "${trm_wpaflags}, ${check}: $(f_char 1)")"
else
@ -162,7 +161,7 @@ f_env()
#
json_load_file "${trm_rtfile}" >/dev/null 2>&1
json_select data >/dev/null 2>&1
if [ "${?}" -ne "0" ]
if [ "${?}" != "0" ]
then
> "${trm_rtfile}"
json_init
@ -188,7 +187,7 @@ f_char()
{
local result input="${1}"
if [ "${input}" -eq "1" ]
if [ "${input}" = "1" ]
then
result="✔"
else
@ -208,7 +207,7 @@ f_reconf()
do
while [ "$(ubus -S call network.wireless status | jsonfilter -l1 -e "@.${radio}.up")" != "true" ]
do
if [ "${cnt}" -eq "$((trm_maxwait/2))" ]
if [ "${cnt}" = "$((trm_maxwait/2))" ]
then
if [ -x "/etc/init.d/wpad" ]
then
@ -232,14 +231,14 @@ f_vpn()
{
local IFS rc action="${1}"
if [ "${trm_vpn}" -eq "1" ] && [ -x "${trm_vpnpgm}" ]
if [ "${trm_vpn}" = "1" ] && [ -x "${trm_vpnpgm}" ]
then
if [ "${action}" = "disable" ] || { [ "${action}" = "enable" ] && [ ! -f "${trm_vpnfile}" ]; }
then
"${trm_vpnpgm}" "${action}" >/dev/null 2>&1
rc="${?}"
fi
if [ "${action}" = "enable" ] && [ "${rc}" -eq "0" ]
if [ "${action}" = "enable" ] && [ "${rc}" = "0" ]
then
> "${trm_vpnfile}"
elif [ "${action}" = "disable" ] && [ -f "${trm_vpnfile}" ]
@ -256,7 +255,7 @@ f_mac()
{
local result ifname action="${1}" section="${2}"
if [ "${trm_randomize}" -eq "1" ] && [ "${action}" = "set" ]
if [ "${trm_randomize}" = "1" ] && [ "${action}" = "set" ]
then
result="$(hexdump -n6 -ve '/1 "%.02X "' /dev/random 2>/dev/null | \
awk -v local="2,6,A,E" -v seed="$(date +%s)" 'BEGIN{srand(seed)}NR==1{split(local,b,",");seed=int(rand()*4+1);printf "%s%s:%s:%s:%s:%s:%s",substr($1,0,1),b[seed],$2,$3,$4,$5,$6}')"
@ -279,7 +278,7 @@ f_contrack()
{
local uplink_config radio_config essid_config bssid_config expiry action="${1}" radio="${2}" essid="${3}" bssid="${4}" cnt=0
while [ "$(uci_get "travelmate" "@uplink[$cnt]" >/dev/null 2>&1; echo $?)" -eq "0" ]
while [ "$(uci_get "travelmate" "@uplink[$cnt]" >/dev/null 2>&1; echo $?)" = "0" ]
do
radio_config="$(uci_get "travelmate" "@uplink[$cnt]" "device")"
essid_config="$(uci_get "travelmate" "@uplink[$cnt]" "ssid")"
@ -357,7 +356,7 @@ f_uplink()
{
local IFS result t_radio t_essid t_bssid t_option="${1}" w_radio="${2}" w_essid="${3}" w_bssid="${4}" cnt=0
while [ "$(uci_get "travelmate" "@uplink[$cnt]" >/dev/null 2>&1; echo $?)" -eq "0" ]
while [ "$(uci_get "travelmate" "@uplink[$cnt]" >/dev/null 2>&1; echo $?)" = "0" ]
do
t_radio="$(uci_get "travelmate" "@uplink[$cnt]" "device")"
t_essid="$(uci_get "travelmate" "@uplink[$cnt]" "ssid")"
@ -411,7 +410,7 @@ f_addif()
if [ "$(uci -q get "wireless.${name}.ssid")" = "${essid}" ]
then
offset=0
elif [ "${offset}" -ne "0" ]
elif [ "${offset}" != "0" ]
then
offset="$((offset+1))"
fi
@ -420,7 +419,7 @@ f_addif()
}
config_load wireless
if [ "${offset}" -ne "0" ]
if [ "${offset}" != "0" ]
then
uci_cfg="trm_uplink${offset}"
while [ -n "$(uci -q get "wireless.${uci_cfg}")" ]
@ -502,10 +501,10 @@ f_prepif()
if [ "${mode}" = "sta" ]
then
if [ "${status}" = "0" ] || \
{ { [ -z "${disabled}" ] || [ "${disabled}" = "0" ]; } && { [ "${proactive}" -eq "0" ] || [ "${trm_ifstatus}" != "true" ]; } }
{ { [ -z "${disabled}" ] || [ "${disabled}" = "0" ]; } && { [ "${proactive}" = "0" ] || [ "${trm_ifstatus}" != "true" ]; } }
then
uci_set "wireless" "${section}" "disabled" "1"
elif [ "${disabled}" = "0" ] && [ "${trm_ifstatus}" = "true" ] && [ "${proactive}" -eq "1" ]
elif [ "${disabled}" = "0" ] && [ "${trm_ifstatus}" = "true" ] && [ "${proactive}" = "1" ]
then
if [ -z "${trm_activesta}" ]
then
@ -535,7 +534,7 @@ f_net()
err="$(awk 'BEGIN{FS="[()'\'' ]"}{printf "%s %s",$3,$(NF-1)}' "/tmp/trm_fetch.err")"
err_rc="${err% *}"
err_domain="${err#* }"
if [ "${err_rc}" -eq "6" ]
if [ "${err_rc}" = "6" ]
then
if [ -n "${err_domain}" ] && [ "${err_domain}" != "timed" ] && [ "${err_domain}" != "${trm_captiveurl#http*://*}" ]
then
@ -583,7 +582,7 @@ f_check()
enabled="$(f_uplink "enabled" "${sta_radio}" "${sta_essid}" "${sta_bssid}")"
fi
if { [ "${mode}" != "initial" ] && [ "${mode}" != "dev" ] && [ "${status}" = "false" ]; } || \
{ [ "${mode}" = "dev" ] && { [ "${status}" = "false" ] || { [ "${trm_ifstatus}" != "${status}" ] && [ "${enabled}" -eq "0" ]; }; }; }
{ [ "${mode}" = "dev" ] && { [ "${status}" = "false" ] || { [ "${trm_ifstatus}" != "${status}" ] && [ "${enabled}" = "0" ]; }; }; }
then
f_reconf
fi
@ -609,7 +608,7 @@ f_check()
break
else
ifname="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
if [ -n "${ifname}" ] && [ "${enabled}" -eq "1" ]
if [ -n "${ifname}" ] && [ "${enabled}" = "1" ]
then
result="$(f_net)"
trm_ifquality="$(${trm_iwinfo} "${ifname}" info 2>/dev/null | awk -F '[ ]' '/Link Quality:/{split($NF,var0,"/");printf "%i\n",(var0[1]*100/var0[2])}')"
@ -618,17 +617,18 @@ f_check()
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
if [ "${trm_ifstatus}" = "true" ]
then
if [ "${trm_captive}" -eq "1" ]
if [ "${trm_captive}" = "1" ]
then
cp_domain="$(printf "%s" "${result}" | awk -F '['\''| ]' '/^net cp/{printf "%s",$4}')"
if [ -n "${cp_domain}" ] && [ -z "$(uci_get "dhcp" "@dnsmasq[0]" "rebind_domain" | grep -Fo "${cp_domain}")" ]
if [ -x "/etc/init.d/dnsmasq" ] && [ -f "/etc/config/dhcp" ] && \
[ -n "${cp_domain}" ] && [ -z "$(uci_get "dhcp" "@dnsmasq[0]" "rebind_domain" | grep -Fo "${cp_domain}")" ]
then
uci_add_list "dhcp" "@dnsmasq[0]" "rebind_domain" "${cp_domain}"
uci_commit "dhcp"
/etc/init.d/dnsmasq reload
f_log "info" "captive portal domain '${cp_domain}' added to to dhcp rebind whitelist"
fi
if [ -n "${cp_domain}" ] && [ "${trm_captive}" -eq "1" ]
if [ -n "${cp_domain}" ] && [ "${trm_captive}" = "1" ]
then
trm_connection="${result:-"-"}/${trm_ifquality}"
f_jsnup
@ -639,14 +639,14 @@ f_check()
"${login_script}" ${login_script_args} >/dev/null 2>&1
rc="${?}"
f_log "info" "captive portal login '${login_script:0:40} ${login_script_args:0:20}' for '${cp_domain}' has been executed with rc '${rc}'"
if [ "${rc}" -eq "0" ]
if [ "${rc}" = "0" ]
then
result="$(f_net)"
fi
fi
fi
fi
if [ "${trm_netcheck}" -eq "1" ] && [ "${result}" = "net nok" ]
if [ "${trm_netcheck}" = "1" ] && [ "${result}" = "net nok" ]
then
f_log "info" "uplink has no internet (new connection)"
f_vpn "disable"
@ -667,7 +667,7 @@ f_check()
unset trm_connection
trm_ifstatus="${status}"
f_contrack "end" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
elif [ "${trm_netcheck}" -eq "1" ] && [ "${result}" = "net nok" ]
elif [ "${trm_netcheck}" = "1" ] && [ "${result}" = "net nok" ]
then
f_log "info" "uplink has no internet (existing connection)"
f_vpn "disable"
@ -761,11 +761,11 @@ f_jsnup()
then
ntp_done="1"
fi
if [ "${trm_vpn}" -eq "1" ] && [ -f "${trm_vpnfile}" ]
if [ "${trm_vpn}" = "1" ] && [ -f "${trm_vpnfile}" ]
then
vpn_done="1"
fi
if [ "${trm_mail}" -eq "1" ] && [ -f "${trm_mailfile}" ]
if [ "${trm_mail}" = "1" ] && [ -f "${trm_mailfile}" ]
then
mail_done="1"
fi
@ -784,9 +784,9 @@ f_jsnup()
if [ "${status%% (net ok/*}" = "connected" ]
then
f_vpn "enable"
if [ "${trm_mail}" -eq "1" ] && [ -x "${trm_mailpgm}" ] && [ "${ntp_done}" = "1" ] && [ "${mail_done}" = "0" ]
if [ "${trm_mail}" = "1" ] && [ -x "${trm_mailpgm}" ] && [ "${ntp_done}" = "1" ] && [ "${mail_done}" = "0" ]
then
if [ "${trm_vpn}" -eq "0" ] || [ "${vpn_done}" -eq "1" ]
if [ "${trm_vpn}" = "0" ] || [ "${vpn_done}" = "1" ]
then
> "${trm_mailfile}"
"${trm_mailpgm}" >/dev/null 2>&1
@ -804,7 +804,7 @@ f_log()
{
local IFS class="${1}" log_msg="${2}"
if [ -n "${log_msg}" ] && { [ "${class}" != "debug" ] || [ "${trm_debug}" -eq "1" ]; }
if [ -n "${log_msg}" ] && { [ "${class}" != "debug" ] || [ "${trm_debug}" = "1" ]; }
then
if [ -x "${trm_logger}" ]
then
@ -831,11 +831,11 @@ f_main()
f_check "initial" "false"
f_log "debug" "f_main ::: status: ${trm_ifstatus}, proactive: ${trm_proactive}"
if [ "${trm_ifstatus}" != "true" ] || [ "${trm_proactive}" -eq "1" ]
if [ "${trm_ifstatus}" != "true" ] || [ "${trm_proactive}" = "1" ]
then
config_load wireless
config_foreach f_prepif wifi-iface ${trm_proactive}
if [ "${trm_ifstatus}" = "true" ] && [ -n "${trm_activesta}" ] && [ "${trm_proactive}" -eq "1" ]
if [ "${trm_ifstatus}" = "true" ] && [ -n "${trm_activesta}" ] && [ "${trm_proactive}" = "1" ]
then
json_get_var station_id "station_id"
config_radio="${station_id%%/*}"
@ -935,7 +935,7 @@ f_main()
trm_radio="${sta_radio}"
while [ "${retrycnt}" -le "${trm_maxretry}" ]
do
if [ "${trm_randomize}" -eq "1" ]
if [ "${trm_randomize}" = "1" ]
then
sta_mac="$(f_mac "set" "${section}")"
fi
@ -947,7 +947,7 @@ f_main()
rm -f "${trm_mailfile}"
uci_commit "wireless"
f_contrack "start" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
if [ "${trm_randomize}" -eq "0" ]
if [ "${trm_randomize}" = "0" ]
then
sta_mac="$(f_mac "get" "${section}")"
fi
@ -956,7 +956,7 @@ f_main()
else
uci -q revert "wireless"
f_check "rev" "false"
if [ "${retrycnt}" -eq "${trm_maxretry}" ]
if [ "${retrycnt}" = "${trm_maxretry}" ]
then
f_contrack "disabled" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
f_log "info" "uplink has been disabled '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${retrycnt}/${trm_maxretry})"
@ -969,7 +969,7 @@ f_main()
retrycnt="$((retrycnt+1))"
sleep "$((trm_maxwait/6))"
done
elif [ "${trm_autoadd}" -eq "1" ] && [ "${scan_open}" = "+" ] && [ "${scan_essid}" != "unknown" ]
elif [ "${trm_autoadd}" = "1" ] && [ "${scan_open}" = "+" ] && [ "${scan_essid}" != "unknown" ]
then
scan_essid="${scan_essid%?}"
scan_essid="${scan_essid:1}"
@ -1013,17 +1013,17 @@ do
rc=0
while true
do
if [ "${rc}" -eq "0" ]
if [ "${rc}" = "0" ]
then
f_check "initial" "false"
fi
sleep "${trm_timeout}" 0
rc=${?}
if [ "${rc}" -ne "0" ]
if [ "${rc}" != "0" ]
then
f_check "initial" "false"
fi
if [ "${rc}" -eq "0" ] || { [ "${rc}" -ne "0" ] && [ "${trm_ifstatus}" = "false" ]; }
if [ "${rc}" = "0" ] || { [ "${rc}" != "0" ] && [ "${trm_ifstatus}" = "false" ]; }
then
break
fi


+ 12
- 5
net/travelmate/files/travelmate.vpn View File

@ -8,10 +8,15 @@
# Please note: you have to setup the package 'wireguard' or 'openvpn' before using this script
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
fi
. "/lib/functions.sh"
vpn_action="${1}"
trm_vpnservice="$(uci_get travelmate global trm_vpnservice)"
trm_vpniface="$(uci_get travelmate global trm_vpniface)"
@ -60,7 +65,8 @@ then
vpn_status="$(ubus -S call network.interface."${trm_vpniface}" status 2>/dev/null | jsonfilter -l1 -e '@.up')"
if [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]
then
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 2>&1)" ]
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 2>&1)" ] && \
[ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ]
then
"${trm_iptables}" "-w $((trm_maxwait/6))" -I ${trm_iptrule_drop} 2>&1
f_log "info" "lan forward blocked for device '${trm_landevice}'"
@ -68,7 +74,8 @@ then
fi
if [ "${vpn_action}" = "disable" ] && [ "${status%% (net cp *}" = "connected" ]
then
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ]
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ] && \
[ -z "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 2>&1)" ]
then
"${trm_iptables}" "-w $((trm_maxwait/6))" -I ${trm_iptrule_accept} 2>&1
f_log "info" "lan forward on ports 80/443 freed for device '${trm_landevice}'"


+ 1
- 1
net/travelmate/files/travelmate_ntp.hotplug View File

@ -23,7 +23,7 @@ f_log()
}
if [ "${ACTION}" = "stratum" ] && [ ! -f "${trm_ntpfile}" ] && \
[ "$("${trm_init}" enabled; printf "%u" ${?})" -eq "0" ]
[ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
then
> "${trm_ntpfile}"
f_log "info" "get ntp time sync"


+ 12
- 0
net/travelmate/files/wifionice.login View File

@ -3,6 +3,18 @@
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
fi
trm_domain="www.wifionice.de"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"


Loading…
Cancel
Save