Main server runs a PHP script published in this post. It's stored as /var/www/send-xxyyzz.php, where xxyyzz is a simple code to protect this script. As the content of a folder is never shown, the script cannot be called unless it's name is known.
Application server has a checkhandler defined in the smsd.conf file:
checkhandler = /usr/local/bin/smsd_checkhandler
The application which uses another server to send SMS, creates a message files using an additional Send_thru header:
To: 358401234567
Send_thru: MAINSERVER
Hi there, this is a message from the Application.
Send_thru: MAINSERVER
Hi there, this is a message from the Application.
The checkhandler code is:
#!/bin/bash
tmp=`formail -zx "Send_thru:" < "$1"`
if [ "x$tmp" = "xMAINSERVER" ]; then
SERVER="123.123.123.123"
SCRIPT="send-xxyyzz.php"
FILE=`mktemp /tmp/send_thru_XXXXXX`
rtout=30
to=`formail -zx "To:" < "$1"`
messagebody=`sed -e '1,/^$/ d' < "$1"`
urlsafe_message=`echo "$messagebody" | sed 's/\n/%0A/g' | sed 's/%/%25/g' | sed 's/&/%26/g' | sed 's/#/%23/g'`
# https is used with a self-signed certificate:
wget --no-check-certificate -t 1 --read-timeout=$rtout \
"https://${SERVER}/${SCRIPT}?To=$to&Message=$urlsafe_message" -O $FILE > /dev/null 2>&1
# Check the result.
if grep "OK." $FILE >/dev/null; then
rm $FILE
rm "$1"
exit 2 # Checkhandler has spooled this message.
fi
fi
exit 0
tmp=`formail -zx "Send_thru:" < "$1"`
if [ "x$tmp" = "xMAINSERVER" ]; then
SERVER="123.123.123.123"
SCRIPT="send-xxyyzz.php"
FILE=`mktemp /tmp/send_thru_XXXXXX`
rtout=30
to=`formail -zx "To:" < "$1"`
messagebody=`sed -e '1,/^$/ d' < "$1"`
urlsafe_message=`echo "$messagebody" | sed 's/\n/%0A/g' | sed 's/%/%25/g' | sed 's/&/%26/g' | sed 's/#/%23/g'`
# https is used with a self-signed certificate:
wget --no-check-certificate -t 1 --read-timeout=$rtout \
"https://${SERVER}/${SCRIPT}?To=$to&Message=$urlsafe_message" -O $FILE > /dev/null 2>&1
# Check the result.
if grep "OK." $FILE >/dev/null; then
rm $FILE
rm "$1"
exit 2 # Checkhandler has spooled this message.
fi
fi
exit 0
'bash' Syntax Highlight powered by GeSHi