install.php 27 KB

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