/**
  * the singleton pattern
  *
  * @return Voipmanager_Controller_Snom_Phone
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Voipmanager_Controller_Snom_Phone();
     }
     return self::$_instance;
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_backends['Asterisk_Context'] = Voipmanager_Controller_Asterisk_Context::getInstance();
     $this->_backends['Asterisk_Meetme'] = Voipmanager_Controller_Asterisk_Meetme::getInstance();
     $this->_backends['Asterisk_SipPeer'] = Voipmanager_Controller_Asterisk_SipPeer::getInstance();
     $this->_backends['Asterisk_Voicemail'] = Voipmanager_Controller_Asterisk_Voicemail::getInstance();
     $this->_backends['Snom_Line'] = Voipmanager_Controller_Snom_Line::getInstance();
     $this->_backends['Snom_Location'] = Voipmanager_Controller_Snom_Location::getInstance();
     $this->_backends['Snom_Phone'] = Voipmanager_Controller_Snom_Phone::getInstance();
     $this->_backends['Snom_Setting'] = Voipmanager_Controller_Snom_Setting::getInstance();
     $this->_backends['Snom_Software'] = Voipmanager_Controller_Snom_Software::getInstance();
     $this->_backends['Snom_Template'] = Voipmanager_Controller_Snom_Template::getInstance();
 }
 /**
  * create edit phone dialog
  *
  * @param int $phoneId
  * @todo catch permission denied exceptions only
  * 
  */
 public function editSnomPhone($phoneId = NULL)
 {
     $snomTemplates = Voipmanager_Controller_Snom_Template::getInstance()->search();
     $snomLocations = Voipmanager_Controller_Snom_Location::getInstance()->search();
     $pagination = new Tinebase_Model_Pagination(array('sort' => 'name'));
     $asteriskSipPeers = Voipmanager_Controller_Asterisk_SipPeer::getInstance()->search(NULL, $pagination);
     $encodedAsteriskSipPeers = Zend_Json::encode($asteriskSipPeers->toArray());
     if (!empty($phoneId)) {
         $snomPhone = Voipmanager_Controller_Snom_Phone::getInstance()->get($phoneId);
         $_phoneData = $snomPhone->toArray();
         $_phoneSettingsData = Voipmanager_Controller_Snom_PhoneSettings::getInstance()->get($_phoneData['id'])->toArray();
         $_templateData = Voipmanager_Controller_Snom_Template::getInstance()->get($_phoneData['template_id'])->toArray();
         $_settingsData = Voipmanager_Controller_Snom_Setting::getInstance()->get($_templateData['setting_id'])->toArray();
         $_writableFields = array('web_language', 'language', 'display_method', 'mwi_notification', 'mwi_dialtone', 'headset_device', 'message_led_other', 'global_missed_counter', 'pickup_indication', 'scroll_outgoing', 'show_local_line', 'show_call_status', 'call_waiting');
         foreach ($_writableFields as $wField) {
             $_fieldRW = $wField . '_writable';
             if ($_settingsData[$_fieldRW] == '0') {
                 $_phoneSettingsData[$wField] = $_settingsData[$wField];
                 $_notWritable[$wField] = 'true';
             } else {
                 if (empty($_phoneSettingsData[$wField])) {
                     $_phoneSettingsData[$wField] = $_settingsData[$wField];
                 }
                 $_notWritable[$wField] = '';
             }
         }
         $encodedWritable = Zend_Json::encode($_notWritable);
         $_phoneData = array_merge($_phoneSettingsData, $_phoneData);
         // encode the data arrays
         $encodedSnomPhone = Zend_Json::encode($_phoneData);
         $encodedSnomLines = Zend_Json::encode($snomPhone->lines->toArray());
     } else {
         $encodedWritable = '{}';
         $encodedSnomPhone = "{current_model:'snom320',redirect_event:'none'}";
         $encodedSnomLines = '[]';
         //$encodedSettings = '{}';
     }
     $encodedTemplates = Zend_Json::encode($snomTemplates->toArray());
     $encodedLocations = Zend_Json::encode($snomLocations->toArray());
     $view = new Zend_View();
     $view->setScriptPath('Tinebase/views');
     $view->title = "edit snom phone data";
     $view->jsExecute = 'Tine.Voipmanager.Snom.Phones.EditDialog.display(' . $encodedSnomPhone . ', ' . $encodedSnomLines . ', ' . $encodedAsteriskSipPeers . ', ' . $encodedTemplates . ', ' . $encodedLocations . ', ' . $encodedWritable . ');';
     header('Content-Type: text/html; charset=utf-8');
     echo $view->render('jsclient.php');
 }
 /**
  * dial number
  *
  * @param   int $_number
  * @param   string $_phoneId
  * @param   string $_lineId
  * @throws  Phone_Exception_NotFound
  * 
  * @todo check dial right here
  * @todo move to MyPhone controller
  */
 public function dialNumber($_number, $_phoneId = NULL, $_lineId = NULL)
 {
     $accountId = Tinebase_Core::getUser()->getId();
     $vmController = Voipmanager_Controller_Snom_Phone::getInstance();
     $backend = Phone_Backend_Factory::factory($this->_callBackendType);
     $number = $this->_cleanNumber($_number);
     if ($_phoneId === NULL && $_lineId === NULL) {
         // use first phone and first line
         $filter = new Voipmanager_Model_Snom_PhoneFilter(array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $accountId)));
         $phones = $vmController->search($filter);
         if (count($phones) > 0) {
             $phone = $vmController->get($phones[0]->id);
             if ($this->_callBackendType === Phone_Backend_Factory::ASTERISK) {
                 if (count($phone->lines) > 0) {
                     $asteriskLineId = $phone->lines[0]->asteriskline_id;
                 } else {
                     throw new Phone_Exception_NotFound('No line found for this phone.');
                 }
             }
         } else {
             throw new Phone_Exception_NotFound('No phones found.');
         }
     } else {
         // use given phone and line ids
         $phone = Phone_Controller_MyPhone::getInstance()->get($_phoneId);
         if ($this->_callBackendType === Phone_Backend_Factory::ASTERISK) {
             $line = $phone->lines[$phone->lines->getIndexById($_lineId)];
             $asteriskLineId = $line->asteriskline_id;
         }
     }
     if ($this->_callBackendType === Phone_Backend_Factory::SNOM_WEBSERVER) {
         $filter = new Voipmanager_Model_Snom_PhoneFilter(array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $accountId)));
         foreach ($vmController->search($filter) as $p) {
             if ($p->id == $phone->id) {
                 // @todo http_user / http_pass
                 $backend->dialNumber($p->ipaddress, $number, null, null);
                 break;
             }
         }
     } else {
         $asteriskLine = Voipmanager_Controller_Asterisk_SipPeer::getInstance()->get($asteriskLineId);
         $asteriskContext = Voipmanager_Controller_Asterisk_Context::getInstance()->get($asteriskLine->context_id);
         $backend->dialNumber('SIP/' . $asteriskLine->name, $asteriskContext->name, $number, 1, "WD {$number}");
     }
 }
 /**
  * keeps track of the call history
  * 
  * the callId can be 3c3b966053be-phxdiv27t9gm or 7027a58643aeb25149e4861076f1b0a9@xxx.xxx.xxx.xxx
  * we strip everything after the @ character
  *
  * @param string $mac the mac address of the phone
  * @param string $event event can be connected, disconnected, incoming, outgoing, missed
  * @param string $callId the callid
  * @param string $local the username of the asterisk sip peer
  * @param string $remote the remote number
  * 
  * @todo add correct line_id
  */
 public function callHistory($mac, $event, $callId, $local, $remote)
 {
     // there is no need to start session for call history
     // it's a single shot request
     parent::_authenticate();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Event: {$event} CallId: {$callId} Local: {$local} Remote: {$remote} ");
     }
     $phone = Voipmanager_Controller_Snom_Phone::getInstance()->getByMacAddress($mac);
     $controller = Phone_Controller::getInstance();
     $pos = strpos($callId, '@');
     if ($pos !== false) {
         $callId = substr($callId, 0, $pos);
     }
     $pos = strpos($local, '@');
     if ($pos !== false) {
         $local = substr($local, 0, $pos);
     }
     $pos = strpos($remote, '@');
     if ($pos !== false) {
         $remote = substr($remote, 0, $pos);
     }
     $call = new Phone_Model_Call(array('id' => substr($callId, 0, 40), 'phone_id' => $phone->getId(), 'line_id' => $local));
     switch ($event) {
         case 'outgoing':
             $call->source = $local;
             $call->destination = $remote;
             $call->direction = Phone_Model_Call::TYPE_OUTGOING;
             $controller->callStarted($call);
             break;
         case 'incoming':
             $call->source = $local;
             $call->destination = $remote;
             $call->direction = Phone_Model_Call::TYPE_INCOMING;
             $controller->callStarted($call);
             break;
         case 'connected':
             $controller->callConnected($call);
             break;
         case 'disconnected':
             $controller->callDisconnected($call);
             break;
     }
 }
Exemple #6
0
 /**
  * set status
  *
  * @param Voipmanager_Model_Snom_Phone $_phone
  * @param string $_type
  * @return Voipmanager_Model_Snom_Phone
  * @throws  Voipmanager_Exception_UnexpectedValue
  */
 protected function _setStatus($_phone, $_type)
 {
     if (!isset($_SERVER['HTTP_USER_AGENT']) || !isset($_SERVER["REMOTE_ADDR"])) {
         throw new Voipmanager_Exception_UnexpectedValue('useragent string or ip address missing');
     }
     $userAgent = $_SERVER['HTTP_USER_AGENT'];
     #$userAgent = 'Mozilla/4.0 (compatible; snom320-SIP 7.1.30';
     if (preg_match('/^Mozilla\\/4\\.0 \\(compatible; (snom...)\\-SIP (\\d+\\.\\d+\\.\\d+)/i', $userAgent, $matches)) {
         $_phone->current_model = $matches[1];
         $_phone->current_software = $matches[2];
     } else {
         throw new Voipmanager_Exception_UnexpectedValue('unparseable useragent string');
     }
     $_phone->ipaddress = $_SERVER["REMOTE_ADDR"];
     switch ($_type) {
         case 'settings':
             $_phone->settings_loaded_at = Tinebase_DateTime::now();
             break;
         case 'firmware':
             $_phone->firmware_checked_at = Tinebase_DateTime::now();
             break;
     }
     Voipmanager_Controller_Snom_Phone::getInstance()->update($_phone);
     return $_phone;
 }
 /**
  * create a phone with a line for the current user
  */
 protected function _createSnomPhone()
 {
     $testLocation = $this->_getSnomLocation();
     $returnedLocation = Voipmanager_Controller_Snom_Location::getInstance()->create($testLocation);
     $testTemplate = $this->_getSnomTemplate();
     $returnedTemplate = Voipmanager_Controller_Snom_Template::getInstance()->create($testTemplate);
     $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array(array('account_id' => Tinebase_Core::getUser()->getId(), 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, 'read_right' => TRUE, 'write_right' => TRUE, 'dial_right' => TRUE)));
     $sipPeer = Voipmanager_Controller_Asterisk_SipPeer::getInstance()->create($this->_getAsteriskSipPeer());
     $lines = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_Line', array(array('asteriskline_id' => $sipPeer->getId(), 'linenumber' => 1, 'lineactive' => 1, 'idletext' => 'idle')));
     $settings = new Voipmanager_Model_Snom_PhoneSettings(array('web_language' => 'English'));
     $this->_phone = Voipmanager_Controller_Snom_Phone::getInstance()->create(new Voipmanager_Model_Snom_Phone(array('description' => 'Created by Tine 2.0 DEMO DATA', 'macaddress' => substr(Tinebase_Record_Abstract::generateUID(), 0, 12), 'location_id' => $returnedLocation['id'], 'template_id' => $returnedTemplate['id'], 'current_model' => 'snom300', 'redirect_event' => 'none', 'http_client_info_sent' => '1', 'http_client_user' => Tinebase_Record_Abstract::generateUID(), 'http_client_pass' => Tinebase_Record_Abstract::generateUID(), 'rights' => $rights, 'lines' => $lines, 'settings' => $settings)));
 }
