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.

32 lines
1.1 KiB

  1. #!/bin/sh
  2. # captive portal auto-login script template with credentials as parameters
  3. # Copyright (c) 2020-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,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. user="${1}"
  16. password="${2}"
  17. success="Thank you!"
  18. trm_domain="example.com"
  19. trm_useragent="$(uci_get travelmate global trm_useragent "Mozilla/5.0 (Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0")"
  20. trm_maxwait="$(uci_get travelmate global trm_maxwait "30")"
  21. trm_fetch="$(command -v curl)"
  22. # login with credentials
  23. #
  24. raw_html="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --connect-timeout $((trm_maxwait / 6)) --silent --show-error --header "Content-Type:application/x-www-form-urlencoded" --data "username=${user}&password=${password}" "http://${trm_domain}")"
  25. if [ -n "${raw_html##*${success}*}" ]; then
  26. exit 1
  27. fi