install.php 37 KB

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