Пример #1
0
 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;
     }
 }
Пример #2
0
 public static function getInstance()
 {
     if (!self::$instance) {
         return self::$instance = new EslManager();
     }
     return self::$instance;
 }
Пример #3
0
 public static function reload()
 {
     $eslMan = new EslManager();
     $eslCon = $eslMan->getESL();
     try {
         $responsestr = $eslCon->sendRecv('api reload mod_callcenter')->getBody();
     } catch (ESLException $e) {
         if (strpos($e->getMessage(), 'Not connected')) {
             throw new callcenterException('<div class="error">Unable to connect to the switch console.  This usually means that mod_event_socket is not running, or that the password that you entered during the setup process has changed. The error message was:<br>' . $e->getMessage() . '</div>');
         } else {
             throw $e;
         }
     }
     $responses = explode('', $responsestr);
     Kohana::log('debug', print_r($responses, true));
     if (substr(trim($responses[count($responses) - 1]), 0, 4) == '-ERR') {
         $this->_throwError($responsestr);
     }
     return $responsestr;
 }
Пример #4
0
 public static function set($base)
 {
     $xml = Telephony::getDriver()->xml;
     $xml_root = '//document/section[@name="configuration"]/configuration[@name="callcenter.conf"][@description="CallCenter"]';
     $xml->setXmlRoot($xml_root . '/tiers');
     $tier_xml = '/tier[@bluebox="tier_agent_' . $base['tier_agent_id'] . '"]';
     $tier_xml .= '{@queue="queue_' . $base['Tier']['queue_id'] . '"}{@agent="agent_' . $base['agent_id'] . '"}';
     $tier_xml .= '{@level="' . $base['Tier']['level'] . '"}{@position="' . $base['position'] . '"}';
     $xml->update($tier_xml);
     $esl = EslManager::getInstance();
     if ($esl->isConnected()) {
         $esl->reloadxml();
         $esl->reload('mod_callcenter');
     }
 }
Пример #5
0
 public static function set($base)
 {
     $xml = Telephony::getDriver()->xml;
     $xml_root = '//document/section[@name="configuration"]/configuration[@name="callcenter.conf"][@description="CallCenter"]';
     $xml->setXmlRoot($xml_root . '/queues');
     $queue_root = '/queue[@name="queue_' . $base['queue_id'] . '"]';
     $xml->update($queue_root . '{@bluebox="' . $base['name'] . '"}');
     $moh = '$${hold_music}';
     $xml->update($queue_root . '/param[@name="moh-sound"]{@value="' . $moh . '"}');
     foreach ($base['registry'] as $key => $val) {
         $key = preg_replace('/_/', '-', $key);
         $xml->update($queue_root . '/param[@name="' . $key . '"]{@value="' . $val . '"}');
     }
     $esl = EslManager::getInstance();
     if ($esl->isConnected()) {
         $esl->reloadxml();
         $esl->reload('mod_callcenter');
     }
 }
Пример #6
0
 public function sendfax($destination, $filename)
 {
     try {
         $faxprofile = Doctrine::getTable('InFax')->findOneBy('fxp_default', true);
         if (!$faxprofile) {
             throw new faxException('No default fax profile found!!!');
         }
         $eslCon = EslManager::getInstance()->getESL();
         $responseobj = $eslCon->sendRecv('originate {fax_verbose=true}' . $destination . ' &txfax(' . $faxprofile->fxp_spool_dir . $filename . ')');
         $responsestr = $responseobj->getBody();
         if (trim($responsestr) == '0 total.' || trim($responsestr) == '+OK') {
             echo 'Fax sent successfully to ' . $destination;
         }
         if (substr(trim($responsestr), 0, 4) == '-ERR') {
             throw new faxException($responsestr);
         }
     } catch (Exception $e) {
         echo 'Error sending fax: ' . $e->getMessage();
     }
     exit;
 }
Пример #7
0
 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;
 }
