Browse Source

Merge pull request #16221 from dibdot/travelmate

travelmate: update to 2.0.4
lilik-openwrt-22.03
Dirk Brenken 3 years ago
committed by GitHub
parent
commit
3995ad1e51
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 594 additions and 637 deletions
  1. +2
    -2
      net/travelmate/Makefile
  2. +19
    -22
      net/travelmate/files/chs-hotel.login
  3. +23
    -39
      net/travelmate/files/db-bahn.login
  4. +12
    -15
      net/travelmate/files/generic-user-pass.login
  5. +20
    -23
      net/travelmate/files/h-hotels.login
  6. +46
    -0
      net/travelmate/files/julianahoeve.login
  7. +64
    -0
      net/travelmate/files/telekom.login
  8. +33
    -53
      net/travelmate/files/travelmate.init
  9. +13
    -25
      net/travelmate/files/travelmate.mail
  10. +244
    -336
      net/travelmate/files/travelmate.sh
  11. +46
    -81
      net/travelmate/files/travelmate.vpn
  12. +5
    -20
      net/travelmate/files/travelmate_ntp.hotplug
  13. +49
    -0
      net/travelmate/files/vodafone.login
  14. +18
    -21
      net/travelmate/files/wifionice.login

+ 2
- 2
net/travelmate/Makefile View File

@ -6,8 +6,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=travelmate
PKG_VERSION:=2.0.3
PKG_RELEASE:=2
PKG_VERSION:=2.0.4
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>


+ 19
- 22
net/travelmate/files/chs-hotel.login View File

@ -1,43 +1,40 @@
#!/bin/sh
# captive portal auto-login script for german chs hotels
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# captive portal auto-login script for chs hotels (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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2181,3040
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
# 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:80.0) Gecko/20100101 Firefox/80.0")"
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)"
# initial get request to receive & extract valid security tokens
# get security tokens
#
"${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 "https://${trm_domain}/logon/cgi/index.cgi"
if [ -r "/tmp/${trm_domain}.cookie" ]
then
lg_id="$(awk '/LGNSID/{print $7}' "/tmp/${trm_domain}.cookie")"
ta_id="$(awk '/ta_id/{print $7}' "/tmp/${trm_domain}.cookie")"
cl_id="$(awk '/cl_id/{print $7}' "/tmp/${trm_domain}.cookie")"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
"${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 "https://${trm_domain}/logon/cgi/index.cgi"
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
# final post request/login with valid session cookie/security token
# final login request
#
if [ -n "${lg_id}" ] && [ -n "${ta_id}" ] && [ -n "${cl_id}" ]
then
"${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"
else
exit 3
"${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

+ 23
- 39
net/travelmate/files/db-bahn.login View File

@ -1,65 +1,49 @@
#!/bin/sh
# captive portal auto-login script for german DB hotspots via portal login API
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# 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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2181,3040
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
# 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:80.0) Gecko/20100101 Firefox/80.0")"
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)"
# initial get request to receive 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}"
# extract the session cookie and the hotspot location
# get all header information
#
if [ -s "/tmp/${trm_domain}.cookie" ]
then
sec_token="$(awk 'BEGIN{FS="[ ;]"}/^Set-Cookie:/{print $2}' "/tmp/${trm_domain}.cookie")"
location="$(awk '/^Location:/{print $2}' "/tmp/${trm_domain}.cookie")"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
"${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
#
if [ -n "${sec_token}" ] && [ -n "${location}" ]
then
"${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"
else
exit 3
fi
# extract additional login and password information from the portal API
#
if [ -s "/tmp/${trm_domain}.cookie" ]
then
login="$(awk 'BEGIN{FS="[\"]"}/^\{\"info/{print $12}' "/tmp/${trm_domain}.cookie")"
password="$(awk 'BEGIN{FS="[\"]"}/^\{\"info/{print $16}' "/tmp/${trm_domain}.cookie")"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 4
"${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
#
if [ -n "${login}" ] && [ -n "${password}" ]
then
"${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"
else
exit 5
"${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

+ 12
- 15
net/travelmate/files/generic-user-pass.login View File

@ -1,35 +1,32 @@
#!/bin/sh
# captive portal auto-login script template with credentials as parameters
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# 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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2039,3040
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
# source function library if necessary
#
if [ -z "${_C}" ]; then
. "/lib/functions.sh"
fi
trm_domain="example.com"
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)"
user="${1}"
password="${2}"
success="Thank you!"
trm_domain="example.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")"
trm_fetch="$(command -v curl)"
# login with credentials
#
response="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait/6)) --data "username=${user}&password=${password}" --header "Content-Type:application/x-www-form-urlencoded" "http://${trm_domain}")"
if [ -n "$(printf "%s" "${response}" | grep "${success}")" ]
then
exit 0
else
exit 2
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

