default_user, false); // Then, we set $_SESSION vars Minz_Session::_params([ 'title' => FreshRSS_Context::$system_conf->title, 'auth_type' => FreshRSS_Context::$system_conf->auth_type, 'default_user' => Minz_User::name(), 'passwordHash' => FreshRSS_Context::$user_conf->passwordHash, 'bd_type' => FreshRSS_Context::$system_conf->db['type'] ?? '', 'bd_host' => FreshRSS_Context::$system_conf->db['host'] ?? '', 'bd_user' => FreshRSS_Context::$system_conf->db['user'] ?? '', 'bd_password' => FreshRSS_Context::$system_conf->db['password'] ?? '', 'bd_base' => FreshRSS_Context::$system_conf->db['base'] ?? '', 'bd_prefix' => FreshRSS_Context::$system_conf->db['prefix'] ?? '', 'bd_error' => false, ]); header('Location: index.php?step=4'); } } function saveStep2(): void { if (!empty($_POST)) { if (Minz_Session::param('bd_type') === 'sqlite') { Minz_Session::_params([ 'bd_base' => false, 'bd_host' => false, 'bd_user' => false, 'bd_password' => false, 'bd_prefix' => false, ]); } else { if (empty($_POST['type']) || empty($_POST['host']) || empty($_POST['user']) || empty($_POST['base'])) { Minz_Session::_param('bd_error', 'Missing parameters!'); } Minz_Session::_params([ 'bd_base' => substr($_POST['base'], 0, 64), 'bd_host' => $_POST['host'], 'bd_user' => $_POST['user'], 'bd_password' => $_POST['pass'], 'bd_prefix' => substr($_POST['prefix'], 0, 16), ]); } if (Minz_Session::param('bd_type') === 'pgsql') { Minz_Session::_param('bd_base', strtolower(Minz_Session::param('bd_base'))); } // We use dirname to remove the /i part $base_url = dirname(Minz_Request::guessBaseUrl()); $config_array = [ 'salt' => generateSalt(), 'base_url' => $base_url, 'default_user' => '_', 'db' => [ 'type' => Minz_Session::param('bd_type'), 'host' => Minz_Session::param('bd_host'), 'user' => Minz_Session::param('bd_user'), 'password' => Minz_Session::param('bd_password'), 'base' => Minz_Session::param('bd_base'), 'prefix' => Minz_Session::param('bd_prefix'), 'pdo_options' => [], ], 'pubsubhubbub_enabled' => Minz_Request::serverIsPublic($base_url), ]; if (Minz_Session::param('title') != '') { $config_array['title'] = Minz_Session::param('title'); } $customConfigPath = DATA_PATH . '/config.custom.php'; if (file_exists($customConfigPath)) { $customConfig = include($customConfigPath); if (is_array($customConfig)) { $config_array = array_merge($customConfig, $config_array); } } @unlink(DATA_PATH . '/config.php'); //To avoid access-rights problems file_put_contents(DATA_PATH . '/config.php', "getMessage()); $ok = false; } if (!$ok) { @unlink(join_path(DATA_PATH, 'config.php')); } if ($ok) { Minz_Session::_param('bd_error'); header('Location: index.php?step=3'); } elseif (Minz_Session::param('bd_error') == '') { Minz_Session::_param('bd_error', 'Unknown error!'); } } invalidateHttpCache(); } function saveStep3(): bool { FreshRSS_Context::initSystem(); Minz_Translate::init(Minz_Session::param('language')); if (!empty($_POST)) { if (param('auth_type', 'form') != '') { FreshRSS_Context::$system_conf->auth_type = param('auth_type', 'form'); Minz_Session::_param('auth_type', FreshRSS_Context::$system_conf->auth_type); } else { return false; } $password_plain = param('passwordPlain', ''); if (FreshRSS_Context::$system_conf->auth_type === 'form' && $password_plain == '') { return false; } if (FreshRSS_user_Controller::checkUsername(param('default_user', ''))) { FreshRSS_Context::$system_conf->default_user = param('default_user', ''); Minz_Session::_param('default_user', FreshRSS_Context::$system_conf->default_user); } else { return false; } if (FreshRSS_Context::$system_conf->auth_type === 'http_auth' && !empty($_SERVER['REMOTE_ADDR']) && is_string($_SERVER['REMOTE_ADDR'])) { // Trust by default the remote IP address (e.g. proxy) used during install to provide remote user name FreshRSS_Context::$system_conf->trusted_sources = [ $_SERVER['REMOTE_ADDR'] ]; } // Create default user files but first, we delete previous data to // avoid access right problems. recursive_unlink(USERS_PATH . '/' . Minz_Session::param('default_user')); $ok = false; try { $ok = FreshRSS_user_Controller::createUser( Minz_Session::param('default_user'), '', //TODO: Add e-mail $password_plain, [ 'language' => Minz_Session::param('language'), 'is_admin' => true, 'enabled' => true, ] ); } catch (Exception $e) { Minz_Session::_param('bd_error', $e->getMessage()); $ok = false; } if (!$ok) { return false; } FreshRSS_Context::$system_conf->save(); header('Location: index.php?step=4'); } return true; } /*** VÉRIFICATIONS ***/ function checkStep(): void { $s0 = checkStep0(); $s1 = checkRequirements(); $s2 = checkStep2(); $s3 = checkStep3(); if (STEP > 0 && $s0['all'] !== 'ok') { header('Location: index.php?step=0'); } elseif (STEP > 1 && $s1['all'] !== 'ok') { header('Location: index.php?step=1'); } elseif (STEP > 2 && $s2['all'] !== 'ok') { header('Location: index.php?step=2'); } elseif (STEP > 3 && $s3['all'] !== 'ok') { header('Location: index.php?step=3'); } Minz_Session::_param('actualize_feeds', true); } /** @return array */ function checkStep0(): array { $languages = Minz_Translate::availableLanguages(); $language = Minz_Session::param('language') != '' && in_array(Minz_Session::param('language'), $languages, true); $sessionWorking = Minz_Session::param('sessionWorking') === 'ok'; return array( 'language' => $language ? 'ok' : 'ko', 'sessionWorking' => $sessionWorking ? 'ok' : 'ko', 'all' => $language && $sessionWorking ? 'ok' : 'ko' ); } function freshrss_already_installed(): bool { $conf_path = join_path(DATA_PATH, 'config.php'); if (!file_exists($conf_path)) { return false; } // A configuration file already exists, we try to load it. $system_conf = null; try { $system_conf = FreshRSS_SystemConfiguration::init($conf_path); } catch (Minz_FileNotExistException $e) { return false; } // ok, the global conf exists… but what about default user conf? $current_user = $system_conf->default_user; try { FreshRSS_UserConfiguration::init(USERS_PATH . '/' . $current_user . '/config.php'); } catch (Minz_FileNotExistException $e) { return false; } // ok, ok, default user exists too! return true; } /** @return array */ function checkStep2(): array { $conf = is_writable(join_path(DATA_PATH, 'config.php')); $bd = Minz_Session::param('bd_type') != ''; $conn = Minz_Session::param('bd_error') == ''; return [ 'bd' => $bd ? 'ok' : 'ko', 'conn' => $conn ? 'ok' : 'ko', 'conf' => $conf ? 'ok' : 'ko', 'all' => $bd && $conn && $conf ? 'ok' : 'ko', ]; } /** @return array */ function checkStep3(): array { $conf = Minz_Session::param('default_user') != ''; $form = Minz_Session::param('auth_type') != ''; $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user']; if ($defaultUser === null) { $defaultUser = Minz_Session::param('default_user') == '' ? '' : Minz_Session::param('default_user'); } $data = is_writable(join_path(USERS_PATH, $defaultUser, 'config.php')); return [ 'conf' => $conf ? 'ok' : 'ko', 'form' => $form ? 'ok' : 'ko', 'data' => $data ? 'ok' : 'ko', 'all' => $conf && $form && $data ? 'ok' : 'ko', ]; } /* select language */ function printStep0(): void { $actual = Minz_Translate::language(); $languages = Minz_Translate::availableLanguages(); $s0 = checkStep0(); ?>

$messageParams * */ function printStep1Template(string $key, string $value, array $messageParams = []): void { if ('ok' === $value) { $message = _t("install.check.{$key}.ok", ...$messageParams); ?>

tabindex="3" />

> <?= _t('install.title') ?>: <?= _t('install.step', STEP + 1) ?>

: