install.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. @unlink(DATA_PATH . '/config.php'); //To avoid access-rights problems
  128. file_put_contents(DATA_PATH . '/config.php', "<?php\n return " . var_export($config_array, true) . ";\n");
  129. if (function_exists('opcache_reset')) {
  130. opcache_reset();
  131. }
  132. FreshRSS_Context::initSystem(true);
  133. $ok = false;
  134. try {
  135. Minz_Session::_param('currentUser', $config_array['default_user']);
  136. $error = initDb();
  137. Minz_Session::_param('currentUser');
  138. if ($error != '') {
  139. Minz_Session::_param('bd_error', $error);
  140. } else {
  141. $ok = true;
  142. }
  143. } catch (Exception $ex) {
  144. Minz_Session::_param('bd_error', $ex->getMessage());
  145. $ok = false;
  146. }
  147. if (!$ok) {
  148. @unlink(join_path(DATA_PATH, 'config.php'));
  149. }
  150. if ($ok) {
  151. Minz_Session::_param('bd_error');
  152. header('Location: index.php?step=3');
  153. } elseif (Minz_Session::param('bd_error') == '') {
  154. Minz_Session::_param('bd_error', 'Unknown error!');
  155. }
  156. }
  157. invalidateHttpCache();
  158. }
  159. function saveStep3() {
  160. $user_default_config = Minz_Configuration::get('default_user');
  161. if (!empty($_POST)) {
  162. $system_default_config = Minz_Configuration::get('default_system');
  163. Minz_Session::_params([
  164. 'title' => $system_default_config->title,
  165. 'auth_type' => param('auth_type', 'form'),
  166. ]);
  167. if (FreshRSS_user_Controller::checkUsername(param('default_user', ''))) {
  168. Minz_Session::_param('default_user', param('default_user', ''));
  169. }
  170. if (Minz_Session::param('auth_type') == '' || Minz_Session::param('default_user') == '') {
  171. return false;
  172. }
  173. $password_plain = param('passwordPlain', false);
  174. if (Minz_Session::param('auth_type') === 'form' && $password_plain == '') {
  175. return false;
  176. }
  177. FreshRSS_Context::initSystem();
  178. Minz_Translate::init(Minz_Session::param('language'));
  179. // Create default user files but first, we delete previous data to
  180. // avoid access right problems.
  181. recursive_unlink(USERS_PATH . '/' . Minz_Session::param('default_user'));
  182. $ok = false;
  183. try {
  184. $ok = FreshRSS_user_Controller::createUser(
  185. Minz_Session::param('default_user'),
  186. '', //TODO: Add e-mail
  187. $password_plain,
  188. [
  189. 'language' => Minz_Session::param('language'),
  190. 'is_admin' => true,
  191. 'enabled' => true,
  192. ]
  193. );
  194. } catch (Exception $e) {
  195. Minz_Session::_param('bd_error', $e->getMessage());
  196. $ok = false;
  197. }
  198. if (!$ok) {
  199. return false;
  200. }
  201. FreshRSS_Context::$system_conf->default_user = Minz_Session::param('default_user');
  202. FreshRSS_Context::$system_conf->save();
  203. header('Location: index.php?step=4');
  204. }
  205. }
  206. /*** VÉRIFICATIONS ***/
  207. function checkStep() {
  208. $s0 = checkStep0();
  209. $s1 = checkRequirements();
  210. $s2 = checkStep2();
  211. $s3 = checkStep3();
  212. if (STEP > 0 && $s0['all'] !== 'ok') {
  213. header('Location: index.php?step=0');
  214. } elseif (STEP > 1 && $s1['all'] !== 'ok') {
  215. header('Location: index.php?step=1');
  216. } elseif (STEP > 2 && $s2['all'] !== 'ok') {
  217. header('Location: index.php?step=2');
  218. } elseif (STEP > 3 && $s3['all'] !== 'ok') {
  219. header('Location: index.php?step=3');
  220. }
  221. Minz_Session::_param('actualize_feeds', true);
  222. }
  223. function checkStep0() {
  224. $languages = Minz_Translate::availableLanguages();
  225. $language = Minz_Session::param('language') != '' && in_array(Minz_Session::param('language'), $languages);
  226. $sessionWorking = Minz_Session::param('sessionWorking') === 'ok';
  227. return array(
  228. 'language' => $language ? 'ok' : 'ko',
  229. 'sessionWorking' => $sessionWorking ? 'ok' : 'ko',
  230. 'all' => $language && $sessionWorking ? 'ok' : 'ko'
  231. );
  232. }
  233. function freshrss_already_installed() {
  234. $conf_path = join_path(DATA_PATH, 'config.php');
  235. if (!file_exists($conf_path)) {
  236. return false;
  237. }
  238. // A configuration file already exists, we try to load it.
  239. $system_conf = null;
  240. try {
  241. Minz_Configuration::register('system', $conf_path);
  242. $system_conf = Minz_Configuration::get('system');
  243. } catch (Minz_FileNotExistException $e) {
  244. return false;
  245. }
  246. // ok, the global conf exists... but what about default user conf?
  247. $current_user = $system_conf->default_user;
  248. try {
  249. Minz_Configuration::register('user', join_path(USERS_PATH, $current_user, 'config.php'));
  250. } catch (Minz_FileNotExistException $e) {
  251. return false;
  252. }
  253. // ok, ok, default user exists too!
  254. return true;
  255. }
  256. function checkStep2() {
  257. $conf = is_writable(join_path(DATA_PATH, 'config.php'));
  258. $bd = Minz_Session::param('bd_type') != '';
  259. $conn = Minz_Session::param('bd_error') == '';
  260. return [
  261. 'bd' => $bd ? 'ok' : 'ko',
  262. 'conn' => $conn ? 'ok' : 'ko',
  263. 'conf' => $conf ? 'ok' : 'ko',
  264. 'all' => $bd && $conn && $conf ? 'ok' : 'ko',
  265. ];
  266. }
  267. function checkStep3() {
  268. $conf = Minz_Session::param('default_user') != '';
  269. $form = Minz_Session::param('auth_type') != '';
  270. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  271. if ($defaultUser === null) {
  272. $defaultUser = Minz_Session::param('default_user') == '' ? '' : Minz_Session::param('default_user');
  273. }
  274. $data = is_writable(join_path(USERS_PATH, $defaultUser, 'config.php'));
  275. return [
  276. 'conf' => $conf ? 'ok' : 'ko',
  277. 'form' => $form ? 'ok' : 'ko',
  278. 'data' => $data ? 'ok' : 'ko',
  279. 'all' => $conf && $form && $data ? 'ok' : 'ko',
  280. ];
  281. }
  282. /*** AFFICHAGE ***/
  283. function printStep0() {
  284. $actual = Minz_Translate::language();
  285. $languages = Minz_Translate::availableLanguages();
  286. $s0 = checkStep0();
  287. ?>
  288. <?php if ($s0['all'] === 'ok') { ?>
  289. <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.language.defined') ?></p>
  290. <?php } elseif (!empty($_POST) && $s0['sessionWorking'] !== 'ok') { ?>
  291. <p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= _t('install.session.nok') ?></p>
  292. <?php } ?>
  293. <form action="index.php?step=0" method="post">
  294. <legend><?= _t('install.language.choose') ?></legend>
  295. <div class="form-group">
  296. <label class="group-name" for="language"><?= _t('install.language') ?></label>
  297. <div class="group-controls">
  298. <select name="language" id="language" tabindex="1" >
  299. <?php foreach ($languages as $lang) { ?>
  300. <option value="<?= $lang ?>"<?= $actual == $lang ? ' selected="selected"' : '' ?>>
  301. <?= _t('gen.lang.' . $lang) ?>
  302. </option>
  303. <?php } ?>
  304. </select>
  305. </div>
  306. </div>
  307. <div class="form-group form-actions">
  308. <div class="group-controls">
  309. <button type="submit" class="btn btn-important" tabindex="2" ><?= _t('gen.action.submit') ?></button>
  310. <button type="reset" class="btn" tabindex="3" ><?= _t('gen.action.cancel') ?></button>
  311. <?php if ($s0['all'] == 'ok') { ?>
  312. <a class="btn btn-important next-step" href="?step=1" tabindex="4" ><?= _t('install.action.next_step') ?></a>
  313. <?php } ?>
  314. </div>
  315. </div>
  316. </form>
  317. <?php
  318. }
  319. function printStep1Template($key, $value, $messageParams = []) {
  320. if ('ok' === $value) {
  321. $message = _t("install.check.{$key}.ok", ...$messageParams);
  322. ?><p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= $message ?></p><?php
  323. } else {
  324. $message = _t("install.check.{$key}.nok", ...$messageParams);
  325. ?><p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= $message ?></p><?php
  326. }
  327. }
  328. function getProcessUsername() {
  329. if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
  330. $processUser = posix_getpwuid(posix_geteuid());
  331. return $processUser['name'];
  332. }
  333. if (function_exists('exec')) {
  334. exec('whoami', $output);
  335. if (!empty($output[0])) {
  336. return $output[0];
  337. }
  338. }
  339. return _t('install.check.unknown_process_username');
  340. }
  341. // @todo refactor this view with the check_install action
  342. function printStep1() {
  343. $res = checkRequirements();
  344. $processUsername = getProcessUsername();
  345. ?>
  346. <noscript><p class="alert alert-warn"><span class="alert-head"><?= _t('gen.short.attention') ?></span> <?= _t('install.javascript_is_better') ?></p></noscript>
  347. <?php
  348. if (function_exists('curl_version')) {
  349. $version = curl_version();
  350. } else {
  351. $version['version'] = '';
  352. }
  353. printStep1Template('php', $res['php'], [PHP_VERSION, FRESHRSS_MIN_PHP_VERSION]);
  354. printStep1Template('pdo', $res['pdo']);
  355. printStep1Template('curl', $res['curl'], [$version['version']]);
  356. printStep1Template('json', $res['json']);
  357. printStep1Template('pcre', $res['pcre']);
  358. printStep1Template('ctype', $res['ctype']);
  359. printStep1Template('dom', $res['dom']);
  360. printStep1Template('xml', $res['xml']);
  361. printStep1Template('mbstring', $res['mbstring']);
  362. printStep1Template('fileinfo', $res['fileinfo']);
  363. printStep1Template('data', $res['data'], [DATA_PATH, $processUsername]);
  364. printStep1Template('cache', $res['cache'], [CACHE_PATH, $processUsername]);
  365. printStep1Template('tmp', $res['tmp'], [TMP_PATH, $processUsername]);
  366. printStep1Template('users', $res['users'], [USERS_PATH, $processUsername]);
  367. printStep1Template('favicons', $res['favicons'], [DATA_PATH . '/favicons', $processUsername]);
  368. ?>
  369. <?php if (freshrss_already_installed() && $res['all'] == 'ok') { ?>
  370. <p class="alert alert-warn"><span class="alert-head"><?= _t('gen.short.attention') ?></span> <?= _t('install.check.already_installed') ?></p>
  371. <form action="index.php?step=1" method="post">
  372. <input type="hidden" name="freshrss-keep-install" value="1" />
  373. <button type="submit" class="btn btn-important next-step" tabindex="1" ><?= _t('install.action.keep_install') ?></button>
  374. <a class="btn btn-attention next-step confirm" data-str-confirm="<?= _t('install.js.confirm_reinstall') ?>"
  375. href="?step=2" tabindex="2" ><?= _t('install.action.reinstall') ?></a>
  376. </form>
  377. <?php } elseif ($res['all'] == 'ok') { ?>
  378. <a class="btn btn-important next-step" href="?step=2" tabindex="1" ><?= _t('install.action.next_step') ?></a>
  379. <?php } else { ?>
  380. <p class="alert alert-error"><?= _t('install.action.fix_errors_before') ?></p>
  381. <a id="actualize" class="btn" href="./index.php?step=1" title="<?= _t('install.check.reload') ?>">
  382. <img class="icon" src="../themes/icons/refresh.svg" alt="🔃" />
  383. </a>
  384. <?php } ?>
  385. <?php
  386. }
  387. function printStep2() {
  388. $system_default_config = Minz_Configuration::get('default_system');
  389. ?>
  390. <?php $s2 = checkStep2(); if ($s2['all'] == 'ok') { ?>
  391. <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.bdd.conf.ok') ?></p>
  392. <?php } elseif ($s2['conn'] == 'ko') { ?>
  393. <p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= _t('install.bdd.conf.ko'),
  394. (empty($_SESSION['bd_error']) ? '' : ' : ' . $_SESSION['bd_error']) ?></p>
  395. <?php } ?>
  396. <form action="index.php?step=2" method="post" autocomplete="off">
  397. <legend><?= _t('install.bdd.conf') ?></legend>
  398. <div class="form-group">
  399. <label class="group-name" for="type"><?= _t('install.bdd.type') ?></label>
  400. <div class="group-controls">
  401. <select name="type" id="type" tabindex="1">
  402. <?php if (extension_loaded('pdo_sqlite')) {?>
  403. <option value="sqlite"
  404. <?= isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite' ? 'selected="selected"' : '' ?>>
  405. SQLite
  406. </option>
  407. <?php }?>
  408. <?php if (extension_loaded('pdo_mysql')) {?>
  409. <option value="mysql"
  410. <?= isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql' ? 'selected="selected"' : '' ?>>
  411. MySQL
  412. </option>
  413. <?php }?>
  414. <?php if (extension_loaded('pdo_pgsql')) {?>
  415. <option value="pgsql"
  416. <?= isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'pgsql' ? 'selected="selected"' : '' ?>>
  417. PostgreSQL
  418. </option>
  419. <?php }?>
  420. </select>
  421. </div>
  422. </div>
  423. <div id="mysql">
  424. <div class="form-group">
  425. <label class="group-name" for="host"><?= _t('install.bdd.host') ?></label>
  426. <div class="group-controls">
  427. <input type="text" id="host" name="host" pattern="[0-9A-Z/a-z_.-]{1,64}(:[0-9]{2,5})?" value="<?=
  428. isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : $system_default_config->db['host'] ?>" tabindex="2" />
  429. </div>
  430. </div>
  431. <div class="form-group">
  432. <label class="group-name" for="user"><?= _t('install.bdd.username') ?></label>
  433. <div class="group-controls">
  434. <input type="text" id="user" name="user" maxlength="64" pattern="[0-9A-Za-z@_.-]{1,64}" value="<?=
  435. isset($_SESSION['bd_user']) ? $_SESSION['bd_user'] : '' ?>" tabindex="3" />
  436. </div>
  437. </div>
  438. <div class="form-group">
  439. <label class="group-name" for="pass"><?= _t('install.bdd.password') ?></label>
  440. <div class="group-controls">
  441. <div class="stick">
  442. <input type="password" id="pass" name="pass" value="<?=
  443. isset($_SESSION['bd_password']) ? $_SESSION['bd_password'] : '' ?>" tabindex="4" autocomplete="off" />
  444. <a class="btn toggle-password" data-toggle="pass" tabindex="5"><?= FreshRSS_Themes::icon('key') ?></a>
  445. </div>
  446. </div>
  447. </div>
  448. <div class="form-group">
  449. <label class="group-name" for="base"><?= _t('install.bdd') ?></label>
  450. <div class="group-controls">
  451. <input type="text" id="base" name="base" maxlength="64" pattern="[0-9A-Za-z_-]{1,64}" value="<?=
  452. isset($_SESSION['bd_base']) ? $_SESSION['bd_base'] : '' ?>" tabindex="6" />
  453. </div>
  454. </div>
  455. <div class="form-group">
  456. <label class="group-name" for="prefix"><?= _t('install.bdd.prefix') ?></label>
  457. <div class="group-controls">
  458. <input type="text" id="prefix" name="prefix" maxlength="16" pattern="[0-9A-Za-z_]{1,16}" value="<?=
  459. isset($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : $system_default_config->db['prefix'] ?>" tabindex="7" />
  460. </div>
  461. </div>
  462. </div>
  463. <div class="form-group form-actions">
  464. <div class="group-controls">
  465. <button type="submit" class="btn btn-important" tabindex="8" ><?= _t('gen.action.submit') ?></button>
  466. <button type="reset" class="btn" tabindex="9" ><?= _t('gen.action.cancel') ?></button>
  467. <?php if ($s2['all'] == 'ok') { ?>
  468. <a class="btn btn-important next-step" href="?step=3" tabindex="10" ><?= _t('install.action.next_step') ?></a>
  469. <?php } ?>
  470. </div>
  471. </div>
  472. </form>
  473. <?php
  474. }
  475. function printStep3() {
  476. $user_default_config = Minz_Configuration::get('default_user');
  477. ?>
  478. <?php $s3 = checkStep3(); if ($s3['all'] == 'ok') { ?>
  479. <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.conf.ok') ?></p>
  480. <?php } elseif (!empty($_POST)) { ?>
  481. <p class="alert alert-error"><?= _t('install.fix_errors_before') ?></p>
  482. <?php } ?>
  483. <form action="index.php?step=3" method="post">
  484. <legend><?= _t('install.conf') ?></legend>
  485. <div class="form-group">
  486. <label class="group-name" for="default_user"><?= _t('install.default_user') ?></label>
  487. <div class="group-controls">
  488. <input type="text" id="default_user" name="default_user" autocomplete="username" required="required" size="16"
  489. pattern="<?= FreshRSS_user_Controller::USERNAME_PATTERN ?>" value="<?= isset($_SESSION['default_user']) ? $_SESSION['default_user'] : '' ?>"
  490. placeholder="<?= httpAuthUser() == '' ? 'alice' : httpAuthUser() ?>" tabindex="3" />
  491. </div>
  492. </div>
  493. <div class="form-group">
  494. <label class="group-name" for="auth_type"><?= _t('install.auth.type') ?></label>
  495. <div class="group-controls">
  496. <select id="auth_type" name="auth_type" required="required" tabindex="4">
  497. <?php
  498. function no_auth($auth_type) {
  499. return !in_array($auth_type, array('form', 'http_auth', 'none'));
  500. }
  501. $auth_type = isset($_SESSION['auth_type']) ? $_SESSION['auth_type'] : '';
  502. ?>
  503. <option value="form"<?= $auth_type === 'form' || (no_auth($auth_type) && cryptAvailable()) ? ' selected="selected"' : '',
  504. cryptAvailable() ? '' : ' disabled="disabled"' ?>><?= _t('install.auth.form') ?></option>
  505. <option value="http_auth"<?= $auth_type === 'http_auth' ? ' selected="selected"' : '',
  506. httpAuthUser() == '' ? ' disabled="disabled"' : '' ?>><?= _t('install.auth.http') ?>(REMOTE_USER = '<?= httpAuthUser() ?>')</option>
  507. <option value="none"<?= $auth_type === 'none' || (no_auth($auth_type) && !cryptAvailable()) ? ' selected="selected"' : ''
  508. ?>><?= _t('install.auth.none') ?></option>
  509. </select>
  510. </div>
  511. </div>
  512. <div class="form-group">
  513. <label class="group-name" for="passwordPlain"><?= _t('install.auth.password_form') ?></label>
  514. <div class="group-controls">
  515. <div class="stick">
  516. <input type="password" id="passwordPlain" name="passwordPlain" pattern=".{7,}"
  517. autocomplete="off" <?= $auth_type === 'form' ? ' required="required"' : '' ?> tabindex="5" />
  518. <button type="button" class="btn toggle-password" data-toggle="passwordPlain"><?= FreshRSS_Themes::icon('key') ?></button>
  519. </div>
  520. <p class="help"><?= _i('help') ?> <?= _t('install.auth.password_format') ?></p>
  521. <noscript><b><?= _t('gen.js.should_be_activated') ?></b></noscript>
  522. </div>
  523. </div>
  524. <div class="form-group form-actions">
  525. <div class="group-controls">
  526. <button type="submit" class="btn btn-important" tabindex="7" ><?= _t('gen.action.submit') ?></button>
  527. <button type="reset" class="btn" tabindex="8" ><?= _t('gen.action.cancel') ?></button>
  528. <?php if ($s3['all'] == 'ok') { ?>
  529. <a class="btn btn-important next-step" href="?step=4" tabindex="9" ><?= _t('install.action.next_step') ?></a>
  530. <?php } ?>
  531. </div>
  532. </div>
  533. </form>
  534. <?php
  535. }
  536. function printStep4() {
  537. ?>
  538. <p class="alert alert-success"><span class="alert-head"><?= _t('install.congratulations') ?></span> <?= _t('install.ok') ?></p>
  539. <a class="btn btn-important next-step" href="?step=5" tabindex="1"><?= _t('install.action.finish') ?></a>
  540. <?php
  541. }
  542. function printStep5() {
  543. ?>
  544. <p class="alert alert-error">
  545. <span class="alert-head"><?= _t('gen.short.damn') ?></span>
  546. <?= _t('install.missing_applied_migrations', DATA_PATH . '/applied_migrations.txt') ?>
  547. </p>
  548. <?php
  549. }
  550. initTranslate();
  551. checkStep();
  552. switch (STEP) {
  553. case 0:
  554. default:
  555. saveLanguage();
  556. break;
  557. case 1:
  558. saveStep1();
  559. break;
  560. case 2:
  561. saveStep2();
  562. break;
  563. case 3:
  564. saveStep3();
  565. break;
  566. case 4:
  567. break;
  568. case 5:
  569. if (setupMigrations()) {
  570. header('Location: index.php');
  571. }
  572. break;
  573. }
  574. ?>
  575. <!DOCTYPE html>
  576. <html<?php
  577. if (_t('gen.dir') === 'rtl') {
  578. echo ' dir="rtl" class="rtl"';
  579. }
  580. ?>>
  581. <head>
  582. <meta charset="UTF-8" />
  583. <meta name="viewport" content="initial-scale=1.0" />
  584. <script id="jsonVars" type="application/json">{}</script>
  585. <title><?= _t('install.title') ?>: <?= _t('install.step', STEP + 1) ?></title>
  586. <link rel="stylesheet" href="../themes/base-theme/template.css?<?= @filemtime(PUBLIC_PATH . '/themes/base-theme/template.css') ?>" />
  587. <link rel="stylesheet" href="../themes/Origine/origine.css?<?= @filemtime(PUBLIC_PATH . '/themes/Origine/origine.css') ?>" />
  588. <meta name="robots" content="noindex,nofollow" />
  589. </head>
  590. <body>
  591. <header class="header">
  592. <div class="item title">
  593. <div id="logo-wrapper">
  594. <a href="./">
  595. <img class="logo" src="../themes/icons/FreshRSS-logo.svg" alt="">
  596. </a>
  597. </div>
  598. </div>
  599. </header>
  600. <main id="global">
  601. <nav class="nav nav-list aside">
  602. <div class="nav-header"><?= _t('install.steps') ?></div>
  603. <ol>
  604. <li class="item<?= STEP == 0 ? ' active' : '' ?>">
  605. <a href="?step=0" title="<?= _t('install.step', 0) ?>: <?= _t('install.language') ?>"><?= _t('install.language') ?></a>
  606. </li>
  607. <li class="item<?= STEP == 1 ? ' active' : '' ?>">
  608. <?php if (STEP > 0) {?>
  609. <a href="?step=1" title="<?= _t('install.step', 1) ?>: <?= _t('install.check') ?>"><?= _t('install.check') ?></a>
  610. <?php } else { ?>
  611. <span><?= _t('install.check') ?></span>
  612. <?php } ?>
  613. </li>
  614. <li class="item<?= STEP == 2 ? ' active' : '' ?>">
  615. <?php if (STEP > 1) {?>
  616. <a href="?step=2" title="<?= _t('install.step', 2) ?>: <?= _t('install.bdd.conf') ?>"><?= _t('install.bdd.conf') ?></a>
  617. <?php } else { ?>
  618. <span><?= _t('install.bdd.conf') ?></span>
  619. <?php } ?>
  620. </li>
  621. <li class="item<?= STEP == 3 ? ' active' : '' ?>">
  622. <?php if (STEP > 2) {?>
  623. <a href="?step=3" title="<?= _t('install.step', 3) ?>: <?= _t('install.conf') ?>"><?= _t('install.conf') ?></a>
  624. <?php } else { ?>
  625. <span><?= _t('install.conf') ?></span>
  626. <?php } ?>
  627. </li>
  628. <li class="item<?= STEP == 4 ? ' active' : '' ?>">
  629. <?php if (STEP > 3) {?>
  630. <a href="?step=4" title="<?= _t('install.step', 4) ?>: <?= _t('install.this_is_the_end') ?>"><?= _t('install.this_is_the_end') ?></a>
  631. <?php } else { ?>
  632. <span><?= _t('install.this_is_the_end') ?></span>
  633. <?php } ?>
  634. </li>
  635. </ol>
  636. </nav>
  637. <div class="post">
  638. <h1><?= _t('install.title') ?>: <?= _t('install.step', STEP + 1) ?></h1>
  639. <?php
  640. switch (STEP) {
  641. case 0:
  642. default:
  643. printStep0();
  644. break;
  645. case 1:
  646. printStep1();
  647. break;
  648. case 2:
  649. printStep2();
  650. break;
  651. case 3:
  652. printStep3();
  653. break;
  654. case 4:
  655. printStep4();
  656. break;
  657. case 5:
  658. printStep5();
  659. break;
  660. }
  661. ?>
  662. </div>
  663. </main>
  664. <script src="../scripts/install.js?<?= @filemtime(PUBLIC_PATH . '/scripts/install.js') ?>"></script>
  665. </body>
  666. </html>