install.php 29 KB

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