From f9c39da3bb5c03cbcff1d4e841ab2b5649c888bf Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 17 Mar 2021 13:40:13 +0100 Subject: [PATCH] Check for file size before trying to send fax --- fax.sh | 11 ++++++++++- faxreport.sh | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fax.sh b/fax.sh index 672410e..b651083 100755 --- a/fax.sh +++ b/fax.sh @@ -15,6 +15,13 @@ FILE=$1 echo -n "Sending file ${FILE} " REC=$(echo "$2" | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:') echo "to $REC" +#Checking for file size: +SIZE=$(ls -l | cut -d " " -f5) +if [ $SIZE -gt 10485760 ] +then + echo "File too big. Cannot be more than 10MB." + exit 2 +fi #Needs to be base64 encoded: CONTENT=$(base64 $FILE -w 0) if [ -z "$CONTENT" ]; @@ -25,7 +32,9 @@ fi #save payload to tempfile to prevent curl from throwing 'argument list too long' error. echo '{"faxlineId":"f0", "recipient":"'${REC}'", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}' > /tmp/sipgatedata.txt #Send fax -FAXID=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data @/tmp/sipgatedata.txt "https://api.sipgate.com/v2/sessions/fax" -s | jq '.sessionId' | sed -e 's:"::g' ) +REPLY=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data @/tmp/sipgatedata.txt "https://api.sipgate.com/v2/sessions/fax" -s) +FAXID=$(echo $REPLY | jq '.sessionId' | sed -e 's:"::g' ) +echo $REPLY > /tmp/sipgatereply.txt #remove tempfile rm /tmp/sipgatedata.txt if [ -z $FAXID ] diff --git a/faxreport.sh b/faxreport.sh index 15319ee..73a97fc 100755 --- a/faxreport.sh +++ b/faxreport.sh @@ -68,5 +68,5 @@ else fi if [ $DF = true ] then - grep -v $ID $BASEPATH/.fax_history > $BASEPATH/.fax_history + echo "$(grep -v "^$ID$" $BASEPATH/.fax_history)" > $BASEPATH/.fax_history fi