PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/install/inc.php

https://bitbucket.org/speedealing/speedealing
PHP | 344 lines | 215 code | 65 blank | 64 comment | 33 complexity | db07bc3fe18a3e7ecec61d2dbb40c817 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  4. * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2007-2013 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2012-2013 Herve Prot <herve.prot@symeos.com>
  8. * Copyright (C) 2012 Marcos GarcĂ­a
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. // Just to define version DOL_VERSION
  24. if (!defined('DOL_INC_FOR_VERSION_ERROR'))
  25. define('DOL_INC_FOR_VERSION_ERROR', '1');
  26. require_once realpath(dirname(__FILE__)) . '/../filefunc.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/class/translatestandalone.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  31. // For couchdb
  32. if (!class_exists('couch'))
  33. require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couch.php';
  34. if (!class_exists('couchAdmin'))
  35. require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couchAdmin.php';
  36. if (!class_exists('couchClient'))
  37. require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couchClient.php';
  38. if (!class_exists('User'))
  39. require DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  40. // Avoid warnings with strict mode E_STRICT
  41. $conf = new stdClass(); // instantiate $conf explicitely
  42. $conf->global = new stdClass();
  43. $conf->file = new stdClass();
  44. $conf->db = new stdClass();
  45. // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
  46. // et non path absolu.
  47. if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
  48. $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
  49. }
  50. // Define vars
  51. $conffiletoshowshort = "conf.php";
  52. // Define localization of conf file
  53. $conffile = DOL_DOCUMENT_ROOT . '/conf/conf.php';
  54. $conffiletoshow = "conf/conf.php";
  55. if (! defined('DONOTLOADCONF') && file_exists($conffile))
  56. include_once $conffile; // Load conf file
  57. // Define DOL_URL_ROOT
  58. // If defined (Ie: Apache with Linux)
  59. if (isset($_SERVER["SCRIPT_URI"])) {
  60. $main_url_root = $_SERVER["SCRIPT_URI"];
  61. }
  62. // If defined (Ie: Apache with Caudium)
  63. elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
  64. $main_url_root = $_SERVER["SERVER_URL"] . $_SERVER["DOCUMENT_URI"];
  65. }
  66. // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
  67. else {
  68. $scheme = 'http';
  69. if (!empty($_SERVER["HTTP_HOST"]))
  70. $serverport = $_SERVER["HTTP_HOST"];
  71. else
  72. $serverport = $_SERVER["SERVER_NAME"];
  73. $main_url_root = $scheme . "://" . $serverport . $_SERVER["SCRIPT_NAME"];
  74. }
  75. // Clean proposed URL
  76. $main_url_root = preg_replace('/\/$/', '', $main_url_root); // Remove the /
  77. $main_url_root = preg_replace('/\/index\.php$/', '', $main_url_root); // Remove the /index.php
  78. $main_url_root = preg_replace('/\/phpinfo\.php$/', '', $main_url_root); // Remove the /phpinfo.php
  79. $main_url_root = preg_replace('/\/prerequisite\.php$/', '', $main_url_root); // Remove the /prerequisite.php
  80. $main_url_root = preg_replace('/\/ajax$/', '', $main_url_root); // Remove the /ajax
  81. $main_url_root = preg_replace('/\/install$/', '', $main_url_root); // Remove the /install
  82. $uri = preg_replace('/^http(s?):\/\//i', '', $main_url_root); // $uri contains url without http*
  83. define('MAIN_SERVER_NAME', $uri);
  84. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  85. if ($suburi == '/')
  86. $suburi = ''; // If $suburi is /, it is now ''
  87. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  88. // Security check
  89. $lockfile = DOL_DOCUMENT_ROOT . '/install/install.lock';
  90. if (file_exists($lockfile)) {
  91. header("Location: " . DOL_URL_ROOT . "/");
  92. exit;
  93. }
  94. // $langs object
  95. $langs = new TranslateStandalone(DOL_DOCUMENT_ROOT);
  96. if (GETPOST('lang'))
  97. $langs->setDefaultLang(GETPOST('lang', 'alpha'));
  98. else
  99. $langs->setDefaultLang('auto');
  100. if (!empty($_SESSION['db_json_files'])) {
  101. $jsonfiles = $_SESSION['db_json_files'];
  102. } else {
  103. // Get json files list
  104. $jsonfiles = array();
  105. // Get dict files
  106. $fileslist = dol_dir_list(DOL_DOCUMENT_ROOT . '/install/couchdb/json', 'files');
  107. foreach($fileslist as $file) {
  108. $jsonfiles[$file['name']] = $file['fullname'];
  109. }
  110. // Stock in session for best performance
  111. $_SESSION['db_json_files'] = $jsonfiles;
  112. }
  113. // Now we load forced value from install.forced.php file.
  114. $useforcedwizard=false;
  115. $forcedfile = DOL_DOCUMENT_ROOT . '/install/install.forced.php';
  116. if (@file_exists($forcedfile)) {
  117. $useforcedwizard=true;
  118. include $forcedfile;
  119. }
  120. /**
  121. * Show HTML header of install pages
  122. *
  123. * @return void
  124. */
  125. function pHeader() {
  126. global $conf, $langs;
  127. global $jsonfiles;
  128. $langs->load("main");
  129. $langs->load("admin");
  130. include 'tpl/header.tpl.php';
  131. }
  132. /**
  133. * Print HTML footer of install pages
  134. *
  135. * @return void
  136. */
  137. function pFooter() {
  138. global $langs;
  139. include 'tpl/footer.tpl.php';
  140. }
  141. /**
  142. * Save configuration file. No particular permissions are set by installer.
  143. *
  144. * @return void
  145. */
  146. function write_conf_file() {
  147. global $conf, $langs;
  148. global $couchdb_host, $couchdb_port, $force_https;
  149. global $memcached_host, $memcached_port, $useforcedwizard, $force_install_urlrewrite;
  150. global $conffile, $conffiletoshowshort;
  151. $key = md5(uniqid(mt_rand(), TRUE)); // Generate random hash
  152. $fp = fopen("$conffile", "w");
  153. if ($fp) {
  154. clearstatcache();
  155. fputs($fp, '<?php' . "\n");
  156. fputs($fp, '//' . "\n");
  157. fputs($fp, '// File generated by Speedealing installer ' . "\n");
  158. fputs($fp, '//' . "\n");
  159. fputs($fp, '// Take a look at conf.php.example file for an example of ' . $conffiletoshowshort . ' file' . "\n");
  160. fputs($fp, '// and explanations for all possibles parameters.' . "\n");
  161. fputs($fp, '//' . "\n\n");
  162. /* Authentication */
  163. fputs($fp, '// Authentication (obsolete ?)');
  164. fputs($fp, "\n");
  165. fputs($fp, '$main_authentication=\'dolibarr\';');
  166. fputs($fp, "\n");
  167. fputs($fp, '// Authentication for backward compatibility');
  168. fputs($fp, "\n");
  169. fputs($fp, '$dolibarr_main_authentication=\'dolibarr\';');
  170. fputs($fp, "\n\n");
  171. /* CouchDB */
  172. fputs($fp, '// Couchdb settings');
  173. fputs($fp, "\n");
  174. fputs($fp, '$main_couchdb_host=\'' . str_replace("'", "\'", $couchdb_host) . '\';');
  175. fputs($fp, "\n");
  176. fputs($fp, '$main_couchdb_port=\'' . str_replace("'", "\'", $couchdb_port) . '\';');
  177. fputs($fp, "\n");
  178. fputs($fp, '// Couchdb settings for backward compatibility');
  179. fputs($fp, "\n");
  180. fputs($fp, '$dolibarr_main_couchdb_host=\'' . str_replace("'", "\'", $couchdb_host) . '\';');
  181. fputs($fp, "\n");
  182. fputs($fp, '$dolibarr_main_couchdb_port=\'' . str_replace("'", "\'", $couchdb_port) . '\';');
  183. fputs($fp, "\n\n");
  184. /* Memcached */
  185. if (!empty($memcached_host) && !empty($memcached_port)) {
  186. fputs($fp, '// Memcached settings');
  187. fputs($fp, "\n");
  188. fputs($fp, '$main_memcached_host=\'' . str_replace("'", "\'", $memcached_host) . '\';');
  189. fputs($fp, "\n");
  190. fputs($fp, '$main_memcached_port=\'' . str_replace("'", "\'", $memcached_port) . '\';');
  191. fputs($fp, "\n");
  192. fputs($fp, '// Memcached settings for backward compatibility');
  193. fputs($fp, "\n");
  194. fputs($fp, '$dolibarr_main_memcached_host=\'' . str_replace("'", "\'", $memcached_host) . '\';');
  195. fputs($fp, "\n");
  196. fputs($fp, '$dolibarr_main_memcached_port=\'' . str_replace("'", "\'", $memcached_port) . '\';');
  197. fputs($fp, "\n\n");
  198. }
  199. /* URL rewriting (multicompany) */
  200. if ($useforcedwizard && !empty($force_install_urlrewrite)) {
  201. fputs($fp, '// URL rewriting');
  202. fputs($fp, "\n");
  203. fputs($fp, '$main_urlrewrite=\'1\';');
  204. fputs($fp, "\n");
  205. fputs($fp, '// URL rewriting for backward compatibility');
  206. fputs($fp, "\n");
  207. fputs($fp, '$dolibarr_urlrewrite=\'1\';');
  208. fputs($fp, "\n\n");
  209. } else {
  210. fputs($fp, '// URL rewriting');
  211. fputs($fp, "\n");
  212. fputs($fp, '$main_urlrewrite=\'0\';');
  213. fputs($fp, "\n");
  214. fputs($fp, '// URL rewriting for backward compatibility');
  215. fputs($fp, "\n");
  216. fputs($fp, '$dolibarr_urlrewrite=\'0\';');
  217. fputs($fp, "\n\n");
  218. }
  219. /* Specific setting */
  220. fputs($fp, '// Specific settings');
  221. fputs($fp, "\n");
  222. fputs($fp, '$main_prod=\'0\';');
  223. fputs($fp, "\n");
  224. fputs($fp, '$main_nocsrfcheck=\'0\';');
  225. fputs($fp, "\n");
  226. fputs($fp, '$main_force_https=\'' . (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on'?1:0) . '\';');
  227. fputs($fp, "\n");
  228. fputs($fp, '$main_cookie_cryptkey=\'' . $key . '\';');
  229. fputs($fp, "\n");
  230. fputs($fp, '$mailing_limit_sendbyweb=\'0\';');
  231. fputs($fp, "\n");
  232. fputs($fp, '// Specific settings for backward compatibility');
  233. fputs($fp, "\n");
  234. fputs($fp, '$dolibarr_main_prod=\'0\';');
  235. fputs($fp, "\n");
  236. fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
  237. fputs($fp, "\n");
  238. fputs($fp, '$dolibarr_main_force_https=\'' . (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on'?1:0) . '\';');
  239. fputs($fp, "\n");
  240. fputs($fp, '$dolibarr_main_cookie_cryptkey=\'' . $key . '\';');
  241. fputs($fp, "\n");
  242. fputs($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
  243. fputs($fp, "\n");
  244. fputs($fp, '?>');
  245. fclose($fp);
  246. if (file_exists("$conffile"))
  247. return 1;
  248. else
  249. return -1;
  250. }
  251. else
  252. return -2;
  253. }
  254. /**
  255. * Save lock file.
  256. *
  257. * @return void
  258. */
  259. function write_lock_file() {
  260. global $lockfile;
  261. $force_install_lockinstall = 444;
  262. $fp = fopen($lockfile, "w");
  263. if ($fp) {
  264. fwrite($fp, "This is a lock file to prevent use of install pages (set with permission " . $force_install_lockinstall . ")");
  265. fclose($fp);
  266. @chmod($lockfile, octdec($force_install_lockinstall));
  267. if (file_exists("$lockfile"))
  268. return 1;
  269. else
  270. return -1;
  271. }
  272. else
  273. return -2;
  274. }
  275. ?>