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'); }
/** * 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; }
function process() { $ini = new \Jelix\IniFile\IniModifier(jApp::configPath('profiles.ini.php')); $hasErrors = false; $_SESSION['dbprofiles']['data'] = $_POST; foreach ($_SESSION['dbprofiles']['profiles'] as $profile) { $errors = array(); $params = array(); $driver = $_POST['driver'][$profile]; $usepdo = false; if (substr($driver, -4) == ':pdo') { $ini->setValue('usepdo', true, $profile); $usepdo = true; $realdriver = substr($driver, 0, -4); } else { $ini->removeValue('usepdo', $profile); $realdriver = $driver; } $ini->removeValue('dsn', $profile); if (isset($_POST['persistent'][$profile]) && $_POST['persistent'][$profile] == 'on') { $ini->setValue('persistent', true, $profile); } else { $ini->removeValue('persistent', $profile); } if (isset($_POST['force_encoding'][$profile]) && $_POST['force_encoding'][$profile] == 'on') { $ini->setValue('force_encoding', true, $profile); } else { $ini->removeValue('force_encoding', $profile); } $ini->setValue('table_prefix', $_POST['table_prefix'][$profile], $profile); $database = trim($_POST['database'][$profile]); if ($database == '') { $errors[] = $this->locales['error.missing.database']; continue; } $params['database'] = $database; $ini->setValue('database', $database, $profile); $params['driver'] = $realdriver; $ini->setValue('driver', $realdriver, $profile); if ($_POST['dbtype'][$profile] != 'sqlite') { $host = trim($_POST['host'][$profile]); if ($host == '' && $realdriver != 'pgsql') { $errors[] = $this->locales['error.missing.host']; } else { $ini->setValue('host', $host, $profile); $params['host'] = $host; } $port = trim($_POST['port'][$profile]); if ($port != '') { $ini->setValue('port', $port, $profile); $params['port'] = $port; } $user = trim($_POST['user'][$profile]); if ($user == '') { $errors[] = $this->locales['error.missing.user']; } else { $ini->setValue('user', $user, $profile); $params['user'] = $user; } $password = trim($_POST['password'][$profile]); $passwordRequired = isset($this->config['passwordRequired']) && $this->config['passwordRequired']; if ($password == '' && $passwordRequired) { $errors[] = $this->locales['error.missing.password']; } else { $ini->setValue('password', $password, $profile); $params['password'] = $password; } if (trim($_POST['passwordconfirm'][$profile]) != $password) { $errors[] = $this->locales['error.invalid.confirm.password']; } if ($_POST['dbtype'][$profile] == 'pgsql') { $search_path = trim($_POST['search_path'][$profile]); $params['search_path'] = $search_path; if ($search_path != '') { $ini->setValue('search_path', $search_path, $profile); } } } if (!count($errors)) { $options = $ini->getValues($profile); $dbparam = new jDbParameters($options); $options = $dbparam->getParameters(); try { if ($usepdo) { $m = 'check_PDO'; } else { $m = 'check_' . $options['driver']; } $this->{$m}($options); } catch (Exception $e) { $errors[] = $e->getMessage(); } } if (count($errors)) { $hasErrors = true; } $_SESSION['dbprofiles']['data']['errors'][$profile] = $errors; } if ($hasErrors) { return false; } $ini->save(); unset($_SESSION['dbprofiles']); return 0; }