install.php 34 KB

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