Пример #8
0
 public function eslreponse()
 {
     $eslManager = new EslManager();
     $errors = message::render(NULL, array('html' => TRUE, 'htmlTemplate' => '{text}' . "\n", 'growl' => FALSE, 'inline' => FALSE));
     if (!empty($errors['html'])) {
         echo implode('', $errors['html']);
     }
     if (!$eslManager->isConnected()) {
         if (empty($errors['html'])) {
             echo __("Failed to load ESL. Check logs");
         }
         flush();
         die;
     }
     switch ($_POST['type']) {
         case 'status':
             $result = $eslManager->status();
             break;
         case 'version':
             $result = $eslManager->version();
             break;
         case 'reloadacl':
             $result = $eslManager->reloadacl();
             break;
         case 'reloadxml':
             $result = $eslManager->reloadxml();
             break;
         case 'channels':
             $result = $eslManager->channels();
             break;
         case 'calls':
             $result = $eslManager->calls();
             break;
         case 'show_codec':
             $result = $eslManager->show('codec');
             break;
         case 'show_modules':
             $result = $eslManager->show('modules');
             break;
         case 'show_files':
             $result = $eslManager->show('file');
             break;
         case 'nat_status':
             $result = $eslManager->nat('status');
             break;
         case 'nat_reinit':
             $result = $eslManager->nat('reinit');
             break;
         case 'nat_republish':
             $result = $eslManager->nat('republish');
             break;
         case 'reload_sofia':
             $result = $eslManager->reload('mod_sofia');
             break;
         case 'sofia_status':
             $result = $eslManager->sofia('status');
             break;
         case 'sofia_profile':
             $result = $eslManager->sofia('status', 'profile', $_POST['param']);
             break;
         case 'gateway_profile':
             $result = $eslManager->sofia('status', 'gateway', $_POST['param']);
             break;
         case 'recvEvent':
             if (empty($_POST['param'])) {
                 $result = '== HELP ==' . "\n";
                 $result .= __('Please use the text input to enable an event listener that you are interested in.') . "\n";
                 $result .= 'Example: events plain all' . "\n";
                 break;
             }
             $result = $eslManager->sendRecv($_POST['param']);
             $reply = $result->getHeader('Reply-Text');
             if (!strstr($reply, '+OK event listener enabled')) {
                 $result = '== HELP ==' . "\n";
                 $result .= __('The supplied command failed to start an event listener, please ensure you are using the events command.') . "\n";
                 break;
             }
             $result = $eslManager->recvEvent();
             break;
         case 'sendRecv':
             if (empty($_POST['param'])) {
                 $result = '== HELP ==' . "\n";
                 $result .= 'Please use the text input to provide a command to execute.' . "\n";
                 $result .= 'Example: api version' . "\n";
                 break;
             }
             $result = $eslManager->sendRecv($_POST['param']);
             break;
         default:
             $result = $_POST['type'] . __(' command not supported by Bluebox ESL plugin.');
             break;
     }
     $text = $eslManager->getResponse($result);
     echo htmlentities($text);
     flush();
     die;
 }