+ 20
- 23
net/travelmate/files/h-hotels.login View File

@ -1,43 +1,40 @@
#!/bin/sh
# captive portal auto-login script for Telekom hotspots in german h+hotels
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# captive portal auto-login script for Telekom hotspots in h+hotels (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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2181,3040
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
# 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:80.0) Gecko/20100101 Firefox/80.0")"
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)"
# initial get request to receive & extract valid security tokens
# get security tokens
#
"${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 "https://${trm_domain}/wlan/rest/freeLogin"
if [ -r "/tmp/${trm_domain}.cookie" ]
then
ses_id="$(awk '/JSESSIONID/{print $7}' "/tmp/${trm_domain}.cookie")"
sec_id="$(awk '/DT_H/{print $7}' "/tmp/${trm_domain}.cookie")"
dev_id="$(sha256sum /etc/config/wireless | awk '{printf "%s",substr($1,1,13)}')"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
"${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 "https://${trm_domain}/wlan/rest/freeLogin"
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
# final post request/login with valid session cookie/security token
# final post request
#
if [ -n "${ses_id}" ] && [ -n "${sec_id}" ] && [ -n "${dev_id}" ]
then
"${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"
else
exit 3
"${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

+ 46
- 0
net/travelmate/files/julianahoeve.login View File

@ -0,0 +1,46 @@
#!/bin/sh
# captive portal auto-login script for Julianahoeve beach resort (NL)
# Copyright (c) 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,2039,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="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")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
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
# 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
# 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

+ 64
- 0
net/travelmate/files/telekom.login View File

@ -0,0 +1,64 @@
#!/bin/sh
# captive portal auto-login script for telekom hotspots (DE)
# Copyright (c) 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,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
# url encoding function
#
urlencode()
{
local chr str="${1}" len="${#1}" pos=0
while [ "${pos}" -lt "${len}" ]; do
chr="${str:pos:1}"
case "${chr}" in
[a-zA-Z0-9.~_-])
printf "%s" "${chr}"
;;
" ")
printf "%%20"
;;
*)
printf "%%%02X" "'${chr}"
;;
esac
pos=$((pos + 1))
done
}
username="$(urlencode "${1}")"
password="$(urlencode "${2}")"
trm_domain="telekom.portal.fon.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")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_fetch="$(command -v curl)"
# get redirect url
#
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
# 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

+ 33
- 53
net/travelmate/files/travelmate.init View File

