install.php 27 KB

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