Example #1
0
 /**
  * Indicate we support FreeSWITCH with this SIP Device and provide code to save SIP device specific settings
  */
 public static function set($obj)
 {
     // Get the asterisk driver
     $driver = Telephony::getDriver();
     // Get the asterisk manager
     $ami = $driver->ami;
     // Sanity check, ensure we have a connected manager
     if (!$ami->connected()) {
         return false;
     }
     // Get the base of this configure object
     $base = Bluebox_Record::getBaseTransactionObject();
     // Get the username of this sip device
     $username = $base->Sip->username;
     // Get the domain of this user or set it to default
     if ($base->User->Location->domain == '') {
         $domain = 'default';
     } else {
         $domain = $base->User->Location->domain;
     }
     /* TODO: This is temporary to push everything into the default context */
     $domain = 'default';
     if ($base instanceof Conference) {
         /* TODO: I expect this will have to be handled in the dialplan */
     } elseif ($base instanceof Device) {
         $ami->queueConfigUpdate('sip.conf', 'Append', $username, 'callerid', '"' . $obj['internal_name'] . '" <' . $obj['internal_number'] . '>');
         $ami->queueConfigUpdate('sip.conf', 'Append', $username, 'setvar', 'external_cid = "' . $obj['external_name'] . '" <' . $obj['external_number'] . '>');
     }
 }
Example #2
0
 /**
  * Prior to a record being deleted from the DB we delete it's config on disk. Note that the item's information is still in memory
  * while the delete transaction and records are running.
  * @param Doctrine_Event $event
  */
 public function postDelete(Doctrine_Event $event)
 {
     $invoker =& $event->getInvoker();
     $baseModel = Bluebox_Record::getBaseTransactionObject();
     $identifier = $invoker->identifier();
     // We do this because we can't set configs until we have saved all related models that may have an auto increment!
     TelephonyListener::$changedModels[$invoker->getOid()] = array('action' => 'delete', 'record' => &$invoker, 'baseModel' => $baseModel, 'identifier' => $identifier);
 }
Example #3
0
 public function postTransactionCommit(Doctrine_Event $event)
 {
     Event::run('telephony.postTransactionCommit', Bluebox_Record::getBaseTransactionObject());
     // A transaction just ended - we write out any configuration information set by the telephony driver now.
     // THIS IS WHERE WE UPDATE VIA THE SWITCH-SPECIFIC DRIVER!
     if (Kohana::config('telephony.driver') && Kohana::config('telephony.diskoutput')) {
         if (!empty(self::$changedModels)) {
             Kohana::log('debug', 'Telephony -> Creating config from saved models in memory.');
             foreach (self::$changedModels as $change) {
                 Kohana::log('debug', 'Telephony -> Preparing to generate configurartion from ' . $change['action'] . ' of ' . get_class($change['record']) . ' ' . implode(', ', $change['identifier']) . ' with OID ' . $change['record']->getOid() . ' on base model ' . get_class($change['baseModel']));
             }
             // Figure out what models were touched and either set or delete based on the action that was done to them
             // NOTE: Make sure this occurs in the same order it occurred via Doctrine's transaction
             foreach (self::$changedModels as $change) {
                 if (!empty($change['baseModel'])) {
                     Bluebox_Record::setBaseSaveObject($change['baseModel']);
                 } else {
                     Kohana::log('alert', 'Telephony -> The record ' . get_class($change['record']) . ' did not have the baseModel set!');
                     continue;
                 }
                 switch ($change['action']) {
                     case 'update':
                     case 'insert':
                         Telephony::set($change['record'], $change['identifier']);
                         break;
                     case 'delete':
                         Telephony::delete($change['record'], $change['identifier']);
                         break;
                     default:
                         Kohana::log('debug', 'An unknown action (' . $change['action'] . ') was performed on model ' . get_class($change['record']));
                         break;
                 }
             }
             self::$changedModels = array();
             Telephony::save();
             // If configured, tell the telephony engine to reload it's configs immediately
             Telephony::commit();
             // Clear the telephony info in memory. This is important, because if someone is doing a bulk add or otherwise, things get crazy
             Telephony::reset();
         }
     }
 }
