travelmate: update 1.2.3
* remove needless third status "not connected", use only "running / not connected" and "connected" * change indentation from spaces to tabs (saves 4kb) * small fixes * update readme Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
3b6e346a4c
commit
1d69658670
4 changed files with 364 additions and 374 deletions
|
@ -6,7 +6,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=travelmate
|
PKG_NAME:=travelmate
|
||||||
PKG_VERSION:=1.2.2
|
PKG_VERSION:=1.2.3
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_LICENSE:=GPL-3.0+
|
PKG_LICENSE:=GPL-3.0+
|
||||||
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
||||||
|
|
|
@ -20,7 +20,7 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
|
||||||
* 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
|
* 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
|
## Prerequisites
|
||||||
* [OpenWrt](https://openwrt.org), tested with the stable release series (17.01.x) and with the latest OpenWrt snapshot
|
* [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
|
* iwinfo for wlan scanning, uclient-fetch for captive portal detection
|
||||||
* optional: qrencode 4.x for QR code support
|
* optional: qrencode 4.x for QR code support
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a
|
||||||
~# /etc/init.d/travelmate status
|
~# /etc/init.d/travelmate status
|
||||||
::: travelmate runtime information
|
::: travelmate runtime information
|
||||||
+ travelmate_status : connected (net ok/78)
|
+ travelmate_status : connected (net ok/78)
|
||||||
+ travelmate_version : 1.2.1
|
+ travelmate_version : 1.2.3
|
||||||
+ station_id : radio1/blackhole/01:02:03:04:05:06
|
+ station_id : radio1/blackhole/01:02:03:04:05:06
|
||||||
+ station_interface : trm_wwan
|
+ station_interface : trm_wwan
|
||||||
+ faulty_stations :
|
+ faulty_stations :
|
||||||
+ last_rundate : 28.07.2018 21:17:45
|
+ last_rundate : 07.09.2018 17:22:37
|
||||||
+ system : TP-LINK RE450, OpenWrt SNAPSHOT r7540+5-20c4819c7b
|
+ system : TP-LINK RE450, OpenWrt SNAPSHOT r8018-42f158314e
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
## Manual Setup
|
## Manual Setup
|
||||||
|
@ -127,6 +127,8 @@ edit /etc/config/travelmate and set 'trm_enabled' to '1'
|
||||||
**A:** Travelmate tries n times (default 3) to connect, then the respective uplink will be marked as "faulty" in the JSON runtime file and hereafter ignored. To reset the JSON runtime file, simply restart travelmate.
|
**A:** Travelmate tries n times (default 3) to connect, then the respective uplink will be marked as "faulty" in the JSON runtime file and hereafter ignored. To reset the JSON runtime file, simply restart travelmate.
|
||||||
**Q:** How to connect to hidden uplinks?
|
**Q:** How to connect to hidden uplinks?
|
||||||
**A:** See 'example\_hidden' STA configuration above, option 'SSID' and 'BSSID' must be specified for successful connections.
|
**A:** See 'example\_hidden' STA configuration above, option 'SSID' and 'BSSID' must be specified for successful connections.
|
||||||
|
**Q:** Any recommendations regarding suitable DNS settings to easily connect to captive portals?
|
||||||
|
**A:** Use a simple DNS forwarder like dnsmasq and disable the option 'rebind_protection'.
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
Please join the travelmate discussion in this [forum thread](https://forum.lede-project.org/t/travelmate-support-thread/5155) or contact me by [mail](mailto:dev@brenken.org)
|
Please join the travelmate discussion in this [forum thread](https://forum.lede-project.org/t/travelmate-support-thread/5155) or contact me by [mail](mailto:dev@brenken.org)
|
||||||
|
|
|
@ -12,62 +12,61 @@ trm_pidfile="/var/run/travelmate.pid"
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
{
|
{
|
||||||
ubus -t 30 wait_for network.interface network.wireless 2>/dev/null
|
ubus -t 30 wait_for network.interface network.wireless 2>/dev/null
|
||||||
rc_procd start_service
|
rc_procd start_service
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service()
|
start_service()
|
||||||
{
|
{
|
||||||
if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
|
if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
|
||||||
then
|
then
|
||||||
procd_open_instance "travelmate"
|
procd_open_instance "travelmate"
|
||||||
procd_set_param command "${trm_script}" "${@}"
|
procd_set_param command "${trm_script}" "${@}"
|
||||||
procd_set_param pidfile "${trm_pidfile}"
|
procd_set_param pidfile "${trm_pidfile}"
|
||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
procd_set_param stderr 1
|
procd_set_param stderr 1
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_service()
|
reload_service()
|
||||||
{
|
{
|
||||||
[ -s "${trm_pidfile}" ] && return 1
|
[ -s "${trm_pidfile}" ] && return 1
|
||||||
rc_procd start_service
|
rc_procd start_service
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service()
|
stop_service()
|
||||||
{
|
{
|
||||||
rc_procd "${trm_script}" stop
|
rc_procd "${trm_script}" stop
|
||||||
rc_procd start_service
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status()
|
status()
|
||||||
{
|
{
|
||||||
local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
|
local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
|
||||||
|
|
||||||
rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
|
rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
|
||||||
if [ -s "${rtfile}" ]
|
json_load_file "${rtfile}" >/dev/null 2>&1
|
||||||
then
|
json_select data >/dev/null 2>&1
|
||||||
printf "%s\n" "::: travelmate runtime information"
|
if [ ${?} -eq 0 ]
|
||||||
json_load "$(cat "${rtfile}" 2>/dev/null)"
|
then
|
||||||
json_select data
|
printf "%s\n" "::: travelmate runtime information"
|
||||||
json_get_keys keylist
|
json_get_keys keylist
|
||||||
for key in ${keylist}
|
for key in ${keylist}
|
||||||
do
|
do
|
||||||
json_get_var value "${key}"
|
json_get_var value "${key}"
|
||||||
printf " + %-18s : %s\n" "${key}" "${value}"
|
printf " + %-18s : %s\n" "${key}" "${value}"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
printf "%s\n" "::: no travelmate runtime information available"
|
printf "%s\n" "::: no travelmate runtime information available"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
service_triggers()
|
service_triggers()
|
||||||
{
|
{
|
||||||
local trigger="$(uci_get travelmate global trm_iface)"
|
local trigger="$(uci_get travelmate global trm_iface)"
|
||||||
local delay="$(uci_get travelmate global trm_triggerdelay)"
|
local delay="$(uci_get travelmate global trm_triggerdelay)"
|
||||||
|
|
||||||
PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
|
PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
|
||||||
procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" reload
|
procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" reload
|
||||||
procd_add_reload_trigger "travelmate"
|
procd_add_reload_trigger "travelmate"
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
trm_ver="1.2.2"
|
trm_ver="1.2.3"
|
||||||
trm_sysver="unknown"
|
trm_sysver="unknown"
|
||||||
trm_enabled=0
|
trm_enabled=0
|
||||||
trm_debug=0
|
trm_debug=0
|
||||||
|
@ -33,396 +33,385 @@ trm_pidfile="/var/run/travelmate.pid"
|
||||||
#
|
#
|
||||||
f_envload()
|
f_envload()
|
||||||
{
|
{
|
||||||
local sys_call sys_desc sys_model sys_ver
|
local sys_call sys_desc sys_model sys_ver
|
||||||
|
|
||||||
# get system information
|
# get system information
|
||||||
#
|
#
|
||||||
sys_call="$(ubus -S call system board 2>/dev/null)"
|
sys_call="$(ubus -S call system board 2>/dev/null)"
|
||||||
if [ -n "${sys_call}" ]
|
if [ -n "${sys_call}" ]
|
||||||
then
|
then
|
||||||
sys_desc="$(printf '%s' "${sys_call}" | jsonfilter -e '@.release.description')"
|
sys_desc="$(printf '%s' "${sys_call}" | jsonfilter -e '@.release.description')"
|
||||||
sys_model="$(printf '%s' "${sys_call}" | jsonfilter -e '@.model')"
|
sys_model="$(printf '%s' "${sys_call}" | jsonfilter -e '@.model')"
|
||||||
sys_ver="$(cat /etc/turris-version 2>/dev/null)"
|
sys_ver="$(cat /etc/turris-version 2>/dev/null)"
|
||||||
if [ -n "${sys_ver}" ]
|
if [ -n "${sys_ver}" ]
|
||||||
then
|
then
|
||||||
sys_desc="${sys_desc}/${sys_ver}"
|
sys_desc="${sys_desc}/${sys_ver}"
|
||||||
fi
|
fi
|
||||||
trm_sysver="${sys_model}, ${sys_desc}"
|
trm_sysver="${sys_model}, ${sys_desc}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# (re-)initialize global list variables
|
# (re-)initialize global list variables
|
||||||
#
|
#
|
||||||
unset trm_devlist trm_stalist trm_radiolist
|
unset trm_devlist trm_stalist trm_radiolist
|
||||||
|
|
||||||
# load config and check 'enabled' option
|
# load config and check 'enabled' option
|
||||||
#
|
#
|
||||||
option_cb()
|
option_cb()
|
||||||
{
|
{
|
||||||
local option="${1}"
|
local option="${1}"
|
||||||
local value="${2}"
|
local value="${2}"
|
||||||
eval "${option}=\"${value}\""
|
eval "${option}=\"${value}\""
|
||||||
}
|
}
|
||||||
config_load travelmate
|
config_load travelmate
|
||||||
|
|
||||||
if [ ${trm_enabled} -ne 1 ]
|
if [ ${trm_enabled} -ne 1 ]
|
||||||
then
|
then
|
||||||
f_log "info" "travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
|
f_log "info" "travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# validate input ranges
|
# validate input ranges
|
||||||
#
|
#
|
||||||
if [ ${trm_minquality} -lt 20 ] || [ ${trm_minquality} -gt 80 ]
|
if [ ${trm_minquality} -lt 20 ] || [ ${trm_minquality} -gt 80 ]
|
||||||
then
|
then
|
||||||
trm_minquality=35
|
trm_minquality=35
|
||||||
fi
|
fi
|
||||||
if [ ${trm_maxretry} -lt 1 ] || [ ${trm_maxretry} -gt 10 ]
|
if [ ${trm_maxretry} -lt 1 ] || [ ${trm_maxretry} -gt 10 ]
|
||||||
then
|
then
|
||||||
trm_maxretry=3
|
trm_maxretry=3
|
||||||
fi
|
fi
|
||||||
if [ ${trm_maxwait} -lt 20 ] || [ ${trm_maxwait} -gt 40 ] || [ ${trm_maxwait} -ge ${trm_timeout} ]
|
if [ ${trm_maxwait} -lt 20 ] || [ ${trm_maxwait} -gt 40 ] || [ ${trm_maxwait} -ge ${trm_timeout} ]
|
||||||
then
|
then
|
||||||
trm_maxwait=30
|
trm_maxwait=30
|
||||||
fi
|
fi
|
||||||
if [ ${trm_timeout} -lt 30 ] || [ ${trm_timeout} -gt 300 ] || [ ${trm_timeout} -le ${trm_maxwait} ]
|
if [ ${trm_timeout} -lt 30 ] || [ ${trm_timeout} -gt 300 ] || [ ${trm_timeout} -le ${trm_maxwait} ]
|
||||||
then
|
then
|
||||||
trm_timeout=60
|
trm_timeout=60
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# gather radio information & bring down all STA interfaces
|
# gather radio information & bring down all STA interfaces
|
||||||
#
|
#
|
||||||
f_prep()
|
f_prep()
|
||||||
{
|
{
|
||||||
local eap_rc=0 config="${1}"
|
local eap_rc=0 config="${1}"
|
||||||
local mode="$(uci_get wireless "${config}" mode)"
|
local mode="$(uci_get wireless "${config}" mode)"
|
||||||
local network="$(uci_get wireless "${config}" network)"
|
local network="$(uci_get wireless "${config}" network)"
|
||||||
local radio="$(uci_get wireless "${config}" device)"
|
local radio="$(uci_get wireless "${config}" device)"
|
||||||
local disabled="$(uci_get wireless "${config}" disabled)"
|
local disabled="$(uci_get wireless "${config}" disabled)"
|
||||||
local eaptype="$(uci_get wireless "${config}" eap_type)"
|
local eaptype="$(uci_get wireless "${config}" eap_type)"
|
||||||
|
|
||||||
if ([ -z "${trm_radio}" ] || [ "${trm_radio}" = "${radio}" ]) && \
|
if ([ -z "${trm_radio}" ] || [ "${trm_radio}" = "${radio}" ]) && \
|
||||||
[ -z "$(printf "%s" "${trm_radiolist}" | grep -Fo " ${radio}")" ]
|
[ -z "$(printf "%s" "${trm_radiolist}" | grep -Fo " ${radio}")" ]
|
||||||
then
|
then
|
||||||
trm_radiolist="${trm_radiolist} ${radio}"
|
trm_radiolist="${trm_radiolist} ${radio}"
|
||||||
fi
|
fi
|
||||||
if [ "${mode}" = "sta" ] && [ "${network}" = "${trm_iface}" ]
|
if [ "${mode}" = "sta" ] && [ "${network}" = "${trm_iface}" ]
|
||||||
then
|
then
|
||||||
if [ -z "${disabled}" ] || [ "${disabled}" = "0" ]
|
if [ -z "${disabled}" ] || [ "${disabled}" = "0" ]
|
||||||
then
|
then
|
||||||
uci_set wireless "${config}" disabled 1
|
uci_set wireless "${config}" disabled 1
|
||||||
fi
|
fi
|
||||||
if [ -n "${eaptype}" ]
|
if [ -n "${eaptype}" ]
|
||||||
then
|
then
|
||||||
eap_rc="$("${trm_wpa}" -veap >/dev/null 2>&1; printf "%u" ${?})"
|
eap_rc="$("${trm_wpa}" -veap >/dev/null 2>&1; printf "%u" ${?})"
|
||||||
fi
|
fi
|
||||||
if [ -z "${eaptype}" ] || [ ${eap_rc} -eq 0 ]
|
if [ -z "${eaptype}" ] || [ ${eap_rc} -eq 0 ]
|
||||||
then
|
then
|
||||||
trm_stalist="${trm_stalist} ${config}_${radio}"
|
trm_stalist="${trm_stalist} ${config}_${radio}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
f_log "debug" "f_prep ::: config: ${config}, mode: ${mode}, network: ${network}, eap_rc: ${eap_rc}, radio: ${radio}, trm_radio: ${trm_radio:-"-"}, disabled: ${disabled}"
|
f_log "debug" "f_prep ::: config: ${config}, mode: ${mode}, network: ${network}, eap_rc: ${eap_rc}, radio: ${radio}, trm_radio: ${trm_radio:-"-"}, disabled: ${disabled}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# check interface status
|
# check interface status
|
||||||
#
|
#
|
||||||
f_check()
|
f_check()
|
||||||
{
|
{
|
||||||
local IFS ifname radio dev_status config sta_essid sta_bssid result wait=1 mode="${1}" status="${2:-"false"}"
|
local IFS ifname radio dev_status config sta_essid sta_bssid result wait=1 mode="${1}" status="${2:-"false"}"
|
||||||
|
|
||||||
trm_ifquality=0
|
trm_ifquality=0
|
||||||
trm_ifstatus="false"
|
trm_ifstatus="false"
|
||||||
if [ "${mode}" != "initial" ]
|
if [ "${mode}" != "initial" ]
|
||||||
then
|
then
|
||||||
ubus call network reload
|
ubus call network reload
|
||||||
fi
|
fi
|
||||||
while [ ${wait} -le ${trm_maxwait} ]
|
while [ ${wait} -le ${trm_maxwait} ]
|
||||||
do
|
do
|
||||||
dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
|
dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
|
||||||
if [ -n "${dev_status}" ]
|
if [ -n "${dev_status}" ]
|
||||||
then
|
then
|
||||||
if [ "${mode}" = "dev" ]
|
if [ "${mode}" = "dev" ]
|
||||||
then
|
then
|
||||||
if [ "${trm_ifstatus}" != "${status}" ]
|
if [ "${trm_ifstatus}" != "${status}" ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="${status}"
|
trm_ifstatus="${status}"
|
||||||
f_jsnup
|
f_jsnup
|
||||||
fi
|
fi
|
||||||
for radio in ${trm_radiolist}
|
for radio in ${trm_radiolist}
|
||||||
do
|
do
|
||||||
result="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e "@.${radio}.up")"
|
result="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e "@.${radio}.up")"
|
||||||
if [ "${result}" = "true" ] && [ -z "$(printf "%s" "${trm_devlist}" | grep -Fo " ${radio}")" ]
|
if [ "${result}" = "true" ] && [ -z "$(printf "%s" "${trm_devlist}" | grep -Fo " ${radio}")" ]
|
||||||
then
|
then
|
||||||
trm_devlist="${trm_devlist} ${radio}"
|
trm_devlist="${trm_devlist} ${radio}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "${trm_devlist}" = "${trm_radiolist}" ] || [ ${wait} -eq ${trm_maxwait} ]
|
if [ "${trm_devlist}" = "${trm_radiolist}" ] || [ ${wait} -eq ${trm_maxwait} ]
|
||||||
then
|
then
|
||||||
ifname="${trm_devlist}"
|
ifname="${trm_devlist}"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
unset trm_devlist
|
unset trm_devlist
|
||||||
fi
|
fi
|
||||||
elif [ "${mode}" = "rev" ]
|
elif [ "${mode}" = "rev" ]
|
||||||
then
|
then
|
||||||
wait=$(( ${trm_maxwait} / 3 ))
|
wait=$(( ${trm_maxwait} / 3 ))
|
||||||
sleep ${wait}
|
sleep ${wait}
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
ifname="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
|
ifname="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
|
||||||
if [ -n "${ifname}" ]
|
if [ -n "${ifname}" ]
|
||||||
then
|
then
|
||||||
trm_ifquality="$(${trm_iwinfo} ${ifname} info 2>/dev/null | awk -F "[\/| ]" '/Link Quality:/{printf "%i\n", (100 / $NF * $(NF-1)) }')"
|
trm_ifquality="$(${trm_iwinfo} ${ifname} info 2>/dev/null | awk -F "[\/| ]" '/Link Quality:/{printf "%i\n", (100 / $NF * $(NF-1)) }')"
|
||||||
if [ ${trm_ifquality} -ge ${trm_minquality} ]
|
if [ ${trm_ifquality} -ge ${trm_minquality} ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
|
trm_ifstatus="$(ubus -S call network.interface dump 2>/dev/null | jsonfilter -l1 -e "@.interface[@.device=\"${ifname}\"].up")"
|
||||||
elif [ "${mode}" = "initial" ] && [ ${trm_ifquality} -lt ${trm_minquality} ]
|
elif [ "${mode}" = "initial" ] && [ ${trm_ifquality} -lt ${trm_minquality} ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="${status}"
|
trm_ifstatus="${status}"
|
||||||
sta_essid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].*.ssid')"
|
sta_essid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].*.ssid')"
|
||||||
sta_bssid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].*.bssid')"
|
sta_bssid="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].*.bssid')"
|
||||||
f_log "info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' is out of range (${trm_ifquality}/${trm_minquality}), uplink disconnected (${trm_sysver})"
|
f_log "info" "uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' is out of range (${trm_ifquality}/${trm_minquality}), uplink disconnected (${trm_sysver})"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ]
|
if [ "${mode}" = "initial" ] || [ "${trm_ifstatus}" = "true" ]
|
||||||
then
|
then
|
||||||
if ([ "${trm_ifstatus}" != "true" ] && [ "${trm_ifstatus}" != "${status}" ]) || [ ${trm_ifquality} -lt ${trm_minquality} ]
|
if ([ "${trm_ifstatus}" != "true" ] && [ "${trm_ifstatus}" != "${status}" ]) || [ ${trm_ifquality} -lt ${trm_minquality} ]
|
||||||
then
|
then
|
||||||
f_jsnup
|
f_jsnup
|
||||||
fi
|
fi
|
||||||
if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ] && [ "${trm_ifstatus}" = "true" ]
|
if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ] && [ "${trm_ifstatus}" = "true" ]
|
||||||
then
|
then
|
||||||
result="$(${trm_fetch} --timeout=$(( ${trm_maxwait} / 3 )) --spider "${trm_captiveurl}" 2>&1 | awk '/^Redirected/{printf "%s" "net cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed|^Connection error/{printf "%s" "net nok";exit}')"
|
result="$(${trm_fetch} --timeout=$(( ${trm_maxwait} / 3 )) --spider "${trm_captiveurl}" 2>&1 | awk '/^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 [ -n "${result}" ] && ([ -z "${trm_connection}" ] || [ "${result}" != "${trm_connection%/*}" ])
|
if [ -n "${result}" ] && ([ -z "${trm_connection}" ] || [ "${result}" != "${trm_connection%/*}" ])
|
||||||
then
|
then
|
||||||
trm_connection="${result}/${trm_ifquality}"
|
trm_connection="${result}/${trm_ifquality}"
|
||||||
f_jsnup
|
f_jsnup
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
wait=$(( wait + 1 ))
|
wait=$(( wait + 1 ))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
f_log "debug" "f_check::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, quality: ${trm_ifquality}, connection: ${trm_connection:-"-"}, wait: ${wait}, max_wait: ${trm_maxwait}, min_quality: ${trm_minquality}, captive: ${trm_captive}"
|
f_log "debug" "f_check::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, quality: ${trm_ifquality}, connection: ${trm_connection:-"-"}, wait: ${wait}, max_wait: ${trm_maxwait}, min_quality: ${trm_minquality}, captive: ${trm_captive}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# update runtime information
|
# update runtime information
|
||||||
#
|
#
|
||||||
f_jsnup()
|
f_jsnup()
|
||||||
{
|
{
|
||||||
local config sta_iface sta_radio sta_essid sta_bssid dev_status status="${trm_ifstatus}" faulty_list faulty_station="${1}"
|
local config sta_iface sta_radio sta_essid sta_bssid dev_status status="${trm_ifstatus}" faulty_list faulty_station="${1}"
|
||||||
|
|
||||||
if [ "${status}" = "true" ]
|
if [ "${status}" = "true" ]
|
||||||
then
|
then
|
||||||
status="connected (${trm_connection:-"-"})"
|
status="connected (${trm_connection:-"-"})"
|
||||||
else
|
else
|
||||||
unset trm_connection
|
unset trm_connection
|
||||||
if [ "${status}" = "false" ]
|
status="running / not connected"
|
||||||
then
|
fi
|
||||||
status="not connected"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
|
dev_status="$(ubus -S call network.wireless status 2>/dev/null)"
|
||||||
if [ -n "${dev_status}" ]
|
if [ -n "${dev_status}" ]
|
||||||
then
|
then
|
||||||
config="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].section')"
|
config="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e '@.*.interfaces[@.config.mode="sta"].section')"
|
||||||
if [ -n "${config}" ]
|
if [ -n "${config}" ]
|
||||||
then
|
then
|
||||||
sta_iface="$(uci_get wireless "${config}" network)"
|
sta_iface="$(uci_get wireless "${config}" network)"
|
||||||
sta_radio="$(uci_get wireless "${config}" device)"
|
sta_radio="$(uci_get wireless "${config}" device)"
|
||||||
sta_essid="$(uci_get wireless "${config}" ssid)"
|
sta_essid="$(uci_get wireless "${config}" ssid)"
|
||||||
sta_bssid="$(uci_get wireless "${config}" bssid)"
|
sta_bssid="$(uci_get wireless "${config}" bssid)"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
json_get_var faulty_list "faulty_stations"
|
json_get_var faulty_list "faulty_stations"
|
||||||
if [ -n "${faulty_station}" ]
|
if [ -n "${faulty_station}" ]
|
||||||
then
|
then
|
||||||
if [ -z "$(printf "%s" "${faulty_list}" | grep -Fo "${faulty_station}")" ]
|
if [ -z "$(printf "%s" "${faulty_list}" | grep -Fo "${faulty_station}")" ]
|
||||||
then
|
then
|
||||||
faulty_list="${faulty_list} ${faulty_station}"
|
faulty_list="${faulty_list} ${faulty_station}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
json_add_string "travelmate_status" "${status}"
|
json_add_string "travelmate_status" "${status}"
|
||||||
json_add_string "travelmate_version" "${trm_ver}"
|
json_add_string "travelmate_version" "${trm_ver}"
|
||||||
json_add_string "station_id" "${sta_radio:-"-"}/${sta_essid:-"-"}/${sta_bssid:-"-"}"
|
json_add_string "station_id" "${sta_radio:-"-"}/${sta_essid:-"-"}/${sta_bssid:-"-"}"
|
||||||
json_add_string "station_interface" "${sta_iface:-"-"}"
|
json_add_string "station_interface" "${sta_iface:-"-"}"
|
||||||
json_add_string "faulty_stations" "${faulty_list}"
|
json_add_string "faulty_stations" "${faulty_list}"
|
||||||
json_add_string "last_rundate" "$(/bin/date "+%d.%m.%Y %H:%M:%S")"
|
json_add_string "last_rundate" "$(/bin/date "+%d.%m.%Y %H:%M:%S")"
|
||||||
json_add_string "system" "${trm_sysver}"
|
json_add_string "system" "${trm_sysver}"
|
||||||
json_dump > "${trm_rtfile}"
|
json_dump > "${trm_rtfile}"
|
||||||
f_log "debug" "f_jsnup::: config: ${config:-"-"}, status: ${status:-"-"}, sta_iface: ${sta_iface:-"-"}, sta_radio: ${sta_radio:-"-"}, sta_essid: ${sta_essid:-"-"}, sta_bssid: ${sta_bssid:-"-"}, faulty_list: ${faulty_list:-"-"}"
|
f_log "debug" "f_jsnup::: config: ${config:-"-"}, status: ${status:-"-"}, sta_iface: ${sta_iface:-"-"}, sta_radio: ${sta_radio:-"-"}, sta_essid: ${sta_essid:-"-"}, sta_bssid: ${sta_bssid:-"-"}, faulty_list: ${faulty_list:-"-"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# write to syslog
|
# write to syslog
|
||||||
#
|
#
|
||||||
f_log()
|
f_log()
|
||||||
{
|
{
|
||||||
local class="${1}"
|
local class="${1}"
|
||||||
local log_msg="${2}"
|
local log_msg="${2}"
|
||||||
|
|
||||||
if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${trm_debug} -eq 1 ])
|
if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${trm_debug} -eq 1 ])
|
||||||
then
|
then
|
||||||
logger -p "${class}" -t "travelmate-${trm_ver}[${$}]" "${log_msg}"
|
logger -p "${class}" -t "travelmate-${trm_ver}[${$}]" "${log_msg}"
|
||||||
if [ "${class}" = "err" ]
|
if [ "${class}" = "err" ]
|
||||||
then
|
then
|
||||||
trm_ifstatus="error"
|
trm_ifstatus="error"
|
||||||
f_jsnup
|
f_jsnup
|
||||||
logger -p "${class}" -t "travelmate-${trm_ver}[${$}]" "Please check 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md' (${trm_sysver})"
|
logger -p "${class}" -t "travelmate-${trm_ver}[${$}]" "Please check 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md' (${trm_sysver})"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# main function for connection handling
|
# main function for connection handling
|
||||||
#
|
#
|
||||||
f_main()
|
f_main()
|
||||||
{
|
{
|
||||||
local IFS cnt dev config scan scan_list scan_essid scan_bssid scan_quality sta sta_essid sta_bssid sta_radio sta_iface faulty_list
|
local IFS cnt dev config scan scan_list scan_essid scan_bssid scan_quality sta sta_essid sta_bssid sta_radio sta_iface faulty_list
|
||||||
|
|
||||||
f_check "initial"
|
f_check "initial"
|
||||||
if [ "${trm_ifstatus}" != "true" ]
|
if [ "${trm_ifstatus}" != "true" ]
|
||||||
then
|
then
|
||||||
config_load wireless
|
config_load wireless
|
||||||
config_foreach f_prep wifi-iface
|
config_foreach f_prep wifi-iface
|
||||||
uci_commit wireless
|
uci_commit wireless
|
||||||
f_check "dev" "running"
|
f_check "dev" "running / not connected"
|
||||||
json_get_var faulty_list "faulty_stations"
|
json_get_var faulty_list "faulty_stations"
|
||||||
f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist:0:800}, faulty_list: ${faulty_list:-"-"}"
|
f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist:0:800}, faulty_list: ${faulty_list:-"-"}"
|
||||||
for dev in ${trm_devlist}
|
for dev in ${trm_devlist}
|
||||||
do
|
do
|
||||||
if [ -z "$(printf "%s" "${trm_stalist}" | grep -Fo "_${dev}")" ]
|
if [ -z "$(printf "%s" "${trm_stalist}" | grep -Fo "_${dev}")" ]
|
||||||
then
|
then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
cnt=1
|
cnt=1
|
||||||
while [ ${cnt} -le ${trm_maxretry} ]
|
while [ ${cnt} -le ${trm_maxretry} ]
|
||||||
do
|
do
|
||||||
scan_list="$(${trm_iwinfo} "${dev}" scan 2>/dev/null | awk 'BEGIN{FS="[/ ]"}/Address:/{var1=$NF}/ESSID:/{var2="";for(i=12;i<=NF;i++)if(var2==""){var2=$i}else{var2=var2" "$i}}/Quality:/{printf "%i,%s,%s\n",(100/$NF*$(NF-1)),var1,var2}' | sort -rn | awk '{ORS=",";print $0}')"
|
scan_list="$(${trm_iwinfo} "${dev}" scan 2>/dev/null | awk 'BEGIN{FS="[/ ]"}/Address:/{var1=$NF}/ESSID:/{var2="";for(i=12;i<=NF;i++)if(var2==""){var2=$i}else{var2=var2" "$i}}/Quality:/{printf "%i,%s,%s\n",(100/$NF*$(NF-1)),var1,var2}' | sort -rn | awk '{ORS=",";print $0}')"
|
||||||
f_log "debug" "f_main ::: dev: ${dev}, scan_list: ${scan_list:0:800}, cnt: ${cnt}, max_cnt: ${trm_maxretry}"
|
f_log "debug" "f_main ::: dev: ${dev}, scan_list: ${scan_list:0:800}, cnt: ${cnt}, max_cnt: ${trm_maxretry}"
|
||||||
if [ -n "${scan_list}" ]
|
if [ -n "${scan_list}" ]
|
||||||
then
|
then
|
||||||
for sta in ${trm_stalist}
|
for sta in ${trm_stalist}
|
||||||
do
|
do
|
||||||
config="${sta%%_*}"
|
config="${sta%%_*}"
|
||||||
sta_radio="${sta##*_}"
|
sta_radio="${sta##*_}"
|
||||||
sta_essid="$(uci_get wireless "${config}" ssid)"
|
sta_essid="$(uci_get wireless "${config}" ssid)"
|
||||||
sta_bssid="$(uci_get wireless "${config}" bssid)"
|
sta_bssid="$(uci_get wireless "${config}" bssid)"
|
||||||
sta_iface="$(uci_get wireless "${config}" network)"
|
sta_iface="$(uci_get wireless "${config}" network)"
|
||||||
json_get_var faulty_list "faulty_stations"
|
json_get_var faulty_list "faulty_stations"
|
||||||
if [ -n "$(printf "%s" "${faulty_list}" | grep -Fo "${sta_radio}/${sta_essid}/${sta_bssid}")" ]
|
if [ -n "$(printf "%s" "${faulty_list}" | grep -Fo "${sta_radio}/${sta_essid}/${sta_bssid}")" ]
|
||||||
then
|
then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
IFS=","
|
IFS=","
|
||||||
for scan in ${scan_list}
|
for scan in ${scan_list}
|
||||||
do
|
do
|
||||||
if [ -z "${scan_quality}" ]
|
if [ -z "${scan_quality}" ]
|
||||||
then
|
then
|
||||||
scan_quality="${scan}"
|
scan_quality="${scan}"
|
||||||
elif [ -z "${scan_bssid}" ]
|
elif [ -z "${scan_bssid}" ]
|
||||||
then
|
then
|
||||||
scan_bssid="${scan}"
|
scan_bssid="${scan}"
|
||||||
elif [ -z "${scan_essid}" ]
|
elif [ -z "${scan_essid}" ]
|
||||||
then
|
then
|
||||||
scan_essid="${scan}"
|
scan_essid="${scan}"
|
||||||
fi
|
fi
|
||||||
if [ -n "${scan_quality}" ] && [ -n "${scan_bssid}" ] && [ -n "${scan_essid}" ]
|
if [ -n "${scan_quality}" ] && [ -n "${scan_bssid}" ] && [ -n "${scan_essid}" ]
|
||||||
then
|
then
|
||||||
if [ ${scan_quality} -ge ${trm_minquality} ]
|
if [ ${scan_quality} -ge ${trm_minquality} ]
|
||||||
then
|
then
|
||||||
if (([ "${scan_essid}" = "\"${sta_essid}\"" ] && ([ -z "${sta_bssid}" ] || [ "${scan_bssid}" = "${sta_bssid}" ])) || \
|
if (([ "${scan_essid}" = "\"${sta_essid}\"" ] && ([ -z "${sta_bssid}" ] || [ "${scan_bssid}" = "${sta_bssid}" ])) || \
|
||||||
([ "${scan_bssid}" = "${sta_bssid}" ] && [ "${scan_essid}" = "unknown" ])) && [ "${dev}" = "${sta_radio}" ]
|
([ "${scan_bssid}" = "${sta_bssid}" ] && [ "${scan_essid}" = "unknown" ])) && [ "${dev}" = "${sta_radio}" ]
|
||||||
then
|
then
|
||||||
f_log "debug" "f_main ::: scan_quality: ${scan_quality}, scan_bssid: ${scan_bssid}, scan_essid: ${scan_essid}"
|
f_log "debug" "f_main ::: scan_quality: ${scan_quality}, scan_bssid: ${scan_bssid}, scan_essid: ${scan_essid}"
|
||||||
uci_set wireless "${config}" disabled 0
|
uci_set wireless "${config}" disabled 0
|
||||||
f_check "sta"
|
f_check "sta"
|
||||||
if [ "${trm_ifstatus}" = "true" ]
|
if [ "${trm_ifstatus}" = "true" ]
|
||||||
then
|
then
|
||||||
uci_commit wireless
|
uci_commit wireless
|
||||||
f_check "initial"
|
f_check "initial"
|
||||||
f_log "info" "connected to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${trm_sysver})"
|
f_log "info" "connected to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${trm_sysver})"
|
||||||
return 0
|
return 0
|
||||||
elif [ ${cnt} -eq ${trm_maxretry} ]
|
elif [ ${cnt} -eq ${trm_maxretry} ]
|
||||||
then
|
then
|
||||||
uci_set wireless "${config}" disabled 1
|
uci_set wireless "${config}" disabled 1
|
||||||
uci_commit wireless
|
uci_commit wireless
|
||||||
faulty_station="${sta_radio}/${sta_essid}/${sta_bssid:-"-"}"
|
faulty_station="${sta_radio}/${sta_essid}/${sta_bssid:-"-"}"
|
||||||
f_jsnup "${faulty_station}"
|
f_jsnup "${faulty_station}"
|
||||||
f_log "info" "can't connect to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}', uplink disabled (${trm_sysver})"
|
f_log "info" "can't connect to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}', uplink disabled (${trm_sysver})"
|
||||||
f_check "rev"
|
f_check "rev"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
uci -q revert wireless
|
uci -q revert wireless
|
||||||
f_jsnup
|
f_jsnup
|
||||||
f_log "info" "can't connect to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${trm_sysver})"
|
f_log "info" "can't connect to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${trm_sysver})"
|
||||||
f_check "rev"
|
f_check "rev"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
unset scan_quality scan_bssid scan_essid
|
unset scan_quality scan_bssid scan_essid
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset IFS scan_quality scan_bssid scan_essid
|
unset IFS scan_quality scan_bssid scan_essid
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
cnt=$(( cnt + 1 ))
|
cnt=$(( cnt + 1 ))
|
||||||
sleep $(( ${trm_maxwait} / 6 ))
|
sleep $(( ${trm_maxwait} / 6 ))
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
if [ ! -s "${trm_rtfile}" ]
|
fi
|
||||||
then
|
|
||||||
trm_ifstatus="false"
|
|
||||||
f_jsnup
|
|
||||||
fi
|
|
||||||
elif [ ! -s "${trm_rtfile}" ]
|
|
||||||
then
|
|
||||||
f_jsnup
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# source required system libraries
|
# source required system libraries
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
|
if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
. "/lib/functions.sh"
|
||||||
. "/usr/share/libubox/jshn.sh"
|
. "/usr/share/libubox/jshn.sh"
|
||||||
else
|
else
|
||||||
f_log "err" "system libraries not found"
|
f_log "err" "system libraries not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# initialize json runtime file
|
# initialize json runtime file
|
||||||
#
|
#
|
||||||
if [ ! -s "${trm_rtfile}" ]
|
json_load_file "${trm_rtfile}" >/dev/null 2>&1
|
||||||
|
json_select data >/dev/null 2>&1
|
||||||
|
if [ ${?} -ne 0 ]
|
||||||
then
|
then
|
||||||
json_init
|
> "${trm_rtfile}"
|
||||||
json_add_object "data"
|
json_init
|
||||||
else
|
json_add_object "data"
|
||||||
json_load_file "${trm_rtfile}"
|
|
||||||
json_select data
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# control travelmate actions
|
# control travelmate actions
|
||||||
#
|
#
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
if [ -z "${trm_action}" ]
|
if [ -z "${trm_action}" ]
|
||||||
then
|
then
|
||||||
sleep ${trm_timeout}
|
sleep ${trm_timeout}
|
||||||
elif [ "${trm_action}" = "stop" ]
|
elif [ "${trm_action}" = "stop" ]
|
||||||
then
|
then
|
||||||
> "${trm_rtfile}"
|
> "${trm_rtfile}"
|
||||||
f_log "info" "travelmate instance stopped ::: action: ${trm_action}, pid: $(cat ${trm_pidfile} 2>/dev/null)"
|
f_log "info" "travelmate instance stopped ::: action: ${trm_action}, pid: $(cat ${trm_pidfile} 2>/dev/null)"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
f_log "info" "travelmate instance started ::: action: ${trm_action}, pid: ${$}"
|
f_log "info" "travelmate instance started ::: action: ${trm_action}, pid: ${$}"
|
||||||
unset trm_action
|
unset trm_action
|
||||||
fi
|
fi
|
||||||
f_envload
|
f_envload
|
||||||
f_main
|
f_main
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue