public static function getRegistrations($SIPInterface) { $cache = Cache::instance(); $sipRegCache = $cache->get('cache_' . $SIPInterface); if (!$sipRegCache) { $eslManager = new EslManager(); $cmd = 'sofia xmlstatus profile ' . $SIPInterface; $result = $eslManager->api($cmd); $xml = $eslManager->getResponse($result); $registrations = array(); if ($xml !== 'Command execution failed.') { $xml = @simplexml_load_string($xml); if ($xml and $xml->registrations and $xml->registrations->registration and $xml->registrations->registration != '') { $registrations = $xml->registrations->registration; } else { Kohana::log('info', 'No XML returned'); } } else { Kohana::log('info', $cmd . ': ' . 'Command execution failed.'); } $result = array(); foreach ($registrations as $r) { $r = (array) $r; $r['interface'] = $SIPInterface; $result[] = $r; } return $result; //array ('user' => 'blah', '') } else { Kohana::log('info', 'Using cached registration'); return $sipRegCache; } }
public static function getList($user, $domain) { //@TODO 10 second cache? //@TODO Put this in a cron self::updateVMTables($user, $domain); $eslManager = new EslManager(); $cmd = sprintf('vm_list %s@%s xml', $user, $domain); $call = $eslManager->api($cmd); $resp = $eslManager->getResponse($call); kohana::log('debug', 'ESL: Cmd ' . $cmd . ' failed to execute in an expected way. Result: ' . $resp); $xml = simplexml_load_string("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" . $resp); $voicemails = array(); foreach ($xml as $voicemail) { $voicemails[] = (array) $voicemail; } return $voicemails; }
public function _get_conferences() { $bbconf = array(); foreach (Doctrine_Query::create()->select("n.number,e.name,e.conference_id")->from("Number n,Conference e")->where("n.class_type='ConferenceNumber'")->andWhere("n.foreign_id=e.conference_id")->orderBy("e.name")->execute(array(), Doctrine::HYDRATE_SCALAR) as $conference) { $bbconf["conference_" . $conference["e_conference_id"]] = $conference; } $clid = array(); foreach (Doctrine::getTable('Device')->findAll() as $ext) { if (array_key_exists('callerid', $ext['plugins']) && array_key_exists('internal_name', $ext['plugins']['callerid']) && array_key_exists('internal_number', $ext['plugins']['callerid'])) { if (array_key_exists('sip', $ext['plugins']) && array_key_exists('username', $ext['plugins']['sip'])) { $clid[$ext['plugins']['sip']['username']] = array('name' => $ext['plugins']['callerid']['internal_name'], 'ext' => $ext['plugins']['callerid']['internal_number']); } } } $esl = new EslManager(); $res = $esl->api("conference xml_list"); $xml = new XMLReader(); $xml->xml($esl->getResponse($res)); $conferences = array(); $path = array(); while ($xml->read()) { if ($xml->nodeType == XMLReader::ELEMENT) { array_unshift($path, $xml->name); if ($xml->name == 'conference') { $conferences[] = array(); end($conferences); $conf =& $conferences[key($conferences)]; $current =& $conferences[key($conferences)]; $conf['members'] = array(); } elseif ($xml->name == 'member') { $key = count($conf['members']); $conf['members'][$key] = array(); $member =& $conf['members'][$key]; $current =& $conf['members'][$key]; } if ($xml->hasAttributes) { while ($xml->moveToNextAttribute()) { $current[$xml->name] = $xml->value; if ($xml->name == 'name' && array_key_exists($xml->value, $bbconf)) { $current['bluebox'] = $bbconf[$xml->value]; } } } } elseif ($xml->nodeType == XMLReader::END_ELEMENT) { array_shift($path); } elseif ($xml->nodeType == XMLReader::TEXT) { $current[$path[0]] = $xml->value; if ($path[0] == "caller_id_number" && array_key_exists($xml->value, $clid)) { $current['clid'] = $clid[$xml->value]; } } } return $conferences; }