function install() { if (!$this->firstDbExec()) { return; } // --- install table for session storage if needed $sessionStorage = $this->config->getValue("storage", "sessions"); $sessionDao = $this->config->getValue("dao_selector", "sessions"); $sessionProfile = $this->config->getValue("dao_db_profile", "sessions"); if ($sessionStorage == "dao" && $sessionDao == "jelix~jsession") { $this->execSQLScript('sql/install_jsession.schema'); } // --- install table for jCache if needed $cachefile = jApp::configPath('profiles.ini.php'); if (file_exists($cachefile)) { $ini = new \Jelix\IniFile\IniModifier($cachefile); foreach ($ini->getSectionList() as $section) { if (substr($section, 0, 7) != 'jcache:') { continue; } $driver = $ini->getValue('driver', $section); $dao = $ini->getValue('dao', $section); $this->useDbProfile($ini->getValue('dbprofile', $section)); if ($driver == 'db' && $dao == 'jelix~jcache' && $this->firstExec('cachedb:' . $this->dbProfile)) { $this->execSQLScript('sql/install_jcache.schema'); } } } }
protected function _upgradeconf($module) { $conf = null; // get from entrypoint config $jacl2File = $this->getConfigIni()->getOverrider()->getValue($module, 'coordplugins'); if ($jacl2File == '') { // get from localConfig.ini.php $jacl2File = $this->getLocalConfigIni()->getOverrider()->getValue($module, 'coordplugins'); if ($jacl2File == '') { // get from mainConfig.ini.php $jacl2File = $this->getMainConfigIni()->getOverrider()->getValue($module, 'coordplugins'); $conf = $this->getMainConfigIni()->getOverrider(); } else { $conf = $this->getLocalConfigIni()->getOverrider(); } } else { $conf = $this->getConfigIni()->getOverrider(); } if ($jacl2File == '' || $jacl2File == '1') { return; } $jacl2File = jApp::configPath($jacl2File); if (!file_exists($jacl2File)) { $jacl2File = ''; $message = $module . "~errors.action.right.needed"; if ($this->entryPoint->type != 'classic') { $onerror = 1; } else { $onerror = 2; } $on_error_action = "jelix~error:badright"; } else { $ini = new \Jelix\IniFile\IniModifier($jacl2File); $message = $ini->getValue('error_message'); // = '); if ($message == "jelix~errors.acl.action.right.needed") { $message = $module . "~errors.action.right.needed"; } $onerror = $ini->getValue('on_error'); $on_error_action = $ini->getValue('on_error_action'); } $conf->setValue($module, '1', 'coordplugins'); $conf->setValue('on_error', $onerror, 'coordplugin_' . $module); $conf->setValue('error_message', $message, 'coordplugin_' . $module); $conf->setValue('on_error_action', $on_error_action, 'coordplugin_' . $module); $conf->save(); }
function install() { if (self::$key === null) { self::$key = jAuth::getRandomPassword(30, true); } $conf = $this->getConfigIni()->getValue('auth', 'coordplugins'); if ($conf != '1') { $conff = jApp::configPath($conf); if (file_exists($conff)) { $ini = new \Jelix\IniFile\IniModifier($conff); $ini->removeValue('persistant_crypt_key'); $ini->save(); } } $localConfigIni = $this->getLocalConfigIni(); $localConfigIni->getMaster()->setValue('persistant_crypt_key', self::$key, 'coordplugin_auth'); }
function install() { if (self::$key === null) { $cryptokey = \Defuse\Crypto\Key::createNewRandomKey(); self::$key = $cryptokey->saveToAsciiSafeString(); } $conf = $this->getConfigIni()->getValue('auth', 'coordplugins'); if ($conf == '1') { $this->getConfigIni()->removeValue('persistant_crypt_key', 'coordplugin_auth'); } else { if ($conf) { $conff = jApp::configPath($conf); if (file_exists($conff)) { $ini = new \Jelix\IniFile\IniModifier($conff); $ini->removeValue('persistant_crypt_key'); } } } $this->getLocalConfigIni()->setValue('persistant_encryption_key', self::$key, 'coordplugin_auth'); }
function install() { $authconfig = $this->getConfigIni()->getValue('auth', 'coordplugins'); if ($authconfig && $this->entryPoint->type != 'cmdline' && $this->firstExec($authconfig)) { $conf = new \Jelix\IniFile\IniModifier(jApp::configPath($authconfig)); $driver = $conf->getValue('driver'); $daoName = $conf->getValue('dao', 'Db'); $formName = $conf->getValue('form', 'Db'); if ($driver == 'Db' && $daoName == 'jauthdb~jelixuser' && $formName == '') { $conf->setValue('form', 'jauthdb_admin~jelixuser', 'Db'); $conf->save(); } } }
function install() { //if ($this->entryPoint->type == 'cmdline') // return; $authconfig = $this->config->getValue('auth', 'coordplugins'); if ($authconfig && $this->firstExec($authconfig)) { // a config file for the auth plugin exists, so we can install // the module, else we ignore it $conf = new \Jelix\IniFile\IniModifier(jApp::configPath($authconfig)); $driver = $conf->getValue('driver'); if ($driver == '') { $driver = 'Db'; $conf->setValue('driver', 'Db'); $conf->setValue('dao', 'jauthdb~jelixuser', 'Db'); $conf->save(); } else { if ($driver != 'Db') { return; } } $this->useDbProfile($conf->getValue('profile', 'Db')); // FIXME: should use the given dao to create the table $daoName = $conf->getValue('dao', 'Db'); if ($daoName == 'jauthdb~jelixuser' && $this->firstDbExec()) { $this->execSQLScript('install_jauth.schema'); if ($this->getParameter('defaultuser')) { require_once JELIX_LIB_PATH . 'auth/jAuth.class.php'; require_once JELIX_LIB_PATH . 'plugins/auth/db/db.auth.php'; $confIni = parse_ini_file(jApp::configPath($authconfig), true); $authConfig = jAuth::loadConfig($confIni); $driver = new dbAuthDriver($authConfig['Db']); $passwordHash = $driver->cryptPassword('admin'); $cn = $this->dbConnection(); $cn->exec("INSERT INTO " . $cn->prefixTable('jlx_user') . " (usr_login, usr_password, usr_email ) VALUES\n ('admin', " . $cn->quote($passwordHash) . " , '*****@*****.**')"); } } } }
/** * 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'); }
protected function _execute(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $initialVersion = $input->getOption('ver'); if (!$initialVersion) { $initialVersion = '0.1pre'; } // note: since module name are used for name of generated name, // only this characters are allowed if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) { throw new \Exception("'" . $module . "' is not a valid name for a module"); } // check if the module already exist or not $path = ''; try { $path = $this->getModulePath($module); } catch (\Exception $e) { } if ($path != '') { throw new \Exception("module '" . $module . "' already exists"); } // verify the given repository $repository = $input->getArgument('repository'); if (substr($repository, -1) != '/') { $repository .= '/'; } $repositoryPath = \jFile::parseJelixPath($repository); if (!$input->getOption('noregistration')) { $this->registerModulesDir($repository, $repositoryPath); } $path = $repositoryPath . $module . '/'; $this->createDir($path); App::setConfig(null); $noSubDir = $input->getOption('nosubdir'); $addInstallZone = $input->getOption('addinstallzone'); $isdefault = $input->getOption('defaultmodule'); if ($input->getOption('admin')) { $noSubDir = false; $addInstallZone = false; } $param = array(); $param['module'] = $module; $param['version'] = $initialVersion; $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param); // create all sub directories of a module if (!$noSubDir) { $this->createDir($path . 'classes/'); $this->createDir($path . 'zones/'); $this->createDir($path . 'controllers/'); $this->createDir($path . 'templates/'); $this->createDir($path . 'classes/'); $this->createDir($path . 'daos/'); $this->createDir($path . 'forms/'); $this->createDir($path . 'locales/'); $this->createDir($path . 'locales/en_US/'); $this->createDir($path . 'locales/fr_FR/'); $this->createDir($path . 'install/'); if ($this->verbose()) { $output->writeln("Sub directories have been created in the new module {$module}."); } $this->createFile($path . 'install/install.php', 'module/install.tpl', $param); $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array()); } $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile()); $urlsFile = App::appConfigPath($iniDefault->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); // activate the module in the application if ($isdefault) { if ($this->allEntryPoint) { $xmlEp = $xmlMap->getDefaultEntryPoint($type); } else { $xmlEp = $xmlMap->getEntryPoint($this->entryPointId); } if ($xmlEp) { $xmlEp->addUrlAction('/', $module, 'default:index', null, null, array('default' => true)); $xmlEp->addUrlModule('', $module); if ($this->verbose()) { $output->writeln("The new module {$module} becomes the default module"); } } else { if ($this->verbose()) { $output->writeln("No default entry point found: the new module cannot be the default module"); } } } $xmlMap->save(); $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules'); $iniDefault->save(); $list = $this->getEntryPointsList(); $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); // install the module for all needed entry points foreach ($list as $entryPoint) { $configFile = App::appConfigPath($entryPoint['config']); $epconfig = new \Jelix\IniFile\IniModifier($configFile); if ($this->allEntryPoint) { $access = 2; } else { $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0; } $epconfig->setValue($module . '.access', $access, 'modules'); $epconfig->save(); if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { $install->setValue($module . '.installed', 1, $entryPoint['id']); $install->setValue($module . '.version', $initialVersion, $entryPoint['id']); } if ($this->verbose()) { $output->writeln("The module is initialized for the entry point " . $entryPoint['file']); } } $install->save(); App::declareModule($path); // create a default controller if (!$input->getOption('nocontroller')) { $arguments = array('module' => $module, 'controller' => 'default', 'method' => 'index'); if ($input->getOption('entry-point')) { $arguments['--entry-point'] = $input->getOption('entry-point'); } if ($input->getOption('cmdline')) { $arguments['--cmdline'] = true; } if ($addInstallZone) { $arguments['--addinstallzone'] = true; } if ($output->isVerbose()) { $arguments['-v'] = true; } $this->executeSubCommand('module:create-ctrl', $arguments, $output); } if ($input->getOption('admin')) { $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener"); $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param); file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module); file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module); } }
protected function loadProfiles() { $file = jApp::configPath('profiles.ini.php'); if (file_exists($file)) { } elseif (file_exists(jApp::configPath('profiles.ini.php.dist'))) { copy(jApp::configPath('profiles.ini.php.dist'), $file); } else { file_put_contents($file, ";<?php die(''); ?>\n;for security reasons, don't remove or modify the first line\n\n[jdb:default]\ndriver=mysqli\ndatabase=\nhost=localhost\nuser=\npassword=\npersistent = on\nforce_encoding = on\ntable_prefix=\n"); } $ini = new \Jelix\IniFile\IniModifier($file); $data = array('dbtype' => array(), 'driver' => array(), 'database' => array(), 'host' => array(), 'port' => array(), 'user' => array(), 'password' => array(), 'passwordconfirm' => array(), 'persistent' => array(), 'table_prefix' => array(), 'force_encoding' => array(), 'search_path' => array(), 'errors' => array()); $profiles = $ini->getSectionList(); $dbprofileslist = array(); foreach ($profiles as $profile) { if (strpos($profile, 'jdb:') !== 0) { continue; } $dbprofileslist[] = $profile; $options = $ini->getValues($profile); $dbparam = new jDbParameters($options); $options = $dbparam->getParameters(); $data['dbtype'][$profile] = $options['dbtype']; $driver = $options['driver']; if ($options['usepdo']) { $dsn = $ini->getValue('dsn', $profile); $data['driver'][$profile] = $driver . ':pdo'; if (preg_match("/host=([^;]*)(;|\$)/", $dsn, $m)) { $data['host'][$profile] = $m[1]; } else { $host = $ini->getValue('host', $profile); $data['host'][$profile] = $host === null ? '' : $host; } if (preg_match("/dbname=([^;]*)(;|\$)/", $dsn, $m)) { $data['database'][$profile] = $m[1]; } else { $host = $ini->getValue('database', $profile); $data['database'][$profile] = $host === null ? '' : $host; } if (preg_match("/port=([^;]*)(;|\$)/", $dsn, $m)) { $data['port'][$profile] = $m[1]; } else { $port = $ini->getValue('port', $profile); $data['port'][$profile] = $port === null ? '' : $port; } } else { $data['driver'][$profile] = $driver . ($options['usepdo'] ? ':pdo' : ''); $data['database'][$profile] = $ini->getValue('database', $profile); $data['host'][$profile] = $ini->getValue('host', $profile); $data['port'][$profile] = $ini->getValue('port', $profile); } $data['user'][$profile] = $ini->getValue('user', $profile); $data['password'][$profile] = $ini->getValue('password', $profile); $data['passwordconfirm'][$profile] = $data['password'][$profile]; $data['persistent'][$profile] = $options['persistent']; $data['force_encoding'][$profile] = $options['force_encoding']; $data['table_prefix'][$profile] = $ini->getValue('table_prefix', $profile); $data['search_path'][$profile] = $ini->getValue('search_path', $profile); $data['errors'][$profile] = array(); } $_SESSION['dbprofiles']['profiles'] = $dbprofileslist; $_SESSION['dbprofiles']['data'] = $data; }
protected function loadconf() { $ini = new \Jelix\IniFile\IniModifier(jApp::mainConfigFile()); $emailConfig = array('webmasterEmail' => $ini->getValue('webmasterEmail', 'mailer'), 'webmasterName' => $ini->getValue('webmasterName', 'mailer'), 'mailerType' => $ini->getValue('mailerType', 'mailer'), 'hostname' => $ini->getValue('hostname', 'mailer'), 'sendmailPath' => $ini->getValue('sendmailPath', 'mailer'), 'smtpHost' => $ini->getValue('smtpHost', 'mailer'), 'smtpPort' => $ini->getValue('smtpPort', 'mailer'), 'smtpSecure' => $ini->getValue('smtpSecure', 'mailer'), 'smtpHelo' => $ini->getValue('smtpHelo', 'mailer'), 'smtpAuth' => $ini->getValue('smtpAuth', 'mailer'), 'smtpUsername' => $ini->getValue('smtpUsername', 'mailer'), 'smtpPassword' => $ini->getValue('smtpPassword', 'mailer'), 'smtpTimeout' => $ini->getValue('smtpTimeout', 'mailer'), 'errors' => array()); if (!in_array($emailConfig['mailerType'], array('mail', 'sendmail', 'smtp'))) { $emailConfig['mailerType'] = 'mail'; } return $emailConfig; }
public function store() { $input = Input::all(); $rules = ['c' => 'required', 'cn' => 'required', 'cns' => 'required', 'root_password' => 'required']; $v = Validator::make($input, $rules); if ($v->fails()) { return Redirect::route('certs-path')->withInput(Input::except('root_password'))->with('error', 'Please provide at least the country, a common name and the password of your Root CA.'); } if (!in_array('*' . $input['cns'], Auth::user()->domains)) { return Redirect::route('certs-path')->withInput(Input::except('root_password'))->with('error', 'You are not allowed to create a certificate for this domain.'); } $sluggedDomain = Str::slug(str_replace('.', '_', $input['cn'] . $input['cns'])); if (!File::exists($this->certDir . $sluggedDomain . '.crt')) { // Get field $c = Input::get('c'); $st = Input::get('st'); $l = Input::get('l'); $o = Input::get('o'); $ou = Input::get('ou'); $cn = $input['cn'] . $input['cns']; $san = Input::get('san'); $email = Input::get('email'); $root_pw = Input::get('root_password'); $extension = 'v3_emp'; // Prepare subject $subj = "'/C={$c}"; $subj .= !empty($st) ? "/ST={$st}" : ''; $subj .= !empty($l) ? "/L={$l}" : ''; $subj .= !empty($o) ? "/O={$o}" : ''; $subj .= !empty($ou) ? "/OU={$ou}" : ''; $subj .= "/CN={$cn}"; $subj .= !empty($email) ? "/Email={$email}" : ''; $subj .= "'"; // copy config openssl $tmpcnf = tempnam(sys_get_temp_dir(), 'ssl'); file_put_contents($tmpcnf, file_get_contents($this->cnfPath)); $ini = new \Jelix\IniFile\IniModifier($tmpcnf); // Add alternate name if (!empty($san)) { $altNames = array_filter(explode(',', str_replace(array(',', ' ', ';'), ',', $san . ','))); foreach ($altNames as $index => $altName) { $ini->setValue('DNS.' . ($index + 1), $altName, 'alt_names'); } $extension = 'v3_req'; } $ini->save(); // Create private key and CSR $process = new Process("cd {$this->certDir} && openssl req -nodes -new -newkey rsa:2048 -sha256 " . "-reqexts {$extension} -extensions {$extension} -config {$tmpcnf} -keyout {$sluggedDomain}.key " . "-out {$sluggedDomain}.csr -days 365 -subj {$subj}"); $process->run(); if (!$process->isSuccessful()) { File::delete($this->certDir . $sluggedDomain . '.csr'); // cleanup File::delete($this->certDir . $sluggedDomain . '.pem'); File::delete($this->certDir . $sluggedDomain . '.key'); File::delete($tmpcnf); return Redirect::route('certs-path')->withInput(Input::except('root_password'))->with('error', 'Could not create private key or CSR. ' . $process->getErrorOutput()); } // Sign cert, convert into DES and remove CSR $process = new Process("cd {$this->certDir} && openssl x509 -passin pass:{$root_pw} -CA rootCA.pem " . "-CAkey rootCA.key -CAcreateserial -days 365 -sha256 -req -extensions {$extension} " . "-extfile {$tmpcnf} -in {$sluggedDomain}.csr -out {$sluggedDomain}.pem && openssl x509 " . "-extensions {$extension} -extfile {$tmpcnf} -in {$sluggedDomain}.pem -out {$sluggedDomain}.crt"); $process->run(); if (!$process->isSuccessful()) { File::delete($this->certDir . $sluggedDomain . '.csr'); // cleanup File::delete($this->certDir . $sluggedDomain . '.pem'); File::delete($this->certDir . $sluggedDomain . '.key'); File::delete($tmpcnf); return Redirect::route('certs-path')->withInput(Input::except('root_password'))->with('error', 'Could not sign certificate. Is the provided Root CA password correct? ' . nl2br($process->getErrorOutput())); } File::delete($this->certDir . $sluggedDomain . '.csr'); File::delete($tmpcnf); // Create database entry Cert::create(['user_id' => Auth::user()->id, 'domain' => $cn, 'csr' => 0]); return Redirect::route('certs-path')->with('success', 'Certificate has been created.'); } else { return Redirect::route('certs-path')->withInput(Input::except('root_password'))->with('warning', 'Certificate already exists.'); } }
public function run() { $this->loadAppConfig(); $module = $this->getParam('module'); $initialVersion = $this->getOption('-ver'); if ($initialVersion === false) { $initialVersion = '0.1pre'; } // note: since module name are used for name of generated name, // only this characters are allowed if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) { throw new Exception("'" . $module . "' is not a valid name for a module"); } // check if the module already exist or not $path = ''; try { $path = $this->getModulePath($module); } catch (Exception $e) { } if ($path != '') { throw new Exception("module '" . $module . "' already exists"); } // verify the given repository $repository = $this->getParam('repository', 'app:modules/'); if (substr($repository, -1) != '/') { $repository .= '/'; } $repositoryPath = jFile::parseJelixPath($repository); if (!$this->getOption('-noregistration')) { $this->registerModulesDir($repository, $repositoryPath); } $path = $repositoryPath . $module . '/'; $this->createDir($path); App::setConfig(null); if ($this->getOption('-admin')) { $this->removeOption('-nosubdir'); $this->removeOption('-addinstallzone'); } $param = array(); $param['module'] = $module; $param['version'] = $initialVersion; $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param); // create all sub directories of a module if (!$this->getOption('-nosubdir')) { $this->createDir($path . 'classes/'); $this->createDir($path . 'zones/'); $this->createDir($path . 'controllers/'); $this->createDir($path . 'templates/'); $this->createDir($path . 'classes/'); $this->createDir($path . 'daos/'); $this->createDir($path . 'forms/'); $this->createDir($path . 'locales/'); $this->createDir($path . 'locales/en_US/'); $this->createDir($path . 'locales/fr_FR/'); $this->createDir($path . 'install/'); if ($this->verbose()) { echo "Sub directories have been created in the new module {$module}.\n"; } $this->createFile($path . 'install/install.php', 'module/install.tpl', $param); $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array()); } $isdefault = $this->getOption('-defaultmodule'); $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile()); // activate the module in the application if ($isdefault) { $iniDefault->setValue('startModule', $module); $iniDefault->setValue('startAction', 'default:index'); if ($this->verbose()) { echo "The new module {$module} becomes the default module\n"; } } $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules'); $iniDefault->save(); $list = $this->getEntryPointsList(); $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); // install the module for all needed entry points foreach ($list as $entryPoint) { $configFile = App::configPath($entryPoint['config']); $epconfig = new \Jelix\IniFile\IniModifier($configFile); if ($this->allEntryPoint) { $access = 2; } else { $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0; } $epconfig->setValue($module . '.access', $access, 'modules'); $epconfig->save(); if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { $install->setValue($module . '.installed', 1, $entryPoint['id']); $install->setValue($module . '.version', $initialVersion, $entryPoint['id']); } if ($isdefault) { // we set the module as default module for one or all entry points. // we set the startModule option for all entry points except // if an entry point is indicated on the command line if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { if ($epconfig->getValue('startModule') != '') { $epconfig->setValue('startModule', $module); $epconfig->setValue('startAction', 'default:index'); $epconfig->save(); } } } if ($this->verbose()) { echo "The module is initialized for the entry point " . $entryPoint['file'] . ".\n"; } } $install->save(); // create a default controller if (!$this->getOption('-nocontroller')) { $agcommand = JelixScript::getCommand('createctrl', $this->config); $options = $this->getCommonActiveOption(); if ($this->getOption('-cmdline')) { $options['-cmdline'] = true; } if ($this->getOption('-addinstallzone')) { $options['-addinstallzone'] = true; } $agcommand->initOptParam($options, array('module' => $module, 'name' => 'default', 'method' => 'index')); $agcommand->run(); } if ($this->getOption('-admin')) { $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener"); $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param); file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module); file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module); } }
protected function _execute(InputInterface $input, OutputInterface $output) { $entrypoint = $input->getArgument('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $options = array('entrypoint' => $entrypoint); $this->executeSubCommand('app:createentrypoint', $options, $output); $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::appConfigPath($ep['config'])); $params = array(); $this->createFile(App::appPath('app/responses/adminHtmlResponse.class.php'), 'app/responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(App::appPath('app/responses/adminLoginHtmlResponse.class.php'), 'app/responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $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'); $inifile->save(); $urlsFile = jApp::appConfigPath($inifile->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); $xmlEp = $xmlMap->getEntryPoint($entrypoint); $xmlEp->addUrlAction('/', 'master_admin', 'default:index', null, null, array('default' => true)); $xmlEp->addUrlModule('', 'master_admin'); $xmlEp->addUrlInclude('/admin/acl', 'jacl2db_admin', 'urls.xml'); $xmlEp->addUrlInclude('/admin/auth', 'jauthdb_admin', 'urls.xml'); $xmlEp->addUrlInclude('/admin/pref', 'jpref_admin', 'urls.xml'); $xmlEp->addUrlInclude('/auth', 'jauth', 'urls.xml'); $xmlMap->save(); $reporter = new \Jelix\Installer\Reporter\Console($output->isVerbose() ? 'notice' : 'warning'); $installer = new \Jelix\Installer\Installer($reporter); $installer->installModules(array('jauth', '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 = $input->getOption('profile'); if (!$input->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 (!$input->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'); }