Compare commits

...

2 Commits

Author SHA1 Message Date
Gandalf 3771439131 Readme dazu 2021-03-04 18:31:10 +01:00
Gandalf 6f372c4f08 Aufteilung in verschiedene Dateien 2021-03-04 18:29:32 +01:00
7 changed files with 39 additions and 28 deletions

View File

@ -5,6 +5,9 @@ This is a small hack to send faxes via the sipgate REST API from the command lin
Add your login credentials to `login_credentials_muster.sh` and rename the file to `login_credentials.sh`
## Usage
`skript.sh <letter.pdf> <recipient>`
`fax.sh <letter.pdf> <recipient>`
sipgate doesn't accept pdf files larger than 30 pages or 10MB.
For now, `<recipient>` has to be numbers-only, starting with `+49`. It is planned to parse different number formats.
~~For now, `<recipient>` has to be numbers-only, starting with `+49`. It is planned to parse different number formats.~~ Should be done.
`balance.sh` just gives your account balance.

8
authorization.sh Executable file
View File

@ -0,0 +1,8 @@
. login_credentials.sh
AUTH_TOKEN=$(echo $(curl --request POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --data-urlencode client_id=sipgate-app-web --data-urlencode grant_type=password --data-urlencode username=$SIPUSER --data-urlencode password=$SIPPWD https://api.sipgate.com/login/sipgate-apps/protocol/openid-connect/token -s | jq '.access_token') | sed 's/\"//g')
if [ -z "$AUTH_TOKEN" ];
then
echo "Login failed"
else
echo "Logged in"
fi

4
balance.sh Executable file
View File

@ -0,0 +1,4 @@
#! /bin/bash
. authorization.sh
. getbalance.sh

21
fax.sh Executable file
View File

@ -0,0 +1,21 @@
#! /bin/bash
. authorization.sh
#Prepare fax credentials:
FILE=$1
echo $FILE
REC=$(echo $2 | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
#Needs to be base64 encoded:
CONTENT=$(base64 $FILE -w 0)
if [ -z "$CONTENT" ];
then
echo "Encoding failed"
fi
DATA='{"faxlineId":"f0", "recipient":"+495512829364", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}'
#Send fax
curl -i --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data "$DATA" "https://api.sipgate.com/v2/sessions/fax" -s
echo
#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" -s | jq
#And show the account balance
. getbalance.sh

1
getbalance.sh Executable file
View File

@ -0,0 +1 @@
curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/balance" -s | jq

2
login_credentials_muster.sh Normal file → Executable file
View File

@ -1,5 +1,3 @@
#! /bin/bash
#Add your sipgate username and password here:
SIPUSER=
SIPPWD=

View File

@ -1,24 +0,0 @@
#! /bin/bash
FILE=$1
echo $FILE
REC=$(echo $2 | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
. login_credentials.sh
AUTH_TOKEN=$(echo $(curl --request POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --data-urlencode client_id=sipgate-app-web --data-urlencode grant_type=password --data-urlencode username=$SIPUSER --data-urlencode password=$SIPPWD https://api.sipgate.com/login/sipgate-apps/protocol/openid-connect/token -s | jq '.access_token') | sed 's/\"//g')
if [ -z "$AUTH_TOKEN" ];
then
echo "Login failed"
else
echo "Logged in"
fi
CONTENT=$(base64 $FILE -w 0)
if [ -z "$CONTENT" ];
then
echo "Encoding failed"
fi
DATA='{"faxlineId":"f0", "recipient":"+495512829364", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}'
#echo "$DATA"
curl -i --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data "$DATA" "https://api.sipgate.com/v2/sessions/fax" -s
echo
curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history" -s | jq
curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/balance" -s | jq