install.php 30 KB

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