write_conf_file()   F
last analyzed

Complexity

Conditions 16
Paths 16385

Size

Total Lines 212
Code Lines 158

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 158
nc 16385
nop 1
dl 0
loc 212
rs 1.1198
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* Copyright (C) 2004-2007  Rodolphe Quiedeville    <[email protected]>
4
 * Copyright (C) 2004-2016  Laurent Destailleur     <[email protected]>
5
 * Copyright (C) 2004       Benoit Mortier          <[email protected]>
6
 * Copyright (C) 2004       Sebastien Di Cintio     <[email protected]>
7
 * Copyright (C) 2005-2011  Regis Houssin           <[email protected]>
8
 * Copyright (C) 2015-2016  Raphaël Doursenaud      <[email protected]>
9
 * Copyright (C) 2024		MDW							<[email protected]>
10
 * Copyright (C) 2024       Rafael San José             <[email protected]>
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24
 */
25
26
/**
27
 *      \file       htdocs/install/step1.php
28
 *      \ingroup    install
29
 *      \brief      Build conf file on disk
30
 */
31
32
define('DONOTLOADCONF', 1); // To avoid loading conf by file inc.php
33
34
include 'inc.php';
35
36
global $langs;
37
38
$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]);
39
$setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[2]) ? 'auto' : $argv[2]);
40
$langs->setDefaultLang($setuplang);
41
42
$langs->loadLangs(array("admin", "install", "errors"));
43
44
// Dolibarr pages directory
45
$main_dir = GETPOST('main_dir') ? GETPOST('main_dir') : (empty($argv[3]) ? '' : $argv[3]);
46
// Directory for generated documents (invoices, orders, ecm, etc...)
47
$main_data_dir = GETPOST('main_data_dir') ? GETPOST('main_data_dir') : (empty($argv[4]) ? ($main_dir . '/documents') : $argv[4]);
48
// Dolibarr root URL
49
$main_url = GETPOST('main_url') ? GETPOST('main_url') : (empty($argv[5]) ? '' : $argv[5]);
50
// Database login information
51
$userroot = GETPOST('db_user_root', 'alpha') ? GETPOST('db_user_root', 'alpha') : (empty($argv[6]) ? '' : $argv[6]);
52
$passroot = GETPOST('db_pass_root', 'none') ? GETPOST('db_pass_root', 'none') : (empty($argv[7]) ? '' : $argv[7]);
53
// Database server
54
$db_type = GETPOST('db_type', 'aZ09') ? GETPOST('db_type', 'aZ09') : (empty($argv[8]) ? '' : $argv[8]);
55
$db_host = GETPOST('db_host', 'alpha') ? GETPOST('db_host', 'alpha') : (empty($argv[9]) ? '' : $argv[9]);
56
$db_name = GETPOST('db_name', 'aZ09') ? GETPOST('db_name', 'aZ09') : (empty($argv[10]) ? '' : $argv[10]);
57
$db_user = GETPOST('db_user', 'alpha') ? GETPOST('db_user', 'alpha') : (empty($argv[11]) ? '' : $argv[11]);
58
$db_pass = GETPOST('db_pass', 'none') ? GETPOST('db_pass', 'none') : (empty($argv[12]) ? '' : $argv[12]);
59
$db_port = GETPOSTINT('db_port') ? GETPOSTINT('db_port') : (empty($argv[13]) ? '' : $argv[13]);
60
$db_prefix = GETPOST('db_prefix', 'aZ09') ? GETPOST('db_prefix', 'aZ09') : (empty($argv[14]) ? '' : $argv[14]);
61
$db_create_database = GETPOST('db_create_database', 'alpha') ? GETPOST('db_create_database', 'alpha') : (empty($argv[15]) ? '' : $argv[15]);
62
$db_create_user = GETPOST('db_create_user', 'alpha') ? GETPOST('db_create_user', 'alpha') : (empty($argv[16]) ? '' : $argv[16]);
63
// Force https
64
$main_force_https = ((GETPOST("main_force_https", 'alpha') && (GETPOST("main_force_https", 'alpha') == "on" || GETPOST("main_force_https", 'alpha') == 1)) ? '1' : '0');
65
// Use alternative directory
66
$main_use_alt_dir = ((GETPOST("main_use_alt_dir", 'alpha') == '' || (GETPOST("main_use_alt_dir", 'alpha') == "on" || GETPOST("main_use_alt_dir", 'alpha') == 1)) ? '' : '//');
67
// Alternative root directory name
68
$main_alt_dir_name = ((GETPOST("main_alt_dir_name", 'alpha') && GETPOST("main_alt_dir_name", 'alpha') != '') ? GETPOST("main_alt_dir_name", 'alpha') : 'custom');
69
70
$dolibarr_main_distrib = 'standard';
71
72
session_start(); // To be able to keep info into session (used for not losing password during navigation. The password must not transit through parameters)
73
74
// Save a flag to tell to restore input value if we go back
75
$_SESSION['dol_save_pass'] = $db_pass;
76
//$_SESSION['dol_save_passroot']=$passroot;
77
78
// Now we load forced values from install.forced.php file.
79
$useforcedwizard = false;
80
$forcedfile = "./install.forced.php";
81
if ($conffile == "/etc/dolibarr/conf.php") {
82
    $forcedfile = "/etc/dolibarr/install.forced.php";
83
}
84
if (@file_exists($forcedfile)) {
85
    $useforcedwizard = true;
86
    include_once $forcedfile;
87
    // If forced install is enabled, replace the post values. These are empty because form fields are disabled.
88
    if ($force_install_noedit) {
89
        $main_dir = detect_dolibarr_main_document_root();
90
        if (!empty($argv[3])) {
91
            $main_dir = $argv[3]; // override when executing the script in command line
92
        }
93
        if (!empty($force_install_main_data_root)) {
94
            $main_data_dir = $force_install_main_data_root;
95
        } else {
96
            $main_data_dir = detect_dolibarr_main_data_root($main_dir);
97
        }
98
        if (!empty($argv[4])) {
99
            $main_data_dir = $argv[4]; // override when executing the script in command line
100
        }
101
        // In mode 3 the main_url is custom
102
        if ($force_install_noedit != 3)
103
            $main_url = detect_dolibarr_main_url_root();
104
        if (!empty($argv[5])) {
105
            $main_url = $argv[5]; // override when executing the script in command line
106
        }
107
108
        if (!empty($force_install_databaserootlogin)) {
109
            $userroot = parse_database_login($force_install_databaserootlogin);
110
        }
111
        if (!empty($argv[6])) {
112
            $userroot = $argv[6]; // override when executing the script in command line
113
        }
114
        if (!empty($force_install_databaserootpass)) {
115
            $passroot = parse_database_pass($force_install_databaserootpass);
116
        }
117
        if (!empty($argv[7])) {
118
            $passroot = $argv[7]; // override when executing the script in command line
119
        }
120
    }
121
    if (($force_install_noedit == 2) || ($force_install_noedit == 3)) {
122
        if (!empty($force_install_type)) {
123
            $db_type = $force_install_type;
124
        }
125
        if (!empty($force_install_dbserver)) {
126
            $db_host = $force_install_dbserver;
127
        }
128
        if (!empty($force_install_database)) {
129
            $db_name = $force_install_database;
130
        }
131
        if (!empty($force_install_databaselogin)) {
132
            $db_user = $force_install_databaselogin;
133
        }
134
        if (!empty($force_install_databasepass)) {
135
            $db_pass = $force_install_databasepass;
136
        }
137
        if (!empty($force_install_port)) {
138
            $db_port = $force_install_port;
139
        }
140
        if (!empty($force_install_prefix)) {
141
            $db_prefix = $force_install_prefix;
142
        }
143
        if (!empty($force_install_createdatabase)) {
144
            $db_create_database = $force_install_createdatabase;
145
        }
146
        if (!empty($force_install_createuser)) {
147
            $db_create_user = $force_install_createuser;
148
        }
149
        if (!empty($force_install_mainforcehttps)) {
150
            $main_force_https = $force_install_mainforcehttps;
151
        }
152
    }
153
154
    if (!empty($force_install_distrib)) {
155
        $dolibarr_main_distrib = $force_install_distrib;
156
    }
157
}
158
159
$error = 0;
160
161
/*
162
 *	View
163
 */
