install.php 31 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. 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. //TODO: load `config.default.php` as default
  142. $config_array = array(
  143. 'environment' => 'production',
  144. 'simplepie_syslog_enabled' => true,
  145. 'salt' => $_SESSION['salt'],
  146. 'title' => $_SESSION['title'],
  147. 'default_user' => $_SESSION['default_user'],
  148. 'auth_type' => $_SESSION['auth_type'],
  149. 'db' => array(
  150. 'type' => $_SESSION['bd_type'],
  151. 'host' => $_SESSION['bd_host'],
  152. 'user' => $_SESSION['bd_user'],
  153. 'password' => $_SESSION['bd_password'],
  154. 'base' => $_SESSION['bd_base'],
  155. 'prefix' => $_SESSION['bd_prefix'],
  156. ),
  157. );
  158. @unlink(join_path(DATA_PATH, 'config.php')); //To avoid access-rights problems
  159. file_put_contents(join_path(DATA_PATH, 'config.php'), "<?php\n return " . var_export($config_array, true) . ';');
  160. $res = checkBD();
  161. if ($res) {
  162. $_SESSION['bd_error'] = '';
  163. header('Location: index.php?step=4');
  164. } elseif (empty($_SESSION['bd_error'])) {
  165. $_SESSION['bd_error'] = 'Unknown error!';
  166. }
  167. }
  168. invalidateHttpCache();
  169. }
  170. function newPdo() {
  171. switch ($_SESSION['bd_type']) {
  172. case 'mysql':
  173. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  174. $driver_options = array(
  175. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  176. );
  177. break;
  178. case 'sqlite':
  179. $str = 'sqlite:' . join_path(USERS_PATH, $_SESSION['default_user'], 'db.sqlite');
  180. $driver_options = array(
  181. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  182. );
  183. break;
  184. default:
  185. return false;
  186. }
  187. return new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  188. }
  189. function deleteInstall() {
  190. $res = unlink(join_path(DATA_PATH, 'do-install.txt'));
  191. if (!$res) {
  192. return false;
  193. }
  194. header('Location: index.php');
  195. }
  196. /*** VÉRIFICATIONS ***/
  197. function checkStep() {
  198. $s0 = checkStep0();
  199. $s1 = checkStep1();
  200. $s2 = checkStep2();
  201. $s3 = checkStep3();
  202. if (STEP > 0 && $s0['all'] != 'ok') {
  203. header('Location: index.php?step=0');
  204. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  205. header('Location: index.php?step=1');
  206. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  207. header('Location: index.php?step=2');
  208. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  209. header('Location: index.php?step=3');
  210. }
  211. $_SESSION['actualize_feeds'] = true;
  212. }
  213. function checkStep0() {
  214. $languages = Minz_Translate::availableLanguages();
  215. $language = isset($_SESSION['language']) &&
  216. in_array($_SESSION['language'], $languages);
  217. return array(
  218. 'language' => $language ? 'ok' : 'ko',
  219. 'all' => $language ? 'ok' : 'ko'
  220. );
  221. }
  222. function checkStep1() {
  223. $php = version_compare(PHP_VERSION, '5.2.1') >= 0;
  224. $minz = file_exists(join_path(LIB_PATH, 'Minz'));
  225. $curl = extension_loaded('curl');
  226. $pdo_mysql = extension_loaded('pdo_mysql');
  227. $pdo_sqlite = extension_loaded('pdo_sqlite');
  228. $pdo = $pdo_mysql || $pdo_sqlite;
  229. $pcre = extension_loaded('pcre');
  230. $ctype = extension_loaded('ctype');
  231. $dom = class_exists('DOMDocument');
  232. $data = DATA_PATH && is_writable(DATA_PATH);
  233. $cache = CACHE_PATH && is_writable(CACHE_PATH);
  234. $users = USERS_PATH && is_writable(USERS_PATH);
  235. $favicons = is_writable(join_path(DATA_PATH, 'favicons'));
  236. $persona = is_writable(join_path(DATA_PATH, 'persona'));
  237. $http_referer = is_referer_from_same_domain();
  238. return array(
  239. 'php' => $php ? 'ok' : 'ko',
  240. 'minz' => $minz ? 'ok' : 'ko',
  241. 'curl' => $curl ? 'ok' : 'ko',
  242. 'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko',
  243. 'pdo-sqlite' => $pdo_sqlite ? 'ok' : 'ko',
  244. 'pdo' => $pdo ? 'ok' : 'ko',
  245. 'pcre' => $pcre ? 'ok' : 'ko',
  246. 'ctype' => $ctype ? 'ok' : 'ko',
  247. 'dom' => $dom ? 'ok' : 'ko',
  248. 'data' => $data ? 'ok' : 'ko',
  249. 'cache' => $cache ? 'ok' : 'ko',
  250. 'users' => $users ? 'ok' : 'ko',
  251. 'favicons' => $favicons ? 'ok' : 'ko',
  252. 'persona' => $persona ? 'ok' : 'ko',
  253. 'http_referer' => $http_referer ? 'ok' : 'ko',
  254. 'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $dom &&
  255. $data && $cache && $users && $favicons && $persona && $http_referer ?
  256. 'ok' : 'ko'
  257. );
  258. }
  259. function checkStep2() {
  260. $conf = !empty($_SESSION['title']) &&
  261. !empty($_SESSION['old_entries']) &&
  262. isset($_SESSION['mail_login']) &&
  263. !empty($_SESSION['default_user']);
  264. $form = (
  265. isset($_SESSION['auth_type']) &&
  266. ($_SESSION['auth_type'] != 'form' || !empty($_SESSION['passwordHash']))
  267. );
  268. $persona = (
  269. isset($_SESSION['auth_type']) &&
  270. ($_SESSION['auth_type'] != 'persona' || !empty($_SESSION['mail_login']))
  271. );
  272. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  273. if ($defaultUser === null) {
  274. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  275. }
  276. $data = is_writable(join_path(USERS_PATH, $defaultUser, 'config.php'));
  277. return array(
  278. 'conf' => $conf ? 'ok' : 'ko',
  279. 'form' => $form ? 'ok' : 'ko',
  280. 'persona' => $persona ? 'ok' : 'ko',
  281. 'data' => $data ? 'ok' : 'ko',
  282. 'all' => $conf && $form && $persona && $data ? 'ok' : 'ko'
  283. );
  284. }
  285. function checkStep3() {
  286. $conf = is_writable(join_path(DATA_PATH, 'config.php'));
  287. $bd = isset($_SESSION['bd_type']) &&
  288. isset($_SESSION['bd_host']) &&
  289. isset($_SESSION['bd_user']) &&
  290. isset($_SESSION['bd_password']) &&
  291. isset($_SESSION['bd_base']) &&
  292. isset($_SESSION['bd_prefix']) &&
  293. isset($_SESSION['bd_error']);
  294. $conn = empty($_SESSION['bd_error']);
  295. return array(
  296. 'bd' => $bd ? 'ok' : 'ko',
  297. 'conn' => $conn ? 'ok' : 'ko',
  298. 'conf' => $conf ? 'ok' : 'ko',
  299. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  300. );
  301. }
  302. function checkBD() {
  303. $ok = false;
  304. try {
  305. $str = '';
  306. $driver_options = null;
  307. switch ($_SESSION['bd_type']) {
  308. case 'mysql':
  309. $driver_options = array(
  310. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  311. );
  312. try { // on ouvre une connexion juste pour créer la base si elle n'existe pas
  313. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  314. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  315. $sql = sprintf(SQL_CREATE_DB, $_SESSION['bd_base']);
  316. $res = $c->query($sql);
  317. } catch (PDOException $e) {
  318. }
  319. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  320. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  321. break;
  322. case 'sqlite':
  323. $str = 'sqlite:' . join_path(USERS_PATH, $_SESSION['default_user'], 'db.sqlite');
  324. $driver_options = array(
  325. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  326. );
  327. break;
  328. default:
  329. return false;
  330. }
  331. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  332. if (defined('SQL_CREATE_TABLES')) {
  333. $sql = sprintf(SQL_CREATE_TABLES, $_SESSION['bd_prefix_user'], _t('gen.short.default_category'));
  334. $stm = $c->prepare($sql);
  335. $ok = $stm->execute();
  336. } else {
  337. global $SQL_CREATE_TABLES;
  338. if (is_array($SQL_CREATE_TABLES)) {
  339. $ok = true;
  340. foreach ($SQL_CREATE_TABLES as $instruction) {
  341. $sql = sprintf($instruction, $_SESSION['bd_prefix_user'], _t('gen.short.default_category'));
  342. $stm = $c->prepare($sql);
  343. $ok &= $stm->execute();
  344. }
  345. }
  346. }
  347. } catch (PDOException $e) {
  348. $ok = false;
  349. $_SESSION['bd_error'] = $e->getMessage();
  350. }
  351. if (!$ok) {
  352. @unlink(join_path(DATA_PATH, 'config.php'));
  353. }
  354. return $ok;
  355. }
  356. /*** AFFICHAGE ***/
  357. function printStep0() {
  358. $actual = Minz_Translate::language();
  359. $languages = Minz_Translate::availableLanguages();
  360. ?>
  361. <?php $s0 = checkStep0(); if ($s0['all'] == 'ok') { ?>
  362. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.language.defined'); ?></p>
  363. <?php } ?>
  364. <form action="index.php?step=0" method="post">
  365. <legend><?php echo _t('install.language.choose'); ?></legend>
  366. <div class="form-group">
  367. <label class="group-name" for="language"><?php echo _t('install.language'); ?></label>
  368. <div class="group-controls">
  369. <select name="language" id="language" tabindex="1" >
  370. <?php foreach ($languages as $lang) { ?>
  371. <option value="<?php echo $lang; ?>"<?php echo $actual == $lang ? ' selected="selected"' : ''; ?>>
  372. <?php echo _t('gen.lang.' . $lang); ?>
  373. </option>
  374. <?php } ?>
  375. </select>
  376. </div>
  377. </div>
  378. <div class="form-group form-actions">
  379. <div class="group-controls">
  380. <button type="submit" class="btn btn-important" tabindex="2" ><?php echo _t('gen.action.submit'); ?></button>
  381. <button type="reset" class="btn" tabindex="3" ><?php echo _t('gen.action.cancel'); ?></button>
  382. <?php if ($s0['all'] == 'ok') { ?>
  383. <a class="btn btn-important next-step" href="?step=1" tabindex="4" ><?php echo _t('install.action.next_step'); ?></a>
  384. <?php } ?>
  385. </div>
  386. </div>
  387. </form>
  388. <?php
  389. }
  390. // @todo refactor this view with the check_install action
  391. function printStep1() {
  392. $res = checkStep1();
  393. ?>
  394. <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>
  395. <?php if ($res['php'] == 'ok') { ?>
  396. <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>
  397. <?php } else { ?>
  398. <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>
  399. <?php } ?>
  400. <?php if ($res['minz'] == 'ok') { ?>
  401. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.minz.ok'); ?></p>
  402. <?php } else { ?>
  403. <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>
  404. <?php } ?>
  405. <?php if ($res['pdo'] == 'ok') { ?>
  406. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.pdo.ok'); ?></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.pdo.nok'); ?></p>
  409. <?php } ?>
  410. <?php if ($res['curl'] == 'ok') { ?>
  411. <?php $version = curl_version(); ?>
  412. <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>
  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.curl.nok'); ?></p>
  415. <?php } ?>
  416. <?php if ($res['pcre'] == 'ok') { ?>
  417. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.pcre.ok'); ?></p>
  418. <?php } else { ?>
  419. <p class="alert alert-error"><span class="alert-head"><?php echo _t('gen.short.damn'); ?></span> <?php echo _t('install.check.pcre.nok'); ?></p>
  420. <?php } ?>
  421. <?php if ($res['ctype'] == 'ok') { ?>
  422. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.ctype.ok'); ?></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.ctype.nok'); ?></p>
  425. <?php } ?>
  426. <?php if ($res['dom'] == 'ok') { ?>
  427. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.dom.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.dom.nok'); ?></p>
  430. <?php } ?>
  431. <?php if ($res['data'] == 'ok') { ?>
  432. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.data.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.data.nok', DATA_PATH); ?></p>
  435. <?php } ?>
  436. <?php if ($res['cache'] == 'ok') { ?>
  437. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.cache.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.cache.nok', CACHE_PATH); ?></p>
  440. <?php } ?>
  441. <?php if ($res['users'] == 'ok') { ?>
  442. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.users.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.users.nok', USERS_PATH); ?></p>
  445. <?php } ?>
  446. <?php if ($res['favicons'] == 'ok') { ?>
  447. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.favicons.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.favicons.nok', DATA_PATH . '/favicons'); ?></p>
  450. <?php } ?>
  451. <?php if ($res['persona'] == 'ok') { ?>
  452. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.check.persona.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.persona.nok', DATA_PATH . '/persona'); ?></p>
  455. <?php } ?>
  456. <?php if ($res['http_referer'] == 'ok') { ?>
  457. <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>
  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.http_referer.nok'); ?></p>
  460. <?php } ?>
  461. <?php if ($res['all'] == 'ok') { ?>
  462. <a class="btn btn-important next-step" href="?step=2" tabindex="1" ><?php echo _t('install.action.next_step'); ?></a>
  463. <?php } else { ?>
  464. <p class="alert alert-error"><?php echo _t('install.action.fix_errors_before'); ?></p>
  465. <?php } ?>
  466. <?php
  467. }
  468. function printStep2() {
  469. ?>
  470. <?php $s2 = checkStep2(); if ($s2['all'] == 'ok') { ?>
  471. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.conf.ok'); ?></p>
  472. <?php } elseif (!empty($_POST)) { ?>
  473. <p class="alert alert-error"><?php echo _t('install.fix_errors_before'); ?></p>
  474. <?php } ?>
  475. <form action="index.php?step=2" method="post">
  476. <legend><?php echo _t('install.conf'); ?></legend>
  477. <div class="form-group">
  478. <label class="group-name" for="title"><?php echo _t('install.title'); ?></label>
  479. <div class="group-controls">
  480. <input type="text" id="title" name="title" value="<?php echo isset($_SESSION['title']) ? $_SESSION['title'] : _t('gen.freshrss'); ?>" tabindex="1" />
  481. </div>
  482. </div>
  483. <div class="form-group">
  484. <label class="group-name" for="old_entries"><?php echo _t('install.delete_articles_after'); ?></label>
  485. <div class="group-controls">
  486. <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'; ?>" tabindex="2" /> <?php echo _t('gen.date.month'); ?>
  487. </div>
  488. </div>
  489. <div class="form-group">
  490. <label class="group-name" for="default_user"><?php echo _t('install.default_user'); ?></label>
  491. <div class="group-controls">
  492. <input type="text" id="default_user" name="default_user" required="required" size="16" maxlength="16" pattern="[0-9a-zA-Z]{1,16}" value="<?php echo isset($_SESSION['default_user']) ? $_SESSION['default_user'] : ''; ?>" placeholder="<?php echo httpAuthUser() == '' ? 'alice' : httpAuthUser(); ?>" tabindex="3" />
  493. </div>
  494. </div>
  495. <div class="form-group">
  496. <label class="group-name" for="auth_type"><?php echo _t('install.auth.type'); ?></label>
  497. <div class="group-controls">
  498. <select id="auth_type" name="auth_type" required="required" onchange="auth_type_change(true)" tabindex="4">
  499. <?php
  500. function no_auth($auth_type) {
  501. return !in_array($auth_type, array('form', 'persona', 'http_auth', 'none'));
  502. }
  503. $auth_type = isset($_SESSION['auth_type']) ? $_SESSION['auth_type'] : '';
  504. ?>
  505. <option value="form"<?php echo $auth_type === 'form' || no_auth($auth_type) ? ' selected="selected"' : '', cryptAvailable() ? '' : ' disabled="disabled"'; ?>><?php echo _t('install.auth.form'); ?></option>
  506. <option value="persona"<?php echo $auth_type === 'persona' ? ' selected="selected"' : ''; ?>><?php echo _t('install.auth.persona'); ?></option>
  507. <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>
  508. <option value="none"<?php echo $auth_type === 'none' ? ' selected="selected"' : ''; ?>><?php echo _t('install.auth.none'); ?></option>
  509. </select>
  510. </div>
  511. </div>
  512. <div class="form-group">
  513. <label class="group-name" for="passwordPlain"><?php echo _t('install.auth.password_form'); ?></label>
  514. <div class="group-controls">
  515. <div class="stick">
  516. <input type="password" id="passwordPlain" name="passwordPlain" pattern=".{7,}" autocomplete="off" <?php echo $auth_type === 'form' ? ' required="required"' : ''; ?> tabindex="5" />
  517. <a class="btn toggle-password" data-toggle="passwordPlain"><?php echo FreshRSS_Themes::icon('key'); ?></a>
  518. </div>
  519. <?php echo _i('help'); ?> <?php echo _t('install.auth.password_format'); ?>
  520. <noscript><b><?php echo _t('gen.js.should_be_activated'); ?></b></noscript>
  521. </div>
  522. </div>
  523. <div class="form-group">
  524. <label class="group-name" for="mail_login"><?php echo _t('install.auth.email_persona'); ?></label>
  525. <div class="group-controls">
  526. <input type="email" id="mail_login" name="mail_login" value="<?php echo isset($_SESSION['mail_login']) ? $_SESSION['mail_login'] : ''; ?>" placeholder="alice@example.net" <?php echo $auth_type === 'persona' ? ' required="required"' : ''; ?> tabindex="6"/>
  527. <noscript><b><?php echo _t('gen.js.should_be_activated'); ?></b></noscript>
  528. </div>
  529. </div>
  530. <script>
  531. function show_password() {
  532. var button = this;
  533. var passwordField = document.getElementById(button.getAttribute('data-toggle'));
  534. passwordField.setAttribute('type', 'text');
  535. button.className += ' active';
  536. return false;
  537. }
  538. function hide_password() {
  539. var button = this;
  540. var passwordField = document.getElementById(button.getAttribute('data-toggle'));
  541. passwordField.setAttribute('type', 'password');
  542. button.className = button.className.replace(/(?:^|\s)active(?!\S)/g , '');
  543. return false;
  544. }
  545. toggles = document.getElementsByClassName('toggle-password');
  546. for (var i = 0 ; i < toggles.length ; i++) {
  547. toggles[i].addEventListener('mousedown', show_password);
  548. toggles[i].addEventListener('mouseup', hide_password);
  549. }
  550. function auth_type_change() {
  551. var auth_value = document.getElementById('auth_type').value,
  552. password_input = document.getElementById('passwordPlain'),
  553. mail_input = document.getElementById('mail_login');
  554. if (auth_value === 'form') {
  555. password_input.required = true;
  556. mail_input.required = false;
  557. } else if (auth_value === 'persona') {
  558. password_input.required = false;
  559. mail_input.required = true;
  560. } else {
  561. password_input.required = false;
  562. mail_input.required = false;
  563. }
  564. }
  565. auth_type_change();
  566. </script>
  567. <div class="form-group form-actions">
  568. <div class="group-controls">
  569. <button type="submit" class="btn btn-important" tabindex="7" ><?php echo _t('gen.action.submit'); ?></button>
  570. <button type="reset" class="btn" tabindex="8" ><?php echo _t('gen.action.cancel'); ?></button>
  571. <?php if ($s2['all'] == 'ok') { ?>
  572. <a class="btn btn-important next-step" href="?step=3" tabindex="9" ><?php echo _t('install.action.next_step'); ?></a>
  573. <?php } ?>
  574. </div>
  575. </div>
  576. </form>
  577. <?php
  578. }
  579. function printStep3() {
  580. ?>
  581. <?php $s3 = checkStep3(); if ($s3['all'] == 'ok') { ?>
  582. <p class="alert alert-success"><span class="alert-head"><?php echo _t('gen.short.ok'); ?></span> <?php echo _t('install.bdd.conf.ok'); ?></p>
  583. <?php } elseif ($s3['conn'] == 'ko') { ?>
  584. <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>
  585. <?php } ?>
  586. <form action="index.php?step=3" method="post">
  587. <legend><?php echo _t('install.bdd.conf'); ?></legend>
  588. <div class="form-group">
  589. <label class="group-name" for="type"><?php echo _t('install.bdd.type'); ?></label>
  590. <div class="group-controls">
  591. <select name="type" id="type" onchange="mySqlShowHide()" tabindex="1" >
  592. <?php if (extension_loaded('pdo_mysql')) {?>
  593. <option value="mysql"
  594. <?php echo(isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  595. MySQL
  596. </option>
  597. <?php }?>
  598. <?php if (extension_loaded('pdo_sqlite')) {?>
  599. <option value="sqlite"
  600. <?php echo(isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  601. SQLite
  602. </option>
  603. <?php }?>
  604. </select>
  605. </div>
  606. </div>
  607. <div id="mysql">
  608. <div class="form-group">
  609. <label class="group-name" for="host"><?php echo _t('install.bdd.host'); ?></label>
  610. <div class="group-controls">
  611. <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'; ?>" tabindex="2" />
  612. </div>
  613. </div>
  614. <div class="form-group">
  615. <label class="group-name" for="user"><?php echo _t('install.bdd.username'); ?></label>
  616. <div class="group-controls">
  617. <input type="text" id="user" name="user" maxlength="16" pattern="[0-9A-Za-z_.-]{1,16}" value="<?php echo isset($_SESSION['bd_user']) ? $_SESSION['bd_user'] : ''; ?>" tabindex="3" />
  618. </div>
  619. </div>
  620. <div class="form-group">
  621. <label class="group-name" for="pass"><?php echo _t('install.bdd.password'); ?></label>
  622. <div class="group-controls">
  623. <input type="password" id="pass" name="pass" value="<?php echo isset($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" tabindex="4" />
  624. </div>
  625. </div>
  626. <div class="form-group">
  627. <label class="group-name" for="base"><?php echo _t('install.bdd'); ?></label>
  628. <div class="group-controls">
  629. <input type="text" id="base" name="base" maxlength="64" pattern="[0-9A-Za-z_]{1,64}" value="<?php echo isset($_SESSION['bd_base']) ? $_SESSION['bd_base'] : ''; ?>" tabindex="5" />
  630. </div>
  631. </div>
  632. <div class="form-group">
  633. <label class="group-name" for="prefix"><?php echo _t('install.bdd.prefix'); ?></label>
  634. <div class="group-controls">
  635. <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_'; ?>" tabindex="6" />
  636. </div>
  637. </div>
  638. </div>
  639. <script>
  640. function mySqlShowHide() {
  641. document.getElementById('mysql').style.display = document.getElementById('type').value === 'mysql' ? 'block' : 'none';
  642. if (document.getElementById('type').value !== 'mysql') {
  643. document.getElementById('host').value = '';
  644. document.getElementById('user').value = '';
  645. document.getElementById('pass').value = '';
  646. document.getElementById('base').value = '';
  647. document.getElementById('prefix').value = '';
  648. }
  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" tabindex="7" ><?php echo _t('gen.action.submit'); ?></button>
  655. <button type="reset" class="btn" tabindex="8" ><?php echo _t('gen.action.cancel'); ?></button>
  656. <?php if ($s3['all'] == 'ok') { ?>
  657. <a class="btn btn-important next-step" href="?step=4" tabindex="9" ><?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" tabindex="1"><?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. initTranslate();
  676. checkStep();
  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>