Пример #9
0
 public function fluxresponse()
 {
     // Turn off the view
     $this->auto_render = FALSE;
     // Turn down log level
     $log_level = Kohana::config('core.log_threshold');
     Kohana::config_set('core.log_threshold', 2);
     $response = array();
     $eslManager = EslManager::getInstance();
     $subscribers = $_POST['subscribers'];
     foreach ($subscribers as $subscriber) {
         switch ($subscriber) {
             case "esl/numactivecalls":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->calls();
                     $text = $eslManager->getResponse($result);
                     preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                     $event = array("name" => $subscriber, "data" => array($output[0]));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/numactivemodules":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->show('modules');
                     $text = $eslManager->getResponse($result);
                     preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                     $event = array("name" => $subscriber, "data" => array($output[0]));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/numactivechannels":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->channels();
                     $text = $eslManager->getResponse($result);
                     preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                     $event = array("name" => $subscriber, "data" => array($output[0]));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/channels":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->channels();
                     $text = $eslManager->getResponse($result);
                     $event = array("name" => $subscriber, "data" => array($text));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/numactivecodecs":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->show('codecs');
                     $text = $eslManager->getResponse($result);
                     preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                     $event = array("name" => $subscriber, "data" => array($output[0]));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/modules":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->show('modules');
                     $text = $eslManager->getResponse($result);
                     preg_match_all("/(?<=\\,)mod_[A-Za-z_0-9]+(?=,)/", $text, $output, PREG_PATTERN_ORDER);
                     if (isset($output)) {
                         // A dirty hack to eliminate duplicates
                         $matches = array();
                         foreach ($output[0] as $value) {
                             $matches[$value] = 1337;
                         }
                         $text = "";
                         foreach ($matches as $key => $value) {
                             $text .= $key . ',';
                         }
                     } else {
                         $text = "No modules found... I think something is broken.";
                     }
                     $event = array("name" => $subscriber, "data" => array($text));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("Freeswitch not loaded.."));
                 }
                 break;
             case "esl/sipinterfaces":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->sofia('status');
                     $text = $eslManager->getResponse($result);
                     $event = array("name" => $subscriber, "data" => array($text));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/calls":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->calls();
                     $text = $eslManager->getResponse($result);
                     $event = array("name" => $subscriber, "data" => array($text));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/activecalls":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->calls();
                     $text = $eslManager->getResponse($result);
                     $output = explode("\n", $text);
                     $event = array("name" => $subscriber, "data" => array($text));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("N\\A"));
                 }
                 break;
             case "esl/uptime":
                 if ($eslManager->isConnected()) {
                     $result = $eslManager->status();
                     $text = $eslManager->getResponse($result);
                     preg_match("/[0-9]+(?=\\syear)/", $text, $output);
                     $years = $output[0];
                     preg_match("/[0-9]+(?=\\sday)/", $text, $output);
                     $days = $output[0];
                     preg_match("/[0-9]+(?=\\shour)/", $text, $output);
                     $hours = $output[0];
                     preg_match("/[0-9]+(?=\\sminute)/", $text, $output);
                     $mins = $output[0];
                     preg_match("/[0-9]+(?=\\ssecond)/", $text, $output);
                     $secs = $output[0];
                     $text = "";
                     if ($years > 0) {
                         $text .= $years . " year";
                         //Plurar check
                         if ($years > 1) {
                             $text .= "s";
                         }
                         //check if there will be another field
                         if ($days + $hours + $mins > 0) {
                             $text .= ", ";
                         }
                     }
                     if ($days > 0) {
                         $text .= $days . " day";
                         //Plurar check
                         if ($days > 1) {
                             $text .= "s";
                         }
                         //check if there will be another field
                         if ($hours + $mins > 0) {
                             $text .= ", ";
                         }
                     }
                     if ($hours > 0) {
                         $text .= $hours . " hour";
                         //Plurar check
                         if ($hours > 1) {
                             $text .= "s";
                         }
                         //check if there will be another field
                         if ($mins > 0) {
                             $text .= ", ";
                         }
                     }
                     if ($mins > 0) {
                         $text .= $mins . " minute";
                         //Plurar check
                         if ($mins > 1) {
                             $text .= "s";
                         }
                     }
                     if ($mins + $hours + $days + $years == 0 && $secs > 0) {
                         $text .= "<0 minutes";
                     }
                     $event = array("name" => $subscriber, "data" => array($text));
                 } else {
                     $event = array("name" => $subscriber, "data" => array("(Server is down)"));
                 }
                 break;
             case "esl/logviewer":
                 //Do some nifty magic to get freeswitch root path
                 $confpath = Kohana::config('freeswitch.cfg_root');
                 preg_match('/.+(?=\\/conf$)/', $confpath, $output);
                 $basepath = $output[0];
                 $logfile = $basepath . "/log/freeswitch.log";
                 if (!file_exists($logfile)) {
                     if (!file_exists($logfile = '/var/log/freeswitch/freeswitch.log')) {
                         // If you still can't find the log file, just give up
                         break;
                     }
                 }
                 if (!isset($_SESSION["esl"]["logviewer_pos"])) {
                     $logviewer_pos = filesize($logfile) - 1200;
                     if ($logviewer_pos < 0) {
                         $logviewer_pos = 0;
                     }
                 } else {
                     $logviewer_pos = $_SESSION["esl"]["logviewer_pos"];
                 }
                 $text = "";
                 $log_pointer = fopen($logfile, "r");
                 fseek($log_pointer, $logviewer_pos);
                 //Skip to the first complete line....
                 while ($char = fgetc($log_pointer)) {
                     if ($char == "\n") {
                         break;
                     }
                 }
                 while (!feof($log_pointer)) {
                     $line = fgets($log_pointer);
                     if (trim($line) != "") {
                         $text .= $line;
                     }
                 }
                 $_SESSION["esl"]["logviewer_pos"] = ftell($log_pointer);
                 fclose($log_pointer);
                 $event = array("name" => $subscriber, "data" => array($text));
                 break;
             default:
                 $event = NULL;
                 break;
         }
         if (isset($event)) {
             if (isset($_SESSION["esl"][$subscriber])) {
                 if ($_SESSION["esl"][$subscriber] == $event["data"]) {
                     continue;
                 }
             }
             $_SESSION["esl"][$subscriber] = $event["data"];
             $response[] = $event;
         }
     }
     // Restore log level
     Kohana::config_set('core.log_threshold', $log_level);
     echo json_encode($response);
     flush();
     die;
 }
