/** * check if the application is opened. If not, it displays the yourapp/install/closed.html * file with a http error (or lib/jelix/installer/closed.html), and exit. * This function should be called in all entry point, before the creation of the coordinator. * @see jAppManager * @todo migrate the code to jAppManager or jApp */ function checkAppOpened() { if (!jApp::isInit()) { header("HTTP/1.1 500 Application not available"); header('Content-type: text/html'); echo "checkAppOpened: jApp is not initialized!"; exit(1); } if (file_exists(jApp::configPath('CLOSED'))) { $message = file_get_contents(jApp::configPath('CLOSED')); if (jServer::isCLI()) { echo "Application closed." . ($message ? "\n{$message}\n" : "\n"); exit(1); } if (file_exists(jApp::appPath('install/closed.html'))) { $file = jApp::appPath('install/closed.html'); } else { $file = JELIX_LIB_PATH . 'installer/closed.html'; } header("HTTP/1.1 500 Application not available"); header('Content-type: text/html'); echo str_replace('%message%', $message, file_get_contents($file)); exit(1); } }
function checkAppPaths() { $ok = true; if (!defined('JELIX_LIB_PATH') || !jApp::isInit()) { throw new Exception($this->messages->get('path.core')); } if (!file_exists(jApp::tempBasePath()) || !is_writable(jApp::tempBasePath())) { $this->error('path.temp'); $ok = false; } if (!file_exists(jApp::logPath()) || !is_writable(jApp::logPath())) { $this->error('path.log'); $ok = false; } if (!file_exists(jApp::varPath())) { $this->error('path.var'); $ok = false; } if (!file_exists(jApp::configPath())) { $this->error('path.config'); $ok = false; } elseif ($this->checkForInstallation) { if (!is_writable(jApp::configPath())) { $this->error('path.config.writable'); $ok = false; } if (file_exists(jApp::configPath('profiles.ini.php')) && !is_writable(jApp::configPath('profiles.ini.php'))) { $this->error('path.profiles.writable'); $ok = false; } if (file_exists(jApp::mainConfigFile()) && !is_writable(jApp::mainConfigFile())) { $this->error('path.mainconfig.writable'); $ok = false; } elseif (file_exists(jApp::configPath('defaultconfig.ini.php')) && !is_writable(jApp::configPath('defaultconfig.ini.php'))) { $this->error('path.mainconfig.writable'); $ok = false; } if (file_exists(jApp::configPath('installer.ini.php')) && !is_writable(jApp::configPath('installer.ini.php'))) { $this->error('path.installer.writable'); $ok = false; } } if (!file_exists(jApp::wwwPath())) { $this->error('path.www'); $ok = false; } foreach ($this->otherPaths as $path) { $realPath = jFile::parseJelixPath($path); if (!file_exists($realPath)) { $this->error('path.custom.not.exists', array($path)); $ok = false; } else { if (!is_writable($realPath)) { $this->error('path.custom.writable', array($path)); $ok = false; } else { $this->ok('path.custom.ok', array($path)); } } } if ($ok) { $this->ok('paths.ok'); } else { throw new Exception($this->messages->get('too.critical.error')); } /*if(!isset($GLOBALS['config_file']) || empty($GLOBALS['config_file']) || !file_exists(jApp::configPath($GLOBALS['config_file']))){ throw new Exception($this->messages->get('config.file')); }*/ return $ok; }
*/ // caller script should setup : // $commandName error_reporting(E_ALL); define('JELIX_SCRIPTS_PATH', dirname(__FILE__) . '/../'); if (PHP_SAPI != 'cli') { echo "You must use the CLI version of PHP, not the " . PHP_SAPI . " version\n"; exit(1); } // ------------- retrieve the name of the jelix command $argv = $_SERVER['argv']; $scriptName = array_shift($argv); // shift the script name // ------------ load the config and retrieve the command object require JELIX_SCRIPTS_PATH . '../jelix/init.php'; require JELIX_SCRIPTS_PATH . 'includes/JelixScript.class.php'; set_error_handler('JelixScriptsErrorHandler'); set_exception_handler('JelixScriptsExceptionHandler'); $command = JelixScript::getCommand($commandName, null, true); if (jApp::isInit()) { echo "Error: shouldn't run within an application\n"; exit(1); } if ($command->applicationRequirement == JelixScriptCommand::APP_MUST_EXIST) { echo "Error: This command needs an existing application\n"; exit(1); } // --------- launch the command now $command->init($argv); $command->run(); exit(0);
} // ------------- retrieve the name of the jelix command if ($_SERVER['argc'] < 2) { echo "Error: command is missing. See '" . $_SERVER['argv'][0] . " help'.\n"; exit(1); } $argv = $_SERVER['argv']; $scriptName = array_shift($argv); // shift the script name $commandName = array_shift($argv); // get the command name // ------------ load the config and retrieve the command object require JELIX_SCRIPTS_PATH . 'includes/JelixScript.class.php'; set_error_handler('JelixScriptsErrorHandler'); set_exception_handler('JelixScriptsExceptionHandler'); $config = JelixScript::loadConfig(); $command = JelixScript::getCommand($commandName, $config); if (!jApp::isInit()) { echo "Error: should run within an application\n"; exit(1); } if ($command->applicationRequirement == JelixScriptCommand::APP_MUST_NOT_EXIST) { echo "Error: This command doesn't apply on an existing application\n"; exit(1); } jApp::setEnv('jelix-scripts'); JelixScript::checkTempPath(); // --------- launch the command now $command->init($argv); $command->run(); exit(0);
function checkAppPaths() { $ok = true; if (!defined('JELIX_LIB_PATH') || !jApp::isInit()) { throw new Exception($this->messages->get('path.core')); } if (!file_exists(jApp::tempBasePath()) || !is_writable(jApp::tempBasePath())) { $this->error('path.temp'); $ok = false; } if (!file_exists(jApp::logPath()) || !is_writable(jApp::logPath())) { $this->error('path.log'); $ok = false; } if (!file_exists(jApp::varPath())) { $this->error('path.var'); $ok = false; } if (!file_exists(jApp::configPath())) { $this->error('path.config'); $ok = false; } elseif ($this->checkForInstallation) { if (!is_writable(jApp::configPath())) { $this->error('path.config.writable'); $ok = false; } if (file_exists(jApp::configPath('profiles.ini.php')) && !is_writable(jApp::configPath('profiles.ini.php'))) { $this->error('path.profiles.writable'); $ok = false; } if (file_exists(jApp::configPath('defaultconfig.ini.php')) && !is_writable(jApp::configPath('defaultconfig.ini.php'))) { $this->error('path.defaultconfig.writable'); $ok = false; } if (file_exists(jApp::configPath('installer.ini.php')) && !is_writable(jApp::configPath('installer.ini.php'))) { $this->error('path.installer.writable'); $ok = false; } } if (!file_exists(jApp::wwwPath())) { $this->error('path.www'); $ok = false; } foreach ($this->otherPaths as $path) { $realPath = str_replace(array('app:', 'lib:', 'var:', 'www:'), array(jApp::appPath(), LIB_PATH, jApp::varPath(), jApp::wwwPath()), $path); if (!file_exists($realPath)) { $this->error('path.custom.not.exists', array($path)); $ok = false; } else { if (!is_writable($realPath)) { $this->error('path.custom.writable', array($path)); $ok = false; } else { $this->ok('path.custom.ok', array($path)); } } } if ($ok) { $this->ok('paths.ok'); } else { throw new Exception($this->messages->get('too.critical.error')); } return $ok; }