Example #4
0
 /**
  * Indicate we support FreeSWITCH
  */
 public static function set($obj)
 {
     // Get the asterisk driver
     $driver = Telephony::getDriver();
     // Get the asterisk manager
     $ami = $driver->ami;
     // Sanity check, ensure we have a connected manager
     if (!$ami->connected()) {
         return false;
     }
     // Get the base of this configure object
     $base = Bluebox_Record::getBaseTransactionObject();
     // Get a unqiue name for this trunk
     $trunkName = 'trunk_' . $base->trunk_id;
     // If this is a sip trunk it belongs in sip.conf
     if (isset($base['plugins']['sip']['username'])) {
         $ami->queueConfigUpdate('sip.conf', 'NewCat', $trunkName);
         $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'type', 'friend');
         $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'host', $obj->server);
         $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'canreinvite', 'no');
         $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'context', 'default');
     }
 }
Example #5
0
 public static function delete($obj, $identifier)
 {
     $success = FALSE;
     // Sanity check
     if (!is_object($obj)) {
         return FALSE;
     }
     // Initialize telephony driver / check if already initialized
     $driver = self::getDriver();
     $driverName = get_class($driver);
     // If no driver is set, just return w/ FALSE.
     if (!$driver) {
         return FALSE;
     }
     // Support for column aggregation automagically as well as special handling of dialplan/numbers
     if (get_parent_class($obj) != 'Doctrine_Record' and get_parent_class($obj) != 'Bluebox_Record') {
         $objectName = get_parent_class($obj);
         Kohana::log('debug', 'Telephony -> Deleting information from ' . $objectName . ' (' . get_class($obj) . ') ' . implode(', ', $identifier) . ' with OID ' . $obj->getOid());
     } else {
         $objectName = get_class($obj);
         Kohana::log('debug', 'Telephony -> Deleting information from ' . $objectName . ' ' . implode(', ', $identifier) . ' with OID ' . $obj->getOid());
     }
     $modelDriverName = self::$driverName . '_' . $objectName . '_Driver';
     // Does the [Doctrine] object we were just passed contain a relevant driver? If so, call it's driver method
     if (class_exists($modelDriverName, TRUE)) {
         self::$identifier = $identifier;
         // Get base model to give to the set() routine, for reference
         $base = Bluebox_Record::getBaseTransactionObject();
         try {
             kohana::log('debug', 'Telephony -> EVAL ' . $modelDriverName . '::delete($obj, $base);');
             $success = eval('return ' . $modelDriverName . '::delete($obj, $base);');
         } catch (Exception $e) {
             Kohana::log('error', 'Telephony -> Eval exception: "' . $objectName . '". ' . $e->getMessage());
         }
         if (!empty($obj['plugins'])) {
             foreach ($obj['plugins'] as $name => $data) {
                 $pluginName = ucfirst($name);
                 $pluginDriverName = $driverName . '_' . $pluginName . '_Driver';
                 if (!class_exists($pluginDriverName)) {
                     Kohana::log('debug', 'Telephony -> No telephony plugin driver for delete of "' . $objectName . '" records...');
                     continue;
                 }
                 Kohana::log('debug', 'Telephony -> Deleting information from plugin ' . $pluginName . ' on ' . $objectName . ' ' . $identifier);
                 try {
                     kohana::log('debug', 'Telephony -> EVAL ' . $pluginDriverName . '::delete($obj, $base);');
                     $success = eval('return ' . $pluginDriverName . '::delete($obj, $base);');
                 } catch (Exception $e) {
                     Kohana::log('error', 'Telephony -> Eval exception: "' . $pluginName . '". ' . $e->getMessage());
                 }
             }
         }
         self::$identifier = NULL;
     } else {
         Kohana::log('debug', 'Telephony -> No telephony module driver for delete of "' . $objectName . '" records...');
     }
     Kohana::log('debug', 'Telephony -> Done deleting information from model "' . $objectName . '".');
     return $success;
 }
Example #6
0
 public static function delete($obj)
 {
     $doc = Telephony::getDriver()->doc;
     $base = Bluebox_Record::getBaseTransactionObject();
     if (empty($base->trunk_id)) {
         return FALSE;
     }
     $patterns = simplerouter::getOutboundPattern('emergency', 'asterisk');
     foreach ($patterns as $pattern => $exten) {
         $doc->deleteDialplanExtension($obj->context_id, $pattern);
     }
     $patterns = simplerouter::getOutboundPattern('international', 'asterisk');
     foreach ($patterns as $pattern => $exten) {
         $doc->deleteDialplanExtension($obj->context_id, $pattern);
     }
     $patterns = simplerouter::getOutboundPattern('local', 'asterisk');
     foreach ($patterns as $pattern => $exten) {
         $doc->deleteDialplanExtension($obj->context_id, $pattern);
     }
     $patterns = simplerouter::getOutboundPattern('short', 'asterisk');
     foreach ($patterns as $pattern => $exten) {
         $doc->deleteDialplanExtension($obj->context_id, $pattern);
     }
 }