install.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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. 'allow_anonymous' => isset($_SESSION['allow_anonymous']) ? $_SESSION['allow_anonymous'] : false,
  210. 'allow_anonymous_refresh' => isset($_SESSION['allow_anonymous_refresh']) ? $_SESSION['allow_anonymous_refresh'] : false,
  211. 'auth_type' => $_SESSION['auth_type'],
  212. 'api_enabled' => isset($_SESSION['api_enabled']) ? $_SESSION['api_enabled'] : false,
  213. 'unsafe_autologin_enabled' => isset($_SESSION['unsafe_autologin_enabled']) ? $_SESSION['unsafe_autologin_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', 'allow_anonymous_refresh', 'auth_type', 'api_enabled', 'unsafe_autologin_enabled');
  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_mysql = extension_loaded ('pdo_mysql');
  503. $pdo_sqlite = extension_loaded ('pdo_sqlite');
  504. $pdo = $pdo_mysql || $pdo_sqlite;
  505. $pcre = extension_loaded ('pcre');
  506. $ctype = extension_loaded ('ctype');
  507. $dom = class_exists('DOMDocument');
  508. $data = DATA_PATH && is_writable (DATA_PATH);
  509. $cache = CACHE_PATH && is_writable (CACHE_PATH);
  510. $log = LOG_PATH && is_writable (LOG_PATH);
  511. $favicons = is_writable (DATA_PATH . '/favicons');
  512. $persona = is_writable (DATA_PATH . '/persona');
  513. return array (
  514. 'php' => $php ? 'ok' : 'ko',
  515. 'minz' => $minz ? 'ok' : 'ko',
  516. 'curl' => $curl ? 'ok' : 'ko',
  517. 'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko',
  518. 'pdo-sqlite' => $pdo_sqlite ? 'ok' : 'ko',
  519. 'pdo' => $pdo ? 'ok' : 'ko',
  520. 'pcre' => $pcre ? 'ok' : 'ko',
  521. 'ctype' => $ctype ? 'ok' : 'ko',
  522. 'dom' => $dom ? 'ok' : 'ko',
  523. 'data' => $data ? 'ok' : 'ko',
  524. 'cache' => $cache ? 'ok' : 'ko',
  525. 'log' => $log ? 'ok' : 'ko',
  526. 'favicons' => $favicons ? 'ok' : 'ko',
  527. 'persona' => $persona ? 'ok' : 'ko',
  528. 'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $dom && $data && $cache && $log && $favicons && $persona ? 'ok' : 'ko'
  529. );
  530. }
  531. function checkStep2 () {
  532. $conf = !empty($_SESSION['salt']) &&
  533. !empty($_SESSION['title']) &&
  534. !empty($_SESSION['old_entries']) &&
  535. isset($_SESSION['mail_login']) &&
  536. !empty($_SESSION['default_user']);
  537. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  538. if ($defaultUser === null) {
  539. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  540. }
  541. $data = is_writable(DATA_PATH . '/' . $defaultUser . '_user.php');
  542. if ($data) {
  543. @unlink(DATA_PATH . '/Configuration.array.php'); //v0.6
  544. }
  545. return array (
  546. 'conf' => $conf ? 'ok' : 'ko',
  547. 'data' => $data ? 'ok' : 'ko',
  548. 'all' => $conf && $data ? 'ok' : 'ko'
  549. );
  550. }
  551. function checkStep3 () {
  552. $conf = is_writable(DATA_PATH . '/config.php');
  553. $bd = isset ($_SESSION['bd_type']) &&
  554. isset ($_SESSION['bd_host']) &&
  555. isset ($_SESSION['bd_user']) &&
  556. isset ($_SESSION['bd_password']) &&
  557. isset ($_SESSION['bd_base']) &&
  558. isset ($_SESSION['bd_prefix']) &&
  559. isset ($_SESSION['bd_error']);
  560. $conn = empty($_SESSION['bd_error']);
  561. return array (
  562. 'bd' => $bd ? 'ok' : 'ko',
  563. 'conn' => $conn ? 'ok' : 'ko',
  564. 'conf' => $conf ? 'ok' : 'ko',
  565. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  566. );
  567. }
  568. function checkBD () {
  569. $ok = false;
  570. try {
  571. $str = '';
  572. $driver_options = null;
  573. switch ($_SESSION['bd_type']) {
  574. case 'mysql':
  575. $driver_options = array(
  576. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  577. );
  578. try { // on ouvre une connexion juste pour créer la base si elle n'existe pas
  579. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  580. $c = new PDO ($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  581. $sql = sprintf (SQL_CREATE_DB, $_SESSION['bd_base']);
  582. $res = $c->query ($sql);
  583. } catch (PDOException $e) {
  584. }
  585. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  586. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  587. break;
  588. case 'sqlite':
  589. $str = 'sqlite:' . DATA_PATH . '/' . $_SESSION['default_user'] . '.sqlite';
  590. $driver_options = array(
  591. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  592. );
  593. break;
  594. default:
  595. return false;
  596. }
  597. $c = new PDO ($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options);
  598. if ($_SESSION['bd_type'] !== 'sqlite') { //No SQL backup for SQLite
  599. $stm = $c->prepare(SQL_SHOW_TABLES);
  600. $stm->execute();
  601. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  602. if (in_array($_SESSION['bd_prefix'] . 'entry', $res) && !in_array($_SESSION['bd_prefix'] . 'entry006', $res)) {
  603. $sql = sprintf(SQL_BACKUP006, $_SESSION['bd_prefix']); //v0.6
  604. $res = $c->query($sql); //Backup tables
  605. }
  606. }
  607. if (defined('SQL_CREATE_TABLES')) {
  608. $sql = sprintf(SQL_CREATE_TABLES, $_SESSION['bd_prefix_user'], _t('default_category'));
  609. $stm = $c->prepare($sql);
  610. $ok = $stm->execute();
  611. } else {
  612. global $SQL_CREATE_TABLES;
  613. if (is_array($SQL_CREATE_TABLES)) {
  614. $ok = true;
  615. foreach ($SQL_CREATE_TABLES as $instruction) {
  616. $sql = sprintf($instruction, $_SESSION['bd_prefix_user'], _t('default_category'));
  617. $stm = $c->prepare($sql);
  618. $ok &= $stm->execute();
  619. }
  620. }
  621. }
  622. } catch (PDOException $e) {
  623. $ok = false;
  624. $_SESSION['bd_error'] = $e->getMessage();
  625. }
  626. if (!$ok) {
  627. @unlink(DATA_PATH . '/config.php');
  628. }
  629. return $ok;
  630. }
  631. /*** AFFICHAGE ***/
  632. function printStep0 () {
  633. global $actual;
  634. ?>
  635. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  636. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  637. <?php } ?>
  638. <form action="index.php?step=0" method="post">
  639. <legend><?php echo _t ('choose_language'); ?></legend>
  640. <div class="form-group">
  641. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  642. <div class="group-controls">
  643. <select name="language" id="language">
  644. <?php $languages = availableLanguages (); ?>
  645. <?php foreach ($languages as $short => $lib) { ?>
  646. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  647. <?php } ?>
  648. </select>
  649. </div>
  650. </div>
  651. <div class="form-group form-actions">
  652. <div class="group-controls">
  653. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  654. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  655. <?php if ($s0['all'] == 'ok') { ?>
  656. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  657. <?php } ?>
  658. </div>
  659. </div>
  660. </form>
  661. <?php
  662. }
  663. function printStep1 () {
  664. $res = checkStep1 ();
  665. ?>
  666. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  667. <?php if ($res['php'] == 'ok') { ?>
  668. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  669. <?php } else { ?>
  670. <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>
  671. <?php } ?>
  672. <?php if ($res['minz'] == 'ok') { ?>
  673. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  674. <?php } else { ?>
  675. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/Minz'); ?></p>
  676. <?php } ?>
  677. <?php if ($res['pdo'] == 'ok') { ?>
  678. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdo_is_ok'); ?></p>
  679. <?php } else { ?>
  680. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdo_is_nok'); ?></p>
  681. <?php } ?>
  682. <?php if ($res['curl'] == 'ok') { ?>
  683. <?php $version = curl_version(); ?>
  684. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  685. <?php } else { ?>
  686. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  687. <?php } ?>
  688. <?php if ($res['pcre'] == 'ok') { ?>
  689. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pcre_is_ok'); ?></p>
  690. <?php } else { ?>
  691. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pcre_is_nok'); ?></p>
  692. <?php } ?>
  693. <?php if ($res['ctype'] == 'ok') { ?>
  694. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('ctype_is_ok'); ?></p>
  695. <?php } else { ?>
  696. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('ctype_is_nok'); ?></p>
  697. <?php } ?>
  698. <?php if ($res['dom'] == 'ok') { ?>
  699. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  700. <?php } else { ?>
  701. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  702. <?php } ?>
  703. <?php if ($res['data'] == 'ok') { ?>
  704. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  705. <?php } else { ?>
  706. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH); ?></p>
  707. <?php } ?>
  708. <?php if ($res['cache'] == 'ok') { ?>
  709. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  710. <?php } else { ?>
  711. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', CACHE_PATH); ?></p>
  712. <?php } ?>
  713. <?php if ($res['log'] == 'ok') { ?>
  714. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  715. <?php } else { ?>
  716. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', LOG_PATH); ?></p>
  717. <?php } ?>
  718. <?php if ($res['favicons'] == 'ok') { ?>
  719. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('favicons_is_ok'); ?></p>
  720. <?php } else { ?>
  721. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH . '/favicons'); ?></p>
  722. <?php } ?>
  723. <?php if ($res['persona'] == 'ok') { ?>
  724. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('persona_is_ok'); ?></p>
  725. <?php } else { ?>
  726. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH . '/persona'); ?></p>
  727. <?php } ?>
  728. <?php if ($res['all'] == 'ok') { ?>
  729. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  730. <?php } else { ?>
  731. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  732. <?php } ?>
  733. <?php
  734. }
  735. function printStep2 () {
  736. ?>
  737. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  738. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  739. <?php } ?>
  740. <form action="index.php?step=2" method="post">
  741. <legend><?php echo _t ('general_configuration'); ?></legend>
  742. <div class="form-group">
  743. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  744. <div class="group-controls">
  745. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  746. </div>
  747. </div>
  748. <div class="form-group">
  749. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  750. <div class="group-controls">
  751. <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'); ?>
  752. </div>
  753. </div>
  754. <div class="form-group">
  755. <label class="group-name" for="default_user"><?php echo _t ('default_user'); ?></label>
  756. <div class="group-controls">
  757. <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(); ?>" />
  758. </div>
  759. </div>
  760. <div class="form-group">
  761. <label class="group-name" for="auth_type"><?php echo _t('auth_type'); ?></label>
  762. <div class="group-controls">
  763. <select id="auth_type" name="auth_type" required="required">
  764. <?php if (!in_array($_SESSION['auth_type'], array('form', 'persona', 'http_auth', 'none'))) { ?>
  765. <option selected="selected"></option>
  766. <?php } ?>
  767. <option value="form"<?php echo $_SESSION['auth_type'] === 'form' ? ' selected="selected"' : '', cryptAvailable() ? '' : ' disabled="disabled"'; ?>><?php echo _t('auth_form'); ?></option>
  768. <option value="persona"<?php echo $_SESSION['auth_type'] === 'persona' ? ' selected="selected"' : ''; ?>><?php echo _t('auth_persona'); ?></option>
  769. <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>
  770. <option value="none"<?php echo $_SESSION['auth_type'] === 'none' ? ' selected="selected"' : ''; ?>><?php echo _t('auth_none'); ?></option>
  771. </select>
  772. </div>
  773. </div>
  774. <div class="form-group">
  775. <label class="group-name" for="passwordPlain"><?php echo _t('password_form'); ?></label>
  776. <div class="group-controls">
  777. <input type="password" id="passwordPlain" name="passwordPlain" pattern=".{7,}" autocomplete="off" />
  778. <noscript><b><?php echo _t('javascript_should_be_activated'); ?></b></noscript>
  779. </div>
  780. </div>
  781. <div class="form-group">
  782. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  783. <div class="group-controls">
  784. <input type="email" id="mail_login" name="mail_login" value="<?php echo isset ($_SESSION['mail_login']) ? $_SESSION['mail_login'] : ''; ?>" placeholder="alice@example.net" />
  785. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  786. </div>
  787. </div>
  788. <div class="form-group form-actions">
  789. <div class="group-controls">
  790. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  791. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  792. <?php if ($s2['all'] == 'ok') { ?>
  793. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  794. <?php } ?>
  795. </div>
  796. </div>
  797. </form>
  798. <?php
  799. }
  800. function printStep3 () {
  801. ?>
  802. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  803. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  804. <?php } elseif ($s3['conn'] == 'ko') { ?>
  805. <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>
  806. <?php } ?>
  807. <form action="index.php?step=3" method="post">
  808. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  809. <div class="form-group">
  810. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  811. <div class="group-controls">
  812. <select name="type" id="type" onchange="mySqlShowHide()">
  813. <?php if (extension_loaded('pdo_mysql')) {?>
  814. <option value="mysql"
  815. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  816. MySQL
  817. </option>
  818. <?php }?>
  819. <?php if (extension_loaded('pdo_sqlite')) {?>
  820. <option value="sqlite"
  821. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  822. SQLite
  823. </option>
  824. <?php }?>
  825. </select>
  826. </div>
  827. </div>
  828. <div id="mysql">
  829. <div class="form-group">
  830. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  831. <div class="group-controls">
  832. <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'; ?>" />
  833. </div>
  834. </div>
  835. <div class="form-group">
  836. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  837. <div class="group-controls">
  838. <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'] : ''; ?>" />
  839. </div>
  840. </div>
  841. <div class="form-group">
  842. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  843. <div class="group-controls">
  844. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" />
  845. </div>
  846. </div>
  847. <div class="form-group">
  848. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  849. <div class="group-controls">
  850. <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" />
  851. </div>
  852. </div>
  853. <div class="form-group">
  854. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  855. <div class="group-controls">
  856. <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_'; ?>" />
  857. </div>
  858. </div>
  859. </div>
  860. <script>
  861. function mySqlShowHide() {
  862. document.getElementById('mysql').style.display = document.getElementById('type').value === 'mysql' ? 'block' : 'none';
  863. }
  864. mySqlShowHide();
  865. </script>
  866. <div class="form-group form-actions">
  867. <div class="group-controls">
  868. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  869. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  870. <?php if ($s3['all'] == 'ok') { ?>
  871. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  872. <?php } ?>
  873. </div>
  874. </div>
  875. </form>
  876. <?php
  877. }
  878. function printStep4 () {
  879. ?>
  880. <form action="index.php?step=4" method="post">
  881. <legend><?php echo _t ('version_update'); ?></legend>
  882. <?php if (updateDatabase(false)) { ?>
  883. <p class="alert alert-warn"><?php echo _t ('update_long'); ?></p>
  884. <div class="form-group form-actions">
  885. <div class="group-controls">
  886. <input type="hidden" name="updateDatabase" value="1" />
  887. <button type="submit" class="btn btn-important"><?php echo _t ('update_start'); ?></button>
  888. </div>
  889. </div>
  890. <?php } else { ?>
  891. <p class="alert alert-warn"><?php echo _t ('update_end'); ?></p>
  892. <div class="form-group form-actions">
  893. <div class="group-controls">
  894. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('next_step'); ?></a>
  895. </div>
  896. </div>
  897. <?php } ?>
  898. </form>
  899. <?php
  900. }
  901. function printStep5 () {
  902. ?>
  903. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  904. <a class="btn btn-important next-step" href="?step=6"><?php echo _t ('finish_installation'); ?></a>
  905. <?php
  906. }
  907. function printStep6 () {
  908. ?>
  909. <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>
  910. <?php
  911. }
  912. checkStep ();
  913. initTranslate ();
  914. switch (STEP) {
  915. case 0:
  916. default:
  917. saveLanguage ();
  918. break;
  919. case 1:
  920. break;
  921. case 2:
  922. saveStep2 ();
  923. break;
  924. case 3:
  925. saveStep3 ();
  926. break;
  927. case 4:
  928. if (!empty($_POST['updateDatabase'])) {
  929. updateDatabase(true);
  930. }
  931. break;
  932. case 5:
  933. postUpdate();
  934. break;
  935. case 6:
  936. deleteInstall ();
  937. break;
  938. }
  939. ?>
  940. <!DOCTYPE html>
  941. <html lang="fr">
  942. <head>
  943. <meta charset="utf-8">
  944. <meta name="viewport" content="initial-scale=1.0">
  945. <title><?php echo _t ('freshrss_installation'); ?></title>
  946. <link rel="stylesheet" type="text/css" media="all" href="../themes/Origine/template.css" />
  947. <link rel="stylesheet" type="text/css" media="all" href="../themes/Origine/origine.css" />
  948. </head>
  949. <body>
  950. <div class="header">
  951. <div class="item title">
  952. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  953. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  954. </div>
  955. </div>
  956. <div id="global">
  957. <ul class="nav nav-list aside">
  958. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  959. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  960. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  961. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  962. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  963. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('version_update'); ?></a></li>
  964. <li class="item<?php echo STEP == 5 ? ' active' : ''; ?>"><a href="?step=5"><?php echo _t ('this_is_the_end'); ?></a></li>
  965. </ul>
  966. <div class="post">
  967. <?php
  968. switch (STEP) {
  969. case 0:
  970. default:
  971. printStep0 ();
  972. break;
  973. case 1:
  974. printStep1 ();
  975. break;
  976. case 2:
  977. printStep2 ();
  978. break;
  979. case 3:
  980. printStep3 ();
  981. break;
  982. case 4:
  983. printStep4 ();
  984. break;
  985. case 5:
  986. printStep5 ();
  987. break;
  988. case 6:
  989. printStep6 ();
  990. break;
  991. }
  992. ?>
  993. </div>
  994. </div>
  995. </body>
  996. </html>