From cf25e04bad163a09aeaa7830cb23d0850f904b1b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 28 Nov 2014 18:46:54 +0100 Subject: sendxmpp logger for incoming calls --- src/callnotifier/Logger/CallSendXmpp.php | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/callnotifier/Logger/CallSendXmpp.php (limited to 'src/callnotifier/Logger/CallSendXmpp.php') diff --git a/src/callnotifier/Logger/CallSendXmpp.php b/src/callnotifier/Logger/CallSendXmpp.php new file mode 100644 index 0000000..c970430 --- /dev/null +++ b/src/callnotifier/Logger/CallSendXmpp.php @@ -0,0 +1,80 @@ +recipients = $recipients; + } + + public function log($type, $arData) + { + $call = $arData['call']; + if (!$this->hasValidType($call)) { + return; + } + if (!$this->hasValidMsn($call)) { + return; + } + + if ($type != 'startingCall') { + return; + } + $this->displayStart($arData['call']); + } + + + protected function displayStart(CallMonitor_Call $call) + { + $this->addUnsetVars($call); + + $type = 'from'; + $varNumber = $type; + $varName = $type . 'Name'; + $varLocation = $type . 'Location'; + + $str = "Incoming call:\n"; + if ($call->$varName !== null) { + $str .= $call->$varName . "\n"; + } else { + $str .= "*unknown*\n"; + } + if ($call->$varLocation !== null) { + $str .= '' . $call->$varLocation . "\n"; + } + $str .= $this->getNumber($call->$varNumber) . "\n"; + + $this->notify($str); + } + + protected function notify($msg) + { + $runInBackground = ' > /dev/null 2>&1 &'; + if ($this->debug) { + $runInBackground = ''; + echo $msg . "\n"; + } + + foreach ((array)$this->recipients as $recipient) { + //use system instead of exec to make debugging possible + system( + 'echo ' . escapeshellarg($msg) + . ' | sendxmpp' + . ' --message-type=headline'//no offline storage + . ' --resource callnotifier' + . ' ' . escapeshellarg($recipient) + . $runInBackground + ); + } + } +} +?> -- cgit v1.2.3