install.php 28 KB

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