install.php 30 KB

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