Browse Source

Merge pull request #5663 from dibdot/travelmate

travelmate: update 1.1.1
lilik-openwrt-22.03
Dirk Brenken 7 years ago
committed by GitHub
parent
commit
c06819b67e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 54 deletions
  1. +1
    -1
      net/travelmate/Makefile
  2. +1
    -1
      net/travelmate/files/travelmate.conf
  3. +45
    -52
      net/travelmate/files/travelmate.sh

+ 1
- 1
net/travelmate/Makefile View File

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=travelmate PKG_NAME:=travelmate
PKG_VERSION:=1.1.0
PKG_VERSION:=1.1.1
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>


+ 1
- 1
net/travelmate/files/travelmate.conf View File

@ -9,7 +9,7 @@ config travelmate 'global'
option trm_triggerdelay '2' option trm_triggerdelay '2'
option trm_debug '0' option trm_debug '0'
option trm_maxretry '3' option trm_maxretry '3'
option trm_minquality '30'
option trm_minquality '35'
option trm_maxwait '30' option trm_maxwait '30'
option trm_timeout '60' option trm_timeout '60'
option trm_rtfile '/tmp/trm_runtime.json' option trm_rtfile '/tmp/trm_runtime.json'

+ 45
- 52
net/travelmate/files/travelmate.sh View File

