install.php 29 KB

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