@ -8,14 +8,14 @@
export LC_ALL = C
export LC_ALL = C
export PATH = "/usr/sbin:/usr/bin:/sbin:/bin"
export PATH = "/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
trm_ver = "2.0.9 "
trm_ver = "2.1.0 "
trm_enabled = "0"
trm_enabled = "0"
trm_debug = "0"
trm_debug = "0"
trm_iface = ""
trm_iface = ""
trm_captive = "1"
trm_captive = "1"
trm_proactive = "1"
trm_proactive = "1"
trm_vpn = "1"
trm_netcheck = "0"
trm_netcheck = "0"
trm_autoadd = "0"
trm_autoadd = "0"
trm_randomize = "0"
trm_randomize = "0"
@ -28,11 +28,12 @@ trm_maxwait="30"
trm_maxautoadd = "5"
trm_maxautoadd = "5"
trm_maxscan = "10"
trm_maxscan = "10"
trm_timeout = "60"
trm_timeout = "60"
trm_opensta = "0"
trm_radio = ""
trm_radio = ""
trm_connection = ""
trm_connection = ""
trm_wpaflags = ""
trm_wpaflags = ""
trm_uplinkcfg = ""
trm_ovpninfolist = ""
trm_vpnifacelist = ""
trm_vpninfolist = ""
trm_rtfile = "/tmp/trm_runtime.json"
trm_rtfile = "/tmp/trm_runtime.json"
trm_wifi = " $( command -v wifi) "
trm_wifi = " $( command -v wifi) "
trm_fetch = " $( command -v curl) "
trm_fetch = " $( command -v curl) "
@ -57,7 +58,7 @@ f_env() {
return
return
fi
fi
unset trm_stalist trm_radiolist trm_uplinklist trm_vpnifacelist trm_ uplinkcfg trm_wpaflags trm_activesta trm_opensta
unset trm_stalist trm_radiolist trm_uplinklist trm_uplinkcfg trm_activesta trm_opensta
trm_sysver = " $( ubus -S call system board 2>/dev/null | jsonfilter -q -e '@.model' -e '@.release.description' |
trm_sysver = " $( ubus -S call system board 2>/dev/null | jsonfilter -q -e '@.model' -e '@.release.description' |
awk 'BEGIN{RS="";FS="\n"}{printf "%s, %s",$1,$2}' ) "
awk 'BEGIN{RS="";FS="\n"}{printf "%s, %s",$1,$2}' ) "
@ -70,6 +71,12 @@ f_env() {
local option = " ${ 1 } " value = " ${ 2 } "
local option = " ${ 1 } " value = " ${ 2 } "
eval " ${ option } =\" ${ value } \" "
eval " ${ option } =\" ${ value } \" "
}
}
list_cb( ) {
local option = " ${ 1 } " value = " ${ 2 } "
if [ " ${ option } " = "trm_vpnifacelist" ] ; then
eval " trm_vpnifacelist=\" $( printf "%s" " ${ trm_vpnifacelist } " ) ${ value } \" "
fi
}
elif [ " ${ name } " = "uplink" ] ; then
elif [ " ${ name } " = "uplink" ] ; then
if [ " $( uci_get " travelmate. ${ type } .opensta " ) " = "1" ] ; then
if [ " $( uci_get " travelmate. ${ type } .opensta " ) " = "1" ] ; then
eval " trm_opensta=\" $(( ${ trm_opensta :- 0 } + 1 )) \" "
eval " trm_opensta=\" $(( ${ trm_opensta :- 0 } + 1 )) \" "
@ -93,17 +100,19 @@ f_env() {
/etc/init.d/travelmate stop
/etc/init.d/travelmate stop
fi
fi
wpa_checks = "sae owe eap suiteb192"
for check in ${ wpa_checks } ; do
if [ -x " ${ trm_wpa } " ] ; then
if " ${ trm_wpa } " -v" ${ check } " >/dev/null 2>& 1; then
result = " $( f_trim " ${ result } ${ check } : $( f_char 1) " ) "
else
result = " $( f_trim " ${ result } ${ check } : $( f_char 0) " ) "
if [ -z " ${ trm_wpaflags } " ] ; then
wpa_checks = "sae owe eap suiteb192"
for check in ${ wpa_checks } ; do
if [ -x " ${ trm_wpa } " ] ; then
if " ${ trm_wpa } " -v" ${ check } " >/dev/null 2>& 1; then
result = " $( f_trim " ${ result } ${ check } : $( f_char 1) " ) "
else
result = " $( f_trim " ${ result } ${ check } : $( f_char 0) " ) "
fi
fi
fi
fi
done
trm_wpaflags = " $( print f "%s" " ${ result } " | awk '{printf "%s %s, %s %s, %s %s, %s %s",$1,$2,$3,$4,$5,$6,$7,$8}' ) "
done
trm_wpaflags = " $( printf "%s" " ${ result } " | awk '{printf "%s %s, %s %s, %s %s, %s %s",$1,$2,$3,$4,$5,$6,$7,$8}' ) "
fi
config_load wireless
config_load wireless
config_foreach f_setdev "wifi-device"
config_foreach f_setdev "wifi-device"
@ -119,9 +128,11 @@ f_env() {
json_add_object "data"
json_add_object "data"
fi
fi
config_load network
config_foreach f_getvpn "interface"
f_log "debug" " f_env ::: auto_sta: ${ trm_opensta :- "-" } , wpa_flags: ${ trm_wpaflags } , sys_ver: ${ trm_sysver } "
if [ " ${ trm_vpn } " = "1" ] && [ -z " ${ trm_vpninfolist } " ] ; then
config_load network
config_foreach f_getvpn "interface"
fi
f_log "debug" " f_env ::: auto_sta: ${ trm_opensta :- "-" } , wpa_flags: ${ trm_wpaflags } , sys_ver: ${ trm_sysver } "
}
}
# trim helper function
# trim helper function
@ -176,57 +187,74 @@ f_wifi() {
sleep " $(( trm_maxwait / 6 )) "
sleep " $(( trm_maxwait / 6 )) "
timeout = " $(( timeout + ( trm_maxwait / 6 )) ) "
timeout = " $(( timeout + ( trm_maxwait / 6 )) ) "
fi
fi
f_log "debug" " f_wifi ::: radio_list: ${ trm_radiolist } , radio: ${ radio } , timeout: ${ timeout } "
f_log "debug" " f_wifi ::: radio_list: ${ trm_radiolist } , radio: ${ radio } , timeout: ${ timeout } "
}
}
# vpn helper function
# vpn helper function
#
#
f_vpn( ) {
f_vpn( ) {
local rc result iface vpn vpn_service vpn_iface vpn_status vpn_action = " ${ 1 } "
vpn = " $( f_getval "vpn" ) "
vpn_service = " $( f_getval "vpnservice" ) "
vpn_iface = " $( f_getval "vpniface" ) "
if [ ! -f " ${ trm_vpnfile } " ] || { [ -f " ${ trm_vpnfile } " ] && [ " ${ vpn_action } " = "enable" ] ; } ; then
for iface in ${ trm_vpnifacelist } ; do
vpn_status = " $( ifstatus " ${ iface } " | jsonfilter -q -l1 -e '@.up' ) "
if [ " ${ vpn_status } " = "true" ] ; then
ifdown " ${ iface } "
f_log "info" " take down vpn interface ' ${ iface } ' (initial) "
local rc result info iface vpn vpn_service vpn_iface vpn_instance vpn_status vpn_action = " ${ 1 } "
if [ " ${ trm_vpn } " = "1" ] && [ -n " ${ trm_vpninfolist } " ] ; then
vpn = " $( f_getval "vpn" ) "
vpn_service = " $( f_getval "vpnservice" ) "
vpn_iface = " $( f_getval "vpniface" ) "
if [ ! -f " ${ trm_vpnfile } " ] || { [ -f " ${ trm_vpnfile } " ] && [ " ${ vpn_action } " = "enable" ] ; } ; then
for info in ${ trm_vpninfolist } ; do
iface = " ${ info %%&&* } "
[ " ${ iface } " = " ${ info } " ] && vpn_instance = "" || vpn_instance = " ${ info ##*&& } "
vpn_status = " $( ifstatus " ${ iface } " | jsonfilter -q -l1 -e '@.up' ) "
if [ " ${ vpn_status } " = "true" ] ; then
ifdown " ${ iface } "
if [ -x "/etc/init.d/openvpn" ] && [ -n " ${ vpn_instance } " ] && /etc/init.d/openvpn running " ${ vpn_instance } " ; then
/etc/init.d/openvpn stop " ${ vpn_instance } "
fi
f_log "info" " take down vpn interface ' ${ iface } / ${ vpn_instance :- "-" } ' (initial) "
fi
done
if [ -f "/etc/init.d/sysntpd" ] ; then
/etc/init.d/sysntpd restart >/dev/null 2>& 1
fi
fi
done
[ -x "/etc/init.d/openvpn" ] && /etc/init.d/openvpn stop
if [ -f "/etc/init.d/sysntpd" ] ; then
/etc/init.d/sysntpd restart >/dev/null 2>& 1
rm -f " ${ trm_vpnfile } "
elif [ " ${ vpn } " = "1" ] && [ -n " ${ vpn_iface } " ] && [ " ${ vpn_action } " = "enable_keep" ] ; then
for info in ${ trm_vpninfolist } ; do
iface = " ${ info %%&&* } "
[ " ${ iface } " = " ${ info } " ] && vpn_instance = "" || vpn_instance = " ${ info ##*&& } "
vpn_status = " $( ifstatus " ${ iface } " | jsonfilter -q -l1 -e '@.up' ) "
if [ " ${ vpn_status } " = "true" ] && [ " ${ iface } " != " ${ vpn_iface } " ] ; then
ifdown " ${ iface } "
if [ -x "/etc/init.d/openvpn" ] && [ -n " ${ vpn_instance } " ] && /etc/init.d/openvpn running " ${ vpn_instance } " ; then
/etc/init.d/openvpn stop " ${ vpn_instance } "
fi
f_log "info" " take down vpn interface ' ${ iface } / ${ vpn_instance :- "-" } ' (switch) "
rm -f " ${ trm_vpnfile } "
break
fi
done
fi
fi
rm -f " ${ trm_vpnfile } "
elif [ " ${ vpn } " = "1" ] && [ -n " ${ vpn_iface } " ] && [ " ${ vpn_action } " = "enable_keep" ] ; then
for iface in ${ trm_vpnifacelist } ; do
vpn_status = " $( ifstatus " ${ iface } " | jsonfilter -q -l1 -e '@.up' ) "
if [ " ${ vpn_status } " = "true" ] && [ " ${ iface } " != " ${ vpn_iface } " ] ; then
ifdown " ${ iface } "
[ -x "/etc/init.d/openvpn" ] && /etc/init.d/openvpn stop
f_log "info" " take down vpn interface ' ${ iface } ' (switch) "
rm -f " ${ trm_vpnfile } "
break
if [ -x " ${ trm_vpnpgm } " ] && [ -n " ${ vpn_service } " ] && [ -n " ${ vpn_iface } " ] ; then
if { [ " ${ vpn_action } " = "disable" ] && [ -f " ${ trm_vpnfile } " ] ; } ||
{ [ -f " ${ trm_ntpfile } " ] && { [ " ${ vpn } " = "1" ] && [ " ${ vpn_action %_* } " = "enable" ] && [ ! -f " ${ trm_vpnfile } " ] ; } ||
{ [ " ${ vpn } " != "1" ] && [ " ${ vpn_action %_* } " = "enable" ] && [ -f " ${ trm_vpnfile } " ] ; } ; } ; then
result = " $( f_net) "
if [ " ${ result } " = "net ok" ] || [ " ${ vpn_action } " = "disable" ] ; then
for info in ${ trm_vpninfolist } ; do
iface = " ${ info %%&&* } "
if [ " ${ iface } " = " ${ vpn_iface } " ] ; then
[ " ${ iface } " = " ${ info } " ] && vpn_instance = "" || vpn_instance = " ${ info ##*&& } "
break
fi
done
f_log "debug" " f_vpn ::: vpn: ${ vpn :- "0" } , action: ${ vpn_action } , service: ${ vpn_service } , iface: ${ vpn_iface } , instance: ${ vpn_instance } "
" ${ trm_vpnpgm } " " ${ vpn :- "0" } " " ${ vpn_action } " " ${ vpn_service } " " ${ vpn_iface } " " ${ vpn_instance } " >/dev/null 2>& 1
rc = " ${ ? } "
fi
fi
fi
done
fi
if [ -x " ${ trm_vpnpgm } " ] && [ -n " ${ vpn_service } " ] && [ -n " ${ vpn_iface } " ] ; then
if { [ " ${ vpn_action } " = "disable" ] && [ -f " ${ trm_vpnfile } " ] ; } ||
{ [ -f " ${ trm_ntpfile } " ] && { [ " ${ vpn } " = "1" ] && [ " ${ vpn_action %_* } " = "enable" ] && [ ! -f " ${ trm_vpnfile } " ] ; } ||
{ [ " ${ vpn } " != "1" ] && [ " ${ vpn_action %_* } " = "enable" ] && [ -f " ${ trm_vpnfile } " ] ; } ; } ; then
result = " $( f_net) "
if [ " ${ result } " = "net ok" ] || [ " ${ vpn_action } " = "disable" ] ; then
f_log "info" " vpn call ' ${ vpn :- "0" } / ${ vpn_action } / ${ vpn_service } / ${ vpn_iface } ' "
" ${ trm_vpnpgm } " " ${ vpn :- "0" } " " ${ vpn_action %_* } " " ${ vpn_service } " " ${ vpn_iface } " >/dev/null 2>& 1
rc = " ${ ? } "
fi
[ -n " ${ rc } " ] && f_jsnup
fi
fi
[ -n " ${ rc } " ] && f_jsnup
fi
fi
f_log "debug" " f_vpn ::: enabled: ${ vpn :- "-" } , action: ${ vpn_action } , service: ${ vpn_service :- "-" } , iface: ${ vpn_iface :- "-" } , rc: ${ rc :- "-" } "
f_log "debug" " f_vpn ::: vpn: ${ trm_vpn :- "-" } , enabled: ${ vpn :- "-" } , action: ${ vpn_action } , service: ${ vpn_service :- "-" } , iface: ${ vpn_iface :- "-" } , instance: ${ vpn_instance :- "-" } , infolist: ${ trm_vpninfolist :- "-" } , result: ${ result } , rc: ${ rc :- "-" } "
}
}
# mac helper function
# mac helper function
@ -257,7 +285,7 @@ f_mac() {
fi
fi
fi
fi
printf "%s" " ${ result } "
printf "%s" " ${ result } "
f_log "debug" " f_mac ::: action: ${ action :- "-" } , section: ${ section :- "-" } , macaddr: ${ macaddr :- "-" } , result: ${ result :- "-" } "
f_log "debug" " f_mac ::: action: ${ action :- "-" } , section: ${ section :- "-" } , macaddr: ${ macaddr :- "-" } , result: ${ result :- "-" } "
}
}
# set connection information
# set connection information
@ -315,19 +343,74 @@ f_ctrack() {
fi
fi
fi
fi
fi
fi
f_log "debug" " f_ctrack ::: action: ${ action :- "-" } , uplink_config: ${ trm_uplinkcfg :- "-" } "
f_log "debug" " f_ctrack ::: action: ${ action :- "-" } , uplink_config: ${ trm_uplinkcfg :- "-" } "
}
# get openvpn information
#
f_getovpn( ) {
local file instance device
for file in /etc/openvpn/*.conf /etc/openvpn/*.ovpn; do
if [ -f " ${ file } " ] ; then
instance = " ${ file ##*/ } "
instance = " ${ instance %.conf } "
instance = " ${ instance %.ovpn } "
device = " $( awk '/^[[:space:]]*dev /{print $2}' " ${ file } " ) "
[ " ${ device } " = "tun" ] && device = "tun0"
[ " ${ device } " = "tap" ] && device = "tap0"
if [ -n " ${ device } " ] && [ -n " ${ instance } " ] && ! printf "%s" " ${ trm_ovpninfolist } " | grep -q " ${ device } " ; then
trm_ovpninfolist = " ${ trm_ovpninfolist } ${ device } && ${ instance } "
fi
fi
done
uci_config( ) {
local device section = " ${ 1 } "
device = " $( uci_get "openvpn" " ${ section } " "dev" ) "
[ " ${ device } " = "tun" ] && device = "tun0"
[ " ${ device } " = "tap" ] && device = "tap0"
if [ -n " ${ device } " ] && ! printf "%s" " ${ trm_ovpninfolist } " | grep -q " ${ device } " ; then
trm_ovpninfolist = " ${ trm_ovpninfolist } ${ device } && ${ section } "
fi
}
if [ -f "/etc/config/openvpn" ] ; then
config_load openvpn
config_foreach uci_config "openvpn"
fi
f_log "debug" " f_getovpn ::: ovpninfolist: ${ trm_ovpninfolist :- "-" } "
}
}
# get logical vpn network interfaces
# get logical vpn network interfaces
#
#
f_getvpn( ) {
f_getvpn( ) {
local proto iface = " ${ 1 } "
local info proto device iface = " ${ 1 } "
proto = " $( uci_get "network" " ${ iface } " "proto" ) "
proto = " $( uci_get "network" " ${ iface } " "proto" ) "
if [ " ${ proto } " = "none" ] || [ " ${ proto } " = "wireguard" ] ; then
trm_vpnifacelist = " $( f_trim " ${ trm_vpnifacelist } ${ iface } " ) "
device = " $( uci_get "network" " ${ iface } " "device" ) "
if [ " ${ proto } " = "wireguard" ] ; then
if { [ -z " ${ trm_vpnifacelist } " ] || printf "%s" " ${ trm_vpnifacelist } " | grep -q " ${ iface } " ; } ; then
if ! printf "%s" " ${ trm_vpninfolist } " | grep -q " ${ iface } " ; then
trm_vpninfolist = " $( f_trim " ${ trm_vpninfolist } ${ iface } " ) "
fi
fi
elif [ " ${ proto } " = "none" ] && [ -n " ${ device } " ] ; then
if [ -z " ${ trm_ovpninfolist } " ] ; then
f_getovpn
fi
if { [ -z " ${ trm_vpnifacelist } " ] || printf "%s" " ${ trm_vpnifacelist } " | grep -q " ${ iface } " ; } ; then
for info in ${ trm_ovpninfolist } ; do
if [ " ${ info %%&&* } " = " ${ device } " ] ; then
if ! printf "%s" " ${ trm_vpninfolist } " | grep -q " ${ iface } " ; then
trm_vpninfolist = " $( f_trim " ${ trm_vpninfolist } ${ iface } && ${ info ##*&& } " ) "
break
fi
fi
done
fi
fi
fi
f_log "debug" " f_getvpn ::: interface: ${ iface :- "-" } , protocol: ${ proto :- "-" } , vpn_interfacelist: ${ trm_vpnifacelist :- "-" } "
f_log "debug" " f_getvpn ::: iface: ${ iface :- "-" } , proto: ${ proto :- "-" } , device: ${ device :- "-" } , i facelist: ${ trm_vpnifacelist :- "-" } , infolist: ${ trm_vpninfo list :- "-" } "
}
}
# get wan gateway addresses
# get wan gateway addresses
@ -344,7 +427,7 @@ f_getgw() {
result = " ${ wan4_gw } ${ wan6_gw } "
result = " ${ wan4_gw } ${ wan6_gw } "
fi
fi
printf "%s" " ${ result } "
printf "%s" " ${ result } "
f_log "debug" " f_getgw ::: wan4_gw: ${ wan4_gw :- "-" } , wan6_gw: ${ wan6_gw :- "-" } , result: ${ result :- "-" } "
f_log "debug" " f_getgw ::: wan4_gw: ${ wan4_gw :- "-" } , wan6_gw: ${ wan6_gw :- "-" } , result: ${ result :- "-" } "
}
}
# get uplink config section
# get uplink config section
@ -363,7 +446,7 @@ f_getcfg() {
fi
fi
cnt = " $(( cnt + 1 )) "
cnt = " $(( cnt + 1 )) "
done
done
f_log "debug" " f_getcfg ::: status: ${ status } , section: ${ section } , uplink_config: ${ trm_uplinkcfg :- "-" } "
f_log "debug" " f_getcfg ::: status: ${ status } , section: ${ section } , uplink_config: ${ trm_uplinkcfg :- "-" } "
}
}
# get travelmate option value in 'uplink' sections
# get travelmate option value in 'uplink' sections
@ -375,7 +458,7 @@ f_getval() {
result = " $( uci_get "travelmate" " ${ trm_uplinkcfg } " " ${ t_option } " ) "
result = " $( uci_get "travelmate" " ${ trm_uplinkcfg } " " ${ t_option } " ) "
printf "%s" " ${ result } "
printf "%s" " ${ result } "
fi
fi
f_log "debug" " f_getval ::: option: ${ t_option :- "-" } , result: ${ result :- "-" } , uplink_config: ${ trm_uplinkcfg :- "-" } "
f_log "debug" " f_getval ::: option: ${ t_option :- "-" } , result: ${ result :- "-" } , uplink_config: ${ trm_uplinkcfg :- "-" } "
}
}
# set 'wifi-device' sections
# set 'wifi-device' sections
@ -392,7 +475,7 @@ f_setdev() {
elif [ -z " ${ trm_radio } " ] && ! printf "%s" " ${ trm_radiolist } " | grep -q " ${ radio } " ; then
elif [ -z " ${ trm_radio } " ] && ! printf "%s" " ${ trm_radiolist } " | grep -q " ${ radio } " ; then
trm_radiolist = " $( f_trim " ${ trm_radiolist } ${ radio } " ) "
trm_radiolist = " $( f_trim " ${ trm_radiolist } ${ radio } " ) "
fi
fi
f_log "debug" " f_setdev ::: radio: ${ radio :- "-" } , radio_list(cnf/cur): ${ trm_radio :- "-" } / ${ trm_radiolist :- "-" } , disabled: ${ disabled :- "-" } "
f_log "debug" " f_setdev ::: radio: ${ radio :- "-" } , radio_list(cnf/cur): ${ trm_radio :- "-" } / ${ trm_radiolist :- "-" } , disabled: ${ disabled :- "-" } "
}
}
# set 'wifi-iface' sections
# set 'wifi-iface' sections
@ -447,7 +530,7 @@ f_setif() {
trm_stalist = " $( f_trim " ${ trm_stalist } ${ section } - ${ radio } " ) "
trm_stalist = " $( f_trim " ${ trm_stalist } ${ section } - ${ radio } " ) "
fi
fi
fi
fi
f_log "debug" " f_setif ::: enabled: ${ enabled } , section: ${ section } , active_sta: ${ trm_activesta :- "-" } , uplink_config: ${ trm_uplinkcfg :- "-" } "
f_log "debug" " f_setif ::: enabled: ${ enabled } , section: ${ section } , active_sta: ${ trm_activesta :- "-" } , uplink_config: ${ trm_uplinkcfg :- "-" } "
}
}
# add open uplinks
# add open uplinks
@ -508,7 +591,7 @@ f_addsta() {
f_log "info" " open uplink ' ${ radio } / ${ essid } ' added to wireless config "
f_log "info" " open uplink ' ${ radio } / ${ essid } ' added to wireless config "
fi
fi
fi
fi
f_log "debug" " f_addsta ::: radio: ${ radio :- "-" } , essid: ${ essid } , opensta/maxautoadd: ${ trm_opensta :- "-" } / ${ trm_maxautoadd :- "-" } , new_uplink: ${ new_uplink } , offset: ${ offset } "
f_log "debug" " f_addsta ::: radio: ${ radio :- "-" } , essid: ${ essid } , opensta/maxautoadd: ${ trm_opensta :- "-" } / ${ trm_maxautoadd :- "-" } , new_uplink: ${ new_uplink } , offset: ${ offset } "
}
}
# check net status
# check net status
@ -554,7 +637,7 @@ f_net() {
fi
fi
fi
fi
printf "%s" " ${ result } "
printf "%s" " ${ result } "
f_log "debug" " f_net ::: fetch: ${ trm_fetch } , timeout: $(( trm_maxwait / 6 )) , cp (json/html/js): ${ json_cp :- "-" } / ${ html_cp :- "-" } / ${ js_cp :- "-" } , result: ${ result } , error (rc/msg): ${ json_ec } / ${ err_msg :- "-" } , url: ${ trm_captiveurl } , user_agent: ${ trm_useragent } "
f_log "debug" " f_net ::: fetch: ${ trm_fetch } , timeout: $(( trm_maxwait / 6 )) , cp (json/html/js): ${ json_cp :- "-" } / ${ html_cp :- "-" } / ${ js_cp :- "-" } , result: ${ result } , error (rc/msg): ${ json_ec } / ${ err_msg :- "-" } , url: ${ trm_captiveurl } , user_agent: ${ trm_useragent } "
}
}
# check interface status
# check interface status
@ -688,13 +771,13 @@ f_check() {
wait_time = " $(( wait_time + 1 )) "
wait_time = " $(( wait_time + 1 )) "
sleep 1
sleep 1
done
done
f_log "debug" " f_check ::: mode: ${ mode } , name: ${ ifname :- "-" } , status: ${ trm_ifstatus } , enabled: ${ enabled } , connection: ${ trm_connection :- "-" } , wait: ${ wait_time } , 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 } , enabled: ${ enabled } , connection: ${ trm_connection :- "-" } , wait: ${ wait_time } , max_wait: ${ trm_maxwait } , min_quality: ${ trm_minquality } , captive: ${ trm_captive } , netcheck: ${ trm_netcheck } "
}
}
# update runtime information
# update runtime information
#
#
f_jsnup( ) {
f_jsnup( ) {
local vpn section last_date last_station sta_iface sta_radio sta_essid sta_bssid sta_mac dev_status last_status status = " ${ trm_ifstatus } " ntp_done = "0" vpn_done = "0" mail_done = "0"
local vpn vpn_iface section last_date last_station sta_iface sta_radio sta_essid sta_bssid sta_mac dev_status last_status status = " ${ trm_ifstatus } " ntp_done = "0" vpn_done = "0" mail_done = "0"
if [ " ${ status } " = "true" ] ; then
if [ " ${ status } " = "true" ] ; then
status = " connected ( ${ trm_connection :- "-" } ) "
status = " connected ( ${ trm_connection :- "-" } ) "
@ -707,7 +790,6 @@ f_jsnup() {
sta_bssid = " $( uci_get "wireless" " ${ section } " "bssid" ) "
sta_bssid = " $( uci_get "wireless" " ${ section } " "bssid" ) "
sta_mac = " $( f_mac "get" " ${ section } " ) "
sta_mac = " $( f_mac "get" " ${ section } " ) "
f_getcfg " ${ sta_radio } " " ${ sta_essid } " " ${ sta_bssid } "
f_getcfg " ${ sta_radio } " " ${ sta_essid } " " ${ sta_bssid } "
vpn = " $( f_getval "vpn" ) "
fi
fi
json_get_var last_date "last_run"
json_get_var last_date "last_run"
json_get_var last_station "station_id"
json_get_var last_station "station_id"
@ -720,6 +802,11 @@ f_jsnup() {
printf "%s" " ${ last_date } " >" ${ trm_ntpfile } "
printf "%s" " ${ last_date } " >" ${ trm_ntpfile } "
fi
fi
fi
fi
vpn = " $( f_getval "vpn" ) "
if [ " ${ trm_vpn } " = "1" ] && [ -n " ${ trm_vpninfolist } " ] && [ " ${ vpn } " = "1" ] && [ -f " ${ trm_vpnfile } " ] ; then
vpn_iface = " $( f_getval "vpniface" ) "
vpn_done = "1"
fi
elif [ " ${ status } " = "error" ] ; then
elif [ " ${ status } " = "error" ] ; then
unset trm_connection
unset trm_connection
status = "program error"
status = "program error"
@ -733,9 +820,6 @@ f_jsnup() {
if [ -s " ${ trm_ntpfile } " ] ; then
if [ -s " ${ trm_ntpfile } " ] ; then
ntp_done = "1"
ntp_done = "1"
fi
fi
if [ " ${ vpn } " = "1" ] && [ -f " ${ trm_vpnfile } " ] ; then
vpn_done = "1"
fi
if [ " ${ trm_mail } " = "1" ] && [ -f " ${ trm_mailfile } " ] ; then
if [ " ${ trm_mail } " = "1" ] && [ -f " ${ trm_mailfile } " ] ; then
mail_done = "1"
mail_done = "1"
fi
fi
@ -743,7 +827,7 @@ f_jsnup() {
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_mac" " ${ sta_mac :- "-" } "
json_add_string "station_mac" " ${ sta_mac :- "-" } "
json_add_string "station_interface" " ${ sta_iface :- "-" } "
json_add_string "station_interfaces " " ${ sta_iface :- "-" } , ${ vpn _iface :- "-" } "
json_add_string "wpa_flags" " ${ trm_wpaflags :- "-" } "
json_add_string "wpa_flags" " ${ trm_wpaflags :- "-" } "
json_add_string "run_flags" " captive: $( f_char ${ trm_captive } ) , proactive: $( f_char ${ trm_proactive } ) , netcheck: $( f_char ${ trm_netcheck } ) , autoadd: $( f_char ${ trm_autoadd } ) , randomize: $( f_char ${ trm_randomize } ) "
json_add_string "run_flags" " captive: $( f_char ${ trm_captive } ) , proactive: $( f_char ${ trm_proactive } ) , netcheck: $( f_char ${ trm_netcheck } ) , autoadd: $( f_char ${ trm_autoadd } ) , randomize: $( f_char ${ trm_randomize } ) "
json_add_string "ext_hooks" " ntp: $( f_char ${ ntp_done } ) , vpn: $( f_char ${ vpn_done } ) , mail: $( f_char ${ mail_done } ) "
json_add_string "ext_hooks" " ntp: $( f_char ${ ntp_done } ) , vpn: $( f_char ${ vpn_done } ) , mail: $( f_char ${ mail_done } ) "
@ -752,12 +836,12 @@ f_jsnup() {
json_dump >" ${ trm_rtfile } "
json_dump >" ${ trm_rtfile } "
if [ " ${ status %% (net ok/* } " = "connected" ] && [ " ${ trm_mail } " = "1" ] && [ -x " ${ trm_mailpgm } " ] && [ " ${ ntp_done } " = "1" ] && [ " ${ mail_done } " = "0" ] ; then
if [ " ${ status %% (net ok/* } " = "connected" ] && [ " ${ trm_mail } " = "1" ] && [ -x " ${ trm_mailpgm } " ] && [ " ${ ntp_done } " = "1" ] && [ " ${ mail_done } " = "0" ] ; then
if [ " ${ vpn } " != "1" ] || [ " ${ vpn_done } " = "1" ] ; then
if [ " ${ trm_ vpn} " != "1" ] || [ " ${ vpn } " != "1" ] || [ -z " ${ trm_vpninfolist } " ] || [ " ${ vpn_done } " = "1" ] ; then
: >" ${ trm_mailfile } "
: >" ${ trm_mailfile } "
" ${ trm_mailpgm } " >/dev/null 2>& 1
" ${ trm_mailpgm } " >/dev/null 2>& 1
fi
fi
fi
fi
f_log "debug" " f_jsnup ::: section: ${ section :- "-" } , status: ${ status :- "-" } , sta_iface: ${ sta_iface :- "-" } , sta_radio: ${ sta_radio :- "-" } , sta_essid: ${ sta_essid :- "-" } , sta_bssid: ${ sta_bssid :- "-" } , ntp: ${ ntp_done } , vpn: ${ vpn :- "0" } / ${ vpn_done } , mail: ${ trm_mail } / ${ mail_done } "
f_log "debug" " f_jsnup ::: section: ${ section :- "-" } , status: ${ status :- "-" } , sta_iface: ${ sta_iface :- "-" } , sta_radio: ${ sta_radio :- "-" } , sta_essid: ${ sta_essid :- "-" } , sta_bssid: ${ sta_bssid :- "-" } , ntp: ${ ntp_done } , vpn: ${ vpn :- "0" } / ${ vpn_done } , mail: ${ trm_mail } / ${ mail_done } "
}
}
# write to syslog
# write to syslog
@ -787,7 +871,7 @@ f_main() {
local station_id section sta sta_essid sta_bssid sta_radio sta_mac config_essid config_bssid config_radio
local station_id section sta sta_essid sta_bssid sta_radio sta_mac config_essid config_bssid config_radio
f_check "initial" "false"
f_check "initial" "false"
f_log "debug" " f_main-1 ::: status: ${ trm_ifstatus } , proactive: ${ trm_proactive } "
f_log "debug" " f_main-1 ::: status: ${ trm_ifstatus } , proactive: ${ trm_proactive } "
if [ " ${ trm_ifstatus } " != "true" ] || [ " ${ trm_proactive } " = "1" ] ; then
if [ " ${ trm_ifstatus } " != "true" ] || [ " ${ trm_proactive } " = "1" ] ; then
config_load wireless
config_load wireless
config_foreach f_setif wifi-iface " ${ trm_proactive } "
config_foreach f_setif wifi-iface " ${ trm_proactive } "
@ -799,12 +883,12 @@ f_main() {
config_bssid = " ${ station_id ##*/ } "
config_bssid = " ${ station_id ##*/ } "
config_bssid = " ${ config_bssid //-/ } "
config_bssid = " ${ config_bssid //-/ } "
f_check "dev" "true"
f_check "dev" "true"
f_log "debug" " f_main-2 ::: config_radio: ${ config_radio } , config_essid: \" ${ config_essid } \", config_bssid: ${ config_bssid :- "-" } "
f_log "debug" " f_main-2 ::: config_radio: ${ config_radio } , config_essid: \" ${ config_essid } \", config_bssid: ${ config_bssid :- "-" } "
else
else
uci_commit "wireless"
uci_commit "wireless"
f_check "dev" "false"
f_check "dev" "false"
fi
fi
f_log "debug" " f_main-3 ::: radio_list: ${ trm_radiolist :- "-" } , sta_list: ${ trm_stalist :- "-" } "
f_log "debug" " f_main-3 ::: radio_list: ${ trm_radiolist :- "-" } , sta_list: ${ trm_stalist :- "-" } "
# radio loop
# radio loop
#
#
@ -834,10 +918,10 @@ f_main() {
[ " ${ sta_essid } " = " ${ config_essid } " ] && [ " ${ sta_bssid } " = " ${ config_bssid } " ] ; then
[ " ${ sta_essid } " = " ${ config_essid } " ] && [ " ${ sta_bssid } " = " ${ config_bssid } " ] ; then
f_ctrack "refresh"
f_ctrack "refresh"
f_vpn "enable_keep"
f_vpn "enable_keep"
f_log "debug" " f_main-4 ::: config_radio: ${ config_radio } , config_essid: ${ config_essid } , config_bssid: ${ config_bssid :- "-" } "
f_log "debug" " f_main-4 ::: config_radio: ${ config_radio } , config_essid: ${ config_essid } , config_bssid: ${ config_bssid :- "-" } "
return 0
return 0
fi
fi
f_log "debug" " f_main-5 ::: sta_radio: ${ sta_radio } , sta_essid: \" ${ sta_essid } \", sta_bssid: ${ sta_bssid :- "-" } "
f_log "debug" " f_main-5 ::: sta_radio: ${ sta_radio } , sta_essid: \" ${ sta_essid } \", sta_bssid: ${ sta_bssid :- "-" } "
fi
fi
if [ -z " ${ scan_list } " ] ; then
if [ -z " ${ scan_list } " ] ; then
scan_dev = " $( ubus -S call network.wireless status 2>/dev/null | jsonfilter -q -l1 -e " @. ${ radio } .interfaces[0].ifname " ) "
scan_dev = " $( ubus -S call network.wireless status 2>/dev/null | jsonfilter -q -l1 -e " @. ${ radio } .interfaces[0].ifname " ) "
@ -845,7 +929,7 @@ f_main() {
awk ' BEGIN{ FS = "[[:space:]]" } /Address:/{ var1 = $NF } /ESSID:/{ var2 = "" ; for ( i = 12; i<= NF; i++) if ( var2 = = "" ) { var2 = $i } else { var2 = var2" " $i } }
awk ' BEGIN{ FS = "[[:space:]]" } /Address:/{ var1 = $NF } /ESSID:/{ var2 = "" ; for ( i = 12; i<= NF; i++) if ( var2 = = "" ) { var2 = $i } else { var2 = var2" " $i } }
/Quality:/{ split( $NF ,var0,"/" ) } /Encryption:/{ if ( $NF = = "none" ) { var3 = "+" } else { var3 = "-" } ;
/Quality:/{ split( $NF ,var0,"/" ) } /Encryption:/{ if ( $NF = = "none" ) { var3 = "+" } else { var3 = "-" } ;
printf "%i %s %s %s\n" ,( var0[ 1] *100/var0[ 2] ) ,var3,var1,var2} ' | sort -rn | head -qn " ${ trm_maxscan } " ) "
printf "%i %s %s %s\n" ,( var0[ 1] *100/var0[ 2] ) ,var3,var1,var2} ' | sort -rn | head -qn " ${ trm_maxscan } " ) "
f_log "debug" " f_main-6 ::: radio: ${ radio } , scan_device: ${ scan_dev } , scan_max: ${ trm_maxscan } "
f_log "debug" " f_main-6 ::: radio: ${ radio } , scan_device: ${ scan_dev } , scan_max: ${ trm_maxscan } "
if [ -z " ${ scan_list } " ] ; then
if [ -z " ${ scan_list } " ] ; then
f_log "info" " no scan results on ' ${ radio } ' "
f_log "info" " no scan results on ' ${ radio } ' "
continue 2
continue 2
@ -856,7 +940,7 @@ f_main() {
#
#
while read -r scan_quality scan_open scan_bssid scan_essid; do
while read -r scan_quality scan_open scan_bssid scan_essid; do
if [ -n " ${ scan_quality } " ] && [ -n " ${ scan_open } " ] && [ -n " ${ scan_bssid } " ] && [ -n " ${ scan_essid } " ] ; then
if [ -n " ${ scan_quality } " ] && [ -n " ${ scan_open } " ] && [ -n " ${ scan_bssid } " ] && [ -n " ${ scan_essid } " ] ; then
f_log "debug" " f_main-7 ::: radio(sta/scan): ${ sta_radio } / ${ radio } , essid(sta/scan): \" ${ sta_essid } \"/ ${ scan_essid } , bssid(sta/scan): ${ sta_bssid } / ${ scan_bssid } , quality(min/scan): ${ trm_minquality } / ${ scan_quality } , open: ${ scan_open } "
f_log "debug" " f_main-7 ::: radio(sta/scan): ${ sta_radio } / ${ radio } , essid(sta/scan): \" ${ sta_essid } \"/ ${ scan_essid } , bssid(sta/scan): ${ sta_bssid } / ${ scan_bssid } , quality(min/scan): ${ trm_minquality } / ${ scan_quality } , open: ${ scan_open } "
if [ " ${ scan_quality } " -ge " ${ trm_minquality } " ] ; then
if [ " ${ scan_quality } " -ge " ${ trm_minquality } " ] ; 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" ] ; } ; } && [ " ${ radio } " = " ${ sta_radio } " ] ; then
{ [ " ${ scan_bssid } " = " ${ sta_bssid } " ] && [ " ${ scan_essid } " = "unknown" ] ; } ; } && [ " ${ radio } " = " ${ sta_radio } " ] ; then