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.

46 lines
1.8 KiB

  1. #!/bin/sh
  2. # captive portal auto-login script for Julianahoeve beach resort (NL)
  3. # Copyright (c) 2021 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,2039,2181,3040
  7. export LC_ALL=C
  8. export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  9. set -o pipefail
  10. # source function library if necessary
  11. #
  12. if [ -z "${_C}" ]; then
  13. . "/lib/functions.sh"
  14. fi
  15. trm_domain="n23.network-auth.com"
  16. trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
  17. trm_captiveurl="$(uci_get travelmate global trm_captiveurl "http://detectportal.firefox.com")"
  18. trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
  19. trm_fetch="$(command -v curl)"
  20. # get redirect url
  21. #
  22. 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}")"
  23. if [ -z "${redirect_url}" ]; then
  24. exit 1
  25. fi
  26. # get session cookie
  27. #
  28. "${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}"
  29. session_id="$(awk '/p_splash_session/{print $7}' "/tmp/${trm_domain}.cookie" 2>/dev/null)"
  30. rm -f "/tmp/${trm_domain}.cookie"
  31. if [ -z "${session_id}" ]; then
  32. exit 2
  33. fi
  34. # final login request
  35. #
  36. "${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"
  37. if [ "${?}" != "0" ]; then
  38. exit 3
  39. fi