install.php 30 KB

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