Exemple #1
0
 public static function register($driver, $hook)
 {
     $driverName = Telephony::getDriverName();
     if (!$driverName or $driverName == 'none') {
         return true;
     } elseif (!class_exists($driverName)) {
         Kohana::log('error', 'Telephony -> Unable to register the dialplan driver \'' . $driverName . '\'');
         return false;
     }
     $hookClass = $driverName . '_' . $driver . '_Driver';
     if (!class_exists($hookClass)) {
         Kohana::log('error', 'Telephony -> Unable to register the dialplan hook \'' . $driver . '\'(' . $hookClass . ')');
         return false;
     }
     if (empty(self::$dialplanSections)) {
         kohana::log('debug', 'Telephony -> EVAL ' . $driverName . '::getDialplanSections();');
         $sections = eval('return ' . $driverName . '::getDialplanSections();');
         if (is_array($sections)) {
             self::$dialplanSections = $sections;
         }
     }
     if (!in_array($hook, self::$dialplanSections)) {
         //Logger::ExceptionByCaller();
         throw new Exception('The hook ' . $hook . ' is not a recognized telephony global hook. (While trying to register callback ' . $driver . ')');
     }
     // Register event as _telephony.action with the callback array as the callback
     Event::add('_telephony.' . $hook, array($hookClass, $hook));
     Kohana::log('debug', 'Telephony -> Added hook for _telephony.' . $hook . ' to call ' . $hookClass . '::' . $hook);
     return TRUE;
 }
Exemple #2
0
 public static function getAvaliableRingGroupMembers()
 {
     $members =& Event::$data;
     $devices = Doctrine::getTable('Device')->findAll();
     foreach ($devices as $device) {
         if (!empty($device['plugins']['sip'])) {
             switch (Telephony::getDriverName()) {
                 case 'Asterisk':
                     $bridge = 'SIP/';
                     $bridge .= $device['plugins']['sip']['username'];
                     break;
                 case 'FreeSwitch':
                     $bridge = 'user/';
                     $bridge .= $device['plugins']['sip']['username'];
                     $bridge .= '@$${location_' . $device['User']['location_id'] . '}';
                     break;
                 default:
                     continue 2;
             }
             $member = array('bridge' => $bridge, 'display_name' => $device['name'], 'display_type' => 'Sip Device', 'id' => $device['device_id'], 'type' => 'Device');
         } else {
             continue;
         }
         $members[] = $member;
     }
 }
Exemple #3
0
 public function index()
 {
     $this->template->content = new View('callmanager/index');
     $callmanagerdriverName = strtolower(Telephony::getDriverName()) . '_callmanager_Driver';
     $callmanagerdriverObj = new $callmanagerdriverName();
     $this->view->summaryfields = $callmanagerdriverObj->getSummaryFields();
 }
Exemple #4
0
 public function executeAction($funcname, $params)
 {
     $callmanagementclass = Telephony::getDriverName() . '_cm' . $funcname . '_Driver';
     try {
         $callmanagementobject = new $callmanagementclass();
     } catch (Exception $e) {
         throw new callmanagerException('Unable to find driver for ' . $funcname);
     }
     return $callmanagementobject->executeAction($params);
 }
 public static function __callStatic($funcname, $params = null)
 {
     if ($params == null) {
         $number = Event::$data;
     } else {
         $number = $params[0];
     }
     $faxProfile = $number['Destination'];
     $dispobj = Doctrine::getTable('FaxDisposition')->findOneBy('fxd_id', $faxProfile['fxp_fxd_id']);
     $dispositionDriver = Telephony::getDriverName() . '_' . $dispobj->name . '_Driver';
     if (count($params) > 0) {
         return call_user_func_array($dispositionDriver . '::' . $funcname, $params);
     } else {
         return call_user_func($dispositionDriver . '::' . $funcname);
     }
 }
Exemple #6
0
 protected function prepareUpdateView($baseModel = NULL)
 {
     $types = array();
     switch (Telephony::getDriverName()) {
         case 'FreeSwitch':
             $types = array(SimpleRoute::TYPE_SIMPLE => 'Short Hand', SimpleRoute::TYPE_REGEX => 'Regex');
             break;
         default:
             $types = array(SimpleRoute::TYPE_SIMPLE => 'Short Hand');
     }
     $patternTemplate = new View('simpleroute/pattern.mus', array('mustache_template' => FALSE));
     $patternTemplate = json_encode((string) $patternTemplate);
     $patternTemplate = str_replace(array('\\n', '  '), '', $patternTemplate);
     $this->view->patternTemplate = $patternTemplate;
     $this->view->types = $types;
     parent::prepareUpdateView($baseModel);
 }
