install.php 32 KB

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