install.php 26 KB

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