From 122105044a35b66ad7c248fdb0ec96828783c5f3 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Sun, 14 Mar 2021 11:38:08 +0100 Subject: [PATCH] Download fax reports --- README.md | 5 +++++ faxreport.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 faxreport.sh diff --git a/README.md b/README.md index 03a56fe..824746f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ Spaces in filename seem to make trouble at the moment - avoid them. `balance.sh` just gives your account balance. +`faxreport.sh [options] [id]` loads the report of a given fax id (as shown by status.sh) + : Options are not implemented yet, but those are gonna be accepted: + * `-p` to only print and not save the report + * `-d` to delete the given id from `.fax_history` + ## Recommendation Put ``` diff --git a/faxreport.sh b/faxreport.sh new file mode 100755 index 0000000..6b9edc6 --- /dev/null +++ b/faxreport.sh @@ -0,0 +1,52 @@ +#! /bin/bash +# depends on bash >4.3 + +# Prepare Input Variables +PF=false #print flag +DF=false #delete flag +ID="" # fax id +IDF=false # ID set flag +BASEPATH=$(dirname $(realpath $0)) + +for ARG in $@ +do + case $ARG in + "-p") PF=true ;; + "-d") DF=true ;; + "-pd") PF=true; DF=true ;; + "-dp") PF=true; DF=true ;; + esac + if [[ $ARG =~ [0-9]+ && $IDF = false ]] + then + ID=$ARG + IDF=true + echo $ID + fi +done + +if [ $IDF = false ] +then + echo "Guessing…" + exit 0 # Nur, damit es nix durcheinanderbringt, bis die guess-Arithmetik implementiert ist +fi + +. $BASEPATH/authorization.sh # stellt AUTH_TOKEN bereit + +JSON=$(curl -X GET -H "accept: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history/$ID" -s) +DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' ) +if [ -z $DATE ] +then + echo "Fax seems to not exist. " + exit 1 +fi +DATE=$(date -d $DATE +%Y%m%d%H%M) +FILE=$(echo $JSON | jq '.reportUrl' | sed -e 's:"::g' ) +OUTFILE="$DATE-$ID-report.pdf" +if [ -z $FILE ] +then + echo "Fax seems not to be sent successfully (yet). No report available" + exit 1 +else + echo "Speichere Report in $OUTFILE" + curl $FILE --output $OUTFILE -s +fi