Пример #10
0
 public function getRunningListByQueue($queuename)
 {
     $eslCon = EslManager::getInstance();
     $responseobj = $eslCon->sendRecv('api callcenter_config tier list ' . $queuename);
     $responsestr = $responseobj->getBody();
     if (trim($responsestr) == '0 total.' || trim($responsestr) == '+OK') {
         return array();
     }
     if (substr(trim($responsestr), 0, 4) == '-ERR') {
         throw new callcenterException($responsestr);
     }
     $tierList_arr = explode("\n", $responsestr);
     $tierList = array();
     $keyarr = explode('|', $tierList_arr[0]);
     foreach ($tierList_arr as $key => $valuestr) {
         if ($key == 0 || $valuestr == '+OK' || $valuestr == '') {
             continue;
         }
         $valuearr = explode('|', $valuestr);
         $tierList[$valuearr[0]] = array_combine($keyarr, $valuearr);
         list($queue_name, $queue_domain) = explode('@', $tierList[$valuearr[0]]['queue']);
         $tierList[$valuearr[0]]['queue_name'] = $queue_name;
         $tierList[$valuearr[0]]['queue_domain'] = $queue_domain;
         list($agent_loginid, $agent_domain) = explode('@', $tierList[$valuearr[0]]['agent']);
         $tierList[$valuearr[0]]['agent_loginid'] = $agent_loginid;
         $tierList[$valuearr[0]]['agent_domain'] = $agent_domain;
     }
     return $tierList;
 }
Пример #11
0
 protected function save_prepare(&$mediafile)
 {
     $eslManager = EslManager::getInstance();
     $result = $eslManager->api('module_exists mod_shout');
     $text = $eslManager->getResponse($result);
     if ($text == "false") {
         EslManager::getInstance()->reload('mod_shout');
     }
     if (!strcasecmp(Router::$method, 'create')) {
         if ($error = $mediafile->prepare_upload()) {
             Bluebox_Controller::$validation->add_error('mediafile[upload]', $error);
             throw new Bluebox_Exception('Upload error ' . $error);
         }
     }
     parent::save_prepare($object);
 }
Пример #12
0
 public static function delete($user, $domain, $uuid)
 {
     //vm_delete,<id>@<domain>[/profile] [<uuid>],vm_delete,mod_voicemail
     $eslManager = EslManager::getInstance();
     $resp = $eslManager->getResponse($eslManager->api(sprintf('vm_delete %s@%s %s', $user, $domain, $uuid)));
     kohana::log('debug', 'VM Delete returned ' . $resp);
 }
