aboutsummaryrefslogtreecommitdiff
path: root/src/callnotifier/Logger/CallSendXmpp.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-11-28 18:46:54 +0100
committerChristian Weiske <cweiske@cweiske.de>2014-11-28 18:46:54 +0100
commitcf25e04bad163a09aeaa7830cb23d0850f904b1b (patch)
tree71f045d0320a4fcb5ceca772b3c749fe48971d3f /src/callnotifier/Logger/CallSendXmpp.php
parentd7af2527afe27d01a8ed809529c2d569d14fd0ee (diff)
downloadauerswald-callnotifier-cf25e04bad163a09aeaa7830cb23d0850f904b1b.tar.gz
auerswald-callnotifier-cf25e04bad163a09aeaa7830cb23d0850f904b1b.zip
sendxmpp logger for incoming calls
Diffstat (limited to 'src/callnotifier/Logger/CallSendXmpp.php')
-rw-r--r--src/callnotifier/Logger/CallSendXmpp.php80
1 files changed, 80 insertions, 0 deletions
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 @@
+<?php
+namespace callnotifier;
+
+/**
+ * Notify people via XMPP about incoming calls
+ * Utilizes the "sendxmpp" tool.
+ */
+class Logger_CallSendXmpp extends Logger_CallBase
+{
+ protected $recipients;
+ protected $debug = false;
+
+ public function __construct($recipients, $callTypes = 'i', $msns = array())
+ {
+ parent::__construct($callTypes, $msns);
+ $this->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
+ );
+ }
+ }
+}
+?>