install.php 26 KB

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