2021-03-14 10:38:08 +00:00
|
|
|
#! /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…"
|
2021-03-29 09:47:14 +00:00
|
|
|
ID=$(tail -n 1 $BASEPATH/.fax_history)
|
2021-03-14 10:51:12 +00:00
|
|
|
if [ -z $ID ]
|
|
|
|
then
|
|
|
|
echo "Nothing to guess from. Please send a fax first"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-03-29 09:47:14 +00:00
|
|
|
IDF=true
|
2021-03-14 10:38:08 +00:00
|
|
|
fi
|
|
|
|
|
2022-03-22 09:30:29 +00:00
|
|
|
. $BASEPATH/authorization.sh # Checks if account works - after changed auth processes not necessarily needed anymore
|
2021-03-14 10:38:08 +00:00
|
|
|
|
2022-03-22 09:30:29 +00:00
|
|
|
JSON=$(curl -X GET -H "accept: application/json" --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$ID" -s)
|
2021-03-14 10:38:08 +00:00
|
|
|
DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' )
|
|
|
|
if [ -z $DATE ]
|
|
|
|
then
|
2021-03-14 10:51:12 +00:00
|
|
|
echo "Fax seems to not exist with this account."
|
2021-03-14 10:38:08 +00:00
|
|
|
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"
|
2022-02-05 17:06:24 +00:00
|
|
|
if [ $DF = true ]
|
2021-03-14 11:32:09 +00:00
|
|
|
then
|
2022-02-05 17:06:24 +00:00
|
|
|
read -p "Delete id from history anyways? (y/n) " DIN
|
|
|
|
if [ $DIN =~ [yYjJ] ]
|
|
|
|
then
|
|
|
|
echo "$(grep -v "^$ID$" $BASEPATH/.fax_history)" > $BASEPATH/.fax_history
|
|
|
|
fi
|
2021-03-14 11:32:09 +00:00
|
|
|
fi
|
2021-03-14 10:38:08 +00:00
|
|
|
exit 1
|
2021-03-14 11:32:09 +00:00
|
|
|
fi
|
|
|
|
if [ $PF = false ]
|
|
|
|
then
|
2021-03-14 10:38:08 +00:00
|
|
|
echo "Speichere Report in $OUTFILE"
|
|
|
|
curl $FILE --output $OUTFILE -s
|
2021-03-14 11:32:09 +00:00
|
|
|
else
|
|
|
|
echo "Schicke Report an Drucker"
|
2021-03-14 11:58:34 +00:00
|
|
|
curl $FILE -s --output - | lp -
|
2021-03-14 11:32:09 +00:00
|
|
|
fi
|
|
|
|
if [ $DF = true ]
|
|
|
|
then
|
2021-03-17 12:40:13 +00:00
|
|
|
echo "$(grep -v "^$ID$" $BASEPATH/.fax_history)" > $BASEPATH/.fax_history
|
2021-03-14 10:38:08 +00:00
|
|
|
fi
|