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.

35 lines
1.1 KiB

  1. #!/bin/sh
  2. # captive portal auto-login script template with credentials as parameters
  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="example.com"
  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. user="${1}"
  19. password="${2}"
  20. success="Thank you!"
  21. # login with credentials
  22. #
  23. response="$("${trm_fetch}" --user-agent "${trm_useragent}" --referer "http://www.example.com" --silent --connect-timeout $((trm_maxwait/6)) --data "username=${user}&password=${password}" --header "Content-Type:application/x-www-form-urlencoded" "http://${trm_domain}")"
  24. if [ -n "$(printf "%s" "${response}" | grep "${success}")" ]
  25. then
  26. exit 0
  27. else
  28. exit 2
  29. fi