install.php 31 KB

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