示例#1
0
    protected function post_save(&$object)
    {
        $extension = $_POST['number']['number'];
        
        $context_id = $_POST['number']['context_id'];

        $location_id = $_POST['number']['location_id'];

        $external_cid = $_POST['callerid']['external_number'];

        $success = Bluebox_Tenant::createUserExtension($object['user_id'], $extension, $context_id, $location_id, array(
                'callerid_external_number' => $extension,
                'callerid_external_number' => $external_cid,
                'sip_password' => $_POST['user']['create_password']
            )
        );

        if (!$success)
        {
           Doctrine_Manager::connection()->rollback();           

           throw new Bluebox_Validation_Exception('Could not quick create!');
        }
        else
        {
            Doctrine_Manager::connection()->commit();
        }

        parent::post_save($object);
    }
示例#2
0
文件: configure.php 项目: swk/bluebox
 public static function initializeMasterTenant()
 {
     $session = Session::instance();
     Doctrine::getTable('Location')->getRecordListener()->get('MultiTenant')->setOption('disabled', true);
     Doctrine::getTable('User')->getRecordListener()->get('MultiTenant')->setOption('disabled', true);
     $options = array();
     $options['account'] = array('name' => 'Master Account', 'type' => Account::TYPE_NORMAL);
     $options['location'] = array('name' => 'Main Location');
     $options['user'] = array('username' => $session->get('installer.adminEmailAddress'), 'password' => $session->get('installer.adminPassword'), 'user_type' => User::TYPE_SYSTEM_ADMIN);
     Bluebox_Tenant::initializeTenant($options);
     Bluebox_Tenant::initializeSite('localhost', 1);
     // Force a login of the master/admin user for the remainder of the install
     Auth::instance()->force_login($session->get('installer.adminEmailAddress'));
     users::isUserAuthentic();
     users::getCurrentUser();
 }
示例#3
0
 /**
  * Use this function to create a new account, location and user all in one shot. You will get an associative array back containing
  * the new account, location and user IDs, respectively
  * @param string $username
  * @param string $password
  * @param string $accountName
  * @param string $locationName
  * @return array
  *
  * TODO: Should we just pass in a list of options, and then pass it around accordingly?
  */
 public static function initializeTenant($options, $users = array())
 {
     // Add the core admin user to the system
     // TODO: Should check for errors here...
     Kohana::log('debug', 'Initializing account...');
     try {
         $accountId = self::initializeAccount($options['account']);
         self::$accountName = $options['account']['name'];
     } catch (Exception $e) {
         Kohana::log('error', 'Creating account failed: ' . $e->getMessage());
         // Bubble up
         throw $e;
     }
     Kohana::log('debug', 'Initializing location...');
     try {
         $locationId = self::initializeLocation($accountId, $options['location']);
     } catch (Exception $e) {
         Kohana::log('error', 'Creating location failed (rolling back tenant): ' . $e->getMessage());
         $account = Doctrine::getTable('Account')->find($accountId);
         $account->delete();
         self::$accountName = NULL;
         // Bubble up
         throw $e;
     }
     Kohana::log('debug', 'Initializing user...');
     try {
         $userId = self::initializeUser($accountId, $locationId, $options['user']);
     } catch (Exception $e) {
         Kohana::log('error', 'Creating user failed (rolling back tenant: ' . $e->getMessage());
         $location = Doctrine::getTable('Location')->find($locationId);
         $location->delete();
         $account = Doctrine::getTable('Account')->find($accountId);
         $account->delete();
         self::$accountName = NULL;
         // Bubble up
         throw $e;
     }
     Kohana::log('debug', 'Initializing contexts...');
     self::initializeContext($accountId);
     Kohana::log('debug', 'Scanning packages for tenant-setup routines.');
     Package_Catalog::buildCatalog();
     $packagelist = Package_Catalog::getPackageList();
     foreach ($packagelist as $name => $packages) {
         if (empty($packages[Package_Manager::STATUS_INSTALLED])) {
             continue;
         }
         $installed = reset($packages[Package_Manager::STATUS_INSTALLED]);
         try {
             $configureInstance = Package_Catalog::getPackageConfigureInstance($installed['identifier']);
             if (method_exists($configureInstance, 'createTenant')) {
                 $configureInstance->createTenant($package);
                 Kohana::log('debug', 'Multi-tenant initialization routine for ' . $package['packageName'] . ' complete');
             }
         } catch (Exception $e) {
             Kohana::log('error', 'Multi-tenant initialization routine createTenant failed on ' . $package['packageName'] . ': ' . $e->getMessage());
             message::set('Unable to initialize tenant!' . '<div class="error_details">' . $e->getMessage() . '</div>');
             self::$accountName = NULL;
             return false;
         }
     }
     Kohana::log('debug', 'Done creating tenant.');
     self::$accountName = NULL;
     self::$created = array('userId' => $userId, 'locationId' => $locationId, 'accountId' => $accountId);
     // You can get everything you need from here
     return array('userId' => $userId, 'locationId' => $locationId, 'accountId' => $accountId);
 }
