Skip to content

Commit

Permalink
Merge pull request openwrt#13563 from dibdot/trm-2.0.2
Browse files Browse the repository at this point in the history
travelmate: update 2.0.2
  • Loading branch information
dibdot authored Oct 3, 2020
2 parents d3a213b + 404dc5b commit 76d86e0
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 96 deletions.
6 changes: 3 additions & 3 deletions net/travelmate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=travelmate
PKG_VERSION:=2.0.1
PKG_RELEASE:=2
PKG_VERSION:=2.0.2
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <[email protected]>

Expand All @@ -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 +dnsmasq
DEPENDS:=+iwinfo +jshn +jsonfilter +curl +ca-bundle
PKGARCH:=all
endef

Expand Down
34 changes: 20 additions & 14 deletions net/travelmate/files/chs-hotel.login
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@
# Copyright (c) 2020 Dirk Brenken ([email protected])
# This is free software, licensed under the GNU General Public License v3.

domain="hotspot.internet-for-guests.com"
cmd="$(command -v curl)"
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188

# curl check
#
if [ ! -x "${cmd}" ]
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
exit 1
. "/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_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_fetch="$(command -v curl)"

# initial get request to receive & extract valid security tokens
#
"${cmd}" "https://${domain}/logon/cgi/index.cgi" -c "/tmp/${domain}.cookie" -s -o /dev/null

if [ -r "/tmp/${domain}.cookie" ]
"${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/${domain}.cookie")"
ta_id="$(awk '/ta_id/{print $7}' "/tmp/${domain}.cookie")"
cl_id="$(awk '/cl_id/{print $7}' "/tmp/${domain}.cookie")"
rm -f "/tmp/${domain}.cookie"
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
fi
Expand All @@ -31,7 +37,7 @@ fi
#
if [ -n "${lg_id}" ] && [ -n "${ta_id}" ] && [ -n "${cl_id}" ]
then
"${cmd}" "https://${domain}/logon/cgi/index.cgi" -H "Referer: https://${domain}/logon/cgi/index.cgi" -H "Cookie: LGNSID=${lg_id}; lang=en_US; use_mobile_interface=0; ta_id=${ta_id}; cl_id=${cl_id}" -H 'Connection: keep-alive' --data 'accept_termsofuse=&freeperperiod=1&device_infos=1125:2048:1152:2048' -s -o /dev/null
"${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
fi
20 changes: 16 additions & 4 deletions net/travelmate/files/db-bahn.login
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
# Copyright (c) 2020 Dirk Brenken ([email protected])
# 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

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"
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_maxwait="$(uci_get travelmate global trm_maxwait "30")"
Expand All @@ -16,7 +28,7 @@ trm_fetch="$(command -v curl)"
#
if [ -s "/tmp/${trm_domain}.cookie" ]
then
php_token="$(awk 'BEGIN{FS="[ ;]"}/^Set-Cookie:/{print $2}' "/tmp/${trm_domain}.cookie")"
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
Expand All @@ -25,9 +37,9 @@ fi

# post request to subscribe to the portal API
#
if [ -n "${php_token}" ] && [ -n "${location}" ]
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: ${php_token}" --data "action=subscribe&type=one&connect_policy_accept=false&user_login=&user_password=&user_password_confirm=&email_address=&prefix=&phone=&policy_accept=false&gender=&interests=" --output /dev/null "https://${trm_domain}/portal_api.php"
"${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
Expand All @@ -47,7 +59,7 @@ fi
#
if [ -n "${login}" ] && [ -n "${password}" ]
then
"${trm_fetch}" --user-agent "${trm_useragent}" --referer "${location}" --silent --connect-timeout $((trm_maxwait/6)) --header "Cookie: ${php_token}" --data "action=authenticate&login=${login}&password=${password}&policy_accept=false&from_ajax=true&wispr_mode=false" "https://${trm_domain}/portal_api.php"
"${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
fi
31 changes: 23 additions & 8 deletions net/travelmate/files/generic-user-pass.login
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
#!/bin/sh
# captive portal auto-login script template with credentials as parameters
# Copyright (c) 2020 Dirk Brenken ([email protected])
# This is free software, licensed under the GNU General Public License v3.

cmd="$(command -v curl)"
url="http://example.com/"
success_string="Thank you!"
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188

if [ ! -x "${cmd}" ]
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
exit 1
. "/lib/functions.sh"
fi

response="$("${cmd}" $url -d "username=${1}&password=${2}" \
--header "Content-Type:application/x-www-form-urlencoded" -s)"
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!"

if [ -n "$(printf "%s" "${response}" | grep "${success_string}")" ]
# 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
Expand Down
32 changes: 19 additions & 13 deletions net/travelmate/files/h-hotels.login
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@
# Copyright (c) 2020 Dirk Brenken ([email protected])
# This is free software, licensed under the GNU General Public License v3.

domain="hotspot.t-mobile.net"
cmd="$(command -v curl)"
# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188

# curl check
#
if [ ! -x "${cmd}" ]
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
exit 1
. "/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_maxwait="$(uci_get travelmate global trm_maxwait "30")"
trm_fetch="$(command -v curl)"

# initial get request to receive & extract valid security tokens
#
"${cmd}" "https://${domain}/wlan/rest/freeLogin" -c "/tmp/${domain}.cookie" -s -o /dev/null

if [ -r "/tmp/${domain}.cookie" ]
"${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/${domain}.cookie")"
sec_id="$(awk '/DT_H/{print $7}' "/tmp/${domain}.cookie")"
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/${domain}.cookie"
rm -f "/tmp/${trm_domain}.cookie"
else
exit 2
fi
Expand All @@ -31,7 +37,7 @@ fi
#
if [ -n "${ses_id}" ] && [ -n "${sec_id}" ] && [ -n "${dev_id}" ]
then
"${cmd}" "https://${domain}/wlan/rest/freeLogin" -H "Referer: https://${domain}/TD/hotspot/H_Hotels/en_GB/index.html" -H "Cookie: JSESSIONID=${ses_id}; DT_DEV_ID=${dev_id}; DT_H=${sec_id}" -H 'Connection: keep-alive' --data "rememberMe=true" -s -o /dev/null
"${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
fi
6 changes: 3 additions & 3 deletions net/travelmate/files/travelmate.init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh /etc/rc.common

# set (s)hellcheck exceptions
# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
# shellcheck disable=1091,2016,2034,2039,2059,2086,2143,2181,2188

START=25
USE_PROCD=1
Expand All @@ -25,7 +25,7 @@ boot()

start_service()
{
if [ "$("${trm_init}" enabled; printf "%u" ${?})" -eq "0" ]
if [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
then
procd_open_instance "travelmate"
procd_set_param command "${trm_script}" "${@}"
Expand Down Expand Up @@ -69,7 +69,7 @@ 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 [ ${?} -eq 0 ]
if [ "${?}" = "0" ]
then
printf "%s\n" "::: travelmate runtime information"
json_get_keys keylist
Expand Down
13 changes: 9 additions & 4 deletions net/travelmate/files/travelmate.mail
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

# Please note: you have to setup the package 'msmtp' before using this script

LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
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"
fi

. "/lib/functions.sh"
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")"
Expand All @@ -38,7 +43,7 @@ then
exit 1
fi

if [ "${trm_debug}" -eq "1" ]
if [ "${trm_debug}" = "1" ]
then
debug="--debug"
fi
Expand Down
Loading

0 comments on commit 76d86e0

Please sign in to comment.