Updated auth process

This commit is contained in:
Gandalf 2022-03-22 10:30:29 +01:00
parent b450ba94ec
commit f58de6d3f3
4 changed files with 7 additions and 6 deletions

5
fax.sh
View file

@ -55,6 +55,7 @@ if [[ -z $REC0 || -z $1 ]]
then then
usage usage
fi fi
#Check if account works - not necessarily needed anymore, since sipgate changed their auth processes
. $BASEPATH/authorization.sh . $BASEPATH/authorization.sh
#Prepare fax credentials: #Prepare fax credentials:
FILE=$1 FILE=$1
@ -94,7 +95,7 @@ fi
#save payload to tempfile to prevent curl from throwing 'argument list too long' error. #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 echo '{"faxlineId":"f0", "recipient":"'${REC}'", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}' > /tmp/sipgatedata.txt
#Send fax #Send fax
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) REPLY=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --user $SIPUSER:$SIPPWD --data @/tmp/sipgatedata.txt "https://api.sipgate.com/v2/sessions/fax" -s)
FAXID=$(echo $REPLY | jq '.sessionId' | sed -e 's:"::g' ) FAXID=$(echo $REPLY | jq '.sessionId' | sed -e 's:"::g' )
echo $REPLY > /tmp/sipgatereply.txt echo $REPLY > /tmp/sipgatereply.txt
#remove tempfile #remove tempfile
@ -108,6 +109,6 @@ else
echo "$FAXID" >> $BASEPATH/.fax_history echo "$FAXID" >> $BASEPATH/.fax_history
fi fi
#Check if fax request was accepted by sipgate #Check if fax request was accepted by sipgate
curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history/$FAXID" -s | jq '.faxStatusType' curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$FAXID" -s | jq '.faxStatusType'
#And show the account balance #And show the account balance
. $BASEPATH/getbalance.sh . $BASEPATH/getbalance.sh

View file

@ -36,9 +36,9 @@ then
IDF=true IDF=true
fi fi
. $BASEPATH/authorization.sh # stellt AUTH_TOKEN bereit . $BASEPATH/authorization.sh # Checks if account works - after changed auth processes not necessarily needed anymore
JSON=$(curl -X GET -H "accept: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history/$ID" -s) JSON=$(curl -X GET -H "accept: application/json" --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$ID" -s)
DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' ) DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' )
if [ -z $DATE ] if [ -z $DATE ]
then then

View file

@ -1,4 +1,4 @@
BAL=$(curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/balance" -s) BAL=$(curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/balance" -s)
AMOUNT=$(echo $BAL | jq '.amount') AMOUNT=$(echo $BAL | jq '.amount')
CUR=$(echo $BAL | jq '.currency' | sed -e 's:"::g' ) CUR=$(echo $BAL | jq '.currency' | sed -e 's:"::g' )
AMOUNT=$(echo "scale=2; $AMOUNT/10000" | bc -l) AMOUNT=$(echo "scale=2; $AMOUNT/10000" | bc -l)

View file

@ -4,7 +4,7 @@ BASEPATH=$(dirname $(realpath $0))
. $BASEPATH/authorization.sh . $BASEPATH/authorization.sh
while read LINE; while read LINE;
do do
JSON=$(curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history/$LINE" -s) JSON=$(curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$LINE" -s)
STATUS=$(echo $JSON | jq '.faxStatusType' | sed -e 's:"::g' ) STATUS=$(echo $JSON | jq '.faxStatusType' | sed -e 's:"::g' )
DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' ) DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' )
TARGET=$(echo $JSON | jq '.target' | sed -e 's:"::g' ) TARGET=$(echo $JSON | jq '.target' | sed -e 's:"::g' )