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>
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
# 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
#
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
# 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")"
#
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
# 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
#
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
#!/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
# 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
#
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
#!/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
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}" "${@}"
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
# 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")"
exit 1
fi
-if [ "${trm_debug}" -eq "1" ]
+if [ "${trm_debug}" = "1" ]
then
debug="--debug"
fi
# 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=""
# 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
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
#
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
{
local result input="${1}"
- if [ "${input}" -eq "1" ]
+ if [ "${input}" = "1" ]
then
result="✔"
else
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
{
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}" ]
{
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}')"
{
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")"
{
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")"
if [ "$(uci -q get "wireless.${name}.ssid")" = "${essid}" ]
then
offset=0
- elif [ "${offset}" -ne "0" ]
+ elif [ "${offset}" != "0" ]
then
offset="$((offset+1))"
fi
}
config_load wireless
- if [ "${offset}" -ne "0" ]
+ if [ "${offset}" != "0" ]
then
uci_cfg="trm_uplink${offset}"
while [ -n "$(uci -q get "wireless.${uci_cfg}")" ]
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
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
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
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])}')"
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
"${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"
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"
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
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
{
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
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%%/*}"
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
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
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})"
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}"
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
# 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)"
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}'"
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}'"
}
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"
# 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")"