install.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. <?php
  2. declare(strict_types=1);
  3. if (function_exists('opcache_reset')) {
  4. opcache_reset();
  5. }
  6. header("Content-Security-Policy: default-src 'self'; frame-ancestors 'none'");
  7. header('Referrer-Policy: same-origin');
  8. require(LIB_PATH . '/lib_install.php');
  9. Minz_Session::init('FreshRSS');
  10. if (isset($_GET['step']) && is_numeric($_GET['step'])) {
  11. define('STEP', (int)$_GET['step']);
  12. } else {
  13. define('STEP', 0);
  14. }
  15. if (STEP === 2 && isset($_POST['type'])) {
  16. Minz_Session::_param('bd_type', $_POST['type']);
  17. }
  18. function param(string $key, string $default = ''): string {
  19. return isset($_POST[$key]) && is_string($_POST[$key]) ? trim($_POST[$key]) : $default;
  20. }
  21. // gestion internationalisation
  22. function initTranslate(): void {
  23. Minz_Translate::init();
  24. $available_languages = Minz_Translate::availableLanguages();
  25. if (Minz_Session::paramString('language') == '') {
  26. Minz_Session::_param('language', get_best_language());
  27. }
  28. if (!in_array(Minz_Session::paramString('language'), $available_languages, true)) {
  29. Minz_Session::_param('language', 'en');
  30. }
  31. Minz_Translate::reset(Minz_Session::paramString('language'));
  32. }
  33. function get_best_language(): string {
  34. $accept = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) || !is_string($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  35. return strtolower(substr($accept, 0, 2));
  36. }
  37. /*** SAUVEGARDES ***/
  38. function saveLanguage(): bool {
  39. if (!empty($_POST)) {
  40. if (!isset($_POST['language'])) {
  41. return false;
  42. }
  43. Minz_Session::_param('language', $_POST['language']);
  44. Minz_Session::_param('sessionWorking', 'ok');
  45. header('Location: index.php?step=1');
  46. }
  47. return true;
  48. }
  49. function saveStep1(): void {
  50. if (isset($_POST['freshrss-keep-install']) &&
  51. $_POST['freshrss-keep-install'] === '1') {
  52. // We want to keep our previous installation of FreshRSS
  53. // so we need to make next steps valid by setting $_SESSION vars
  54. // with values from the previous installation
  55. // First, we try to get previous configurations
  56. FreshRSS_Context::initSystem();
  57. FreshRSS_Context::initUser(FreshRSS_Context::systemConf()->default_user, false);
  58. // Then, we set $_SESSION vars
  59. Minz_Session::_params([
  60. 'title' => FreshRSS_Context::systemConf()->title,
  61. 'auth_type' => FreshRSS_Context::systemConf()->auth_type,
  62. 'default_user' => Minz_User::name() ?? '',
  63. 'passwordHash' => FreshRSS_Context::userConf()->passwordHash,
  64. 'bd_type' => FreshRSS_Context::systemConf()->db['type'] ?? '',
  65. 'bd_host' => FreshRSS_Context::systemConf()->db['host'] ?? '',
  66. 'bd_user' => FreshRSS_Context::systemConf()->db['user'] ?? '',
  67. 'bd_password' => FreshRSS_Context::systemConf()->db['password'] ?? '',
  68. 'bd_base' => FreshRSS_Context::systemConf()->db['base'] ?? '',
  69. 'bd_prefix' => FreshRSS_Context::systemConf()->db['prefix'] ?? '',
  70. 'bd_error' => false,
  71. ]);
  72. header('Location: index.php?step=4');
  73. }
  74. }
  75. function saveStep2(): void {
  76. if (!empty($_POST)) {
  77. if (Minz_Session::paramString('bd_type') === 'sqlite') {
  78. Minz_Session::_params([
  79. 'bd_base' => false,
  80. 'bd_host' => false,
  81. 'bd_user' => false,
  82. 'bd_password' => false,
  83. 'bd_prefix' => false,
  84. ]);
  85. } else {
  86. if (empty($_POST['type']) || !is_string($_POST['type']) ||
  87. empty($_POST['host']) || !is_string($_POST['host']) ||
  88. empty($_POST['user']) || !is_string($_POST['user']) ||
  89. empty($_POST['base']) || !is_string($_POST['base']) ||
  90. !is_string($_POST['pass'] ?? null) || !is_string($_POST['prefix'] ?? null)
  91. ) {
  92. Minz_Session::_param('bd_error', 'Missing parameters!');
  93. } else {
  94. Minz_Session::_params([
  95. 'bd_base' => substr($_POST['base'], 0, 64),
  96. 'bd_host' => $_POST['host'],
  97. 'bd_user' => $_POST['user'],
  98. 'bd_password' => $_POST['pass'],
  99. 'bd_prefix' => substr($_POST['prefix'], 0, 16),
  100. ]);
  101. }
  102. }
  103. // We use dirname to remove the /i part
  104. $base_url = dirname(Minz_Request::guessBaseUrl());
  105. $config_array = [
  106. 'salt' => generateSalt(),
  107. 'base_url' => $base_url,
  108. 'default_user' => '_',
  109. 'db' => [
  110. 'type' => Minz_Session::paramString('bd_type'),
  111. 'host' => Minz_Session::paramString('bd_host'),
  112. 'user' => Minz_Session::paramString('bd_user'),
  113. 'password' => Minz_Session::paramString('bd_password'),
  114. 'base' => Minz_Session::paramString('bd_base'),
  115. 'prefix' => Minz_Session::paramString('bd_prefix'),
  116. 'pdo_options' => [],
  117. ],
  118. 'pubsubhubbub_enabled' => Minz_Request::serverIsPublic($base_url),
  119. ];
  120. if (Minz_Session::paramString('title') != '') {
  121. $config_array['title'] = Minz_Session::paramString('title');
  122. }
  123. $customConfigPath = DATA_PATH . '/config.custom.php';
  124. if (file_exists($customConfigPath)) {
  125. $customConfig = include($customConfigPath);
  126. if (is_array($customConfig)) {
  127. $config_array = array_merge($customConfig, $config_array);
  128. if (!is_string($config_array['default_user'] ?? null)) {
  129. $config_array['default_user'] = '_';
  130. }
  131. }
  132. }
  133. @unlink(DATA_PATH . '/config.php'); //To avoid access-rights problems
  134. file_put_contents(DATA_PATH . '/config.php', "<?php\n return " . var_export($config_array, true) . ";\n");
  135. if (function_exists('opcache_reset')) {
  136. opcache_reset();
  137. }
  138. FreshRSS_Context::initSystem(true);
  139. $ok = false;
  140. try {
  141. if (!is_string($config_array['default_user'])) {
  142. throw new Exception('Invalid default user name');
  143. }
  144. Minz_User::change($config_array['default_user']);
  145. $error = initDb();
  146. Minz_User::change();
  147. if ($error != '') {
  148. Minz_Session::_param('bd_error', $error);
  149. } else {
  150. $ok = true;
  151. }
  152. } catch (Exception $ex) {
  153. Minz_Session::_param('bd_error', $ex->getMessage());
  154. $ok = false;
  155. }
  156. if (!$ok) {
  157. @unlink(join_path(DATA_PATH, 'config.php'));
  158. }
  159. if ($ok) {
  160. Minz_Session::_param('bd_error');
  161. header('Location: index.php?step=3');
  162. } elseif (Minz_Session::paramString('bd_error') == '') {
  163. Minz_Session::_param('bd_error', 'Unknown error!');
  164. }
  165. }
  166. invalidateHttpCache();
  167. }
  168. function saveStep3(): bool {
  169. FreshRSS_Context::initSystem();
  170. Minz_Translate::init(Minz_Session::paramString('language'));
  171. if (!empty($_POST)) {
  172. $auth_type = param('auth_type', 'form');
  173. if (in_array($auth_type, ['form', 'http_auth', 'none'], true)) {
  174. FreshRSS_Context::systemConf()->auth_type = $auth_type;
  175. Minz_Session::_param('auth_type', FreshRSS_Context::systemConf()->auth_type);
  176. } else {
  177. return false;
  178. }
  179. $password_plain = param('passwordPlain', '');
  180. if (FreshRSS_Context::systemConf()->auth_type === 'form' && $password_plain == '') {
  181. return false;
  182. }
  183. if (FreshRSS_user_Controller::checkUsername(param('default_user', ''))) {
  184. FreshRSS_Context::systemConf()->default_user = param('default_user', '');
  185. Minz_Session::_param('default_user', FreshRSS_Context::systemConf()->default_user);
  186. } else {
  187. return false;
  188. }
  189. if (FreshRSS_Context::systemConf()->auth_type === 'http_auth' &&
  190. connectionRemoteAddress() !== '' &&
  191. empty($_SERVER['REMOTE_USER']) && empty($_SERVER['REDIRECT_REMOTE_USER']) && // No safe authentication HTTP headers
  192. (!empty($_SERVER['HTTP_REMOTE_USER']) || !empty($_SERVER['HTTP_X_WEBAUTH_USER'])) // but has unsafe authentication HTTP headers
  193. ) {
  194. // Trust by default the remote IP address (e.g. last proxy) used during install to provide remote user name via unsafe HTTP header
  195. FreshRSS_Context::systemConf()->trusted_sources[] = connectionRemoteAddress();
  196. FreshRSS_Context::systemConf()->trusted_sources = array_unique(FreshRSS_Context::systemConf()->trusted_sources);
  197. }
  198. // Create default user files but first, we delete previous data to
  199. // avoid access right problems.
  200. recursive_unlink(USERS_PATH . '/' . Minz_Session::paramString('default_user'));
  201. $ok = false;
  202. try {
  203. Minz_ModelPdo::$usesSharedPdo = false;
  204. $databaseDAO = FreshRSS_Factory::createDatabaseDAO(Minz_User::INTERNAL_USER);
  205. if (!$databaseDAO->testTyping()) {
  206. $message = 'Invalid PDO driver behaviour for selected database type!';
  207. if (Minz_Session::paramString('bd_type') === 'mysql') {
  208. $message .= ' MySQL requires mysqlnd.';
  209. }
  210. throw new Exception($message);
  211. }
  212. Minz_ModelPdo::$usesSharedPdo = true;
  213. $ok = FreshRSS_user_Controller::createUser(
  214. Minz_Session::paramString('default_user'),
  215. '', //TODO: Add e-mail
  216. $password_plain,
  217. [
  218. 'language' => Minz_Session::paramString('language'),
  219. 'is_admin' => true,
  220. 'enabled' => true,
  221. ]
  222. );
  223. } catch (Exception $e) {
  224. Minz_Session::_param('bd_error', $e->getMessage());
  225. $ok = false;
  226. }
  227. if (!$ok) {
  228. checkStep();
  229. return false;
  230. }
  231. FreshRSS_Context::systemConf()->save();
  232. header('Location: index.php?step=4');
  233. }
  234. return true;
  235. }
  236. /*** VÉRIFICATIONS ***/
  237. function checkStep(): void {
  238. $s0 = checkStep0();
  239. $s1 = checkRequirements();
  240. $s2 = checkStep2();
  241. $s3 = checkStep3();
  242. if (STEP > 0 && $s0['all'] !== 'ok') {
  243. header('Location: index.php?step=0');
  244. } elseif (STEP > 1 && $s1['all'] !== 'ok') {
  245. header('Location: index.php?step=1');
  246. } elseif (STEP > 2 && $s2['all'] !== 'ok') {
  247. header('Location: index.php?step=2');
  248. } elseif (STEP > 3 && $s3['all'] !== 'ok') {
  249. header('Location: index.php?step=3');
  250. }
  251. Minz_Session::_param('actualize_feeds', true);
  252. }
  253. /** @return array<string,string> */
  254. function checkStep0(): array {
  255. $languages = Minz_Translate::availableLanguages();
  256. $language = Minz_Session::paramString('language') != '' && in_array(Minz_Session::paramString('language'), $languages, true);
  257. $sessionWorking = Minz_Session::paramString('sessionWorking') === 'ok';
  258. return [
  259. 'language' => $language ? 'ok' : 'ko',
  260. 'sessionWorking' => $sessionWorking ? 'ok' : 'ko',
  261. 'all' => $language && $sessionWorking ? 'ok' : 'ko',
  262. ];
  263. }
  264. function freshrss_already_installed(): bool {
  265. $conf_path = join_path(DATA_PATH, 'config.php');
  266. if (!file_exists($conf_path)) {
  267. return false;
  268. }
  269. // A configuration file already exists, we try to load it.
  270. $system_conf = null;
  271. try {
  272. $system_conf = FreshRSS_SystemConfiguration::init($conf_path);
  273. } catch (Minz_FileNotExistException $e) {
  274. return false;
  275. }
  276. // ok, the global conf exists… but what about default user conf?
  277. $current_user = $system_conf->default_user;
  278. try {
  279. FreshRSS_UserConfiguration::init(USERS_PATH . '/' . $current_user . '/config.php');
  280. } catch (Minz_FileNotExistException $e) {
  281. return false;
  282. }
  283. // ok, ok, default user exists too!
  284. return true;
  285. }
  286. /** @return array<string,string> */
  287. function checkStep2(): array {
  288. $conf = is_writable(join_path(DATA_PATH, 'config.php'));
  289. $bd = Minz_Session::paramString('bd_type') != '';
  290. $conn = Minz_Session::paramString('bd_error') == '';
  291. return [
  292. 'bd' => $bd ? 'ok' : 'ko',
  293. 'conn' => $conn ? 'ok' : 'ko',
  294. 'conf' => $conf ? 'ok' : 'ko',
  295. 'all' => $bd && $conn && $conf ? 'ok' : 'ko',
  296. ];
  297. }
  298. /** @return array<string,string> */
  299. function checkStep3(): array {
  300. $conf = Minz_Session::paramString('default_user') != '';
  301. $form = Minz_Session::paramString('auth_type') != '';
  302. $defaultUser = is_string($_POST['default_user'] ?? null) ? trim($_POST['default_user']) : '';
  303. if ($defaultUser === '') {
  304. $defaultUser = Minz_Session::paramString('default_user') == '' ? '' : Minz_Session::paramString('default_user');
  305. }
  306. $data = is_writable(USERS_PATH . '/' . $defaultUser . '/config.php');
  307. return [
  308. 'conf' => $conf ? 'ok' : 'ko',
  309. 'form' => $form ? 'ok' : 'ko',
  310. 'data' => $data ? 'ok' : 'ko',
  311. 'all' => $conf && $form && $data ? 'ok' : 'ko',
  312. ];
  313. }
  314. /* select language */
  315. function printStep0(): void {
  316. $actual = Minz_Translate::language();
  317. $languages = Minz_Translate::availableLanguages();
  318. $s0 = checkStep0();
  319. ?>
  320. <?php if ($s0['all'] === 'ok') { ?>
  321. <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.language.defined') ?></p>
  322. <?php } elseif (!empty($_POST) && $s0['sessionWorking'] !== 'ok') { ?>
  323. <p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= _t('install.session.nok') ?></p>
  324. <?php } ?>
  325. <div class="form-group">
  326. <label class="group-name"><?= _t('index.about') ?></label>
  327. <div class="group-controls">
  328. <?= _t('index.about.freshrss_description') ?>
  329. </div>
  330. </div>
  331. <div class="form-group">
  332. <label class="group-name"><?= _t('index.about.project_website') ?></label>
  333. <div class="group-controls">
  334. <a href="<?= FRESHRSS_WEBSITE ?>" target="_blank"><?= FRESHRSS_WEBSITE ?></a>
  335. </div>
  336. </div>
  337. <div class="form-group">
  338. <label class="group-name"><?= _t('index.about.documentation') ?></label>
  339. <div class="group-controls">
  340. <a href="<?= FRESHRSS_WIKI ?>" target="_blank"><?= FRESHRSS_WIKI ?></a>
  341. </div>
  342. </div>
  343. <div class="form-group">
  344. <label class="group-name"><?= _t('index.about.version') ?></label>
  345. <div class="group-controls">
  346. <?= FRESHRSS_VERSION ?>
  347. </div>
  348. </div>
  349. <h2><?= _t('install.language.choose') ?></h2>
  350. <form action="index.php?step=0" method="post">
  351. <div class="form-group">
  352. <label class="group-name" for="language"><?= _t('install.language') ?></label>
  353. <div class="group-controls">
  354. <select name="language" id="language" tabindex="1" >
  355. <?php foreach ($languages as $lang) { ?>
  356. <option value="<?= $lang ?>"<?= $actual == $lang ? ' selected="selected"' : '' ?>>
  357. <?= _t('gen.lang.' . $lang) ?>
  358. </option>
  359. <?php } ?>
  360. </select>
  361. </div>
  362. </div>
  363. <div class="form-group form-actions">
  364. <div class="group-controls">
  365. <button type="submit" class="btn btn-important" tabindex="2" ><?= _t('gen.action.submit') ?></button>
  366. <?php if ($s0['all'] == 'ok') { ?>
  367. <a class="next-step" href="?step=1" tabindex="4" ><?= _t('install.action.next_step') ?></a>
  368. <?php } ?>
  369. </div>
  370. </div>
  371. </form>
  372. <?php
  373. }
  374. /**
  375. * Alert box template
  376. * @param array<string> $messageParams
  377. * */
  378. function printStep1Template(string $key, string $value, array $messageParams = []): void {
  379. if ('ok' === $value) {
  380. $message = _t("install.check.{$key}.ok", ...$messageParams);
  381. ?><p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= $message ?></p><?php
  382. } else {
  383. $message = _t("install.check.{$key}.nok", ...$messageParams);
  384. ?><p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= $message ?></p><?php
  385. }
  386. }
  387. function getProcessUsername(): string {
  388. if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
  389. $processUser = posix_getpwuid(posix_geteuid()) ?: [];
  390. if (!empty($processUser['name'])) {
  391. return $processUser['name'];
  392. }
  393. }
  394. if (function_exists('exec')) {
  395. exec('whoami', $output);
  396. if (!empty($output[0])) {
  397. return $output[0];
  398. }
  399. }
  400. return _t('install.check.unknown_process_username');
  401. }
  402. // @todo refactor this view with the check_install action
  403. /* check system environment */
  404. function printStep1(): void {
  405. $res = checkRequirements();
  406. ?>
  407. <h2><?= _t('admin.check_install.php') ?></h2>
  408. <noscript><p class="alert alert-warn"><span class="alert-head"><?= _t('gen.short.attention') ?></span> <?= _t('install.javascript_is_better') ?></p></noscript>
  409. <?php
  410. printStep1Template('php', $res['php'], [PHP_VERSION, FRESHRSS_MIN_PHP_VERSION]);
  411. printStep1Template('pdo', $res['pdo']);
  412. $curlVersion = function_exists('curl_version') ? curl_version() : [];
  413. $curlVersion = is_string($curlVersion['version'] ?? null) ? $curlVersion['version'] : '';
  414. printStep1Template('curl', $res['curl'], [$curlVersion]); // TODO: We actually require cURL >= 7.52 for CURLPROXY_HTTPS
  415. printStep1Template('json', $res['json']);
  416. printStep1Template('pcre', $res['pcre']);
  417. printStep1Template('ctype', $res['ctype']);
  418. printStep1Template('dom', $res['dom']);
  419. printStep1Template('xml', $res['xml']);
  420. printStep1Template('mbstring', $res['mbstring']);
  421. printStep1Template('fileinfo', $res['fileinfo']);
  422. ?>
  423. <h2><?= _t('admin.check_install.files') ?></h2>
  424. <?php
  425. $processUsername = getProcessUsername();
  426. printStep1Template('data', $res['data'], [DATA_PATH, $processUsername]);
  427. printStep1Template('cache', $res['cache'], [CACHE_PATH, $processUsername]);
  428. printStep1Template('tmp', $res['tmp'], [TMP_PATH, $processUsername]);
  429. printStep1Template('users', $res['users'], [USERS_PATH, $processUsername]);
  430. printStep1Template('favicons', $res['favicons'], [DATA_PATH . '/favicons', $processUsername]);
  431. ?>
  432. <?php if (freshrss_already_installed() && $res['all'] == 'ok') { ?>
  433. <p class="alert alert-warn"><span class="alert-head"><?= _t('gen.short.attention') ?></span> <?= _t('install.check.already_installed') ?></p>
  434. <div class="form-group form-actions">
  435. <div class="group-controls">
  436. <form action="index.php?step=1" method="post">
  437. <input type="hidden" name="freshrss-keep-install" value="1" />
  438. <button type="submit" class="btn btn-important" tabindex="1"><?= _t('install.action.keep_install') ?></button>
  439. <a class="btn btn-attention confirm" data-str-confirm="<?= _t('install.js.confirm_reinstall') ?>"
  440. href="?step=2" tabindex="2"><?= _t('install.action.reinstall') ?></a>
  441. </form>
  442. </div>
  443. </div>
  444. <?php } elseif ($res['all'] == 'ok') { ?>
  445. <div class="form-group form-actions">
  446. <div class="group-controls">
  447. <a class="btn btn-important" href="?step=2" tabindex="1"><?= _t('install.action.next_step') ?></a>
  448. </div>
  449. </div>
  450. <?php } else { ?>
  451. <p class="alert alert-error"><?= _t('install.action.fix_errors_before') ?></p>
  452. <div class="form-group form-actions">
  453. <div class="group-controls">
  454. <a id="actualize" class="btn" href="./index.php?step=1" title="<?= _t('install.check.reload') ?>" tabindex="1">
  455. <img class="icon" src="../themes/icons/refresh.svg" alt="🔃" loading="lazy" />
  456. </a>
  457. </div>
  458. </div>
  459. <?php } ?>
  460. <?php
  461. }
  462. /**
  463. * Select database & configuration
  464. * @throws Minz_ConfigurationNamespaceException
  465. */
  466. function printStep2(): void {
  467. $system_default_config = FreshRSS_SystemConfiguration::get('default_system');
  468. $s2 = checkStep2();
  469. if ($s2['all'] == 'ok') { ?>
  470. <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.bdd.conf.ok') ?></p>
  471. <?php } elseif ($s2['conn'] == 'ko') { ?>
  472. <p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= _t('install.bdd.conf.ko'),
  473. (empty($_SESSION['bd_error']) || !is_string($_SESSION['bd_error']) ? '' : ' ' . $_SESSION['bd_error']) ?></p>
  474. <?php } ?>
  475. <h2><?= _t('install.bdd.conf') ?></h2>
  476. <form action="index.php?step=2" method="post" autocomplete="off">
  477. <div class="form-group">
  478. <label class="group-name" for="type"><?= _t('install.bdd.type') ?></label>
  479. <div class="group-controls">
  480. <select name="type" id="type" tabindex="1">
  481. <?php if (extension_loaded('pdo_sqlite')) {?>
  482. <option value="sqlite"
  483. <?= ($_SESSION['bd_type'] ?? null) === 'sqlite' ? 'selected="selected"' : '' ?>>
  484. SQLite
  485. </option>
  486. <?php }?>
  487. <?php if (extension_loaded('pdo_mysql')) {?>
  488. <option value="mysql"
  489. <?= ($_SESSION['bd_type'] ?? null) === 'mysql' ? 'selected="selected"' : '' ?>>
  490. MySQL / MariaDB
  491. </option>
  492. <?php }?>
  493. <?php if (extension_loaded('pdo_pgsql')) {?>
  494. <option value="pgsql"
  495. <?= ($_SESSION['bd_type'] ?? null) === 'pgsql' ? 'selected="selected"' : '' ?>>
  496. PostgreSQL
  497. </option>
  498. <?php }?>
  499. </select>
  500. </div>
  501. </div>
  502. <div id="mysql">
  503. <?php
  504. $bd_base = is_string($_SESSION['bd_base'] ?? null) ? $_SESSION['bd_base'] : null;
  505. $bd_host = is_string($_SESSION['bd_host'] ?? null) ? $_SESSION['bd_host'] : null;
  506. $bd_password = is_string($_SESSION['bd_password'] ?? null) ? $_SESSION['bd_password'] : null;
  507. $bd_prefix = is_string($_SESSION['bd_prefix'] ?? null) ? $_SESSION['bd_prefix'] : null;
  508. $bd_user = is_string($_SESSION['bd_user'] ?? null) ? $_SESSION['bd_user'] : null;
  509. ?>
  510. <div class="form-group">
  511. <label class="group-name" for="host"><?= _t('install.bdd.host') ?></label>
  512. <div class="group-controls">
  513. <input type="text" id="host" name="host" pattern="[0-9A-Z\/a-z_.\-]{1,64}(:[0-9]{2,5})?" value="<?=
  514. $bd_host ?? $system_default_config->db['host'] ?? '' ?>" tabindex="2" />
  515. </div>
  516. </div>
  517. <div class="form-group">
  518. <label class="group-name" for="user"><?= _t('install.bdd.username') ?></label>
  519. <div class="group-controls">
  520. <input type="text" id="user" name="user" maxlength="64" pattern="[0-9A-Za-z@_.\-]{1,64}" value="<?=
  521. $bd_user ?? '' ?>" tabindex="3" />
  522. </div>
  523. </div>
  524. <div class="form-group">
  525. <label class="group-name" for="pass"><?= _t('install.bdd.password') ?></label>
  526. <div class="group-controls">
  527. <div class="stick">
  528. <input type="password" id="pass" name="pass" value="<?=
  529. $bd_password ?? '' ?>" tabindex="4" autocomplete="off" />
  530. <a class="btn toggle-password" data-toggle="pass" tabindex="5"><?= FreshRSS_Themes::icon('key') ?></a>
  531. </div>
  532. </div>
  533. </div>
  534. <div class="form-group">
  535. <label class="group-name" for="base"><?= _t('install.bdd') ?></label>
  536. <div class="group-controls">
  537. <input type="text" id="base" name="base" maxlength="64" pattern="[0-9A-Za-z_\-]{1,64}" value="<?=
  538. $bd_base ?? '' ?>" tabindex="6" />
  539. </div>
  540. </div>
  541. <div class="form-group">
  542. <label class="group-name" for="prefix"><?= _t('install.bdd.prefix') ?></label>
  543. <div class="group-controls">
  544. <input type="text" id="prefix" name="prefix" maxlength="16" pattern="[0-9A-Za-z_]{1,16}" value="<?=
  545. $bd_prefix ?? $system_default_config->db['prefix'] ?? '' ?>" tabindex="7" />
  546. </div>
  547. </div>
  548. </div>
  549. <div class="form-group form-actions">
  550. <div class="group-controls">
  551. <button type="submit" class="btn btn-important" tabindex="8" ><?= _t('gen.action.submit') ?></button>
  552. <button type="reset" class="btn" tabindex="9" ><?= _t('gen.action.cancel') ?></button>
  553. <?php if ($s2['all'] == 'ok') { ?>
  554. <a class="next-step" href="?step=3" tabindex="10" ><?= _t('install.action.next_step') ?></a>
  555. <?php } ?>
  556. </div>
  557. </div>
  558. </form>
  559. <?php
  560. }
  561. function no_auth(string $auth_type): bool {
  562. return !in_array($auth_type, ['form', 'http_auth', 'none'], true);
  563. }
  564. /* Create default user */
  565. function printStep3(): void {
  566. $auth_type = is_string($_SESSION['auth_type'] ?? null) ? $_SESSION['auth_type'] : '';
  567. $default_user = is_string($_SESSION['default_user'] ?? null) ? $_SESSION['default_user'] : '';
  568. $s3 = checkStep3();
  569. if ($s3['all'] == 'ok') { ?>
  570. <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.conf.ok') ?></p>
  571. <?php } elseif (!empty($_POST)) { ?>
  572. <p class="alert alert-error"><?= _t('install.fix_errors_before') ?></p>
  573. <?php } ?>
  574. <h2><?= _t('install.conf') ?></h2>
  575. <form action="index.php?step=3" method="post">
  576. <div class="form-group">
  577. <label class="group-name" for="default_user"><?= _t('install.default_user') ?></label>
  578. <div class="group-controls">
  579. <input type="text" id="default_user" name="default_user" autocomplete="username" required="required" size="16"
  580. pattern="<?= FreshRSS_user_Controller::USERNAME_PATTERN ?>" value="<?= $default_user ?>"
  581. placeholder="<?= httpAuthUser(false) == '' ? 'alice' : httpAuthUser(false) ?>" tabindex="1" />
  582. <p class="help"><?= _i('help') ?> <?= _t('install.default_user.max_char') ?></p>
  583. </div>
  584. </div>
  585. <div class="form-group">
  586. <label class="group-name" for="auth_type"><?= _t('admin.auth.type') ?></label>
  587. <div class="group-controls">
  588. <select id="auth_type" name="auth_type" required="required" tabindex="2">
  589. <option value="form"<?= $auth_type === 'form' || (no_auth($auth_type) && cryptAvailable()) ? ' selected="selected"' : '',
  590. cryptAvailable() ? '' : ' disabled="disabled"' ?>><?= _t('admin.auth.form') ?></option>
  591. <option value="http_auth"<?= $auth_type === 'http_auth' ? ' selected="selected"' : '',
  592. httpAuthUser(false) == '' ? ' disabled="disabled"' : '' ?>>
  593. <?= _t('admin.auth.http') ?> (REMOTE_USER = '<?= httpAuthUser(false) ?>')</option>
  594. <option value="none"<?= $auth_type === 'none' || (no_auth($auth_type) && !cryptAvailable()) ? ' selected="selected"' : ''
  595. ?>><?= _t('admin.auth.none') ?></option>
  596. </select>
  597. </div>
  598. </div>
  599. <div class="form-group">
  600. <label class="group-name" for="passwordPlain"><?= _t('admin.user.password_form') ?></label>
  601. <div class="group-controls">
  602. <div class="stick">
  603. <input type="password" id="passwordPlain" name="passwordPlain" pattern=".{7,}"
  604. autocomplete="off" <?= $auth_type === 'form' ? ' required="required"' : '' ?> tabindex="3" />
  605. <button type="button" class="btn toggle-password" data-toggle="passwordPlain" tabindex="4"><?= FreshRSS_Themes::icon('key') ?></button>
  606. </div>
  607. <p class="help"><?= _i('help') ?> <?= _t('admin.user.password_format') ?></p>
  608. <noscript><b><?= _t('gen.js.should_be_activated') ?></b></noscript>
  609. </div>
  610. </div>
  611. <div class="form-group form-actions">
  612. <div class="group-controls">
  613. <button type="submit" class="btn btn-important" tabindex="5" ><?= _t('gen.action.submit') ?></button>
  614. <button type="reset" class="btn" tabindex="6" ><?= _t('gen.action.cancel') ?></button>
  615. <?php if ($s3['all'] == 'ok') { ?>
  616. <a class="next-step" href="?step=4" tabindex="7" ><?= _t('install.action.next_step') ?></a>
  617. <?php } ?>
  618. </div>
  619. </div>
  620. </form>
  621. <?php
  622. }
  623. /* congrats. Installation successful completed */
  624. function printStep4(): void {
  625. ?>
  626. <p class="alert alert-success"><span class="alert-head"><?= _t('install.congratulations') ?></span> <?= _t('install.ok') ?></p>
  627. <div class="form-group form-actions">
  628. <div class="group-controls">
  629. <a class="btn btn-important" href="?step=5" tabindex="1"><?= _t('install.action.finish') ?></a>
  630. </div>
  631. </div>
  632. <?php
  633. }
  634. /* failed */
  635. function printStep5(): void {
  636. ?>
  637. <p class="alert alert-error">
  638. <span class="alert-head"><?= _t('gen.short.damn') ?></span>
  639. <?= _t('install.missing_applied_migrations', DATA_PATH . '/applied_migrations.txt') ?>
  640. </p>
  641. <?php
  642. }
  643. initTranslate();
  644. checkStep();
  645. switch (STEP) {
  646. case 0:
  647. default:
  648. saveLanguage();
  649. break;
  650. case 1:
  651. saveStep1();
  652. break;
  653. case 2:
  654. saveStep2();
  655. break;
  656. case 3:
  657. saveStep3();
  658. break;
  659. case 4:
  660. break;
  661. case 5:
  662. if (setupMigrations()) {
  663. header('Location: index.php');
  664. }
  665. break;
  666. }
  667. ?>
  668. <!DOCTYPE html>
  669. <html <?php
  670. if (_t('gen.dir') === 'rtl') {
  671. echo ' dir="rtl" class="rtl"';
  672. }
  673. ?>>
  674. <head>
  675. <meta charset="UTF-8" />
  676. <meta name="viewport" content="initial-scale=1.0" />
  677. <script id="jsonVars" type="application/json">{}</script>
  678. <title><?= _t('install.title') ?>: <?= _t('install.step', STEP + 1) ?></title>
  679. <link rel="stylesheet" href="../themes/base-theme/frss.css?<?= @filemtime(PUBLIC_PATH . '/themes/base-theme/frss.css') ?>" />
  680. <link rel="stylesheet" href="../themes/Origine/origine.css?<?= @filemtime(PUBLIC_PATH . '/themes/Origine/origine.css') ?>" />
  681. <link rel="shortcut icon" id="favicon" type="image/x-icon" sizes="16x16 64x64" href="../favicon.ico" />
  682. <link rel="icon msapplication-TileImage apple-touch-icon" type="image/png" sizes="256x256" href="../themes/icons/favicon-256.png" />
  683. <link rel="apple-touch-icon" href="../themes/icons/apple-touch-icon.png" />
  684. <meta name="apple-mobile-web-app-capable" content="yes" />
  685. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  686. <meta name="apple-mobile-web-app-title" content="FreshRSS">
  687. <meta name="robots" content="noindex,nofollow" />
  688. </head>
  689. <body>
  690. <header class="header">
  691. <div class="item title">
  692. <div id="logo-wrapper">
  693. <a href="./">
  694. <img class="logo" src="../themes/icons/FreshRSS-logo.svg" alt="" loading="lazy">
  695. </a>
  696. </div>
  697. </div>
  698. <div class="item"></div>
  699. <div class="item configure">
  700. <a class="btn only-mobile" href="#aside"><?= _i('view-normal') ?></a>
  701. </div>
  702. </header>
  703. <div id="global">
  704. <nav class="nav nav-list aside" id="aside">
  705. <a class="toggle_aside" href="#close"><img class="icon" src="../themes/icons/close.svg" loading="lazy" alt="❌"></a>
  706. <ul>
  707. <li class="item nav-section">
  708. <div class="nav-header"><?= _t('install.steps') ?></div>
  709. <ol>
  710. <li class="item<?= STEP == 0 ? ' active' : '' ?>">
  711. <a href="?step=0" title="<?= _t('install.step', 0) ?>: <?= _t('install.language') ?>"><?= _t('install.language') ?></a>
  712. </li>
  713. <li class="item<?= STEP == 1 ? ' active' : '' ?>">
  714. <?php if (STEP > 0) {?>
  715. <a href="?step=1" title="<?= _t('install.step', 1) ?>: <?= _t('install.check') ?>"><?= _t('install.check') ?></a>
  716. <?php } else { ?>
  717. <span><?= _t('install.check') ?></span>
  718. <?php } ?>
  719. </li>
  720. <li class="item<?= STEP == 2 ? ' active' : '' ?>">
  721. <?php if (STEP > 1) {?>
  722. <a href="?step=2" title="<?= _t('install.step', 2) ?>: <?= _t('install.bdd.conf') ?>"><?= _t('install.bdd.conf') ?></a>
  723. <?php } else { ?>
  724. <span><?= _t('install.bdd.conf') ?></span>
  725. <?php } ?>
  726. </li>
  727. <li class="item<?= STEP == 3 ? ' active' : '' ?>">
  728. <?php if (STEP > 2) {?>
  729. <a href="?step=3" title="<?= _t('install.step', 3) ?>: <?= _t('install.conf') ?>"><?= _t('install.conf') ?></a>
  730. <?php } else { ?>
  731. <span><?= _t('install.conf') ?></span>
  732. <?php } ?>
  733. </li>
  734. <li class="item<?= STEP == 4 ? ' active' : '' ?>">
  735. <?php if (STEP > 3) {?>
  736. <a href="?step=4" title="<?= _t('install.step', 4) ?>: <?= _t('install.this_is_the_end') ?>"><?= _t('install.this_is_the_end') ?></a>
  737. <?php } else { ?>
  738. <span><?= _t('install.this_is_the_end') ?></span>
  739. <?php } ?>
  740. </li>
  741. </ol>
  742. </li>
  743. </ul>
  744. </nav>
  745. <a class="close-aside" href="#close">❌</a>
  746. <main class="post">
  747. <h1><?= _t('install.title') ?>: <?= _t('install.step', STEP + 1) ?></h1>
  748. <?php
  749. switch (STEP) {
  750. case 0:
  751. default:
  752. printStep0();
  753. break;
  754. case 1:
  755. printStep1();
  756. break;
  757. case 2:
  758. printStep2();
  759. break;
  760. case 3:
  761. printStep3();
  762. break;
  763. case 4:
  764. printStep4();
  765. break;
  766. case 5:
  767. printStep5();
  768. break;
  769. }
  770. ?>
  771. </main>
  772. </div>
  773. <script src="../scripts/install.js?<?= @filemtime(PUBLIC_PATH . '/scripts/install.js') ?>"></script>
  774. </body>
  775. </html>