From de8ce5d025079485dd9ca7c04ccd153003504c0c Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Sun, 27 Sep 2020 06:57:44 +0200 Subject: [PATCH] travelmate: update to 2.0.1 * fix some remaining vpn issues * various cleanups Signed-off-by: Dirk Brenken --- net/travelmate/Makefile | 2 +- net/travelmate/files/README.md | 11 ++-- net/travelmate/files/db-bahn.login | 8 +-- net/travelmate/files/travelmate.mail | 22 +++----- net/travelmate/files/travelmate.sh | 81 ++++++++++++++++------------ net/travelmate/files/travelmate.vpn | 41 +++++++------- net/travelmate/files/wifionice.login | 2 +- 7 files changed, 91 insertions(+), 76 deletions(-) diff --git a/net/travelmate/Makefile b/net/travelmate/Makefile index 3f721b5279..468d4fc3b5 100644 --- a/net/travelmate/Makefile +++ b/net/travelmate/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=travelmate -PKG_VERSION:=2.0.0 +PKG_VERSION:=2.0.1 PKG_RELEASE:=1 PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Dirk Brenken diff --git a/net/travelmate/files/README.md b/net/travelmate/files/README.md index 06cb0e9629..b8079e39e6 100644 --- a/net/travelmate/files/README.md +++ b/net/travelmate/files/README.md @@ -1,3 +1,5 @@ + + # travelmate, a wlan connection manager for travel router ## Description @@ -40,7 +42,10 @@ To avoid these kind of deadlocks, travelmate will set all station interfaces to * optional: 'msmtp' to send out travelmate related status messages via email ## Installation & Usage -* before you start with travelmate you should setup at least one Access Point, ideally on a separate radio +* **Please note:** before you start with travelmate ... + * you should setup at least one Access Point, ideally on a separate radio, + * if you're updating from a former 1.x release, please use the '--force-reinstall --force-maintainer' options in opkg, + * and remove any existing travelmate related uplink stations in your wireless config manually * download [travelmate](https://downloads.openwrt.org/snapshots/packages/x86_64/packages) * download [luci-app-travelmate](https://downloads.openwrt.org/snapshots/packages/x86_64/luci) * install both packages (_opkg install travelmate_, _opkg install luci-app-travelmate_) @@ -86,7 +91,7 @@ To avoid these kind of deadlocks, travelmate will set all station interfaces to | Option | Default | Description/Valid Values | | :----------------- | :--------------------------------- | :---------------------------------------------------------------------------------------------------- | -| enabled | 1, enabled | enable or disable the uplink in travelmate | +| enabled | 1, enabled | enable or disable the uplink, automatically set if the retry limit or the conn. expiry was reached | | device | -, not set | match the 'device' in the wireless config section | | ssid | -, not set | match the 'ssid' in the wireless config section | | bssid | -, not set | match the 'bssid' in the wireless config section | @@ -166,7 +171,7 @@ root@2go_ar750s:~# /etc/init.d/travelmate status + system : GL.iNet GL-AR750S (NOR/NAND), OpenWrt SNAPSHOT r14430-2dda301d40 -To debug travelmate runtime problems, please always enable the 'trm\_debug' flag, restart travelmate and scan the system log (_logread -e "trm-"_) +To debug travelmate runtime problems, please always enable the 'trm\_debug' flag, restart travelmate and check the system log afterwards (_logread -e "trm-"_) ## 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) diff --git a/net/travelmate/files/db-bahn.login b/net/travelmate/files/db-bahn.login index f9cb122f6a..e419a95d83 100755 --- a/net/travelmate/files/db-bahn.login +++ b/net/travelmate/files/db-bahn.login @@ -3,14 +3,14 @@ # Copyright (c) 2020 Dirk Brenken (dev@brenken.org) # This is free software, licensed under the GNU General Public License v3. -trm_fetch="$(command -v curl)" trm_domain="wifi.bahn.de" trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")" trm_maxwait="$(uci_get travelmate global trm_maxwait "30")" +trm_fetch="$(command -v curl)" # initial get request to receive all header information # -"${trm_fetch}" -A "${trm_useragent}" "https://${trm_domain}" -si > "/tmp/${trm_domain}.cookie" +"${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait/6)) --include --cookie-jar "/tmp/${trm_domain}.cookie" --output /dev/null "http://${trm_domain}" # extract the session cookie and the hotspot location # @@ -27,7 +27,7 @@ fi # if [ -n "${php_token}" ] && [ -n "${location}" ] then - "${trm_fetch}" -A "${trm_useragent}" "https://${trm_domain}/portal_api.php" -H "Connection: keep-alive" -H "Referer: ${location}" -H "Cookie: ${php_token}" --data "action=subscribe&type=one&connect_policy_accept=false&user_login=&user_password=&user_password_confirm=&email_address=&prefix=&phone=&policy_accept=false&gender=&interests=" -si > "/tmp/${trm_domain}.cookie" + "${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --include --cookie-jar "/tmp/${trm_domain}.cookie" --header "Cookie: ${php_token}" --data "action=subscribe&type=one&connect_policy_accept=false&user_login=&user_password=&user_password_confirm=&email_address=&prefix=&phone=&policy_accept=false&gender=&interests=" --output /dev/null "https://${trm_domain}/portal_api.php" else exit 3 fi @@ -47,7 +47,7 @@ fi # if [ -n "${login}" ] && [ -n "${password}" ] then - "${trm_fetch}" -A "${trm_useragent}" "https://${trm_domain}/portal_api.php" -H "Connection: keep-alive" -H "Referer: ${location}" -H "Cookie: ${php_token}" --data "action=authenticate&login=${login}&password=${password}&policy_accept=false&from_ajax=true&wispr_mode=false" + "${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --header "Cookie: ${php_token}" --data "action=authenticate&login=${login}&password=${password}&policy_accept=false&from_ajax=true&wispr_mode=false" "https://${trm_domain}/portal_api.php" else exit 5 fi diff --git a/net/travelmate/files/travelmate.mail b/net/travelmate/files/travelmate.mail index 859bf1f117..a8b10e6d79 100755 --- a/net/travelmate/files/travelmate.mail +++ b/net/travelmate/files/travelmate.mail @@ -13,13 +13,12 @@ PATH="/usr/sbin:/usr/bin:/sbin:/bin" . "/lib/functions.sh" trm_debug="$(uci_get travelmate global trm_debug "0")" -trm_mailsender="$(uci_get travelmate global trm_mailsender "no-reply@travelmate")" trm_mailreceiver="$(uci_get travelmate global trm_mailreceiver)" trm_mailprofile="$(uci_get travelmate global trm_mailprofile "trm_notify")" -trm_mail="$(command -v msmtp)" +trm_mailsender="$(uci_get travelmate global trm_mailsender "no-reply@travelmate")" trm_rtfile="$(uci_get travelmate global trm_rtfile "/tmp/trm_runtime.json")" +trm_mailpgm="$(command -v msmtp)" trm_logger="$(command -v logger)" -trm_rc=1 f_log() { @@ -36,10 +35,10 @@ f_log() if [ -z "${trm_mailreceiver}" ] then f_log "err" "please set the mail receiver with the 'trm_mailreceiver' option" - exit ${trm_rc} + exit 1 fi -if [ "${trm_debug}" -eq 1 ] +if [ "${trm_debug}" -eq "1" ] then debug="--debug" fi @@ -61,12 +60,7 @@ trm_mailtext="${trm_mailtext}" # send mail # -if [ -x "${trm_mail}" ] -then - printf "%b" "${trm_mailhead}${trm_mailtext}" 2>/dev/null | "${trm_mail}" ${debug} -a "${trm_mailprofile}" "${trm_mailreceiver}" >/dev/null 2>&1 - trm_rc=${?} - f_log "info" "mail sent to '${trm_mailreceiver}' with rc '${trm_rc}'" -else - f_log "err" "msmtp mail daemon not found" -fi -exit ${trm_rc} +printf "%b" "${trm_mailhead}${trm_mailtext}" 2>/dev/null | "${trm_mailpgm}" ${debug} -a "${trm_mailprofile}" "${trm_mailreceiver}" >/dev/null 2>&1 +mail_rc="${?}" +f_log "info" "mail sent to '${trm_mailreceiver}' with rc '${mail_rc}'" +exit ${mail_rc} diff --git a/net/travelmate/files/travelmate.sh b/net/travelmate/files/travelmate.sh index 0a85cc2353..d8ef004943 100755 --- a/net/travelmate/files/travelmate.sh +++ b/net/travelmate/files/travelmate.sh @@ -11,7 +11,7 @@ export LC_ALL=C export PATH="/usr/sbin:/usr/bin:/sbin:/bin" set -o pipefail -trm_ver="2.0.0" +trm_ver="2.0.1" trm_enabled=0 trm_debug=0 trm_iface="" @@ -42,7 +42,9 @@ trm_wpa="$(command -v wpa_supplicant)" trm_captiveurl="http://captive.apple.com" trm_useragent="Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0" trm_ntpfile="/var/state/travelmate.ntp" +trm_vpnfile="/var/state/travelmate.vpn" trm_mailfile="/var/state/travelmate.mail" +trm_refreshfile="/var/state/travelmate.refresh" trm_pidfile="/var/run/travelmate.pid" trm_action="${1:-"start"}" @@ -72,20 +74,7 @@ f_env() # if [ ! -r "/etc/config/travelmate" ] || [ -z "$(uci -q show travelmate.global.trm_vpn)" ] then - if { [ -r "/etc/config/travelmate-opkg" ] && [ -n "$(uci -q show travelmate.global.trm_vpn)" ]; } || \ - { [ -r "/rom/etc/config/travelmate" ] && [ -n "$(uci -q show /rom/etc/config/travelmate.global.trm_vpn)" ]; } - then - if [ -r "/etc/config/travelmate-opkg" ] - then - cp -pf "/etc/config/travelmate-opkg" "/etc/config/travelmate" - elif [ -r "/rom/etc/config/travelmate" ] - then - cp -pf "/rom/etc/config/travelmate" "/etc/config/travelmate" - fi - f_log "info" "missing or old travelmate config replaced with a new one" - else - f_log "err" "unrecoverable travelmate config error, please re-install the package via opkg with the '--force-reinstall --force-maintainer' options" - fi + f_log "err" "no valid travelmate config found, please re-install the package via opkg with the '--force-reinstall --force-maintainer' options" fi # load travelmate config @@ -241,16 +230,27 @@ f_reconf() # f_vpn() { - local IFS action="${1}" + local IFS rc action="${1}" if [ "${trm_vpn}" -eq "1" ] && [ -x "${trm_vpnpgm}" ] then - "${trm_vpnpgm}" "${action}" >/dev/null 2>&1 + if [ "${action}" = "disable" ] || { [ "${action}" = "enable" ] && [ ! -f "${trm_vpnfile}" ]; } + then + "${trm_vpnpgm}" "${action}" >/dev/null 2>&1 + rc="${?}" + fi + if [ "${action}" = "enable" ] && [ "${rc}" -eq "0" ] + then + > "${trm_vpnfile}" + elif [ "${action}" = "disable" ] && [ -f "${trm_vpnfile}" ] + then + rm -f "${trm_vpnfile}" + fi fi - f_log "debug" "f_vpn ::: vpn: ${trm_vpn}, vpnservice: ${trm_vpnservice:-"-"}, vpnpgm: ${trm_vpnpgm}, action: ${action}" + f_log "debug" "f_vpn ::: vpn: ${trm_vpn}, vpnservice: ${trm_vpnservice:-"-"}, vpnpgm: ${trm_vpnpgm}, action: ${action}, rc: ${rc:-"-"}" } -# mac helper function +# mac randomizer helper function # f_mac() { @@ -343,9 +343,9 @@ f_contrack() if [ -n "$(uci -q changes "travelmate")" ] then uci_commit "travelmate" - if [ ! -f "/var/run/travelmate.refresh" ] + if [ ! -f "${trm_refreshfile}" ] then - printf "%s" "cfg_reload" > "/var/run/travelmate.refresh" + printf "%s" "cfg_reload" > "${trm_refreshfile}" fi fi fi @@ -450,9 +450,9 @@ f_addif() uci_commit "travelmate" uci_commit "wireless" f_reconf - if [ ! -f "/var/run/travelmate.refresh" ] + if [ ! -f "${trm_refreshfile}" ] then - printf "%s" "ui_reload" > "/var/run/travelmate.refresh" + printf "%s" "ui_reload" > "${trm_refreshfile}" fi f_log "info" "open uplink '${radio}/${essid}' added to wireless config" fi @@ -637,7 +637,7 @@ f_check() then login_script_args="$(f_uplink "script_args" "${sta_radio}" "${sta_essid}" "${sta_bssid}")" "${login_script}" ${login_script_args} >/dev/null 2>&1 - rc=${?} + rc="${?}" f_log "info" "captive portal login '${login_script:0:40} ${login_script_args:0:20}' for '${cp_domain}' has been executed with rc '${rc}'" if [ "${rc}" -eq "0" ] then @@ -713,7 +713,7 @@ f_check() # f_jsnup() { - local IFS section bg_pid last_date last_station sta_iface sta_radio sta_essid sta_bssid sta_mac dev_status last_status status="${trm_ifstatus}" ntp_sync="0" + local IFS 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 @@ -757,12 +757,18 @@ f_jsnup() then last_date="$(date "+%Y.%m.%d-%H:%M:%S")" fi - if [ -s "${trm_ntpfile}" ] then - ntp_sync="1" + ntp_done="1" + fi + if [ "${trm_vpn}" -eq "1" ] && [ -f "${trm_vpnfile}" ] + then + vpn_done="1" + fi + if [ "${trm_mail}" -eq "1" ] && [ -f "${trm_mailfile}" ] + then + mail_done="1" fi - json_add_string "travelmate_status" "${status}" json_add_string "travelmate_version" "${trm_ver}" json_add_string "station_id" "${sta_radio:-"-"}/${sta_essid:-"-"}/${sta_bssid:-"-"}" @@ -770,7 +776,7 @@ f_jsnup() json_add_string "station_interface" "${sta_iface:-"-"}" 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 "ext_hooks" "ntp: $(f_char ${ntp_sync}), vpn: $(f_char ${trm_vpn}), mail: $(f_char ${trm_mail})" + json_add_string "ext_hooks" "ntp: $(f_char ${ntp_done}), vpn: $(f_char ${vpn_done}), mail: $(f_char ${mail_done})" json_add_string "last_run" "${last_date}" json_add_string "system" "${trm_sysver}" json_dump > "${trm_rtfile}" @@ -778,16 +784,18 @@ f_jsnup() if [ "${status%% (net ok/*}" = "connected" ] then f_vpn "enable" - if [ "${trm_mail}" -eq "1" ] && [ -x "${trm_mailpgm}" ] && [ -s "${trm_ntpfile}" ] && [ ! -f "${trm_mailfile}" ] + if [ "${trm_mail}" -eq "1" ] && [ -x "${trm_mailpgm}" ] && [ "${ntp_done}" = "1" ] && [ "${mail_done}" = "0" ] then - > "${trm_mailfile}" - ( "${trm_mailpgm}" >/dev/null 2>&1 )& - bg_pid="${!}" + if [ "${trm_vpn}" -eq "0" ] || [ "${vpn_done}" -eq "1" ] + then + > "${trm_mailfile}" + "${trm_mailpgm}" >/dev/null 2>&1 + fi fi else f_vpn "disable" 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:-"-"}, vpn: ${trm_vpn}, mail: ${trm_mail}, mail_pid: ${bg_pid:-"-"}" + 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: ${trm_vpn}/${vpn_done}, mail: ${trm_mail}/${mail_done}" } # write to syslog @@ -994,7 +1002,10 @@ fi # control travelmate actions # -f_env +if [ "${trm_action}" != "stop" ] +then + f_env +fi while true do if [ -z "${trm_action}" ] diff --git a/net/travelmate/files/travelmate.vpn b/net/travelmate/files/travelmate.vpn index f0ca8fab69..87c18c5757 100755 --- a/net/travelmate/files/travelmate.vpn +++ b/net/travelmate/files/travelmate.vpn @@ -12,7 +12,7 @@ LC_ALL=C PATH="/usr/sbin:/usr/bin:/sbin:/bin" . "/lib/functions.sh" -trm_action="${1}" +vpn_action="${1}" trm_vpnservice="$(uci_get travelmate global trm_vpnservice)" trm_vpniface="$(uci_get travelmate global trm_vpniface)" trm_landevice="$(uci_get travelmate global trm_landevice)" @@ -58,40 +58,40 @@ if [ -n "${trm_vpnservice}" ] && [ -n "${trm_vpniface}" ] && [ -n "${trm_landevi then status="$(jsonfilter -i "/tmp/trm_runtime.json" -l1 -e '@.data.travelmate_status' 2>/dev/null)" vpn_status="$(ubus -S call network.interface."${trm_vpniface}" status 2>/dev/null | jsonfilter -l1 -e '@.up')" - if [ "${trm_action}" = "disable" ] && [ "${vpn_status}" = "true" ] + if [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ] then if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 2>&1)" ] then "${trm_iptables}" "-w $((trm_maxwait/6))" -I ${trm_iptrule_drop} 2>&1 f_log "info" "lan forward blocked for device '${trm_landevice}'" fi - if [ "${status%% (net cp *}" = "connected" ] + fi + if [ "${vpn_action}" = "disable" ] && [ "${status%% (net cp *}" = "connected" ] + then + if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ] then - if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ] - then - "${trm_iptables}" "-w $((trm_maxwait/6))" -I ${trm_iptrule_accept} 2>&1 - f_log "info" "lan forward on ports 80/443 freed for device '${trm_landevice}'" - fi + "${trm_iptables}" "-w $((trm_maxwait/6))" -I ${trm_iptrule_accept} 2>&1 + f_log "info" "lan forward on ports 80/443 freed for device '${trm_landevice}'" fi fi case "${trm_vpnservice}" in "wireguard") - if [ "${trm_action}" = "enable" ] && [ "${vpn_status}" != "true" ] + if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ] then ubus call network.interface."${trm_vpniface}" up - elif [ "${trm_action}" = "disable" ] && [ "${vpn_status}" = "true" ] + elif [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ] then ubus call network.interface."${trm_vpniface}" down f_log "info" "${trm_vpnservice} client connection disabled" fi ;; "openvpn") - if [ "${trm_action}" = "enable" ] && [ "${vpn_status}" != "true" ] + if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ] then ubus call network.interface."${trm_vpniface}" up /etc/init.d/openvpn restart >/dev/null 2>&1 - elif [ "${trm_action}" = "disable" ] && [ "${vpn_status}" = "true" ] + elif [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ] then ubus call network.interface."${trm_vpniface}" down /etc/init.d/openvpn stop >/dev/null 2>&1 @@ -100,7 +100,7 @@ then ;; esac - if [ "${trm_action}" = "enable" ] && [ "${vpn_status}" != "true" ] + if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ] then cnt=0 while true @@ -121,10 +121,6 @@ then fi f_log "info" "lan forward freed for device '${trm_landevice}'" fi - if [ -f "/etc/init.d/sysntpd" ] - then - /etc/init.d/sysntpd restart >/dev/null 2>&1 - fi break fi fi @@ -132,10 +128,19 @@ then then f_log "info" "${trm_vpnservice} restart failed, lan forward for device '${trm_landevice}' still blocked" ubus call network.interface."${trm_vpniface}" down - break + exit 2 fi sleep 1 cnt="$((cnt+1))" done fi + if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" = "true" ] + then + if [ -f "/etc/init.d/sysntpd" ] + then + /etc/init.d/sysntpd restart >/dev/null 2>&1 + fi + fi + exit 0 fi +exit 1 diff --git a/net/travelmate/files/wifionice.login b/net/travelmate/files/wifionice.login index 6ff93b8f15..79a1c8e6ea 100755 --- a/net/travelmate/files/wifionice.login +++ b/net/travelmate/files/wifionice.login @@ -3,10 +3,10 @@ # Copyright (c) 2020 Dirk Brenken (dev@brenken.org) # This is free software, licensed under the GNU General Public License v3. -trm_fetch="$(command -v curl)" trm_domain="www.wifionice.de" trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")" trm_maxwait="$(uci_get travelmate global trm_maxwait "30")" +trm_fetch="$(command -v curl)" # initial get request to receive & extract a valid security token # -- 2.30.2