@ -3,7 +3,7 @@
# This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2034,2039,2059,2086,2143,2154,2181,2188
# shellcheck disable=2034,2086,2154,3043,3060
START=25
USE_PROCD=1
@ -17,19 +17,16 @@ trm_pidfile="/var/run/travelmate.pid"
boot()
{
if [ -s "${trm_pidfile}" ]
then
> "${trm_pidfile}"
if [ -s "${trm_pidfile}" ]; then
: >"${trm_pidfile}"
fi
rc_procd start_service
}
start_service()
{
if [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
then
if [ "${action}" = "boot" ]
then
if "${trm_init}" enabled; then
if [ "${action}" = "boot" ]; then
return 0
fi
procd_open_instance "travelmate"
@ -45,17 +42,14 @@ start_service()
reload_service()
{
local ppid pid timeout
timeout="$(uci_get travelmate global trm_timeout)"
if [ -s "${trm_pidfile}" ]
then
if [ -s "${trm_pidfile}" ]; then
ppid="$(cat "${trm_pidfile}" 2>/dev/null)"
if [ -n "${ppid}" ]
then
if [ -n "${ppid}" ]; then
pid="$(pgrep -xnf "sleep ${timeout:-60} 0" -P ${ppid} 2>/dev/null)"
if [ -n "${pid}" ]
then
if [ -n "${pid}" ]; then
kill -INT ${pid} 2>/dev/null
fi
fi
@ -73,13 +67,10 @@ status_service()
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 [ "${?}" = "0" ]
then
if json_select data >/dev/null 2>&1; then
printf "%s\n" "::: travelmate runtime information"
json_get_keys keylist
for key in ${keylist}
do
for key in ${keylist}; do
json_get_var value "${key}"
printf " + %-18s : %s\n" "${key}" "${value}"
done
@ -92,21 +83,20 @@ 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 | \
scan_dev="$(ubus -S call network.wireless status 2>/dev/null | jsonfilter -q -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}' | \
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}"
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"
printf '%s\n' "::: No scan results"
fi
}
@ -119,13 +109,10 @@ setup()
zone="${zone//[+*~%&\$@\"\' ]/}"
metric="${metric//[^0-9]/}"
if [ -n "${iface}" ] && [ "${iface}" = "${input}" ]
then
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
elif [ -n "${input}" ]; then
if [ -n "${iface}" ]; then
uci -q batch <<-EOC
del network."${iface}"
del network."${iface}6"
@ -144,12 +131,9 @@ setup()
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
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"
@ -162,19 +146,16 @@ setup()
EOC
break
fi
cnt=$((cnt+1))
cnt=$((cnt + 1))
done
if [ -n "${iface}" ]
then
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
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))
cnt=$((cnt + 1))
done
uci -q commit wireless
fi
@ -192,8 +173,7 @@ service_triggers()
delay="$(uci_get travelmate global trm_triggerdelay "2")"
PROCD_RELOAD_DELAY=$((delay * 1000))
if [ -n "${iface}" ]
then
if [ -n "${iface}" ]; then
procd_add_interface_trigger "interface.*.down" "${iface}" "${trm_init}" reload
fi
procd_add_raw_trigger "interface.*.up" "${PROCD_RELOAD_DELAY}" "${trm_init}" start


+ 13
- 25
net/travelmate/files/travelmate.mail View File

