2 namespace callnotifier;
5 * Notify people via XMPP about incoming calls
6 * Utilizes the "sendxmpp" tool.
8 class Logger_CallSendXmpp extends Logger_CallBase
10 protected $recipients;
11 public $debug = false;
13 public function __construct($recipients, $callTypes = 'i', $msns = array())
15 parent::__construct($callTypes, $msns);
16 $this->recipients = $recipients;
19 public function log($type, $arData)
21 $call = $arData['call'];
22 if (!$this->hasValidType($call)) {
25 if (!$this->hasValidMsn($call)) {
29 if ($type != 'startingCall') {
32 $this->displayStart($arData['call']);
36 protected function displayStart(CallMonitor_Call $call)
38 $this->addUnsetVars($call);
42 $varName = $type . 'Name';
43 $varLocation = $type . 'Location';
45 $str = "Incoming call:\n";
46 if ($call->$varName !== null) {
47 $str .= $call->$varName . "\n";
49 $str .= "*unknown*\n";
51 if ($call->$varLocation !== null) {
52 $str .= '' . $call->$varLocation . "\n";
54 $str .= $this->getNumber($call->$varNumber) . "\n";
59 protected function notify($msg)
61 $runInBackground = ' > /dev/null 2>&1 &';
63 $runInBackground = '';
64 echo "Message:\n" . $msg . "\n";
65 echo 'Sending to ' . count((array) $this->recipients)
69 foreach ((array)$this->recipients as $recipient) {
70 //use system instead of exec to make debugging possible
71 $cmd = 'echo ' . escapeshellarg($msg)
73 . ' --message-type=headline'//no offline storage
74 . ' --resource callnotifier'
75 . ' ' . escapeshellarg($recipient)
78 echo "Executing:\n" . $cmd . "\n";
80 system($cmd, $retval);
82 echo 'Exit code: ' . $retval . "\n";