4
0

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