install.php 33 KB

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