install.php 31 KB

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