@ -10,14 +10,14 @@
# #
LC_ALL=C LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin" PATH="/usr/sbin:/usr/bin:/sbin:/bin"
trm_ver="1.1.0"
trm_ver="1.1.1"
trm_sysver="unknown" trm_sysver="unknown"
trm_enabled=0 trm_enabled=0
trm_debug=0 trm_debug=0
trm_automatic=1 trm_automatic=1
trm_captive=1 trm_captive=1
trm_captiveurl="http://captive.apple.com" trm_captiveurl="http://captive.apple.com"
trm_minquality=30
trm_minquality=35
trm_maxretry=3 trm_maxretry=3
trm_maxwait=30 trm_maxwait=30
trm_timeout=60 trm_timeout=60
@ -49,13 +49,13 @@ f_envload()
trm_sysver="${sys_model}, ${sys_desc}" trm_sysver="${sys_model}, ${sys_desc}"
fi fi
# initialize variables
# (re-)initialize global list variables
# #
trm_devlist="" trm_devlist=""
trm_stalist="" trm_stalist=""
trm_radiolist="" trm_radiolist=""
# load uci config and check 'enabled' option
# load config and check 'enabled' option
# #
option_cb() option_cb()
{ {
@ -110,7 +110,7 @@ f_prep()
# #
f_check() f_check()
{ {
local ifname radio dev_status config sta_iface sta_radio sta_essid sta_bssid heartbeat cnt=1 mode="${1}" status="${2:-"false"}"
local ifname radio dev_status config sta_iface sta_radio sta_essid sta_bssid result cnt=1 mode="${1}" status="${2:-"false"}" IFS=" "
trm_ifquality=0 trm_ifquality=0
trm_ifstatus="false" trm_ifstatus="false"
@ -132,8 +132,8 @@ f_check()
fi fi
for radio in ${trm_radiolist} for radio in ${trm_radiolist}
do do
trm_ifstatus="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e "@.${radio}.up")"
if [ "${trm_ifstatus}" = "true" ] && [ -z "$(printf "%s" "${trm_devlist}" | grep -Fo " ${radio}")" ]
status="$(printf "%s" "${dev_status}" | jsonfilter -l1 -e "@.${radio}.up")"
if [ "${status}" = "true" ] && [ -z "$(printf "%s" "${trm_devlist}" | grep -Fo " ${radio}")" ]
then then
trm_devlist="${trm_devlist} ${radio}" trm_devlist="${trm_devlist} ${radio}"
fi fi
@ -171,10 +171,10 @@ f_check()
fi fi
if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ] && [ "${trm_ifstatus}" = "true" ] if [ "${mode}" = "initial" ] && [ "${trm_captive}" -eq 1 ] && [ "${trm_ifstatus}" = "true" ]
then then
heartbeat="$(${trm_fetch} --timeout=1 --spider "${trm_captiveurl}" 2>&1 | awk '/^Redirected/{printf "%s" "cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed/{printf "%s" "net nok";exit}')"
if ([ -n "${heartbeat}" ] && [ -z "${trm_connection}" ]) || [ "${trm_connection%/*}" != "${heartbeat}" ]
result="$(${trm_fetch} --timeout=1 --spider "${trm_captiveurl}" 2>&1 | awk '/^Redirected/{printf "%s" "cp \047"$NF"\047";exit}/^Download completed/{printf "%s" "net ok";exit}/^Failed/{printf "%s" "net nok";exit}')"
if ([ -n "${result}" ] && [ -z "${trm_connection}" ]) || [ "${trm_connection%/*}" != "${result}" ]
then then
trm_connection="${heartbeat}/${trm_ifquality}"
trm_connection="${result}/${trm_ifquality}"
f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}" f_jsnup "${sta_iface}" "${sta_radio}" "${sta_essid}" "${sta_bssid}"
fi fi
fi fi
@ -184,7 +184,7 @@ f_check()
cnt=$((cnt+1)) cnt=$((cnt+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:-"-"}, cnt: ${cnt}, max-wait: ${trm_maxwait}, min-quality: ${trm_minquality}, captive: ${trm_captive}, automatic: ${trm_automatic}"
f_log "debug" "f_check::: mode: ${mode}, name: ${ifname:-"-"}, status: ${trm_ifstatus}, quality: ${trm_ifquality}, connection: ${trm_connection:-"-"}, cnt: ${cnt}, max_wait: ${trm_maxwait}, min_quality: ${trm_minquality}, captive: ${trm_captive}, automatic: ${trm_automatic}"
} }
# update runtime information # update runtime information
@ -238,31 +238,28 @@ f_log()
# #
f_main() f_main()
{ {
local dev config combo_list scan scan_essid scan_bssid scan_quality sta sta_essid sta_bssid sta_radio sta_iface cnt=1 IFS=" "
local cnt dev config scan scan_list scan_essid scan_bssid scan_quality sta sta_essid sta_bssid sta_radio sta_iface IFS=" "
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
if [ -n "$(uci -q changes wireless)" ]
then
uci_commit wireless
fi
uci_commit wireless
f_check "dev" "running" f_check "dev" "running"
f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, eap_rc: ${trm_eap}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist}"
f_log "debug" "f_main ::: iwinfo: ${trm_iwinfo}, eap_rc: ${trm_eap}, dev_list: ${trm_devlist}, sta_list: ${trm_stalist:0:800}"
for dev in ${trm_devlist} for dev in ${trm_devlist}
do do
cnt=1
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
while [ ${trm_maxretry} -eq 0 ] || [ ${cnt} -le ${trm_maxretry} ] while [ ${trm_maxretry} -eq 0 ] || [ ${cnt} -le ${trm_maxretry} ]
do do
combo_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}, combo_list: ${combo_list}"
if [ -n "${combo_list}" ]
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}"
if [ -n "${scan_list}" ]
then then
for sta in ${trm_stalist} for sta in ${trm_stalist}
do do
@ -272,7 +269,7 @@ f_main()
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)"
IFS="," IFS=","
for scan in ${combo_list}
for scan in ${scan_list}
do do
if [ -z "${scan_quality}" ] if [ -z "${scan_quality}" ]
then then
@ -288,43 +285,39 @@ f_main()
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}" ]) && [ "${dev}" = "${sta_radio}" ]
if (([ "${scan_essid}" = "\"${sta_essid}\"" ] && ([ -z "${sta_bssid}" ] || [ "${scan_bssid}" = "${sta_bssid}" ])) || \
([ "${scan_bssid}" = "${sta_bssid}" ] && [ "${scan_essid}" = "unknown" ])) && [ "${dev}" = "${sta_radio}" ]
then then
uci_set wireless "${config}" disabled 0 uci_set wireless "${config}" disabled 0
f_check "sta" f_check "sta"
if [ ${trm_ifquality} -ge ${trm_minquality} ]
if [ "${trm_ifstatus}" = "true" ]
then then
if [ "${trm_ifstatus}" = "true" ]
uci_commit wireless
f_log "info" "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${trm_sysver})"
f_check "initial"
return 0
elif [ ${trm_maxretry} -ne 0 ] && [ ${cnt} -eq ${trm_maxretry} ]
then
uci_set wireless "${config}" disabled 1
if [ -n "${sta_essid}" ]
then
uci_set wireless "${config}" ssid "${sta_essid}_err"
fi
if [ -n "${sta_bssid}" ]
then then
uci_commit wireless
f_log "info" "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${trm_sysver})"
f_check "initial"
return 0
elif [ ${trm_maxretry} -ne 0 ] && [ ${cnt} -eq ${trm_maxretry} ]
uci_set wireless "${config}" bssid "${sta_bssid}_err"
fi
uci_commit wireless
f_log "info" "can't connect to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}', uplink disabled (${trm_sysver})"
f_check "dev"
else
if [ ${trm_maxretry} -eq 0 ]
then then
uci_set wireless "${config}" disabled 1
if [ -n "${sta_essid}" ]
then
uci_set wireless "${config}" ssid "${sta_essid}_err"
fi
if [ -n "${sta_bssid}" ]
then
uci_set wireless "${config}" bssid "${sta_bssid}_err"
fi
uci_commit wireless
f_check "dev"
f_log "info" "can't connect to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}), uplink disabled (${trm_sysver})"
else
if [ ${trm_maxretry} -eq 0 ]
then
cnt=0
fi
uci -q revert wireless
f_check "dev"
f_log "info" "can't connect to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${cnt}/${trm_maxretry}) (${trm_sysver})"
cnt=0
fi fi
f_jsnup
uci -q revert wireless
f_log "info" "can't connect to uplink '${sta_essid:-"-"}/${sta_bssid:-"-"}' (${trm_sysver})"
f_check "dev"
fi fi
fi fi
fi fi


Loading…
Cancel
Save