install.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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' => $_SESSION['theme'],
  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 = $_SESSION['auth_type'] != 'form' || !empty($_SESSION['passwordHash']);
  292. $persona = $_SESSION['auth_type'] != 'persona' || !empty($_SESSION['mail_login']);
  293. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  294. if ($defaultUser === null) {
  295. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  296. }
  297. $data = is_writable(DATA_PATH . '/' . $defaultUser . '_user.php');
  298. return array(
  299. 'conf' => $conf ? 'ok' : 'ko',
  300. 'form' => $form ? 'ok' : 'ko',
  301. 'persona' => $persona ? 'ok' : 'ko',
  302. 'data' => $data ? 'ok' : 'ko',
  303. 'all' => $conf && $form && $persona && $data ? 'ok' : 'ko'
  304. );
  305. }
  306. function checkStep3() {
  307. $conf = is_writable(DATA_PATH . '/config.php');
  308. $bd = isset($_SESSION['bd_type']) &&
  309. isset($_SESSION['bd_host']) &&
  310. isset($_SESSION['bd_user']) &&
  311. isset($_SESSION['bd_password']) &&
  312. isset($_SESSION['bd_base']) &&
  313. isset($_SESSION['bd_prefix']) &&
  314. isset($_SESSION['bd_error']);
  315. $conn = empty($_SESSION['bd_error']);
  316. return array(
  317. 'bd' => $bd ? 'ok' : 'ko',
  318. 'conn' => $conn ? 'ok' : 'ko',
  319. 'conf' => $conf ? 'ok' : 'ko',
  320. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  321. );
  322. }
  323. function checkBD() {
  324. $ok = false;
  325. try {
  326. $str = '';
  327. $driver_options = null;
  328. switch ($_SESSION['bd_type']) {
  329. case 'mysql':
  330. $driver_options = array(
  331. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  332. );
  333. try { // on ouvre une connexion juste pour créer la base si elle n'existe pas
  334. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  335. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  336. $sql = sprintf(SQL_CREATE_DB, $_SESSION['bd_base']);
  337. $res = $c->query($sql);
  338. } catch (PDOException $e) {
  339. }
  340. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  341. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  342. break;
  343. case 'sqlite':
  344. $str = 'sqlite:' . DATA_PATH . '/' . $_SESSION['default_user'] . '.sqlite';
  345. $driver_options = array(
  346. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  347. );
  348. break;
  349. default:
  350. return false;
  351. }
  352. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  353. if (defined('SQL_CREATE_TABLES')) {
  354. $sql = sprintf(SQL_CREATE_TABLES, $_SESSION['bd_prefix_user'], _t('default_category'));
  355. $stm = $c->prepare($sql);
  356. $ok = $stm->execute();
  357. } else {
  358. global $SQL_CREATE_TABLES;
  359. if (is_array($SQL_CREATE_TABLES)) {
  360. $ok = true;
  361. foreach ($SQL_CREATE_TABLES as $instruction) {
  362. $sql = sprintf($instruction, $_SESSION['bd_prefix_user'], _t('default_category'));
  363. $stm = $c->prepare($sql);
  364. $ok &= $stm->execute();
  365. }
  366. }
  367. }
  368. } catch (PDOException $e) {
  369. $ok = false;
  370. $_SESSION['bd_error'] = $e->getMessage();
  371. }
  372. if (!$ok) {
  373. @unlink(DATA_PATH . '/config.php');
  374. }
  375. return $ok;
  376. }
  377. /*** AFFICHAGE ***/
  378. function printStep0() {
  379. global $actual;
  380. ?>
  381. <?php $s0 = checkStep0(); if ($s0['all'] == 'ok') { ?>
  382. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('language_defined'); ?></p>
  383. <?php } ?>
  384. <form action="index.php?step=0" method="post">
  385. <legend><?php echo _t('choose_language'); ?></legend>
  386. <div class="form-group">
  387. <label class="group-name" for="language"><?php echo _t('language'); ?></label>
  388. <div class="group-controls">
  389. <select name="language" id="language">
  390. <?php $languages = availableLanguages(); ?>
  391. <?php foreach ($languages as $short => $lib) { ?>
  392. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  393. <?php } ?>
  394. </select>
  395. </div>
  396. </div>
  397. <div class="form-group form-actions">
  398. <div class="group-controls">
  399. <button type="submit" class="btn btn-important"><?php echo _t('save'); ?></button>
  400. <button type="reset" class="btn"><?php echo _t('cancel'); ?></button>
  401. <?php if ($s0['all'] == 'ok') { ?>
  402. <a class="btn btn-important next-step" href="?step=1"><?php echo _t('next_step'); ?></a>
  403. <?php } ?>
  404. </div>
  405. </div>
  406. </form>
  407. <?php
  408. }
  409. function printStep1() {
  410. $res = checkStep1();
  411. ?>
  412. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t('attention'); ?></span> <?php echo _t('javascript_is_better'); ?></p></noscript>
  413. <?php if ($res['php'] == 'ok') { ?>
  414. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('php_is_ok', PHP_VERSION); ?></p>
  415. <?php } else { ?>
  416. <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>
  417. <?php } ?>
  418. <?php if ($res['minz'] == 'ok') { ?>
  419. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('minz_is_ok'); ?></p>
  420. <?php } else { ?>
  421. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('minz_is_nok', LIB_PATH . '/Minz'); ?></p>
  422. <?php } ?>
  423. <?php if ($res['pdo'] == 'ok') { ?>
  424. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('pdo_is_ok'); ?></p>
  425. <?php } else { ?>
  426. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('pdo_is_nok'); ?></p>
  427. <?php } ?>
  428. <?php if ($res['curl'] == 'ok') { ?>
  429. <?php $version = curl_version(); ?>
  430. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('curl_is_ok', $version['version']); ?></p>
  431. <?php } else { ?>
  432. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('curl_is_nok'); ?></p>
  433. <?php } ?>
  434. <?php if ($res['pcre'] == 'ok') { ?>
  435. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('pcre_is_ok'); ?></p>
  436. <?php } else { ?>
  437. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('pcre_is_nok'); ?></p>
  438. <?php } ?>
  439. <?php if ($res['ctype'] == 'ok') { ?>
  440. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('ctype_is_ok'); ?></p>
  441. <?php } else { ?>
  442. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('ctype_is_nok'); ?></p>
  443. <?php } ?>
  444. <?php if ($res['dom'] == 'ok') { ?>
  445. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('dom_is_ok'); ?></p>
  446. <?php } else { ?>
  447. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('dom_is_nok'); ?></p>
  448. <?php } ?>
  449. <?php if ($res['data'] == 'ok') { ?>
  450. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('data_is_ok'); ?></p>
  451. <?php } else { ?>
  452. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('file_is_nok', DATA_PATH); ?></p>
  453. <?php } ?>
  454. <?php if ($res['cache'] == 'ok') { ?>
  455. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('cache_is_ok'); ?></p>
  456. <?php } else { ?>
  457. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('file_is_nok', CACHE_PATH); ?></p>
  458. <?php } ?>
  459. <?php if ($res['log'] == 'ok') { ?>
  460. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('log_is_ok'); ?></p>
  461. <?php } else { ?>
  462. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('file_is_nok', LOG_PATH); ?></p>
  463. <?php } ?>
  464. <?php if ($res['favicons'] == 'ok') { ?>
  465. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('favicons_is_ok'); ?></p>
  466. <?php } else { ?>
  467. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('file_is_nok', DATA_PATH . '/favicons'); ?></p>
  468. <?php } ?>
  469. <?php if ($res['persona'] == 'ok') { ?>
  470. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('persona_is_ok'); ?></p>
  471. <?php } else { ?>
  472. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('file_is_nok', DATA_PATH . '/persona'); ?></p>
  473. <?php } ?>
  474. <?php if ($res['http_referer'] == 'ok') { ?>
  475. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('http_referer_is_ok'); ?></p>
  476. <?php } else { ?>
  477. <p class="alert alert-error"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('http_referer_is_nok'); ?></p>
  478. <?php } ?>
  479. <?php if ($res['all'] == 'ok') { ?>
  480. <a class="btn btn-important next-step" href="?step=2"><?php echo _t('next_step'); ?></a>
  481. <?php } else { ?>
  482. <p class="alert alert-error"><?php echo _t('fix_errors_before'); ?></p>
  483. <?php } ?>
  484. <?php
  485. }
  486. function printStep2() {
  487. ?>
  488. <?php $s2 = checkStep2(); if ($s2['all'] == 'ok') { ?>
  489. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('general_conf_is_ok'); ?></p>
  490. <?php } elseif (!empty($_POST)) { ?>
  491. <p class="alert alert-error"><?php echo _t('fix_errors_before'); ?></p>
  492. <?php } ?>
  493. <form action="index.php?step=2" method="post">
  494. <legend><?php echo _t('general_configuration'); ?></legend>
  495. <div class="form-group">
  496. <label class="group-name" for="title"><?php echo _t('title'); ?></label>
  497. <div class="group-controls">
  498. <input type="text" id="title" name="title" value="<?php echo isset($_SESSION['title']) ? $_SESSION['title'] : _t('freshrss'); ?>" />
  499. </div>
  500. </div>
  501. <div class="form-group">
  502. <label class="group-name" for="old_entries"><?php echo _t('delete_articles_every'); ?></label>
  503. <div class="group-controls">
  504. <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'); ?>
  505. </div>
  506. </div>
  507. <div class="form-group">
  508. <label class="group-name" for="default_user"><?php echo _t('default_user'); ?></label>
  509. <div class="group-controls">
  510. <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(); ?>" />
  511. </div>
  512. </div>
  513. <div class="form-group">
  514. <label class="group-name" for="auth_type"><?php echo _t('auth_type'); ?></label>
  515. <div class="group-controls">
  516. <select id="auth_type" name="auth_type" required="required" onchange="auth_type_change()">
  517. <?php
  518. function no_auth() {
  519. return !in_array($_SESSION['auth_type'], array('form', 'persona', 'http_auth', 'none'));
  520. }
  521. ?>
  522. <option value="form"<?php echo $_SESSION['auth_type'] === 'form' || no_auth() ? ' selected="selected"' : '', cryptAvailable() ? '' : ' disabled="disabled"'; ?>><?php echo _t('auth_form'); ?></option>
  523. <option value="persona"<?php echo $_SESSION['auth_type'] === 'persona' ? ' selected="selected"' : ''; ?>><?php echo _t('auth_persona'); ?></option>
  524. <option value="http_auth"<?php echo $_SESSION['auth_type'] === 'http_auth' ? ' selected="selected"' : '', httpAuthUser() == '' ? ' disabled="disabled"' : ''; ?>><?php echo _t('http_auth'); ?>(REMOTE_USER = '<?php echo httpAuthUser(); ?>')</option>
  525. <option value="none"<?php echo $_SESSION['auth_type'] === 'none' ? ' selected="selected"' : ''; ?>><?php echo _t('auth_none'); ?></option>
  526. </select>
  527. </div>
  528. </div>
  529. <div class="form-group">
  530. <label class="group-name" for="passwordPlain"><?php echo _t('password_form'); ?></label>
  531. <div class="group-controls">
  532. <div class="stick">
  533. <input type="password" id="passwordPlain" name="passwordPlain" pattern=".{7,}" autocomplete="off" <?php echo $_SESSION['auth_type'] === 'form' ? ' required="required"' : ''; ?> />
  534. <a class="btn toggle-password" data-toggle="passwordPlain"><?php echo FreshRSS_Themes::icon('key'); ?></a>
  535. </div>
  536. <noscript><b><?php echo _t('javascript_should_be_activated'); ?></b></noscript>
  537. </div>
  538. </div>
  539. <div class="form-group">
  540. <label class="group-name" for="mail_login"><?php echo _t('persona_connection_email'); ?></label>
  541. <div class="group-controls">
  542. <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 $_SESSION['auth_type'] === 'persona' ? ' required="required"' : ''; ?> />
  543. <noscript><b><?php echo _t('javascript_should_be_activated'); ?></b></noscript>
  544. </div>
  545. </div>
  546. <script>
  547. function toggle_password() {
  548. var button = this;
  549. var passwordField = document.getElementById(button.getAttribute('data-toggle'));
  550. passwordField.setAttribute('type', 'text');
  551. button.className += ' active';
  552. setTimeout(function() {
  553. passwordField.setAttribute('type', 'password');
  554. button.className = button.className.replace(/(?:^|\s)active(?!\S)/g , '');
  555. }, 2000);
  556. return false;
  557. }
  558. toggles = document.getElementsByClassName('toggle-password');
  559. for (var i = 0 ; i < toggles.length ; i++) {
  560. toggles[i].addEventListener('click', toggle_password);
  561. }
  562. function auth_type_change() {
  563. var auth_value = document.getElementById('auth_type').value,
  564. password_input = document.getElementById('passwordPlain'),
  565. mail_input = document.getElementById('mail_login');
  566. if (auth_value === 'form') {
  567. password_input.required = true;
  568. mail_input.required = false;
  569. } else if (auth_value === 'persona') {
  570. password_input.required = false;
  571. mail_input.required = true;
  572. } else {
  573. password_input.required = false;
  574. mail_input.required = false;
  575. }
  576. }
  577. auth_type_change();
  578. </script>
  579. <div class="form-group form-actions">
  580. <div class="group-controls">
  581. <button type="submit" class="btn btn-important"><?php echo _t('save'); ?></button>
  582. <button type="reset" class="btn"><?php echo _t('cancel'); ?></button>
  583. <?php if ($s2['all'] == 'ok') { ?>
  584. <a class="btn btn-important next-step" href="?step=3"><?php echo _t('next_step'); ?></a>
  585. <?php } ?>
  586. </div>
  587. </div>
  588. </form>
  589. <?php
  590. }
  591. function printStep3() {
  592. ?>
  593. <?php $s3 = checkStep3(); if ($s3['all'] == 'ok') { ?>
  594. <p class="alert alert-success"><span class="alert-head"><?php echo _t('ok'); ?></span> <?php echo _t('bdd_conf_is_ok'); ?></p>
  595. <?php } elseif ($s3['conn'] == 'ko') { ?>
  596. <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>
  597. <?php } ?>
  598. <form action="index.php?step=3" method="post">
  599. <legend><?php echo _t('bdd_configuration'); ?></legend>
  600. <div class="form-group">
  601. <label class="group-name" for="type"><?php echo _t('bdd_type'); ?></label>
  602. <div class="group-controls">
  603. <select name="type" id="type" onchange="mySqlShowHide()">
  604. <?php if (extension_loaded('pdo_mysql')) {?>
  605. <option value="mysql"
  606. <?php echo(isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  607. MySQL
  608. </option>
  609. <?php }?>
  610. <?php if (extension_loaded('pdo_sqlite')) {?>
  611. <option value="sqlite"
  612. <?php echo(isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  613. SQLite
  614. </option>
  615. <?php }?>
  616. </select>
  617. </div>
  618. </div>
  619. <div id="mysql">
  620. <div class="form-group">
  621. <label class="group-name" for="host"><?php echo _t('host'); ?></label>
  622. <div class="group-controls">
  623. <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'; ?>" />
  624. </div>
  625. </div>
  626. <div class="form-group">
  627. <label class="group-name" for="user"><?php echo _t('username'); ?></label>
  628. <div class="group-controls">
  629. <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'] : ''; ?>" />
  630. </div>
  631. </div>
  632. <div class="form-group">
  633. <label class="group-name" for="pass"><?php echo _t('password'); ?></label>
  634. <div class="group-controls">
  635. <input type="password" id="pass" name="pass" value="<?php echo isset($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" />
  636. </div>
  637. </div>
  638. <div class="form-group">
  639. <label class="group-name" for="base"><?php echo _t('bdd'); ?></label>
  640. <div class="group-controls">
  641. <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" />
  642. </div>
  643. </div>
  644. <div class="form-group">
  645. <label class="group-name" for="prefix"><?php echo _t('prefix'); ?></label>
  646. <div class="group-controls">
  647. <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_'; ?>" />
  648. </div>
  649. </div>
  650. </div>
  651. <script>
  652. function mySqlShowHide() {
  653. document.getElementById('mysql').style.display = document.getElementById('type').value === 'mysql' ? 'block' : 'none';
  654. }
  655. mySqlShowHide();
  656. </script>
  657. <div class="form-group form-actions">
  658. <div class="group-controls">
  659. <button type="submit" class="btn btn-important"><?php echo _t('save'); ?></button>
  660. <button type="reset" class="btn"><?php echo _t('cancel'); ?></button>
  661. <?php if ($s3['all'] == 'ok') { ?>
  662. <a class="btn btn-important next-step" href="?step=4"><?php echo _t('next_step'); ?></a>
  663. <?php } ?>
  664. </div>
  665. </div>
  666. </form>
  667. <?php
  668. }
  669. function printStep4() {
  670. ?>
  671. <p class="alert alert-success"><span class="alert-head"><?php echo _t('congratulations'); ?></span> <?php echo _t('installation_is_ok'); ?></p>
  672. <a class="btn btn-important next-step" href="?step=5"><?php echo _t('finish_installation'); ?></a>
  673. <?php
  674. }
  675. function printStep5() {
  676. ?>
  677. <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>
  678. <?php
  679. }
  680. checkStep();
  681. initTranslate();
  682. switch (STEP) {
  683. case 0:
  684. default:
  685. saveLanguage();
  686. break;
  687. case 1:
  688. break;
  689. case 2:
  690. saveStep2();
  691. break;
  692. case 3:
  693. saveStep3();
  694. break;
  695. case 4:
  696. break;
  697. case 5:
  698. deleteInstall();
  699. break;
  700. }
  701. ?>
  702. <!DOCTYPE html>
  703. <html lang="fr">
  704. <head>
  705. <meta charset="utf-8">
  706. <meta name="viewport" content="initial-scale=1.0">
  707. <title><?php echo _t('freshrss_installation'); ?></title>
  708. <link rel="stylesheet" type="text/css" media="all" href="../themes/base-theme/template.css" />
  709. <link rel="stylesheet" type="text/css" media="all" href="../themes/Origine/origine.css" />
  710. </head>
  711. <body>
  712. <div class="header">
  713. <div class="item title">
  714. <h1><a href="index.php"><?php echo _t('freshrss'); ?></a></h1>
  715. <h2><?php echo _t('installation_step', STEP); ?></h2>
  716. </div>
  717. </div>
  718. <div id="global">
  719. <ul class="nav nav-list aside">
  720. <li class="nav-header"><?php echo _t('steps'); ?></li>
  721. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t('language'); ?></a></li>
  722. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t('checks'); ?></a></li>
  723. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t('general_configuration'); ?></a></li>
  724. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t('bdd_configuration'); ?></a></li>
  725. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=5"><?php echo _t('this_is_the_end'); ?></a></li>
  726. </ul>
  727. <div class="post">
  728. <?php
  729. switch (STEP) {
  730. case 0:
  731. default:
  732. printStep0();
  733. break;
  734. case 1:
  735. printStep1();
  736. break;
  737. case 2:
  738. printStep2();
  739. break;
  740. case 3:
  741. printStep3();
  742. break;
  743. case 4:
  744. printStep4();
  745. break;
  746. case 5:
  747. printStep5();
  748. break;
  749. }
  750. ?>
  751. </div>
  752. </div>
  753. </body>
  754. </html>