Exemple #7
0
 /**
  * Indicate we support Asterisk with this SIP Device and provide code to save SIP device specific settings
  */
 public static function set($base)
 {
     kohana::log('debug', 'Asterisk -> Create a context dialplan for id ' . $base['context_id']);
     $doc = Telephony::getDriver()->doc;
     // Create the context we're going to start routing at. This just does pre-call setup routines
     // In Asterisk land this ensures a [context_X] exists and has, at minimum, a NoOp() at the top
     // and a GoSub to our actual list of available numbers
     $doc->createRoutableContext($base['context_id']);
     // THE ABOVE TWO LINES SHOULD RESULT IN:
     // [context_1]
     // exten => _X,NoOp()        ; added by dialplanStart
     // exten => _X,n,network-stuff
     // exten => _X,n,conditioning-stuff
     // exten => _X,n,blah
     // exten => _X,n,Gosub(destinations_1) ; added by diaplanEnd
     // exten => _X,n,FinishUpCallHooks   ; diaplanEnd hooks
     // exten => _X,n,Hangup()
     //
     // [context_1_destinations]
     //
     // THAT'S IT. It will delete and recreate the context_1 section but not destinations_1. This LOGIC belongs elsewhere, NOT HERE.
     // Does this number go anywhere?
     if ($base['Number']['class_type']) {
         $dialplan = $base['Number']['dialplan'];
         // Create the exten => 3000,Goto(number_X)  or whatever in the [destinations] list so we can actually reach this guy via the current context
         // This also sets some internal variable that tracks our current number and context (for use by the next few items) and
         // also creates a dummy [number_X] section
         // NOTE: This also sets a pointer in memory for the preNumber, actual dialplan and postNumber routines to use
         // too add their "stuff" to this dialplan entry
         //$doc->createDestination($base['context_id'], $base['Number']['number_id'], $base['Number']['number']);
         $doc->createDialplanExtension($base['context_id'], $base['Number']['number_id'], $base['Number']['number']);
         // Make sure the extensions list for this context exists
         $doc->createContext('extensions.conf', 'extensions_' . $base['context_id'], $base['Number']['number']);
         // Delete any existing references to this particular extension number in the extensions list
         $doc->deleteDialplanExtension($base['context_id'], $base['Number']['number']);
         // Add a NoOp at the top of all numbers
         $doc->add('NoOp', 1, array('replace' => TRUE));
         // Add an extension-specific prenumber items
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the number_X section
         dialplan::preNumber($base['Number']);
         // Replace nay matching extension definitions
         $doc->add('GoSub(number_' . $base['Number']['number_id'] . ',${EXTEN},1)', NULL, array('replace' => TRUE));
         // Add a failure route for this dialplan
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the dialplan
         dialplan::postNumber($base['Number']);
         if (!empty($dialplan['terminate']['action'])) {
             switch ($dialplan['terminate']['action']) {
                 case 'transfer':
                     if ($transfer = astrsk::getTransferToNumber($dialplan['terminate']['transfer'])) {
                         $doc->add('Goto(' . $transfer . ')');
                     } else {
                         $doc->add('Hangup');
                     }
                     break;
                 case 'continue':
                     $doc->add('Return');
                     break;
                 case 'hangup':
                 default:
                     $doc->add('Hangup');
                     break;
             }
         } else {
             $doc->add('Hangup');
         }
         $doc->createContext('extensions.conf', 'number_' . $base['Number']['number_id'], NULL, array('replace' => TRUE));
         // Add related final destination XML
         $destinationDriverName = Telephony::getDriverName() . '_' . substr($base['Number']['class_type'], 0, strlen($base['Number']['class_type']) - 6) . '_Driver';
         Kohana::log('debug', 'Asterisk -> Looking for destination driver ' . $destinationDriverName);
         // Is there a driver?
         if (class_exists($destinationDriverName, TRUE)) {
             // Logging
             Kohana::log('debug', 'Asterisk -> Adding information for destination ' . $base['Number']['number_id'] . ' from model "' . get_class($base['Number']) . '" to our telephony configuration...');
             // Drivers are always singletons, and are responsible for persistenting data for their own config generation via static vars
             // TODO: Change this for PHP 5.3, which doesn't require eval(). Don't change this until all the cool kids are on PHP 5.3*/
             kohana::log('debug', 'Asterisk -> EVAL ' . $destinationDriverName . '::dialplan($base->Number);');
             // Drivers are always singletons, and are responsible for persistenting data for their own config generation via static vars
             // TODO: Change this for PHP 5.3, which doesn't require eval(). Don't change this until all the cool kids are on PHP 5.3*/
             $success = eval('return ' . $destinationDriverName . '::dialplan($base->Number);');
         }
         $doc->add('Return');
         return TRUE;
     } else {
         kohana::log('debug', 'Asterisk -> REMOVING NUMBER ID ' . $base['Number']['number_id'] . ' FROM CONTEXT ' . $base['context_id']);
         // Number doesn't go anywhere - delete it altogether.
         $doc->deleteDialplanExtension($base['context_id'], $base['Number']['number']);
     }
     return FALSE;
 }
