travelmate: update to 2.0.7 16612/head
authorDirk Brenken <dev@brenken.org>
Sat, 11 Sep 2021 16:23:35 +0000 (18:23 +0200)
committerDirk Brenken <dev@brenken.org>
Sat, 11 Sep 2021 16:23:35 +0000 (18:23 +0200)
* add wpa-supplicant package dependency
* removed no longer working 'db-bahn.login' and 'wifionice.login' auto-login scripts
* added the new 'wifibahn.login' script for auto-logins to captive portals WIFI@BAHN (DE),
  run tested on a single ICE (station logins are currently unsupported!)
* vodafone.login prepared to support free/time limited logins (still WIP!)
* change return code handling in login scripts and travelmate
* refine f_wifi function
* fix a few conercase issues

Signed-off-by: Dirk Brenken <dev@brenken.org>
13 files changed:
net/travelmate/Makefile
net/travelmate/files/chs-hotel.login
net/travelmate/files/db-bahn.login [deleted file]
net/travelmate/files/generic-user-pass.login
net/travelmate/files/h-hotels.login
net/travelmate/files/julianahoeve.login
net/travelmate/files/telekom.login
net/travelmate/files/travelmate.mail
net/travelmate/files/travelmate.sh
net/travelmate/files/travelmate.vpn
net/travelmate/files/vodafone.login
net/travelmate/files/wifibahn.login [new file with mode: 0755]
net/travelmate/files/wifionice.login [deleted file]

index d8914cd8f7767a0aa6183529dc533ee60b828a16..10f511e48a5add5b2a82900daea25d6c6781d136 100644 (file)
@@ -6,7 +6,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=travelmate
-PKG_VERSION:=2.0.6
+PKG_VERSION:=2.0.7
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0-or-later
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
@@ -17,7 +17,7 @@ define Package/travelmate
        SECTION:=net
        CATEGORY:=Network
        TITLE:=A wlan connection manager for travel router
-       DEPENDS:=+iwinfo +jshn +jsonfilter +curl +ca-bundle
+       DEPENDS:=+iwinfo +jshn +jsonfilter +curl +ca-bundle +wpa-supplicant
        PKGARCH:=all
 endef
 
index 905824ad79680e7a71b1c3c101441c2e7d346e99..76aa14ef6b7cbd4c147241c7bcad545e729c7628 100755 (executable)
@@ -6,16 +6,12 @@
 # set (s)hellcheck exceptions
 # shellcheck disable=1091,2181,3040
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
 trm_domain="hotspot.internet-for-guests.com"
 trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
 trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
@@ -28,13 +24,9 @@ lg_id="$(awk '/LGNSID/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
 ta_id="$(awk '/ta_id/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
 cl_id="$(awk '/cl_id/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
 rm -f "/tmp/${trm_domain}.cookie"
-if [ -z "${lg_id}" ] || [ -z "${ta_id}" ] || [ -z "${cl_id}" ]; then
-       exit 1
-fi
+{ [ -z "${lg_id}" ] || [ -z "${ta_id}" ] || [ -z "${cl_id}" ]; } && exit 1
 
 # final login request
 #
 "${trm_fetch}" --user-agent "${trm_useragent}" --referer "https://${trm_domain}/logon/cgi/index.cgi" --silent --connect-timeout $((trm_maxwait / 6)) --header "Cookie: LGNSID=${lg_id}; lang=en_US; use_mobile_interface=0; ta_id=${ta_id}; cl_id=${cl_id}" --data "accept_termsofuse=&freeperperiod=1&device_infos=1125:2048:1152:2048" --output /dev/null "https://${trm_domain}/logon/cgi/index.cgi"
