install.php 33 KB

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