164
165
dolibarr_install_syslog("--- step1: entering step1.php page");
166
167
pHeader($langs->trans("ConfigurationFile"), "step2");
168
169
// Test if we can run a first install process
170
if (!is_writable($conffile)) {
171
    print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
172
    pFooter(1, $setuplang, 'jscheckparam');
173
    exit;
174
}
175
176
// Check parameters
177
$is_sqlite = false;
178
if (empty($db_type)) {
179
    print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseType")) . '</div>';
180
    $error++;
181
} else {
182
    $is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3');
183
}
184
if (empty($db_host) && !$is_sqlite) {
185
    print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Server")) . '</div>';
186
    $error++;
187
}
188
if (empty($db_name)) {
189
    print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseName")) . '</div>';
190
    $error++;
191
}
192
if (empty($db_user) && !$is_sqlite) {
193
    print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Login")) . '</div>';
194
    $error++;
195
}
196
if (!empty($db_port) && !is_numeric($db_port)) {
197
    print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $db_port, $langs->transnoentities("Port")) . '</div>';
198
    $error++;
199
}
200
if (!empty($db_prefix) && !preg_match('/^[a-z0-9]+_$/i', $db_prefix)) {
201
    print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $db_prefix, $langs->transnoentities("DatabasePrefix")) . '</div>';
202
    $error++;
203
}
204
205
$main_dir = dol_sanitizePathName($main_dir);
206
$main_data_dir = dol_sanitizePathName($main_data_dir);
207
208
if (!filter_var($main_url, FILTER_VALIDATE_URL)) {
209
    print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $main_url, $langs->transnoentitiesnoconv("URLRoot")) . '</div>';
210
    print '<br>';
211
    print $langs->trans("ErrorGoBackAndCorrectParameters");
212
    $error++;
213
}
214
215
// Remove last / into dans main_dir
216
if (substr($main_dir, dol_strlen($main_dir) - 1) == "/") {
217
    $main_dir = substr($main_dir, 0, dol_strlen($main_dir) - 1);
218
}
219
220
// Remove last / into dans main_url
221
if (!empty($main_url) && substr($main_url, dol_strlen($main_url) - 1) == "/") {
222
    $main_url = substr($main_url, 0, dol_strlen($main_url) - 1);
223
}
224
225
if (!dol_is_dir($main_dir . '/core/db/')) {
226
    print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $main_dir, $langs->transnoentitiesnoconv("WebPagesDirectory")) . '</div>';
227
    print '<br>';
228
    //print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
229
    print $langs->trans("ErrorGoBackAndCorrectParameters");
230
    $error++;