-if [ "${?}" != "0" ]; then
-       exit 2
-fi
+[ "${?}" = "0" ] && exit 0 || exit 255
diff --git a/net/travelmate/files/db-bahn.login b/net/travelmate/files/db-bahn.login
deleted file mode 100755 (executable)
index 2b4bf30..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-# captive portal auto-login script for DB hotspots (DE)
-# Copyright (c) 2020-2021 Dirk Brenken (dev@brenken.org)
-# This is free software, licensed under the GNU General Public License v3.
-
-# set (s)hellcheck exceptions
-# shellcheck disable=1091,2181,3040
-
-export LC_ALL=C
-export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-set -o pipefail
-
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
-trm_domain="wifi.bahn.de"
-trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
-trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
-trm_fetch="$(command -v curl)"
-
-# get all header information
-#
-"${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}"
-sec_token="$(awk 'BEGIN{FS="[ ;]"}/^Set-Cookie:/{print $2}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
-location="$(awk '/^Location:/{print $2}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
-rm -f "/tmp/${trm_domain}.cookie"
-if [ -z "${sec_token}" ] || [ -z "${location}" ]; then
-       exit 1
-fi
-
-# post request to subscribe to the portal API
-#
-"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait / 6)) --include --cookie-jar "/tmp/${trm_domain}.cookie" --header "Cookie: ${sec_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"
-login="$(awk 'BEGIN{FS="[\"]"}/^\{\"info/{print $12}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
-password="$(awk 'BEGIN{FS="[\"]"}/^\{\"info/{print $16}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
-rm -f "/tmp/${trm_domain}.cookie"
-if [ -z "${login}" ] && [ -z "${password}" ]; then
-       exit 2
-fi
-
-# final post request to authenticate to the portal API
-#
-"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait / 6)) --header "Cookie: ${sec_token}" --data "action=authenticate&login=${login}&password=${password}&policy_accept=false&from_ajax=true&wispr_mode=false" "https://${trm_domain}/portal_api.php"
-if [ "${?}" != "0" ]; then
-       exit 3
-fi
index 687a183589326203de8a7e32a23b51b51795d699..0cce7d40392f5e12f51f460e18610477c4c1104e 100755 (executable)
@@ -6,16 +6,12 @@
 # set (s)hellcheck exceptions
 # shellcheck disable=1091,2039,3040
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
 user="${1}"
 password="${2}"
 success="Thank you!"
@@ -27,6 +23,4 @@ trm_fetch="$(command -v curl)"
 # login with credentials
 #
 raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --silent --show-error --header "Content-Type:application/x-www-form-urlencoded" --data "username=${user}&password=${password}" "http://${trm_domain}")"
-if [ -n "${raw_html##*${success}*}" ]; then
-       exit 1
-fi
+[ -z "${raw_html##*${success}*}" ] && exit 0 || exit 255
index fa55f7d36ea25ae92b8e172776d07f794a7554f8..efb17e7cf9914fe61a6e141619960df3cfd9bb98 100755 (executable)
@@ -6,16 +6,12 @@
 # set (s)hellcheck exceptions
 # shellcheck disable=1091,2181,3040
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-    . "/lib/functions.sh"
-fi
-
 trm_domain="hotspot.t-mobile.net"
 trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
 trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
@@ -28,13 +24,9 @@ ses_id="$(awk '/JSESSIONID/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
 sec_id="$(awk '/DT_H/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
 dev_id="$(sha256sum /etc/config/wireless 2>/dev/null | awk '{printf "%s",substr($1,1,13)}' 2>/dev/null)"
 rm -f "/tmp/${trm_domain}.cookie"
-if [ -z "${ses_id}" ] || [ -z "${sec_id}" ] || [ -z "${dev_id}" ]; then
-       exit 1
-fi
+{ [ -z "${ses_id}" ] || [ -z "${sec_id}" ] || [ -z "${dev_id}" ]; } && exit 1
 
 # final post request
 #
 "${trm_fetch}" --user-agent "${trm_useragent}" --referer "https://${trm_domain}/TD/hotspot/H_Hotels/en_GB/index.html" --silent --connect-timeout $((trm_maxwait / 6)) --header "Cookie: JSESSIONID=${ses_id}; DT_DEV_ID=${dev_id}; DT_H=${sec_id}" --data "rememberMe=true" --output /dev/null "https://${trm_domain}/wlan/rest/freeLogin"
-if [ "${?}" != "0" ]; then
-       exit 2
-fi
+[ "${?}" = "0" ] && exit 0 || exit 255
index f4927c336003a061433b4a3a23d4e3fddae1f5ac..843ffc6ab60086aecee4bbf256cbb94a5df12c74 100755 (executable)
@@ -6,16 +6,12 @@
 # set (s)hellcheck exceptions
 # shellcheck disable=1091,2039,2181,3040
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
 trm_domain="n23.network-auth.com"
 trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
 trm_captiveurl="$(uci_get travelmate global trm_captiveurl "http://detectportal.firefox.com")"
@@ -25,22 +21,16 @@ trm_fetch="$(command -v curl)"
 # get redirect url
 #
 redirect_url="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --write-out "%{redirect_url}" --silent --show-error --output /dev/null "${trm_captiveurl}")"
-if [ -z "${redirect_url}" ]; then
-       exit 1
-fi
+[ -z "${redirect_url}" ] && exit 1
 
 # get session cookie
 #
 "${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://${trm_domain}" --silent --connect-timeout $((trm_maxwait / 6)) --cookie-jar "/tmp/${trm_domain}.cookie" --output /dev/null "${redirect_url}"
 session_id="$(awk '/p_splash_session/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
 rm -f "/tmp/${trm_domain}.cookie"
-if [ -z "${session_id}" ]; then
-       exit 2
-fi
+[ -z "${session_id}" ] && exit 2
 
 # final login request
 #
 "${trm_fetch}" --user-agent "${trm_useragent}" --referer "${redirect_url}" --silent --connect-timeout $((trm_maxwait / 6)) --header "Cookie: p_splash_session=${session_id};" --output /dev/null "https://${trm_domain}/Camping-Julianah/hi/IHYW9cx/grant"
-if [ "${?}" != "0" ]; then
-       exit 3
-fi
+[ "${?}" = "0" ] && exit 0 || exit 255
index 060bce7ff9c19f90b85cc2a679479f10fcdcba44..26ce8008e117dbe63506590663db09c72b0b5a12 100755 (executable)
@@ -6,15 +6,7 @@
 # set (s)hellcheck exceptions
 # shellcheck disable=1091,3040,3043,3057
 
-export LC_ALL=C
-export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-set -o pipefail
-
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-    . "/lib/functions.sh"
-fi
+. "/lib/functions.sh"
 
 # url encoding function
 #
@@ -39,6 +31,10 @@ urlencode()
     done
 }
 
+export LC_ALL=C
+export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
+set -o pipefail
+
 username="$(urlencode "${1}")"
 password="$(urlencode "${2}")"
 trm_domain="telekom.portal.fon.com"
@@ -51,14 +47,10 @@ trm_fetch="$(command -v curl)"
 #
 raw_html="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --location --silent --show-error "${trm_captiveurl}")"
 redirect_url="$(printf "%s" "${raw_html}" | awk 'match(tolower($0),/<loginurl>.*<\/loginurl>/){printf "%s",substr($0,RSTART+10,RLENGTH-21)}' 2>/dev/null | awk '{gsub("&amp;","\\&");printf "%s",$0}' 2>/dev/null)"
-if [ -z "${redirect_url}" ]; then
-    exit 1
-fi
+[ -z "${redirect_url}" ] && exit 1
 
 # final login request
 #
 raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "https://${trm_domain}" --connect-timeout $((trm_maxwait / 6)) --header "content-type: application/x-www-form-urlencoded" --location --silent --show-error --data "UserName=${username}&Password=${password}&FNAME=0&button=Login&OriginatingServer=http%3A%2F%2F${trm_captiveurl}" "${redirect_url}")"
 login_url="$(printf "%s" "${raw_html}" | awk 'match(tolower($0),/<logoffurl>.*<\/logoffurl>/){printf "%s",substr($0,RSTART+11,RLENGTH-23)}' 2>/dev/null)"
