install.php 31 KB

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