231
}
232
233
// Test database connection
234
if (!$error) {
235
    $result = @include_once $main_dir . "/core/db/" . $db_type . '.class.php';
236
    if ($result) {
237
        // If we require database or user creation we need to connect as root, so we need root login credentials
238
        if (!empty($db_create_database) && !$userroot) {
239
            print '<div class="error">' . $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $db_name) . '</div>';
240
            print '<br>';
241
            print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
242
            print $langs->trans("ErrorGoBackAndCorrectParameters");
243
            $error++;
244
        }
245
        if (!empty($db_create_user) && !$userroot) {
246
            print '<div class="error">' . $langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect", $db_user) . '</div>';
247
            print '<br>';
248
            print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
249
            print $langs->trans("ErrorGoBackAndCorrectParameters");
250
            $error++;
251
        }
252
253
        // If we need root access
254
        if (!$error && (!empty($db_create_database) || !empty($db_create_user))) {
255
            $databasefortest = $db_name;
256
            if (!empty($db_create_database)) {
257
                if ($db_type == 'mysql' || $db_type == 'mysqli') {
258
                    $databasefortest = 'mysql';
259
                } elseif ($db_type == 'pgsql') {
260
                    $databasefortest = 'postgres';
261
                } else {
262
                    $databasefortest = 'master';
263
                }
264
            }
265
266
            $db = getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, (int)$db_port);
267
268
            dol_syslog("databasefortest=" . $databasefortest . " connected=" . json_encode($db->connected) . " database_selected=" . json_encode($db->database_selected), LOG_DEBUG);
269
270
            if (empty($db_create_database) && $db->connected && !$db->database_selected) {
271
                print '<div class="error">' . $langs->trans("ErrorConnectedButDatabaseNotFound", $db_name) . '</div>';
272
                print '<br>';
273
                if (!$db->connected) {
274
                    print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate") . '<br><br>';
275
                }
276
                print $langs->trans("ErrorGoBackAndCorrectParameters");
277
                $error++;
278
            } elseif ($db->error && !(!empty($db_create_database) && $db->connected)) {
279
                // Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
280
                if ($db->error == "No such file or directory") {
281
                    print '<div class="error">' . $langs->trans("ErrorToConnectToMysqlCheckInstance") . '</div>';
282
                } else {
283
                    print '<div class="error">' . $db->error . '</div>';
284
                }
285
                if (!$db->connected) {
286
                    print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
287
                }
288
                //print '<a href="#" onClick="javascript: history.back();">';
289
                print $langs->trans("ErrorGoBackAndCorrectParameters");
290
                //print '</a>';
291
                $error++;
292
            }
293
        }
294
295
        // If we need simple access
296
        if (!$error && (empty($db_create_database) && empty($db_create_user))) {
297
            $db = getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, (int)$db_port);
298
299
            if ($db->error) {
300
                print '<div class="error">' . $db->error . '</div>';
301
                if (!$db->connected) {
302
                    print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
303
                }
304
                //print '<a href="#" onClick="javascript: history.back();">';
305
                print $langs->trans("ErrorGoBackAndCorrectParameters");
306
                //print '</a>';
307
                $error++;
308
            }
309
        }
310
    } else {
311
        print "<br>\nFailed to include_once(\"" . $main_dir . "/core/db/" . $db_type . ".class.php\")<br>\n";
312
        print '<div class="error">' . $langs->trans("ErrorWrongValueForParameter", $langs->transnoentities("WebPagesDirectory")) . '</div>';
313
        //print '<a href="#" onClick="javascript: history.back();">';
314
        print $langs->trans("ErrorGoBackAndCorrectParameters");
315
        //print '</a>';
316
        $error++;
317
    }