Exemple #8
0
 /**
  * send HTTP Client Info to multiple phones
  *
  * @param  array $phoneIds list of phoneId's to send http client info to
  * @return array
  */
 public function resetHttpClientInfo($phoneIds)
 {
     $result = array('success' => TRUE);
     Voipmanager_Controller_Snom_Phone::getInstance()->resetHttpClientInfo($phoneIds);
     return $result;
 }
 /**
  * update one phone
  *
  * @param Voipmanager_Model_Snom_Phone $_phone
  * @return Voipmanager_Model_Snom_Phone
  * @throws Voipmanager_Exception_Validation
  *
  * @todo do not overwrite update() -> use inspectBefore/After functions
  */
 public function update(Tinebase_Record_Interface $_phone)
 {
     $oldRecord = $this->get($_phone->getId());
     $rights = $this->_backend->getPhoneRights($_phone->getId());
     $currentAccountId = Tinebase_Core::getUser()->getId();
     $hasRight = false;
     foreach ($rights as $right) {
         if ($right->account_id == $currentAccountId) {
             // if  user has the right to dial and read the phone, he or she may edit the lines
             if ($right->dial_right && $right->read_right) {
                 $hasRight = true;
             }
         }
     }
     if (!$hasRight) {
         throw new Tinebase_Exception_AccessDenied('You are not allowed to edit this phone!');
     }
     // user is not allowed to add or remove lines
     $diff = $oldRecord->lines->diff($_phone->lines);
     if (count($diff->added) > 0 || count($diff->removed) > 0) {
         throw new Tinebase_Exception_AccessDenied('You are not allowed to add or remove lines of this phone!');
     }
     // user may just edit the lines and settings of the phone
     $oldRecord->lines = $_phone->lines;
     $oldRecord->settings = $_phone->settings;
     return parent::update($oldRecord);
 }