@ -1,10 +1,10 @@
#!/bin/sh
# send mail script for travelmate notifications
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# 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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,3040
# Please note: you have to setup the package 'msmtp' before using this script
@ -12,8 +12,9 @@ export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
# source function library if necessary
#
if [ -z "${_C}" ]; then
. "/lib/functions.sh"
fi
@ -25,32 +26,21 @@ trm_rtfile="$(uci_get travelmate global trm_rtfile "/tmp/trm_runtime.json")"
trm_mailpgm="$(command -v msmtp)"
trm_logger="$(command -v logger)"
f_log()
{
local class="${1}" log_msg="${2}"
if [ -x "${trm_logger}" ]
then
"${trm_logger}" -p "${class}" -t "trm-mail [${$}]" "${log_msg}"
else
printf "%s %s %s\\n" "${class}" "trm-mail [${$}]" "${log_msg}"
fi
}
if [ -z "${trm_mailreceiver}" ]
then
f_log "err" "please set the mail receiver with the 'trm_mailreceiver' option"
if [ -z "${trm_mailreceiver}" ]; then
"${trm_logger}" -p "err" -t "trm-mail [${$}]" "please set the mail receiver with the 'trm_mailreceiver' option" 2>/dev/null
exit 1
fi
if [ "${trm_debug}" = "1" ]
then
if [ "${trm_debug}" = "1" ]; then
debug="--debug"
fi
# info preparation
#
sys_info="$(strings /etc/banner 2>/dev/null; ubus call system board | sed -e 's/\"release\": {//' | sed -e 's/^[ \t]*//' | sed -e 's/[{}\",]//g' | sed -e 's/[ ]/ \t/' | sed '/^$/d' 2>/dev/null)"
sys_info="$(
strings /etc/banner 2>/dev/null
ubus call system board | sed -e 's/\"release\": {//' | sed -e 's/^[ \t]*//' | sed -e 's/[{}\",]//g' | sed -e 's/[ ]/ \t/' | sed '/^$/d' 2>/dev/null
)"
trm_info="$(/etc/init.d/travelmate status 2>/dev/null)"
sta_info="$(jsonfilter -i "${trm_rtfile}" -l1 -e '@.data.station_id')"
trm_mailtopic="$(uci_get travelmate global trm_mailtopic "travelmate connection to '${sta_info}'")"
@ -66,6 +56,4 @@ trm_mailtext="${trm_mailtext}</pre></body></html>"
# send mail
#
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}
"${trm_logger}" -p "info" -t "trm-mail [${$}]" "mail sent to '${trm_mailreceiver}' with rc '${?}'" 2>/dev/null

+ 244
- 336
net/travelmate/files/travelmate.sh
File diff suppressed because it is too large
View File


+ 46
- 81
net/travelmate/files/travelmate.vpn View File