318
} else {
319
    if (isset($db)) {
320
        print $db->lasterror();
321
    }
322
    if (isset($db) && !$db->connected) {
323
        print '<br>' . $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
324
    }
325
    print $langs->trans("ErrorGoBackAndCorrectParameters");
326
    $error++;
327
}
328
329
if (!$error && $db->connected) {
330
    if (!empty($db_create_database)) {
331
        $result = $db->select_db($db_name);
332
        if ($result) {
333
            print '<div class="error">' . $langs->trans("ErrorDatabaseAlreadyExists", $db_name) . '</div>';
334
            print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate") . '<br><br>';
335
            print $langs->trans("ErrorGoBackAndCorrectParameters");
336
            $error++;
337
        }
338
    }
339
}
340
341
// Define $defaultCharacterSet and $defaultDBSortingCollation
342
if (!$error && $db->connected) {
343
    if (!empty($db_create_database)) {    // If we create database, we force default value
344
        // Default values come from the database handler
345
346
        $defaultCharacterSet = $db->forcecharset;
347
        $defaultDBSortingCollation = $db->forcecollate;
348
    } else { // If already created, we take current value
349
        $defaultCharacterSet = $db->getDefaultCharacterSetDatabase();
350
        $defaultDBSortingCollation = $db->getDefaultCollationDatabase();
351
    }
352
353
    /*
354
    // It seems some PHP driver mysqli does not support utf8mb3
355
    if ($defaultCharacterSet == 'utf8mb3' || $defaultDBSortingCollation == 'utf8mb3_unicode_ci') {
356
        $defaultCharacterSet = 'utf8';
357
        $defaultDBSortingCollation = 'utf8_unicode_ci';
358
    }
359
    // Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
360
    // TODO Remove this when utf8mb4 is supported
361
    if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci') {
362
        $defaultCharacterSet = 'utf8';
363
        $defaultDBSortingCollation = 'utf8_unicode_ci';
364
    }
365
    */
366
367
    print '<input type="hidden" name="dolibarr_main_db_character_set" value="' . $defaultCharacterSet . '">';
368
    print '<input type="hidden" name="dolibarr_main_db_collation" value="' . $defaultDBSortingCollation . '">';
369
    $db_character_set = $defaultCharacterSet;
370
    $db_collation = $defaultDBSortingCollation;
371
    dolibarr_install_syslog("step1: db_character_set=" . $db_character_set . " db_collation=" . $db_collation);
372
}
373
374
375
// Create config file
376
if (!$error && $db->connected && $action == "set") {
377
    umask(0);
378
    if (is_array($_POST)) {
379
        foreach ($_POST as $key => $value) {
380
            if (!preg_match('/^db_pass/i', $key)) {
381
                dolibarr_install_syslog("step1: choice for " . $key . " = " . $value);
382
            }
383
        }
384
    }
385
386
    // Show title of step
387
    print '<h3><img class="valignmiddle inline-block paddingright" src="' . constant('DOL_URL_ROOT') . '/theme/common/octicons/build/svg/gear.svg" width="20" alt="Configuration"> ' . $langs->trans("ConfigurationFile") . '</h3>';
388
    print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
389
390
    // Check parameter main_dir
391
    if (!$error) {
392
        if (!is_dir($main_dir)) {
393
            dolibarr_install_syslog("step1: directory '" . $main_dir . "' is unavailable or can't be accessed");
394
395
            print "<tr><td>";
396
            print $langs->trans("ErrorDirDoesNotExists", $main_dir) . '<br>';
397
            print $langs->trans("ErrorWrongValueForParameter", $langs->transnoentitiesnoconv("WebPagesDirectory")) . '<br>';
398
            print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>';
399
            print '</td><td>';
400
            print $langs->trans("Error");
401
            print "</td></tr>";
402
            $error++;
403
        }
404
    }
405
406
    if (!$error) {
407
        dolibarr_install_syslog("step1: directory '" . $main_dir . "' exists");
408
    }
409
410
411
    // Create subdirectory main_data_dir
412
    if (!$error) {
413
        // Create directory for documents
414
        if (!is_dir($main_data_dir)) {
415
            dol_mkdir($main_data_dir);
416
        }
417
418
        if (!is_dir($main_data_dir)) {
419
            print "<tr><td>" . $langs->trans("ErrorDirDoesNotExists", $main_data_dir);
420
            print ' ' . $langs->trans("YouMustCreateItAndAllowServerToWrite");
421
            print '</td><td>';
422
            print '<span class="error">' . $langs->trans("Error") . '</span>';
423
            print "</td></tr>";
424
            print '<tr><td colspan="2"><br>' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</td></tr>';
425
            $error++;
426
        } else {
427
            // Create .htaccess file in document directory
428
            $pathhtaccess = $main_data_dir . '/.htaccess';
429
            if (!file_exists($pathhtaccess)) {
430
                dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '" . $main_data_dir . "'");
431
                $handlehtaccess = @fopen($pathhtaccess, 'w');
432
                if ($handlehtaccess) {
433
                    fwrite($handlehtaccess, 'Order allow,deny' . "\n");
434
                    fwrite($handlehtaccess, 'Deny from all' . "\n");
435
436
                    fclose($handlehtaccess);
437
                    dolibarr_install_syslog("step1: .htaccess file created");
438
                }
439
            }
440
441
            // Documents are stored above the web pages root to prevent being downloaded without authentication
442
            $dir = array();
443
            $dir[] = $main_data_dir . "/mycompany";
444
            $dir[] = $main_data_dir . "/medias";
445
            $dir[] = $main_data_dir . "/users";
446
            $dir[] = $main_data_dir . "/facture";
447
            $dir[] = $main_data_dir . "/propale";
448
            $dir[] = $main_data_dir . "/ficheinter";
449
            $dir[] = $main_data_dir . "/produit";
450
            $dir[] = $main_data_dir . "/doctemplates";
451
452
            // Loop on each directory of dir [] to create them if they do not exist
453
            $num = count($dir);
454
            for ($i = 0; $i < $num; $i++) {
455
                if (is_dir($dir[$i])) {
456
                    dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' exists");
457
                } else {
458
                    if (dol_mkdir($dir[$i]) < 0) {
459
                        print "<tr><td>";
460
                        print "Failed to create directory: " . $dir[$i];
461
                        print '</td><td>';
462
                        print $langs->trans("Error");
463
                        print "</td></tr>";
464
                        $error++;
465
                    } else {
466
                        dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' created");
467
                    }
468
                }
469
            }
470
471
            require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
472
473
            // Copy directory medias
474
            $srcroot = $main_dir . '/install/medias';
475
            $destroot = $main_data_dir . '/medias';
476
            dolCopyDir($srcroot, $destroot, 0, 0);
477
478
            if ($error) {
479
                print "<tr><td>" . $langs->trans("ErrorDirDoesNotExists", $main_data_dir);
480
                print ' ' . $langs->trans("YouMustCreateItAndAllowServerToWrite");
481
                print '</td><td>';
482
                print '<span class="error">' . $langs->trans("Error") . '</span>';
483
                print "</td></tr>";
484
                print '<tr><td colspan="2"><br>' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</td></tr>';
485
            } else {
486
                //ODT templates
487
                $srcroot = $main_dir . '/install/doctemplates';
488
                $destroot = $main_data_dir . '/doctemplates';
489
                $docs = array(
490
                    'contracts' => 'contract',
491
                    'invoices' => 'invoice',
492
                    'orders' => 'order',
493
                    'products' => 'product',
494
                    'projects' => 'project',
495
                    'proposals' => 'proposal',
496
                    'shipments' => 'shipment',
497
                    'supplier_proposals' => 'supplier_proposal',
498
                    'tasks' => 'task_summary',
499
                    'thirdparties' => 'thirdparty',
500
                    'usergroups' => 'usergroups',
501
                    'users' => 'user',
502
                );
503
                foreach ($docs as $cursordir => $cursorfile) {
504
                    $src = $srcroot . '/' . $cursordir . '/template_' . $cursorfile . '.odt';
505
                    $dirodt = $destroot . '/' . $cursordir;
506
                    $dest = $dirodt . '/template_' . $cursorfile . '.odt';
507
508
                    dol_mkdir($dirodt);
509
                    $result = dol_copy($src, $dest, 0, 0);
510
                    if ($result < 0) {
511
                        print '<tr><td colspan="2"><br>' . $langs->trans('ErrorFailToCopyFile', $src, $dest) . '</td></tr>';
512
                    }
513
                }
514
            }
515
        }
516
    }
517
518
    // Table prefix
519
    $main_db_prefix = (!empty($db_prefix) ? $db_prefix : 'llx_');
520
521
    // Write conf file on disk
522
    if (!$error) {
523
        // Save old conf file on disk
524
        if (file_exists("$conffile")) {
525
            // We must ignore errors as an existing old file may already exist and not be replaceable or
526
            // the installer (like for ubuntu) may not have permission to create another file than conf.php.
527
            // Also no other process must be able to read file or we expose the new file, so content with password.
528
            @dol_copy($conffile, $conffile . '.old', '0400');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for dol_copy(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

528
            /** @scrutinizer ignore-unhandled */ @dol_copy($conffile, $conffile . '.old', '0400');

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
529
        }
530
531
        $error += write_conf_file($conffile);
532
    }
533
534
    // Create database and admin user database
535
    if (!$error) {
536
        // We reload configuration file
537
        conf($dolibarr_main_document_root);
538
539
        print '<tr><td>';
540
        print $langs->trans("ConfFileReload");
541
        print '</td>';
542
        print '<td><img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"></td></tr>';
543
544
        // Create database user if requested
545
        if (isset($db_create_user) && ($db_create_user == "1" || $db_create_user == "on")) {
546
            dolibarr_install_syslog("step1: create database user: " . $dolibarr_main_db_user);
547
548
            //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
549
            $databasefortest = $conf->db->name;
550
            if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') {
551
                $databasefortest = 'mysql';
552
            } elseif ($conf->db->type == 'pgsql') {
553
                $databasefortest = 'postgres';
554
            } elseif ($conf->db->type == 'mssql') {
555
                $databasefortest = 'master';
556
            }
557
558
            // Check database connection
559
560
            $db = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, $databasefortest, (int)$conf->db->port);
561
562
            if ($db->error) {
563
                print '<div class="error">' . $db->error . '</div>';
564
                $error++;
565
            }
566
567
            if (!$error) {
568
                if ($db->connected) {
569
                    $resultbis = 1;
570
571
                    if (empty($dolibarr_main_db_pass)) {
572
                        dolibarr_install_syslog("step1: failed to create user, password is empty", LOG_ERR);
573
                        print '<tr><td>';
574
                        print $langs->trans("UserCreation") . ' : ';
575
                        print $dolibarr_main_db_user;
576
                        print '</td>';
577
                        print '<td>' . $langs->trans("Error") . ": A password for database user is mandatory.</td></tr>";
578
                    } else {
579
                        // Create user
580
                        $result = $db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
581
582
                        // Create user bis
583
                        if ($databasefortest == 'mysql') {
584
                            if (!in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local'))) {
585
                                $resultbis = $db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
586
                            }
587
                        }
588
589
                        if ($result > 0 && $resultbis > 0) {
590
                            print '<tr><td>';
591
                            print $langs->trans("UserCreation") . ' : ';
592
                            print $dolibarr_main_db_user;
593
                            print '</td>';
594
                            print '<td><img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"></td></tr>';
595
                        } else {
596
                            if (
597
                                $db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
598
                                || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
599
                                || $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS'
600
                            ) {
601
                                dolibarr_install_syslog("step1: user already exists");
602
                                print '<tr><td>';
603
                                print $langs->trans("UserCreation") . ' : ';
604
                                print $dolibarr_main_db_user;
605
                                print '</td>';
606
                                print '<td>' . $langs->trans("LoginAlreadyExists") . '</td></tr>';
607
                            } else {
608
                                dolibarr_install_syslog("step1: failed to create user", LOG_ERR);
609
                                print '<tr><td>';
610
                                print $langs->trans("UserCreation") . ' : ';
611
                                print $dolibarr_main_db_user;
612
                                print '</td>';
613
                                print '<td>' . $langs->trans("Error") . ': ' . $db->errno() . ' ' . $db->error() . ($db->error ? '. ' . $db->error : '') . "</td></tr>";
614
                            }
615
                        }
616
                    }
617
618
                    $db->close();
619
                } else {
620
                    print '<tr><td>';
621
                    print $langs->trans("UserCreation") . ' : ';
622
                    print $dolibarr_main_db_user;
623
                    print '</td>';
624
                    print '<td><img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error"></td>';
625
                    print '</tr>';
626
627
                    // warning message due to connection failure
628
                    print '<tr><td colspan="2"><br>';
629
                    print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot);
630
                    print '<br>';
631
                    print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
632
                    print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>';
633
                    print '</td></tr>';
634
635
                    $error++;
636
                }
637
            }
638
        }   // end of user account creation
