I have an sh script that is listening to log output.
When it finds an IP address under certain conditions, it need to send a curl request out to that IP address (Receiver is a Polycom VoIP phone if it matters).
On the receiver, I am getting:
PushParserC::parseDoc: Expecting <PolycomIPPhone>: $'<PolycomIPPhone><Data
where as a correct line produces this:
wappPushHandlerC::Handle: <PolycomIPPhone><Data priority="Critical">Key:Setup
and on a -v dump of curl I get:
curl: (6) Could not resolve host: priority="Critical">Key.... < should be an IP address
In both cases, it looks like communication is being cut the at white space in my script. Most solutions get rid of the whitespace, but that breaks the XHTML that is expected.
My script is below
#!/bin/sh
tail -0f /var/log/somelogfile.log | while read line
do
if echo $line | grep "\[WARNING\]" | grep -q "SIP auth failure" ; then
# Log detected sip authentication error to file
STR="$(echo $line | awk '{print "Date:",$1,"Time:",$2,"Login:",$14,"IP:",$17}')" >> logger.txt
# Get the found private IP address out of the errored line
IP="$(echo $STR | rev | cut -d" " -f1 | rev)"
# Provide output to the user of the IP to brute
echo "Target IP: " $IP
# Content Type header
CT="Content-Type: application/x-com-polycom-spipx"
# The XHTML to send to the phone in question for forced factory reset
XHTML="curl -v --digest -u Push:Push -d $'<PolycomIPPhone><Data priority=\"Critical\">Key:Setup\nKey:Dialpad2\nKey:Dialpad9\nKey:Dialpad9\nKey:Dialpad9\nKey:Softkey4\nKey:Dialpad1\nKey:Dialpad5\nKey:Dialpad5</Data></PolycomIPPhone>' --header \"$CT\" $IP/push"
# print out URL for test
echo $XHTML
RESPONSE=`$XHTML`
echo
echo $RESPONSE
fi
done
# This is an example of the fuctional code that works straight in the terminal.
# curl --digest -u Push:Push -d $'<PolycomIPPhone><Data priority="Critical">Key:Setup\nKey:Dialpad2\nKey:Dialpad9\nKey:Dialpad9\nKey:Dialpad9\nKey:Softkey4\nKey:Dialpad1\nKey:Dialpad5\nKey:Dialpad5</Data></PolycomIPPhone>' --header "Content-Type: application/x-com-polycom-spipx" xx.xx.xx.xx/push && echo
Other solutions remove whitespace which isn't possible in this context or encode. Neither of which work in this application though!
Thanks!