install.php 27 KB

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