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.

41 lines
1.5 KiB

  1. #!/bin/sh
  2. # captive portal auto-login script for german ICE hotspots
  3. # Copyright (c) 2020 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,2016,2039,2059,2086,2143,2181,2188
  7. export LC_ALL=C
  8. export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  9. set -o pipefail
  10. if [ "$(uci_get 2>/dev/null; printf "%u" "${?}")" = "127" ]
  11. then
  12. . "/lib/functions.sh"
  13. fi
  14. trm_domain="www.wifionice.de"
  15. trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0")"
  16. trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
  17. trm_fetch="$(command -v curl)"
  18. # initial get request to receive & extract a valid security token
  19. #
  20. "${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/"
  21. if [ -f "/tmp/${trm_domain}.cookie" ]
  22. then
  23. sec_token="$(awk '/csrf/{print $7}' "/tmp/${trm_domain}.cookie")"
  24. rm -f "/tmp/${trm_domain}.cookie"
  25. else
  26. exit 2
  27. fi
  28. # final post request/login with valid session cookie/security token
  29. #
  30. if [ -n "${sec_token}" ]
  31. then
  32. "${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/"
  33. else
  34. exit 3
  35. fi