install.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. <?php
  2. if (function_exists('opcache_reset')) {
  3. opcache_reset();
  4. }
  5. define('BCRYPT_COST', 9);
  6. session_name('FreshRSS');
  7. session_set_cookie_params(0, dirname(empty($_SERVER['REQUEST_URI']) ? '/' : dirname($_SERVER['REQUEST_URI'])), null, false, true);
  8. session_start();
  9. Minz_Configuration::register('default_system', DATA_PATH . '/config.default.php');
  10. Minz_Configuration::register('default_user', USERS_PATH . '/_/config.default.php');
  11. if (isset($_GET['step'])) {
  12. define('STEP',(int)$_GET['step']);
  13. } else {
  14. define('STEP', 0);
  15. }
  16. define('SQL_CREATE_DB', 'CREATE DATABASE IF NOT EXISTS %1$s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  17. if (STEP === 3 && isset($_POST['type'])) {
  18. $_SESSION['bd_type'] = $_POST['type'];
  19. }
  20. if (isset($_SESSION['bd_type'])) {
  21. switch ($_SESSION['bd_type']) {
  22. case 'mysql':
  23. include(APP_PATH . '/SQL/install.sql.mysql.php');
  24. break;
  25. case 'sqlite':
  26. include(APP_PATH . '/SQL/install.sql.sqlite.php');
  27. break;
  28. }
  29. }
  30. function param($key, $default = false) {
  31. if (isset($_POST[$key])) {
  32. return $_POST[$key];
  33. } else {
  34. return $default;
  35. }
  36. }
  37. // gestion internationalisation
  38. function initTranslate() {
  39. Minz_Translate::init();
  40. $available_languages = Minz_Translate::availableLanguages();
  41. if (!isset($_SESSION['language'])) {
  42. $_SESSION['language'] = get_best_language();
  43. }
  44. if (!in_array($_SESSION['language'], $available_languages)) {
  45. $_SESSION['language'] = 'en';
  46. }
  47. Minz_Translate::reset($_SESSION['language']);
  48. }
  49. function get_best_language() {
  50. $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  51. return strtolower(substr($accept, 0, 2));
  52. }
  53. /*** SAUVEGARDES ***/
  54. function saveLanguage() {
  55. if (!empty($_POST)) {
  56. if (!isset($_POST['language'])) {
  57. return false;
  58. }
  59. $_SESSION['language'] = $_POST['language'];
  60. header('Location: index.php?step=1');
  61. }
  62. }
  63. function saveStep1() {
  64. if (isset($_POST['freshrss-keep-reinstall']) &&
  65. $_POST['freshrss-keep-reinstall'] === '1') {
  66. // We want to keep our previous installation of FreshRSS
  67. // so we need to make next steps valid by setting $_SESSION vars
  68. // with values from the previous installation
  69. // First, we try to get previous configurations
  70. Minz_Configuration::register('system',
  71. DATA_PATH . '/config.php',
  72. DATA_PATH . '/config.default.php');
  73. $system_conf = Minz_Configuration::get('system');
  74. $current_user = $system_conf->default_user;
  75. Minz_Configuration::register('user',
  76. USERS_PATH . '/' . $current_user . '/config.php',
  77. USERS_PATH . '/_/config.default.php');
  78. $user_conf = Minz_Configuration::get('user');
  79. // Then, we set $_SESSION vars
  80. $_SESSION['title'] = $system_conf->title;
  81. $_SESSION['old_entries'] = $user_conf->old_entries;
  82. $_SESSION['mail_login'] = $user_conf->mail_login;
  83. $_SESSION['default_user'] = $current_user;
  84. $db = $system_conf->db;
  85. $_SESSION['bd_type'] = $db['type'];
  86. $_SESSION['bd_host'] = $db['host'];
  87. $_SESSION['bd_user'] = $db['user'];
  88. $_SESSION['bd_password'] = $db['password'];
  89. $_SESSION['bd_base'] = $db['base'];
  90. $_SESSION['bd_prefix'] = $db['prefix'];
  91. $_SESSION['bd_error'] = '';
  92. header('Location: index.php?step=4');
  93. }
  94. }
  95. function saveStep2() {
  96. $user_default_config = Minz_Configuration::get('default_user');
  97. if (!empty($_POST)) {
  98. $_SESSION['title'] = substr(trim(param('title', _t('gen.freshrss'))), 0, 25);
  99. $_SESSION['old_entries'] = param('old_entries', $user_default_config->old_entries);
  100. $_SESSION['auth_type'] = param('auth_type', 'form');
  101. $_SESSION['default_user'] = substr(preg_replace('/[^a-zA-Z0-9]/', '', param('default_user', '')), 0, 16);
  102. $_SESSION['mail_login'] = filter_var(param('mail_login', ''), FILTER_VALIDATE_EMAIL);
  103. $password_plain = param('passwordPlain', false);
  104. if ($password_plain !== false) {
  105. if (!function_exists('password_hash')) {
  106. include_once(LIB_PATH . '/password_compat.php');
  107. }
  108. $passwordHash = password_hash($password_plain, PASSWORD_BCRYPT, array('cost' => BCRYPT_COST));
  109. $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash); //Compatibility with bcrypt.js
  110. $_SESSION['passwordHash'] = $passwordHash;
  111. }
  112. if (empty($_SESSION['title']) ||
  113. empty($_SESSION['old_entries']) ||
  114. empty($_SESSION['auth_type']) ||
  115. empty($_SESSION['default_user'])) {
  116. return false;
  117. }
  118. if (($_SESSION['auth_type'] === 'form' && empty($_SESSION['passwordHash'])) ||
  119. ($_SESSION['auth_type'] === 'persona' && empty($_SESSION['mail_login']))) {
  120. return false;
  121. }
  122. $_SESSION['salt'] = sha1(uniqid(mt_rand(), true).implode('', stat(__FILE__)));
  123. if ((!ctype_digit($_SESSION['old_entries'])) ||($_SESSION['old_entries'] < 1)) {
  124. $_SESSION['old_entries'] = $user_default_config->old_entries;
  125. }
  126. $token = '';
  127. if ($_SESSION['mail_login']) {
  128. $token = sha1($_SESSION['salt'] . $_SESSION['mail_login']);
  129. }
  130. $config_array = array(
  131. 'language' => $_SESSION['language'],
  132. 'theme' => $user_default_config->theme,
  133. 'old_entries' => $_SESSION['old_entries'],
  134. 'mail_login' => $_SESSION['mail_login'],
  135. 'passwordHash' => $_SESSION['passwordHash'],
  136. 'token' => $token,
  137. );
  138. // Create default user files but first, we delete previous data to
  139. // avoid access right problems.
  140. $user_dir = join_path(USERS_PATH, $_SESSION['default_user']);
  141. $user_config_path = join_path($user_dir, 'config.php');
  142. recursive_unlink($user_dir);
  143. mkdir($user_dir);
  144. file_put_contents($user_config_path, "<?php\n return " . var_export($config_array, true) . ';');
  145. if ($_SESSION['mail_login'] != '') {
  146. $personaFile = join_path(DATA_PATH, 'persona', $_SESSION['mail_login'] . '.txt');
  147. @unlink($personaFile);
  148. file_put_contents($personaFile, $_SESSION['default_user']);
  149. }
  150. header('Location: index.php?step=3');
  151. }
  152. }
  153. function saveStep3() {
  154. if (!empty($_POST)) {
  155. if ($_SESSION['bd_type'] === 'sqlite') {
  156. $_SESSION['bd_base'] = $_SESSION['default_user'];
  157. $_SESSION['bd_host'] = '';
  158. $_SESSION['bd_user'] = '';
  159. $_SESSION['bd_password'] = '';
  160. $_SESSION['bd_prefix'] = '';
  161. $_SESSION['bd_prefix_user'] = ''; //No prefix for SQLite
  162. } else {
  163. if (empty($_POST['type']) ||
  164. empty($_POST['host']) ||
  165. empty($_POST['user']) ||
  166. empty($_POST['base'])) {
  167. $_SESSION['bd_error'] = 'Missing parameters!';
  168. }
  169. $_SESSION['bd_base'] = substr($_POST['base'], 0, 64);
  170. $_SESSION['bd_host'] = $_POST['host'];
  171. $_SESSION['bd_user'] = $_POST['user'];
  172. $_SESSION['bd_password'] = $_POST['pass'];
  173. $_SESSION['bd_prefix'] = substr($_POST['prefix'], 0, 16);
  174. $_SESSION['bd_prefix_user'] = $_SESSION['bd_prefix'] . (empty($_SESSION['default_user']) ? '' : ($_SESSION['default_user'] . '_'));
  175. }
  176. $config_array = array(
  177. 'salt' => $_SESSION['salt'],
  178. 'title' => $_SESSION['title'],
  179. 'default_user' => $_SESSION['default_user'],
  180. 'auth_type' => $_SESSION['auth_type'],
  181. 'db' => array(
  182. 'type' => $_SESSION['bd_type'],
  183. 'host' => $_SESSION['bd_host'],
  184. 'user' => $_SESSION['bd_user'],
  185. 'password' => $_SESSION['bd_password'],
  186. 'base' => $_SESSION['bd_base'],
  187. 'prefix' => $_SESSION['bd_prefix'],
  188. 'pdo_options' => array(),
  189. ),
  190. );
  191. @unlink(join_path(DATA_PATH, 'config.php')); //To avoid access-rights problems
  192. file_put_contents(join_path(DATA_PATH, 'config.php'), "<?php\n return " . var_export($config_array, true) . ';');
  193. $res = checkBD();
  194. if ($res) {
  195. $_SESSION['bd_error'] = '';
  196. header('Location: index.php?step=4');
  197. } elseif (empty($_SESSION['bd_error'])) {
  198. $_SESSION['bd_error'] = 'Unknown error!';
  199. }
  200. }
  201. invalidateHttpCache();
  202. }
  203. function newPdo() {
  204. switch ($_SESSION['bd_type']) {
  205. case 'mysql':
  206. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  207. $driver_options = array(
  208. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  209. );
  210. break;
  211. case 'sqlite':
  212. $str = 'sqlite:' . join_path(USERS_PATH, $_SESSION['default_user'], 'db.sqlite');
  213. $driver_options = array(
  214. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  215. );
  216. break;
  217. default:
  218. return false;
  219. }
  220. return new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  221. }
  222. function deleteInstall() {
  223. $res = unlink(join_path(DATA_PATH, 'do-install.txt'));
  224. if (!$res) {
  225. return false;
  226. }
  227. header('Location: index.php');
  228. }
  229. /*** VÉRIFICATIONS ***/
  230. function checkStep() {
  231. $s0 = checkStep0();
  232. $s1 = checkStep1();
  233. $s2 = checkStep2();
  234. $s3 = checkStep3();
  235. if (STEP > 0 && $s0['all'] != 'ok') {
  236. header('Location: index.php?step=0');
  237. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  238. header('Location: index.php?step=1');
  239. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  240. header('Location: index.php?step=2');
  241. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  242. header('Location: index.php?step=3');
  243. }
  244. $_SESSION['actualize_feeds'] = true;
  245. }
  246. function checkStep0() {
  247. $languages = Minz_Translate::availableLanguages();
  248. $language = isset($_SESSION['language']) &&
  249. in_array($_SESSION['language'], $languages);
  250. return array(
  251. 'language' => $language ? 'ok' : 'ko',
  252. 'all' => $language ? 'ok' : 'ko'
  253. );
  254. }
  255. function checkStep1() {
  256. $php = version_compare(PHP_VERSION, '5.2.1') >= 0;
  257. $minz = file_exists(join_path(LIB_PATH, 'Minz'));
  258. $curl = extension_loaded('curl');
  259. $pdo_mysql = extension_loaded('pdo_mysql');
  260. $pdo_sqlite = extension_loaded('pdo_sqlite');
  261. $pdo = $pdo_mysql || $pdo_sqlite;
  262. $pcre = extension_loaded('pcre');
  263. $ctype = extension_loaded('ctype');
  264. $dom = class_exists('DOMDocument');
  265. $data = DATA_PATH && is_writable(DATA_PATH);
  266. $cache = CACHE_PATH && is_writable(CACHE_PATH);
  267. $users = USERS_PATH && is_writable(USERS_PATH);
  268. $favicons = is_writable(join_path(DATA_PATH, 'favicons'));
  269. $persona = is_writable(join_path(DATA_PATH, 'persona'));
  270. $http_referer = is_referer_from_same_domain();
  271. return array(
  272. 'php' => $php ? 'ok' : 'ko',
  273. 'minz' => $minz ? 'ok' : 'ko',
  274. 'curl' => $curl ? 'ok' : 'ko',
  275. 'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko',
  276. 'pdo-sqlite' => $pdo_sqlite ? 'ok' : 'ko',
  277. 'pdo' => $pdo ? 'ok' : 'ko',
  278. 'pcre' => $pcre ? 'ok' : 'ko',
  279. 'ctype' => $ctype ? 'ok' : 'ko',
  280. 'dom' => $dom ? 'ok' : 'ko',
  281. 'data' => $data ? 'ok' : 'ko',
  282. 'cache' => $cache ? 'ok' : 'ko',
  283. 'users' => $users ? 'ok' : 'ko',
  284. 'favicons' => $favicons ? 'ok' : 'ko',
  285. 'persona' => $persona ? 'ok' : 'ko',
  286. 'http_referer' => $http_referer ? 'ok' : 'ko',
  287. 'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $dom &&
  288. $data && $cache && $users && $favicons && $persona && $http_referer ?
  289. 'ok' : 'ko'
  290. );
  291. }
  292. function freshrss_already_installed() {
  293. return false;
  294. }
  295. function checkStep2() {
  296. $conf = !empty($_SESSION['title']) &&
  297. !empty($_SESSION['old_entries']) &&
  298. isset($_SESSION['mail_login']) &&
  299. !empty($_SESSION['default_user']);
  300. $form = (
  301. isset($_SESSION['auth_type']) &&
  302. ($_SESSION['auth_type'] != 'form' || !empty($_SESSION['passwordHash']))
  303. );
  304. $persona = (
  305. isset($_SESSION['auth_type']) &&
  306. ($_SESSION['auth_type'] != 'persona' || !empty($_SESSION['mail_login']))
  307. );
  308. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  309. if ($defaultUser === null) {
  310. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  311. }
  312. $data = is_writable(join_path(USERS_PATH, $defaultUser, 'config.php'));
  313. return array(
  314. 'conf' => $conf ? 'ok' : 'ko',
  315. 'form' => $form ? 'ok' : 'ko',
  316. 'persona' => $persona ? 'ok' : 'ko',
  317. 'data' => $data ? 'ok' : 'ko',
  318. 'all' => $conf && $form && $persona && $data ? 'ok' : 'ko'
  319. );
  320. }
  321. function checkStep3() {
  322. $conf = is_writable(join_path(DATA_PATH, 'config.php'));
  323. $bd = isset($_SESSION['bd_type']) &&
  324. isset($_SESSION['bd_host']) &&
  325. isset($_SESSION['bd_user']) &&
  326. isset($_SESSION['bd_password']) &&
  327. isset($_SESSION['bd_base']) &&
  328. isset($_SESSION['bd_prefix']) &&
  329. isset($_SESSION['bd_error']);
  330. $conn = empty($_SESSION['bd_error']);
  331. return array(
  332. 'bd' => $bd ? 'ok' : 'ko',
  333. 'conn' => $conn ? 'ok' : 'ko',
  334. 'conf' => $conf ? 'ok' : 'ko',
  335. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  336. );
  337. }
  338. function checkBD() {
  339. $ok = false;
  340. try {
  341. $str = '';
  342. $driver_options = null;
  343. switch ($_SESSION['bd_type']) {
  344. case 'mysql':
  345. $driver_options = array(
  346. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  347. );
  348. try { // on ouvre une connexion juste pour créer la base si elle n'existe pas
  349. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  350. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  351. $sql = sprintf(SQL_CREATE_DB, $_SESSION['bd_base']);
  352. $res = $c->query($sql);
  353. } catch (PDOException $e) {
  354. }
  355. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  356. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  357. break;
  358. case 'sqlite':
  359. $str = 'sqlite:' . join_path(USERS_PATH, $_SESSION['default_user'], 'db.sqlite');
  360. $driver_options = array(
  361. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  362. );
  363. break;
  364. default:
  365. return false;
  366. }
  367. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  368. if (defined('SQL_CREATE_TABLES')) {
  369. $sql = sprintf(SQL_CREATE_TABLES, $_SESSION['bd_prefix_user'], _t('gen.short.default_category'));
  370. $stm = $c->prepare($sql);
  371. $ok = $stm->execute();
  372. } else {
  373. global $SQL_CREATE_TABLES;
  374. if (is_array($SQL_CREATE_TABLES)) {
  375. $ok = true;
  376. foreach ($SQL_CREATE_TABLES as $instruction) {
  377. $sql = sprintf($instruction, $_SESSION['bd_prefix_user'], _t('gen.short.default_category'));
  378. $stm = $c->prepare($sql);
  379. $ok &= $stm->execute();
  380. }
  381. }
  382. }
  383. } catch (PDOException $e) {
  384. $ok = false;
  385. $_SESSION['bd_error'] = $e->getMessage();
  386. }
  387. if (!$ok) {
  388. @unlink(join_path(DATA_PATH, 'config.php'));
  389. }
  390. return $ok;
  391. }
  392. /*** AFFICHAGE ***/
  393. function printStep0() {
  394. $actual = Minz_Translate::language();
  395. $languages = Minz_Translate::availableLanguages();
  396. ?>
  397. <?php $s0 = checkStep0(); if ($s0['all'] == 'ok') { ?>
  398. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.language.defined'); ?></p>
  399. <?php } ?>
  400. <form action="index.php?step=0" method="post">
  401. <legend><?php echo _t('install.language.choose'); ?></legend>
  402. <div class="form-group">
  403. <label class="group-name" for="language"><?php echo _t('install.language'); ?></label>
  404. <div class="group-controls">
  405. <select name="language" id="language" tabindex="1" >
  406. <?php foreach ($languages as $lang) { ?>
  407. <option value="<?php echo $lang; ?>"<?php echo $actual == $lang ? ' selected="selected"' : ''; ?>>
  408. <?php echo _t('gen.lang.' . $lang); ?>
  409. </option>
  410. <?php } ?>
  411. </select>
  412. </div>
  413. </div>
  414. <div class="form-group form-actions">
  415. <div class="group-controls">
  416. <button type="submit" class="btn btn-important" tabindex="2" ><?php echo _t('gen.action.submit'); ?></button>
  417. <button type="reset" class="btn" tabindex="3" ><?php echo _t('gen.action.cancel'); ?></button>
  418. <?php if ($s0['all'] == 'ok') { ?>
  419. <a class="btn btn-important next-step" href="?step=1" tabindex="4" ><?php echo _t('install.action.next_step'); ?></a>
  420. <?php } ?>
  421. </div>
  422. </div>
  423. </form>
  424. <?php
  425. }
  426. // @todo refactor this view with the check_install action
  427. function printStep1() {
  428. $res = checkStep1();
  429. ?>
  430. <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>
  431. <?php if ($res['php'] == 'ok') { ?>
  432. <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>
  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.php.nok', PHP_VERSION, '5.2.1'); ?></p>
  435. <?php } ?>
  436. <?php if ($res['minz'] == 'ok') { ?>
  437. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.minz.ok'); ?></p>
  438. <?php } else { ?>
  439. <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>
  440. <?php } ?>
  441. <?php if ($res['pdo'] == 'ok') { ?>
  442. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.pdo.ok'); ?></p>
  443. <?php } else { ?>
  444. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.pdo.nok'); ?></p>
  445. <?php } ?>
  446. <?php if ($res['curl'] == 'ok') { ?>
  447. <?php $version = curl_version(); ?>
  448. <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>
  449. <?php } else { ?>
  450. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.curl.nok'); ?></p>
  451. <?php } ?>
  452. <?php if ($res['pcre'] == 'ok') { ?>
  453. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.pcre.ok'); ?></p>
  454. <?php } else { ?>
  455. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.pcre.nok'); ?></p>
  456. <?php } ?>
  457. <?php if ($res['ctype'] == 'ok') { ?>
  458. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.ctype.ok'); ?></p>
  459. <?php } else { ?>
  460. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.ctype.nok'); ?></p>
  461. <?php } ?>
  462. <?php if ($res['dom'] == 'ok') { ?>
  463. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.dom.ok'); ?></p>
  464. <?php } else { ?>
  465. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.dom.nok'); ?></p>
  466. <?php } ?>
  467. <?php if ($res['data'] == 'ok') { ?>
  468. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.data.ok'); ?></p>
  469. <?php } else { ?>
  470. <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>
  471. <?php } ?>
  472. <?php if ($res['cache'] == 'ok') { ?>
  473. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.cache.ok'); ?></p>
  474. <?php } else { ?>
  475. <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>
  476. <?php } ?>
  477. <?php if ($res['users'] == 'ok') { ?>
  478. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.users.ok'); ?></p>
  479. <?php } else { ?>
  480. <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>
  481. <?php } ?>
  482. <?php if ($res['favicons'] == 'ok') { ?>
  483. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.favicons.ok'); ?></p>
  484. <?php } else { ?>
  485. <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>
  486. <?php } ?>
  487. <?php if ($res['persona'] == 'ok') { ?>
  488. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.persona.ok'); ?></p>
  489. <?php } else { ?>
  490. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.persona.nok', DATA_PATH . '/persona'); ?></p>
  491. <?php } ?>
  492. <?php if ($res['http_referer'] == 'ok') { ?>
  493. <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>
  494. <?php } else { ?>
  495. <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>
  496. <?php } ?>
  497. <?php if (freshrss_already_installed() && $res['all'] == 'ok') { ?>
  498. <p class="alert alert-warn"><span class="alert-head"><?php echo _t('gen.short.attention'); ?></span> <?php echo _t('install.check.freshrss_alreadyy_installed'); ?></p>
  499. <form action="index.php?step=1" method="post">
  500. <input type="hidden" name="freshrss-keep-reinstall" value="1" />
  501. <button type="submit" class="btn btn-important" tabindex="1" ><?php echo _t('install.action.keep_install'); ?></button>
  502. <a class="btn btn-attention next-step" href="?step=2" tabindex="2" ><?php echo _t('install.action.reinstall'); ?></a>
  503. </form>
  504. <?php } elseif ($res['all'] == 'ok') { ?>
  505. <a class="btn btn-important next-step" href="?step=2" tabindex="1" ><?php echo _t('install.action.next_step'); ?></a>
  506. <?php } else { ?>
  507. <p class="alert alert-error"><?php echo _t('install.action.fix_errors_before'); ?></p>
  508. <?php } ?>
  509. <?php
  510. }
  511. function printStep2() {
  512. $user_default_config = Minz_Configuration::get('default_user');
  513. ?>
  514. <?php $s2 = checkStep2(); if ($s2['all'] == 'ok') { ?>
  515. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.conf.ok'); ?></p>
  516. <?php } elseif (!empty($_POST)) { ?>
  517. <p class="alert alert-error"><?php echo _t('install.fix_errors_before'); ?></p>
  518. <?php } ?>
  519. <form action="index.php?step=2" method="post">
  520. <legend><?php echo _t('install.conf'); ?></legend>
  521. <div class="form-group">
  522. <label class="group-name" for="title"><?php echo _t('install.title'); ?></label>
  523. <div class="group-controls">
  524. <input type="text" id="title" name="title" value="<?php echo isset($_SESSION['title']) ? $_SESSION['title'] : _t('gen.freshrss'); ?>" tabindex="1" />
  525. </div>
  526. </div>
  527. <div class="form-group">
  528. <label class="group-name" for="old_entries"><?php echo _t('install.delete_articles_after'); ?></label>
  529. <div class="group-controls">
  530. <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'); ?>
  531. </div>
  532. </div>
  533. <div class="form-group">
  534. <label class="group-name" for="default_user"><?php echo _t('install.default_user'); ?></label>
  535. <div class="group-controls">
  536. <input type="text" id="default_user" name="default_user" required="required" size="16" maxlength="16" pattern="[0-9a-zA-Z]{1,16}" value="<?php echo isset($_SESSION['default_user']) ? $_SESSION['default_user'] : ''; ?>" placeholder="<?php echo httpAuthUser() == '' ? 'alice' : httpAuthUser(); ?>" tabindex="3" />
  537. </div>
  538. </div>
  539. <div class="form-group">
  540. <label class="group-name" for="auth_type"><?php echo _t('install.auth.type'); ?></label>
  541. <div class="group-controls">
  542. <select id="auth_type" name="auth_type" required="required" onchange="auth_type_change(true)" tabindex="4">
  543. <?php
  544. function no_auth($auth_type) {
  545. return !in_array($auth_type, array('form', 'persona', 'http_auth', 'none'));
  546. }
  547. $auth_type = isset($_SESSION['auth_type']) ? $_SESSION['auth_type'] : '';
  548. ?>
  549. <option value="form"<?php echo $auth_type === 'form' || no_auth($auth_type) ? ' selected="selected"' : '', cryptAvailable() ? '' : ' disabled="disabled"'; ?>><?php echo _t('install.auth.form'); ?></option>
  550. <option value="persona"<?php echo $auth_type === 'persona' ? ' selected="selected"' : ''; ?>><?php echo _t('install.auth.persona'); ?></option>
  551. <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>
  552. <option value="none"<?php echo $auth_type === 'none' ? ' selected="selected"' : ''; ?>><?php echo _t('install.auth.none'); ?></option>
  553. </select>
  554. </div>
  555. </div>
  556. <div class="form-group">
  557. <label class="group-name" for="passwordPlain"><?php echo _t('install.auth.password_form'); ?></label>
  558. <div class="group-controls">
  559. <div class="stick">
  560. <input type="password" id="passwordPlain" name="passwordPlain" pattern=".{7,}" autocomplete="off" <?php echo $auth_type === 'form' ? ' required="required"' : ''; ?> tabindex="5" />
  561. <a class="btn toggle-password" data-toggle="passwordPlain"><?php echo FreshRSS_Themes::icon('key'); ?></a>
  562. </div>
  563. <?php echo _i('help'); ?> <?php echo _t('install.auth.password_format'); ?>
  564. <noscript><b><?php echo _t('gen.js.should_be_activated'); ?></b></noscript>
  565. </div>
  566. </div>
  567. <div class="form-group">
  568. <label class="group-name" for="mail_login"><?php echo _t('install.auth.email_persona'); ?></label>
  569. <div class="group-controls">
  570. <input type="email" id="mail_login" name="mail_login" value="<?php echo isset($_SESSION['mail_login']) ? $_SESSION['mail_login'] : ''; ?>" placeholder="alice@example.net" <?php echo $auth_type === 'persona' ? ' required="required"' : ''; ?> tabindex="6"/>
  571. <noscript><b><?php echo _t('gen.js.should_be_activated'); ?></b></noscript>
  572. </div>
  573. </div>
  574. <script>
  575. function show_password() {
  576. var button = this;
  577. var passwordField = document.getElementById(button.getAttribute('data-toggle'));
  578. passwordField.setAttribute('type', 'text');
  579. button.className += ' active';
  580. return false;
  581. }
  582. function hide_password() {
  583. var button = this;
  584. var passwordField = document.getElementById(button.getAttribute('data-toggle'));
  585. passwordField.setAttribute('type', 'password');
  586. button.className = button.className.replace(/(?:^|\s)active(?!\S)/g , '');
  587. return false;
  588. }
  589. toggles = document.getElementsByClassName('toggle-password');
  590. for (var i = 0 ; i < toggles.length ; i++) {
  591. toggles[i].addEventListener('mousedown', show_password);
  592. toggles[i].addEventListener('mouseup', hide_password);
  593. }
  594. function auth_type_change() {
  595. var auth_value = document.getElementById('auth_type').value,
  596. password_input = document.getElementById('passwordPlain'),
  597. mail_input = document.getElementById('mail_login');
  598. if (auth_value === 'form') {
  599. password_input.required = true;
  600. mail_input.required = false;
  601. } else if (auth_value === 'persona') {
  602. password_input.required = false;
  603. mail_input.required = true;
  604. } else {
  605. password_input.required = false;
  606. mail_input.required = false;
  607. }
  608. }
  609. auth_type_change();
  610. </script>
  611. <div class="form-group form-actions">
  612. <div class="group-controls">
  613. <button type="submit" class="btn btn-important" tabindex="7" ><?php echo _t('gen.action.submit'); ?></button>
  614. <button type="reset" class="btn" tabindex="8" ><?php echo _t('gen.action.cancel'); ?></button>
  615. <?php if ($s2['all'] == 'ok') { ?>
  616. <a class="btn btn-important next-step" href="?step=3" tabindex="9" ><?php echo _t('install.action.next_step'); ?></a>
  617. <?php } ?>
  618. </div>
  619. </div>
  620. </form>
  621. <?php
  622. }
  623. function printStep3() {
  624. $system_default_config = Minz_Configuration::get('default_system');
  625. ?>
  626. <?php $s3 = checkStep3(); if ($s3['all'] == 'ok') { ?>
  627. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.bdd.conf.ok'); ?></p>
  628. <?php } elseif ($s3['conn'] == 'ko') { ?>
  629. <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>
  630. <?php } ?>
  631. <form action="index.php?step=3" method="post">
  632. <legend><?php echo _t('install.bdd.conf'); ?></legend>
  633. <div class="form-group">
  634. <label class="group-name" for="type"><?php echo _t('install.bdd.type'); ?></label>
  635. <div class="group-controls">
  636. <select name="type" id="type" onchange="mySqlShowHide()" tabindex="1" >
  637. <?php if (extension_loaded('pdo_mysql')) {?>
  638. <option value="mysql"
  639. <?php echo(isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  640. MySQL
  641. </option>
  642. <?php }?>
  643. <?php if (extension_loaded('pdo_sqlite')) {?>
  644. <option value="sqlite"
  645. <?php echo(isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  646. SQLite
  647. </option>
  648. <?php }?>
  649. </select>
  650. </div>
  651. </div>
  652. <div id="mysql">
  653. <div class="form-group">
  654. <label class="group-name" for="host"><?php echo _t('install.bdd.host'); ?></label>
  655. <div class="group-controls">
  656. <input type="text" id="host" name="host" pattern="[0-9A-Za-z_.-]{1,64}" value="<?php echo isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : $system_default_config->db['host']; ?>" tabindex="2" />
  657. </div>
  658. </div>
  659. <div class="form-group">
  660. <label class="group-name" for="user"><?php echo _t('install.bdd.username'); ?></label>
  661. <div class="group-controls">
  662. <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" />
  663. </div>
  664. </div>
  665. <div class="form-group">
  666. <label class="group-name" for="pass"><?php echo _t('install.bdd.password'); ?></label>
  667. <div class="group-controls">
  668. <input type="password" id="pass" name="pass" value="<?php echo isset($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" tabindex="4" />
  669. </div>
  670. </div>
  671. <div class="form-group">
  672. <label class="group-name" for="base"><?php echo _t('install.bdd'); ?></label>
  673. <div class="group-controls">
  674. <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" />
  675. </div>
  676. </div>
  677. <div class="form-group">
  678. <label class="group-name" for="prefix"><?php echo _t('install.bdd.prefix'); ?></label>
  679. <div class="group-controls">
  680. <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" />
  681. </div>
  682. </div>
  683. </div>
  684. <script>
  685. function mySqlShowHide() {
  686. document.getElementById('mysql').style.display = document.getElementById('type').value === 'mysql' ? 'block' : 'none';
  687. if (document.getElementById('type').value !== 'mysql') {
  688. document.getElementById('host').value = '';
  689. document.getElementById('user').value = '';
  690. document.getElementById('pass').value = '';
  691. document.getElementById('base').value = '';
  692. document.getElementById('prefix').value = '';
  693. }
  694. }
  695. mySqlShowHide();
  696. </script>
  697. <div class="form-group form-actions">
  698. <div class="group-controls">
  699. <button type="submit" class="btn btn-important" tabindex="7" ><?php echo _t('gen.action.submit'); ?></button>
  700. <button type="reset" class="btn" tabindex="8" ><?php echo _t('gen.action.cancel'); ?></button>
  701. <?php if ($s3['all'] == 'ok') { ?>
  702. <a class="btn btn-important next-step" href="?step=4" tabindex="9" ><?php echo _t('install.action.next_step'); ?></a>
  703. <?php } ?>
  704. </div>
  705. </div>
  706. </form>
  707. <?php
  708. }
  709. function printStep4() {
  710. ?>
  711. <p class="alert alert-success"><span class="alert-head"><?php echo _t('install.congratulations'); ?></span> <?php echo _t('install.ok'); ?></p>
  712. <a class="btn btn-important next-step" href="?step=5" tabindex="1"><?php echo _t('install.action.finish'); ?></a>
  713. <?php
  714. }
  715. function printStep5() {
  716. ?>
  717. <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>
  718. <?php
  719. }
  720. initTranslate();
  721. checkStep();
  722. switch (STEP) {
  723. case 0:
  724. default:
  725. saveLanguage();
  726. break;
  727. case 1:
  728. saveStep1();
  729. break;
  730. case 2:
  731. saveStep2();
  732. break;
  733. case 3:
  734. saveStep3();
  735. break;
  736. case 4:
  737. break;
  738. case 5:
  739. deleteInstall();
  740. break;
  741. }
  742. ?>
  743. <!DOCTYPE html>
  744. <html lang="fr">
  745. <head>
  746. <meta charset="utf-8">
  747. <meta name="viewport" content="initial-scale=1.0">
  748. <title><?php echo _t('install.title'); ?></title>
  749. <link rel="stylesheet" type="text/css" media="all" href="../themes/base-theme/template.css" />
  750. <link rel="stylesheet" type="text/css" media="all" href="../themes/Origine/origine.css" />
  751. </head>
  752. <body>
  753. <div class="header">
  754. <div class="item title">
  755. <h1><a href="index.php"><?php echo _t('install.title'); ?></a></h1>
  756. <h2><?php echo _t('install.step', STEP); ?></h2>
  757. </div>
  758. </div>
  759. <div id="global">
  760. <ul class="nav nav-list aside">
  761. <li class="nav-header"><?php echo _t('install.steps'); ?></li>
  762. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t('install.language'); ?></a></li>
  763. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t('install.check'); ?></a></li>
  764. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t('install.conf'); ?></a></li>
  765. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t('install.bdd.conf'); ?></a></li>
  766. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=5"><?php echo _t('install.this_is_the_end'); ?></a></li>
  767. </ul>
  768. <div class="post">
  769. <?php
  770. switch (STEP) {
  771. case 0:
  772. default:
  773. printStep0();
  774. break;
  775. case 1:
  776. printStep1();
  777. break;
  778. case 2:
  779. printStep2();
  780. break;
  781. case 3:
  782. printStep3();
  783. break;
  784. case 4:
  785. printStep4();
  786. break;
  787. case 5:
  788. printStep5();
  789. break;
  790. }
  791. ?>
  792. </div>
  793. </div>
  794. </body>
  795. </html>