* support all kinds of uplinks, incl. hidden and enterprise uplinks
* continuously checks the existing uplink connection (quality), e.g. for conditional uplink (dis-) connections
* captive portal detection with internet online check and a 'heartbeat' function to keep the uplink connection up & running
+* captive portal auto-login hook (configured via uci/LuCI), you could reference an external script for captive portal auto-logins (see example below)
* proactively scan and switch to a higher prioritized uplink, despite of an already existing connection
* support devices with multiple radios in any order
* procd init and hotplug support
* optional: the LuCI frontend shows the WiFi QR codes from all configured Access Points. It allows you to connect your Android or iOS devices to your router’s WiFi using the QR code
## Prerequisites
-* [OpenWrt](https://openwrt.org), tested with the stable release series (18.06.x) and with the latest OpenWrt snapshot
-* iwinfo for wlan scanning, uclient-fetch for captive portal detection
+* [OpenWrt](https://openwrt.org), tested with the stable release series (19.07.x) and with the latest OpenWrt snapshot
+* iwinfo for wlan scanning, uclient-fetch for captive portal detection, dnsmasq as dns backend
* optional: qrencode 4.x for QR code support
* optional: wpad (the full version, not wpad-mini) to use Enterprise WiFi
+* optional: curl to use external scripts for captive portal auto-logins
## Installation & Usage
* download the package [here](https://downloads.openwrt.org/snapshots/packages/x86_64/packages)
* trm\_maxretry => how many times should travelmate try to connect to an uplink (int/default: '3', valid range: 1-10)
* trm\_timeout => overall retry timeout in seconds (int/default: '60', valid range: 30-300)
* trm\_radio => limit travelmate to a single radio (e.g. 'radio1') or change the overall scanning priority (e.g. 'radio1 radio2 radio0') (default: not set, use all radios 0-n)
- * trm\_iface => main uplink / procd trigger network interface (default: trm_wwan)
+ * trm\_iface => uplink / procd trigger network interface (default: trm_wwan)
* trm\_triggerdelay => additional trigger delay in seconds before travelmate processing begins (int/default: '2')
+## Captive Portal auto-logins
+For automated captive portal logins you could reference external shell scripts. All login scripts should be executable and located in '/etc/travelmate' with the extension '.login'. The provided 'wifionice.login' script example requires curl and automates the login to german ICE hotspots, it also explains the principle approach to extract runtime data like security tokens for a succesful login. Hopefully more scripts for different captive portals will be provided by the community ...
+
+A typical/succesful captive portal login looks like this:
+<pre><code>
+[...]
+Mon Aug 5 10:15:48 2019 user.info travelmate-1.4.10[1481]: travelmate instance started ::: action: start, pid: 1481
+Mon Aug 5 10:16:17 2019 user.info travelmate-1.4.10[1481]: captive portal login '/etc/travelmate/wifionice.login' for 'www.wifionice.de' has been executed with rc '0'
+Mon Aug 5 10:16:23 2019 user.info travelmate-1.4.10[1481]: connected to uplink 'radio1/WIFIonICE/-' (1/5, GL.iNet GL-AR750S, OpenWrt SNAPSHOT r10644-cb49e46a8a)
+[...]
+</code></pre>
+
## Runtime information
**receive travelmate runtime information:**
<pre><code>
~# /etc/init.d/travelmate status
::: travelmate runtime information
- + travelmate_status : connected (net ok/78)
- + travelmate_version : 1.2.3
- + station_id : radio1/blackhole/01:02:03:04:05:06
+ + travelmate_status : connected (net ok/100)
+ + travelmate_version : 1.4.10
+ + station_id : radio1/blackhole/-
+ station_interface : trm_wwan
+ faulty_stations :
- + last_rundate : 07.09.2018 17:22:37
- + system : TP-LINK RE450, OpenWrt SNAPSHOT r8018-42f158314e
+ + last_rundate : 2019.08.03-20:37:19
+ + system : GL.iNet GL-AR750S, OpenWrt SNAPSHOT r10644-cb49e46a8a
</code></pre>
+To debug travelmate runtime problems, please always enable the 'trm\_debug' flag, restart travelmate and scan the system log (_logread -e "travelmate"_)
+
## Manual Setup
**1. configure the travelmate wwan interface in /etc/config/network:**
<pre><code>
#
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-trm_ver="1.4.9"
+trm_ver="1.4.10"
trm_sysver="unknown"
trm_enabled=0
trm_debug=0
trm_sysver="${sys_model}, ${sys_desc}"
fi
- # get eap capabilities and rebind protection setting
+ # get eap capabilities
#
trm_eap="$("${trm_wpa}" -veap >/dev/null 2>&1; printf "%u" ${?})"
- trm_rebind="$(uci_get dhcp "@dnsmasq[0]" rebind_protection)"
# load config and check 'enabled' option
#
fi
fi
fi
- f_log "debug" "f_prep ::: config: ${config}, mode: ${mode}, network: ${network}, radio: ${radio}, trm_radio: ${trm_radio:-"-"}, trm_active_sta: ${trm_active_sta:-"-"}, proactive: ${proactive}, trm_eap: ${trm_eap:-"-"}, trm_rebind: ${trm_rebind:-"-"}, disabled: ${disabled}"
+ f_log "debug" "f_prep ::: config: ${config}, mode: ${mode}, network: ${network}, radio: ${radio}, trm_radio: ${trm_radio:-"-"}, trm_active_sta: ${trm_active_sta:-"-"}, proactive: ${proactive}, trm_eap: ${trm_eap:-"-"}, disabled: ${disabled}"
}
# check interface status
#
f_check()
{
- local IFS ifname radio dev_status last_status config sta_essid sta_bssid result cp_domain wait mode="${1}" status="${2:-"false"}"
+ local IFS ifname radio dev_status config sta_essid sta_bssid result uci_essid uci_bssid login_command bg_pid wait_time mode="${1}" status="${2:-"false"}" cp_domain="${3:-"false"}"
if [ "${mode}" != "initial" ] && [ "${status}" = "false" ]
then
ubus call network reload
- wait=$((trm_maxwait/6))
- sleep ${wait}
+ wait_time=$((trm_maxwait/6))
+ sleep ${wait_time}
fi
- wait=1
- while [ "${wait}" -le "${trm_maxwait}" ]
+ wait_time=1
+ while [ "${wait_time}" -le "${trm_maxwait}" ]
do
dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
if [ -n "${dev_status}" ]
trm_devlist="$(f_trim "${trm_devlist} ${radio}")"
fi
done
- if [ "${trm_devlist}" = "${trm_radiolist}" ] || [ "${wait}" -eq "${trm_maxwait}" ]
+ if [ "${trm_devlist}" = "${trm_radiolist}" ] || [ "${wait_time}" -eq "${trm_maxwait}" ]
then
ifname="${trm_devlist}"
break
if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ]
then
result="$(${trm_fetch} --timeout=$((trm_maxwait/6)) "${trm_captiveurl}" -O /dev/null 2>&1 | \
- awk '/^Failed to redirect|^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|^Connection error/{printf "%s" "net nok";exit}')"
+ awk '/^Failed to redirect|^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|Connection error/{printf "%s" "net nok";exit}')"
+ if [ "${cp_domain}" = "true" ]
+ then
+ cp_domain="$(printf "%s" "${result}" | awk -F "[\\'| ]" '/^net cp/{printf "%s" $4}')"
+ uci_essid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].config.ssid')"
+ uci_essid="$(printf "%s" "${uci_essid//[^[:alnum:]_]/_}" | awk '{print tolower($1)}')"
+ uci_bssid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].config.bssid')"
+ uci_bssid="${uci_bssid//[^[:alnum:]_]/_}"
+ fi
fi
- if [ "${trm_ifquality}" -ge "${trm_minquality}" ] && [ "${result%/*}" != "net nok" ]
+ if [ "${trm_ifquality}" -ge "${trm_minquality}" ] && [ "${result}" != "net nok" ]
then
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
if [ "${trm_ifstatus}" = "true" ]
then
- if [ "${mode}" = "sta" ] && [ "${trm_captive}" -eq 1 ] && [ "${trm_rebind:-0}" -eq 1 ] && [ -x "/etc/init.d/dnsmasq" ]
+ if [ "${mode}" = "sta" ] && [ "${trm_captive}" -eq 1 ]
then
while true
do
result="$(${trm_fetch} --timeout=$((trm_maxwait/6)) "${trm_captiveurl}" -O /dev/null 2>&1 | \
- awk '/^Failed to redirect|^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|^Connection error/{printf "%s" "net nok";exit}')"
+ awk '/^Failed to redirect|^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|Connection error/{printf "%s" "net nok";exit}')"
cp_domain="$(printf "%s" "${result}" | awk -F "[\\'| ]" '/^net cp/{printf "%s" $4}')"
- if [ "${trm_netcheck}" -eq 1 ] && [ "${result%/*}" = "net nok" ]
+ uci_essid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].config.ssid')"
+ uci_essid="$(printf "%s" "${uci_essid//[^[:alnum:]_]/_}" | awk '{print tolower($1)}')"
+ uci_bssid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].config.bssid')"
+ uci_bssid="${uci_bssid//[^[:alnum:]_]/_}"
+ if [ "${trm_netcheck}" -eq 1 ] && [ "${result}" = "net nok" ]
then
trm_ifstatus="${status}"
f_jsnup
break
fi
uci -q add_list dhcp.@dnsmasq[0].rebind_domain="${cp_domain}"
- f_log "info" "captive portal domain '${cp_domain}' added to rebind whitelist"
+ f_log "info" "captive portal domain '${cp_domain}' added to to dhcp rebind whitelist"
+ if [ -z "$(uci_get travelmate "${uci_essid}${uci_bssid}")" ]
+ then
+ uci_add travelmate "login" "${uci_essid}${uci_bssid}"
+ uci_set travelmate "${uci_essid}${uci_bssid}" "command" "none"
+ f_log "info" "captive portal login section '${uci_essid}${uci_bssid}' added to travelmate config section"
+ fi
done
if [ -n "$(uci -q changes dhcp)" ]
then
uci_commit dhcp
/etc/init.d/dnsmasq reload
fi
+ if [ -n "$(uci -q changes travelmate)" ]
+ then
+ uci_commit travelmate
+ fi
+ fi
+ if [ "${cp_domain}" != "false" ] && [ -n "${uci_essid}" ] && [ "${trm_captive}" -eq 1 ]
+ then
+ trm_connection="${result:-"-"}/${trm_ifquality}"
+ f_jsnup
+ login_command="$(uci_get travelmate "${uci_essid}${uci_bssid}" command)"
+ if [ -x "${login_command}" ]
+ then
+ "${login_command}" >/dev/null 2>&1
+ rc=${?}
+ f_log "info" "captive portal login '${login_command:0:40}' for '${cp_domain}' has been executed with rc '${rc}'"
+ if [ "${rc}" -eq 0 ]
+ then
+ result="$(${trm_fetch} --timeout=$((trm_maxwait/6)) "${trm_captiveurl}" -O /dev/null 2>&1 | \
+ awk '/^Failed to redirect|^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|Connection error/{printf "%s" "net nok";exit}')"
+ fi
+ fi
fi
trm_connection="${result:-"-"}/${trm_ifquality}"
f_jsnup
sta_bssid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].*.bssid')"
if [ "${trm_ifquality}" -lt "${trm_minquality}" ]
then
+ unset trm_connection
+ trm_ifstatus="${status}"
f_log "info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' is out of range (${trm_ifquality}/${trm_minquality})"
- elif [ "${trm_netcheck}" -eq 1 ] && [ "${result%/*}" = "net nok" ]
+ elif [ "${trm_netcheck}" -eq 1 ] && [ "${result}" = "net nok" ]
then
+ unset trm_connection
+ trm_ifstatus="${status}"
f_log "info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' has no internet (${result})"
fi
- unset trm_connection
- trm_ifstatus="${status}"
f_jsnup
break
elif [ "${mode}" = "initial" ]
fi
fi
fi
- wait=$((wait+1))
+ wait_time=$((wait_time+1))
sleep 1
done
- f_log "debug" "f_check::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, connection: ${trm_connection:-"-"}, wait: ${wait}, max_wait: ${trm_maxwait}, min_quality: ${trm_minquality}, captive: ${trm_captive}, netcheck: ${trm_netcheck}"
+ f_log "debug" "f_check::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, connection: ${trm_connection:-"-"}, wait: ${wait_time}, max_wait: ${trm_maxwait}, min_quality: ${trm_minquality}, captive: ${trm_captive}, netcheck: ${trm_netcheck}"
}
# update runtime information
local IFS cnt dev config spec scan_list scan_essid scan_bssid scan_quality faulty_list
local station_id sta sta_essid sta_bssid sta_radio sta_iface active_essid active_bssid active_radio
- f_check "initial"
+ f_check "initial" "false" "true"
f_log "debug" "f_main ::: status: ${trm_ifstatus}, proactive: ${trm_proactive}"
if [ "${trm_ifstatus}" != "true" ] || [ "${trm_proactive}" -eq 1 ]
then