Пример #13
0
 public function getRunningList()
 {
     $eslCon = EslManager::getInstance();
     $responseobj = $eslCon->sendRecv('api callcenter_config queue list');
     $responsestr = $responseobj->getBody();
     if (trim($responsestr) == '0 total.' || trim($responsestr) == '+OK') {
         return array();
     }
     if (substr(trim($responsestr), 0, 4) == '-ERR') {
         throw new callcenterException($responsestr);
     }
     $queueStatus_arr = explode("\n", $responsestr);
     $queueStatus = array();
     $keyarr = explode('|', $queueStatus_arr[0]);
     foreach ($queueStatus_arr as $key => $valuestr) {
         if ($key == 0 || $valuestr == '+OK' || $valuestr == '') {
             continue;
         }
         $valuearr = explode('|', $valuestr);
         $queueStatus[$valuearr[0]] = array_combine($keyarr, $valuearr);
         list($name, $domain) = explode('@', $queueStatus[$valuearr[0]]['name']);
         $queueStatus[$valuearr[0]]['queuename'] = $name;
         $queueStatus[$valuearr[0]]['queuedomain'] = $domain;
     }
     return $queueStatus;
 }
Пример #14
0
 public function postInstallReload()
 {
     if (class_exists('EslManager', TRUE)) {
         $esl = new EslManager();
         $esl->reloadacl();
         $esl->reloadxml();
     }
 }
