install.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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['bd_base'] . '.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['bd_base'] . '.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">
  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 class="form-group">
  819. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  820. <div class="group-controls">
  821. <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'; ?>" />
  822. </div>
  823. </div>
  824. <div class="form-group">
  825. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  826. <div class="group-controls">
  827. <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'] : ''; ?>" />
  828. </div>
  829. </div>
  830. <div class="form-group">
  831. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  832. <div class="group-controls">
  833. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" />
  834. </div>
  835. </div>
  836. <div class="form-group">
  837. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  838. <div class="group-controls">
  839. <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" />
  840. </div>
  841. </div>
  842. <div class="form-group">
  843. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  844. <div class="group-controls">
  845. <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_'; ?>" />
  846. </div>
  847. </div>
  848. <div class="form-group form-actions">
  849. <div class="group-controls">
  850. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  851. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  852. <?php if ($s3['all'] == 'ok') { ?>
  853. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  854. <?php } ?>
  855. </div>
  856. </div>
  857. </form>
  858. <?php
  859. }
  860. function printStep4 () {
  861. ?>
  862. <form action="index.php?step=4" method="post">
  863. <legend><?php echo _t ('version_update'); ?></legend>
  864. <?php if (updateDatabase(false)) { ?>
  865. <p class="alert alert-warn"><?php echo _t ('update_long'); ?></p>
  866. <div class="form-group form-actions">
  867. <div class="group-controls">
  868. <input type="hidden" name="updateDatabase" value="1" />
  869. <button type="submit" class="btn btn-important"><?php echo _t ('update_start'); ?></button>
  870. </div>
  871. </div>
  872. <?php } else { ?>
  873. <p class="alert alert-warn"><?php echo _t ('update_end'); ?></p>
  874. <div class="form-group form-actions">
  875. <div class="group-controls">
  876. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('next_step'); ?></a>
  877. </div>
  878. </div>
  879. <?php } ?>
  880. </form>
  881. <?php
  882. }
  883. function printStep5 () {
  884. ?>
  885. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  886. <a class="btn btn-important next-step" href="?step=6"><?php echo _t ('finish_installation'); ?></a>
  887. <?php
  888. }
  889. function printStep6 () {
  890. ?>
  891. <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>
  892. <?php
  893. }
  894. checkStep ();
  895. initTranslate ();
  896. switch (STEP) {
  897. case 0:
  898. default:
  899. saveLanguage ();
  900. break;
  901. case 1:
  902. break;
  903. case 2:
  904. saveStep2 ();
  905. break;
  906. case 3:
  907. saveStep3 ();
  908. break;
  909. case 4:
  910. if (!empty($_POST['updateDatabase'])) {
  911. updateDatabase(true);
  912. }
  913. break;
  914. case 5:
  915. postUpdate();
  916. break;
  917. case 6:
  918. deleteInstall ();
  919. break;
  920. }
  921. ?>
  922. <!DOCTYPE html>
  923. <html lang="fr">
  924. <head>
  925. <meta charset="utf-8">
  926. <meta name="viewport" content="initial-scale=1.0">
  927. <title><?php echo _t ('freshrss_installation'); ?></title>
  928. <link rel="stylesheet" type="text/css" media="all" href="../themes/Origine/template.css" />
  929. <link rel="stylesheet" type="text/css" media="all" href="../themes/Origine/origine.css" />
  930. </head>
  931. <body>
  932. <div class="header">
  933. <div class="item title">
  934. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  935. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  936. </div>
  937. </div>
  938. <div id="global">
  939. <ul class="nav nav-list aside">
  940. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  941. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  942. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  943. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  944. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  945. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('version_update'); ?></a></li>
  946. <li class="item<?php echo STEP == 5 ? ' active' : ''; ?>"><a href="?step=5"><?php echo _t ('this_is_the_end'); ?></a></li>
  947. </ul>
  948. <div class="post">
  949. <?php
  950. switch (STEP) {
  951. case 0:
  952. default:
  953. printStep0 ();
  954. break;
  955. case 1:
  956. printStep1 ();
  957. break;
  958. case 2:
  959. printStep2 ();
  960. break;
  961. case 3:
  962. printStep3 ();
  963. break;
  964. case 4:
  965. printStep4 ();
  966. break;
  967. case 5:
  968. printStep5 ();
  969. break;
  970. case 6:
  971. printStep6 ();
  972. break;
  973. }
  974. ?>
  975. </div>
  976. </div>
  977. </body>
  978. </html>