You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.5 KiB

  1. #!/bin/sh
  2. # captive portal auto-login script for bahn hotspots (DE)
  3. # Copyright (c) 2020-2022 Dirk Brenken (dev@brenken.org)
  4. # This is free software, licensed under the GNU General Public License v3.
  5. # set (s)hellcheck exceptions
  6. # shellcheck disable=1091,3040
  7. . "/lib/functions.sh"
  8. export LC_ALL=C
  9. export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  10. trm_domain="wifi.bahn.de"
  11. trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
  12. trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
  13. trm_fetch="$(command -v curl)"
  14. # get security token
  15. #
  16. "${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/"
  17. sec_token="$(awk '/csrf/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
  18. rm -f "/tmp/${trm_domain}.cookie"
  19. [ -z "${sec_token}" ] && exit 1
  20. # final post request
  21. #
  22. if [ -z "$redirect_url" ]; then
  23. 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/")"
  24. else
  25. 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}")"
  26. fi
  27. [ -z "${raw_html}" ] && exit 0 || exit 255