install.php 31 KB

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