639
640
641
        // If database creation was asked, we create it
642
        if (!$error && (isset($db_create_database) && ($db_create_database == "1" || $db_create_database == "on"))) {
643
            dolibarr_install_syslog("step1: create database: " . $dolibarr_main_db_name . " " . $dolibarr_main_db_character_set . " " . $dolibarr_main_db_collation . " " . $dolibarr_main_db_user);
644
            $newdb = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, '', (int)$conf->db->port);
645
            //print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
646
647
            if ($newdb->connected) {
648
                $result = $newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
649
650
                if ($result) {
651
                    print '<tr><td>';
652
                    print $langs->trans("DatabaseCreation") . " (" . $langs->trans("User") . " " . $userroot . ") : ";
653
                    print $dolibarr_main_db_name;
654
                    print '</td>';
655
                    print '<td><img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"></td></tr>';
656
657
                    $newdb->select_db($dolibarr_main_db_name);
658
                    $check1 = $newdb->getDefaultCharacterSetDatabase();
659
                    $check2 = $newdb->getDefaultCollationDatabase();
660
                    dolibarr_install_syslog('step1: new database is using charset=' . $check1 . ' collation=' . $check2);
661
662
                    // If values differs, we save conf file again
663
                    //if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('step1: value for character_set is not the one asked for database creation', LOG_WARNING);
664
                    //if ($check2 != $dolibarr_main_db_collation)     dolibarr_install_syslog('step1: value for collation is not the one asked for database creation', LOG_WARNING);
665
                } else {
666
                    // warning message
667
                    print '<tr><td colspan="2"><br>';
668
                    print $langs->trans("ErrorFailedToCreateDatabase", $dolibarr_main_db_name) . '<br>';
669
                    print $newdb->lasterror() . '<br>';
670
                    print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
671
                    print '<br>';
672
                    print '</td></tr>';
673
674
                    dolibarr_install_syslog('step1: failed to create database ' . $dolibarr_main_db_name . ' ' . $newdb->lasterrno() . ' ' . $newdb->lasterror(), LOG_ERR);
675
                    $error++;
676
                }
677
                $newdb->close();
678
            } else {
679
                print '<tr><td>';
680
                print $langs->trans("DatabaseCreation") . " (" . $langs->trans("User") . " " . $userroot . ") : ";
681
                print $dolibarr_main_db_name;
682
                print '</td>';
683
                print '<td><img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error"></td>';
684
                print '</tr>';
685
686
                // warning message
687
                print '<tr><td colspan="2"><br>';
688
                print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot);
