install.php 35 KB

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