From 3167e00aff44c1ae5172f4c5547b3136caef6088 Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Sat, 11 Sep 2021 18:23:35 +0200 Subject: [PATCH] travelmate: update to 2.0.7 * 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 --- net/travelmate/Makefile | 4 +- net/travelmate/files/chs-hotel.login | 16 ++----- net/travelmate/files/db-bahn.login | 49 -------------------- net/travelmate/files/generic-user-pass.login | 12 ++--- net/travelmate/files/h-hotels.login | 16 ++----- net/travelmate/files/julianahoeve.login | 20 ++------ net/travelmate/files/telekom.login | 22 +++------ net/travelmate/files/travelmate.mail | 8 +--- net/travelmate/files/travelmate.sh | 48 +++++++++++++------ net/travelmate/files/travelmate.vpn | 8 +--- net/travelmate/files/vodafone.login | 39 +++++++++------- net/travelmate/files/wifibahn.login | 34 ++++++++++++++ net/travelmate/files/wifionice.login | 38 --------------- 13 files changed, 118 insertions(+), 196 deletions(-) delete mode 100755 net/travelmate/files/db-bahn.login create mode 100755 net/travelmate/files/wifibahn.login delete mode 100755 net/travelmate/files/wifionice.login diff --git a/net/travelmate/Makefile b/net/travelmate/Makefile index d8914cd8f..10f511e48 100644 --- a/net/travelmate/Makefile +++ b/net/travelmate/Makefile @@ -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 @@ -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 diff --git a/net/travelmate/files/chs-hotel.login b/net/travelmate/files/chs-hotel.login index 905824ad7..76aa14ef6 100755 --- a/net/travelmate/files/chs-hotel.login +++ b/net/travelmate/files/chs-hotel.login @@ -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 index 2b4bf30f5..000000000 --- a/net/travelmate/files/db-bahn.login +++ /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 diff --git a/net/travelmate/files/generic-user-pass.login b/net/travelmate/files/generic-user-pass.login index 687a18358..0cce7d403 100755 --- a/net/travelmate/files/generic-user-pass.login +++ b/net/travelmate/files/generic-user-pass.login @@ -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 diff --git a/net/travelmate/files/h-hotels.login b/net/travelmate/files/h-hotels.login index fa55f7d36..efb17e7cf 100755 --- a/net/travelmate/files/h-hotels.login +++ b/net/travelmate/files/h-hotels.login @@ -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 diff --git a/net/travelmate/files/julianahoeve.login b/net/travelmate/files/julianahoeve.login index f4927c336..843ffc6ab 100755 --- a/net/travelmate/files/julianahoeve.login +++ b/net/travelmate/files/julianahoeve.login @@ -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 diff --git a/net/travelmate/files/telekom.login b/net/travelmate/files/telekom.login index 060bce7ff..26ce8008e 100755 --- a/net/travelmate/files/telekom.login +++ b/net/travelmate/files/telekom.login @@ -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>/){printf "%s",substr($0,RSTART+10,RLENGTH-21)}' 2>/dev/null | awk '{gsub("&","\\&");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>/){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 diff --git a/net/travelmate/files/travelmate.mail b/net/travelmate/files/travelmate.mail index 10f7da4ca..da6558181 100755 --- a/net/travelmate/files/travelmate.mail +++ b/net/travelmate/files/travelmate.mail @@ -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")" diff --git a/net/travelmate/files/travelmate.sh b/net/travelmate/files/travelmate.sh index a37461773..6a0fe7f8a 100755 --- a/net/travelmate/files/travelmate.sh +++ b/net/travelmate/files/travelmate.sh @@ -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 diff --git a/net/travelmate/files/travelmate.vpn b/net/travelmate/files/travelmate.vpn index 8c1cf4048..09ce50354 100755 --- a/net/travelmate/files/travelmate.vpn +++ b/net/travelmate/files/travelmate.vpn @@ -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}" diff --git a/net/travelmate/files/vodafone.login b/net/travelmate/files/vodafone.login index 17628da62..cf92c8e42 100755 --- a/net/travelmate/files/vodafone.login +++ b/net/travelmate/files/vodafone.login @@ -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 index 000000000..fe31894ce --- /dev/null +++ b/net/travelmate/files/wifibahn.login @@ -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 index 316c74701..000000000 --- a/net/travelmate/files/wifionice.login +++ /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