install.php 26 KB

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