Last active
September 7, 2020 22:05
-
-
Save gellweiler/85cbc8c6a918cb0af8bfb141fdaedaef to your computer and use it in GitHub Desktop.
Download access logs from telekom homepage center.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -euo pipefail | |
| TELEKOM_ID='XXX' | |
| missing_var=0 | |
| if [ -z "${TELEKOM_USERNAME:-}" ]; then | |
| echo >&2 "[ERROR] Missing \$TELEKOM_USERNAME" | |
| missing_var=1 | |
| fi | |
| if [ -z "${TELEKOM_PASSWORD:-}" ]; then | |
| echo >&2 "[ERROR] Missing \$TELEKOM_PASSWORD" | |
| missing_var=1 | |
| fi | |
| if [ -z "${STARTDATE:-}" ]; then | |
| echo >&2 "[ERROR] Missing \$STARTDATE" | |
| missing_var=1 | |
| fi | |
| if [ -z "${ENDDATE:-}" ]; then | |
| echo >&2 "[ERROR] Missing \$ENDDATE" | |
| missing_var=1 | |
| fi | |
| if [ "$missing_var" -gt 0 ]; then | |
| echo >&2 "[ERROR] Missing mandatory env variables" | |
| exit 1 | |
| fi | |
| rm -f access.log | |
| cookiejar=$(mktemp) | |
| function cleanup { | |
| rm -f "${cookiejar}" | |
| rm -f access.log.tmp.zip | |
| } | |
| trap cleanup EXIT INT TERM | |
| echo >&2 "[INFO] Get the tid (session id) for the login screen" | |
| tid="$(curl -Ls -w %{url_effective} -c "${cookiejar}" "https://homepage.t-online.de/cm4all-analytics/${TELEKOM_ID}/" | grep 'name="tid"' | grep -o -P '(?<=value=")[^"]*')" | |
| echo "$tid" | |
| echo >&2 "[INFO] Login to homepage center" | |
| curl -o /dev/null -L -c "${cookiejar}" -b "${cookiejar}" \ | |
| --data-urlencode pw_domt="t-online.de" \ | |
| --data-urlencode tid="${tid}" \ | |
| --data-urlencode pw_usr="${TELEKOM_USERNAME}" \ | |
| --data-urlencode pw_pwd="${TELEKOM_PASSWORD}" \ | |
| --data-urlencode pw_submit="" \ | |
| "https://accounts.login.idm.telekom.com/sso" | |
| echo >&2 "[INFO] Check that the necessary cookies exists" | |
| cat "${cookiejar}" | grep SID >/dev/null | |
| start=$(date -d $STARTDATE +%s) | |
| end=$(date -d $ENDDATE +%s) | |
| d="$start" | |
| while [[ $d -le $end ]] | |
| do | |
| dformated="$(date -d @$d +%Y-%m-%d)" | |
| echo >&2 "[INFO] downloading log files for $dformated" | |
| if curl -f -L -o access.log.tmp.zip -b "${cookiejar}" "https://homepage.t-online.de/cm4all-analytics/${TELEKOM_ID}/${dformated}/access_log.zip"; then | |
| unzip -p access.log.tmp.zip access_log.txt >> access.log | |
| else | |
| echo >&2 "[INFO] failed downloading log file" | |
| fi | |
| rm -f access.log.tmp.zip | |
| d=$(( $d + 86400 )) | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment