install.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. <?php
  2. require('../../constants.php');
  3. include(LIB_PATH . '/lib_rss.php');
  4. session_name('FreshRSS');
  5. session_set_cookie_params(0, './', null, false, true);
  6. session_start();
  7. if (isset ($_GET['step'])) {
  8. define ('STEP', $_GET['step']);
  9. } else {
  10. define ('STEP', 1);
  11. }
  12. define('SQL_CREATE_DB', 'CREATE DATABASE %1$s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  13. include(APP_PATH . '/sql.php');
  14. //<updates>
  15. define('SQL_SHOW_TABLES', 'SHOW tables;');
  16. define('SQL_BACKUP006', 'RENAME TABLE `%1$scategory` TO `%1$scategory006`, `%1$sfeed` TO `%1$sfeed006`, `%1$sentry` TO `%1$sentry006`;');
  17. define('SQL_SHOW_COLUMNS_UPDATEv006', 'SHOW columns FROM `%1$sentry006` LIKE "id2";');
  18. define('SQL_UPDATEv006', '
  19. ALTER TABLE `%1$scategory006` ADD id2 SMALLINT;
  20. SET @i = 0;
  21. UPDATE `%1$scategory006` SET id2=(@i:=@i+1) ORDER BY id;
  22. ALTER TABLE `%1$sfeed006` ADD id2 SMALLINT, ADD category2 SMALLINT;
  23. SET @i = 0;
  24. UPDATE `%1$sfeed006` SET id2=(@i:=@i+1) ORDER BY name;
  25. UPDATE `%1$sfeed006` f
  26. INNER JOIN `%1$scategory006` c ON f.category = c.id
  27. SET f.category2 = c.id2;
  28. INSERT IGNORE INTO `%2$scategory` (name, color)
  29. SELECT name, color
  30. FROM `%1$scategory006`
  31. ORDER BY id2;
  32. INSERT IGNORE INTO `%2$sfeed` (url, category, name, website, description, priority, pathEntries, httpAuth, keep_history)
  33. SELECT url, category2, name, website, description, priority, pathEntries, httpAuth, IF(keep_history = 1, -1, -2)
  34. FROM `%1$sfeed006`
  35. ORDER BY id2;
  36. ALTER TABLE `%1$sentry006` ADD id2 bigint;
  37. UPDATE `%1$sentry006` SET id2 = ((date * 1000000) + (rand() * 100000000));
  38. INSERT IGNORE INTO `%2$sentry` (id, guid, title, author, link, date, is_read, is_favorite, id_feed, tags)
  39. SELECT e0.id2, e0.guid, e0.title, e0.author, e0.link, e0.date, e0.is_read, e0.is_favorite, f0.id2, e0.tags
  40. FROM `%1$sentry006` e0
  41. INNER JOIN `%1$sfeed006` f0 ON e0.id_feed = f0.id;
  42. ');
  43. define('SQL_CONVERT_SELECTv006', '
  44. SELECT e0.id2, e0.content
  45. FROM `%1$sentry006` e0
  46. INNER JOIN `%2$sentry` e1 ON e0.id2 = e1.id
  47. WHERE e1.content_bin IS NULL');
  48. define('SQL_CONVERT_UPDATEv006', 'UPDATE `%1$sentry` SET content_bin=COMPRESS(?) WHERE id=?;');
  49. define('SQL_DROP_BACKUPv006', 'DROP TABLE IF EXISTS `%1$sentry006`, `%1$sfeed006`, `%1$scategory006`;');
  50. define('SQL_UPDATE_CACHED_VALUES', '
  51. UPDATE `%1$sfeed` f
  52. INNER JOIN (
  53. SELECT e.id_feed,
  54. COUNT(CASE WHEN e.is_read = 0 THEN 1 END) AS nbUnreads,
  55. COUNT(e.id) AS nbEntries
  56. FROM `%1$sentry` e
  57. GROUP BY e.id_feed
  58. ) x ON x.id_feed=f.id
  59. SET f.cache_nbEntries=x.nbEntries, f.cache_nbUnreads=x.nbUnreads
  60. ');
  61. define('SQL_UPDATE_HISTORYv007b', 'UPDATE `%1$sfeed` SET keep_history = CASE WHEN keep_history = 0 THEN -2 WHEN keep_history = 1 THEN -1 ELSE keep_history END;');
  62. //</updates>
  63. // gestion internationalisation
  64. $translates = array ();
  65. $actual = 'en';
  66. function initTranslate () {
  67. global $translates;
  68. global $actual;
  69. $actual = isset($_SESSION['language']) ? $_SESSION['language'] : getBetterLanguage('en');
  70. $file = APP_PATH . '/i18n/' . $actual . '.php';
  71. if (file_exists($file)) {
  72. $translates = array_merge($translates, include($file));
  73. }
  74. $file = APP_PATH . '/i18n/install.' . $actual . '.php';
  75. if (file_exists($file)) {
  76. $translates = array_merge($translates, include($file));
  77. }
  78. }
  79. function getBetterLanguage ($fallback) {
  80. $available = availableLanguages ();
  81. $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  82. $language = strtolower (substr ($accept, 0, 2));
  83. if (isset ($available[$language])) {
  84. return $language;
  85. } else {
  86. return $fallback;
  87. }
  88. }
  89. function availableLanguages () {
  90. return array (
  91. 'en' => 'English',
  92. 'fr' => 'Français'
  93. );
  94. }
  95. function _t ($key) {
  96. global $translates;
  97. $translate = $key;
  98. if (isset ($translates[$key])) {
  99. $translate = $translates[$key];
  100. }
  101. $args = func_get_args ();
  102. unset($args[0]);
  103. return vsprintf ($translate, $args);
  104. }
  105. /*** SAUVEGARDES ***/
  106. function saveLanguage () {
  107. if (!empty ($_POST)) {
  108. if (!isset ($_POST['language'])) {
  109. return false;
  110. }
  111. $_SESSION['language'] = $_POST['language'];
  112. header ('Location: index.php?step=1');
  113. }
  114. }
  115. function saveStep2 () {
  116. if (!empty ($_POST)) {
  117. if (empty ($_POST['title']) ||
  118. empty ($_POST['old_entries']) ||
  119. empty ($_POST['default_user'])) {
  120. return false;
  121. }
  122. $_SESSION['salt'] = sha1(uniqid(mt_rand(), true).implode('', stat(__FILE__)));
  123. $_SESSION['title'] = substr(trim($_POST['title']), 0, 25);
  124. $_SESSION['old_entries'] = $_POST['old_entries'];
  125. if ((!ctype_digit($_SESSION['old_entries'])) || ($_SESSION['old_entries'] < 1)) {
  126. $_SESSION['old_entries'] = 3;
  127. }
  128. $_SESSION['mail_login'] = filter_var($_POST['mail_login'], FILTER_VALIDATE_EMAIL);
  129. $_SESSION['default_user'] = substr(preg_replace('/[^a-zA-Z0-9]/', '', $_POST['default_user']), 0, 16);
  130. $token = '';
  131. if ($_SESSION['mail_login']) {
  132. $token = sha1($_SESSION['salt'] . $_SESSION['mail_login']);
  133. }
  134. $config_array = array (
  135. 'language' => $_SESSION['language'],
  136. 'old_entries' => $_SESSION['old_entries'],
  137. 'mail_login' => $_SESSION['mail_login'],
  138. 'token' => $token,
  139. );
  140. $configPath = DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php';
  141. @unlink($configPath); //To avoid access-rights problems
  142. file_put_contents($configPath, "<?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 (empty ($_POST['type']) ||
  149. empty ($_POST['host']) ||
  150. empty ($_POST['user']) ||
  151. empty ($_POST['base'])) {
  152. $_SESSION['bd_error'] = true;
  153. }
  154. $_SESSION['bd_type'] = isset ($_POST['type']) ? $_POST['type'] : 'mysql';
  155. $_SESSION['bd_host'] = $_POST['host'];
  156. $_SESSION['bd_user'] = $_POST['user'];
  157. $_SESSION['bd_password'] = $_POST['pass'];
  158. $_SESSION['bd_base'] = substr($_POST['base'], 0, 64);
  159. $_SESSION['bd_prefix'] = substr($_POST['prefix'], 0, 16);
  160. $_SESSION['bd_prefix_user'] = $_SESSION['bd_prefix'] . (empty($_SESSION['default_user']) ? '' : ($_SESSION['default_user'] . '_'));
  161. $ini_array = array(
  162. 'general' => array(
  163. 'environment' => empty($_SESSION['environment']) ? 'production' : $_SESSION['environment'],
  164. 'use_url_rewriting' => false,
  165. 'salt' => $_SESSION['salt'],
  166. 'base_url' => '',
  167. 'title' => $_SESSION['title'],
  168. 'default_user' => $_SESSION['default_user'],
  169. ),
  170. 'db' => array(
  171. 'type' => $_SESSION['bd_type'],
  172. 'host' => $_SESSION['bd_host'],
  173. 'user' => $_SESSION['bd_user'],
  174. 'password' => $_SESSION['bd_password'],
  175. 'base' => $_SESSION['bd_base'],
  176. 'prefix' => $_SESSION['bd_prefix'],
  177. ),
  178. );
  179. @unlink(DATA_PATH . '/config.php'); //To avoid access-rights problems
  180. file_put_contents(DATA_PATH . '/config.php', "<?php\n return " . var_export($ini_array, true) . ';');
  181. if (file_exists(DATA_PATH . '/config.php') && file_exists(DATA_PATH . '/application.ini')) {
  182. @unlink(DATA_PATH . '/application.ini'); //v0.6
  183. }
  184. $res = checkBD ();
  185. if ($res) {
  186. $_SESSION['bd_error'] = false;
  187. header ('Location: index.php?step=4');
  188. } else {
  189. $_SESSION['bd_error'] = true;
  190. }
  191. }
  192. invalidateHttpCache();
  193. }
  194. function updateDatabase($perform = false) {
  195. $needs = array('bd_type', 'bd_host', 'bd_base', 'bd_user', 'bd_password', 'bd_prefix', 'bd_prefix_user');
  196. foreach ($needs as $need) {
  197. if (!isset($_SESSION[$need])) {
  198. return false;
  199. }
  200. }
  201. try {
  202. $str = '';
  203. switch ($_SESSION['bd_type']) {
  204. case 'mysql':
  205. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  206. $driver_options = array(
  207. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  208. );
  209. break;
  210. case 'sqlite':
  211. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_base'] . '.sqlite';
  212. $driver_options = null;
  213. break;
  214. default:
  215. return false;
  216. }
  217. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  218. $stm = $c->prepare(SQL_SHOW_TABLES);
  219. $stm->execute();
  220. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  221. if (!in_array($_SESSION['bd_prefix'] . 'entry006', $res)) {
  222. return false;
  223. }
  224. $sql = sprintf(SQL_SHOW_COLUMNS_UPDATEv006, $_SESSION['bd_prefix']);
  225. $stm = $c->prepare($sql);
  226. $stm->execute();
  227. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  228. if (!in_array('id2', $res)) {
  229. if (!$perform) {
  230. return true;
  231. }
  232. $sql = sprintf(SQL_UPDATEv006, $_SESSION['bd_prefix'], $_SESSION['bd_prefix_user']);
  233. $stm = $c->prepare($sql, array(PDO::ATTR_EMULATE_PREPARES => true));
  234. $stm->execute();
  235. }
  236. $sql = sprintf(SQL_UPDATE_HISTORYv007b, $_SESSION['bd_prefix_user']);
  237. $stm = $c->prepare($sql);
  238. $stm->execute();
  239. $sql = sprintf(SQL_UPDATE_CACHED_VALUES, $_SESSION['bd_prefix_user']);
  240. $stm = $c->prepare($sql);
  241. $stm->execute();
  242. $sql = sprintf(SQL_CONVERT_SELECTv006, $_SESSION['bd_prefix'], $_SESSION['bd_prefix_user']);
  243. if (!$perform) {
  244. $sql .= ' LIMIT 1';
  245. }
  246. $stm = $c->prepare($sql);
  247. $stm->execute();
  248. if (!$perform) {
  249. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  250. return count($res) > 0;
  251. } else {
  252. @set_time_limit(300);
  253. }
  254. $c2 = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  255. $sql = sprintf(SQL_CONVERT_UPDATEv006, $_SESSION['bd_prefix_user']);
  256. $stm2 = $c2->prepare($sql);
  257. while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
  258. $id = $row['id2'];
  259. $content = unserialize(gzinflate(base64_decode($row['content'])));
  260. $stm2->execute(array($content, $id));
  261. }
  262. return true;
  263. } catch (PDOException $e) {
  264. return false;
  265. }
  266. return false;
  267. }
  268. function deleteInstall () {
  269. $res = unlink (INDEX_PATH . '/install.php');
  270. if ($res) {
  271. header ('Location: index.php');
  272. }
  273. $needs = array('bd_type', 'bd_host', 'bd_base', 'bd_user', 'bd_password', 'bd_prefix');
  274. foreach ($needs as $need) {
  275. if (!isset($_SESSION[$need])) {
  276. return false;
  277. }
  278. }
  279. try {
  280. switch ($_SESSION['bd_type']) {
  281. case 'mysql':
  282. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  283. $driver_options = array(
  284. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  285. );
  286. break;
  287. case 'sqlite':
  288. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_base'] . '.sqlite';
  289. $driver_options = null;
  290. break;
  291. default:
  292. return false;
  293. }
  294. $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  295. $sql = sprintf(SQL_DROP_BACKUPv006, $_SESSION['bd_prefix']);
  296. $stm = $c->prepare($sql);
  297. $stm->execute();
  298. return true;
  299. } catch (PDOException $e) {
  300. return false;
  301. }
  302. return false;
  303. }
  304. function moveOldFiles() {
  305. $mvs = array(
  306. '/app/configuration/application.ini' => '/data/application.ini', //v0.6
  307. '/public/data/Configuration.array.php' => '/data/Configuration.array.php', //v0.6
  308. );
  309. $ok = true;
  310. foreach ($mvs as $fFrom => $fTo) {
  311. if (file_exists(FRESHRSS_PATH . $fFrom)) {
  312. if (copy(FRESHRSS_PATH . $fFrom, FRESHRSS_PATH . $fTo)) {
  313. @unlink(FRESHRSS_PATH . $fFrom);
  314. } else {
  315. $ok = false;
  316. }
  317. }
  318. }
  319. return $ok;
  320. }
  321. function delTree($dir) { //http://php.net/rmdir#110489
  322. if (!is_dir($dir)) {
  323. return true;
  324. }
  325. $files = array_diff(scandir($dir), array('.', '..'));
  326. foreach ($files as $file) {
  327. $f = $dir . '/' . $file;
  328. if (is_dir($f)) {
  329. @chmod($f, 0777);
  330. delTree($f);
  331. }
  332. else unlink($f);
  333. }
  334. return rmdir($dir);
  335. }
  336. /*** VÉRIFICATIONS ***/
  337. function checkStep () {
  338. $s0 = checkStep0 ();
  339. $s1 = checkStep1 ();
  340. $s2 = checkStep2 ();
  341. $s3 = checkStep3 ();
  342. if (STEP > 0 && $s0['all'] != 'ok') {
  343. header ('Location: index.php?step=0');
  344. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  345. header ('Location: index.php?step=1');
  346. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  347. header ('Location: index.php?step=2');
  348. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  349. header ('Location: index.php?step=3');
  350. }
  351. $_SESSION['actualize_feeds'] = true;
  352. }
  353. function checkStep0 () {
  354. moveOldFiles();
  355. if (file_exists(DATA_PATH . '/config.php')) {
  356. $ini_array = include(DATA_PATH . '/config.php');
  357. } elseif (file_exists(DATA_PATH . '/application.ini')) {
  358. $ini_array = parse_ini_file(DATA_PATH . '/application.ini', true);
  359. } else {
  360. $ini_array = null;
  361. }
  362. if ($ini_array) {
  363. $ini_general = isset($ini_array['general']) ? $ini_array['general'] : null;
  364. if ($ini_general) {
  365. $keys = array('environment', 'salt', 'title', 'default_user');
  366. foreach ($keys as $key) {
  367. if ((empty($_SESSION[$key])) && isset($ini_general[$key])) {
  368. $_SESSION[$key] = $ini_general[$key];
  369. }
  370. }
  371. }
  372. $ini_db = isset($ini_array['db']) ? $ini_array['db'] : null;
  373. if ($ini_db) {
  374. $keys = array('type', 'host', 'user', 'password', 'base', 'prefix');
  375. foreach ($keys as $key) {
  376. if ((!isset($_SESSION['bd_' . $key])) && isset($ini_db[$key])) {
  377. $_SESSION['bd_' . $key] = $ini_db[$key];
  378. }
  379. }
  380. }
  381. }
  382. if (isset($_SESSION['default_user']) && file_exists(DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php')) {
  383. $userConfig = include(DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php');
  384. } elseif (file_exists(DATA_PATH . '/Configuration.array.php')) {
  385. $userConfig = include(DATA_PATH . '/Configuration.array.php'); //v0.6
  386. } else {
  387. $userConfig = array();
  388. }
  389. $keys = array('language', 'old_entries', 'mail_login');
  390. foreach ($keys as $key) {
  391. if ((!isset($_SESSION[$key])) && isset($userConfig[$key])) {
  392. $_SESSION[$key] = $userConfig[$key];
  393. }
  394. }
  395. $languages = availableLanguages ();
  396. $language = isset ($_SESSION['language']) &&
  397. isset ($languages[$_SESSION['language']]);
  398. return array (
  399. 'language' => $language ? 'ok' : 'ko',
  400. 'all' => $language ? 'ok' : 'ko'
  401. );
  402. }
  403. function checkStep1 () {
  404. $php = version_compare (PHP_VERSION, '5.2.0') >= 0;
  405. $minz = file_exists (LIB_PATH . '/Minz');
  406. $curl = extension_loaded ('curl');
  407. $pdo = extension_loaded ('pdo_mysql');
  408. $pcre = extension_loaded ('pcre');
  409. $ctype = extension_loaded ('ctype');
  410. $dom = class_exists('DOMDocument');
  411. $data = DATA_PATH && is_writable (DATA_PATH);
  412. $cache = CACHE_PATH && is_writable (CACHE_PATH);
  413. $log = LOG_PATH && is_writable (LOG_PATH);
  414. $favicons = is_writable (DATA_PATH . '/favicons');
  415. return array (
  416. 'php' => $php ? 'ok' : 'ko',
  417. 'minz' => $minz ? 'ok' : 'ko',
  418. 'curl' => $curl ? 'ok' : 'ko',
  419. 'pdo-mysql' => $pdo ? 'ok' : 'ko',
  420. 'pcre' => $pcre ? 'ok' : 'ko',
  421. 'ctype' => $ctype ? 'ok' : 'ko',
  422. 'dom' => $dom ? 'ok' : 'ko',
  423. 'data' => $data ? 'ok' : 'ko',
  424. 'cache' => $cache ? 'ok' : 'ko',
  425. 'log' => $log ? 'ok' : 'ko',
  426. 'favicons' => $favicons ? 'ok' : 'ko',
  427. 'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $dom && $data && $cache && $log && $favicons ? 'ok' : 'ko'
  428. );
  429. }
  430. function checkStep2 () {
  431. $conf = !empty($_SESSION['salt']) &&
  432. !empty($_SESSION['title']) &&
  433. !empty($_SESSION['old_entries']) &&
  434. isset($_SESSION['mail_login']) &&
  435. !empty($_SESSION['default_user']);
  436. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  437. if ($defaultUser === null) {
  438. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  439. }
  440. $data = is_writable(DATA_PATH . '/' . $defaultUser . '_user.php');
  441. if ($data) {
  442. @unlink(DATA_PATH . '/Configuration.array.php'); //v0.6
  443. }
  444. return array (
  445. 'conf' => $conf ? 'ok' : 'ko',
  446. 'data' => $data ? 'ok' : 'ko',
  447. 'all' => $conf && $data ? 'ok' : 'ko'
  448. );
  449. }
  450. function checkStep3 () {
  451. $conf = is_writable(DATA_PATH . '/config.php');
  452. $bd = isset ($_SESSION['bd_type']) &&
  453. isset ($_SESSION['bd_host']) &&
  454. isset ($_SESSION['bd_user']) &&
  455. isset ($_SESSION['bd_password']) &&
  456. isset ($_SESSION['bd_base']) &&
  457. isset ($_SESSION['bd_prefix']) &&
  458. isset ($_SESSION['bd_error']);
  459. $conn = !isset ($_SESSION['bd_error']) || !$_SESSION['bd_error'];
  460. return array (
  461. 'bd' => $bd ? 'ok' : 'ko',
  462. 'conn' => $conn ? 'ok' : 'ko',
  463. 'conf' => $conf ? 'ok' : 'ko',
  464. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  465. );
  466. }
  467. function checkBD () {
  468. $ok = false;
  469. try {
  470. $str = '';
  471. $driver_options = null;
  472. switch ($_SESSION['bd_type']) {
  473. case 'mysql':
  474. $driver_options = array(
  475. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  476. );
  477. // on ouvre une connexion juste pour créer la base si elle n'existe pas
  478. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  479. $c = new PDO ($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  480. $sql = sprintf (SQL_CREATE_DB, $_SESSION['bd_base']);
  481. $res = $c->query ($sql);
  482. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  483. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  484. break;
  485. case 'sqlite':
  486. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_base'] . '.sqlite';
  487. break;
  488. default:
  489. return false;
  490. }
  491. $c = new PDO ($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  492. $stm = $c->prepare(SQL_SHOW_TABLES);
  493. $stm->execute();
  494. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  495. if (in_array($_SESSION['bd_prefix'] . 'entry', $res) && !in_array($_SESSION['bd_prefix'] . 'entry006', $res)) {
  496. $sql = sprintf(SQL_BACKUP006, $_SESSION['bd_prefix']); //v0.6
  497. $res = $c->query($sql); //Backup tables
  498. }
  499. $sql = sprintf(SQL_CREATE_TABLES, $_SESSION['bd_prefix_user']);
  500. $stm = $c->prepare($sql, array(PDO::ATTR_EMULATE_PREPARES => true));
  501. $ok = $stm->execute();
  502. } catch (PDOException $e) {
  503. $error = true;
  504. }
  505. if (!$ok) {
  506. @unlink(DATA_PATH . '/config.php');
  507. }
  508. return $ok;
  509. }
  510. /*** AFFICHAGE ***/
  511. function printStep0 () {
  512. global $actual;
  513. ?>
  514. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  515. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  516. <?php } ?>
  517. <form action="index.php?step=0" method="post">
  518. <legend><?php echo _t ('choose_language'); ?></legend>
  519. <div class="form-group">
  520. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  521. <div class="group-controls">
  522. <select name="language" id="language">
  523. <?php $languages = availableLanguages (); ?>
  524. <?php foreach ($languages as $short => $lib) { ?>
  525. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  526. <?php } ?>
  527. </select>
  528. </div>
  529. </div>
  530. <div class="form-group form-actions">
  531. <div class="group-controls">
  532. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  533. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  534. <?php if ($s0['all'] == 'ok') { ?>
  535. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  536. <?php } ?>
  537. </div>
  538. </div>
  539. </form>
  540. <?php
  541. }
  542. function printStep1 () {
  543. $res = checkStep1 ();
  544. ?>
  545. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  546. <?php if ($res['php'] == 'ok') { ?>
  547. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  548. <?php } else { ?>
  549. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('php_is_nok', PHP_VERSION, '5.1.0'); ?></p>
  550. <?php } ?>
  551. <?php if ($res['minz'] == 'ok') { ?>
  552. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  553. <?php } else { ?>
  554. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/Minz'); ?></p>
  555. <?php } ?>
  556. <?php if ($res['pdo-mysql'] == 'ok') { ?>
  557. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdomysql_is_ok'); ?></p>
  558. <?php } else { ?>
  559. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdomysql_is_nok'); ?></p>
  560. <?php } ?>
  561. <?php if ($res['curl'] == 'ok') { ?>
  562. <?php $version = curl_version(); ?>
  563. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  564. <?php } else { ?>
  565. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  566. <?php } ?>
  567. <?php if ($res['pcre'] == 'ok') { ?>
  568. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pcre_is_ok'); ?></p>
  569. <?php } else { ?>
  570. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pcre_is_nok'); ?></p>
  571. <?php } ?>
  572. <?php if ($res['ctype'] == 'ok') { ?>
  573. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('ctype_is_ok'); ?></p>
  574. <?php } else { ?>
  575. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('ctype_is_nok'); ?></p>
  576. <?php } ?>
  577. <?php if ($res['dom'] == 'ok') { ?>
  578. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  579. <?php } else { ?>
  580. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  581. <?php } ?>
  582. <?php if ($res['data'] == 'ok') { ?>
  583. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  584. <?php } else { ?>
  585. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH); ?></p>
  586. <?php } ?>
  587. <?php if ($res['cache'] == 'ok') { ?>
  588. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  589. <?php } else { ?>
  590. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', CACHE_PATH); ?></p>
  591. <?php } ?>
  592. <?php if ($res['log'] == 'ok') { ?>
  593. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  594. <?php } else { ?>
  595. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', LOG_PATH); ?></p>
  596. <?php } ?>
  597. <?php if ($res['favicons'] == 'ok') { ?>
  598. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('favicons_is_ok'); ?></p>
  599. <?php } else { ?>
  600. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH . '/favicons'); ?></p>
  601. <?php } ?>
  602. <?php if ($res['all'] == 'ok') { ?>
  603. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  604. <?php } else { ?>
  605. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  606. <?php } ?>
  607. <?php
  608. }
  609. function printStep2 () {
  610. ?>
  611. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  612. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  613. <?php } ?>
  614. <form action="index.php?step=2" method="post">
  615. <legend><?php echo _t ('general_configuration'); ?></legend>
  616. <div class="form-group">
  617. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  618. <div class="group-controls">
  619. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  620. </div>
  621. </div>
  622. <div class="form-group">
  623. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  624. <div class="group-controls">
  625. <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'] : '3'; ?>" /> <?php echo _t ('month'); ?>
  626. </div>
  627. </div>
  628. <div class="form-group">
  629. <label class="group-name" for="default_user"><?php echo _t ('default_user'); ?></label>
  630. <div class="group-controls">
  631. <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() == '' ? 'user1' : httpAuthUser(); ?>" />
  632. </div>
  633. </div>
  634. <div class="form-group">
  635. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  636. <div class="group-controls">
  637. <input type="email" id="mail_login" name="mail_login" value="<?php echo isset ($_SESSION['mail_login']) ? $_SESSION['mail_login'] : ''; ?>" placeholder="<?php echo _t ('blank_to_disable'); ?>" />
  638. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  639. </div>
  640. </div>
  641. <div class="form-group form-actions">
  642. <div class="group-controls">
  643. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  644. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  645. <?php if ($s2['all'] == 'ok') { ?>
  646. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  647. <?php } ?>
  648. </div>
  649. </div>
  650. </form>
  651. <?php
  652. }
  653. function printStep3 () {
  654. ?>
  655. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  656. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  657. <?php } elseif ($s3['conn'] == 'ko') { ?>
  658. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('bdd_conf_is_ko'); ?></p>
  659. <?php } ?>
  660. <form action="index.php?step=3" method="post">
  661. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  662. <div class="form-group">
  663. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  664. <div class="group-controls">
  665. <select name="type" id="type">
  666. <option value="mysql"
  667. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  668. MySQL
  669. </option>
  670. <!-- TODO : l'utilisation de SQLite n'est pas encore possible. Pour tester tout de même, décommentez ce bloc
  671. <option value="sqlite"
  672. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  673. SQLite
  674. </option>-->
  675. </select>
  676. </div>
  677. </div>
  678. <div class="form-group">
  679. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  680. <div class="group-controls">
  681. <input type="text" id="host" name="host" pattern="[0-9A-Za-z_.-]{1,64}" value="<?php echo isset ($_SESSION['bd_host']) ? $_SESSION['bd_host'] : 'localhost'; ?>" />
  682. </div>
  683. </div>
  684. <div class="form-group">
  685. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  686. <div class="group-controls">
  687. <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'] : ''; ?>" />
  688. </div>
  689. </div>
  690. <div class="form-group">
  691. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  692. <div class="group-controls">
  693. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" />
  694. </div>
  695. </div>
  696. <div class="form-group">
  697. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  698. <div class="group-controls">
  699. <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'] : ''; ?>" placeholder="freshrss" />
  700. </div>
  701. </div>
  702. <div class="form-group">
  703. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  704. <div class="group-controls">
  705. <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'] : 'freshrss_'; ?>" />
  706. </div>
  707. </div>
  708. <div class="form-group form-actions">
  709. <div class="group-controls">
  710. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  711. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  712. <?php if ($s3['all'] == 'ok') { ?>
  713. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  714. <?php } ?>
  715. </div>
  716. </div>
  717. </form>
  718. <?php
  719. }
  720. function printStep4 () {
  721. ?>
  722. <form action="index.php?step=4" method="post">
  723. <legend><?php echo _t ('version_update'); ?></legend>
  724. <div class="form-group form-actions">
  725. <div class="group-controls">
  726. <?php if (updateDatabase(false)) { ?>
  727. <input type="hidden" name="updateDatabase" value="1" />
  728. <button type="submit" class="btn btn-important"><?php echo _t ('update_start'); ?></button>
  729. <p><?php echo _t ('update_long'); ?></p>
  730. <?php } else { ?>
  731. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('next_step'); ?></a>
  732. <?php } ?>
  733. </div>
  734. </div>
  735. </form>
  736. <?php
  737. }
  738. function printStep5 () {
  739. ?>
  740. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  741. <a class="btn btn-important next-step" href="?step=6"><?php echo _t ('finish_installation'); ?></a>
  742. <?php
  743. }
  744. function printStep6 () {
  745. ?>
  746. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('oops'); ?></span> <?php echo _t ('install_not_deleted', INDEX_PATH . '/install.php'); ?></p>
  747. <?php
  748. }
  749. checkStep ();
  750. initTranslate ();
  751. switch (STEP) {
  752. case 0:
  753. default:
  754. saveLanguage ();
  755. break;
  756. case 1:
  757. break;
  758. case 2:
  759. saveStep2 ();
  760. break;
  761. case 3:
  762. saveStep3 ();
  763. break;
  764. case 4:
  765. if (!empty($_POST['updateDatabase'])) {
  766. updateDatabase(true);
  767. }
  768. break;
  769. case 5:
  770. break;
  771. case 6:
  772. deleteInstall ();
  773. break;
  774. }
  775. ?>
  776. <!DOCTYPE html>
  777. <html lang="fr">
  778. <head>
  779. <meta charset="utf-8">
  780. <meta name="viewport" content="initial-scale=1.0">
  781. <title><?php echo _t ('freshrss_installation'); ?></title>
  782. <link rel="stylesheet" type="text/css" media="all" href="../themes/default/global.css" />
  783. <link rel="stylesheet" type="text/css" media="all" href="../themes/default/freshrss.css" />
  784. </head>
  785. <body>
  786. <div class="header">
  787. <div class="item title">
  788. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  789. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  790. </div>
  791. </div>
  792. <div id="global">
  793. <ul class="nav nav-list aside">
  794. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  795. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  796. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  797. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  798. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  799. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('version_update'); ?></a></li>
  800. <li class="item<?php echo STEP == 5 ? ' active' : ''; ?>"><a href="?step=5"><?php echo _t ('this_is_the_end'); ?></a></li>
  801. </ul>
  802. <div class="post">
  803. <?php
  804. switch (STEP) {
  805. case 0:
  806. default:
  807. printStep0 ();
  808. break;
  809. case 1:
  810. printStep1 ();
  811. break;
  812. case 2:
  813. printStep2 ();
  814. break;
  815. case 3:
  816. printStep3 ();
  817. break;
  818. case 4:
  819. printStep4 ();
  820. break;
  821. case 5:
  822. printStep5 ();
  823. break;
  824. case 6:
  825. printStep6 ();
  826. break;
  827. }
  828. ?>
  829. </div>
  830. </div>
  831. </body>
  832. </html>