install.php 27 KB

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