689
                print '<br>';
690
                print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>';
691
                print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>';
692
                print '</td></tr>';
693
694
                $error++;
695
            }
696
        }   // end of create database
697
698
699
        // We test access with dolibarr database user (not admin)
700
        if (!$error) {
701
            dolibarr_install_syslog("step1: connection type=" . $conf->db->type . " on host=" . $conf->db->host . " port=" . $conf->db->port . " user=" . $conf->db->user . " name=" . $conf->db->name);
702
            //print "connection de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
703
704
            $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int)$conf->db->port);
705
706
            if ($db->connected) {
707
                dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " ok");
708
                print "<tr><td>";
709
                print $langs->trans("ServerConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : ";
710
                print $dolibarr_main_db_host;
711
                print "</td><td>";
712
                print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok">';
713
                print "</td></tr>";
714
715
                // server access ok, basic access ok
716
                if ($db->database_selected) {
717
                    dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " ok");
718
                    print "<tr><td>";
719
                    print $langs->trans("DatabaseConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : ";
720
                    print $dolibarr_main_db_name;
721
                    print "</td><td>";
722
                    print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok">';
723
                    print "</td></tr>";
724
725
                    $error = 0;
726
                } else {
727
                    dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " failed", LOG_ERR);
728
                    print "<tr><td>";
729
                    print $langs->trans("DatabaseConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : ";
730
                    print $dolibarr_main_db_name;
731
                    print '</td><td>';
732
                    print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error">';
733
                    print "</td></tr>";
734
735
                    // warning message
736
                    print '<tr><td colspan="2"><br>';
737
                    print $langs->trans('CheckThatDatabasenameIsCorrect', $dolibarr_main_db_name) . '<br>';
738
                    print $langs->trans('IfAlreadyExistsCheckOption') . '<br>';
739
                    print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>';
740
                    print '</td></tr>';
741
742
                    $error++;
743
                }
744
            } else {
745
                dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " failed", LOG_ERR);
746
                print "<tr><td>";
747
                print $langs->trans("ServerConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : ";
748
                print $dolibarr_main_db_host;
749
                print '</td><td>';
750
                print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error">';
751
                print "</td></tr>";
752
753
                // warning message
754
                print '<tr><td colspan="2"><br>';
755
                print $langs->trans("ErrorConnection", $conf->db->host, $conf->db->name, $conf->db->user);
756
                print $langs->trans('IfLoginDoesNotExistsCheckCreateUser') . '<br>';
757
                print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>';
758
                print '</td></tr>';
759
760
                $error++;
761
            }
762
        }
763
    }
764
765
    print '</table>';
766
}
767
768
?>
769
770
    <script type="text/javascript">
771
        function jsinfo() {
772
            ok = true;
773
774
            //alert('<?php echo dol_escape_js($langs->transnoentities("NextStepMightLastALongTime")); ?>');
775
776
            document.getElementById('nextbutton').style.visibility = "hidden";
777
            document.getElementById('pleasewait').style.visibility = "visible";
778
779
            return ok;
780
        }
781
    </script>
782
783
<?php
784
785
$ret = 0;
786
if ($error && isset($argv[1])) {
787
    $ret = 1;
788
}
789
dolibarr_install_syslog("Exit " . $ret);
790
791
dolibarr_install_syslog("--- step1: end");
792
793
pFooter($error ? 1 : 0, $setuplang, 'jsinfo', 1);
794
795
// Return code if ran from command line
796
if ($ret) {
797
    exit($ret);
798
}
799
800
801
/**
802
 *  Create main file. No particular permissions are set by installer.
803
 *
804
 * @param string $mainfile Full path name of main file to generate/update
805
 * @param string $main_dir Full path name to main.inc.php file
806
 * @return void
807
 */
808
function write_main_file($mainfile, $main_dir)
809
{
810
    $fp = @fopen("$mainfile", "w");
811
    if ($fp) {
812
        clearstatcache();
813
        fwrite($fp, '<?php' . "\n");
814
        fwrite($fp, "// Wrapper to include main into htdocs\n");
815
        fwrite($fp, "include_once '" . $main_dir . "/main.inc.php';\n");
816
        fclose($fp);
817
    }
818
}
819
820
821
/**
822
 *  Create master file. No particular permissions are set by installer.
823
 *
824
 * @param string $masterfile Full path name of master file to generate/update
825
 * @param string $main_dir Full path name to master.inc.php file
826
 * @return void
827
 */
828
function write_master_file($masterfile, $main_dir)
829
{
830
    $fp = @fopen("$masterfile", "w");
831
    if ($fp) {
832
        clearstatcache();
833
        fwrite($fp, '<?php' . "\n");
834
        fwrite($fp, "// Wrapper to include master into htdocs\n");
835
        fwrite($fp, "include_once '" . $main_dir . "/master.inc.php';\n");
836
        fclose($fp);
837
    }
838
}
839
840
841
/**
842
 *  Save configuration file. No particular permissions are set by installer.
843
 *
844
 * @param string $conffile Path to conf file to generate/update
845
 * @return integer
846
 */
