Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
|
3e8962f01d | ||
|
7c35a31aff | ||
|
de37f626c7 | ||
|
9f96328b70 | ||
|
b615aaa634 |
22
README.md
22
README.md
|
@ -2,30 +2,8 @@
|
||||||
This is a small hack to send faxes via the sipgate REST API from the command line.
|
This is a small hack to send faxes via the sipgate REST API from the command line.
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
### Dependencies
|
|
||||||
* `bash >= 4.3`
|
|
||||||
* `curl`
|
|
||||||
* `sed`
|
|
||||||
* `bc`
|
|
||||||
* `getopt`
|
|
||||||
* [`jq`](https://stedolan.github.io/jq/download/).
|
|
||||||
* optional: `ghostscript`
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
Add your login credentials to `login_credentials_muster.sh` and rename the file to `.env`
|
Add your login credentials to `login_credentials_muster.sh` and rename the file to `.env`
|
||||||
|
|
||||||
Since sipgate enforces 2FA, your usual username and password won't work anymore.
|
|
||||||
Now, you need a so-called [Personal Access Token](https://app.sipgate.com/w0/personal-access-token), that you can retrieve after you login to the web interface.
|
|
||||||
Enable at least the following scopes:
|
|
||||||
* `balance:read`
|
|
||||||
* `devices:callerid:read`
|
|
||||||
* `devices:callerid:write`
|
|
||||||
* `history:read`
|
|
||||||
* `sessions:fax:write`
|
|
||||||
|
|
||||||
Enter the token-ID as `SIPUSER` or `TOKENID` and the token as `SIPPWD` or `TOKEN`.
|
|
||||||
It's prefered to use the `TOKEN*` variables, but in that case, the `SIP*` variables **MUST** be left empty/unset.
|
|
||||||
|
|
||||||
If you use Letterheads Address database, uncomment the last line of that file and add `your/path/to/Letterhead`
|
If you use Letterheads Address database, uncomment the last line of that file and add `your/path/to/Letterhead`
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
BASEPATH=$(dirname $(realpath $0))
|
BASEPATH=$(dirname $(realpath $0))
|
||||||
. $BASEPATH/.env
|
. $BASEPATH/.env
|
||||||
|
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 [ $TOKENID ] && [ -z $SIPUSER ]
|
if [ -z "$AUTH_TOKEN" ];
|
||||||
then SIPUSER=$TOKENID
|
|
||||||
fi
|
|
||||||
if [ $TOKEN ] && [ -z $SIPPWD ]
|
|
||||||
then SIPPWD=$TOKEN
|
|
||||||
fi
|
|
||||||
|
|
||||||
AUTH_TOKEN=$(curl -o /dev/null -s -w "%{http_code}\n" --request GET --header 'Accept: application/json' --user $SIPUSER:$SIPPWD https://api.sipgate.com/v2/authorization/userinfo -s)
|
|
||||||
if [ $AUTH_TOKEN = "200" ];
|
|
||||||
then
|
then
|
||||||
echo "Login OK"
|
|
||||||
else
|
|
||||||
echo "Login failed"
|
echo "Login failed"
|
||||||
|
else
|
||||||
|
echo "Logged in"
|
||||||
fi
|
fi
|
||||||
|
|
23
callerid.sh
Executable file
23
callerid.sh
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
BASEPATH=$(dirname $(realpath $0))
|
||||||
|
#. $BASEPATH/authorization.sh
|
||||||
|
CALLER_ID="+49"
|
||||||
|
CALLER_ID_JSON=
|
||||||
|
case "$SPOOF" in
|
||||||
|
"1")
|
||||||
|
RANDOM=$(date +%s%N | cut -b10-19)
|
||||||
|
for (( x=1;x<=11;x++ ));
|
||||||
|
do
|
||||||
|
CALLER_ID="${CALLER_ID}$[$RANDOM % 10]"
|
||||||
|
done
|
||||||
|
CALLER_ID_JSON='{"value":"'${CALLER_ID}'"}'
|
||||||
|
;;
|
||||||
|
"-1")
|
||||||
|
CALLER_ID_JSON=$OLD_CALLER_ID_JSON
|
||||||
|
;;
|
||||||
|
"0")
|
||||||
|
CALLER_ID_JSON='{"value":"'${DEFAULT_CALLER_ID}'"}'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
OLD_CALLER_ID_JSON=$(curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/w0/faxlines/f0/callerid" -s)
|
||||||
|
REPLY=$(curl --request PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data ${CALLER_ID_JSON} "https://api.sipgate.com/v2/w0/faxlines/f0/callerid" -s)
|
||||||
|
#echo $OLD_CALLER_ID_JSON $CALLER_ID_JSON
|
22
fax.sh
22
fax.sh
|
@ -19,13 +19,14 @@ BASEPATH=$(dirname $(realpath $0))
|
||||||
|
|
||||||
#Parsing Parameters:
|
#Parsing Parameters:
|
||||||
unset $GETOPT_COMPATIBLE
|
unset $GETOPT_COMPATIBLE
|
||||||
ARGV=$(getopt -n "$0" -a -o "" -l "help,handle:" -- "$@")
|
ARGV=$(getopt -n "$0" -a -o "" -l "help,spoof-callerid,handle:" -- "$@")
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
eval set -- "$ARGV"
|
eval set -- "$ARGV"
|
||||||
REC0=
|
REC0=
|
||||||
|
SPOOF=0
|
||||||
#Now we have $@ clean and tidy and begin parsing
|
#Now we have $@ clean and tidy and begin parsing
|
||||||
while :
|
while :
|
||||||
do
|
do
|
||||||
|
@ -41,6 +42,10 @@ do
|
||||||
REC0=$($LETTERHEAD_PATH/Adressen/address.sh -f $HAND 2>/dev/null | sed 's: ::g')
|
REC0=$($LETTERHEAD_PATH/Adressen/address.sh -f $HAND 2>/dev/null | sed 's: ::g')
|
||||||
shift
|
shift
|
||||||
shift ;;
|
shift ;;
|
||||||
|
"--spoof-callerid")
|
||||||
|
SPOOF=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
"--")
|
"--")
|
||||||
shift
|
shift
|
||||||
break ;;
|
break ;;
|
||||||
|
@ -55,15 +60,20 @@ 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
|
||||||
|
#Spoof CallerID if wanted
|
||||||
|
if [ $SPOOF -eq 1 ]
|
||||||
|
then
|
||||||
|
. $BASEPATH/callerid.sh
|
||||||
|
SPOOF=-1
|
||||||
|
fi
|
||||||
#Prepare fax credentials:
|
#Prepare fax credentials:
|
||||||
FILE=$1
|
FILE=$1
|
||||||
echo -n "Sending file ${FILE} "
|
echo -n "Sending file ${FILE} "
|
||||||
REC=$(echo "$REC0" | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
|
REC=$(echo "$REC0" | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
|
||||||
echo "to $REC"
|
echo "to $REC"
|
||||||
#Checking for file size:
|
#Checking for file size:
|
||||||
if [ ! -e "$FILE" ]
|
if [ ! -e $FILE ]
|
||||||
then
|
then
|
||||||
echo "File not found"
|
echo "File not found"
|
||||||
exit 2
|
exit 2
|
||||||
|
@ -95,7 +105,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' --user $SIPUSER:$SIPPWD --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' --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' )
|
FAXID=$(echo $REPLY | jq '.sessionId' | sed -e 's:"::g' )
|
||||||
echo $REPLY > /tmp/sipgatereply.txt
|
echo $REPLY > /tmp/sipgatereply.txt
|
||||||
#remove tempfile
|
#remove tempfile
|
||||||
|
@ -109,6 +119,8 @@ 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' --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$FAXID" -s | jq '.faxStatusType'
|
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'
|
||||||
|
#Revert CallerID spoofing
|
||||||
|
. $BASEPATH/callerid.sh
|
||||||
#And show the account balance
|
#And show the account balance
|
||||||
. $BASEPATH/getbalance.sh
|
. $BASEPATH/getbalance.sh
|
||||||
|
|
|
@ -36,9 +36,9 @@ then
|
||||||
IDF=true
|
IDF=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. $BASEPATH/authorization.sh # Checks if account works - after changed auth processes not necessarily needed anymore
|
. $BASEPATH/authorization.sh # stellt AUTH_TOKEN bereit
|
||||||
|
|
||||||
JSON=$(curl -X GET -H "accept: application/json" --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$ID" -s)
|
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' )
|
DATE=$(echo $JSON | jq '.created' | sed -e 's:"::g' )
|
||||||
if [ -z $DATE ]
|
if [ -z $DATE ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
BAL=$(curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/balance" -s)
|
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)
|
||||||
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)
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
# Add your sipgate token-ID and token here:
|
#Add your sipgate username and password here:
|
||||||
# TOKENID is an alias for SIPUSER
|
SIPUSER=
|
||||||
# TOKEN is an alias for SIPPWD,
|
SIPPWD=
|
||||||
# so for legacy reasons you can use those variables as well.
|
#Add your default CallerID here:
|
||||||
# Take care: The SIP* variables MUST be empty/unset or contain the config to use.
|
DEFAULT_CALLER_ID=
|
||||||
# If they are set and not empty, the corresponding TOKEN* variable is ignored.
|
|
||||||
TOKENID=
|
|
||||||
TOKEN=
|
|
||||||
#uncomment if you use Letterheads Address database
|
#uncomment if you use Letterheads Address database
|
||||||
#LETTERHEAD_PATH=
|
#LETTERHEAD_PATH=
|
||||||
#Add your default CallerID here:
|
|
||||||
DEFAULT_CALLER_ID="anonymous"
|
|
||||||
LETTERHEAD_PATH="/home/bernhardt/Entwicklung/Letterhead"
|
|
||||||
|
|
|
@ -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' --user $SIPUSER:$SIPPWD "https://api.sipgate.com/v2/history/$LINE" -s)
|
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)
|
||||||
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' )
|
||||||
|
|
Loading…
Reference in a new issue