speedealing /htdocs/install/inc.php

Language PHP Lines 344
MD5 Hash 9a8b9bcdefa37236bd4ab711f871a233 Estimated Cost $5,221 (why?)
Repository https://bitbucket.org/speedealing/speedealing.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php

/* Copyright (C) 2004		Rodolphe Quiedeville	<rodolphe@quiedeville.org>
 * Copyright (C) 2004		Benoit Mortier			<benoit.mortier@opensides.be>
 * Copyright (C) 2004		Sebastien DiCintio		<sdicintio@ressource-toi.org>
 * Copyright (C) 2007-2012	Laurent Destailleur		<eldy@users.sourceforge.net>
 * Copyright (C) 2007-2013	Regis Houssin			<regis.houssin@capnetworks.com>
 * Copyright (C) 2012-2013	Herve Prot				<herve.prot@symeos.com>
 * Copyright (C) 2012		Marcos García
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

// Just to define version DOL_VERSION
if (!defined('DOL_INC_FOR_VERSION_ERROR'))
    define('DOL_INC_FOR_VERSION_ERROR', '1');
require_once realpath(dirname(__FILE__)) . '/../filefunc.inc.php';

require_once DOL_DOCUMENT_ROOT . '/core/class/translatestandalone.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';

// For couchdb
if (!class_exists('couch'))
	require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couch.php';
if (!class_exists('couchAdmin'))
	require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couchAdmin.php';
if (!class_exists('couchClient'))
	require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couchClient.php';
if (!class_exists('User'))
	require DOL_DOCUMENT_ROOT . '/user/class/user.class.php';


// Avoid warnings with strict mode E_STRICT
$conf = new stdClass(); // instantiate $conf explicitely
$conf->global = new stdClass();
$conf->file = new stdClass();
$conf->db = new stdClass();


// Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
// et non path absolu.
if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
    $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
}

// Define vars
$conffiletoshowshort = "conf.php";
// Define localization of conf file
$conffile = DOL_DOCUMENT_ROOT . '/conf/conf.php';
$conffiletoshow = "conf/conf.php";

if (! defined('DONOTLOADCONF') && file_exists($conffile))
	include_once $conffile;	// Load conf file

// Define DOL_URL_ROOT
// If defined (Ie: Apache with Linux)
if (isset($_SERVER["SCRIPT_URI"])) {
	$main_url_root = $_SERVER["SCRIPT_URI"];
}
// If defined (Ie: Apache with Caudium)
elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
	$main_url_root = $_SERVER["SERVER_URL"] . $_SERVER["DOCUMENT_URI"];
}
// If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
else {
	$scheme = 'http';
	if (!empty($_SERVER["HTTP_HOST"]))
		$serverport = $_SERVER["HTTP_HOST"];
	else
		$serverport = $_SERVER["SERVER_NAME"];
	$main_url_root = $scheme . "://" . $serverport . $_SERVER["SCRIPT_NAME"];
}
// Clean proposed URL
$main_url_root = preg_replace('/\/$/', '', $main_url_root);     // Remove the /
$main_url_root = preg_replace('/\/index\.php$/', '', $main_url_root);  // Remove the /index.php
$main_url_root = preg_replace('/\/phpinfo\.php$/', '', $main_url_root);   // Remove the /phpinfo.php
$main_url_root = preg_replace('/\/prerequisite\.php$/', '', $main_url_root);   // Remove the /prerequisite.php
$main_url_root = preg_replace('/\/ajax$/', '', $main_url_root);   // Remove the /ajax
$main_url_root = preg_replace('/\/install$/', '', $main_url_root);   // Remove the /install
$uri = preg_replace('/^http(s?):\/\//i', '', $main_url_root);	// $uri contains url without http*
define('MAIN_SERVER_NAME', $uri);
$suburi = strstr($uri, '/');       // $suburi contains url without domain
if ($suburi == '/')
    $suburi = '';   // If $suburi is /, it is now ''
define('DOL_URL_ROOT', $suburi);    // URL relative root ('', '/dolibarr', ...)

// Security check
$lockfile = DOL_DOCUMENT_ROOT . '/install/install.lock';
if (file_exists($lockfile)) {
	header("Location: " . DOL_URL_ROOT . "/");
	exit;
}

// $langs object
$langs = new TranslateStandalone(DOL_DOCUMENT_ROOT);
if (GETPOST('lang'))
    $langs->setDefaultLang(GETPOST('lang', 'alpha'));
else
    $langs->setDefaultLang('auto');

if (!empty($_SESSION['db_json_files'])) {
	$jsonfiles = $_SESSION['db_json_files'];
} else {
	// Get json files list
	$jsonfiles = array();
	// Get dict files
	$fileslist = dol_dir_list(DOL_DOCUMENT_ROOT . '/install/couchdb/json', 'files');
	foreach($fileslist as $file) {
			$jsonfiles[$file['name']] = $file['fullname'];
	}
	// Stock in session for best performance
	$_SESSION['db_json_files'] = $jsonfiles;
}

// Now we load forced value from install.forced.php file.
$useforcedwizard=false;
$forcedfile = DOL_DOCUMENT_ROOT . '/install/install.forced.php';
if (@file_exists($forcedfile)) {
	$useforcedwizard=true;
	include $forcedfile;
}


/**
 * Show HTML header of install pages
 *
 * @return	void
 */
function pHeader() {
    global $conf, $langs;
    global $jsonfiles;

    $langs->load("main");
    $langs->load("admin");

    include 'tpl/header.tpl.php';
}

/**
 * Print HTML footer of install pages
 *
 * @return	void
 */