示例#4
0
 public function add($data)
 {
     $this->auto_render = FALSE;
     self::authorize();
     switch ($data) {
         case 'extension':
             if (!($user_id = arr::get($_REQUEST, 'user_id'))) {
                 $user_id = 1;
             }
             $number = self::requireRequest('number');
             $extcid = self::requireRequest('ext_cid');
             $username = self::requireRequest('username');
             $password = self::requireRequest('password');
             $context_id = self::requireRequest('context_id');
             $user_id = self::requireRequest('user_id');
             $options = array('callerid_internal_number' => $number, 'callerid_external_number' => $extcid, 'sip_username' => $username, 'sip_password' => $password);
             Doctrine_Manager::connection()->beginTransaction();
             $success = Bluebox_Tenant::createUserExtension($user_id, $number, $context_id, NULL, $options);
             if (!$success) {
                 Doctrine_Manager::connection()->rollback();
                 self::throwErrorAndDie('Could not add extension');
             } else {
                 Doctrine_Manager::connection()->commit();
             }
             self::returnSuccessAndDie("Added extension");
             break;
         case 'trunk':
             $name = self::requireRequest('name');
             $server = self::requireRequest('server');
             $username = self::requireRequest('username');
             $password = self::requireRequest('password');
             $interface_id = self::requireRequest('interface_id');
             $contexts = array_fill_keys(explode(',', self::requireRequest('contexts')), '1');
             $register = self::requireRequest('register');
             $cid_name = self::requireRequest('cid_name');
             $cid_number = self::requireRequest('cid_number');
             $pattern_ids = explode(',', self::requireRequest('pattern_ids'));
             $prepends = explode(',', self::requireRequest('prepends'));
             $account_id = self::requireRequest('account_id');
             foreach ($pattern_ids as $index => $pattern_id) {
                 $patterns[$pattern_id]['enabled'] = 1;
                 if (($prepend = arr::get($prepends, $index)) === FALSE) {
                     $prepend = "";
                 }
                 $patterns[$pattern_id]['prepend'] = $prepend;
             }
             Doctrine_Manager::connection()->beginTransaction();
             $trunk = new Trunk();
             $trunk->synchronizeWithArray(array('name' => $name, 'type' => 'sip', 'server' => $server, 'plugins' => array('sip' => array('username' => $username, 'password' => $password, 'register' => $register, 'cid_format' => '1', 'caller_id_field' => 'rpid', 'sip_invite_format' => '1'), 'sipinterface' => array('sipinterface_id' => $interface_id), 'simpleroute' => array('patterns' => $patterns, 'contexts' => $contexts, 'caller_id_name' => $cid_name, 'caller_id_number' => $cid_number, 'continue_on_fail' => '1'))));
             $trunk->account_id = $account_id;
             $trunk->refreshRelated();
             $success = $trunk->save();
             if (!$success) {
                 Doctrine_Manager::connection()->rollback();
                 self::throwErrorAndDie('Could not add trunk');
             } else {
                 Doctrine_Manager::connection()->commit();
             }
             self::returnSuccessAndDie('Added trunk');
             break;
         default:
             self::throwErrorAndDie('Command not recognized');
             break;
     }
 }
示例#5
0
文件: installer.php 项目: swk/bluebox
 /**
  * This step finalizes the installation (whatever that means)
  *
  * @return subview
  */
 private function finalize()
 {
     $subview = new View('installer/finalize');
     $this->template->title = __('Complete!');
     $this->template->allowPrev = FALSE;
     $this->template->allowNext = FALSE;
     // Force a login of the master/admin user for the remainder of the install
     Auth::instance()->force_login($this->session->get('installer.adminEmailAddress'));
     users::isUserAuthentic();
     users::getCurrentUser();
     $created = $this->session->get('Bluebox_installer.created');
     Bluebox_Tenant::createUserExtension($created['userId']);
     if (Session::instance()->get('installer.samples', FALSE)) {
         $sampleUsers = array(array('first' => 'Peter', 'last' => 'Gibbons', 'username' => '*****@*****.**', 'password' => inflector::generatePassword(), 'user_type' => User::TYPE_NORMAL_USER), array('first' => 'Michael', 'last' => 'Bolton', 'username' => '*****@*****.**', 'password' => inflector::generatePassword(), 'user_type' => User::TYPE_NORMAL_USER), array('first' => 'Samir', 'last' => 'Nagheenanajar', 'username' => '*****@*****.**', 'password' => inflector::generatePassword(), 'user_type' => User::TYPE_NORMAL_USER), array('first' => 'Bill', 'last' => 'Lumbergh', 'username' => '*****@*****.**', 'password' => inflector::generatePassword(), 'user_type' => User::TYPE_NORMAL_USER), array('first' => 'Milton', 'last' => 'Waddams', 'username' => '*****@*****.**', 'password' => inflector::generatePassword(), 'user_type' => User::TYPE_NORMAL_USER));
         foreach ($sampleUsers as $sampleUser) {
             $userId = Bluebox_Tenant::initializeUser($created['accountId'], $created['locationId'], $sampleUser);
             Bluebox_Tenant::createUserExtension($userId);
         }
     }
     if ($this->session->get('installer.tel_driver') == 'freeswitch') {
         Event::run('freeswitch.reload.xml');
         Event::run('freeswitch.reload.acl');
         Event::run('freeswitch.reload.sofia');
     }
     self::_resetWizard();
     $this->session->delete('Bluebox_message');
     // Disable the installer after a successful installtion
     self::updateConfig(array('installer_enabled' => 'FALSE'), 'config');
     Kohana::log('info', 'Installer wizard terminated');
     return $subview;
 }