@ -1,10 +1,10 @@
#!/bin/sh
# vpn switch for travelmate
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# 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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,3040,3043
# Please note: you have to setup the package 'wireguard' or 'openvpn' before using this script
@ -12,9 +12,10 @@ export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
# source function library if necessary
#
if [ -z "${_C}" ]; then
. "/lib/functions.sh"
fi
vpn_action="${1}"
@ -22,129 +23,93 @@ trm_vpnservice="$(uci_get travelmate global trm_vpnservice)"
trm_vpniface="$(uci_get travelmate global trm_vpniface)"
trm_landevice="$(uci_get travelmate global trm_landevice)"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_captiveurl="$(uci_get travelmate global trm_captiveurl "http://captive.apple.com")"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
trm_captiveurl="$(uci_get travelmate global trm_captiveurl "http://detectportal.firefox.com")"
trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
trm_iptrule_accept="FORWARD -i ${trm_landevice} -p tcp --match multiport --dports 80,443 -j ACCEPT"
trm_iptrule_drop="FORWARD -i ${trm_landevice} -j DROP"
trm_iptables="$(command -v iptables)"
trm_logger="$(command -v logger)"
trm_fetch="$(command -v curl)"
f_log()
{
local class="${1}" log_msg="${2}"
if [ -x "${trm_logger}" ]
then
"${trm_logger}" -p "${class}" -t "trm-vpn [${$}]" "${log_msg}"
else
printf "%s %s %s\\n" "${class}" "trm-vpn [${$}]" "${log_msg}"
fi
}
f_net()
{
local IFS json_raw json_rc result="net nok"
local IFS json_rc result="net nok"
json_raw="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --write-out "%{json}" --silent --show-error --connect-timeout $((trm_maxwait/10)) "${trm_captiveurl}" 2>/dev/null)"
json_raw="${json_raw#*\{}"
if [ -n "${json_raw}" ]
then
json_rc="$(printf "%s" "{${json_raw}" | jsonfilter -l1 -e '@.response_code' 2>/dev/null)"
if [ "${json_rc}" = "200" ] || [ "${json_rc}" = "204" ]
then
result="net ok"
fi
json_rc="$(${trm_fetch} --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 10)) --header "Cache-Control: no-cache, no-store, must-revalidate" --header "Pragma: no-cache" --header "Expires: 0" --write-out "%{response_code}" --silent --show-error --output /dev/null "${trm_captiveurl}")"
if [ "${json_rc}" = "200" ] || [ "${json_rc}" = "204" ]; then
result="net ok"
fi
printf "%s" "${result}"
}
if [ -n "${trm_vpnservice}" ] && [ -n "${trm_vpniface}" ] && [ -n "${trm_landevice}" ] && [ -f "/tmp/trm_runtime.json" ]
then
if [ -n "${trm_vpnservice}" ] && [ -n "${trm_vpniface}" ] && [ -n "${trm_landevice}" ] && [ -f "/tmp/trm_runtime.json" ]; 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 [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]
then
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 2>&1)" ] && \
[ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 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}'"
if [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]; then
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait / 6))" -C "${trm_iptrule_drop}" 2>&1)" ] &&
[ -n "$("${trm_iptables}" "-w $((trm_maxwait / 6))" -C "${trm_iptrule_accept}" 2>&1)" ]; then
"${trm_iptables}" "-w $((trm_maxwait / 6))" -I "${trm_iptrule_drop}" 2>&1
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "lan forward blocked for device '${trm_landevice}'" 2>/dev/null
fi
fi
if [ "${vpn_action}" = "disable" ] && [ "${status%% (net cp *}" = "connected" ]
then
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ] && \
[ -z "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 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}'"
if [ "${vpn_action}" = "disable" ] && [ "${status%% (net cp *}" = "connected" ]; then
if [ -n "$("${trm_iptables}" "-w $((trm_maxwait / 6))" -C "${trm_iptrule_accept}" 2>&1)" ] &&
[ -z "$("${trm_iptables}" "-w $((trm_maxwait / 6))" -C "${trm_iptrule_drop}" 2>&1)" ]; then
"${trm_iptables}" "-w $((trm_maxwait / 6))" -I "${trm_iptrule_accept}" 2>&1
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "lan forward on ports 80/443 freed for device '${trm_landevice}'" 2>/dev/null
fi
fi
case "${trm_vpnservice}" in
"wireguard")
if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ]
then
if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ]; then
ubus call network.interface."${trm_vpniface}" up
elif [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]
then
elif [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]; then
ubus call network.interface."${trm_vpniface}" down
f_log "info" "${trm_vpnservice} client connection disabled"
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${trm_vpnservice} client connection disabled" 2>/dev/null
fi
;;
;;
"openvpn")
if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ]
then
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 [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]
then
elif [ "${vpn_action}" = "disable" ] && [ "${vpn_status}" = "true" ]; then
ubus call network.interface."${trm_vpniface}" down
/etc/init.d/openvpn stop >/dev/null 2>&1
f_log "info" "${trm_vpnservice} client connection disabled"
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${trm_vpnservice} client connection disabled" 2>/dev/null
fi
;;
;;
esac
if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ]
then
if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" != "true" ]; then
cnt=0
while true
do
while true; do
vpn_status="$(ubus -S call network.interface."${trm_vpniface}" status 2>/dev/null | jsonfilter -l1 -e '@.up')"
if [ "${vpn_status}" = "true" ]
then
if [ "${vpn_status}" = "true" ]; then
net_status="$(f_net)"
if [ "${net_status}" = "net ok" ]
then
f_log "info" "${trm_vpnservice} client connection enabled"
if [ -z "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_drop} 2>&1)" ]
then
"${trm_iptables}" "-w $((trm_maxwait/6))" -D ${trm_iptrule_drop} 2>&1
if [ -z "$("${trm_iptables}" "-w $((trm_maxwait/6))" -C ${trm_iptrule_accept} 2>&1)" ]
then
"${trm_iptables}" "-w $((trm_maxwait/6))" -D ${trm_iptrule_accept} 2>&1
if [ "${net_status}" = "net ok" ]; then
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${trm_vpnservice} client connection enabled" 2>/dev/null
if [ -z "$("${trm_iptables}" "-w $((trm_maxwait / 6))" -C "${trm_iptrule_drop}" 2>&1)" ]; then
"${trm_iptables}" "-w $((trm_maxwait / 6))" -D "${trm_iptrule_drop}" 2>&1
if [ -z "$("${trm_iptables}" "-w $((trm_maxwait / 6))" -C "${trm_iptrule_accept}" 2>&1)" ]; then
"${trm_iptables}" "-w $((trm_maxwait / 6))" -D "${trm_iptrule_accept}" 2>&1
fi
f_log "info" "lan forward freed for device '${trm_landevice}'"
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "lan forward freed for device '${trm_landevice}'" 2>/dev/null
fi
break
fi
fi
if [ "${cnt}" -ge "$((trm_maxwait/6))" ]
then
f_log "info" "${trm_vpnservice} restart failed, lan forward for device '${trm_landevice}' still blocked"
if [ "${cnt}" -ge "$((trm_maxwait / 6))" ]; then
"${trm_logger}" -p "info" -t "trm-vpn [${$}]" "${trm_vpnservice} restart failed, lan forward for device '${trm_landevice}' still blocked" 2>/dev/null
ubus call network.interface."${trm_vpniface}" down
exit 2
fi
sleep 1
cnt="$((cnt+1))"
cnt="$((cnt + 1))"
done
fi
if [ "${vpn_action}" = "enable" ] && [ "${vpn_status}" = "true" ]
then
if [ -f "/etc/init.d/sysntpd" ]
then
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