Пример #15
0
 public function fluxresponse()
 {
     //Turn off the view
     $this->auto_render = FALSE;
     //Set the timeout for the http request (in seconds)
     //Until flux handles firefox correctly, set this to 5
     $TIMEOUT = 5;
     $response = array();
     $eslManager = new EslManager();
     $subscribers = $_POST['subscribers'];
     $starttime = time();
     $exectime = 0;
     while (sizeof($response) == 0 && $exectime < $TIMEOUT) {
         foreach ($subscribers as $subscriber) {
             switch ($subscriber) {
                 case "switchboard/numactivecalls":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->calls();
                         $text = $eslManager->getResponse($result);
                         preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                         $event = array("name" => $subscriber, "data" => array($output[0]));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/numactivemodules":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->show('modules');
                         $text = $eslManager->getResponse($result);
                         preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                         $event = array("name" => $subscriber, "data" => array($output[0]));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/numactivechannels":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->channels();
                         $text = $eslManager->getResponse($result);
                         preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                         $event = array("name" => $subscriber, "data" => array($output[0]));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/channels":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->channels();
                         $text = $eslManager->getResponse($result);
                         $event = array("name" => $subscriber, "data" => array($text));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/numactivecodecs":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->show('codecs');
                         $text = $eslManager->getResponse($result);
                         preg_match("/[0-9]+(?=\\stotal\\.)/", $text, $output);
                         $event = array("name" => $subscriber, "data" => array($output[0]));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/modules":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->show('modules');
                         $text = $eslManager->getResponse($result);
                         preg_match_all("/(?<=\\,)mod_[A-Za-z_0-9]+(?=,)/", $text, $output, PREG_PATTERN_ORDER);
                         if (isset($output)) {
                             // A dirty hack to eliminate duplicates
                             $matches = array();
                             foreach ($output[0] as $value) {
                                 $matches[$value] = 1337;
                             }
                             $text = "";
                             foreach ($matches as $key => $value) {
                                 $text .= $key . ',';
                             }
                         } else {
                             $text = "No modules found... I think something is broken.";
                         }
                         $event = array("name" => $subscriber, "data" => array($text));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("Freeswitch not loaded.."));
                     }
                     break;
                 case "switchboard/sipinterfaces":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->sofia('status');
                         $text = $eslManager->getResponse($result);
                         $event = array("name" => $subscriber, "data" => array($text));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/calls":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->calls();
                         $text = $eslManager->getResponse($result);
                         $event = array("name" => $subscriber, "data" => array($text));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/activecalls":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->calls();
                         $text = $eslManager->getResponse($result);
                         $output = explode("\n", $text);
                         $event = array("name" => $subscriber, "data" => array($text));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("N\\A"));
                     }
                     break;
                 case "switchboard/uptime":
                     if ($eslManager->isConnected()) {
                         $result = $eslManager->status();
                         $text = $eslManager->getResponse($result);
                         preg_match("/[0-9]+(?=\\syear)/", $text, $output);
                         $years = $output[0];
                         preg_match("/[0-9]+(?=\\sday)/", $text, $output);
                         $days = $output[0];
                         preg_match("/[0-9]+(?=\\shour)/", $text, $output);
                         $hours = $output[0];
                         preg_match("/[0-9]+(?=\\sminute)/", $text, $output);
                         $mins = $output[0];
                         preg_match("/[0-9]+(?=\\ssecond)/", $text, $output);
                         $secs = $output[0];
                         $text = "";
                         if ($years > 0) {
                             $text .= $years . " year";
                             //Plurar check
                             if ($years > 1) {
                                 $text .= "s";
                             }
                             //check if there will be another field
                             if ($days + $hours + $mins > 0) {
                                 $text .= ", ";
                             }
                         }
                         if ($days > 0) {
                             $text .= $days . " day";
                             //Plurar check
                             if ($days > 1) {
                                 $text .= "s";
                             }
                             //check if there will be another field
                             if ($hours + $mins > 0) {
                                 $text .= ", ";
                             }
                         }
                         if ($hours > 0) {
                             $text .= $hours . " hour";
                             //Plurar check
                             if ($hours > 1) {
                                 $text .= "s";
                             }
                             //check if there will be another field
                             if ($mins > 0) {
                                 $text .= ", ";
                             }
                         }
                         if ($mins > 0) {
                             $text .= $mins . " minute";
                             //Plurar check
                             if ($mins > 1) {
                                 $text .= "s";
                             }
                         }
                         if ($mins + $hours + $days + $years == 0 && $secs > 0) {
                             $text .= "<0 minutes";
                         }
                         $event = array("name" => $subscriber, "data" => array($text));
                     } else {
                         $event = array("name" => $subscriber, "data" => array("(Server is down)"));
                     }
                     break;
                 case "switchboard/logviewer":
                     $logfile = "/usr/local/freeswitch/log/freeswitch.log";
                     if (!isset($_SESSION["esl"]["logviewer_pos"])) {
                         $logviewer_pos = filesize($logfile) - 1200;
                         if ($logviewer_pos < 0) {
                             $logviewer_pos = 0;
                         }
                     } else {
                         $logviewer_pos = $_SESSION["esl"]["logviewer_pos"];
                     }
                     $text = "";
                     $log_pointer = fopen($logfile, "r");
                     fseek($log_pointer, $logviewer_pos);
                     //Skip to the first complete line....
                     while ($char = fgetc($log_pointer)) {
                         if ($char == "\n") {
                             break;
                         }
                     }
                     while (!feof($log_pointer)) {
                         $line = fgets($log_pointer);
                         if (trim($line) != "") {
                             $text .= $line;
                         }
                     }
                     $_SESSION["esl"]["logviewer_pos"] = ftell($log_pointer);
                     fclose($log_pointer);
                     $event = array("name" => $subscriber, "data" => array($text));
                     break;
                 default:
                     $event = NULL;
                     break;
             }
             if (isset($event)) {
                 if (isset($_SESSION["esl"][$subscriber])) {
                     if ($_SESSION["esl"][$subscriber] == $event["data"]) {
                         continue;
                     }
                 }
                 $_SESSION["esl"][$subscriber] = $event["data"];
                 $response[] = $event;
             }
         }
         $exectime = time() - $starttime;
     }
     echo json_encode($response);
     flush();
     die;
 }