#!/bin/bash
# Hans Schou

# Dokumentation:
# https://www.bibob.dk/SmsSender.asmx?op=SendMessage

# Character set: UTF-8

if [ -z "$PASSWORD" ]; then
	echo "Variablen \$PASSWORD til bibob ikke sat."
	echo "Start med at eksekvere kommandoen:"
	echo "    read -s PASSWORD ; export PASSWORD"
	exit 1
fi

smscontents="Godt nytår!"
cellphone="22648020"
fromNumber="22648020"
smsto="22648020"

password=$( echo -n $PASSWORD | md5sum | sed -e 's/ .*$//' )

BIBOBPOST=bibob.post

cat > $BIBOBPOST << EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SendMessage xmlns="http://www.bibob.dk/">
      <cellphone>$cellphone</cellphone>
      <password>$password</password>
      <smsTo>
        <string>$smsto</string>
	<!-- more receiver lines goes here -->
      </smsTo>
      <smscontents>$smscontents</smscontents>
      <fromNumber>$fromNumber</fromNumber>
      <deliveryReport>false</deliveryReport>
    </SendMessage>
  </soap:Body>
</soap:Envelope>
EOF

wget -q -O - \
	--header='SOAPAction: http://www.bibob.dk/SendMessage' \
	--header='Content-Type: text/xml; charset=utf-8' \
	--post-file=$BIBOBPOST \
	"https://www.bibob.dk/SmsSender.asmx?WSDL"

rm $BIBOBPOST
