2 namespace callnotifier;
4 class Logger_CallDreambox extends Logger_CallBase
8 public function __construct($host, $callTypes = 'io', $msns = array())
10 parent::__construct($callTypes, $msns);
14 public function log($type, $arData)
16 if ($type != 'startingCall') {
20 $call = $arData['call'];
21 if (!$this->hasValidType($call)) {
24 if (!$this->hasValidMsn($call)) {
27 $this->displayStart($call);
31 protected function displayStart(CallMonitor_Call $call)
33 if ($call->type != CallMonitor_Call::INCOMING) {
37 $this->addUnsetVars($call);
40 if ($call->fromName !== null) {
41 $msg .= $call->fromName
42 . "\nNummer: " . $call->from;
46 if ($call->fromLocation !== null) {
47 $msg .= "\nOrt: " . $call->fromLocation;
53 protected function notify($msg)
55 $dreamboxUrl = 'http://' . $this->host;
56 $token = $this->fetchSessionToken($dreamboxUrl);
58 if ($token === false) {
62 $url = $dreamboxUrl . '/web/message';
63 $this->debug('POSTing to: ' . $url);
67 . '&text=' . urlencode($msg)
68 . '&sessionid=' . urlencode($token);
69 $ctx = stream_context_create(
74 'Content-type: application/x-www-form-urlencoded',
80 $xml = @file_get_contents($url, false, $ctx);
81 $sx = $this->handleError($xml);
84 protected function fetchSessionToken($dreamboxUrl)
86 $xml = @file_get_contents($dreamboxUrl . '/web/session');
87 $sx = $this->handleError($xml);
92 $token = (string) $sx;
97 protected function handleError($xml)
100 if (!isset($http_response_header)) {
102 'Error talking with dreambox web interface: '
103 . error_get_last()['message']
108 list($http, $code, $message) = explode(
109 ' ', $http_response_header[0], 3
112 //dreambox web interface authentication has been enabled
114 'Error: Web interface authentication is required'
119 'Failed to fetch dreambox session token: '
120 . error_get_last()['message']
126 $sx = simplexml_load_string($xml);
127 if (isset($sx->e2state) && (string) $sx->e2state === 'False') {
128 $this->warn('Error: ' . $sx->e2statetext);
135 protected function warn($msg)