Exemple #8
0
 /**
  * Indicate we support FreeSWITCH with this SIP Device and provide code to save SIP device specific settings
  */
 public static function set($base)
 {
     $xml = Telephony::getDriver()->xml;
     // Reference to our XML document, context and extension. Creates the extension & context if does not already exist
     $xml = FreeSwitch::createExtension('number_' . $base['Number']['number_id'], 'main', 'context_' . $base['context_id']);
     // Does this number go anywhere?
     if ($base['Number']['class_type']) {
         kohana::log('debug', 'FreeSWITCH -> ADDING NUMBER ' . $base['Number']['number'] . ' (' . $base['Number']['number_id'] . ') TO CONTEXT ' . $base['context_id']);
         // Dialplans are a bit different - we don't want to keep anything that is currently in an extension, in the event it's totally changed
         $xml->deleteChildren();
         // Check what number they dialed
         $xml->update('/condition[@field="destination_number"]{@expression="^' . $base['Number']['number'] . '$"}');
         // Now that the extension and condition fields are created for this number, set our root to inside the condition
         $xml->setXmlRoot($xml->getXmlRoot() . '/condition[@field="destination_number"][@expression="^' . $base['Number']['number'] . '$"]');
         $dialplan = $base['Number']['dialplan'];
         // Add an extension-specific prenumber items
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the XML document for the add
         dialplan::preNumber($base['Number']);
         if (!empty($dialplan['terminate']['action'])) {
             switch ($dialplan['terminate']['action']) {
                 case 'transfer':
                     $xml->update('/action[@application="set"][@bluebox="settingEndBridge"][@data="hangup_after_bridge=true"]');
                     $xml->update('/action[@application="set"][@bluebox="settingFail"][@data="continue_on_fail=true"]');
                     break;
             }
         }
         // Add related final destination XML
         $destinationDriverName = Telephony::getDriverName() . '_' . substr($base['Number']['class_type'], 0, strlen($base['Number']['class_type']) - 6) . '_Driver';
         Kohana::log('debug', 'FreeSWITCH -> Looking for destination driver ' . $destinationDriverName);
         // Is there a driver?
         if (class_exists($destinationDriverName, TRUE)) {
             // Logging
             Kohana::log('debug', 'FreeSWITCH -> Adding information for destination ' . $base['Number']['number_id'] . ' from model "' . get_class($base['Number']) . '" to our telephony configuration...');
             // Drivers are always singletons, and are responsible for persistenting data for their own config generation via static vars
             // TODO: Change this for PHP 5.3, which doesn't require eval(). Don't change this until all the cool kids are on PHP 5.3*/
             kohana::log('debug', 'FreeSWITCH -> EVAL ' . $destinationDriverName . '::dialplan($base->Number);');
             $success = eval('return ' . $destinationDriverName . '::dialplan($base->Number);');
         }
         // Add an anti-action / failure route for this dialplan
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the XML document for the add
         dialplan::postNumber($base['Number']);
         if (!empty($dialplan['terminate']['action'])) {
             switch ($dialplan['terminate']['action']) {
                 case 'transfer':
                     if ($transfer = fs::getTransferToNumber($dialplan['terminate']['transfer'])) {
                         $xml->update('/action[@application="transfer"][@data="' . $transfer . '"]');
                     } else {
                         $xml->update('/action[@application="hangup"]');
                     }
                     break;
                 case 'continue':
                     break;
                 case 'hangup':
                 default:
                     $xml->update('/action[@application="hangup"]');
                     break;
             }
         } else {
             $xml->update('/action[@application="hangup"]');
         }
     } else {
         kohana::log('debug', 'FreeSWITCH -> REMOVING NUMBER ID ' . $base['Number']['number_id'] . ' FROM CONTEXT ' . $base['context_id']);
         $xml->deleteNode();
     }
 }
Exemple #9
0
 public static function executeAction($funcname, $params)
 {
     $callmanagementclass = strtolower(Telephony::getDriverName()) . '_callmanager_Driver';
     $callmanagementobject = new $callmanagementclass();
     return $callmanagementobject->executeAction($funcname, $params);
 }
Exemple #10
0
 public static function getFunctionsForCall($callinfo)
 {
     $callmanagementclass = Telephony::getDriverName() . '_callmanager_Driver';
     $callmanagementobj = new $callmanagementclass();
     return $callmanagementobj->getFunctionsForCall($callinfo);
 }
Exemple #11
0
 public function reload()
 {
     $driverName = Telephony::getDriverName();
     $result = call_user_func(array($driverName . '_callcenter_settings_Driver', 'reload'));
 }