mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 15:38:40 +01:00
travelmate: update to release 2.0
- new package dependency: curl (plus one of the wpad variants) - optional package dependencies: - 'msmtp' for email notification support - 'wireguard' or 'openvpn' for vpn support - removed WEP support, only WPA/WPA2/WPA3 are supported! - new, more robust setup wizard (CLI and LuCI) - more robust captive portal detection - randomize mac addresses with every uplnk connect - automatic vpn handling during uplink switch (only classic/simple client-setups for wireguard or openvpn are supported) - email notifications after successful uplink connections - automatically disable uplinks after n minutes, e.g. for timed connections - automatically (re-)enable uplinks after n minutes, e.g. after failed login attempts - complete LuCI rewrite - migrated to client side JS (separate PR) Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
# set (s)hellcheck exceptions
|
||||
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
|
||||
|
||||
START=25
|
||||
USE_PROCD=1
|
||||
|
||||
EXTRA_COMMANDS="status_service"
|
||||
EXTRA_COMMANDS="scan setup"
|
||||
EXTRA_HELP=" scan <radio> Scan for available nearby uplinks
|
||||
setup [<iface>] [<zone>] [<metric>] Setup the travelmate uplink interface, by default 'trm_wwan' with firewall zone 'wan' and metric '100'"
|
||||
|
||||
trm_init="/etc/init.d/travelmate"
|
||||
trm_script="/usr/bin/travelmate.sh"
|
||||
@@ -11,20 +16,21 @@ trm_pidfile="/var/run/travelmate.pid"
|
||||
|
||||
boot()
|
||||
{
|
||||
local iface="$(uci_get travelmate global trm_iface)"
|
||||
|
||||
ubus -t 30 wait_for network.wireless network.interface."${iface:-"trm_wwan"}" 2>/dev/null
|
||||
if [ -s "${trm_pidfile}" ]
|
||||
then
|
||||
> "${trm_pidfile}"
|
||||
fi
|
||||
rc_procd start_service
|
||||
}
|
||||
|
||||
start_service()
|
||||
{
|
||||
if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
|
||||
if [ "$("${trm_init}" enabled; printf "%u" ${?})" -eq "0" ]
|
||||
then
|
||||
procd_open_instance "travelmate"
|
||||
procd_set_param command "${trm_script}" "${@}"
|
||||
procd_set_param pidfile "${trm_pidfile}"
|
||||
procd_set_param nice "$(uci_get travelmate extra trm_nice "0")"
|
||||
procd_set_param nice "$(uci_get travelmate global trm_nice "0")"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_close_instance
|
||||
@@ -33,7 +39,9 @@ start_service()
|
||||
|
||||
reload_service()
|
||||
{
|
||||
local ppid pid timeout="$(uci_get travelmate global trm_timeout)"
|
||||
local ppid pid timeout
|
||||
|
||||
timeout="$(uci_get travelmate global trm_timeout)"
|
||||
|
||||
if [ -s "${trm_pidfile}" ]
|
||||
then
|
||||
@@ -56,9 +64,9 @@ stop_service()
|
||||
|
||||
status_service()
|
||||
{
|
||||
local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
|
||||
local key keylist value rtfile
|
||||
|
||||
rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
|
||||
rtfile="$(uci_get travelmate global trm_rtfile "/tmp/trm_runtime.json")"
|
||||
json_load_file "${rtfile}" >/dev/null 2>&1
|
||||
json_select data >/dev/null 2>&1
|
||||
if [ ${?} -eq 0 ]
|
||||
@@ -75,18 +83,113 @@ status_service()
|
||||
fi
|
||||
}
|
||||
|
||||
scan()
|
||||
{
|
||||
local result scan_dev radio="${1:-"radio0"}"
|
||||
|
||||
scan_dev="$(ubus -S call network.wireless status 2>/dev/null | jsonfilter -l1 -e "@.${radio}.interfaces[0].ifname")"
|
||||
result="$(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}}/Channel:/{var3=$NF}/Quality:/{split($NF,var0,"/")}/Encryption:/{var4="";
|
||||
for(j=12;j<=NF;j++)if(var4==""){var4=$j}else{var4=var4" "$j};printf " %-11i%-10s%-35s%-20s%s\n",(var0[1]*100/var0[2]),var3,var2,var1,var4}' | \
|
||||
sort -rn)"
|
||||
printf "%s\\n" "::: Available nearby uplinks on '${scan_dev:-${radio}}'"
|
||||
printf "%s\\n" ":::"
|
||||
if [ -n "${result}" ]
|
||||
then
|
||||
printf "%-15s%-10s%-35s%-20s%s\\n" " Strength" "Channel" "ESSID" "BSSID" "Encryption"
|
||||
printf "%s\\n" " --------------------------------------------------------------------------------------"
|
||||
printf "%s\\n" "${result}"
|
||||
else
|
||||
printf "%s\\n" "::: No scan results"
|
||||
fi
|
||||
}
|
||||
|
||||
setup()
|
||||
{
|
||||
local iface cnt=0 input="${1:-"trm_wwan"}" zone="${2:-"wan"}" metric="${3:-"100"}"
|
||||
|
||||
iface="$(uci_get travelmate global trm_iface)"
|
||||
input="${input//[+*~%&\$@\"\' ]/}"
|
||||
zone="${zone//[+*~%&\$@\"\' ]/}"
|
||||
metric="${metric//[^0-9]/}"
|
||||
|
||||
if [ -n "${iface}" ] && [ "${iface}" = "${input}" ]
|
||||
then
|
||||
printf "%s\n" "The uplink interface '${input}' has been already configured"
|
||||
elif [ -n "${input}" ]
|
||||
then
|
||||
if [ -n "${iface}" ]
|
||||
then
|
||||
uci -q batch <<-EOC
|
||||
del network."${iface}"
|
||||
del network."${iface}6"
|
||||
EOC
|
||||
fi
|
||||
uci -q batch <<-EOC
|
||||
set travelmate.global.trm_enabled="1"
|
||||
set travelmate.global.trm_iface="${input}"
|
||||
set network."${input}"="interface"
|
||||
set network."${input}".proto="dhcp"
|
||||
set network."${input}".metric="${metric}"
|
||||
set network."${input}6"=interface
|
||||
set network."${input}6".ifname="@${input}"
|
||||
set network."${input}6".proto="dhcpv6"
|
||||
commit travelmate
|
||||
commit network
|
||||
EOC
|
||||
|
||||
while [ -n "$(uci -q get firewall.@zone["${cnt}"].name)" ]
|
||||
do
|
||||
if [ "$(uci -q get firewall.@zone["${cnt}"].name)" = "${zone}" ]
|
||||
then
|
||||
if [ -n "${iface}" ]
|
||||
then
|
||||
uci -q batch <<-EOC
|
||||
del_list firewall.@zone["${cnt}"].network="${iface}"
|
||||
del_list firewall.@zone["${cnt}"].network="${iface}6"
|
||||
EOC
|
||||
fi
|
||||
uci -q batch <<-EOC
|
||||
add_list firewall.@zone["${cnt}"].network="${input}"
|
||||
add_list firewall.@zone["${cnt}"].network="${input}6"
|
||||
commit firewall
|
||||
EOC
|
||||
break
|
||||
fi
|
||||
cnt=$((cnt+1))
|
||||
done
|
||||
|
||||
if [ -n "${iface}" ]
|
||||
then
|
||||
cnt=0
|
||||
while [ -n "$(uci -q get wireless.@wifi-iface["${cnt}"].network)" ]
|
||||
do
|
||||
if [ "$(uci -q get wireless.@wifi-iface["${cnt}"].network)" = "${iface}" ]
|
||||
then
|
||||
uci -q set wireless.@wifi-iface["${cnt}"].network="${input}"
|
||||
fi
|
||||
cnt=$((cnt+1))
|
||||
done
|
||||
uci -q commit wireless
|
||||
fi
|
||||
/etc/init.d/network reload >/dev/null 2>&1
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
"${trm_init}" restart
|
||||
fi
|
||||
}
|
||||
|
||||
service_triggers()
|
||||
{
|
||||
local trigger="$(uci_get travelmate global trm_iface)"
|
||||
local delay="$(uci_get travelmate global trm_triggerdelay)"
|
||||
local iface delay
|
||||
|
||||
PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
|
||||
if [ -n "${trigger}" ]
|
||||
iface="$(uci_get travelmate global trm_iface)"
|
||||
delay="$(uci_get travelmate global trm_triggerdelay "2")"
|
||||
PROCD_RELOAD_DELAY=$((delay * 1000))
|
||||
|
||||
if [ -n "${iface}" ]
|
||||
then
|
||||
procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" reload
|
||||
else
|
||||
procd_add_raw_trigger "interface.*.down" ${PROCD_RELOAD_DELAY} "${trm_init}" reload
|
||||
procd_add_interface_trigger "interface.*.down" "${iface}" "${trm_init}" reload
|
||||
fi
|
||||
procd_add_config_trigger "config.change" "wireless" "${trm_init}" reload
|
||||
procd_add_config_trigger "config.change" "travelmate" "${trm_init}" restart
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user