function pFooter() {
	global $langs;

	include 'tpl/footer.tpl.php';
}

/**
 *  Save configuration file. No particular permissions are set by installer.
 *
 *  @return	void
 */
function write_conf_file() {
	global $conf, $langs;
	global $couchdb_host, $couchdb_port, $force_https;
	global $memcached_host, $memcached_port, $useforcedwizard, $force_install_urlrewrite;
	global $conffile, $conffiletoshowshort;

	$key = md5(uniqid(mt_rand(), TRUE)); // Generate random hash

	$fp = fopen("$conffile", "w");
	if ($fp) {
		clearstatcache();

		fputs($fp, '<?php' . "\n");
		fputs($fp, '//' . "\n");
		fputs($fp, '// File generated by Speedealing installer ' . "\n");
		fputs($fp, '//' . "\n");
		fputs($fp, '// Take a look at conf.php.example file for an example of ' . $conffiletoshowshort . ' file' . "\n");
		fputs($fp, '// and explanations for all possibles parameters.' . "\n");
		fputs($fp, '//' . "\n\n");

		/* Authentication */

		fputs($fp, '// Authentication (obsolete ?)');
		fputs($fp, "\n");

		fputs($fp, '$main_authentication=\'dolibarr\';');
		fputs($fp, "\n");

		fputs($fp, '// Authentication for backward compatibility');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_main_authentication=\'dolibarr\';');
		fputs($fp, "\n\n");

		/* CouchDB */

		fputs($fp, '// Couchdb settings');
		fputs($fp, "\n");

		fputs($fp, '$main_couchdb_host=\'' . str_replace("'", "\'", $couchdb_host) . '\';');
		fputs($fp, "\n");

		fputs($fp, '$main_couchdb_port=\'' . str_replace("'", "\'", $couchdb_port) . '\';');
		fputs($fp, "\n");

		fputs($fp, '// Couchdb settings for backward compatibility');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_main_couchdb_host=\'' . str_replace("'", "\'", $couchdb_host) . '\';');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_main_couchdb_port=\'' . str_replace("'", "\'", $couchdb_port) . '\';');
		fputs($fp, "\n\n");

		/* Memcached */

		if (!empty($memcached_host) && !empty($memcached_port)) {
			fputs($fp, '// Memcached settings');
			fputs($fp, "\n");

			fputs($fp, '$main_memcached_host=\'' . str_replace("'", "\'", $memcached_host) . '\';');
			fputs($fp, "\n");

			fputs($fp, '$main_memcached_port=\'' . str_replace("'", "\'", $memcached_port) . '\';');
			fputs($fp, "\n");

			fputs($fp, '// Memcached settings for backward compatibility');
			fputs($fp, "\n");

			fputs($fp, '$dolibarr_main_memcached_host=\'' . str_replace("'", "\'", $memcached_host) . '\';');
			fputs($fp, "\n");

			fputs($fp, '$dolibarr_main_memcached_port=\'' . str_replace("'", "\'", $memcached_port) . '\';');
			fputs($fp, "\n\n");
		}

		/* URL rewriting (multicompany) */

		if ($useforcedwizard && !empty($force_install_urlrewrite)) {
			fputs($fp, '// URL rewriting');
			fputs($fp, "\n");

			fputs($fp, '$main_urlrewrite=\'1\';');
			fputs($fp, "\n");

			fputs($fp, '// URL rewriting for backward compatibility');
			fputs($fp, "\n");

			fputs($fp, '$dolibarr_urlrewrite=\'1\';');
			fputs($fp, "\n\n");
		} else {
			fputs($fp, '// URL rewriting');
			fputs($fp, "\n");

			fputs($fp, '$main_urlrewrite=\'0\';');
			fputs($fp, "\n");

			fputs($fp, '// URL rewriting for backward compatibility');
			fputs($fp, "\n");

			fputs($fp, '$dolibarr_urlrewrite=\'0\';');
			fputs($fp, "\n\n");
		}

		/* Specific setting */

		fputs($fp, '// Specific settings');
		fputs($fp, "\n");

		fputs($fp, '$main_prod=\'0\';');
		fputs($fp, "\n");

		fputs($fp, '$main_nocsrfcheck=\'0\';');
		fputs($fp, "\n");

		fputs($fp, '$main_force_https=\'' . (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on'?1:0) . '\';');
		fputs($fp, "\n");

		fputs($fp, '$main_cookie_cryptkey=\'' . $key . '\';');
		fputs($fp, "\n");

		fputs($fp, '$mailing_limit_sendbyweb=\'0\';');
		fputs($fp, "\n");

		fputs($fp, '// Specific settings for backward compatibility');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_main_prod=\'0\';');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_main_force_https=\'' . (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on'?1:0) . '\';');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_main_cookie_cryptkey=\'' . $key . '\';');
		fputs($fp, "\n");

		fputs($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
		fputs($fp, "\n");

		fputs($fp, '?>');
		fclose($fp);

		if (file_exists("$conffile"))
			return 1;
		else
			return -1;
	}
	else
		return -2;
}

/**
 *	Save lock file.
 *
 *  @return	void
 */
function write_lock_file() {
	global $lockfile;

	$force_install_lockinstall = 444;
	$fp = fopen($lockfile, "w");
	if ($fp) {
		fwrite($fp, "This is a lock file to prevent use of install pages (set with permission " . $force_install_lockinstall . ")");
		fclose($fp);
		@chmod($lockfile, octdec($force_install_lockinstall));
		if (file_exists("$lockfile"))
			return 1;
		else
			return -1;
	}
	else
		return -2;
}
?>
Back to Top