install.php 26 KB

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