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.

52 lines
2.3 KiB

  1. #!/bin/sh
  2. # captive portal auto-login script for vodafone hotspots (DE)
  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,3040
  7. . "/lib/functions.sh"
  8. export LC_ALL=C
  9. export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  10. set -o pipefail
  11. username="${1}"
  12. password="${2}"
  13. trm_domain="hotspot.vodafone.de"
  14. trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
  15. trm_captiveurl="$(uci_get travelmate global trm_captiveurl "http://detectportal.firefox.com")"
  16. trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
  17. trm_fetch="$(command -v curl)"
  18. # get sid
  19. #
  20. 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}")"
  21. sid="$(printf "%s" "${redirect_url}" 2>/dev/null | awk 'BEGIN{FS="[=&]"}{printf "%s",$2}')"
  22. [ -z "${sid}" ] && exit 1
  23. # get session
  24. #
  25. raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://${trm_domain}/portal/?sid=${sid}" --silent --connect-timeout $((trm_maxwait / 6)) "https://${trm_domain}/api/v4/session?sid=${sid}")"
  26. session="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -l1 -e '@.session')"
  27. [ -z "${session}" ] && exit 2
  28. ids="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -e '@.loginProfiles[*].id' | sort -n | awk '{ORS=" ";print $0}')"
  29. for id in ${ids}; do
  30. if [ "${id}" = "4" ]; then
  31. login_id="4"
  32. access_type="csc-community"
  33. account_type="csc"
  34. break
  35. fi
  36. done
  37. [ -z "${login_id}" ] && exit 3
  38. # final login request
  39. #
  40. if [ "${login_id}" = "4" ] && [ -n "${username}" ] && [ -n "${password}" ]; then
  41. raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://${trm_domain}/portal/?sid=${sid}" --silent --connect-timeout $((trm_maxwait / 6)) --data "loginProfile=${login_id}&accessType=${access_type}&accountType=${account_type}&password=${password}&session=${session}&username=${username}" "https://${trm_domain}/api/v4/login?sid=${sid}")"
  42. fi
  43. success="$(printf "%s" "${raw_html}" 2>/dev/null | jsonfilter -q -l1 -e '@.success')"
  44. [ "${success}" = "true" ] && exit 0 || exit 255