install.php 30 KB

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