847
function write_conf_file($conffile)
848
{
849
    global $conf, $langs;
850
    global $main_url, $main_dir, $main_data_dir, $main_force_https, $main_use_alt_dir, $main_alt_dir_name, $main_db_prefix;
851
    global $dolibarr_main_url_root, $dolibarr_main_document_root, $dolibarr_main_data_root, $dolibarr_main_db_host;
852
    global $dolibarr_main_db_port, $dolibarr_main_db_name, $dolibarr_main_db_user, $dolibarr_main_db_pass;
853
    global $dolibarr_main_db_type, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_authentication;
854
    global $dolibarr_main_distrib;
855
    global $db_host, $db_port, $db_name, $db_user, $db_pass, $db_type, $db_character_set, $db_collation;
856
    global $conffile, $conffiletoshow, $conffiletoshowshort;
857
    global $force_dolibarr_lib_NUSOAP_PATH;
858
    global $force_dolibarr_lib_FPDF_PATH, $force_dolibarr_lib_TCPDF_PATH, $force_dolibarr_lib_FPDI_PATH;
859
    global $force_dolibarr_lib_GEOIP_PATH;
860
    global $force_dolibarr_lib_ODTPHP_PATH, $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP;
861
    global $force_dolibarr_js_CKEDITOR, $force_dolibarr_js_JQUERY, $force_dolibarr_js_JQUERY_UI;
862
    global $force_dolibarr_font_DOL_DEFAULT_TTF, $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD;
863
864
    $error = 0;
865
866
    $key = md5(uniqid((string)mt_rand(), true)); // Generate random hash
867
868
    $fp = fopen("$conffile", "w");
869
    if ($fp) {
870
        clearstatcache();
871
872
        fwrite($fp, '<?php' . "\n");
873
        fwrite($fp, '//' . "\n");
874
        fwrite($fp, '// File generated by Dolibarr installer ' . DOL_VERSION . ' on ' . dol_print_date(dol_now(), '') . "\n");
875
        fwrite($fp, '//' . "\n");
876
        fwrite($fp, '// Take a look at conf.php.example file for an example of ' . $conffiletoshowshort . ' file' . "\n");
877
        fwrite($fp, '// and explanations for all possibles parameters.' . "\n");
878
        fwrite($fp, '//' . "\n");
879
        fwrite($fp, '$dolibarr_main_url_root=\'' . dol_escape_php(trim($main_url), 1) . '\';');
880
        fwrite($fp, "\n");
881
882
        fwrite($fp, '$dolibarr_main_document_root="' . dol_escape_php(dol_sanitizePathName(trim($main_dir))) . '";');
883
        fwrite($fp, "\n");
884
885
        fwrite($fp, $main_use_alt_dir . '$dolibarr_main_url_root_alt=\'' . dol_escape_php(trim("/" . $main_alt_dir_name), 1) . '\';');
886
        fwrite($fp, "\n");
887
888
        fwrite($fp, $main_use_alt_dir . '$dolibarr_main_document_root_alt="' . dol_escape_php(dol_sanitizePathName(trim($main_dir . "/" . $main_alt_dir_name))) . '";');
889
        fwrite($fp, "\n");
890
891
        fwrite($fp, '$dolibarr_main_data_root="' . dol_escape_php(dol_sanitizePathName(trim($main_data_dir))) . '";');
892
        fwrite($fp, "\n");
893
894
        fwrite($fp, '$dolibarr_main_db_host=\'' . dol_escape_php(trim($db_host), 1) . '\';');
895
        fwrite($fp, "\n");
896
897
        fwrite($fp, '$dolibarr_main_db_port=\'' . ((int)$db_port) . '\';');
898
        fwrite($fp, "\n");
899
900
        fwrite($fp, '$dolibarr_main_db_name=\'' . dol_escape_php(trim($db_name), 1) . '\';');
901
        fwrite($fp, "\n");
902
903
        fwrite($fp, '$dolibarr_main_db_prefix=\'' . dol_escape_php(trim($main_db_prefix), 1) . '\';');
904
        fwrite($fp, "\n");
905
906
        fwrite($fp, '$dolibarr_main_db_user=\'' . dol_escape_php(trim($db_user), 1) . '\';');
907
        fwrite($fp, "\n");
908
        fwrite($fp, '$dolibarr_main_db_pass=\'' . dol_escape_php(trim($db_pass), 1) . '\';');
909
        fwrite($fp, "\n");
910
911
        fwrite($fp, '$dolibarr_main_db_type=\'' . dol_escape_php(trim($db_type), 1) . '\';');
912
        fwrite($fp, "\n");
913
914
        fwrite($fp, '$dolibarr_main_db_character_set=\'' . dol_escape_php(trim($db_character_set), 1) . '\';');
915
        fwrite($fp, "\n");
916
917
        fwrite($fp, '$dolibarr_main_db_collation=\'' . dol_escape_php(trim($db_collation), 1) . '\';');
918
        fwrite($fp, "\n");
919
920
        // Authentication
921
        fwrite($fp, '// Authentication settings');
922
        fwrite($fp, "\n");
923
924
        fwrite($fp, '$dolibarr_main_authentication=\'dolibarr\';');
925
        fwrite($fp, "\n\n");
926
927
        fwrite($fp, '//$dolibarr_main_demo=\'autologin,autopass\';');
928
        fwrite($fp, "\n");
929
930
        fwrite($fp, '// Security settings');
931
        fwrite($fp, "\n");
932
933
        fwrite($fp, '$dolibarr_main_prod=\'0\';');
934
        fwrite($fp, "\n");
935
936
        fwrite($fp, '$dolibarr_main_force_https=\'' . dol_escape_php($main_force_https, 1) . '\';');
937
        fwrite($fp, "\n");
938
939
        fwrite($fp, '$dolibarr_main_restrict_os_commands=\'mariadb-dump, mariadb, mysqldump, mysql, pg_dump, pg_restore, clamdscan, clamdscan.exe\';');
940
        fwrite($fp, "\n");
941
942
        fwrite($fp, '$dolibarr_nocsrfcheck=\'0\';');
943
        fwrite($fp, "\n");
944
945
        fwrite($fp, '$dolibarr_main_instance_unique_id=\'' . dol_escape_php($key, 1) . '\';');
946
        fwrite($fp, "\n");
947
948
        fwrite($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
949
        fwrite($fp, "\n");
950
        fwrite($fp, '$dolibarr_mailing_limit_sendbycli=\'0\';');
951
        fwrite($fp, "\n");
952
953
        // Write params to overwrites default lib path
954
        fwrite($fp, "\n");
955
        if (empty($force_dolibarr_lib_FPDF_PATH)) {
956
            fwrite($fp, '//');
957
            $force_dolibarr_lib_FPDF_PATH = '';
958
        }
959
        fwrite($fp, '$dolibarr_lib_FPDF_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_FPDF_PATH)) . '";');
960
        fwrite($fp, "\n");
961
        if (empty($force_dolibarr_lib_TCPDF_PATH)) {
962
            fwrite($fp, '//');
963
            $force_dolibarr_lib_TCPDF_PATH = '';
964
        }
965
        fwrite($fp, '$dolibarr_lib_TCPDF_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_TCPDF_PATH)) . '";');
966
        fwrite($fp, "\n");
967
        if (empty($force_dolibarr_lib_FPDI_PATH)) {
968
            fwrite($fp, '//');
969
            $force_dolibarr_lib_FPDI_PATH = '';
970
        }
971
        fwrite($fp, '$dolibarr_lib_FPDI_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_FPDI_PATH)) . '";');
972
        fwrite($fp, "\n");
973
        if (empty($force_dolibarr_lib_TCPDI_PATH)) {
974
            fwrite($fp, '//');
975
            $force_dolibarr_lib_TCPDI_PATH = '';
976
        }
977
        fwrite($fp, '$dolibarr_lib_TCPDI_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_TCPDI_PATH)) . '";');
978
        fwrite($fp, "\n");
979
        if (empty($force_dolibarr_lib_GEOIP_PATH)) {
980
            fwrite($fp, '//');
981
            $force_dolibarr_lib_GEOIP_PATH = '';
982
        }
983
        fwrite($fp, '$dolibarr_lib_GEOIP_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_GEOIP_PATH)) . '";');
984
        fwrite($fp, "\n");
985
        if (empty($force_dolibarr_lib_NUSOAP_PATH)) {
986
            fwrite($fp, '//');
987
            $force_dolibarr_lib_NUSOAP_PATH = '';
988
        }
989
        fwrite($fp, '$dolibarr_lib_NUSOAP_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_NUSOAP_PATH)) . '";');
990
        fwrite($fp, "\n");
991
        if (empty($force_dolibarr_lib_ODTPHP_PATH)) {
992
            fwrite($fp, '//');
993
            $force_dolibarr_lib_ODTPHP_PATH = '';
994
        }
995
        fwrite($fp, '$dolibarr_lib_ODTPHP_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_ODTPHP_PATH)) . '";');
996
        fwrite($fp, "\n");
997
        if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) {
998
            fwrite($fp, '//');
999
            $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP = '';
1000
        }
1001
        fwrite($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) . '";');
1002
        fwrite($fp, "\n");
1003
        if (empty($force_dolibarr_js_CKEDITOR)) {
1004
            fwrite($fp, '//');
1005
            $force_dolibarr_js_CKEDITOR = '';
1006
        }
1007
        fwrite($fp, '$dolibarr_js_CKEDITOR=\'' . dol_escape_php($force_dolibarr_js_CKEDITOR, 1) . '\';');
1008
        fwrite($fp, "\n");
1009
        if (empty($force_dolibarr_js_JQUERY)) {
1010
            fwrite($fp, '//');
1011
            $force_dolibarr_js_JQUERY = '';
1012
        }
1013
        fwrite($fp, '$dolibarr_js_JQUERY=\'' . dol_escape_php($force_dolibarr_js_JQUERY, 1) . '\';');
1014
        fwrite($fp, "\n");
1015
        if (empty($force_dolibarr_js_JQUERY_UI)) {
1016
            fwrite($fp, '//');
1017
            $force_dolibarr_js_JQUERY_UI = '';
1018
        }
1019
        fwrite($fp, '$dolibarr_js_JQUERY_UI=\'' . dol_escape_php($force_dolibarr_js_JQUERY_UI, 1) . '\';');
1020
        fwrite($fp, "\n");
1021
1022
        // Write params to overwrites default font path
1023
        fwrite($fp, "\n");
1024
        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) {
1025
            fwrite($fp, '//');
1026
            $force_dolibarr_font_DOL_DEFAULT_TTF = '';
1027
        }
1028
        fwrite($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\'' . dol_escape_php($force_dolibarr_font_DOL_DEFAULT_TTF, 1) . '\';');
1029
        fwrite($fp, "\n");
1030
        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) {
1031
            fwrite($fp, '//');
1032
            $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD = '';
1033
        }
1034
        fwrite($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\'' . dol_escape_php($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD, 1) . '\';');
1035
        fwrite($fp, "\n");
1036
1037
        // Other
1038
        fwrite($fp, '$dolibarr_main_distrib=\'' . dol_escape_php(trim($dolibarr_main_distrib), 1) . '\';');
1039
        fwrite($fp, "\n");
1040
1041
        fclose($fp);
1042
1043
        if (file_exists("$conffile")) {
1044
            include $conffile; // force config reload, do not put include_once
1045
            conf($dolibarr_main_document_root);
1046
1047
            print "<tr><td>";
1048
            print $langs->trans("SaveConfigurationFile");
1049
            print ' <strong>' . $conffile . '</strong>';
1050
            print "</td><td>";
1051
            print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok">';
1052
            print "</td></tr>";
1053
        } else {
1054
            $error++;
1055
        }
1056
    }
1057
1058
    return $error;
1059
}
1060