-if [ -z "${login_url}" ]; then
-    exit 2
-fi
+[ -n "${login_url}" ] && exit 0 || exit 255
index 10f7da4ca2c476b5e52b16bd713c8215b2e0393c..da6558181b233da8128412ee75463c2928b92b46 100755 (executable)
@@ -8,16 +8,12 @@
 
 # Please note: you have to setup the package 'msmtp' before using this script
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
 trm_debug="$(uci_get travelmate global trm_debug "0")"
 trm_mailreceiver="$(uci_get travelmate global trm_mailreceiver)"
 trm_mailprofile="$(uci_get travelmate global trm_mailprofile "trm_notify")"
index a374617732382b40b8fe781661de706bb5883c9e..6a0fe7f8a00d97e00990c2e1f198eae65cb00a15 100755 (executable)
@@ -10,7 +10,7 @@ export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-trm_ver="2.0.6"
+trm_ver="2.0.7"
 trm_enabled="0"
 trm_debug="0"
 trm_iface=""
@@ -148,9 +148,9 @@ f_char() {
 # wifi helper function
 #
 f_wifi() {
-       local status radio timeout="0"
+       local status radio radio_up timeout="0"
 
-       "${trm_wifi}" reconf
+       "${trm_wifi}" reload
        for radio in ${trm_radiolist}; do
                while true; do
                        if [ "${timeout}" -ge "${trm_maxwait}" ]; then
@@ -159,6 +159,10 @@ f_wifi() {
                        status="$("${trm_wifi}" status 2>/dev/null)"
                        if [ "$(printf "%s" "${status}" | jsonfilter -q -l1 -e "@.${radio}.up")" != "true" ] ||
                                [ "$(printf "%s" "${status}" | jsonfilter -q -l1 -e "@.${radio}.pending")" != "false" ]; then
+                               if [ "${radio}" != "${radio_up}" ]; then
+                                       "${trm_wifi}" up "${radio}"
+                                       radio_up="${radio}"
+                               fi
                                timeout="$((timeout + 1))"
                                sleep 1
                        else
@@ -166,8 +170,10 @@ f_wifi() {
                        fi
                done
        done
-       sleep "$((trm_maxwait / 6))"
-       timeout="$((timeout + (trm_maxwait / 6)))"
+       if [ "${timeout}" -lt "${trm_maxwait}" ]; then
+               sleep "$((trm_maxwait / 6))"
+               timeout="$((timeout + (trm_maxwait / 6)))"
+       fi
        f_log "debug" "f_wifi   ::: radio_list: ${trm_radiolist}, radio: ${radio}, timeout: ${timeout}"
 }
 
@@ -179,10 +185,9 @@ f_vpn() {
        vpn="$(f_getval "vpn")"
        vpn_service="$(f_getval "vpnservice")"
        vpn_iface="$(f_getval "vpniface")"
-       if [ -z "${vpn_action}" ]; then
-               [ "${vpn}" = "1" ] && vpn_action="enable" || vpn_action="disable"
-       fi
-       if [ -x "${trm_vpnpgm}" ] && [ -n "${vpn_service}" ] && [ -n "${vpn_iface}" ]; then
+       [ -z "${vpn_action}" ] && { [ "${vpn}" = "1" ] && vpn_action="enable" || vpn_action="disable"; }
+
+       if [ -x "${trm_vpnpgm}" ] && [ -n "${vpn_service}" ] && [ -n "${vpn_iface}" ] && [ -f "${trm_ntpfile}" ]; then
                if { [ "${vpn_action}" = "disable" ] && [ -f "${trm_vpnfile}" ]; } ||
                        { [ "${vpn}" = "1" ] && [ "${vpn_action}" = "enable" ] && [ ! -f "${trm_vpnfile}" ]; } ||
                        { [ "${vpn}" != "1" ] && [ "${vpn_action}" = "enable" ] && [ -f "${trm_vpnfile}" ]; }; then
@@ -211,13 +216,20 @@ f_mac() {
                        uci_set "wireless" "${section}" "macaddr" "${result}"
                elif [ "${trm_randomize}" = "1" ]; then
                        result="$(hexdump -n6 -ve '/1 "%.02X "' /dev/random 2>/dev/null |
-                               awk -v local="2,6,A,E" -v seed="$(date +%s)" 'BEGIN{srand(seed)}NR==1{split(local,b,",");seed=int(rand()*4+1);printf "%s%s:%s:%s:%s:%s:%s",substr($1,0,1),b[seed],$2,$3,$4,$5,$6}')"
+                               awk -v local="2,6,A,E" -v seed="$(date +%s)" 'BEGIN{srand(seed)}NR==1{split(local,b,",");
+                               seed=int(rand()*4+1);printf "%s%s:%s:%s:%s:%s:%s",substr($1,0,1),b[seed],$2,$3,$4,$5,$6}')"
                        uci_set "wireless" "${section}" "macaddr" "${result}"
                else
-                       result="$(uci_get "wireless" "${section}" "macaddr")"
+                       uci_remove "wireless" "${section}" "macaddr" 2>/dev/null
+                       ifname="$(ubus -S call network.wireless status 2>/dev/null | jsonfilter -q -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
+                       result="$(${trm_iwinfo} "${ifname}" info 2>/dev/null | awk '/Access Point:/{printf "%s",$3}')"
                fi
        elif [ "${action}" = "get" ]; then
                result="$(uci_get "wireless" "${section}" "macaddr")"
+               if [ -z "${result}" ]; then
+                       ifname="$(ubus -S call network.wireless status 2>/dev/null | jsonfilter -q -l1 -e '@.*.interfaces[@.config.mode="sta"].ifname')"
+                       result="$(${trm_iwinfo} "${ifname}" info 2>/dev/null | awk '/Access Point:/{printf "%s",$3}')"
+               fi
        fi
        printf "%s" "${result}"
        f_log "debug" "f_mac    ::: action: ${action:-"-"}, section: ${section:-"-"}, macaddr: ${macaddr:-"-"}, result: ${result:-"-"}"
@@ -568,9 +580,17 @@ f_check() {
                                                                                login_script_args="$(f_getval "script_args")"
                                                                                "${login_script}" ${login_script_args} >/dev/null 2>&1
                                                                                rc="${?}"
-                                                                               f_log "info" "captive portal login for '${cp_domain}' has been executed with rc '${rc}'"
-                                                                               if [ "${rc}" = "0" ]; then
-                                                                                       result="$(f_net)"
+                                                                               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
                                                                                fi
                                                                        fi
                                                                fi
index 8c1cf40480433a377b9307ddb71471791e3af41b..09ce503541bde0aef43a5be180ffe5db4b145694 100755 (executable)
@@ -8,16 +8,12 @@
 
 # Please note: you have to setup the package 'wireguard' or 'openvpn' before using this script
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
 vpn="${1}"
 vpn_action="${2}"
 vpn_service="${3}"
index 17628da6248e8fbe2008a74b33619e5a016971b5..cf92c8e420317558ef3f2a602021a886ced63f23 100755 (executable)
@@ -6,16 +6,12 @@
 # set (s)hellcheck exceptions
 # shellcheck disable=1091,3040
 
+. "/lib/functions.sh"
+
 export LC_ALL=C
 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
 set -o pipefail
 
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-       . "/lib/functions.sh"
-fi
-
 username="${1}"
 password="${2}"
 trm_domain="hotspot.vodafone.de"
@@ -26,24 +22,31 @@ trm_fetch="$(command -v curl)"
 
 # get sid
 #
-raw_html="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --write-out "%{redirect_url}" --silent --show-error --output /dev/null "${trm_captiveurl}")"
-sid="$(printf "%s" "${raw_html}" 2>/dev/null | awk 'BEGIN{FS="[=&]"}{printf "%s",$2}')"
-if [ -z "${sid}" ]; then
-       exit 1
-fi
+redirect_url="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --write-out "%{redirect_url}" --silent --show-error --output /dev/null "${trm_captiveurl}")"
+sid="$(printf "%s" "${redirect_url}" 2>/dev/null | awk 'BEGIN{FS="[=&]"}{printf "%s",$2}')"
+[ -z "${sid}" ] && exit 1
 
 # get session
 #
 raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://${trm_domain}/portal/?sid=${sid}" --silent --connect-timeout $((trm_maxwait / 6)) "https://${trm_domain}/api/v4/session?sid=${sid}")"
 session="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -l1 -e '@.session')"
-if [ -z "${session}" ]; then
-       exit 2
-fi
+[ -z "${session}" ] && exit 2
+
+ids="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -e '@.loginProfiles[*].id' | sort -n | awk '{ORS=" ";print $0}')"
+for id in ${ids}; do
+       if [ "${id}" = "4" ]; then
+               login_id="4"
+               access_type="csc-community"
+               account_type="csc"
+               break
+       fi
+done
+[ -z "${login_id}" ] && exit 3
 
 # final login request
 #
-raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://${trm_domain}/portal/?sid=${sid}" --silent --connect-timeout $((trm_maxwait / 6)) --data "accessType=csc-community&accountType=csc&loginProfile=4&password=${password}&session=${session}&username=${username}&save=true" "https://${trm_domain}/api/v4/login?sid=${sid}")"
-success="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -l1 -e '@.success')"
-if [ "${success}" != "true" ]; then
-       exit 3
+if [ "${login_id}" = "4" ] && [ -n "${username}" ] && [ -n "${password}" ]; then
+       raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://${trm_domain}/portal/?sid=${sid}" --silent --connect-timeout $((trm_maxwait / 6)) --data "loginProfile=${login_id}&accessType=${access_type}&accountType=${account_type}&password=${password}&session=${session}&username=${username}" "https://${trm_domain}/api/v4/login?sid=${sid}")"
 fi
+success="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -l1 -e '@.success')"
+[ "${success}" = "true" ] && exit 0 || exit 255
diff --git a/net/travelmate/files/wifibahn.login b/net/travelmate/files/wifibahn.login
new file mode 100755 (executable)
index 0000000..fe31894
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+# captive portal auto-login script for bahn hotspots (DE)
+# Copyright (c) 2020-2021 Dirk Brenken (dev@brenken.org)
+# This is free software, licensed under the GNU General Public License v3.
+
+# set (s)hellcheck exceptions
+# shellcheck disable=1091,3040
+
+. "/lib/functions.sh"
+
+export LC_ALL=C
+export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
+set -o pipefail
+
+trm_domain="wifi.bahn.de"
+trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
+trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
+trm_fetch="$(command -v curl)"
+
+# get security token
+#
+"${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --cookie-jar "/tmp/${trm_domain}.cookie" --silent --show-error --output /dev/null "https://${trm_domain}/en/"
+sec_token="$(awk '/csrf/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
+rm -f "/tmp/${trm_domain}.cookie"
+[ -z "${sec_token}" ] && exit 1
+
+# final post request
+#
+if [ -z "$redirect_url" ]; then
+       raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --connect-timeout $((trm_maxwait / 6)) --header "Cookie: csrf=${sec_token}" --data "login=true&CSRFToken=${sec_token}" --silent --show-error "https://${trm_domain}/en/")"
+else
+       raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --connect-timeout $((trm_maxwait / 6)) --header "Cookie: PHPSESSID=${sec_token}" --data "login=true&PHPSESSID=${sec_token}" --silent --show-error "${redirect_url}")"
+fi
+[ -z "${raw_html}" ] && exit 0 || exit 255
diff --git a/net/travelmate/files/wifionice.login b/net/travelmate/files/wifionice.login
deleted file mode 100755 (executable)
index 316c747..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-# captive portal auto-login script for ICE hotspots (DE)
-# Copyright (c) 2020-2021 Dirk Brenken (dev@brenken.org)
-# This is free software, licensed under the GNU General Public License v3.
-
-# set (s)hellcheck exceptions
-# shellcheck disable=1091,2181,3040
-
-export LC_ALL=C
-export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-set -o pipefail
-
-# source function library if necessary
-#
-if [ -z "${_C}" ]; then
-    . "/lib/functions.sh"
-fi
-
-trm_domain="www.wifionice.de"
-trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
-trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
-trm_fetch="$(command -v curl)"
-
-# get security token
-#
-"${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait / 6)) --cookie-jar "/tmp/${trm_domain}.cookie" --output /dev/null "http://${trm_domain}/en/"
-sec_token="$(awk '/csrf/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
-rm -f "/tmp/${trm_domain}.cookie"
-if [ -z "${sec_token}" ]; then
-       exit 1
-fi
-
-# final post request
-#
-"${trm_fetch}" --user-agent "${trm_useragent}" --silent --connect-timeout $((trm_maxwait / 6)) --header "Cookie: csrf=${sec_token}" --data "login=true&CSRFToken=${sec_token}&connect=" --output /dev/null "http://${trm_domain}/en/"
-if [ "${?}" != "0" ]; then
-       exit 2
-fi