EPESI BIM • Business Information Manager • Cloud CRM/ERP http://epe.si/ https://epe.si
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setup.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. /**
  3. * @author Janusz Tylek <j@epe.si>
  4. * @version 1.1
  5. * @copyright Copyright &copy; 2019, Janusz Tylek
  6. * @license MIT
  7. * @package epesi-base
  8. */
  9. if (version_compare(phpversion(), '7.0.0')==-1)
  10. error_reporting(E_ALL); //all without notices
  11. else
  12. error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
  13. ob_start();
  14. ini_set('arg_separator.output','&');
  15. @define('SYSTEM_TIMEZONE',date_default_timezone_get());
  16. date_default_timezone_set(SYSTEM_TIMEZONE);
  17. define('_VALID_ACCESS',1);
  18. require_once('include/data_dir.php');
  19. require_once('modules/Libs/QuickForm/requires.php');
  20. /* You can predefine user, password, database name, etc in file defined by var below.
  21. Example installation_config.php file:
  22. <?php
  23. $CONFIG = array('user' => 'db_username', 'password' => 'db_password', 'db' => 'database_name', 'host' => 'db_server_host',
  24. 'newdb' => 0, // or 1 to create new database
  25. 'engine' => 'mysqli', // or 'postgres' for PostgreSQL
  26. 'direction' => 0 // Left to Right, or 1 for Right to Left
  27. );
  28. ?>
  29. */
  30. $fast_install_filename = "installation_config.php";
  31. // translation support
  32. $install_lang_dir = 'modules/Base/Lang/lang';
  33. $ls_langs = scandir($install_lang_dir);
  34. $langs = array();
  35. foreach ($ls_langs as $entry)
  36. if (preg_match('/.\.php$/i', $entry)) {
  37. $lang = substr($entry, 0, -4);
  38. $langs[$lang] = $lang;
  39. }
  40. $install_lang_code = & $_GET['install_lang'];
  41. require 'include/misc.php';
  42. require 'include/module_primitive.php';
  43. require 'include/module.php';
  44. require 'include/module_common.php';
  45. require 'modules/Base/Lang/LangCommon_0.php';
  46. $install_lang_load = isset($langs[$install_lang_code])
  47. ? $langs[$install_lang_code] : 'en'; // fallback to english
  48. define('FORCE_LANG_CODE', $install_lang_load);
  49. include "{$install_lang_dir}/{$install_lang_load}.php";
  50. // end translations load
  51. function set_header($str) {
  52. print('<script type="text/javascript">document.getElementById("setup_page_header").innerHTML="'.$str.'";</script>');
  53. }
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  56. <html>
  57. <head>
  58. <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  59. <title><?php echo __("EPESI setup"); ?></title>
  60. <link href="setup.css" type="text/css" rel="stylesheet"/>
  61. </head>
  62. <body>
  63. <table id="banner" border="0" cellpadding="0" cellspacing="0">
  64. <tr>
  65. <td class="image">&nbsp;</td>
  66. <td class="back" id="setup_page_header">&nbsp;</td>
  67. <td class="image back">&nbsp;</td>
  68. </tr>
  69. </table>
  70. <br>
  71. <center>
  72. <table id="main" border="0" cellpadding="0" cellspacing="0">
  73. <tr>
  74. <td>
  75. <?php
  76. function footer() {
  77. ?>
  78. </td>
  79. </tr>
  80. </table>
  81. </center>
  82. <br>
  83. <center>
  84. <span class="footer">MIT License &bull; Copyright &copy; 2006 - <?php echo date('Y'); ?> by <a href="https://epe.si">Janusz Tylek</a></span>
  85. <p><a href="http://www.epe.si"><img src="images/epesi-powered.png" border="0"></a></p>
  86. </center>
  87. </body>
  88. </html>
  89. <?php
  90. }
  91. register_shutdown_function('footer');
  92. // language selection form
  93. if (!isset($install_lang_code)) {
  94. print('<h2>Select Language</h2>');
  95. $complete = Base_LangCommon::get_complete_languages();
  96. $labels = Base_LangCommon::get_base_languages();
  97. $list = array();
  98. foreach ($complete as $l) {
  99. $list[$l] = isset($labels[$l])?$labels[$l]:$l;
  100. }
  101. $rest = array();
  102. foreach ($langs as $l) {
  103. $rest[$l] = isset($labels[$l])?$labels[$l]:$l;
  104. }
  105. asort($list);
  106. asort($rest);
  107. $list = array_merge(array('en'=>$labels['en']), $list);
  108. print('<div id="complete_translations">');
  109. foreach ($list as $l=>$label) {
  110. Base_LangCommon::print_flag($l, $label, 'href="?install_lang='.$l.'"');
  111. unset($rest[$l]);
  112. }
  113. print('</div>');
  114. print('<a class="show_incomplete button" onclick="this.style.display=\'none\';document.getElementById(\'incomplete_translations\').style.display=\'\';">Show incomplete translations</a>');
  115. print('<div id="incomplete_translations" style="display:none;">');
  116. foreach ($rest as $l=>$label) {
  117. Base_LangCommon::print_flag($l, $label, 'href="?install_lang='.$l.'"');
  118. }
  119. print('</div>');
  120. set_header('Setup Wizard');
  121. die();
  122. }
  123. /**
  124. * Check access to working directories
  125. */
  126. if(file_exists('easyinstall.php')){
  127. unlink('easyinstall.php');
  128. }
  129. if (isset($_GET['check'])) {
  130. require_once('check.php');
  131. print('<br><br><a class="button" href="index.php?install_lang='.$install_lang_load.'" style="display:block;width:200px; margin:0 auto;">' . __('Continue with installation') . '</a>');
  132. die();
  133. }
  134. if(trim(ini_get("safe_mode")))
  135. die(__('You cannot use EPESI with PHP safe mode turned on - please disable it. Please notice this feature is deprecated since PHP 5.3 and is removed in PHP 5.4.'));
  136. if (!file_exists(DATA_DIR)) {
  137. mkdir("./" . 'data', 0777);
  138. }
  139. if(file_exists(DATA_DIR.'/config.php'))
  140. die(__('Cannot write into %s file. Please delete this file.', array(DATA_DIR.'/config.php')));
  141. if(!is_writable(DATA_DIR))
  142. die(__('Cannot write into "%s" directory. Please fix privileges.', array(DATA_DIR)));
  143. if (isset($_GET['tos1']) && $_GET['tos1'] && isset($_GET['tos2']) && $_GET['tos2'] && isset($_GET['tos3']) && $_GET['tos3'] && isset($_GET['tos4']) && $_GET['tos4']) {
  144. $_GET['license'] = 1;
  145. unset($_GET['tos1']);
  146. unset($_GET['tos2']);
  147. unset($_GET['tos3']);
  148. unset($_GET['tos4']);
  149. }
  150. if(!isset($_GET['license'])) {
  151. set_header(__('License Agreement'));
  152. print('<div class="license">');
  153. print read_doc_file('license');
  154. print('</div>');
  155. print('<div class="license agreement">');
  156. $form = new HTML_QuickForm('licenceform','get');
  157. $form -> addElement('html', '<tr><td colspan=2><h3>'.__('By installing and using this software you automatically accept terms of the EULA and also agree that:').'</h3></td></tr>');
  158. $form -> addElement('checkbox','tos1','',__('You will not remove the <strong>"Copyright by Janusz Tylek"</strong> notice as required by the MIT license.'));
  159. $form -> addElement('checkbox','tos2','',__('You will not remove <strong>"made with epesi"</strong> logo and the link from the application login screen or other locations.'));
  160. $form -> addElement('checkbox','tos3','',__('You will not remove <strong>"Support -> About Epesi"</strong> credit page from the application menu.'));
  161. $form -> addElement('checkbox','tos4','',__('You will not remove or rename <strong>"EPESI Store"</strong> links from the application.'));
  162. foreach($_GET as $f=>$v) {
  163. if (substr($f, 0, 3) != 'tos' && $f != 'submitted')
  164. $form->addElement('hidden',$f,$v);
  165. }
  166. $form->addElement('hidden','submitted',1);
  167. $form -> addRule('tos1', __('Field required'), 'required');
  168. $form -> addRule('tos2', __('Field required'), 'required');
  169. $form -> addRule('tos3', __('Field required'), 'required');
  170. $form -> addRule('tos4', __('Field required'), 'required');
  171. isset($_GET['submitted']) && $_GET['submitted'] && $form->validate();
  172. $form -> addElement('submit', null, __('Next'));
  173. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">'.__('denotes required field').'</span>');
  174. $form->display();
  175. print('</div>');
  176. } elseif(!isset($_GET['htaccess'])) {
  177. ob_start();
  178. print('<h1>' . __('Welcome to EPESI setup!') . '<br></h1><h2>' . __('Hosting compatibility') . ':</h2><br><div class="license">');
  179. if(check_htaccess()) {
  180. $_GET['htaccess'] = 1;
  181. ob_end_clean();
  182. } else {
  183. print('</div><br><a class="button" href="setup.php?license=1&htaccess=1&install_lang='.$install_lang_load.'">' . __('Ok') . '</a>');
  184. ob_end_flush();
  185. }
  186. }
  187. if(isset($_GET['htaccess']) && isset($_GET['license'])) {
  188. set_header(__('Configuration'));
  189. $form = new HTML_QuickForm('serverform','post',$_SERVER['PHP_SELF'].'?'.http_build_query($_GET));
  190. $form -> addElement('header', null, __('Database server settings'));
  191. $form -> addElement('text', 'host', __('Database server address'));
  192. $form -> addRule('host', __('Field required'), 'required');
  193. $form -> addElement('text', 'port', __('Custom database port'));
  194. $form -> addElement('select', 'engine', __('Database engine'), array('postgres'=>'PostgreSQL', 'mysqli'=>'MySQL'));
  195. $form -> addRule('engine', __('Field required'), 'required');
  196. $form -> addElement('text', 'user', __('Database server user'));
  197. $form -> addRule('user', __('Field required'), 'required');
  198. $form -> addElement('password', 'password', __('Database server password'));
  199. $form -> addRule('password', __('Field required'), 'required');
  200. $form -> addElement('text', 'db', __('Database name'));
  201. $form -> addRule('db', __('Field required'), 'required');
  202. $create_db_warn_msg = __('WARNING: Make sure you have CREATE access level to do this!');
  203. $form -> addElement('select', 'newdb', __('Create new database'),
  204. array(0 => __('No'), 1 => __('Yes')),
  205. array('onChange' => 'if(this.value==1) alert("' . $create_db_warn_msg . '","warning");'));
  206. $form -> addRule('newdb', __('Field required'), 'required');
  207. $form -> addElement('header', null, __('Other settings'));
  208. $form -> addElement('select', 'direction', __('Text direction'),
  209. array(0 => __('Left to Right'), 1 => __('Right to Left')));
  210. $form -> addElement('submit', 'submit', __('Next'));
  211. $form -> setDefaults(array('engine'=>'mysqli','db'=>'epesi','host'=>'localhost'));
  212. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">'.__('denotes required field').'</span>');
  213. if (file_exists($fast_install_filename)) {
  214. include $fast_install_filename;
  215. if (isset($CONFIG) && is_array($CONFIG)) {
  216. $txt = __('Some fields were filled to make installation easier.');
  217. print '<div style="text-align:center"><p style="width: 250px;margin-left: auto;margin-right: auto;">' . $txt . '</p></div>';
  218. foreach ($CONFIG as $key => $value) {
  219. $form->setDefaults(array($key => $value));
  220. $form->getElement($key)->freeze();
  221. }
  222. }
  223. }
  224. $required_note_text = __('denotes required field');
  225. $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">' . $required_note_text . '</span>');
  226. $form -> addElement('html', '<tr><td colspan=2><br /><b>'
  227. . __('Any existing tables will be dropped!') . '</b><br />'
  228. . __('The database will be populated with data.') . '<br />'
  229. . __('This operation can take several minutes.') . '</td></tr>');
  230. if($form -> validate()) {
  231. $engine = $form -> exportValue('engine');
  232. $direction = $form -> exportValue('direction');
  233. $other = array('direction'=>$direction);
  234. $host = $form -> exportValue('host');
  235. $port = $form->exportValue('port');
  236. $user = $form -> exportValue('user');
  237. $pass = $form -> exportValue('password');
  238. $dbname = $form -> exportValue('db');
  239. $new_db = $form->exportValue('newdb');
  240. switch($engine) {
  241. case 'postgres':
  242. if(!function_exists('pg_connect')) {
  243. echo(__('Please enable postgresql extension in php.ini.'));
  244. } else {
  245. $port_def = $port ? " port=$port" : '';
  246. $link = pg_connect("host=$host user=$user password=$pass dbname=postgres" . $port_def);
  247. if(!$link) {
  248. echo(__('Could not connect.'));
  249. } else {
  250. if ($port) {
  251. $host .= ':' . $port;
  252. }
  253. if ($new_db == 1) {
  254. $sql = 'CREATE DATABASE "'.$dbname.'"';
  255. if (pg_query($link, $sql)) {
  256. //echo "Database '$dbname' created successfully\n";
  257. write_config($host,$user,$pass,$dbname,$engine,$other);
  258. } else {
  259. echo __('Error creating database') . ': ' . pg_last_error() . "\n";
  260. }
  261. pg_close($link);
  262. } else {
  263. include_once('libs/adodb/adodb.inc.php');
  264. $ado = & NewADOConnection('postgres');
  265. if(!@$ado->Connect($host,$user,$pass,$dbname)) {
  266. echo __('Database does not exist.') . "\n";
  267. echo '<br />' .__('Please create the database first or select option')
  268. . ':<br /><b>' . __('Create new database') . '</b>';
  269. } else {
  270. write_config($host, $user, $pass, $dbname, $engine,$other);
  271. }
  272. }
  273. }
  274. }
  275. break;
  276. case 'mysqli':
  277. if (!class_exists('mysqli')) {
  278. echo(__('Please enable mysql extension in php.ini.'));
  279. } else {
  280. if ($port) {
  281. $host .= ':' . $port;
  282. }
  283. $link = new mysqli($host, $user, $pass);
  284. if ($link->connect_errno) {
  285. echo(__('Could not connect') . "(Errno: {$link->connect_errno}): " . $link->connect_error);
  286. } else {
  287. if ($new_db == 1) {
  288. $sql = 'CREATE DATABASE `' . $dbname . '` CHARACTER SET utf8 COLLATE utf8_unicode_ci';
  289. if ($link->query($sql)) {
  290. write_config($host, $user, $pass, $dbname, $engine, $other);
  291. } else {
  292. echo __('Error creating database: ') . $link->error . "\n";
  293. }
  294. $link->close();
  295. } else {
  296. $result = $link->select_db($dbname);
  297. if (!$result) {
  298. echo __('Database does not exist') . ': ' . $link->error . "\n";
  299. echo '<br />' . __('Please create the database first or select option')
  300. . ':<br /><b>' . __('Create new database') . '</b>';
  301. } else {
  302. write_config($host, $user, $pass, $dbname, $engine, $other);
  303. }
  304. }
  305. }
  306. }
  307. break;
  308. }
  309. }
  310. $renderer =& $form->defaultRenderer();
  311. $renderer->setHeaderTemplate("\n\t<tr>\n\t\t<td style=\"white-space: nowrap; height: 20px; vertical-align: middle; background-color: #336699; background-repeat: repeat-x; color: #FFFFFF; font-weight: normal; text-align: center;\" align=\"left\" valign=\"baseline\" colspan=\"2\">{header}</td>\n\t</tr>");
  312. $renderer->setElementTemplate("\n\t<tr>\n\t\t<td align=\"right\" valign=\"baseline\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required -->{label}</td>\n\t\t<td valign=\"baseline\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>");
  313. $form->accept($renderer);
  314. print($renderer->toHtml());
  315. }
  316. ///////////////////////////////////////////////////////////////
  317. ///////////////////////////////////////////////////////////////
  318. function check_htaccess() {
  319. $dir = trim(dirname($_SERVER['SCRIPT_NAME']),'/');
  320. $epesi_dir = '/'.$dir.($dir?'/':'');
  321. $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])!== "off") ? 'https://' : 'http://';
  322. $test_url = $protocol.$_SERVER['HTTP_HOST'].$epesi_dir.'data/test.php';
  323. file_put_contents('data/test.php','<?php'."\n".'print("OK"); ?>');
  324. copy('htaccess.txt','data/.htaccess');
  325. if(ini_get('allow_url_fopen'))
  326. $ret = @file_get_contents($test_url);
  327. elseif (extension_loaded('curl')) { // Test if curl is loaded
  328. $ch = curl_init();
  329. curl_setopt($ch, CURLOPT_HEADER, 0);
  330. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  331. curl_setopt($ch, CURLOPT_URL, $test_url);
  332. $ret = curl_exec($ch);
  333. curl_close($ch);
  334. }
  335. if(!isset($ret)) {
  336. unlink('data/.htaccess');
  337. unlink('data/test.php');
  338. print(__('Unable to check EPESI root .htaccess file hosting compatibility. You should tweak it yourself.')
  339. . '<br>' . __('Suggested .htaccess file is:') . '<pre>' . file_get_contents('htaccess.txt') . '</pre>');
  340. return false;
  341. }
  342. if($ret!=="OK") {
  343. file_put_contents('data/.htaccess',"Options -Indexes\nSetEnv PHPRC ".dirname(__FILE__)."\n");
  344. if(ini_get('allow_url_fopen'))
  345. $ret = @file_get_contents($test_url);
  346. elseif (extension_loaded('curl')) { // Test if curl is loaded
  347. $ch = curl_init();
  348. curl_setopt($ch, CURLOPT_HEADER, 0);
  349. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  350. curl_setopt($ch, CURLOPT_URL, $test_url);
  351. $ret = curl_exec($ch);
  352. curl_close($ch);
  353. }
  354. if($ret!=="OK") {
  355. unlink('data/.htaccess');
  356. unlink('data/test.php');
  357. print(__('Your hosting is not compatible with default EPESI root .htaccess file. You should tweak it yourself.')
  358. . '<br>' . __('Default .htaccess file is:') . '<pre>' . file_get_contents('htaccess.txt') . '</pre>');
  359. return false;
  360. }
  361. }
  362. if(!is_writable('.')) {
  363. unlink('data/test.php');
  364. print(__('Your hosting is compatible with default EPESI root .htaccess file, but installer cannot write to EPESI root directory. You should paste following text to .htaccess file manually.')
  365. . '<pre>' . file_get_contents('data/.htaccess') . '</pre>');
  366. unlink('data/.htaccess');
  367. return false;
  368. }
  369. unlink('data/test.php');
  370. rename('data/.htaccess','.htaccess');
  371. return true;
  372. }
  373. function write_config($host, $user, $pass, $dbname, $engine, $other) {
  374. global $install_lang_load;
  375. $local_dir = dirname(dirname(str_replace('\\','/',__FILE__)));
  376. $script_filename = str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']);
  377. $other_conf = '';
  378. if(strcmp($local_dir,substr($script_filename,0,strlen($local_dir)))) {
  379. $epesi_dir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
  380. $other_conf .= "\n".'@define(\'EPESI_DIR\',\''. addcslashes($epesi_dir, '\'\\') .'\');';
  381. }
  382. $other_conf .= "\n".'define(\'DIRECTION_RTL\',\''.($other['direction']?'1':'0').'\');';
  383. $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])!== "off") ? 'https://' : 'http://';
  384. $domain_name = '';
  385. if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) {
  386. $domain_name = $_SERVER['HTTP_HOST'];
  387. } else if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']) {
  388. $domain_name = $_SERVER['SERVER_NAME'];
  389. }
  390. if ($domain_name) {
  391. $url = $protocol . $domain_name . dirname($_SERVER['REQUEST_URI']);
  392. $url = str_replace('\\', '/', $url);
  393. $other_conf .= "\n" . 'define(\'EPESI_URL\',\'' . addcslashes($url, '\'\\') . '\');';
  394. }
  395. $c = & fopen(DATA_DIR.'/config.php', 'w');
  396. fwrite($c, '<?php
  397. /**
  398. * Config file.
  399. *
  400. * All commented out defines are default values as they were
  401. * during the installation process. Default values may change after an update,
  402. * but your config file will remain as it was. If you want to know
  403. * current default values please look at file include/config.php
  404. *
  405. * This file contains database configuration.
  406. */
  407. defined(\'_VALID_ACCESS\') || die(\'Direct access forbidden\');
  408. /**
  409. * Address of SQL server.
  410. */
  411. define(\'DATABASE_HOST\',\''.addcslashes($host, '\'\\').'\');
  412. /**
  413. * User to log in to SQL server.
  414. */
  415. define(\'DATABASE_USER\',\''.addcslashes($user, '\'\\').'\');
  416. /**
  417. * User password to authorize SQL server.
  418. */
  419. define(\'DATABASE_PASSWORD\',\''.addcslashes($pass, '\'\\').'\');
  420. /**
  421. * Database to use.
  422. */
  423. define(\'DATABASE_NAME\',\''.addcslashes($dbname, '\'\\').'\');
  424. /**
  425. * Database driver.
  426. */
  427. define(\'DATABASE_DRIVER\',\''.addcslashes($engine, '\'\\').'\');
  428. /*
  429. * Turns on transfer reduction: not everything is sent to the client
  430. */
  431. //define(\'REDUCING_TRANSFER\',1);
  432. /*
  433. * A lot of debug info, starting with what modules are changed, what module variables are set... etc.
  434. */
  435. //define(\'DEBUG\',0);
  436. /*
  437. * Show module loading time ... = module + all children times
  438. */
  439. //define(\'MODULE_TIMES\',0);
  440. /*
  441. * Show queries execution time.
  442. */
  443. //define(\'SQL_TIMES\',0);
  444. /*
  445. * If you have got good server, but poor connection, turn it on.
  446. */
  447. //define(\'STRIP_OUTPUT\',0);
  448. /*
  449. * Display errors on page.
  450. */
  451. //define(\'DISPLAY_ERRORS\',1);
  452. /*
  453. * Notify all errors, including E_NOTICE, etc. Developer should use it!
  454. */
  455. //define(\'REPORT_ALL_ERRORS\',0);
  456. /*
  457. * Compress history
  458. */
  459. //define(\'GZIP_HISTORY\',1);
  460. /*
  461. * Compress HTTP output
  462. */
  463. //define(\'MINIFY_ENCODE\',1);
  464. /*
  465. * Apply sources minifying algorithms.
  466. *
  467. * If enabled CPU usage may raise, but amount
  468. * of transferred data is smaller.
  469. */
  470. //define(\'MINIFY_SOURCES\',0);
  471. /*
  472. * Show donation links in EPESI
  473. */
  474. //define(\'SUGGEST_DONATION\',1);
  475. /*
  476. * automatically check for new version
  477. */
  478. //define(\'CHECK_VERSION\',1);
  479. /*
  480. * Disable some administrator preferences.
  481. */
  482. //define(\'DEMO_MODE\',0);
  483. define(\'FILE_SESSION_DIR\',\''.str_replace('\\', '/', sys_get_temp_dir()).'\');
  484. define(\'INSTALLATION_ID\',\''.md5(__FILE__ . strval(microtime(true))).'\');
  485. '.$other_conf.'
  486. ?>');
  487. fclose($c);
  488. ob_start();
  489. ob_start('rm_config');
  490. //fill database
  491. clean_database();
  492. install_base();
  493. ob_end_flush();
  494. if(file_exists(DATA_DIR.'/config.php'))
  495. header("Location: setup.php?install_lang={$install_lang_load}&check=1");
  496. ob_end_flush();
  497. }
  498. //////////////////////////////////////////////
  499. function rm_config($x) {
  500. if($x) {
  501. unlink(dirname(__FILE__).'/'.DATA_DIR.'/config.php');
  502. clean_database();
  503. }
  504. return $x;
  505. }
  506. function clean_database() {
  507. require_once('include/config.php');
  508. require_once('include/database.php');
  509. $tables_db = DB::MetaTables();
  510. $tables = array();
  511. if(DB::is_mysql())
  512. DB::Execute('SET FOREIGN_KEY_CHECKS=0');
  513. if(DB::is_postgresql() && strpos(DB::GetOne('SELECT version()'),'PostgreSQL 8.2')!==false) {
  514. foreach ($tables_db as $t) {
  515. $idxs = DB::Execute('SELECT t.tgargs as args FROM pg_trigger t,pg_class c,pg_proc p WHERE t.tgenabled AND t.tgrelid = c.oid AND t.tgfoid = p.oid AND p.proname = \'RI_FKey_check_ins\' AND c.relname = \''.strtolower($t).'\' ORDER BY t.tgrelid');
  516. $matches = array(1=>array());
  517. while ($i = $idxs->FetchRow()) {
  518. $data = explode(chr(0), $i[0]);
  519. $matches[1][] = $data[0];
  520. }
  521. $num_keys = count($matches[1]);
  522. for ( $i = 0; $i < $num_keys; $i ++ )
  523. DB::Execute('ALTER TABLE '.$t.' DROP CONSTRAINT '.$matches[1][$i]);
  524. }
  525. }
  526. foreach($tables_db as $t) {
  527. DB::DropTable($t);
  528. }
  529. if(DB::is_mysql())
  530. DB::Execute('SET FOREIGN_KEY_CHECKS=1');
  531. }
  532. function install_base() {
  533. require_once('include/config.php');
  534. require_once('include/database.php');
  535. @DB::Execute('ALTER DATABASE `'.DATABASE_NAME.'` CHARACTER SET utf8 COLLATE utf8_unicode_ci');
  536. $ret = DB::CreateTable('modules',"name C(128) KEY,version I NOTNULL, priority I NOTNULL DEFAULT 0, state I NOTNULL DEFAULT 0");
  537. if($ret===false)
  538. die('Invalid SQL query - Setup module (modules table)');
  539. $ret = DB::CreateTable('cron',"func C(32) KEY,last I NOTNULL, running I1 NOTNULL DEFAULT 0, description C(255)");
  540. if($ret===false)
  541. die('Invalid SQL query - Setup cron (cron table)');
  542. $ret = DB::CreateTable('session',"name C(128) NOTNULL," .
  543. "expires I NOTNULL DEFAULT 0, data B",array('constraints'=>', PRIMARY KEY(name)'));
  544. if($ret===false)
  545. die('Invalid SQL query - Database module (session table)');
  546. $ret = DB::CreateTable('session_client',"session_name C(128) NOTNULL, client_id I2," .
  547. "data B",array('constraints'=>', FOREIGN KEY(session_name) REFERENCES session(name), PRIMARY KEY(client_id,session_name)'));
  548. if($ret===false)
  549. die('Invalid SQL query - Database module (session_client table)');
  550. $ret = DB::CreateTable('history',"session_name C(128) NOTNULL, page_id I, client_id I2," .
  551. "data B",array('constraints'=>', FOREIGN KEY(session_name) REFERENCES session(name), PRIMARY KEY(client_id,session_name,page_id)'));
  552. if($ret===false)
  553. die('Invalid SQL query - Database module (history table)');
  554. DB::CreateIndex('history__session_name__client_id__idx', 'history', 'session_name, client_id');
  555. $ret = DB::CreateTable('variables',"name C(128) KEY,value X");
  556. if($ret===false)
  557. die('Invalid SQL query - Database module (variables table)');
  558. $ret = DB::Execute("insert into variables values('default_module',%s)",array(serialize('FirstRun')));
  559. if($ret === false)
  560. die('Invalid SQL query - Setup module (populating variables)');
  561. $ret = DB::Execute("insert into variables values('version',%s)",array(serialize(EPESI_VERSION)));
  562. if($ret === false)
  563. die('Invalid SQL query - Setup module (populating variables)');
  564. }
  565. //////////////////////////////////////////////
  566. function read_doc_file($file_basename, $suffix = 'html') {
  567. global $install_lang_load;
  568. $dir = 'docs/';
  569. $file = $dir . $file_basename . '.' . $suffix; // default file
  570. $custom_file = $dir . "{$file_basename}_{$install_lang_load}.{$suffix}";
  571. if (file_exists($custom_file))
  572. $file = $custom_file;
  573. $fp = @fopen($file, 'r');
  574. if ($fp) {
  575. $content = fread($fp, filesize($file));
  576. }
  577. fclose($fp);
  578. return $content;
  579. }
  580. ob_end_flush();
  581. ?>