install.php 30 KB

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