install.php 32 KB

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