install.php 28 KB

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