install.php 30 KB

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