net/snort3: Include default configs and snort2lua
[feed/packages.git] / net / travelmate / files / db-bahn.login
1 #!/bin/sh
2 # captive portal auto-login script for german DB hotspots via portal login API
3 # Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
4 # This is free software, licensed under the GNU General Public License v3.
5
6 # set (s)hellcheck exceptions
7 # shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
8
9 export LC_ALL=C
10 export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
11 set -o pipefail
12
13 if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
14 then
15 . "/lib/functions.sh"
16 fi
17
18 trm_domain="wifi.bahn.de"
19 trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
20 trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
21 trm_fetch="$(command -v curl)"
22
23 # initial get request to receive all header information
24 #
25 "${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}"
26
27 # extract the session cookie and the hotspot location
28 #
29 if [ -s "/tmp/${trm_domain}.cookie" ]
30 then
31 sec_token="$(awk 'BEGIN{FS="[ ;]"}/^Set-Cookie:/{print $2}' "/tmp/${trm_domain}.cookie")"
32 location="$(awk '/^Location:/{print $2}' "/tmp/${trm_domain}.cookie")"
33 rm -f "/tmp/${trm_domain}.cookie"
34 else
35 exit 2
36 fi
37
38 # post request to subscribe to the portal API
39 #
40 if [ -n "${sec_token}" ] && [ -n "${location}" ]
41 then
42 "${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"
43 else
44 exit 3
45 fi
46
47 # extract additional login and password information from the portal API
48 #
49 if [ -s "/tmp/${trm_domain}.cookie" ]
50 then
51 login="$(awk 'BEGIN{FS="[\"]"}/^\{\"info/{print $12}' "/tmp/${trm_domain}.cookie")"
52 password="$(awk 'BEGIN{FS="[\"]"}/^\{\"info/{print $16}' "/tmp/${trm_domain}.cookie")"
53 rm -f "/tmp/${trm_domain}.cookie"
54 else
55 exit 4
56 fi
57
58 # final post request to authenticate to the portal API
59 #
60 if [ -n "${login}" ] && [ -n "${password}" ]
61 then
62 "${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"
63 else
64 exit 5
65 fi