public function __construct() { $this->config = \Jelix\Core\App::config()->syslogLogger; $this->catSyslog = array('error' => LOG_ERR, 'warning' => LOG_WARNING, 'notice' => LOG_NOTICE, 'deprecated' => LOG_NOTICE, 'strict' => LOG_NOTICE, 'debug' => LOG_DEBUG); $ident = strtr($this->config['ident'], array('%sapi%' => php_sapi_name(), '%domain%' => \Jelix\Core\App::config()->domainName, '%pid%' => getmypid())); openlog($ident, LOG_ODELAY | LOG_PERROR, $this->config['facility']); }
protected function _execute(InputInterface $input, OutputInterface $output) { $config = App::config(); $model_lang = $input->getArgument('model_lang'); if (!$model_lang) { $model_lang = $config->locale; } $lang = $input->getArgument('lang'); foreach ($config->_modulesPathList as $module => $dir) { $source_dir = $dir . 'locales/' . $model_lang . '/'; if (!file_exists($source_dir)) { continue; } if ($input->getOption('to-overload')) { $target_dir = App::appPath('app/overloads/' . $module . '/locales/' . $lang . '/'); } else { $target_dir = App::appPath('app/locales/' . $lang . '/' . $module . '/locales/'); } \jFile::createDir($target_dir); if ($dir_r = opendir($source_dir)) { while (FALSE !== ($fich = readdir($dir_r))) { if ($fich != "." && $fich != ".." && is_file($source_dir . $fich) && strpos($fich, '.' . $config->charset . '.properties') && !file_exists($target_dir . $fich)) { copy($source_dir . $fich, $target_dir . $fich); if ($this->verbose()) { $output->writeln("Copy Locales file {$fich} from {$source_dir} to {$target_dir}."); } } } closedir($dir_r); } } }
/** * @param string $path path to the app directory. If not given * call \Jelix\Core\App to retrieve it. */ function __construct($path = '') { $config = \Jelix\Core\App::config(); if ($config) { $locale = $config->locale; } else { $locale = ''; } if (!$path) { $path = \Jelix\Core\App::appPath(); if (!$path) { throw new \Exception("Jelix Application is not initialized with Jelix\\Core\\App"); } } $this->path = rtrim($path, '/') . '/'; if (file_exists($this->path . 'jelix-app.json')) { $parser = new AppJsonParser($this->path . 'jelix-app.json', $locale); } else { if (file_exists($this->path . 'project.xml')) { $this->isXml = true; $parser = new ProjectXmlParser($this->path . 'project.xml', $locale); } else { return; } } $this->_exists = true; $parser->parse($this); }
/** * Loads the resources for a given locale/charset. * @param string $locale the locale * @param string $charset the charset */ protected function _loadLocales($locale, $charset) { $this->_loadedCharset[] = $charset; $source = $this->fic->getPath(); $cache = $this->fic->getCompiledFilePath(); // check if we have a compiled version of the ressources if (is_readable($cache)) { $okcompile = true; if (App::config()->compilation['force']) { $okcompile = false; } else { if (App::config()->compilation['checkCacheFiletime']) { if (is_readable($source) && filemtime($source) > filemtime($cache)) { $okcompile = false; } } } if ($okcompile) { include $cache; $this->_strings[$charset] = $_loaded; return; } } $reader = new \jPropertiesFileReader($source, $charset); $reader->parse(); $this->_strings[$charset] = $reader->getProperties(); $content = '<?php $_loaded= ' . var_export($this->_strings[$charset], true) . ' ?>'; \jFile::write($cache, $content); }
public function compileItem($sourceFile, $module) { if (is_readable($sourceFile)) { $xml = simplexml_load_file($sourceFile); $config = App::config()->disabledListeners; if (isset($xml->listener)) { foreach ($xml->listener as $listener) { $listenerName = (string) $listener['name']; $selector = $module . '~' . $listenerName; foreach ($listener->event as $eventListened) { $name = (string) $eventListened['name']; if (isset($config[$name])) { if (is_array($config[$name])) { if (in_array($selector, $config[$name])) { continue; } } else { if ($config[$name] == $selector) { continue; } } } // key = event name , value = list of file listener $this->eventList[$name][] = array($module, $listenerName); } } } } return true; }
public function run() { $this->loadAppConfig(); $config = \Jelix\Core\App::config(); $model_lang = $this->getParam('model_lang', $config->locale); $lang = $this->getParam('lang'); foreach ($config->_modulesPathList as $module => $dir) { $source_dir = $dir . 'locales/' . $model_lang . '/'; if (!file_exists($source_dir)) { continue; } if ($this->getOption('-to-overload')) { $target_dir = \Jelix\Core\App::varPath('overloads/' . $module . '/locales/' . $lang . '/'); } else { $target_dir = \Jelix\Core\App::varPath('locales/' . $lang . '/' . $module . '/locales/'); } jFile::createDir($target_dir); if ($dir_r = opendir($source_dir)) { while (FALSE !== ($fich = readdir($dir_r))) { if ($fich != "." && $fich != ".." && is_file($source_dir . $fich) && strpos($fich, '.' . $config->charset . '.properties') && !file_exists($target_dir . $fich)) { copy($source_dir . $fich, $target_dir . $fich); if ($this->verbose()) { echo "Copy Locales file {$fich} from {$source_dir} to {$target_dir}.\n"; } } } closedir($dir_r); } } }
/** * @param string $path path to the module directory */ function __construct($path) { $p = rtrim($path, '/'); $this->path = $p . '/'; // by default, the module name is the directory name of the module $this->name = basename($p); $config = \Jelix\Core\App::config(); if ($config) { $locale = $config->locale; } else { $locale = ''; } if (file_exists($this->path . 'jelix-module.json')) { $parser = new ModuleJsonParser($this->path . 'jelix-module.json', $locale); } else { if (file_exists($this->path . 'module.xml')) { $this->isXml = true; $parser = new ModuleXmlParser($this->path . 'module.xml', $locale); } else { return; } } $this->_exists = true; $parser->parse($this); }
public function run() { try { $tempPath = \Jelix\Core\App::tempBasePath(); if ($tempPath == DIRECTORY_SEPARATOR || $tempPath == '' || $tempPath == '/') { echo "Error: bad path in \\Jelix\\Core\\App::tempBasePath(), it is equals to '" . $tempPath . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " Correct the path in your application.init.php or create the corresponding directory\n"; exit(1); } if (!jFile::removeDir($tempPath, false, array('.svn', '.dummy'))) { echo "Some temp files were not removed\n"; } else { if ($this->verbose()) { echo "All temp files have been removed\n"; } } } catch (Exception $e) { if ($this->config->helpLang == 'fr') { echo "Un ou plusieurs répertoires n'ont pas pu être supprimés.\n" . "Message d'erreur : " . $e->getMessage() . "\n"; } else { echo "One or more directories couldn't be deleted.\n" . "Error: " . $e->getMessage() . "\n"; } } }
/** * @param \Jelix\Logger\MessageInterface $message the message to log */ function logMessage($message) { $type = $message->getCategory(); if (\Jelix\Core\App::router()->request) { $ip = \Jelix\Core\App::router()->request->getIP(); } else { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; } error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\t{$type}\t" . $message->getFormatedMessage(), 0); }
protected function execute(InputInterface $input, OutputInterface $output) { $paths = array(); $paths[] = \Jelix\Core\App::tempBasePath(); $paths[] = \Jelix\Core\App::logPath(); $paths[] = \Jelix\Core\App::varPath('mails'); $paths[] = \Jelix\Core\App::varPath('db'); foreach ($paths as $path) { $this->setRights($path); } }
public function run() { $paths = array(); $paths[] = \Jelix\Core\App::tempBasePath(); $paths[] = \Jelix\Core\App::logPath(); $paths[] = \Jelix\Core\App::varPath('mails'); $paths[] = \Jelix\Core\App::varPath('db'); foreach ($paths as $path) { $this->setRights($path); } }
protected function _createPath() { if (!isset(App::config()->_modulesPathList[$this->module])) { throw new Exception('jelix~errors.selector.module.unknown', $this->toString()); } $this->_path = App::config()->_modulesPathList[$this->module] . $this->_dirname . $this->subpath . $this->className . $this->_suffix; if (!file_exists($this->_path) || strpos($this->subpath, '..') !== false) { // second test for security issues throw new Exception('jelix~errors.selector.invalid.target', array($this->toString(), $this->type)); } }
/** * @param \Jelix\IniFile\IniModifier $mainConfig the mainconfig.ini.php file * @param string $configFile the path of the configuration file, relative * to the var/config directory * @param string $file the filename of the entry point * @param string $type type of the entry point ('classic', 'cli', 'xmlrpc'....) */ function __construct(\Jelix\IniFile\IniModifier $mainConfig, $configFile, $file, $type) { $this->type = $type; $this->isCliScript = $type == 'cmdline'; $this->configFile = $configFile; $this->scriptName = $this->isCliScript ? $file : '/' . $file; $this->file = $file; $this->configIni = new \Jelix\IniFile\MultiIniModifier($mainConfig, \Jelix\Core\App::configPath($configFile)); $compiler = new \Jelix\Core\Config\Compiler($configFile, $this->scriptName, $this->isCliScript); $this->config = $compiler->read(true); $this->modulesInfos = $compiler->getModulesInfos(); }
public function run() { \Jelix\Core\AppManager::close(); $module = $this->getParam('module'); $modulesList = $this->getParam('...', array()); array_unshift($modulesList, $module); $parameters = $this->getOption('-p'); if ($parameters && count($modulesList) > 1) { throw new Exception('Parameters are for only one module'); } if ($parameters) { $params = explode(';', $parameters); $parameters = array(); foreach ($params as $param) { $kp = explode("=", $param); if (count($kp) > 1) { $parameters[$kp[0]] = $kp[1]; } else { $parameters[$kp[0]] = true; } } } if ($this->verbose()) { $reporter = new \Jelix\Installer\Reporter\Console(); } else { $reporter = new \Jelix\Installer\Reporter\Console('error'); } $installer = new \Jelix\Installer\Installer($reporter); if ($this->allEntryPoint) { if ($parameters) { $installer->setModuleParameters($modulesList[0], $parameters); } $installer->installModules($modulesList); } else { if ($parameters) { $installer->setModuleParameters($modulesList[0], $parameters, $this->entryPointName); } $installer->installModules($modulesList, $this->entryPointName); } try { \Jelix\Core\AppManager::clearTemp(\Jelix\Core\App::tempBasePath()); } catch (Exception $e) { if ($e->getCode() == 2) { echo "Error: bad path in \\Jelix\\Core\\App::tempBasePath(), it is equals to '" . \Jelix\Core\App::tempBasePath() . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " you must clear it your self.\n"; echo " Correct the path in application.init.php or create the directory\n"; } else { echo "Error: " . $e->getMessage(); } } \Jelix\Core\AppManager::open(); }
/** * @param \Jelix\Routing\ServerResponse $response */ function output($response) { if (!\Jelix\Core\App::router()->request) { return; } $email = \Jelix\Core\App::config()->mailLogger['email']; $headers = str_replace(array('\\r', '\\n'), array("\r", "\n"), \Jelix\Core\App::config()->mailLogger['emailHeaders']); $message = ''; foreach ($this->messages as $msg) { $message .= "\n\n" . $msg->getFormatedMessage(); } error_log(wordwrap($message, 70), 1, $email, $headers); }
protected function _execute(InputInterface $input, OutputInterface $output) { require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php'; \Jelix\Core\AppManager::close(); $module = $input->getArgument('module'); $parameters = $input->getOption('parameters'); if ($parameters) { $params = explode(';', $parameters); $parameters = array(); foreach ($params as $param) { $kp = explode("=", $param); if (count($kp) > 1) { $parameters[$kp[0]] = $kp[1]; } else { $parameters[$kp[0]] = true; } } } if ($this->verbose()) { $reporter = new \Jelix\Installer\Reporter\Console(); } else { $reporter = new \Jelix\Installer\Reporter\Console('error'); } $installer = new \Jelix\Installer\Installer($reporter); if ($this->allEntryPoint) { if ($parameters) { $installer->setModuleParameters($module, $parameters); } $installer->installModules(array($module)); } else { if ($parameters) { $installer->setModuleParameters($module, $parameters, $this->entryPointName); } $installer->installModules(array($module), $this->entryPointName); } try { \Jelix\Core\AppManager::clearTemp(\jApp::tempBasePath()); } catch (\Exception $e) { if ($e->getCode() == 2) { $output->writeln("Error: bad path in \\Jelix\\Core\\App::tempBasePath(), it is equals to '" . App::tempBasePath() . "' !!"); $output->writeln(" Jelix cannot clear the content of the temp directory."); $output->writeln(" you must clear it your self."); $output->writeln(" Correct the path in application.init.php or create the directory"); } else { $output->writeln("<error>Error: " . $e->getMessage() . "</error>"); } } \Jelix\Core\AppManager::open(); }
static function getInstalledPackages() { if (self::$packages === null) { self::$packages = array(); $path = App::appPath('composer.lock'); if (file_exists($path)) { $lock = json_decode(file_get_contents($path)); if ($lock) { foreach ($lock->packages as $package) { self::$packages[$package->name] = $package; } } } } return self::$packages; }
/** * @param \Jelix\Logger\MessageInterface $message the message to log */ function logMessage($message) { if (!is_writable(\Jelix\Core\App::logPath())) { return; } $type = $message->getCategory(); $appConf = \Jelix\Core\App::config(); if ($appConf) { $conf =& \Jelix\Core\App::config()->fileLogger; if (!isset($conf[$type])) { return; } $f = $conf[$type]; $f = str_replace('%m%', date("m"), $f); $f = str_replace('%Y%', date("Y"), $f); $f = str_replace('%d%', date("d"), $f); $f = str_replace('%H%', date("H"), $f); } else { $f = 'errors.log'; } $coord = \Jelix\Core\App::router(); if ($coord && $coord->request) { $ip = $coord->request->getIP(); } else { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; } $f = str_replace('%ip%', $ip, $f); try { if (!preg_match("/^([\\w\\.\\/]+)\$/", $f, $m)) { throw new Exception("Invalid file name for file logger name {$f}"); } $file = \Jelix\Core\App::logPath($f); @error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\t{$type}\t" . $message->getFormatedMessage() . "\n", 3, $file); @chmod($file, \Jelix\Core\App::config()->chmodFile); } catch (\Exception $e) { $file = \Jelix\Core\App::logPath('errors.log'); @error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\terror\t" . $e->getMessage() . "\n", 3, $file); @chmod($file, \Jelix\Core\App::config()->chmodFile); } }
protected function execute(InputInterface $input, OutputInterface $output) { try { $tempPath = \Jelix\Core\App::tempBasePath(); if ($tempPath == DIRECTORY_SEPARATOR || $tempPath == '' || $tempPath == '/') { $output->writeln("<error>Error: bad path in jApp::tempBasePath(), it is equals to '" . $tempPath . "' !!</error>"); $output->writeln(" Jelix cannot clear the content of the temp directory."); $output->writeln(" Correct the path in your application.init.php or create the corresponding directory"); return 1; } if (!\jFile::removeDir($tempPath, false, array('.svn', '.git', '.dummy'))) { $output->writeln("Some temp files were not removed"); } else { if ($output->isVerbose()) { $output->writeln("All temp files have been removed"); } } } catch (\Exception $e) { $output->writeln("One or more directories couldn't be deleted."); $output->writeln("<error>Error: " . $e->getMessage() . "</error>"); return 2; } }
protected function _execute(InputInterface $input, OutputInterface $output) { \Jelix\Core\AppManager::close(); if ($this->verbose()) { $reporter = new \Jelix\Installer\Reporter\Console('notice', 'Low-level migration'); } else { $reporter = new \Jelix\Installer\Reporter\Console('error', 'Low-level migration'); } // launch the low-level migration $migrator = new \Jelix\Installer\Migration($reporter); $migrator->migrate(); // we can now launch the installer/updater if ($this->verbose()) { $reporter = new \Jelix\Installer\Reporter\Console(); } else { $reporter = new \Jelix\Installer\Reporter\Console('error'); } $installer = new \Jelix\Installer\Installer($reporter); if ($input->getOption('entry-point')) { $installer->installEntryPoint($this->entryPointId); } else { $installer->installApplication(); } try { \Jelix\Core\AppManager::clearTemp(\Jelix\Core\App::tempBasePath()); } catch (\Exception $e) { if ($e->getCode() == 2) { $output->writeln("<error>Error: bad path in jApp::tempBasePath(), it is equals to '" . jApp::tempBasePath() . "' !!</error>"); $output->writeln(" Jelix cannot clear the content of the temp directory."); $output->writeln(" you must clear it your self."); $output->writeln(" Correct the path in the application.init.php or create the directory"); } else { $output->writeln("<error>Error: " . $e->getMessage() . "</error>"); } } \Jelix\Core\AppManager::open(); }
public function run() { \Jelix\Core\AppManager::close(); if ($this->verbose()) { $reporter = new \Jelix\Installer\Reporter\Console(); } else { $reporter = new \Jelix\Installer\Reporter\Console('error'); } $installer = new \Jelix\Installer\Installer($reporter); $installer->installApplication(); try { \Jelix\Core\AppManager::clearTemp(\Jelix\Core\App::tempBasePath()); } catch (Exception $e) { if ($e->getCode() == 2) { echo "Error: bad path in use \\Jelix\\Core\\App::tempBasePath(), it is equals to '" . \Jelix\Core\App::tempBasePath() . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " you must clear it your self.\n"; echo " Correct the path in the application.init.php or create the directory\n"; } else { echo "Error: " . $e->getMessage(); } } \Jelix\Core\AppManager::open(); }
/** * @param \Jelix\IniFile\MultiIniModifier $mainConfig the mainconfig.ini.php file combined with defaultconfig.ini.php * @param \Jelix\IniFile\MultiIniModifier $localConfig the localconfig.ini.php file combined with $mainConfig * @param string $configFile the path of the configuration file, relative * to the app/config directory * @param string $file the filename of the entry point * @param string $type type of the entry point ('classic', 'cli', 'xmlrpc'....) */ function __construct(\Jelix\IniFile\MultiIniModifier $mainConfig, \Jelix\IniFile\MultiIniModifier $localConfig, $configFile, $file, $type) { $this->type = $type; $this->isCliScript = $type == 'cmdline'; $this->configFile = $configFile; $this->scriptName = $this->isCliScript ? $file : '/' . $file; $this->file = $file; $this->mainConfigIni = $mainConfig; $this->localConfigIni = $localConfig; $appConfigPath = \Jelix\Core\App::appConfigPath($configFile); if (!file_exists($appConfigPath)) { \jFile::createDir(dirname($appConfigPath)); file_put_contents($appConfigPath, ';<' . '?php die(\'\');?' . '>'); } $this->epConfigIni = new \Jelix\IniFile\IniModifier($appConfigPath); $varConfigPath = \Jelix\Core\App::configPath($configFile); if (!file_exists($varConfigPath)) { \jFile::createDir(dirname($varConfigPath)); file_put_contents($varConfigPath, ';<' . '?php die(\'\');?' . '>'); } $this->localEpConfigIni = new \Jelix\IniFile\IniModifier($varConfigPath); $this->fullConfigIni = new \Jelix\IniFile\MultiIniModifier($localConfig, $this->epConfigIni); $this->fullConfigIni = new \Jelix\IniFile\MultiIniModifier($this->fullConfigIni, $this->localEpConfigIni); $compiler = new \Jelix\Core\Config\Compiler($configFile, $this->scriptName, $this->isCliScript); $this->config = $compiler->read(true); $this->modulesInfos = $compiler->getModulesInfos(); }
} // ------------- 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('JelixScript::errorHandler'); set_exception_handler('JelixScript::exceptionHandler'); $config = JelixScript::loadConfig(); $command = JelixScript::getCommand($commandName, $config); if (!\Jelix\Core\App::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); } \Jelix\Core\App::setEnv('jelix-scripts'); JelixScript::checkTempPath(); // --------- launch the command now $command->init($argv); $command->run(); exit(0);
static function checkTempPath() { $tempBasePath = \Jelix\Core\App::tempBasePath(); // we always clean the temp directory. But first, let's check the temp path (see ticket #840)... if ($tempBasePath == DIRECTORY_SEPARATOR || $tempBasePath == '' || $tempBasePath == '/') { throw new Exception("Error: bad path in \\Jelix\\Core\\App::tempBasePath(), it is equals to '" . $tempBasePath . "' !!\n" . " Jelix cannot clear the content of the temp directory.\n" . " Correct the path for the temp directory or create the directory you\n" . " indicated with \\Jelix\\Core\\App in your application.init.php.\n"); } jFile::removeDir(\Jelix\Core\App::tempPath(), false, array('.svn', '.dummy')); }
/** * declare a new db profile. if the content of the section is not given, * it will declare an alias to the default profile * @param string $name the name of the new section/alias * @param null|string|array $sectionContent the content of the new section, or null * to create an alias. * @param boolean $force true:erase the existing profile * @return boolean true if the ini file has been changed */ protected function declareDbProfile($name, $sectionContent = null, $force = true) { $profiles = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php')); if ($sectionContent == null) { if (!$profiles->isSection('jdb:' . $name)) { // no section if ($profiles->getValue($name, 'jdb') && !$force) { // already a name return false; } } else { if ($force) { // existing section, and no content provided : we erase the section // and add an alias $profiles->removeValue('', 'jdb:' . $name); } else { return false; } } $default = $profiles->getValue('default', 'jdb'); if ($default) { $profiles->setValue($name, $default, 'jdb'); } else { // default is a section $profiles->setValue($name, 'default', 'jdb'); } } else { if ($profiles->getValue($name, 'jdb') !== null) { if (!$force) { return false; } $profiles->removeValue($name, 'jdb'); } if (is_array($sectionContent)) { foreach ($sectionContent as $k => $v) { $profiles->setValue($k, $v, 'jdb:' . $name); } } else { $profile = $profiles->getValue($sectionContent, 'jdb'); if ($profile !== null) { $profiles->setValue($name, $profile, 'jdb'); } else { $profiles->setValue($name, $sectionContent, 'jdb'); } } } $profiles->save(); \Jelix\Core\Profiles::clear(); return true; }
public function run() { $this->loadAppConfig(); $entrypoint = $this->getParam('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $cmd = JelixScript::getCommand('createentrypoint', $this->config); $cmd->initOptParam(array(), array('name' => $entrypoint)); $cmd->run(); $this->appInfos = null; $ep = $this->getEntryPointInfo($entrypoint); } catch (Exception $e) { throw new Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n"); } } $installConfig = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), App::configPath($ep['config'])); $params = array(); $this->createFile(App::appPath('responses/adminHtmlResponse.class.php'), 'responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(App::appPath('responses/adminLoginHtmlResponse.class.php'), 'responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $inifile->setValue('startModule', 'master_admin'); $inifile->setValue('startAction', 'default:index'); $repositoryPath = jFile::parseJelixPath('lib:jelix-admin-modules'); $this->registerModulesDir('lib:jelix-admin-modules', $repositoryPath); $installConfig->setValue('jacl.installed', '0', $entrypoint); $inifile->setValue('jacl.access', '0', 'modules'); $installConfig->setValue('jacldb.installed', '0', $entrypoint); $inifile->setValue('jacldb.access', '0', 'modules'); $urlconf = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints', null, true); if ($urlconf === null || $urlconf == '') { // in defaultconfig $inifile->setValue($entrypoint, 'jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints', null, true); // in the config of the entry point $inifile->setValue($entrypoint, 'jacl2db~*@classic, jauth~*@classic, jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints'); } else { $urlconf2 = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints'); if (strpos($urlconf, 'jacl2db_admin~*@classic') === false) { $urlconf .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf, 'jauthdb_admin~*@classic') === false) { $urlconf .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf, 'master_admin~*@classic') === false) { $urlconf .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db_admin~*@classic') === false) { $urlconf2 .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf2, 'jauthdb_admin~*@classic') === false) { $urlconf2 .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf2, 'master_admin~*@classic') === false) { $urlconf2 .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db~*@classic') === false) { $urlconf2 .= ',jacl2db~*@classic'; } if (strpos($urlconf2, 'jauth~*@classic') === false) { $urlconf2 .= ',jauth~*@classic'; } if (strpos($urlconf2, 'jpref_admin~*@classic') === false) { $urlconf2 .= ',jpref_admin~*@classic'; } $inifile->setValue($entrypoint, $urlconf, 'simple_urlengine_entrypoints', null, true); $inifile->setValue($entrypoint, $urlconf2, 'simple_urlengine_entrypoints'); } if (null == $inifile->getValue($entrypoint, 'basic_significant_urlengine_entrypoints', null, true)) { $inifile->setValue($entrypoint, '1', 'basic_significant_urlengine_entrypoints', null, true); } $inifile->save(); $verbose = $this->verbose(); $reporter = new \Jelix\Installer\Reporter\Console($verbose ? 'notice' : 'warning'); $installer = new \Jelix\Installer\Installer($reporter); $installer->installModules(array('master_admin'), $entrypoint . '.php'); $authini = new \Jelix\IniFile\IniModifier(App::configPath($entrypoint . '/auth.coord.ini.php')); $authini->setValue('after_login', 'master_admin~default:index'); $authini->setValue('timeout', '30'); $authini->save(); $profile = $this->getOption('-profile'); if (!$this->getOption('-noauthdb')) { if ($profile != '') { $authini->setValue('profile', $profile, 'Db'); } $authini->save(); $installer->setModuleParameters('jauthdb', array('defaultuser' => true)); $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jauthdb_admin.access', '0', 'modules'); $inifile->save(); } if (!$this->getOption('-noacl2db')) { if ($profile != '') { $dbini = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php')); $dbini->setValue('jacl2_profile', $profile, 'jdb'); $dbini->save(); } $installer = new \Jelix\Installer\Installer($reporter); $installer->setModuleParameters('jacl2db', array('defaultuser' => true)); $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jacl2db_admin.access', '0', 'modules'); $inifile->save(); } $installer->installModules(array('jpref_admin'), $entrypoint . '.php'); }
/** * return the server port of the application * @return string the ":port" or empty string * @since 1.2.4 */ function getPort($forceHttps = null) { $isHttps = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off'; if ($forceHttps === null) { $https = $isHttps; } else { $https = $forceHttps; } $forcePort = $https ? App::config()->forceHTTPSPort : App::config()->forceHTTPPort; if ($forcePort === true) { return ''; } else { if ($forcePort) { // a number $port = $forcePort; } else { if ($isHttps != $https || !isset($_SERVER['SERVER_PORT'])) { // the asked protocol is different from the current protocol // we use the standard port for the asked protocol return ''; } else { $port = $_SERVER['SERVER_PORT']; } } } if ($port === NULL || $port == '' || $https && $port == '443' || !$https && $port == '80') { return ''; } return ':' . $port; }
function checkAppPaths() { $ok = true; if (!defined('JELIX_LIB_PATH') || !App::isInit()) { throw new \Exception($this->messages->get('path.core')); } if (!file_exists(App::tempBasePath()) || !is_writable(App::tempBasePath())) { $this->error('path.temp'); $ok = false; } if (!file_exists(App::logPath()) || !is_writable(App::logPath())) { $this->error('path.log'); $ok = false; } if (!file_exists(App::varPath())) { $this->error('path.var'); $ok = false; } if (!file_exists(App::appConfigPath())) { $this->error('path.config'); $ok = false; } if (!file_exists(App::configPath())) { $this->error('path.config'); $ok = false; } elseif ($this->checkForInstallation) { if (!is_writable(App::configPath())) { $this->error('path.config.writable'); $ok = false; } if (file_exists(App::configPath('profiles.ini.php')) && !is_writable(App::configPath('profiles.ini.php'))) { $this->error('path.profiles.writable'); $ok = false; } if (file_exists(App::configPath('installer.ini.php')) && !is_writable(App::configPath('installer.ini.php'))) { $this->error('path.installer.writable'); $ok = false; } } if (!file_exists(App::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')); } return $ok; }
protected function checkPhpSettings() { if (file_exists(App::configPath("mainconfig.ini.php"))) { $defaultconfig = parse_ini_file(App::configPath("mainconfig.ini.php"), true); } else { $defaultconfig = array(); } if (file_exists(App::configPath("index/config.ini.php"))) { $indexconfig = parse_ini_file(App::configPath("index/config.ini.php"), true); } else { $indexconfig = array(); } return parent::checkPhpSettings(); }
public function run() { $appPath = $this->getParam('path'); $appPath = $this->getRealPath($appPath); $appName = basename($appPath); $appPath .= '/'; if (file_exists($appPath . '/jelix-app.json') || file_exists($appPath . '/project.xml')) { throw new Exception("this application is already created"); } $this->config = JelixScript::loadConfig($appName); $this->config->infoWebsite = $this->config->newAppInfoWebsite; $this->config->infoLicence = $this->config->newAppInfoLicence; $this->config->infoLicenceUrl = $this->config->newAppInfoLicenceUrl; $this->config->infoLocale = $this->config->newAppInfoLocale; $this->config->infoCopyright = $this->config->newAppInfoCopyright; $this->config->initAppPaths($appPath); App::setEnv('jelix-scripts'); JelixScript::checkTempPath(); if ($p = $this->getOption('-wwwpath')) { $wwwpath = path::real($appPath . $p, false) . '/'; } else { $wwwpath = App::wwwPath(); } $this->createDir($appPath); $this->createDir(App::tempBasePath()); $this->createDir($wwwpath); $varPath = App::varPath(); $configPath = App::configPath(); $this->createDir($varPath); $this->createDir(App::logPath()); $this->createDir($configPath); $this->createDir($configPath . 'index/'); $this->createDir($varPath . 'overloads/'); $this->createDir($varPath . 'themes/'); $this->createDir($varPath . 'themes/default/'); $this->createDir($varPath . 'uploads/'); $this->createDir($varPath . 'sessions/'); $this->createDir($varPath . 'mails/'); $this->createDir($appPath . 'install'); $this->createDir($appPath . 'modules'); $this->createDir($appPath . 'plugins'); $this->createDir($appPath . 'responses'); $this->createDir($appPath . 'tests'); $this->createDir(App::scriptsPath()); $param = array(); if ($this->getOption('-nodefaultmodule')) { $param['tplname'] = 'jelix~defaultmain'; $param['modulename'] = 'jelix'; } else { $moduleName = $this->getOption('-modulename'); if (!$moduleName) { // note: since module name are used for name of generated name, // only this characters are allowed $moduleName = preg_replace('/([^a-zA-Z_0-9])/', '_', $appName); } $param['modulename'] = $moduleName; $param['tplname'] = $moduleName . '~main'; } $param['config_file'] = 'index/config.ini.php'; $param['rp_temp'] = $this->getRelativePath($appPath, App::tempBasePath()); $param['rp_var'] = $this->getRelativePath($appPath, App::varPath()); $param['rp_log'] = $this->getRelativePath($appPath, App::logPath()); $param['rp_conf'] = $this->getRelativePath($appPath, $configPath); $param['rp_www'] = $this->getRelativePath($appPath, $wwwpath); $param['rp_cmd'] = $this->getRelativePath($appPath, App::scriptsPath()); $param['rp_jelix'] = $this->getRelativePath($appPath, JELIX_LIB_PATH); $param['rp_vendor'] = ''; foreach (array(LIB_PATH . 'vendor/', LIB_PATH . '../vendor/', LIB_PATH . '../../../') as $path) { if (file_exists($path)) { $param['rp_vendor'] = $this->getRelativePath($appPath, realpath($path) . '/'); break; } } $param['rp_app'] = $this->getRelativePath($wwwpath, $appPath); $this->createFile(App::logPath() . '.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'mails/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'sessions/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'overloads/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'themes/default/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'uploads/.dummy', 'dummy.tpl', array()); $this->createFile($appPath . 'plugins/.dummy', 'dummy.tpl', array()); $this->createFile(App::scriptsPath() . '.dummy', 'dummy.tpl', array()); $this->createFile(App::tempBasePath() . '.dummy', 'dummy.tpl', array()); $this->createFile($appPath . '.htaccess', 'htaccess_deny', $param, "Configuration file for Apache"); $this->createFile($appPath . '.gitignore', 'git_ignore.tpl', $param, ".gitignore"); $this->createFile($appPath . 'jelix-app.json', 'jelix-app.json.tpl', $param, "Project description file"); $this->createFile($appPath . 'composer.json', 'composer.json.tpl', $param, "Composer file"); $this->createFile($appPath . 'cmd.php', 'cmd.php.tpl', $param, "Script for developer commands"); $this->createFile($configPath . 'mainconfig.ini.php', 'var/config/mainconfig.ini.php.tpl', $param, "Main configuration file"); $this->createFile($configPath . 'localconfig.ini.php.dist', 'var/config/localconfig.ini.php.tpl', $param, "Configuration file for specific environment"); $this->createFile($configPath . 'profiles.ini.php', 'var/config/profiles.ini.php.tpl', $param, "Profiles file"); $this->createFile($configPath . 'profiles.ini.php.dist', 'var/config/profiles.ini.php.tpl', $param, "Profiles file for your repository"); $this->createFile($configPath . 'preferences.ini.php', 'var/config/preferences.ini.php.tpl', $param, "Preferences file"); $this->createFile($configPath . 'urls.xml', 'var/config/urls.xml.tpl', $param, "URLs mapping file"); $this->createFile($configPath . 'index/config.ini.php', 'var/config/index/config.ini.php.tpl', $param, "Entry point configuration file"); $this->createFile($appPath . 'responses/myHtmlResponse.class.php', 'responses/myHtmlResponse.class.php.tpl', $param, "Main response class"); $this->createFile($appPath . 'install/installer.php', 'installer/installer.php.tpl', $param, "Installer script"); $this->createFile($appPath . 'tests/runtests.php', 'tests/runtests.php', $param, "Tests script"); $temp = dirname(rtrim(App::tempBasePath(), '/')); if ($temp != rtrim($appPath, '/')) { if (file_exists($temp . '/.gitignore')) { $gitignore = file_get_contents($temp . '/.gitignore') . "\n" . $appName . "/*\n"; file_put_contents($temp . '/.gitignore', $gitignore); } else { file_put_contents($temp . '/.gitignore', $appName . "/*\n"); } } else { $gitignore = file_get_contents($appPath . '.gitignore') . "\n" . basename(rtrim(App::tempBasePath(), '/')) . "/*\n"; file_put_contents($appPath . '.gitignore', $gitignore); } $this->createFile($wwwpath . 'index.php', 'www/index.php.tpl', $param, "Main entry point"); $this->createFile($wwwpath . '.htaccess', 'htaccess_allow', $param, "Configuration file for Apache"); $param['php_rp_temp'] = $this->convertRp($param['rp_temp']); $param['php_rp_var'] = $this->convertRp($param['rp_var']); $param['php_rp_log'] = $this->convertRp($param['rp_log']); $param['php_rp_conf'] = $this->convertRp($param['rp_conf']); $param['php_rp_www'] = $this->convertRp($param['rp_www']); $param['php_rp_cmd'] = $this->convertRp($param['rp_cmd']); $param['php_rp_jelix'] = $this->convertRp($param['rp_jelix']); if ($param['rp_vendor']) { $param['php_rp_vendor'] = $this->convertRp($param['rp_vendor']); $this->createFile($appPath . 'application.init.php', 'application2.init.php.tpl', $param, "Bootstrap file"); } else { $this->createFile($appPath . 'application.init.php', 'application.init.php.tpl', $param, "Bootstrap file"); } $installer = new \Jelix\Installer\Installer(new \Jelix\Installer\Reporter\Console('warning')); $installer->installApplication(); $moduleok = true; if (!$this->getOption('-nodefaultmodule')) { try { $cmd = JelixScript::getCommand('createmodule', $this->config); $options = $this->getCommonActiveOption(); $options['-addinstallzone'] = true; $options['-noregistration'] = true; $cmd->initOptParam($options, array('module' => $param['modulename'])); $cmd->run(); $this->createFile($appPath . 'modules/' . $param['modulename'] . '/templates/main.tpl', 'module/main.tpl.tpl', $param, "Main template"); } catch (Exception $e) { $moduleok = false; echo "The module has not been created because of this error: " . $e->getMessage() . "\nHowever the application has been created\n"; } } if ($this->getOption('-withcmdline')) { if (!$this->getOption('-nodefaultmodule') && $moduleok) { $agcommand = JelixScript::getCommand('createctrl', $this->config); $options = $this->getCommonActiveOption(); $options['-cmdline'] = true; $agcommand->initOptParam($options, array('module' => $param['modulename'], 'name' => 'default', 'method' => 'index')); $agcommand->run(); } $agcommand = JelixScript::getCommand('createentrypoint', $this->config); $options = $this->getCommonActiveOption(); $options['-type'] = 'cmdline'; $parameters = array('name' => $param['modulename']); $agcommand->initOptParam($options, $parameters); $agcommand->run(); } }