install.php 23 KB

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