dreambox web message notifier
[auerswald-callnotifier.git] / src / callnotifier / Logger / CallDreambox.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_CallDreambox extends Logger_CallBase
5 {
6     protected $host;
7
8     public function __construct($host)
9     {
10         $this->host = $host;
11     }
12
13     public function log($type, $arData)
14     {
15         switch ($type) {
16         case 'startingCall':
17             $this->displayStart($arData['call']);
18             break;
19         }
20     }
21
22
23     protected function displayStart(CallMonitor_Call $call)
24     {
25         if ($call->type != CallMonitor_Call::INCOMING) {
26             return;
27         }
28
29         $this->addUnsetVars($call);
30
31         $msg = 'Anruf von ';
32         if ($call->fromName !== null) {
33             $msg .= $call->fromName
34                 . "\nNummer: " . $call->from;
35         } else {
36             $msg .= $call->from;
37         }
38         if ($call->fromLocation !== null) {
39             $msg .= "\nOrt: " . $call->fromLocation;
40         }
41
42         $this->notify($msg);
43     }
44
45     protected function notify($msg)
46     {
47         $url = 'http://' . $this->host
48             . '/web/message?type=2&timeout=10&text=' . urlencode($msg);
49         exec(
50             'curl'
51             . ' ' . escapeshellarg($url)
52             . ' > /dev/null 2>&1 &'
53         );
54     }
55 }
56 ?>