Esempio n. 1
0
 public static function package($path)
 {
     Package_Message::log('debug', 'Attempting to import package ' . $path);
     $filename = basename($path);
     if (self::is_url($path)) {
         $path = Package_Import_Remote::fetch($path);
     }
     $importPath = MODPATH . pathinfo($path, PATHINFO_FILENAME);
     if (!class_exists('ZipArchive')) {
         $return = FALSE;
         Package_Message::log('debug', 'Attempting to unzip with: /usr/bin/unzip ' . $path . ' -d ' . MODPATH);
         @system('/usr/bin/unzip ' . $path . ' -d ' . $importPath, $return);
         if ($return !== 0) {
             throw new Package_Import_Exception('System does not have zip archive support or could not extract ' . $path);
         }
     } else {
         Package_Message::log('debug', 'Attempting to unzip with: ZipArchive->open(' . $path . ', ZIPARCHIVE::CHECKCONS)');
         $zip = new ZipArchive();
         if (!($error = $zip->open($path, ZIPARCHIVE::CHECKCONS))) {
             switch ($error) {
                 case ZIPARCHIVE::ER_EXISTS:
                     throw new Package_Import_Exception('Package archive already exists: ' . $error);
                 case ZIPARCHIVE::ER_INCONS:
                     throw new Package_Import_Exception('Consistency check on the package archive failed: ' . $error);
                 case ZIPARCHIVE::ER_INVAL:
                     throw new Package_Import_Exception('Invalid argument while opening package archive: ' . $error);
                 case ZIPARCHIVE::ER_MEMORY:
                     throw new Package_Import_Exception('Memory allocation failure while opening package archive: ' . $error);
                 case ZIPARCHIVE::ER_NOENT:
                     throw new Package_Import_Exception('Could not locate package archive: ' . $error);
                 case ZIPARCHIVE::ER_NOZIP:
                     throw new Package_Import_Exception('Package archive is not a zip: ' . $error);
                 case ZIPARCHIVE::ER_OPEN:
                     throw new Package_Import_Exception('Cant open package archive: ' . $error);
                 case ZIPARCHIVE::ER_READ:
                     throw new Package_Import_Exception('Package archive read error: ' . $error);
                 case ZIPARCHIVE::ER_SEEK:
                     throw new Package_Import_Exception('Package archive seek error: ' . $error);
                 default:
                     throw new Package_Import_Exception('Unknown error while opening package archive: ' . $error);
             }
         }
         if (is_dir($importPath)) {
             throw new Package_Import_Exception('Import path `' . $importPath . '` already exists');
         }
         if (!@$zip->extractTo($importPath)) {
             throw new Package_Import_Exception('Failed to extract package archive ' . $filename . ' or no permissions to unzip to ' . MODPATH);
         }
         $zip->close();
     }
     kohana::log('debug', 'Dynamically adding `' . $importPath . '` to kohana');
     $loadedModules = Kohana::config('core.modules');
     $modules = array_unique(array_merge($loadedModules, array($importPath)));
     Kohana::config_set('core.modules', $modules);
     Package_Catalog::disableRemote();
     Package_Catalog::buildCatalog();
     Package_Catalog::enableRemote();
     return $importPath;
 }
Esempio n. 2
0
 public function finalize($identifier)
 {
     $package =& Package_Catalog::getPackageByIdentifier($identifier);
     $package['status'] = Package_Manager::STATUS_INSTALLED;
     Package_Catalog_Datastore::export($package);
     Package_Catalog::buildCatalog();
     $configureInstance = Package_Catalog::getPackageConfigureInstance($identifier);
     $configureInstance->finalizeInstall($identifier);
 }
Esempio n. 3
0
 protected function submitReport($report)
 {
     $valid = TRUE;
     $validation = Bluebox_Controller::$validation;
     if (empty($report['issue'])) {
         $validation->add_error('report[issue]', 'Please describe the issue');
         $valid = FALSE;
     }
     if (empty($report['while'])) {
         $validation->add_error('report[while]', 'Please describe the cause');
         $valid = FALSE;
     }
     if (empty($report['contact'])) {
         $validation->add_error('report[contact]', 'Please provide a method to contact you');
         $valid = FALSE;
     }
     if (empty($report['error'])) {
         $validation->add_error('report[error]', 'Please provide the error message');
         $valid = FALSE;
     }
     if (!$valid) {
         return FALSE;
     }
     if (!empty($report['log'])) {
         $filename = Kohana::log_directory() . date('Y-m-d') . '.log' . EXT;
         $offset = -150 * 120;
         $rs = @fopen($filename, 'r');
         $report['log'] = '';
         if ($rs !== FALSE) {
             fseek($rs, $offset, SEEK_END);
             fgets($rs);
             while (!feof($rs)) {
                 $buffer = fgets($rs);
                 $report['log'] .= htmlspecialchars($buffer . "\n");
             }
             fclose($rs);
         }
     }
     $allowStats = Kohana::config('core.anonymous_statistics');
     if (!empty($allowStats)) {
         $report['anonymous_id'] = Kohana::config('core.anonymous_id');
         Package_Catalog::disableRemote();
         Package_Catalog::buildCatalog();
         $report['catalog'] = Package_Catalog::getPackageList();
     }
     try {
         $errorCollector = Kohana::config('errorreporter.collector');
         $this->do_post_request($errorCollector, $report);
     } catch (Exception $e) {
         message::set($e->getMessage());
         $this->returnQtipAjaxForm(NULL);
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 4
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);
 }