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