+ 5
- 20
net/travelmate/files/travelmate_ntp.hotplug View File

@ -1,34 +1,19 @@
#!/bin/sh
# ntp hotplug script for travelmate
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# 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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=3023
trm_init="/etc/init.d/travelmate"
trm_ntpfile="/var/state/travelmate.ntp"
trm_logger="$(command -v logger)"
f_log()
{
local class="${1}" log_msg="${2}"
if [ -x "${trm_logger}" ]
then
"${trm_logger}" -p "${class}" -t "trm-ntp [${$}]" "${log_msg}"
else
printf "%s %s %s\\n" "${class}" "trm-ntp [${$}]" "${log_msg}"
fi
}
if [ "${ACTION}" = "stratum" ] && [ ! -f "${trm_ntpfile}" ] && [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
then
if [ "${ACTION}" = "stratum" ] && [ ! -f "${trm_ntpfile}" ] && "${trm_init}" enabled; then
{
flock -xn 1001
if [ "$?" = "0" ]
then
f_log "info" "get ntp time sync"
if flock -xn 1001; then
"${trm_logger}" -p "info" -t "trm-ntp [${$}]" "get ntp time sync" 2>/dev/null
"${trm_init}" restart
fi
} 1001>"${trm_ntpfile}"


+ 49
- 0
net/travelmate/files/vodafone.login View File

@ -0,0 +1,49 @@
#!/bin/sh
# captive portal auto-login script for vodafone hotspots (DE)
# Copyright (c) 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
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"
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")"
trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
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
# 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
# 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
fi

+ 18
- 21
net/travelmate/files/wifionice.login View File

@ -1,41 +1,38 @@
#!/bin/sh
# captive portal auto-login script for german ICE hotspots
# Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
# 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,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2181,3040
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
then
. "/lib/functions.sh"
# 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:80.0) Gecko/20100101 Firefox/80.0")"
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)"
# initial get request to receive & extract a valid security token
# 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/"
if [ -f "/tmp/${trm_domain}.cookie" ]
then
sec_token="$(awk '/csrf/{print $7}' "/tmp/${trm_domain}.cookie")"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
"${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/login with valid session cookie/security token
# final post request
#
if [ -n "${sec_token}" ]
then
"${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/"
else
exit 3
"${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

Loading…
Cancel
Save