/** * This function will determine there is a valid user on a page the requires * a user. If the user does not exist then it will redirect to the login * page. * * @return bool */ public static function redirectInvalidUser() { // If the system is installing then there is no login required if (Bluebox_Installer::is_installing()) { Kohana::config_set('core.require_login', FALSE); return TRUE; } $session = Session::instance(); // If there is no current user if (!self::isUserAuthentic()) { $controller = strtolower(Router::$controller); $method = strtolower(Router::$method); $noAuth = FALSE; $controllerBypass = Event::$data->getAuthBypass(); if (!empty($controllerBypass) and is_array($controllerBypass)) { self::$authBypass = arr::merge(self::$authBypass, array($controller => $controllerBypass)); } if (!empty(self::$authBypass[$controller])) { if (in_array($method, self::$authBypass[$controller])) { kohana::log('debug', 'The url `' . url::current() . '` is configured for auth bypass, allowing'); $noAuth = TRUE; } } if (!$noAuth) { // this will redirect from the login page back to this page kohana::log('debug', 'This user is not authorized for `' . url::current() . '`, presenting login form'); $session->set("requested_url", "/" . url::current()); if (request::is_ajax()) { header('HTTP/1.0 401 Forbidden'); flush(); die; } else { url::redirect('user/login'); } return FALSE; } } Event::run('bluebox.users.redirectInvalidUser'); $user_debug = self::getAttr('debug_level'); if ($user_debug > Kohana::config('core.log_threshold')) { self::changeDebugLevel($user_debug); } $log = sprintf('Effective user_id %s - account_id %s', self::getAttr('user_id'), self::getAttr('account_id')); kohana::log('debug', $log); $log = sprintf('Authentic user_id %s - account_id %s', self::getAuthenticAttr('user_id'), self::getAuthenticAttr('account_id')); kohana::log('debug', $log); return TRUE; }
public function checkDBConnectivity() { // Are heading somewhere other then the installer? If so, check that we're OK to proceed. if (!Bluebox_Installer::is_installing()) { // Check DB connectivity $manager = Doctrine_Manager::getInstance(); try { $manager->getCurrentConnection()->connect(); Doctrine::getTable('Package')->findAll(); } catch (Doctrine_Connection_Exception $e) { // We can't connect to the database - run the installer! // Get the guess the URL to work on Kohana::config_set('core.site_domain', Bluebox_Installer::guess_site_domain()); url::redirect('/installer'); } } }
public static function bootstrapPackages($ignoreInstaller = FALSE) { if (Bluebox_Installer::is_installing() and $ignoreInstaller !== TRUE) { return TRUE; } $installedPackages = Doctrine::getTable('Package')->findByStatus(Package_Manager::STATUS_INSTALLED); if (empty($installedPackages)) { return FALSE; } $loadList = $navigation = array(); foreach ($installedPackages as $package) { $packageDir = DOCROOT . $package['basedir']; $loadList[$package['name']] = $packageDir; if (is_dir($packageDir . '/models')) { // Note that with MODEL_LOADING_CONSERVATIVE set, the model isn't really loaded until first requested Doctrine::loadModels($packageDir . '/models', Doctrine::MODEL_LOADING_CONSERVATIVE); } if (empty($package['navigation'])) { continue; } $navigation[$package['name']] = $package['navigation']; } $loadedModules = Kohana::config('core.modules'); $systemModules = array_unique(array_merge($loadedModules, $loadList)); Kohana::config_set('core.modules', $systemModules); foreach ($loadList as $packageDir) { // Load hooks only for modules in the DB, if hooks are enabled if (Kohana::config('core.enable_hooks') === TRUE) { if (is_dir($packageDir . '/hooks')) { // Since we're running late, we need to go grab // the hook files again (sad but true) $hooks = Kohana::list_files('hooks', TRUE, $packageDir . '/hooks'); foreach ($hooks as $file) { // Load the hook include_once $file; } } } } navigation::bootstrap($navigation); }
/** * This function is responsible for ensuring the requirements in the configure require array * can be met * * @param array a complete listing of avaliable packages that can be used to met the requirements * @param string the name of the package whoes requirements we need to check * @return array if a package can be installed but needs to do so disabled, the packages array is updated */ private static function _fulfillRequired($packages, $name) { $runForActions = array('downgrade', 'install', 'upgrade', 'enable', 'repair', 'verify'); $package = $packages[$name]; $requirements = $package['required']; // If this action does not rely on requirements return if (!in_array($package['action'], $runForActions)) { return $packages; } // If there are no requirements return if (empty($requirements) || !is_array($requirements)) { return $packages; } $relationTree = self::relationTree($packages); foreach ($requirements as $required => $requiredVersion) { $requirement = strtolower($required); // check if the core mets requirements if ($requirement == 'core') { $coreVersion = Bluebox_Controller::$version; if (!self::_compareVersions($requiredVersion, $coreVersion)) { self::_setError('This module is incompatable with Bluebox version ' . $coreVersion, $name); } continue; } if (!empty($packages[$name]['incompatible'])) { unset($packages[$name]['incompatible']); continue; } // If this is a logic operation then handle it //$logicOperator = array('or', 'not', 'xor'); $logicOperator = array('not'); if (in_array($requirement, $logicOperator)) { if (!is_array($requiredVersion)) { continue; } // Push the array to the stack so we can hijack the errors array $errors = self::$errors; self::$errors = array(); $tmpPackages = $packages; // First make our package look like it only requires this sub-array $tmpPackages[$name]['required'] = $requiredVersion; self::_fulfillRequired($tmpPackages, $name); // Save the new errors and return pop the error stack $subErrors = self::$errors; self::$errors = $errors; // This is counter-intuative but if the package is avaliable there are no errors.... if ($requirement == 'not' && empty($subErrors)) { foreach (array_keys($requiredVersion) as $subName) { $incompatible = FALSE; if (self::packageAvailable($packages, $subName) == 2) { self::_setError('This module is incompatible with ' . $packages[$subName]['displayName'], $name); self::_setError('This module is incompatible with ' . $packages[$name]['displayName'], $subName); $packages[$subName]['incompatible'] = TRUE; $incompatible = TRUE; } if (!empty($incompatible)) { continue; } } } else { if ($requirement == 'or') { /** TODO: Do we even need this? It will have to be addressed in everything that uses requirements **/ } else { if ($requirement == 'xor') { /** TODO: Do we even need this? It will have to be addressed in everything that uses requirements **/ } } } unset($tmpPackages); continue; } // Required module can not be found if (empty($packages[$required])) { self::_setError('The required module ' . $required . ' could not be found', $name); continue; } $requirement = $packages[$required]; // Should the version be retrieved from configure.php depending on its action, errors, and current status $requirementVersion = 0; $useConfigVersion = array('downgrade', 'install', 'upgrade', 'uninstall'); $configVersionValid = in_array($requirement['action'], $useConfigVersion) && empty(self::$errors[$required]); // If the version should come from configure or isnt avaliable in the db get it! if ($configVersionValid || empty($requirement['installedAs']['module_version'])) { $requirementVersion = $requirement['version']; } else { $requirementVersion = $requirement['installedAs']['module_version']; } // Determine if the version is/could be satisfied $versionSatisfied = self::_compareVersions($requiredVersion, $requirementVersion); // The requirements status determines the behavoir switch (self::packageAvailable($packages, $required)) { // Case where a required module can not be found case -1: // This should have been caught above, but just incase.... self::_setError('The required module ' . $required . ' could not be found', $name); break; // Case where a module can be found but is, and wont be, installed // Case where a module can be found but is, and wont be, installed case 0: // If a required module is not installed but avaliable for installation then produce an error if ($versionSatisfied) { // The required module is not installed but if it where things would be fine if (empty(self::$errors[$packages[$required]['packageName']])) { self::_setError('The required module ' . $packages[$required]['displayName'] . ' exists but is not available', $name); } else { kohana::log('error', 'SUPPRESSING RELIANCE ON ' . $packages[$required]['displayName'] . ' but it has an error'); //self::_setError('This package relies on ' .$packages[$required]['displayName'] . ' but it has an error', $name); } } else { // There is an uninstalled module by that name but it is the wrong version self::_setError('The required version of ' . $required . ' could not be found', $name); } break; // Case where a module is, or will be, installed but disabled // Case where a module is, or will be, installed but disabled case 1: if (!$versionSatisfied) { // The installed version does not met the requirement version self::_setError('This module is incompatable with ' . $requirement['displayName'] . ' version ' . $requirementVersion, $name); } else { if ($package['action'] == 'enable') { // The requirement is disabled while this module tries to enable itself self::_setError('This module requires ' . $requirement['displayName'] . ' to also be enabled', $name); } else { if ($package['default']) { // We cant enable this package because one if its dependencies is disabled so we will continue disabled as well $packages[$name]['default'] = false; self::_setWarning('The required module ' . $requirement['displayName'] . ' is disabled so this will default to disabled as well', $name); } } } break; // Case where a module is, or will be, installed // Case where a module is, or will be, installed case 2: if (!$versionSatisfied) { // The installed version does not met the requirement version self::_setError('This module is incompatable with ' . $requirement['displayName'] . ' version ' . $requirementVersion, $name); } break; } } return $packages; }
public function commit() { // Activate any changed settings on the switch, live if (!Bluebox_Installer::is_installing()) { if (self::$dirty) { Event::run('freeswitch.reload.xml'); } if (self::$aclDirty) { Event::run('freeswitch.reload.acl'); } if (self::$xmlcdrDirty) { Event::run('freeswitch.reload.xmlcdr'); } if (self::$sofiaDirty) { Event::run('freeswitch.reload.sofia'); } } self::$dirty = FALSE; self::$aclDirty = FALSE; self::$sofiaDirty = FALSE; self::$xmlcdrDirty = FALSE; self::$trunksDirty = FALSE; }
<?php defined('SYSPATH') or die('No direct access allowed.'); if (!Bluebox_Installer::is_installing()) { Event::add('bluebox.message_html', array('ErrorReporter', 'provideHelpLink')); }
/** * This attempts to uncomment the index_page in config.php if mod_rewrite is not * on or not allowed. * * @return void */ public function fixModRewrite() { Kohana::config_set('core.site_domain', Bluebox_Installer::guess_site_domain()); $indexPage = Kohana::config('core.index_page'); if (!empty($indexPage)) { url::redirect('/installer'); } Kohana::config_set('core.index_page', 'index.php'); // Get the current config.php file if ($files = Kohana::find_file('config', 'config')) { $file = @file(end($files)); } // Make sure we were sucessfull if (empty($file)) { // Use the preLog because we dont know if we have write permissions on logs/ yet! $preLog = $this->session->get('installer.pre_log'); $preLog['error'][] = 'Could not locate or read config.php during mod_rewrite fix!'; $this->session->set('installer.pre_log', $preLog); url::redirect('/index.php/installer?config_file=config'); } foreach ($file as $num => $line) { preg_match('/.*[\'"`]([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)[\'"`].*$/imx', $line, $result); if (!empty($result[1]) && strstr($result[1], 'index_page')) { $file[$num] = ltrim($line, '/#;'); } } $file = implode('', $file); // If we got the file then we must have made changes, attempt to save it back // but if there is an error doing so have the user do it if (@file_put_contents(end($files), $file) === FALSE) { // Use the preLog because we dont know if we have write permissions on logs/ yet! $_GET['config_file'] = 'config'; $this->viewCache($file); $this->template->allowNext = TRUE; return FALSE; } url::redirect('/installer'); }
/** * Tests the Bluebox_Installer::dependencySort() function * @group core.libraries.installer.dependencySort * @test */ public function testDependencySort() { // Get fresh data to work with $package1 = $this->numberedPackage(1); $package2 = $this->numberedPackage(2); $package3 = $this->numberedPackage(3); // If they have no action then they are avaliable at any time (or checkDependencies would have failed) // and the sorter will ignore them... $package1['sample1']['action'] = 'install'; $package2['sample2']['action'] = 'install'; $package3['sample3']['action'] = 'install'; // Set up known relationships $package1['sample1']['required'] = array('core' => Bluebox_Controller::$version, 'sample2' => 0.1); $package2['sample2']['required'] = array('core' => Bluebox_Controller::$version); $package3['sample3']['required'] = array('core' => Bluebox_Controller::$version, 'sample1' => 0.1, 'sample2' => 0.1); // The expected order $expected = array('sample2', 'sample1', 'sample3'); $packages = array_merge($package1, $package2, $package3); Bluebox_Installer::_dependencySort($packages); $this->assertEquals($expected, array_keys($packages)); $packages = array_merge($package3, $package2, $package1); Bluebox_Installer::_dependencySort($packages); $this->assertEquals($expected, array_keys($packages)); $packages = array_merge($package3, $package1, $package2); Bluebox_Installer::_dependencySort($packages); $this->assertEquals($expected, array_keys($packages)); $packages = array_merge($package2, $package1, $package3); Bluebox_Installer::_dependencySort($packages); $this->assertEquals($expected, array_keys($packages)); }
public function customize() { // get the module that these customize options apply to $module = $this->input->post('module', ''); $module = str_replace('_module_permissions_custom', '', $module); // get the package definition for this module $packages = Bluebox_Installer::listPackages(); $package = $packages[$module]; // no package, no love if (empty($package)) { die; } $this->view->module = $module; $this->view->customizable = self::getCustomizable($package); }