install.php 30 KB

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