install.php 28 KB

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