trm_maxretry="3"
trm_maxwait="30"
trm_maxautoadd="5"
-trm_maxscan="10"
trm_timeout="60"
trm_radio=""
trm_connection=""
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##*&&}"
+ if [ "${iface}" = "${info}" ]; then
+ vpn_instance=""
+ else
+ vpn_instance="${info##*&&}"
+ fi
vpn_status="$(ifstatus "${iface}" | "${trm_jsoncmd}" -ql1 -e '@.up')"
if [ "${vpn_status}" = "true" ]; then
/sbin/ifdown "${iface}"
"${trm_ubuscmd}" -S call network.interface."${iface}" remove >/dev/null 2>&1
- 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
+ if [ -x "/etc/init.d/openvpn" ] && [ -n "${vpn_instance}" ] && /etc/init.d/openvpn running "${vpn_instance}"; then
+ /etc/init.d/openvpn stop "${vpn_instance}"
+ f_log "info" "take down openvpn instance '${vpn_instance:-"-"}' (initial)"
+ fi
done
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##*&&}"
+ if [ "${iface}" = "${info}" ]; then
+ vpn_instance=""
+ else
+ vpn_instance="${info##*&&}"
+ fi
vpn_status="$(ifstatus "${iface}" | "${trm_jsoncmd}" -ql1 -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
+ /sbin/ifdown "${iface}"
f_log "info" "take down vpn interface '${iface}/${vpn_instance:-"-"}' (switch)"
- rm -f "${trm_vpnfile}"
- break
fi
+ if [ -x "/etc/init.d/openvpn" ] && [ -n "${vpn_instance}" ] && /etc/init.d/openvpn running "${vpn_instance}"; then
+ /etc/init.d/openvpn stop "${vpn_instance}"
+ f_log "info" "take down openvpn instance '${vpn_instance:-"-"}' (switch)"
+ fi
+ rm -f "${trm_vpnfile}"
+ break
done
fi
if [ -x "${trm_vpnpgm}" ] && [ -n "${vpn_service}" ] && [ -n "${vpn_iface}" ]; then
if { [ "${vpn_action}" = "disable" ] && [ -f "${trm_vpnfile}" ]; } ||
- { [ -s "${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
+ { [ -s "${trm_ntpfile}" ] && { [ "${vpn}" = "1" ] && [ "${vpn_action%%_*}" = "enable" ] && [ ! -f "${trm_vpnfile}" ]; } ||
+ { [ "${vpn}" != "1" ] && [ "${vpn_action%%_*}" = "enable" ] && [ -f "${trm_vpnfile}" ]; }; }; then
+ if [ "${trm_connection%%/*}" = "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##*&&}"
+ if [ "${iface}" = "${info}" ]; then
+ vpn_instance=""
+ else
+ vpn_instance="${info##*&&}"
+ fi
break
fi
done
network_get_gateway wan4_gw "${wan4_if}"
network_get_gateway6 wan6_gw "${wan6_if}"
if [ -n "${wan4_gw}" ] || [ -n "${wan6_gw}" ]; then
- result="${wan4_gw} ${wan6_gw}"
+ result="true"
fi
printf "%s" "${result}"
f_log "debug" "f_getgw ::: wan4_gw: ${wan4_gw:-"-"}, wan6_gw: ${wan6_gw:-"-"}, result: ${result:-"-"}"
if [ -n "${json_ed}" ] && [ "${json_ed}" != "${trm_captiveurl#http*://*}" ]; then
result="net cp '${json_ed}'"
fi
- elif [ "${json_ec}" = "28" ]; then
- if [ -n "$(f_getgw)" ]; then
- result="net ok"
- fi
fi
fi
fi
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}"
}
# check interface status
login_script_args="$(f_getval "script_args")"
"${login_script}" ${login_script_args} >/dev/null 2>&1
rc="${?}"
- if [ "${rc}" = "255" ]; then
- f_log "info" "captive portal login script for '${cp_domain}' failed with rc '${rc}'"
- unset trm_connection
- trm_ifstatus="${status}"
- f_jsnup
- break
- else
- f_log "info" "captive portal login script for '${cp_domain}' has been finished with rc '${rc}'"
- if [ "${rc}" = "0" ]; then
- result="$(f_net)"
- fi
+ f_log "info" "captive portal login script for '${cp_domain}' has been finished with rc '${rc}'"
+ if [ "${rc}" = "0" ]; then
+ result="$(f_net)"
fi
fi
fi
scan_list="$("${trm_iwinfo}" "${scan_dev:-${radio}}" scan 2>/dev/null |
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="-"};
- 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}"
+ printf "%i %s %s %s\n",(var0[1]*100/var0[2]),var3,var1,var2}' | sort -rn)"
+ f_log "debug" "f_main-6 ::: radio: ${radio}, scan_device: ${scan_dev}, scan_cnt: $(printf "%s" "${scan_list}" | grep -c "^")"
if [ -z "${scan_list}" ]; then
f_log "info" "no scan results on '${radio}'"
continue 2
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
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}" -lt "${trm_minquality}" ]; then
+ continue 3
+ elif [ "${scan_quality}" -ge "${trm_minquality}" ]; then
if [ "${trm_autoadd}" = "1" ] && [ "${scan_open}" = "+" ] && [ "${scan_essid}" != "unknown" ]; then
open_essid="${scan_essid%?}"
open_essid="${open_essid:1}"
if [ "${retrycnt}" = "${trm_maxretry}" ]; then
f_ctrack "disabled"
f_log "info" "uplink has been disabled '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${retrycnt}/${trm_maxretry})"
- break 2
+ continue 2
else
f_jsnup
f_log "info" "can't connect to uplink '${sta_radio}/${sta_essid}/${sta_bssid:-"-"}' (${retrycnt}/${trm_maxretry})"