install.php 37 KB

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