Total Complexity | 686 |
Total Lines | 3613 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like InstallController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use InstallController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
46 | class InstallController extends DolibarrNoLoginController |
||
|
|||
47 | { |
||
48 | const DEFAULT_DATABASE_NAME = 'alixar'; |
||
49 | const DEFAULT_DATABASE_PREFIX = 'alx_'; |
||
50 | |||
51 | public function index() |
||
52 | { |
||
53 | global $langs; |
||
54 | global $conf; |
||
55 | |||
56 | $err = 0; |
||
57 | |||
58 | $conffile = Config::getDolibarrConfigFilename(); |
||
59 | |||
60 | // If the config file exists and is filled, we're not on first install so we skip the language selection page |
||
61 | if (file_exists($conffile) && isset($dolibarr_main_url_root)) { |
||
62 | return $this->check(true); |
||
63 | } |
||
64 | |||
65 | if (!isset($conf)) { |
||
66 | $conf = Config::loadConf(); |
||
67 | } |
||
68 | |||
69 | if (!isset($langs)) { |
||
70 | $langs = Globals::getLangs($conf); |
||
71 | $langs->setDefaultLang('auto'); |
||
72 | } |
||
73 | |||
74 | $langs->load("admin"); |
||
75 | |||
76 | /* |
||
77 | * View |
||
78 | */ |
||
79 | |||
80 | $formadmin = new FormAdmin(null); // Note: $db does not exist yet but we don't need it, so we put ''. |
||
81 | |||
82 | pHeader("", "check"); // Next step = check |
||
83 | |||
84 | |||
85 | if (!is_readable($conffile)) { |
||
86 | print '<br>'; |
||
87 | print '<span class="opacitymedium">' . $langs->trans("NoReadableConfFileSoStartInstall") . '</span>'; |
||
88 | } |
||
89 | |||
90 | |||
91 | // Ask installation language |
||
92 | print '<br><br><div class="center">'; |
||
93 | print '<table>'; |
||
94 | |||
95 | print '<tr>'; |
||
96 | print '<td>' . $langs->trans("DefaultLanguage") . ' : </td><td>'; |
||
97 | print $formadmin->select_language('auto', 'selectlang', 1, 0, 0, 1); |
||
98 | print '</td>'; |
||
99 | print '</tr>'; |
||
100 | |||
101 | print '</table></div>'; |
||
102 | |||
103 | |||
104 | //print '<br><br><span class="opacitymedium">'.$langs->trans("SomeTranslationAreUncomplete").'</span>'; |
||
105 | |||
106 | // If there's no error, we display the next step button |
||
107 | if ($err == 0) { |
||
108 | pFooter(0); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | public function check($testget = false) |
||
113 | { |
||
114 | global $langs; |
||
115 | global $conf; |
||
116 | |||
117 | $conffile = Config::getDolibarrConfigFilename(); |
||
118 | $conffiletoshow = $conffile; |
||
119 | |||
120 | if (!isset($conf)) { |
||
121 | $conf = Config::loadConf(); |
||
122 | } |
||
123 | |||
124 | if (!isset($langs)) { |
||
125 | $langs = Globals::getLangs($conf); |
||
126 | $langs->setDefaultLang('auto'); |
||
127 | } |
||
128 | |||
129 | $err = 0; |
||
130 | $allowinstall = 0; |
||
131 | $allowupgrade = false; |
||
132 | $checksok = 1; |
||
133 | |||
134 | $setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang(); |
||
135 | $langs->setDefaultLang($setuplang); |
||
136 | |||
137 | $langs->load("install"); |
||
138 | |||
139 | // Now we load forced/pre-set values from install.forced.php file. |
||
140 | $useforcedwizard = false; |
||
141 | $forcedfile = "./install.forced.php"; |
||
142 | if ($conffile == "/etc/dolibarr/conf.php") { |
||
143 | $forcedfile = "/etc/dolibarr/install.forced.php"; |
||
144 | } |
||
145 | if (@file_exists($forcedfile)) { |
||
146 | $useforcedwizard = true; |
||
147 | include_once $forcedfile; |
||
148 | } |
||
149 | |||
150 | dolibarr_install_syslog("- check: Dolibarr install/upgrade process started"); |
||
151 | |||
152 | |||
153 | /* |
||
154 | * View |
||
155 | */ |
||
156 | |||
157 | pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links. |
||
158 | |||
159 | |||
160 | //print "<br>\n"; |
||
161 | //print $langs->trans("InstallEasy")."<br><br>\n"; |
||
162 | |||
163 | print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> '; |
||
164 | print '<span class="inline-block">' . $langs->trans("MiscellaneousChecks") . "</span></h3>\n"; |
||
165 | |||
166 | // Check browser |
||
167 | $useragent = $_SERVER['HTTP_USER_AGENT']; |
||
168 | if (!empty($useragent)) { |
||
169 | $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]); |
||
170 | $browserversion = $tmp['browserversion']; |
||
171 | $browsername = $tmp['browsername']; |
||
172 | if ($browsername == 'ie' && $browserversion < 7) { |
||
173 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("WarningBrowserTooOld") . "<br>\n"; |
||
174 | } |
||
175 | } |
||
176 | |||
177 | |||
178 | // Check PHP version min |
||
179 | $arrayphpminversionerror = [7, 0, 0]; |
||
180 | $arrayphpminversionwarning = [7, 1, 0]; |
||
181 | if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower) |
||
182 | print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror)); |
||
183 | $checksok = 0; // 0=error, 1=warning |
||
184 | } elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower) |
||
185 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning)); |
||
186 | $checksok = 1; // 0=error, 1=warning |
||
187 | } else { |
||
188 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPVersion") . " " . versiontostring(versionphparray()); |
||
189 | } |
||
190 | if (empty($force_install_nophpinfo)) { |
||
191 | print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">' . $langs->trans("MoreInformation") . '</a>)'; |
||
192 | } |
||
193 | print "<br>\n"; |
||
194 | |||
195 | // Check PHP version max |
||
196 | $arrayphpmaxversionwarning = [8, 2, 0]; |
||
197 | if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher) |
||
198 | print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning)); |
||
199 | $checksok = 1; // 0=error, 1=warning |
||
200 | print "<br>\n"; |
||
201 | } |
||
202 | |||
203 | |||
204 | // Check PHP support for $_GET and $_POST |
||
205 | if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here |
||
206 | print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> ' . $langs->trans("PHPSupportPOSTGETKo"); |
||
207 | print ' (<a href="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?testget=ok">' . $langs->trans("Recheck") . '</a>)'; |
||
208 | print "<br>\n"; |
||
209 | $checksok = 0; |
||
210 | } else { |
||
211 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupportPOSTGETOk") . "<br>\n"; |
||
212 | } |
||
213 | |||
214 | |||
215 | // Check if session_id is enabled |
||
216 | if (!function_exists("session_id")) { |
||
217 | print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupportSessions") . "<br>\n"; |
||
218 | $checksok = 0; |
||
219 | } else { |
||
220 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupportSessions") . "<br>\n"; |
||
221 | } |
||
222 | |||
223 | |||
224 | // Check for mbstring extension |
||
225 | if (!extension_loaded("mbstring")) { |
||
226 | $langs->load("errors"); |
||
227 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "MBString") . "<br>\n"; |
||
228 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
229 | } else { |
||
230 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "MBString") . "<br>\n"; |
||
231 | } |
||
232 | |||
233 | // Check for json extension |
||
234 | if (!extension_loaded("json")) { |
||
235 | $langs->load("errors"); |
||
236 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "JSON") . "<br>\n"; |
||
237 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
238 | } else { |
||
239 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "JSON") . "<br>\n"; |
||
240 | } |
||
241 | |||
242 | // Check if GD is supported (we need GD for image conversion) |
||
243 | if (!function_exists("imagecreate")) { |
||
244 | $langs->load("errors"); |
||
245 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "GD") . "<br>\n"; |
||
246 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
247 | } else { |
||
248 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "GD") . "<br>\n"; |
||
249 | } |
||
250 | |||
251 | // Check if Curl is supported |
||
252 | if (!function_exists("curl_init")) { |
||
253 | $langs->load("errors"); |
||
254 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Curl") . "<br>\n"; |
||
255 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
256 | } else { |
||
257 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Curl") . "<br>\n"; |
||
258 | } |
||
259 | |||
260 | // Check if PHP calendar extension is available |
||
261 | if (!function_exists("easter_date")) { |
||
262 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Calendar") . "<br>\n"; |
||
263 | } else { |
||
264 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Calendar") . "<br>\n"; |
||
265 | } |
||
266 | |||
267 | // Check if Xml is supported |
||
268 | if (!function_exists("simplexml_load_string")) { |
||
269 | $langs->load("errors"); |
||
270 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Xml") . "<br>\n"; |
||
271 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
272 | } else { |
||
273 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Xml") . "<br>\n"; |
||
274 | } |
||
275 | |||
276 | // Check if UTF8 is supported |
||
277 | if (!function_exists("utf8_encode")) { |
||
278 | $langs->load("errors"); |
||
279 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "UTF8") . "<br>\n"; |
||
280 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
281 | } else { |
||
282 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "UTF8") . "<br>\n"; |
||
283 | } |
||
284 | |||
285 | // Check if intl methods are supported if install is not from DoliWamp. TODO Why ? |
||
286 | if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') { |
||
287 | if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) { |
||
288 | $langs->load("errors"); |
||
289 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Intl") . "<br>\n"; |
||
290 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
291 | } else { |
||
292 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Intl") . "<br>\n"; |
||
293 | } |
||
294 | } |
||
295 | |||
296 | // Check if Imap is supported |
||
297 | if (PHP_VERSION_ID <= 80300) { |
||
298 | if (!function_exists("imap_open")) { |
||
299 | $langs->load("errors"); |
||
300 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "IMAP") . "<br>\n"; |
||
301 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
302 | } else { |
||
303 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "IMAP") . "<br>\n"; |
||
304 | } |
||
305 | } |
||
306 | |||
307 | // Check if Zip is supported |
||
308 | if (!class_exists('ZipArchive')) { |
||
309 | $langs->load("errors"); |
||
310 | print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "ZIP") . "<br>\n"; |
||
311 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
312 | } else { |
||
313 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "ZIP") . "<br>\n"; |
||
314 | } |
||
315 | |||
316 | // Check memory |
||
317 | $memrequiredorig = '64M'; |
||
318 | $memrequired = 64 * 1024 * 1024; |
||
319 | $memmaxorig = @ini_get("memory_limit"); |
||
320 | $memmax = @ini_get("memory_limit"); |
||
321 | if ($memmaxorig != '') { |
||
322 | preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg); |
||
323 | if ($reg[2]) { |
||
324 | if (strtoupper($reg[2]) == 'G') { |
||
325 | $memmax = $reg[1] * 1024 * 1024 * 1024; |
||
326 | } |
||
327 | if (strtoupper($reg[2]) == 'M') { |
||
328 | $memmax = $reg[1] * 1024 * 1024; |
||
329 | } |
||
330 | if (strtoupper($reg[2]) == 'K') { |
||
331 | $memmax = $reg[1] * 1024; |
||
332 | } |
||
333 | } |
||
334 | if ($memmax >= $memrequired || $memmax == -1) { |
||
335 | print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig) . "<br>\n"; |
||
336 | } else { |
||
337 | print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> ' . $langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig) . "<br>\n"; |
||
338 | } |
||
339 | } |
||
340 | |||
341 | |||
342 | // If that config file is present and filled |
||
343 | clearstatcache(); |
||
344 | if (is_readable($conffile) && filesize($conffile) > 8) { |
||
345 | dolibarr_install_syslog("check: conf file '" . $conffile . "' already defined"); |
||
346 | $confexists = 1; |
||
347 | include_once $conffile; |
||
348 | |||
349 | $databaseok = 1; |
||
350 | if ($databaseok) { |
||
351 | // Already installed for all parts (config and database). We can propose upgrade. |
||
352 | $allowupgrade = true; |
||
353 | } else { |
||
354 | $allowupgrade = false; |
||
355 | } |
||
356 | } else { |
||
357 | // If not, we create it |
||
358 | dolibarr_install_syslog("check: we try to create conf file '" . $conffile . "'"); |
||
359 | $confexists = 0; |
||
360 | |||
361 | // First we try by copying example |
||
362 | if (@copy($conffile . ".example", $conffile)) { |
||
363 | // Success |
||
364 | dolibarr_install_syslog("check: successfully copied file " . $conffile . ".example into " . $conffile); |
||
365 | } else { |
||
366 | // If failed, we try to create an empty file |
||
367 | dolibarr_install_syslog("check: failed to copy file " . $conffile . ".example into " . $conffile . ". We try to create it.", LOG_WARNING); |
||
368 | |||
369 | $fp = @fopen($conffile, "w"); |
||
370 | if ($fp) { |
||
371 | @fwrite($fp, '<?php'); |
||
372 | @fwrite($fp, "\n"); |
||
373 | fclose($fp); |
||
374 | } else { |
||
375 | dolibarr_install_syslog("check: failed to create a new file " . $conffile . " into current dir " . getcwd() . ". Please check permissions.", LOG_ERR); |
||
376 | } |
||
377 | } |
||
378 | |||
379 | // First install: no upgrade necessary/required |
||
380 | $allowupgrade = false; |
||
381 | } |
||
382 | |||
383 | // File is missing and cannot be created |
||
384 | if (!file_exists($conffile)) { |
||
385 | print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow); |
||
386 | print '<br><br><div class="error">'; |
||
387 | print $langs->trans("YouMustCreateWithPermission", $conffiletoshow); |
||
388 | print '</div><br><br>' . "\n"; |
||
389 | |||
390 | print '<span class="opacitymedium">' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</span>'; |
||
391 | $err++; |
||
392 | } else { |
||
393 | if (dol_is_dir($conffile)) { |
||
394 | print '<img src="../theme/eldy/img/error.png" alt="Warning"> ' . $langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow); |
||
395 | |||
396 | $allowinstall = 0; |
||
397 | } elseif (!is_writable($conffile)) { |
||
398 | // File exists but cannot be modified |
||
399 | if ($confexists) { |
||
400 | print '<img src="../theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileExists", $conffiletoshow); |
||
401 | } else { |
||
402 | print '<img src="../theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileCouldBeCreated", $conffiletoshow); |
||
403 | } |
||
404 | print "<br>"; |
||
405 | print '<img src="../theme/eldy/img/tick.png" alt="Warning"> ' . $langs->trans("ConfFileIsNotWritable", $conffiletoshow); |
||
406 | print "<br>\n"; |
||
407 | |||
408 | $allowinstall = 0; |
||
409 | } else { |
||
410 | // File exists and can be modified |
||
411 | if ($confexists) { |
||
412 | print '<img src="../theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileExists", $conffiletoshow); |
||
413 | } else { |
||
414 | print '<img src="../theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileCouldBeCreated", $conffiletoshow); |
||
415 | } |
||
416 | print "<br>"; |
||
417 | print '<img src="../theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileIsWritable", $conffiletoshow); |
||
418 | print "<br>\n"; |
||
419 | |||
420 | $allowinstall = 1; |
||
421 | } |
||
422 | print "<br>\n"; |
||
423 | |||
424 | // Requirements met/all ok: display the next step button |
||
425 | if ($checksok) { |
||
426 | $ok = 0; |
||
427 | |||
428 | // Try to create db connection |
||
429 | if (file_exists($conffile)) { |
||
430 | include_once $conffile; |
||
431 | if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) { |
||
432 | if (!file_exists($dolibarr_main_document_root . "/core/lib/admin.lib.php")) { |
||
433 | print '<span class="error">A ' . $conffiletoshow . ' file exists with a dolibarr_main_document_root to ' . $dolibarr_main_document_root . ' that seems wrong. Try to fix or remove the ' . $conffiletoshow . ' file.</span><br>' . "\n"; |
||
434 | dol_syslog("A '" . $conffiletoshow . "' file exists with a dolibarr_main_document_root to " . $dolibarr_main_document_root . " that seems wrong. Try to fix or remove the '" . $conffiletoshow . "' file.", LOG_WARNING); |
||
435 | } else { |
||
436 | require_once $dolibarr_main_document_root . '/core/lib/admin.lib.php'; |
||
437 | |||
438 | // If password is encoded, we decode it |
||
439 | if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) { |
||
440 | require_once $dolibarr_main_document_root . '/core/lib/security.lib.php'; |
||
441 | if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) { |
||
442 | $dolibarr_main_db_encrypted_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); // We need to set this as it is used to know the password was initially encrypted |
||
443 | $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); |
||
444 | } else { |
||
445 | $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); |
||
446 | } |
||
447 | } |
||
448 | |||
449 | // $conf already created in inc.php |
||
450 | $conf->db->type = $dolibarr_main_db_type; |
||
451 | $conf->db->host = $dolibarr_main_db_host; |
||
452 | $conf->db->port = $dolibarr_main_db_port; |
||
453 | $conf->db->name = $dolibarr_main_db_name; |
||
454 | $conf->db->user = $dolibarr_main_db_user; |
||
455 | $conf->db->pass = $dolibarr_main_db_pass; |
||
456 | $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port); |
||
457 | if ($db->connected && $db->database_selected) { |
||
458 | $ok = true; |
||
459 | } |
||
460 | } |
||
461 | } |
||
462 | } |
||
463 | |||
464 | // If database access is available, we set more variables |
||
465 | if ($ok) { |
||
466 | if (empty($dolibarr_main_db_encryption)) { |
||
467 | $dolibarr_main_db_encryption = 0; |
||
468 | } |
||
469 | $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; |
||
470 | if (empty($dolibarr_main_db_cryptkey)) { |
||
471 | $dolibarr_main_db_cryptkey = ''; |
||
472 | } |
||
473 | $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; |
||
474 | |||
475 | $conf->setValues($db); |
||
476 | // Reset forced setup after the setValues |
||
477 | if (defined('SYSLOG_FILE')) { |
||
478 | $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); |
||
479 | } |
||
480 | $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; |
||
481 | |||
482 | // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE |
||
483 | // Version to install is DOL_VERSION |
||
484 | $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : '')); |
||
485 | $dolibarrversiontoinstallarray = versiondolibarrarray(); |
||
486 | } |
||
487 | |||
488 | // Show title |
||
489 | if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) { |
||
490 | print $langs->trans("VersionLastUpgrade") . ': <b><span class="ok">' . (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE) . '</span></b> - '; |
||
491 | print $langs->trans("VersionProgram") . ': <b><span class="ok">' . DOL_VERSION . '</span></b>'; |
||
492 | //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired")); |
||
493 | print '<br>'; |
||
494 | print '<br>'; |
||
495 | } else { |
||
496 | print "<br>\n"; |
||
497 | } |
||
498 | |||
499 | //print $langs->trans("InstallEasy")." "; |
||
500 | print '<h3><span class="soustitre">' . $langs->trans("ChooseYourSetupMode") . '</span></h3>'; |
||
501 | |||
502 | $foundrecommandedchoice = 0; |
||
503 | |||
504 | $available_choices = []; |
||
505 | $notavailable_choices = []; |
||
506 | |||
507 | if (empty($dolibarr_main_db_host)) { // This means install process was not run |
||
508 | $foundrecommandedchoice = 1; // To show only once |
||
509 | } |
||
510 | |||
511 | // Show line of first install choice |
||
512 | $choice = '<tr class="trlineforchoice' . ($foundrecommandedchoice ? ' choiceselected' : '') . '">' . "\n"; |
||
513 | $choice .= '<td class="nowrap center"><b>' . $langs->trans("FreshInstall") . '</b>'; |
||
514 | $choice .= '</td>'; |
||
515 | $choice .= '<td class="listofchoicesdesc">'; |
||
516 | $choice .= $langs->trans("FreshInstallDesc"); |
||
517 | if (empty($dolibarr_main_db_host)) { // This means install process was not run |
||
518 | $choice .= '<br>'; |
||
519 | //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); |
||
520 | $choice .= '<div class="center"><div class="ok suggestedchoice">' . $langs->trans("InstallChoiceSuggested") . '</div></div>'; |
||
521 | // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '; |
||
522 | } |
||
523 | |||
524 | $choice .= '</td>'; |
||
525 | $choice .= '<td class="center">'; |
||
526 | if ($allowinstall) { |
||
527 | $choice .= '<a class="button" href="fileconf.php?selectlang=' . $setuplang . '">' . $langs->trans("Start") . '</a>'; |
||
528 | } else { |
||
529 | $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '') . $langs->trans("InstallNotAllowed") . ($foundrecommandedchoice ? '</span>' : ''); |
||
530 | } |
||
531 | $choice .= '</td>' . "\n"; |
||
532 | $choice .= '</tr>' . "\n"; |
||
533 | |||
534 | $positionkey = ($foundrecommandedchoice ? 999 : 0); |
||
535 | if ($allowinstall) { |
||
536 | $available_choices[$positionkey] = $choice; |
||
537 | } else { |
||
538 | $notavailable_choices[$positionkey] = $choice; |
||
539 | } |
||
540 | |||
541 | // Show upgrade lines |
||
542 | $allowupgrade = true; |
||
543 | if (empty($dolibarr_main_db_host)) { // This means install process was not run |
||
544 | $allowupgrade = false; |
||
545 | } |
||
546 | if (getDolGlobalInt("MAIN_NOT_INSTALLED")) { |
||
547 | $allowupgrade = false; |
||
548 | } |
||
549 | if (GETPOST('allowupgrade')) { |
||
550 | $allowupgrade = true; |
||
551 | } |
||
552 | |||
553 | $dir = DOL_DOCUMENT_ROOT . "/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver |
||
554 | dolibarr_install_syslog("Scan sql files for migration files in " . $dir); |
||
555 | |||
556 | // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration |
||
557 | $migrationscript = []; |
||
558 | $handle = opendir($dir); |
||
559 | if (is_resource($handle)) { |
||
560 | $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION); |
||
561 | while (($file = readdir($handle)) !== false) { |
||
562 | $reg = []; |
||
563 | if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) { |
||
564 | //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2])); |
||
565 | if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) { |
||
566 | $migrationscript[] = ['from' => $reg[1], 'to' => $reg[2]]; |
||
567 | } |
||
568 | } |
||
569 | } |
||
570 | $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1); |
||
571 | } else { |
||
572 | print '<div class="error">' . $langs->trans("ErrorCanNotReadDir", $dir) . '</div>'; |
||
573 | } |
||
574 | |||
575 | $count = 0; |
||
576 | foreach ($migrationscript as $migarray) { |
||
577 | $choice = ''; |
||
578 | |||
579 | $count++; |
||
580 | $recommended_choice = false; |
||
581 | $version = DOL_VERSION; |
||
582 | $versionfrom = $migarray['from']; |
||
583 | $versionto = $migarray['to']; |
||
584 | $versionarray = preg_split('/[\.-]/', $version); |
||
585 | $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom); |
||
586 | $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto); |
||
587 | // Define string newversionxxx that are used for text to show |
||
588 | $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom); |
||
589 | $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto); |
||
590 | $newversionfrombis = ''; |
||
591 | if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1 |
||
592 | $newversionfrombis = ' ' . $langs->trans("or") . ' ' . $versionto; |
||
593 | } |
||
594 | |||
595 | if ($ok) { |
||
596 | if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known |
||
597 | // Now we check if this is the first qualified choice |
||
598 | if ( |
||
599 | $allowupgrade && empty($foundrecommandedchoice) && |
||
600 | (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2) |
||
601 | ) { |
||
602 | $foundrecommandedchoice = 1; // To show only once |
||
603 | $recommended_choice = true; |
||
604 | } |
||
605 | } else { |
||
606 | // We cannot recommend a choice. |
||
607 | // A version of install may be known, but we need last upgrade. |
||
608 | } |
||
609 | } |
||
610 | |||
611 | $choice .= "\n" . '<!-- choice ' . $count . ' -->' . "\n"; |
||
612 | $choice .= '<tr' . ($recommended_choice ? ' class="choiceselected"' : '') . '>'; |
||
613 | $choice .= '<td class="nowrap center"><b>' . $langs->trans("Upgrade") . '<br>' . $newversionfrom . $newversionfrombis . ' -> ' . $newversionto . '</b></td>'; |
||
614 | $choice .= '<td class="listofchoicesdesc">'; |
||
615 | $choice .= $langs->trans("UpgradeDesc"); |
||
616 | |||
617 | if ($recommended_choice) { |
||
618 | $choice .= '<br>'; |
||
619 | //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); |
||
620 | $choice .= '<div class="center">'; |
||
621 | $choice .= '<div class="ok suggestedchoice">' . $langs->trans("InstallChoiceSuggested") . '</div>'; |
||
622 | if ($count < count($migarray)) { // There are other choices after |
||
623 | print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION); |
||
624 | } |
||
625 | $choice .= '</div>'; |
||
626 | } |
||
627 | |||
628 | $choice .= '</td>'; |
||
629 | $choice .= '<td class="center">'; |
||
630 | if ($allowupgrade) { |
||
631 | $disabled = false; |
||
632 | if ($foundrecommandedchoice == 2) { |
||
633 | $disabled = true; |
||
634 | } |
||
635 | if ($foundrecommandedchoice == 1) { |
||
636 | $foundrecommandedchoice = 2; |
||
637 | } |
||
638 | if ($disabled) { |
||
639 | $choice .= '<span class="opacitymedium">' . $langs->trans("NotYetAvailable") . '</span>'; |
||
640 | } else { |
||
641 | $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade' . ($count < count($migrationscript) ? '_' . $versionto : '') . '&selectlang=' . $setuplang . '&versionfrom=' . $versionfrom . '&versionto=' . $versionto . '">' . $langs->trans("Start") . '</a>'; |
||
642 | } |
||
643 | } else { |
||
644 | $choice .= $langs->trans("NotAvailable"); |
||
645 | } |
||
646 | $choice .= '</td>'; |
||
647 | $choice .= '</tr>' . "\n"; |
||
648 | |||
649 | if ($allowupgrade) { |
||
650 | $available_choices[$count] = $choice; |
||
651 | } else { |
||
652 | $notavailable_choices[$count] = $choice; |
||
653 | } |
||
654 | } |
||
655 | |||
656 | // If there is no choice at all, we show all of them. |
||
657 | if (empty($available_choices)) { |
||
658 | $available_choices = $notavailable_choices; |
||
659 | $notavailable_choices = []; |
||
660 | } |
||
661 | |||
662 | // Array of install choices |
||
663 | krsort($available_choices, SORT_NATURAL); |
||
664 | print"\n"; |
||
665 | print '<table width="100%" class="listofchoices">'; |
||
666 | foreach ($available_choices as $choice) { |
||
667 | print $choice; |
||
668 | } |
||
669 | |||
670 | print '</table>' . "\n"; |
||
671 | |||
672 | if (count($notavailable_choices)) { |
||
673 | print '<br><div id="AShowChoices" style="opacity: 0.5">'; |
||
674 | print '> ' . $langs->trans('ShowNotAvailableOptions') . '...'; |
||
675 | print '</div>'; |
||
676 | |||
677 | print '<div id="navail_choices" style="display:none">'; |
||
678 | print "<br>\n"; |
||
679 | print '<table width="100%" class="listofchoices">'; |
||
680 | foreach ($notavailable_choices as $choice) { |
||
681 | print $choice; |
||
682 | } |
||
683 | |||
684 | print '</table>' . "\n"; |
||
685 | print '</div>'; |
||
686 | } |
||
687 | } |
||
688 | } |
||
689 | |||
690 | print '<script type="text/javascript"> |
||
691 | |||
692 | $("div#AShowChoices").click(function() { |
||
693 | |||
694 | $("div#navail_choices").toggle(); |
||
695 | |||
696 | if ($("div#navail_choices").css("display") == "none") { |
||
697 | $(this).text("> ' . $langs->trans('ShowNotAvailableOptions') . '..."); |
||
698 | } else { |
||
699 | $(this).text("' . $langs->trans('HideNotAvailableOptions') . '..."); |
||
700 | } |
||
701 | |||
702 | }); |
||
703 | |||
704 | /* |
||
705 | $(".runupgrade").click(function() { |
||
706 | return confirm("' . dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1) . '"); |
||
707 | }); |
||
708 | */ |
||
709 | |||
710 | </script>'; |
||
711 | |||
712 | dolibarr_install_syslog("- check: end"); |
||
713 | pFooter(1); // Never display next button |
||
714 | } |
||
715 | |||
716 | public function fileconf() |
||
717 | { |
||
718 | global $langs; |
||
719 | global $conf; |
||
720 | |||
721 | $conffile = Config::getDolibarrConfigFilename(); |
||
722 | $conffiletoshow = $conffile; |
||
723 | |||
724 | if (!isset($conf)) { |
||
725 | $conf = Config::loadConf(); |
||
726 | } |
||
727 | |||
728 | if (!isset($langs)) { |
||
729 | $langs = Globals::getLangs($conf); |
||
730 | $langs->setDefaultLang('auto'); |
||
731 | } |
||
732 | |||
733 | $err = 0; |
||
734 | |||
735 | $setuplang = GETPOST("selectlang", 'alpha', 3) ? GETPOST("selectlang", 'alpha', 3) : (GETPOST('lang', 'alpha', 1) ? GETPOST('lang', 'alpha', 1) : 'auto'); |
||
736 | $langs->setDefaultLang($setuplang); |
||
737 | |||
738 | $langs->loadLangs(["install", "errors"]); |
||
739 | |||
740 | dolibarr_install_syslog("- fileconf: entering fileconf.php page"); |
||
741 | |||
742 | // You can force preselected values of the config step of Dolibarr by adding a file |
||
743 | // install.forced.php into directory htdocs/install (This is the case with some wizard |
||
744 | // installer like DoliWamp, DoliMamp or DoliBuntu). |
||
745 | // We first init "forced values" to nothing. |
||
746 | if (!isset($force_install_noedit)) { |
||
747 | $force_install_noedit = ''; // 1=To block vars specific to distrib, 2 to block all technical parameters |
||
748 | } |
||
749 | if (!isset($force_install_type)) { |
||
750 | $force_install_type = ''; |
||
751 | } |
||
752 | if (!isset($force_install_dbserver)) { |
||
753 | $force_install_dbserver = ''; |
||
754 | } |
||
755 | if (!isset($force_install_port)) { |
||
756 | $force_install_port = ''; |
||
757 | } |
||
758 | if (!isset($force_install_database)) { |
||
759 | $force_install_database = ''; |
||
760 | } |
||
761 | if (!isset($force_install_prefix)) { |
||
762 | $force_install_prefix = ''; |
||
763 | } |
||
764 | if (!isset($force_install_createdatabase)) { |
||
765 | $force_install_createdatabase = ''; |
||
766 | } |
||
767 | if (!isset($force_install_databaselogin)) { |
||
768 | $force_install_databaselogin = ''; |
||
769 | } |
||
770 | if (!isset($force_install_databasepass)) { |
||
771 | $force_install_databasepass = ''; |
||
772 | } |
||
773 | if (!isset($force_install_databaserootlogin)) { |
||
774 | $force_install_databaserootlogin = ''; |
||
775 | } |
||
776 | if (!isset($force_install_databaserootpass)) { |
||
777 | $force_install_databaserootpass = ''; |
||
778 | } |
||
779 | // Now we load forced values from install.forced.php file. |
||
780 | $useforcedwizard = false; |
||
781 | $forcedfile = "./install.forced.php"; |
||
782 | if ($conffile == "/etc/dolibarr/conf.php") { |
||
783 | $forcedfile = "/etc/dolibarr/install.forced.php"; // Must be after inc.php |
||
784 | } |
||
785 | if (@file_exists($forcedfile)) { |
||
786 | $useforcedwizard = true; |
||
787 | include_once $forcedfile; |
||
788 | } |
||
789 | |||
790 | |||
791 | /* |
||
792 | * View |
||
793 | */ |
||
794 | |||
795 | session_start(); // To be able to keep info into session (used for not losing pass during navigation. pass must not transit through parameters) |
||
796 | |||
797 | pHeader($langs->trans("ConfigurationFile"), "step1", "set", "", (empty($force_dolibarr_js_JQUERY) ? '' : $force_dolibarr_js_JQUERY . '/'), 'main-inside-bis'); |
||
798 | |||
799 | // Test if we can run a first install process |
||
800 | if (!is_writable($conffile)) { |
||
801 | print $langs->trans("ConfFileIsNotWritable", $conffiletoshow); |
||
802 | dolibarr_install_syslog("fileconf: config file is not writable", LOG_WARNING); |
||
803 | dolibarr_install_syslog("- fileconf: end"); |
||
804 | pFooter(1, $setuplang, 'jscheckparam'); |
||
805 | exit; |
||
806 | } |
||
807 | |||
808 | if (!empty($force_install_message)) { |
||
809 | print '<div><br>' . $langs->trans($force_install_message) . '</div>'; |
||
810 | |||
811 | /*print '<script type="text/javascript">'; |
||
812 | print ' jQuery(document).ready(function() { |
||
813 | jQuery("#linktoshowtechnicalparam").click(function() { |
||
814 | jQuery(".hidewhenedit").hide(); |
||
815 | jQuery(".hidewhennoedit").show(); |
||
816 | });'; |
||
817 | if ($force_install_noedit) print 'jQuery(".hidewhennoedit").hide();'; |
||
818 | print '});'; |
||
819 | print '</script>'; |
||
820 | |||
821 | print '<br><a href="#" id="linktoshowtechnicalparam" class="hidewhenedit">'.$langs->trans("ShowEditTechnicalParameters").'</a><br>'; |
||
822 | */ |
||
823 | } |
||
824 | |||
825 | ?> |
||
826 | <div> |
||
827 | |||
828 | |||
829 | <table class="nobordernopadding<?php if ($force_install_noedit) { |
||
830 | print ' hidewhennoedit'; |
||
831 | } ?>"> |
||
832 | |||
833 | <tr> |
||
834 | <td colspan="3" class="label"> |
||
835 | <h3> |
||
836 | <img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/globe.svg" width="20" alt="webserver"> <?php echo $langs->trans("WebServer"); ?> |
||
837 | </h3> |
||
838 | </td> |
||
839 | </tr> |
||
840 | |||
841 | <!-- Documents root $dolibarr_main_document_root --> |
||
842 | <tr> |
||
843 | <td class="label"> |
||
844 | <label for="main_dir"><b><?php print $langs->trans("WebPagesDirectory"); ?></b></label></td> |
||
845 | <?php |
||
846 | if (empty($dolibarr_main_document_root)) { |
||
847 | $dolibarr_main_document_root = GETPOSTISSET('main_dir') ? GETPOST('main_dir') : DOL_DOCUMENT_ROOT; |
||
848 | } |
||
849 | ?> |
||
850 | <td class="label"> |
||
851 | <input type="text" |
||
852 | class="minwidth300" |
||
853 | id="main_dir" |
||
854 | name="main_dir" |
||
855 | value="<?php print $dolibarr_main_document_root ?>" |
||
856 | <?php |
||
857 | if (!empty($force_install_noedit)) { |
||
858 | print ' disabled'; |
||
859 | } |
||
860 | ?> |
||
861 | > |
||
862 | </td> |
||
863 | <td class="comment"><?php |
||
864 | print '<span class="opacitymedium">' . $langs->trans("WithNoSlashAtTheEnd") . "</span><br>"; |
||
865 | print $langs->trans("Examples") . ":<br>"; |
||
866 | ?> |
||
867 | <ul> |
||
868 | <li>/var/www/dolibarr/htdocs</li> |
||
869 | <li>C:/wwwroot/dolibarr/htdocs</li> |
||
870 | </ul> |
||
871 | </td> |
||
872 | </tr> |
||
873 | |||
874 | <!-- Documents URL $dolibarr_main_data_root --> |
||
875 | <tr> |
||
876 | <td class="label"> |
||
877 | <label for="main_data_dir"><b><?php print $langs->trans("DocumentsDirectory"); ?></b></label> |
||
878 | </td> |
||
879 | <?php |
||
880 | if (!empty($force_install_main_data_root)) { |
||
881 | $dolibarr_main_data_root = @$force_install_main_data_root; |
||
882 | } |
||
883 | if (empty($dolibarr_main_data_root)) { |
||
884 | $dolibarr_main_data_root = GETPOSTISSET('main_data_dir') ? GETPOST('main_data_dir') : detect_dolibarr_main_data_root($dolibarr_main_document_root); |
||
885 | } |
||
886 | ?> |
||
887 | <td class="label"> |
||
888 | <input type="text" |
||
889 | class="minwidth300" |
||
890 | id="main_data_dir" |
||
891 | name="main_data_dir" |
||
892 | value="<?php print $dolibarr_main_data_root ?>" |
||
893 | <?php if (!empty($force_install_noedit)) { |
||
894 | print ' disabled'; |
||
895 | } ?> |
||
896 | > |
||
897 | </td> |
||
898 | <td class="comment"><?php |
||
899 | print '<span class="opacitymedium">' . $langs->trans("WithNoSlashAtTheEnd") . "</span><br>"; |
||
900 | print $langs->trans("DirectoryRecommendation") . "<br>"; |
||
901 | print $langs->trans("Examples") . ":<br>"; |
||
902 | ?> |
||
903 | <ul> |
||
904 | <li>/var/lib/dolibarr/documents</li> |
||
905 | <li>C:/My Documents/dolibarr/documents</li> |
||
906 | </ul> |
||
907 | </td> |
||
908 | </tr> |
||
909 | |||
910 | <!-- Root URL $dolibarr_main_url_root --> |
||
911 | <?php |
||
912 | if (empty($dolibarr_main_url_root)) { |
||
913 | $dolibarr_main_url_root = GETPOSTISSET('main_url') ? GETPOST('main_url') : DOL_URL_ROOT; |
||
914 | } |
||
915 | ?> |
||
916 | <tr> |
||
917 | <td class="label"><label for="main_url"><b><?php echo $langs->trans("URLRoot"); ?></b></label> |
||
918 | </td> |
||
919 | <td class="label"> |
||
920 | <input type="text" |
||
921 | class="minwidth300" |
||
922 | id="main_url" |
||
923 | name="main_url" |
||
924 | value="<?php print $dolibarr_main_url_root; ?> " |
||
925 | <?php if (!empty($force_install_noedit)) { |
||
926 | print ' disabled'; |
||
927 | } |
||
928 | ?> |
||
929 | > |
||
930 | </td> |
||
931 | <td class="comment"><?php print $langs->trans("Examples") . ":<br>"; ?> |
||
932 | <ul> |
||
933 | <li>http://localhost/</li> |
||
934 | <li>http://www.myserver.com:8180/dolibarr</li> |
||
935 | <li>https://www.myvirtualfordolibarr.com/</li> |
||
936 | </ul> |
||
937 | </td> |
||
938 | </tr> |
||
939 | |||
940 | <?php |
||
941 | if (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') { // Enabled if the installation process is "https://" |
||
942 | ?> |
||
943 | <tr> |
||
944 | <td class="label"> |
||
945 | <label for="main_force_https"><?php echo $langs->trans("ForceHttps"); ?></label></td> |
||
946 | <td class="label"> |
||
947 | <input type="checkbox" |
||
948 | id="main_force_https" |
||
949 | name="main_force_https" |
||
950 | <?php if (!empty($force_install_mainforcehttps)) { |
||
951 | print ' checked'; |
||
952 | } ?> |
||
953 | <?php if ($force_install_noedit == 2 && $force_install_mainforcehttps !== null) { |
||
954 | print ' disabled'; |
||
955 | } ?> |
||
956 | > |
||
957 | </td> |
||
958 | <td class="comment"><?php echo $langs->trans("CheckToForceHttps"); ?> |
||
959 | </td> |
||
960 | |||
961 | </tr> |
||
962 | <?php |
||
963 | } |
||
964 | ?> |
||
965 | |||
966 | <!-- Dolibarr database --> |
||
967 | |||
968 | <tr> |
||
969 | <td colspan="3" class="label"><br> |
||
970 | <h3> |
||
971 | <img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="webserver"> <?php echo $langs->trans("DolibarrDatabase"); ?> |
||
972 | </h3> |
||
973 | </td> |
||
974 | </tr> |
||
975 | |||
976 | <tr> |
||
977 | <td class="label"><label for="db_name"><b><?php echo $langs->trans("DatabaseName"); ?></b></label> |
||
978 | </td> |
||
979 | <td class="label"> |
||
980 | <input type="text" |
||
981 | id="db_name" |
||
982 | name="db_name" |
||
983 | value="<?php echo (!empty($dolibarr_main_db_name)) ? $dolibarr_main_db_name : ($force_install_database ? $force_install_database : self::DEFAULT_DATABASE_NAME); ?>" |
||
984 | <?php if ($force_install_noedit == 2 && $force_install_database !== null) { |
||
985 | print ' disabled'; |
||
986 | } ?> |
||
987 | > |
||
988 | </td> |
||
989 | <td class="comment"><?php echo $langs->trans("DatabaseName"); ?></td> |
||
990 | </tr> |
||
991 | |||
992 | |||
993 | <?php |
||
994 | if (!isset($dolibarr_main_db_host)) { |
||
995 | $dolibarr_main_db_host = "localhost"; |
||
996 | } |
||
997 | ?> |
||
998 | <tr> |
||
999 | <!-- Driver type --> |
||
1000 | <td class="label"><label for="db_type"><b><?php echo $langs->trans("DriverType"); ?></b></label> |
||
1001 | </td> |
||
1002 | |||
1003 | <td class="label"> |
||
1004 | <?php |
||
1005 | |||
1006 | $defaultype = !empty($dolibarr_main_db_type) ? $dolibarr_main_db_type : (empty($force_install_type) ? 'mysqli' : $force_install_type); |
||
1007 | |||
1008 | $modules = []; |
||
1009 | $nbok = $nbko = 0; |
||
1010 | $option = ''; |
||
1011 | |||
1012 | // Scan les drivers |
||
1013 | $dir = DOL_DOCUMENT_ROOT . '/core/db'; |
||
1014 | $handle = opendir($dir); |
||
1015 | if (is_resource($handle)) { |
||
1016 | while (($file = readdir($handle)) !== false) { |
||
1017 | if (is_readable($dir . "/" . $file) && preg_match('/^(.*)\.class\.php$/i', $file, $reg)) { |
||
1018 | $type = $reg[1]; |
||
1019 | if ($type === 'DoliDB') { |
||
1020 | continue; // Skip abstract class |
||
1021 | } |
||
1022 | $class = 'DoliDB' . ucfirst($type); |
||
1023 | include_once $dir . "/" . $file; |
||
1024 | |||
1025 | if ($type == 'sqlite') { |
||
1026 | continue; // We hide sqlite because support can't be complete until sqlite does not manage foreign key creation after table creation (ALTER TABLE child ADD CONSTRAINT not supported) |
||
1027 | } |
||
1028 | if ($type == 'sqlite3') { |
||
1029 | continue; // We hide sqlite3 because support can't be complete until sqlite does not manage foreign key creation after table creation (ALTER TABLE child ADD CONSTRAINT not supported) |
||
1030 | } |
||
1031 | |||
1032 | // Version min of database |
||
1033 | $note = '(' . $class::LABEL . ' >= ' . $class::VERSIONMIN . ')'; |
||
1034 | |||
1035 | // Switch to mysql if mysqli is not present |
||
1036 | if ($defaultype == 'mysqli' && !function_exists('mysqli_connect')) { |
||
1037 | $defaultype = 'mysql'; |
||
1038 | } |
||
1039 | |||
1040 | // Show line into list |
||
1041 | if ($type == 'mysql') { |
||
1042 | $testfunction = 'mysql_connect'; |
||
1043 | $testclass = ''; |
||
1044 | } |
||
1045 | if ($type == 'mysqli') { |
||
1046 | $testfunction = 'mysqli_connect'; |
||
1047 | $testclass = ''; |
||
1048 | } |
||
1049 | if ($type == 'pgsql') { |
||
1050 | $testfunction = 'pg_connect'; |
||
1051 | $testclass = ''; |
||
1052 | } |
||
1053 | if ($type == 'mssql') { |
||
1054 | $testfunction = 'mssql_connect'; |
||
1055 | $testclass = ''; |
||
1056 | } |
||
1057 | if ($type == 'sqlite') { |
||
1058 | $testfunction = ''; |
||
1059 | $testclass = 'PDO'; |
||
1060 | } |
||
1061 | if ($type == 'sqlite3') { |
||
1062 | $testfunction = ''; |
||
1063 | $testclass = 'SQLite3'; |
||
1064 | } |
||
1065 | $option .= '<option value="' . $type . '"' . ($defaultype == $type ? ' selected' : ''); |
||
1066 | if ($testfunction && !function_exists($testfunction)) { |
||
1067 | $option .= ' disabled'; |
||
1068 | } |
||
1069 | if ($testclass && !class_exists($testclass)) { |
||
1070 | $option .= ' disabled'; |
||
1071 | } |
||
1072 | $option .= '>'; |
||
1073 | $option .= $type . ' '; |
||
1074 | if ($note) { |
||
1075 | $option .= ' ' . $note; |
||
1076 | } |
||
1077 | // Deprecated and experimental |
||
1078 | if ($type == 'mysql') { |
||
1079 | $option .= ' ' . $langs->trans("Deprecated"); |
||
1080 | } elseif ($type == 'mssql') { |
||
1081 | $option .= ' ' . $langs->trans("VersionExperimental"); |
||
1082 | } elseif ($type == 'sqlite') { |
||
1083 | $option .= ' ' . $langs->trans("VersionExperimental"); |
||
1084 | } elseif ($type == 'sqlite3') { |
||
1085 | $option .= ' ' . $langs->trans("VersionExperimental"); |
||
1086 | } elseif (!function_exists($testfunction)) { |
||
1087 | // No available |
||
1088 | $option .= ' - ' . $langs->trans("FunctionNotAvailableInThisPHP"); |
||
1089 | } |
||
1090 | $option .= '</option>'; |
||
1091 | } |
||
1092 | } |
||
1093 | } |
||
1094 | ?> |
||
1095 | <select id="db_type" |
||
1096 | name="db_type" |
||
1097 | <?php if ($force_install_noedit == 2 && $force_install_type !== null) { |
||
1098 | print ' disabled'; |
||
1099 | } ?> |
||
1100 | > |
||
1101 | <?php print $option; ?> |
||
1102 | </select> |
||
1103 | |||
1104 | </td> |
||
1105 | <td class="comment"><?php echo $langs->trans("DatabaseType"); ?></td> |
||
1106 | |||
1107 | </tr> |
||
1108 | |||
1109 | <tr class="hidesqlite"> |
||
1110 | <td class="label"><label for="db_host"><b><?php echo $langs->trans("DatabaseServer"); ?></b></label> |
||
1111 | </td> |
||
1112 | <td class="label"> |
||
1113 | <input type="text" |
||
1114 | id="db_host" |
||
1115 | name="db_host" |
||
1116 | value="<?php print(!empty($force_install_dbserver) ? $force_install_dbserver : (!empty($dolibarr_main_db_host) ? $dolibarr_main_db_host : 'localhost')); ?>" |
||
1117 | <?php if ($force_install_noedit == 2 && $force_install_dbserver !== null) { |
||
1118 | print ' disabled'; |
||
1119 | } ?> |
||
1120 | > |
||
1121 | </td> |
||
1122 | <td class="comment"><?php echo $langs->trans("ServerAddressDescription"); ?> |
||
1123 | </td> |
||
1124 | |||
1125 | </tr> |
||
1126 | |||
1127 | <tr class="hidesqlite"> |
||
1128 | <td class="label"><label for="db_port"><?php echo $langs->trans("Port"); ?></label></td> |
||
1129 | <td class="label"> |
||
1130 | <input type="text" |
||
1131 | name="db_port" |
||
1132 | id="db_port" |
||
1133 | value="<?php print (!empty($force_install_port)) ? $force_install_port : ($dolibarr_main_db_port ?? ''); ?>" |
||
1134 | <?php if ($force_install_noedit == 2 && $force_install_port !== null) { |
||
1135 | print ' disabled'; |
||
1136 | } ?> |
||
1137 | > |
||
1138 | </td> |
||
1139 | <td class="comment"><?php echo $langs->trans("ServerPortDescription"); ?> |
||
1140 | </td> |
||
1141 | |||
1142 | </tr> |
||
1143 | |||
1144 | <tr class="hidesqlite"> |
||
1145 | <td class="label"><label for="db_prefix"><?php echo $langs->trans("DatabasePrefix"); ?></label></td> |
||
1146 | <td class="label"> |
||
1147 | <input type="text" |
||
1148 | id="db_prefix" |
||
1149 | name="db_prefix" |
||
1150 | value="<?php echo(!empty($force_install_prefix) ? $force_install_prefix : (!empty($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : self::DEFAULT_DATABASE_PREFIX)); ?>" |
||
1151 | <?php if ($force_install_noedit == 2 && $force_install_prefix !== null) { |
||
1152 | print ' disabled'; |
||
1153 | } ?> |
||
1154 | > |
||
1155 | </td> |
||
1156 | <td class="comment"><?php echo $langs->trans("DatabasePrefixDescription"); ?></td> |
||
1157 | </tr> |
||
1158 | |||
1159 | <tr class="hidesqlite"> |
||
1160 | <td class="label"> |
||
1161 | <label for="db_create_database"><?php echo $langs->trans("CreateDatabase"); ?></label></td> |
||
1162 | <td class="label"> |
||
1163 | <input type="checkbox" |
||
1164 | id="db_create_database" |
||
1165 | name="db_create_database" |
||
1166 | value="on" |
||
1167 | <?php |
||
1168 | $checked = 0; |
||
1169 | if ($force_install_createdatabase) { |
||
1170 | $checked = 1; |
||
1171 | print ' checked'; |
||
1172 | } ?> |
||
1173 | <?php if ($force_install_noedit == 2 && $force_install_createdatabase !== null) { |
||
1174 | print ' disabled'; |
||
1175 | } ?> |
||
1176 | > |
||
1177 | </td> |
||
1178 | <td class="comment"> |
||
1179 | <?php echo $langs->trans("CheckToCreateDatabase"); ?> |
||
1180 | </td> |
||
1181 | </tr> |
||
1182 | |||
1183 | <tr class="hidesqlite"> |
||
1184 | <td class="label"><label for="db_user"><b><?php echo $langs->trans("Login"); ?></b></label></td> |
||
1185 | <td class="label"> |
||
1186 | <input type="text" |
||
1187 | id="db_user" |
||
1188 | name="db_user" |
||
1189 | value="<?php print (!empty($force_install_databaselogin)) ? $force_install_databaselogin : ($dolibarr_main_db_user ?? ''); ?>" |
||
1190 | <?php if ($force_install_noedit == 2 && $force_install_databaselogin !== null) { |
||
1191 | print ' disabled'; |
||
1192 | } ?> |
||
1193 | > |
||
1194 | </td> |
||
1195 | <td class="comment"><?php echo $langs->trans("AdminLogin"); ?></td> |
||
1196 | </tr> |
||
1197 | |||
1198 | <tr class="hidesqlite"> |
||
1199 | <td class="label"><label for="db_pass"><b><?php echo $langs->trans("Password"); ?></b></label></td> |
||
1200 | <td class="label"> |
||
1201 | <input type="password" class="text-security" |
||
1202 | id="db_pass" autocomplete="off" |
||
1203 | name="db_pass" |
||
1204 | value="<?php |
||
1205 | // If $force_install_databasepass is on, we don't want to set password, we just show '***'. Real value will be extracted from the forced install file at step1. |
||
1206 | // @phan-suppress-next-line PhanParamSuspiciousOrder |
||
1207 | $autofill = ((!empty($_SESSION['dol_save_pass'])) ? $_SESSION['dol_save_pass'] : str_pad('', strlen($force_install_databasepass), '*')); |
||
1208 | if (!empty($dolibarr_main_prod) && empty($_SESSION['dol_save_pass'])) { // So value can't be found if install page still accessible |
||
1209 | $autofill = ''; |
||
1210 | } |
||
1211 | print dol_escape_htmltag($autofill); |
||
1212 | ?>" |
||
1213 | <?php if ($force_install_noedit == 2 && $force_install_databasepass !== null) { |
||
1214 | print ' disabled'; |
||
1215 | } ?> |
||
1216 | > |
||
1217 | </td> |
||
1218 | <td class="comment"><?php echo $langs->trans("AdminPassword"); ?></td> |
||
1219 | </tr> |
||
1220 | |||
1221 | <tr class="hidesqlite"> |
||
1222 | <td class="label"><label for="db_create_user"><?php echo $langs->trans("CreateUser"); ?></label> |
||
1223 | </td> |
||
1224 | <td class="label"> |
||
1225 | <input type="checkbox" |
||
1226 | id="db_create_user" |
||
1227 | name="db_create_user" |
||
1228 | value="on" |
||
1229 | <?php |
||
1230 | $checked = 0; |
||
1231 | if (!empty($force_install_createuser)) { |
||
1232 | $checked = 1; |
||
1233 | print ' checked'; |
||
1234 | } ?> |
||
1235 | <?php if ($force_install_noedit == 2 && $force_install_createuser !== null) { |
||
1236 | print ' disabled'; |
||
1237 | } ?> |
||
1238 | > |
||
1239 | </td> |
||
1240 | <td class="comment"> |
||
1241 | <?php echo $langs->trans("CheckToCreateUser"); ?> |
||
1242 | </td> |
||
1243 | </tr> |
||
1244 | |||
1245 | |||
1246 | <!-- Super access --> |
||
1247 | <?php |
||
1248 | $force_install_databaserootlogin = parse_database_login($force_install_databaserootlogin); |
||
1249 | $force_install_databaserootpass = parse_database_pass($force_install_databaserootpass); |
||
1250 | ?> |
||
1251 | <tr class="hidesqlite hideroot"> |
||
1252 | <td colspan="3" class="label"><br> |
||
1253 | <h3> |
||
1254 | <img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/shield.svg" width="20" alt="webserver"> <?php echo $langs->trans("DatabaseSuperUserAccess"); ?> |
||
1255 | </h3> |
||
1256 | </td> |
||
1257 | </tr> |
||
1258 | |||
1259 | <tr class="hidesqlite hideroot"> |
||
1260 | <td class="label"><label for="db_user_root"><b><?php echo $langs->trans("Login"); ?></b></label> |
||
1261 | </td> |
||
1262 | <td class="label"> |
||
1263 | <input type="text" |
||
1264 | id="db_user_root" |
||
1265 | name="db_user_root" |
||
1266 | class="needroot" |
||
1267 | value="<?php print (!empty($force_install_databaserootlogin)) ? $force_install_databaserootlogin : (GETPOSTISSET('db_user_root') ? GETPOST('db_user_root') : (isset($db_user_root) ? $db_user_root : '')); ?>" |
||
1268 | <?php if ($force_install_noedit > 0 && !empty($force_install_databaserootlogin)) { |
||
1269 | print ' disabled'; |
||
1270 | } ?> |
||
1271 | > |
||
1272 | </td> |
||
1273 | <td class="comment"><?php echo $langs->trans("DatabaseRootLoginDescription"); ?> |
||
1274 | <!-- |
||
1275 | <?php echo '<br>' . $langs->trans("Examples") . ':<br>' ?> |
||
1276 | <ul> |
||
1277 | <li>root (Mysql)</li> |
||
1278 | <li>postgres (PostgreSql)</li> |
||
1279 | </ul> |
||
1280 | </td> |
||
1281 | --> |
||
1282 | |||
1283 | </tr> |
||
1284 | <tr class="hidesqlite hideroot"> |
||
1285 | <td class="label"><label for="db_pass_root"><b><?php echo $langs->trans("Password"); ?></b></label> |
||
1286 | </td> |
||
1287 | <td class="label"> |
||
1288 | <input type="password" |
||
1289 | autocomplete="off" |
||
1290 | id="db_pass_root" |
||
1291 | name="db_pass_root" |
||
1292 | class="needroot text-security" |
||
1293 | value="<?php |
||
1294 | // If $force_install_databaserootpass is on, we don't want to set password here, we just show '***'. Real value will be extracted from the forced install file at step1. |
||
1295 | // @phan-suppress-next-line PhanParamSuspiciousOrder |
||
1296 | $autofill = ((!empty($force_install_databaserootpass)) ? str_pad('', strlen($force_install_databaserootpass), '*') : (isset($db_pass_root) ? $db_pass_root : '')); |
||
1297 | if (!empty($dolibarr_main_prod)) { |
||
1298 | $autofill = ''; |
||
1299 | } |
||
1300 | // Do not autofill password if instance is a production instance |
||
1301 | if ( |
||
1302 | !empty($_SERVER["SERVER_NAME"]) && !in_array( |
||
1303 | $_SERVER["SERVER_NAME"], |
||
1304 | ['127.0.0.1', 'localhost', 'localhostgit'] |
||
1305 | ) |
||
1306 | ) { |
||
1307 | $autofill = ''; |
||
1308 | } // Do not autofill password for remote access |
||
1309 | print dol_escape_htmltag($autofill); |
||
1310 | ?>" |
||
1311 | <?php if ($force_install_noedit > 0 && !empty($force_install_databaserootpass)) { |
||
1312 | print ' disabled'; /* May be removed by javascript*/ |
||
1313 | } ?> |
||
1314 | > |
||
1315 | </td> |
||
1316 | <td class="comment"><?php echo $langs->trans("KeepEmptyIfNoPassword"); ?> |
||
1317 | </td> |
||
1318 | </tr> |
||
1319 | |||
1320 | </table> |
||
1321 | </div> |
||
1322 | |||
1323 | <script type="text/javascript"> |
||
1324 | function init_needroot() { |
||
1325 | console.log("init_needroot force_install_noedit=<?php echo $force_install_noedit?>"); |
||
1326 | console.log(jQuery("#db_create_database").is(":checked")); |
||
1327 | console.log(jQuery("#db_create_user").is(":checked")); |
||
1328 | |||
1329 | if (jQuery("#db_create_database").is(":checked") || jQuery("#db_create_user").is(":checked")) { |
||
1330 | console.log("init_needroot show root section"); |
||
1331 | jQuery(".hideroot").show(); |
||
1332 | <?php |
||
1333 | if (empty($force_install_noedit)) { ?> |
||
1334 | jQuery(".needroot").removeAttr('disabled'); |
||
1335 | <?php } ?> |
||
1336 | } else { |
||
1337 | console.log("init_needroot hide root section"); |
||
1338 | jQuery(".hideroot").hide(); |
||
1339 | jQuery(".needroot").prop('disabled', true); |
||
1340 | } |
||
1341 | } |
||
1342 | |||
1343 | function checkDatabaseName(databasename) { |
||
1344 | if (databasename.match(/[;\.]/)) { |
||
1345 | return false; |
||
1346 | } |
||
1347 | return true; |
||
1348 | } |
||
1349 | |||
1350 | function jscheckparam() { |
||
1351 | console.log("Click on jscheckparam"); |
||
1352 | |||
1353 | var ok = true; |
||
1354 | |||
1355 | if (document.forminstall.main_dir.value == '') { |
||
1356 | ok = false; |
||
1357 | alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("WebPagesDirectory"))); ?>'); |
||
1358 | } else if (document.forminstall.main_data_dir.value == '') { |
||
1359 | ok = false; |
||
1360 | alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("DocumentsDirectory"))); ?>'); |
||
1361 | } else if (document.forminstall.main_url.value == '') { |
||
1362 | ok = false; |
||
1363 | alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("URLRoot"))); ?>'); |
||
1364 | } else if (document.forminstall.db_host.value == '') { |
||
1365 | ok = false; |
||
1366 | alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server"))); ?>'); |
||
1367 | } else if (document.forminstall.db_name.value == '') { |
||
1368 | ok = false; |
||
1369 | alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatabaseName"))); ?>'); |
||
1370 | } else if (!checkDatabaseName(document.forminstall.db_name.value)) { |
||
1371 | ok = false; |
||
1372 | alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentitiesnoconv("DatabaseName"))); ?>'); |
||
1373 | } |
||
1374 | // If create database asked |
||
1375 | else if (document.forminstall.db_create_database.checked == true && (document.forminstall.db_user_root.value == '')) { |
||
1376 | ok = false; |
||
1377 | alert('<?php echo dol_escape_js($langs->transnoentities("YouAskToCreateDatabaseSoRootRequired")); ?>'); |
||
1378 | init_needroot(); |
||
1379 | } |
||
1380 | // If create user asked |
||
1381 | else if (document.forminstall.db_create_user.checked == true && (document.forminstall.db_user_root.value == '')) { |
||
1382 | ok = false; |
||
1383 | alert('<?php echo dol_escape_js($langs->transnoentities("YouAskToCreateDatabaseUserSoRootRequired")); ?>'); |
||
1384 | init_needroot(); |
||
1385 | } |
||
1386 | |||
1387 | return ok; |
||
1388 | } |
||
1389 | |||
1390 | |||
1391 | jQuery(document).ready(function () { // TODO Test $( window ).load(function() to see if the init_needroot work better after a back |
||
1392 | |||
1393 | var dbtype = jQuery("#db_type"); |
||
1394 | |||
1395 | dbtype.change(function () { |
||
1396 | if (dbtype.val() == 'sqlite' || dbtype.val() == 'sqlite3') { |
||
1397 | jQuery(".hidesqlite").hide(); |
||
1398 | } else { |
||
1399 | jQuery(".hidesqlite").show(); |
||
1400 | } |
||
1401 | |||
1402 | // Automatically set default database ports and admin user |
||
1403 | if (dbtype.val() == 'mysql' || dbtype.val() == 'mysqli') { |
||
1404 | jQuery("#db_port").val(3306); |
||
1405 | jQuery("#db_user_root").val('root'); |
||
1406 | } else if (dbtype.val() == 'pgsql') { |
||
1407 | jQuery("#db_port").val(5432); |
||
1408 | jQuery("#db_user_root").val('postgres'); |
||
1409 | } else if (dbtype.val() == 'mssql') { |
||
1410 | jQuery("#db_port").val(1433); |
||
1411 | jQuery("#db_user_root").val('sa'); |
||
1412 | } |
||
1413 | |||
1414 | }); |
||
1415 | |||
1416 | jQuery("#db_create_database").click(function () { |
||
1417 | console.log("click on db_create_database"); |
||
1418 | init_needroot(); |
||
1419 | }); |
||
1420 | jQuery("#db_create_user").click(function () { |
||
1421 | console.log("click on db_create_user"); |
||
1422 | init_needroot(); |
||
1423 | }); |
||
1424 | <?php if ($force_install_noedit == 2 && empty($force_install_databasepass)) { ?> |
||
1425 | jQuery("#db_pass").focus(); |
||
1426 | <?php } ?> |
||
1427 | |||
1428 | init_needroot(); |
||
1429 | }); |
||
1430 | </script> |
||
1431 | |||
1432 | |||
1433 | <?php |
||
1434 | |||
1435 | // $db->close(); Not database connection yet |
||
1436 | |||
1437 | dolibarr_install_syslog("- fileconf: end"); |
||
1438 | pFooter($err, $setuplang, 'jscheckparam'); |
||
1439 | } |
||
1440 | |||
1441 | public function step1() |
||
1442 | { |
||
1443 | global $langs; |
||
1444 | global $conf; |
||
1445 | global $conffiletoshowshort; |
||
1446 | |||
1447 | $conffile = Config::getDolibarrConfigFilename(); |
||
1448 | $conffiletoshow = $conffile; |
||
1449 | |||
1450 | if (!isset($conf)) { |
||
1451 | $conf = Config::loadConf(); |
||
1452 | } |
||
1453 | |||
1454 | if (!isset($langs)) { |
||
1455 | $langs = Globals::getLangs($conf); |
||
1456 | $langs->setDefaultLang('auto'); |
||
1457 | } |
||
1458 | |||
1459 | $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]); |
||
1460 | $setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[2]) ? 'auto' : $argv[2]); |
||
1461 | $langs->setDefaultLang($setuplang); |
||
1462 | |||
1463 | $langs->loadLangs(["admin", "install", "errors"]); |
||
1464 | |||
1465 | // Dolibarr pages directory |
||
1466 | $main_dir = GETPOST('main_dir') ? GETPOST('main_dir') : (empty($argv[3]) ? '' : $argv[3]); |
||
1467 | // Directory for generated documents (invoices, orders, ecm, etc...) |
||
1468 | $main_data_dir = GETPOST('main_data_dir') ? GETPOST('main_data_dir') : (empty($argv[4]) ? ($main_dir . '/documents') : $argv[4]); |
||
1469 | // Dolibarr root URL |
||
1470 | $main_url = GETPOST('main_url') ? GETPOST('main_url') : (empty($argv[5]) ? '' : $argv[5]); |
||
1471 | // Database login information |
||
1472 | $userroot = GETPOST('db_user_root', 'alpha') ? GETPOST('db_user_root', 'alpha') : (empty($argv[6]) ? '' : $argv[6]); |
||
1473 | $passroot = GETPOST('db_pass_root', 'none') ? GETPOST('db_pass_root', 'none') : (empty($argv[7]) ? '' : $argv[7]); |
||
1474 | // Database server |
||
1475 | $db_type = GETPOST('db_type', 'aZ09') ? GETPOST('db_type', 'aZ09') : (empty($argv[8]) ? '' : $argv[8]); |
||
1476 | $db_host = GETPOST('db_host', 'alpha') ? GETPOST('db_host', 'alpha') : (empty($argv[9]) ? '' : $argv[9]); |
||
1477 | $db_name = GETPOST('db_name', 'aZ09') ? GETPOST('db_name', 'aZ09') : (empty($argv[10]) ? '' : $argv[10]); |
||
1478 | $db_user = GETPOST('db_user', 'alpha') ? GETPOST('db_user', 'alpha') : (empty($argv[11]) ? '' : $argv[11]); |
||
1479 | $db_pass = GETPOST('db_pass', 'none') ? GETPOST('db_pass', 'none') : (empty($argv[12]) ? '' : $argv[12]); |
||
1480 | $db_port = GETPOSTINT('db_port') ? GETPOSTINT('db_port') : (empty($argv[13]) ? '' : $argv[13]); |
||
1481 | $db_prefix = GETPOST('db_prefix', 'aZ09') ? GETPOST('db_prefix', 'aZ09') : (empty($argv[14]) ? '' : $argv[14]); |
||
1482 | $db_create_database = GETPOST('db_create_database', 'alpha') ? GETPOST('db_create_database', 'alpha') : (empty($argv[15]) ? '' : $argv[15]); |
||
1483 | $db_create_user = GETPOST('db_create_user', 'alpha') ? GETPOST('db_create_user', 'alpha') : (empty($argv[16]) ? '' : $argv[16]); |
||
1484 | // Force https |
||
1485 | $main_force_https = ((GETPOST("main_force_https", 'alpha') && (GETPOST("main_force_https", 'alpha') == "on" || GETPOST("main_force_https", 'alpha') == 1)) ? '1' : '0'); |
||
1486 | // Use alternative directory |
||
1487 | $main_use_alt_dir = ((GETPOST("main_use_alt_dir", 'alpha') == '' || (GETPOST("main_use_alt_dir", 'alpha') == "on" || GETPOST("main_use_alt_dir", 'alpha') == 1)) ? '' : '//'); |
||
1488 | // Alternative root directory name |
||
1489 | $main_alt_dir_name = ((GETPOST("main_alt_dir_name", 'alpha') && GETPOST("main_alt_dir_name", 'alpha') != '') ? GETPOST("main_alt_dir_name", 'alpha') : 'custom'); |
||
1490 | |||
1491 | $dolibarr_main_distrib = 'standard'; |
||
1492 | |||
1493 | $dolibarr_main_document_root = BASE_PATH; |
||
1494 | |||
1495 | session_start(); // To be able to keep info into session (used for not losing password during navigation. The password must not transit through parameters) |
||
1496 | |||
1497 | // Save a flag to tell to restore input value if we go back |
||
1498 | $_SESSION['dol_save_pass'] = $db_pass; |
||
1499 | //$_SESSION['dol_save_passroot']=$passroot; |
||
1500 | |||
1501 | // Now we load forced values from install.forced.php file. |
||
1502 | $useforcedwizard = false; |
||
1503 | $forcedfile = "./install.forced.php"; |
||
1504 | if ($conffile == "/etc/dolibarr/conf.php") { |
||
1505 | $forcedfile = "/etc/dolibarr/install.forced.php"; |
||
1506 | } |
||
1507 | if (@file_exists($forcedfile)) { |
||
1508 | $useforcedwizard = true; |
||
1509 | include_once $forcedfile; |
||
1510 | // If forced install is enabled, replace the post values. These are empty because form fields are disabled. |
||
1511 | if ($force_install_noedit) { |
||
1512 | $main_dir = detect_dolibarr_main_document_root(); |
||
1513 | if (!empty($argv[3])) { |
||
1514 | $main_dir = $argv[3]; // override when executing the script in command line |
||
1515 | } |
||
1516 | if (!empty($force_install_main_data_root)) { |
||
1517 | $main_data_dir = $force_install_main_data_root; |
||
1518 | } else { |
||
1519 | $main_data_dir = detect_dolibarr_main_data_root($main_dir); |
||
1520 | } |
||
1521 | if (!empty($argv[4])) { |
||
1522 | $main_data_dir = $argv[4]; // override when executing the script in command line |
||
1523 | } |
||
1524 | $main_url = detect_dolibarr_main_url_root(); |
||
1525 | if (!empty($argv[5])) { |
||
1526 | $main_url = $argv[5]; // override when executing the script in command line |
||
1527 | } |
||
1528 | |||
1529 | if (!empty($force_install_databaserootlogin)) { |
||
1530 | $userroot = parse_database_login($force_install_databaserootlogin); |
||
1531 | } |
||
1532 | if (!empty($argv[6])) { |
||
1533 | $userroot = $argv[6]; // override when executing the script in command line |
||
1534 | } |
||
1535 | if (!empty($force_install_databaserootpass)) { |
||
1536 | $passroot = parse_database_pass($force_install_databaserootpass); |
||
1537 | } |
||
1538 | if (!empty($argv[7])) { |
||
1539 | $passroot = $argv[7]; // override when executing the script in command line |
||
1540 | } |
||
1541 | } |
||
1542 | if ($force_install_noedit == 2) { |
||
1543 | if (!empty($force_install_type)) { |
||
1544 | $db_type = $force_install_type; |
||
1545 | } |
||
1546 | if (!empty($force_install_dbserver)) { |
||
1547 | $db_host = $force_install_dbserver; |
||
1548 | } |
||
1549 | if (!empty($force_install_database)) { |
||
1550 | $db_name = $force_install_database; |
||
1551 | } |
||
1552 | if (!empty($force_install_databaselogin)) { |
||
1553 | $db_user = $force_install_databaselogin; |
||
1554 | } |
||
1555 | if (!empty($force_install_databasepass)) { |
||
1556 | $db_pass = $force_install_databasepass; |
||
1557 | } |
||
1558 | if (!empty($force_install_port)) { |
||
1559 | $db_port = $force_install_port; |
||
1560 | } |
||
1561 | if (!empty($force_install_prefix)) { |
||
1562 | $db_prefix = $force_install_prefix; |
||
1563 | } |
||
1564 | if (!empty($force_install_createdatabase)) { |
||
1565 | $db_create_database = $force_install_createdatabase; |
||
1566 | } |
||
1567 | if (!empty($force_install_createuser)) { |
||
1568 | $db_create_user = $force_install_createuser; |
||
1569 | } |
||
1570 | if (!empty($force_install_mainforcehttps)) { |
||
1571 | $main_force_https = $force_install_mainforcehttps; |
||
1572 | } |
||
1573 | } |
||
1574 | |||
1575 | if (!empty($force_install_distrib)) { |
||
1576 | $dolibarr_main_distrib = $force_install_distrib; |
||
1577 | } |
||
1578 | } |
||
1579 | |||
1580 | |||
1581 | $error = 0; |
||
1582 | |||
1583 | |||
1584 | /* |
||
1585 | * View |
||
1586 | */ |
||
1587 | |||
1588 | dolibarr_install_syslog("--- step1: entering step1.php page"); |
||
1589 | |||
1590 | pHeader($langs->trans("ConfigurationFile"), "step2"); |
||
1591 | |||
1592 | // Test if we can run a first install process |
||
1593 | if (!is_writable($conffile)) { |
||
1594 | print $langs->trans("ConfFileIsNotWritable", $conffiletoshow); |
||
1595 | pFooter(1, $setuplang, 'jscheckparam'); |
||
1596 | exit; |
||
1597 | } |
||
1598 | |||
1599 | |||
1600 | // Check parameters |
||
1601 | $is_sqlite = false; |
||
1602 | if (empty($db_type)) { |
||
1603 | print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseType")) . '</div>'; |
||
1604 | $error++; |
||
1605 | } else { |
||
1606 | $is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3'); |
||
1607 | } |
||
1608 | if (empty($db_host) && !$is_sqlite) { |
||
1609 | print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Server")) . '</div>'; |
||
1610 | $error++; |
||
1611 | } |
||
1612 | if (empty($db_name)) { |
||
1613 | print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseName")) . '</div>'; |
||
1614 | $error++; |
||
1615 | } |
||
1616 | if (empty($db_user) && !$is_sqlite) { |
||
1617 | print '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Login")) . '</div>'; |
||
1618 | $error++; |
||
1619 | } |
||
1620 | if (!empty($db_port) && !is_numeric($db_port)) { |
||
1621 | print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $db_port, $langs->transnoentities("Port")) . '</div>'; |
||
1622 | $error++; |
||
1623 | } |
||
1624 | if (!empty($db_prefix) && !preg_match('/^[a-z0-9]+_$/i', $db_prefix)) { |
||
1625 | print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $db_prefix, $langs->transnoentities("DatabasePrefix")) . '</div>'; |
||
1626 | $error++; |
||
1627 | } |
||
1628 | |||
1629 | $main_dir = dol_sanitizePathName($main_dir); |
||
1630 | $main_data_dir = dol_sanitizePathName($main_data_dir); |
||
1631 | |||
1632 | if (!filter_var($main_url, FILTER_VALIDATE_URL)) { |
||
1633 | print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $main_url, $langs->transnoentitiesnoconv("URLRoot")) . '</div>'; |
||
1634 | print '<br>'; |
||
1635 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1636 | $error++; |
||
1637 | } |
||
1638 | |||
1639 | // Remove last / into dans main_dir |
||
1640 | if (substr($main_dir, dol_strlen($main_dir) - 1) == "/") { |
||
1641 | $main_dir = substr($main_dir, 0, dol_strlen($main_dir) - 1); |
||
1642 | } |
||
1643 | |||
1644 | // Remove last / into dans main_url |
||
1645 | if (!empty($main_url) && substr($main_url, dol_strlen($main_url) - 1) == "/") { |
||
1646 | $main_url = substr($main_url, 0, dol_strlen($main_url) - 1); |
||
1647 | } |
||
1648 | |||
1649 | if (!dol_is_dir($main_dir . '/core/db/')) { |
||
1650 | print '<div class="error">' . $langs->trans("ErrorBadValueForParameter", $main_dir, $langs->transnoentitiesnoconv("WebPagesDirectory")) . '</div>'; |
||
1651 | print '<br>'; |
||
1652 | //print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>'; |
||
1653 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1654 | $error++; |
||
1655 | } |
||
1656 | |||
1657 | // Test database connection |
||
1658 | if (!$error) { |
||
1659 | $result = @include_once $main_dir . "/core/db/" . $db_type . '.class.php'; |
||
1660 | if ($result) { |
||
1661 | // If we require database or user creation we need to connect as root, so we need root login credentials |
||
1662 | if (!empty($db_create_database) && !$userroot) { |
||
1663 | print '<div class="error">' . $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $db_name) . '</div>'; |
||
1664 | print '<br>'; |
||
1665 | print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
1666 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1667 | $error++; |
||
1668 | } |
||
1669 | if (!empty($db_create_user) && !$userroot) { |
||
1670 | print '<div class="error">' . $langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect", $db_user) . '</div>'; |
||
1671 | print '<br>'; |
||
1672 | print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
1673 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1674 | $error++; |
||
1675 | } |
||
1676 | |||
1677 | // If we need root access |
||
1678 | if (!$error && (!empty($db_create_database) || !empty($db_create_user))) { |
||
1679 | $databasefortest = $db_name; |
||
1680 | if (!empty($db_create_database)) { |
||
1681 | if ($db_type == 'mysql' || $db_type == 'mysqli') { |
||
1682 | $databasefortest = 'mysql'; |
||
1683 | } elseif ($db_type == 'pgsql') { |
||
1684 | $databasefortest = 'postgres'; |
||
1685 | } else { |
||
1686 | $databasefortest = 'master'; |
||
1687 | } |
||
1688 | } |
||
1689 | |||
1690 | $db = getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, (int) $db_port); |
||
1691 | |||
1692 | dol_syslog("databasefortest=" . $databasefortest . " connected=" . $db->connected . " database_selected=" . $db->database_selected, LOG_DEBUG); |
||
1693 | //print "databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected; |
||
1694 | |||
1695 | if (empty($db_create_database) && $db->connected && !$db->database_selected) { |
||
1696 | print '<div class="error">' . $langs->trans("ErrorConnectedButDatabaseNotFound", $db_name) . '</div>'; |
||
1697 | print '<br>'; |
||
1698 | if (!$db->connected) { |
||
1699 | print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate") . '<br><br>'; |
||
1700 | } |
||
1701 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1702 | $error++; |
||
1703 | } elseif ($db->error && !(!empty($db_create_database) && $db->connected)) { |
||
1704 | // 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. |
||
1705 | if ($db->error == "No such file or directory") { |
||
1706 | print '<div class="error">' . $langs->trans("ErrorToConnectToMysqlCheckInstance") . '</div>'; |
||
1707 | } else { |
||
1708 | print '<div class="error">' . $db->error . '</div>'; |
||
1709 | } |
||
1710 | if (!$db->connected) { |
||
1711 | print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
1712 | } |
||
1713 | //print '<a href="#" onClick="javascript: history.back();">'; |
||
1714 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1715 | //print '</a>'; |
||
1716 | $error++; |
||
1717 | } |
||
1718 | } |
||
1719 | |||
1720 | // If we need simple access |
||
1721 | if (!$error && (empty($db_create_database) && empty($db_create_user))) { |
||
1722 | $db = getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, (int) $db_port); |
||
1723 | |||
1724 | if ($db->error) { |
||
1725 | print '<div class="error">' . $db->error . '</div>'; |
||
1726 | if (!$db->connected) { |
||
1727 | print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
1728 | } |
||
1729 | //print '<a href="#" onClick="javascript: history.back();">'; |
||
1730 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1731 | //print '</a>'; |
||
1732 | $error++; |
||
1733 | } |
||
1734 | } |
||
1735 | } else { |
||
1736 | print "<br>\nFailed to include_once(\"" . $main_dir . "/core/db/" . $db_type . ".class.php\")<br>\n"; |
||
1737 | print '<div class="error">' . $langs->trans("ErrorWrongValueForParameter", $langs->transnoentities("WebPagesDirectory")) . '</div>'; |
||
1738 | //print '<a href="#" onClick="javascript: history.back();">'; |
||
1739 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1740 | //print '</a>'; |
||
1741 | $error++; |
||
1742 | } |
||
1743 | } else { |
||
1744 | if (isset($db)) { |
||
1745 | print $db->lasterror(); |
||
1746 | } |
||
1747 | if (isset($db) && !$db->connected) { |
||
1748 | print '<br>' . $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
1749 | } |
||
1750 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1751 | $error++; |
||
1752 | } |
||
1753 | |||
1754 | if (!$error && $db->connected) { |
||
1755 | if (!empty($db_create_database)) { |
||
1756 | $result = $db->select_db($db_name); |
||
1757 | if ($result) { |
||
1758 | print '<div class="error">' . $langs->trans("ErrorDatabaseAlreadyExists", $db_name) . '</div>'; |
||
1759 | print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate") . '<br><br>'; |
||
1760 | print $langs->trans("ErrorGoBackAndCorrectParameters"); |
||
1761 | $error++; |
||
1762 | } |
||
1763 | } |
||
1764 | } |
||
1765 | |||
1766 | // Define $defaultCharacterSet and $defaultDBSortingCollation |
||
1767 | if (!$error && $db->connected) { |
||
1768 | if (!empty($db_create_database)) { // If we create database, we force default value |
||
1769 | // Default values come from the database handler |
||
1770 | |||
1771 | $defaultCharacterSet = $db->forcecharset; |
||
1772 | $defaultDBSortingCollation = $db->forcecollate; |
||
1773 | } else { // If already created, we take current value |
||
1774 | $defaultCharacterSet = $db->getDefaultCharacterSetDatabase(); |
||
1775 | $defaultDBSortingCollation = $db->getDefaultCollationDatabase(); |
||
1776 | } |
||
1777 | |||
1778 | // It seems some PHP driver mysqli does not support utf8mb3 |
||
1779 | if ($defaultCharacterSet == 'utf8mb3' || $defaultDBSortingCollation == 'utf8mb3_unicode_ci') { |
||
1780 | $defaultCharacterSet = 'utf8'; |
||
1781 | $defaultDBSortingCollation = 'utf8_unicode_ci'; |
||
1782 | } |
||
1783 | // 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) |
||
1784 | // TODO Remove this when utf8mb4 is supported |
||
1785 | if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci') { |
||
1786 | $defaultCharacterSet = 'utf8'; |
||
1787 | $defaultDBSortingCollation = 'utf8_unicode_ci'; |
||
1788 | } |
||
1789 | |||
1790 | print '<input type="hidden" name="dolibarr_main_db_character_set" value="' . $defaultCharacterSet . '">'; |
||
1791 | print '<input type="hidden" name="dolibarr_main_db_collation" value="' . $defaultDBSortingCollation . '">'; |
||
1792 | $db_character_set = $defaultCharacterSet; |
||
1793 | $db_collation = $defaultDBSortingCollation; |
||
1794 | dolibarr_install_syslog("step1: db_character_set=" . $db_character_set . " db_collation=" . $db_collation); |
||
1795 | } |
||
1796 | |||
1797 | |||
1798 | // Create config file |
||
1799 | if (!$error && $db->connected && $action == "set") { |
||
1800 | umask(0); |
||
1801 | if (is_array($_POST)) { |
||
1802 | foreach ($_POST as $key => $value) { |
||
1803 | if (!preg_match('/^db_pass/i', $key)) { |
||
1804 | dolibarr_install_syslog("step1: choice for " . $key . " = " . $value); |
||
1805 | } |
||
1806 | } |
||
1807 | } |
||
1808 | |||
1809 | // Show title of step |
||
1810 | print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Configuration"> ' . $langs->trans("ConfigurationFile") . '</h3>'; |
||
1811 | print '<table cellspacing="0" width="100%" cellpadding="1" border="0">'; |
||
1812 | |||
1813 | // Check parameter main_dir |
||
1814 | if (!$error) { |
||
1815 | if (!is_dir($main_dir)) { |
||
1816 | dolibarr_install_syslog("step1: directory '" . $main_dir . "' is unavailable or can't be accessed"); |
||
1817 | |||
1818 | print "<tr><td>"; |
||
1819 | print $langs->trans("ErrorDirDoesNotExists", $main_dir) . '<br>'; |
||
1820 | print $langs->trans("ErrorWrongValueForParameter", $langs->transnoentitiesnoconv("WebPagesDirectory")) . '<br>'; |
||
1821 | print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>'; |
||
1822 | print '</td><td>'; |
||
1823 | print $langs->trans("Error"); |
||
1824 | print "</td></tr>"; |
||
1825 | $error++; |
||
1826 | } |
||
1827 | } |
||
1828 | |||
1829 | if (!$error) { |
||
1830 | dolibarr_install_syslog("step1: directory '" . $main_dir . "' exists"); |
||
1831 | } |
||
1832 | |||
1833 | |||
1834 | // Create subdirectory main_data_dir |
||
1835 | if (!$error) { |
||
1836 | // Create directory for documents |
||
1837 | if (!is_dir($main_data_dir)) { |
||
1838 | dol_mkdir($main_data_dir); |
||
1839 | } |
||
1840 | |||
1841 | if (!is_dir($main_data_dir)) { |
||
1842 | print "<tr><td>" . $langs->trans("ErrorDirDoesNotExists", $main_data_dir); |
||
1843 | print ' ' . $langs->trans("YouMustCreateItAndAllowServerToWrite"); |
||
1844 | print '</td><td>'; |
||
1845 | print '<span class="error">' . $langs->trans("Error") . '</span>'; |
||
1846 | print "</td></tr>"; |
||
1847 | print '<tr><td colspan="2"><br>' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</td></tr>'; |
||
1848 | $error++; |
||
1849 | } else { |
||
1850 | // Create .htaccess file in document directory |
||
1851 | $pathhtaccess = $main_data_dir . '/.htaccess'; |
||
1852 | if (!file_exists($pathhtaccess)) { |
||
1853 | dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '" . $main_data_dir . "'"); |
||
1854 | $handlehtaccess = @fopen($pathhtaccess, 'w'); |
||
1855 | if ($handlehtaccess) { |
||
1856 | fwrite($handlehtaccess, 'Order allow,deny' . "\n"); |
||
1857 | fwrite($handlehtaccess, 'Deny from all' . "\n"); |
||
1858 | |||
1859 | fclose($handlehtaccess); |
||
1860 | dolibarr_install_syslog("step1: .htaccess file created"); |
||
1861 | } |
||
1862 | } |
||
1863 | |||
1864 | // Documents are stored above the web pages root to prevent being downloaded without authentication |
||
1865 | $dir = []; |
||
1866 | $dir[] = $main_data_dir . "/mycompany"; |
||
1867 | $dir[] = $main_data_dir . "/medias"; |
||
1868 | $dir[] = $main_data_dir . "/users"; |
||
1869 | $dir[] = $main_data_dir . "/facture"; |
||
1870 | $dir[] = $main_data_dir . "/propale"; |
||
1871 | $dir[] = $main_data_dir . "/ficheinter"; |
||
1872 | $dir[] = $main_data_dir . "/produit"; |
||
1873 | $dir[] = $main_data_dir . "/doctemplates"; |
||
1874 | |||
1875 | // Loop on each directory of dir [] to create them if they do not exist |
||
1876 | $num = count($dir); |
||
1877 | for ($i = 0; $i < $num; $i++) { |
||
1878 | if (is_dir($dir[$i])) { |
||
1879 | dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' exists"); |
||
1880 | } else { |
||
1881 | if (dol_mkdir($dir[$i]) < 0) { |
||
1882 | print "<tr><td>"; |
||
1883 | print "Failed to create directory: " . $dir[$i]; |
||
1884 | print '</td><td>'; |
||
1885 | print $langs->trans("Error"); |
||
1886 | print "</td></tr>"; |
||
1887 | $error++; |
||
1888 | } else { |
||
1889 | dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' created"); |
||
1890 | } |
||
1891 | } |
||
1892 | } |
||
1893 | |||
1894 | require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
||
1895 | |||
1896 | // Copy directory medias |
||
1897 | $srcroot = $main_dir . '/install/medias'; |
||
1898 | $destroot = $main_data_dir . '/medias'; |
||
1899 | dolCopyDir($srcroot, $destroot, 0, 0); |
||
1900 | |||
1901 | if ($error) { |
||
1902 | print "<tr><td>" . $langs->trans("ErrorDirDoesNotExists", $main_data_dir); |
||
1903 | print ' ' . $langs->trans("YouMustCreateItAndAllowServerToWrite"); |
||
1904 | print '</td><td>'; |
||
1905 | print '<span class="error">' . $langs->trans("Error") . '</span>'; |
||
1906 | print "</td></tr>"; |
||
1907 | print '<tr><td colspan="2"><br>' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</td></tr>'; |
||
1908 | } else { |
||
1909 | //ODT templates |
||
1910 | $srcroot = $main_dir . '/install/doctemplates'; |
||
1911 | $destroot = $main_data_dir . '/doctemplates'; |
||
1912 | $docs = [ |
||
1913 | 'contracts' => 'contract', |
||
1914 | 'invoices' => 'invoice', |
||
1915 | 'orders' => 'order', |
||
1916 | 'products' => 'product', |
||
1917 | 'projects' => 'project', |
||
1918 | 'proposals' => 'proposal', |
||
1919 | 'shipments' => 'shipment', |
||
1920 | 'supplier_proposals' => 'supplier_proposal', |
||
1921 | 'tasks' => 'task_summary', |
||
1922 | 'thirdparties' => 'thirdparty', |
||
1923 | 'usergroups' => 'usergroups', |
||
1924 | 'users' => 'user', |
||
1925 | ]; |
||
1926 | foreach ($docs as $cursordir => $cursorfile) { |
||
1927 | $src = $srcroot . '/' . $cursordir . '/template_' . $cursorfile . '.odt'; |
||
1928 | $dirodt = $destroot . '/' . $cursordir; |
||
1929 | $dest = $dirodt . '/template_' . $cursorfile . '.odt'; |
||
1930 | |||
1931 | dol_mkdir($dirodt); |
||
1932 | $result = dol_copy($src, $dest, 0, 0); |
||
1933 | if ($result < 0) { |
||
1934 | print '<tr><td colspan="2"><br>' . $langs->trans('ErrorFailToCopyFile', $src, $dest) . '</td></tr>'; |
||
1935 | } |
||
1936 | } |
||
1937 | } |
||
1938 | } |
||
1939 | } |
||
1940 | |||
1941 | // Table prefix |
||
1942 | $main_db_prefix = (!empty($db_prefix) ? $db_prefix : 'llx_'); |
||
1943 | |||
1944 | // Write conf file on disk |
||
1945 | if (!$error) { |
||
1946 | // Save old conf file on disk |
||
1947 | if (file_exists("$conffile")) { |
||
1948 | // We must ignore errors as an existing old file may already exist and not be replaceable or |
||
1949 | // the installer (like for ubuntu) may not have permission to create another file than conf.php. |
||
1950 | // Also no other process must be able to read file or we expose the new file, so content with password. |
||
1951 | @dol_copy($conffile, $conffile . '.old', '0400'); |
||
1952 | } |
||
1953 | |||
1954 | $error = 0; |
||
1955 | |||
1956 | $key = md5(uniqid(mt_rand(), true)); // Generate random hash |
||
1957 | |||
1958 | $fp = fopen($conffile, "w"); |
||
1959 | if ($fp) { |
||
1960 | clearstatcache(); |
||
1961 | |||
1962 | fwrite($fp, '<?php' . "\n"); |
||
1963 | fwrite($fp, '//' . "\n"); |
||
1964 | fwrite($fp, '// File generated by Dolibarr installer ' . DOL_VERSION . ' on ' . dol_print_date(dol_now(), '') . "\n"); |
||
1965 | fwrite($fp, '//' . "\n"); |
||
1966 | fwrite($fp, '// Take a look at conf.php.example file for an example of ' . $conffiletoshowshort . ' file' . "\n"); |
||
1967 | fwrite($fp, '// and explanations for all possibles parameters.' . "\n"); |
||
1968 | fwrite($fp, '//' . "\n"); |
||
1969 | |||
1970 | fwrite($fp, '$dolibarr_main_url_root=\'' . dol_escape_php(trim($main_url), 1) . '\';'); |
||
1971 | fwrite($fp, "\n"); |
||
1972 | |||
1973 | fwrite($fp, '$dolibarr_main_document_root="' . dol_escape_php(dol_sanitizePathName(trim($main_dir))) . '";'); |
||
1974 | fwrite($fp, "\n"); |
||
1975 | |||
1976 | fwrite($fp, $main_use_alt_dir . '$dolibarr_main_url_root_alt=\'' . dol_escape_php(trim("/" . $main_alt_dir_name), 1) . '\';'); |
||
1977 | fwrite($fp, "\n"); |
||
1978 | |||
1979 | fwrite($fp, $main_use_alt_dir . '$dolibarr_main_document_root_alt="' . dol_escape_php(dol_sanitizePathName(trim($main_dir . "/" . $main_alt_dir_name))) . '";'); |
||
1980 | fwrite($fp, "\n"); |
||
1981 | |||
1982 | fwrite($fp, '$dolibarr_main_data_root="' . dol_escape_php(dol_sanitizePathName(trim($main_data_dir))) . '";'); |
||
1983 | fwrite($fp, "\n"); |
||
1984 | |||
1985 | fwrite($fp, '$dolibarr_main_db_host=\'' . dol_escape_php(trim($db_host), 1) . '\';'); |
||
1986 | fwrite($fp, "\n"); |
||
1987 | |||
1988 | fwrite($fp, '$dolibarr_main_db_port=\'' . ((int) $db_port) . '\';'); |
||
1989 | fwrite($fp, "\n"); |
||
1990 | |||
1991 | fwrite($fp, '$dolibarr_main_db_name=\'' . dol_escape_php(trim($db_name), 1) . '\';'); |
||
1992 | fwrite($fp, "\n"); |
||
1993 | |||
1994 | fwrite($fp, '$dolibarr_main_db_prefix=\'' . dol_escape_php(trim($main_db_prefix), 1) . '\';'); |
||
1995 | fwrite($fp, "\n"); |
||
1996 | |||
1997 | fwrite($fp, '$dolibarr_main_db_user=\'' . dol_escape_php(trim($db_user), 1) . '\';'); |
||
1998 | fwrite($fp, "\n"); |
||
1999 | fwrite($fp, '$dolibarr_main_db_pass=\'' . dol_escape_php(trim($db_pass), 1) . '\';'); |
||
2000 | fwrite($fp, "\n"); |
||
2001 | |||
2002 | fwrite($fp, '$dolibarr_main_db_type=\'' . dol_escape_php(trim($db_type), 1) . '\';'); |
||
2003 | fwrite($fp, "\n"); |
||
2004 | |||
2005 | fwrite($fp, '$dolibarr_main_db_character_set=\'' . dol_escape_php(trim($db_character_set), 1) . '\';'); |
||
2006 | fwrite($fp, "\n"); |
||
2007 | |||
2008 | fwrite($fp, '$dolibarr_main_db_collation=\'' . dol_escape_php(trim($db_collation), 1) . '\';'); |
||
2009 | fwrite($fp, "\n"); |
||
2010 | |||
2011 | // Authentication |
||
2012 | fwrite($fp, '// Authentication settings'); |
||
2013 | fwrite($fp, "\n"); |
||
2014 | |||
2015 | fwrite($fp, '$dolibarr_main_authentication=\'dolibarr\';'); |
||
2016 | fwrite($fp, "\n\n"); |
||
2017 | |||
2018 | fwrite($fp, '//$dolibarr_main_demo=\'autologin,autopass\';'); |
||
2019 | fwrite($fp, "\n"); |
||
2020 | |||
2021 | fwrite($fp, '// Security settings'); |
||
2022 | fwrite($fp, "\n"); |
||
2023 | |||
2024 | fwrite($fp, '$dolibarr_main_prod=\'0\';'); |
||
2025 | fwrite($fp, "\n"); |
||
2026 | |||
2027 | fwrite($fp, '$dolibarr_main_force_https=\'' . dol_escape_php($main_force_https, 1) . '\';'); |
||
2028 | fwrite($fp, "\n"); |
||
2029 | |||
2030 | fwrite($fp, '$dolibarr_main_restrict_os_commands=\'mariadb-dump, mariadb, mysqldump, mysql, pg_dump, pgrestore, clamdscan, clamscan.exe\';'); |
||
2031 | fwrite($fp, "\n"); |
||
2032 | |||
2033 | fwrite($fp, '$dolibarr_nocsrfcheck=\'0\';'); |
||
2034 | fwrite($fp, "\n"); |
||
2035 | |||
2036 | fwrite($fp, '$dolibarr_main_instance_unique_id=\'' . dol_escape_php($key, 1) . '\';'); |
||
2037 | fwrite($fp, "\n"); |
||
2038 | |||
2039 | fwrite($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';'); |
||
2040 | fwrite($fp, "\n"); |
||
2041 | fwrite($fp, '$dolibarr_mailing_limit_sendbycli=\'0\';'); |
||
2042 | fwrite($fp, "\n"); |
||
2043 | |||
2044 | // Write params to overwrites default lib path |
||
2045 | fwrite($fp, "\n"); |
||
2046 | if (empty($force_dolibarr_lib_FPDF_PATH)) { |
||
2047 | fwrite($fp, '//'); |
||
2048 | $force_dolibarr_lib_FPDF_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2049 | } |
||
2050 | fwrite($fp, '$dolibarr_lib_FPDF_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_FPDF_PATH)) . '";'); |
||
2051 | fwrite($fp, "\n"); |
||
2052 | if (empty($force_dolibarr_lib_TCPDF_PATH)) { |
||
2053 | fwrite($fp, '//'); |
||
2054 | $force_dolibarr_lib_TCPDF_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2055 | } |
||
2056 | fwrite($fp, '$dolibarr_lib_TCPDF_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_TCPDF_PATH)) . '";'); |
||
2057 | fwrite($fp, "\n"); |
||
2058 | if (empty($force_dolibarr_lib_FPDI_PATH)) { |
||
2059 | fwrite($fp, '//'); |
||
2060 | $force_dolibarr_lib_FPDI_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2061 | } |
||
2062 | fwrite($fp, '$dolibarr_lib_FPDI_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_FPDI_PATH)) . '";'); |
||
2063 | fwrite($fp, "\n"); |
||
2064 | if (empty($force_dolibarr_lib_TCPDI_PATH)) { |
||
2065 | fwrite($fp, '//'); |
||
2066 | $force_dolibarr_lib_TCPDI_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2067 | } |
||
2068 | fwrite($fp, '$dolibarr_lib_TCPDI_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_TCPDI_PATH)) . '";'); |
||
2069 | fwrite($fp, "\n"); |
||
2070 | if (empty($force_dolibarr_lib_GEOIP_PATH)) { |
||
2071 | fwrite($fp, '//'); |
||
2072 | $force_dolibarr_lib_GEOIP_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2073 | } |
||
2074 | fwrite($fp, '$dolibarr_lib_GEOIP_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_GEOIP_PATH)) . '";'); |
||
2075 | fwrite($fp, "\n"); |
||
2076 | if (empty($force_dolibarr_lib_NUSOAP_PATH)) { |
||
2077 | fwrite($fp, '//'); |
||
2078 | $force_dolibarr_lib_NUSOAP_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2079 | } |
||
2080 | fwrite($fp, '$dolibarr_lib_NUSOAP_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_NUSOAP_PATH)) . '";'); |
||
2081 | fwrite($fp, "\n"); |
||
2082 | if (empty($force_dolibarr_lib_ODTPHP_PATH)) { |
||
2083 | fwrite($fp, '//'); |
||
2084 | $force_dolibarr_lib_ODTPHP_PATH = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2085 | } |
||
2086 | fwrite($fp, '$dolibarr_lib_ODTPHP_PATH="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_ODTPHP_PATH)) . '";'); |
||
2087 | fwrite($fp, "\n"); |
||
2088 | if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { |
||
2089 | fwrite($fp, '//'); |
||
2090 | $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2091 | } |
||
2092 | fwrite($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP="' . dol_escape_php(dol_sanitizePathName($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) . '";'); |
||
2093 | fwrite($fp, "\n"); |
||
2094 | if (empty($force_dolibarr_js_CKEDITOR)) { |
||
2095 | fwrite($fp, '//'); |
||
2096 | $force_dolibarr_js_CKEDITOR = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2097 | } |
||
2098 | fwrite($fp, '$dolibarr_js_CKEDITOR=\'' . dol_escape_php($force_dolibarr_js_CKEDITOR, 1) . '\';'); |
||
2099 | fwrite($fp, "\n"); |
||
2100 | if (empty($force_dolibarr_js_JQUERY)) { |
||
2101 | fwrite($fp, '//'); |
||
2102 | $force_dolibarr_js_JQUERY = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2103 | } |
||
2104 | fwrite($fp, '$dolibarr_js_JQUERY=\'' . dol_escape_php($force_dolibarr_js_JQUERY, 1) . '\';'); |
||
2105 | fwrite($fp, "\n"); |
||
2106 | if (empty($force_dolibarr_js_JQUERY_UI)) { |
||
2107 | fwrite($fp, '//'); |
||
2108 | $force_dolibarr_js_JQUERY_UI = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2109 | } |
||
2110 | fwrite($fp, '$dolibarr_js_JQUERY_UI=\'' . dol_escape_php($force_dolibarr_js_JQUERY_UI, 1) . '\';'); |
||
2111 | fwrite($fp, "\n"); |
||
2112 | |||
2113 | // Write params to overwrites default font path |
||
2114 | fwrite($fp, "\n"); |
||
2115 | if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { |
||
2116 | fwrite($fp, '//'); |
||
2117 | $force_dolibarr_font_DOL_DEFAULT_TTF = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2118 | } |
||
2119 | fwrite($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\'' . dol_escape_php($force_dolibarr_font_DOL_DEFAULT_TTF, 1) . '\';'); |
||
2120 | fwrite($fp, "\n"); |
||
2121 | if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { |
||
2122 | fwrite($fp, '//'); |
||
2123 | $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment |
||
2124 | } |
||
2125 | fwrite($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\'' . dol_escape_php($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD, 1) . '\';'); |
||
2126 | fwrite($fp, "\n"); |
||
2127 | |||
2128 | // Other |
||
2129 | fwrite($fp, '$dolibarr_main_distrib=\'' . dol_escape_php(trim($dolibarr_main_distrib), 1) . '\';'); |
||
2130 | fwrite($fp, "\n"); |
||
2131 | |||
2132 | fclose($fp); |
||
2133 | |||
2134 | if (file_exists("$conffile")) { |
||
2135 | include $conffile; // force config reload, do not put include_once |
||
2136 | conf($dolibarr_main_document_root); |
||
2137 | |||
2138 | print "<tr><td>"; |
||
2139 | print $langs->trans("SaveConfigurationFile"); |
||
2140 | print ' <strong>' . $conffile . '</strong>'; |
||
2141 | print "</td><td>"; |
||
2142 | print '<img src="../theme/eldy/img/tick.png" alt="Ok">'; |
||
2143 | print "</td></tr>"; |
||
2144 | } else { |
||
2145 | $error++; |
||
2146 | } |
||
2147 | } |
||
2148 | } |
||
2149 | |||
2150 | // Create database and admin user database |
||
2151 | if (!$error) { |
||
2152 | // We reload configuration file |
||
2153 | conf($dolibarr_main_document_root); |
||
2154 | |||
2155 | print '<tr><td>'; |
||
2156 | print $langs->trans("ConfFileReload"); |
||
2157 | print '</td>'; |
||
2158 | print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2159 | |||
2160 | // Create database user if requested |
||
2161 | if (isset($db_create_user) && ($db_create_user == "1" || $db_create_user == "on")) { |
||
2162 | dolibarr_install_syslog("step1: create database user: " . $dolibarr_main_db_user); |
||
2163 | |||
2164 | //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port; |
||
2165 | $databasefortest = $conf->db->name; |
||
2166 | if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { |
||
2167 | $databasefortest = 'mysql'; |
||
2168 | } elseif ($conf->db->type == 'pgsql') { |
||
2169 | $databasefortest = 'postgres'; |
||
2170 | } elseif ($conf->db->type == 'mssql') { |
||
2171 | $databasefortest = 'master'; |
||
2172 | } |
||
2173 | |||
2174 | // Check database connection |
||
2175 | |||
2176 | $db = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, $databasefortest, (int) $conf->db->port); |
||
2177 | |||
2178 | if ($db->error) { |
||
2179 | print '<div class="error">' . $db->error . '</div>'; |
||
2180 | $error++; |
||
2181 | } |
||
2182 | |||
2183 | if (!$error) { |
||
2184 | if ($db->connected) { |
||
2185 | $resultbis = 1; |
||
2186 | |||
2187 | if (empty($dolibarr_main_db_pass)) { |
||
2188 | dolibarr_install_syslog("step1: failed to create user, password is empty", LOG_ERR); |
||
2189 | print '<tr><td>'; |
||
2190 | print $langs->trans("UserCreation") . ' : '; |
||
2191 | print $dolibarr_main_db_user; |
||
2192 | print '</td>'; |
||
2193 | print '<td>' . $langs->trans("Error") . ": A password for database user is mandatory.</td></tr>"; |
||
2194 | } else { |
||
2195 | // Create user |
||
2196 | $result = $db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name); |
||
2197 | |||
2198 | // Create user bis |
||
2199 | if ($databasefortest == 'mysql') { |
||
2200 | if (!in_array($dolibarr_main_db_host, ['127.0.0.1', '::1', 'localhost', 'localhost.local'])) { |
||
2201 | $resultbis = $db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name); |
||
2202 | } |
||
2203 | } |
||
2204 | |||
2205 | if ($result > 0 && $resultbis > 0) { |
||
2206 | print '<tr><td>'; |
||
2207 | print $langs->trans("UserCreation") . ' : '; |
||
2208 | print $dolibarr_main_db_user; |
||
2209 | print '</td>'; |
||
2210 | print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2211 | } else { |
||
2212 | if ( |
||
2213 | $db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS' |
||
2214 | || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' |
||
2215 | || $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS' |
||
2216 | ) { |
||
2217 | dolibarr_install_syslog("step1: user already exists"); |
||
2218 | print '<tr><td>'; |
||
2219 | print $langs->trans("UserCreation") . ' : '; |
||
2220 | print $dolibarr_main_db_user; |
||
2221 | print '</td>'; |
||
2222 | print '<td>' . $langs->trans("LoginAlreadyExists") . '</td></tr>'; |
||
2223 | } else { |
||
2224 | dolibarr_install_syslog("step1: failed to create user", LOG_ERR); |
||
2225 | print '<tr><td>'; |
||
2226 | print $langs->trans("UserCreation") . ' : '; |
||
2227 | print $dolibarr_main_db_user; |
||
2228 | print '</td>'; |
||
2229 | print '<td>' . $langs->trans("Error") . ': ' . $db->errno() . ' ' . $db->error() . ($db->error ? '. ' . $db->error : '') . "</td></tr>"; |
||
2230 | } |
||
2231 | } |
||
2232 | } |
||
2233 | |||
2234 | $db->close(); |
||
2235 | } else { |
||
2236 | print '<tr><td>'; |
||
2237 | print $langs->trans("UserCreation") . ' : '; |
||
2238 | print $dolibarr_main_db_user; |
||
2239 | print '</td>'; |
||
2240 | print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>'; |
||
2241 | print '</tr>'; |
||
2242 | |||
2243 | // warning message due to connection failure |
||
2244 | print '<tr><td colspan="2"><br>'; |
||
2245 | print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot); |
||
2246 | print '<br>'; |
||
2247 | print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
2248 | print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>'; |
||
2249 | print '</td></tr>'; |
||
2250 | |||
2251 | $error++; |
||
2252 | } |
||
2253 | } |
||
2254 | } // end of user account creation |
||
2255 | |||
2256 | $conf = Config::loadConf(true); |
||
2257 | |||
2258 | // If database creation was asked, we create it |
||
2259 | if (!$error && (isset($db_create_database) && ($db_create_database == "1" || $db_create_database == "on"))) { |
||
2260 | dolibarr_install_syslog("step1: create database: " . $dolibarr_main_db_name . " " . $dolibarr_main_db_character_set . " " . $dolibarr_main_db_collation . " " . $dolibarr_main_db_user); |
||
2261 | $newdb = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, '', (int) $conf->db->port); |
||
2262 | //print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit; |
||
2263 | |||
2264 | if ($newdb->connected) { |
||
2265 | $result = $newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user); |
||
2266 | |||
2267 | if ($result) { |
||
2268 | print '<tr><td>'; |
||
2269 | print $langs->trans("DatabaseCreation") . " (" . $langs->trans("User") . " " . $userroot . ") : "; |
||
2270 | print $dolibarr_main_db_name; |
||
2271 | print '</td>'; |
||
2272 | print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2273 | |||
2274 | $newdb->select_db($dolibarr_main_db_name); |
||
2275 | $check1 = $newdb->getDefaultCharacterSetDatabase(); |
||
2276 | $check2 = $newdb->getDefaultCollationDatabase(); |
||
2277 | dolibarr_install_syslog('step1: new database is using charset=' . $check1 . ' collation=' . $check2); |
||
2278 | |||
2279 | // If values differs, we save conf file again |
||
2280 | //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); |
||
2281 | //if ($check2 != $dolibarr_main_db_collation) dolibarr_install_syslog('step1: value for collation is not the one asked for database creation', LOG_WARNING); |
||
2282 | } else { |
||
2283 | // warning message |
||
2284 | print '<tr><td colspan="2"><br>'; |
||
2285 | print $langs->trans("ErrorFailedToCreateDatabase", $dolibarr_main_db_name) . '<br>'; |
||
2286 | print $newdb->lasterror() . '<br>'; |
||
2287 | print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate"); |
||
2288 | print '<br>'; |
||
2289 | print '</td></tr>'; |
||
2290 | |||
2291 | dolibarr_install_syslog('step1: failed to create database ' . $dolibarr_main_db_name . ' ' . $newdb->lasterrno() . ' ' . $newdb->lasterror(), LOG_ERR); |
||
2292 | $error++; |
||
2293 | } |
||
2294 | $newdb->close(); |
||
2295 | } else { |
||
2296 | print '<tr><td>'; |
||
2297 | print $langs->trans("DatabaseCreation") . " (" . $langs->trans("User") . " " . $userroot . ") : "; |
||
2298 | print $dolibarr_main_db_name; |
||
2299 | print '</td>'; |
||
2300 | print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>'; |
||
2301 | print '</tr>'; |
||
2302 | |||
2303 | // warning message |
||
2304 | print '<tr><td colspan="2"><br>'; |
||
2305 | print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot); |
||
2306 | print '<br>'; |
||
2307 | print $langs->trans("BecauseConnectionFailedParametersMayBeWrong") . '<br><br>'; |
||
2308 | print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>'; |
||
2309 | print '</td></tr>'; |
||
2310 | |||
2311 | $error++; |
||
2312 | } |
||
2313 | } // end of create database |
||
2314 | |||
2315 | // We test access with dolibarr database user (not admin) |
||
2316 | if (!$error) { |
||
2317 | 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); |
||
2318 | //print "connection de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name; |
||
2319 | |||
2320 | $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port); |
||
2321 | |||
2322 | if ($db->connected) { |
||
2323 | dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " ok"); |
||
2324 | print "<tr><td>"; |
||
2325 | print $langs->trans("ServerConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : "; |
||
2326 | print $dolibarr_main_db_host; |
||
2327 | print "</td><td>"; |
||
2328 | print '<img src="../theme/eldy/img/tick.png" alt="Ok">'; |
||
2329 | print "</td></tr>"; |
||
2330 | |||
2331 | // server access ok, basic access ok |
||
2332 | if ($db->database_selected) { |
||
2333 | dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " ok"); |
||
2334 | print "<tr><td>"; |
||
2335 | print $langs->trans("DatabaseConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : "; |
||
2336 | print $dolibarr_main_db_name; |
||
2337 | print "</td><td>"; |
||
2338 | print '<img src="../theme/eldy/img/tick.png" alt="Ok">'; |
||
2339 | print "</td></tr>"; |
||
2340 | |||
2341 | $error = 0; |
||
2342 | } else { |
||
2343 | dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " failed", LOG_ERR); |
||
2344 | print "<tr><td>"; |
||
2345 | print $langs->trans("DatabaseConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : "; |
||
2346 | print $dolibarr_main_db_name; |
||
2347 | print '</td><td>'; |
||
2348 | print '<img src="../theme/eldy/img/error.png" alt="Error">'; |
||
2349 | print "</td></tr>"; |
||
2350 | |||
2351 | // warning message |
||
2352 | print '<tr><td colspan="2"><br>'; |
||
2353 | print $langs->trans('CheckThatDatabasenameIsCorrect', $dolibarr_main_db_name) . '<br>'; |
||
2354 | print $langs->trans('IfAlreadyExistsCheckOption') . '<br>'; |
||
2355 | print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>'; |
||
2356 | print '</td></tr>'; |
||
2357 | |||
2358 | $error++; |
||
2359 | } |
||
2360 | } else { |
||
2361 | dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " failed", LOG_ERR); |
||
2362 | print "<tr><td>"; |
||
2363 | print $langs->trans("ServerConnection") . " (" . $langs->trans("User") . " " . $conf->db->user . ") : "; |
||
2364 | print $dolibarr_main_db_host; |
||
2365 | print '</td><td>'; |
||
2366 | print '<img src="../theme/eldy/img/error.png" alt="Error">'; |
||
2367 | print "</td></tr>"; |
||
2368 | |||
2369 | // warning message |
||
2370 | print '<tr><td colspan="2"><br>'; |
||
2371 | print $langs->trans("ErrorConnection", $conf->db->host, $conf->db->name, $conf->db->user); |
||
2372 | print $langs->trans('IfLoginDoesNotExistsCheckCreateUser') . '<br>'; |
||
2373 | print $langs->trans("ErrorGoBackAndCorrectParameters") . '<br><br>'; |
||
2374 | print '</td></tr>'; |
||
2375 | |||
2376 | $error++; |
||
2377 | } |
||
2378 | } |
||
2379 | } |
||
2380 | |||
2381 | print '</table>'; |
||
2382 | } |
||
2383 | |||
2384 | ?> |
||
2385 | |||
2386 | <script type="text/javascript"> |
||
2387 | function jsinfo() { |
||
2388 | ok = true; |
||
2389 | |||
2390 | //alert('<?php echo dol_escape_js($langs->transnoentities("NextStepMightLastALongTime")); ?>'); |
||
2391 | |||
2392 | document.getElementById('nextbutton').style.visibility = "hidden"; |
||
2393 | document.getElementById('pleasewait').style.visibility = "visible"; |
||
2394 | |||
2395 | return ok; |
||
2396 | } |
||
2397 | </script> |
||
2398 | |||
2399 | <?php |
||
2400 | |||
2401 | $ret = 0; |
||
2402 | if ($error && isset($argv[1])) { |
||
2403 | $ret = 1; |
||
2404 | } |
||
2405 | dolibarr_install_syslog("Exit " . $ret); |
||
2406 | |||
2407 | dolibarr_install_syslog("--- step1: end"); |
||
2408 | |||
2409 | pFooter($error ? 1 : 0, $setuplang, 'jsinfo', 1); |
||
2410 | |||
2411 | // Return code if ran from command line |
||
2412 | if ($ret) { |
||
2413 | exit($ret); |
||
2414 | } |
||
2415 | } |
||
2416 | |||
2417 | public function step2() |
||
2418 | { |
||
2419 | global $langs; |
||
2420 | |||
2421 | |||
2422 | $conffile = Config::getDolibarrConfigFilename(); |
||
2423 | $conffiletoshow = $conffile; |
||
2424 | |||
2425 | $conf = Config::loadConf(true); |
||
2426 | |||
2427 | if (!isset($langs)) { |
||
2428 | $langs = Globals::getLangs($conf); |
||
2429 | $langs->setDefaultLang('auto'); |
||
2430 | } |
||
2431 | |||
2432 | $step = 2; |
||
2433 | $ok = 0; |
||
2434 | |||
2435 | $dolibarr_main_db_type = $conf->db->type; |
||
2436 | $dolibarr_main_db_prefix = $conf->db->prefix; |
||
2437 | |||
2438 | |||
2439 | // This page can be long. We increase the time allowed. / Cette page peut etre longue. On augmente le delai autorise. |
||
2440 | // Only works if you are not in safe_mode. / Ne fonctionne que si on est pas en safe_mode. |
||
2441 | |||
2442 | $err = error_reporting(); |
||
2443 | error_reporting(0); // Disable all errors |
||
2444 | //error_reporting(E_ALL); |
||
2445 | @set_time_limit(1800); // Need 1800 on some very slow OS like Windows 7/64 |
||
2446 | error_reporting($err); |
||
2447 | |||
2448 | $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]); |
||
2449 | $setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[2]) ? 'auto' : $argv[2]); |
||
2450 | $langs->setDefaultLang($setuplang); |
||
2451 | |||
2452 | $langs->loadLangs(["admin", "install"]); |
||
2453 | |||
2454 | |||
2455 | // Choice of DBMS |
||
2456 | |||
2457 | $choix = 0; |
||
2458 | if ($dolibarr_main_db_type == "mysqli") { |
||
2459 | $choix = 1; |
||
2460 | } |
||
2461 | if ($dolibarr_main_db_type == "pgsql") { |
||
2462 | $choix = 2; |
||
2463 | } |
||
2464 | if ($dolibarr_main_db_type == "mssql") { |
||
2465 | $choix = 3; |
||
2466 | } |
||
2467 | if ($dolibarr_main_db_type == "sqlite") { |
||
2468 | $choix = 4; |
||
2469 | } |
||
2470 | if ($dolibarr_main_db_type == "sqlite3") { |
||
2471 | $choix = 5; |
||
2472 | } |
||
2473 | //if (empty($choix)) dol_print_error(null,'Database type '.$dolibarr_main_db_type.' not supported into step2.php page'); |
||
2474 | |||
2475 | |||
2476 | // Now we load forced values from install.forced.php file. |
||
2477 | |||
2478 | $useforcedwizard = false; |
||
2479 | $forcedfile = "./install.forced.php"; |
||
2480 | if ($conffile == "/etc/dolibarr/conf.php") { |
||
2481 | $forcedfile = "/etc/dolibarr/install.forced.php"; |
||
2482 | } |
||
2483 | if (@file_exists($forcedfile)) { |
||
2484 | $useforcedwizard = true; |
||
2485 | include_once $forcedfile; |
||
2486 | // test for travis |
||
2487 | if (!empty($argv[1]) && $argv[1] == "set") { |
||
2488 | $action = "set"; |
||
2489 | } |
||
2490 | } |
||
2491 | |||
2492 | dolibarr_install_syslog("--- step2: entering step2.php page"); |
||
2493 | |||
2494 | |||
2495 | /* |
||
2496 | * View |
||
2497 | */ |
||
2498 | |||
2499 | pHeader($langs->trans("CreateDatabaseObjects"), "step4"); |
||
2500 | |||
2501 | // Test if we can run a first install process |
||
2502 | if (!is_writable($conffile)) { |
||
2503 | print $langs->trans("ConfFileIsNotWritable", $conffiletoshow); |
||
2504 | pFooter(1, $setuplang, 'jscheckparam'); |
||
2505 | exit; |
||
2506 | } |
||
2507 | |||
2508 | if ($action == "set") { |
||
2509 | print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ' . $langs->trans("Database") . '</h3>'; |
||
2510 | |||
2511 | print '<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">'; |
||
2512 | $error = 0; |
||
2513 | |||
2514 | $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port); |
||
2515 | |||
2516 | if ($db->connected) { |
||
2517 | print "<tr><td>"; |
||
2518 | print $langs->trans("ServerConnection") . " : " . $conf->db->host . '</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2519 | $ok = 1; |
||
2520 | } else { |
||
2521 | print "<tr><td>Failed to connect to server : " . $conf->db->host . '</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>'; |
||
2522 | } |
||
2523 | |||
2524 | if ($ok) { |
||
2525 | if ($db->database_selected) { |
||
2526 | dolibarr_install_syslog("step2: successful connection to database: " . $conf->db->name); |
||
2527 | } else { |
||
2528 | dolibarr_install_syslog("step2: failed connection to database :" . $conf->db->name, LOG_ERR); |
||
2529 | print "<tr><td>Failed to select database " . $conf->db->name . '</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>'; |
||
2530 | $ok = 0; |
||
2531 | } |
||
2532 | } |
||
2533 | |||
2534 | |||
2535 | // Display version / Affiche version |
||
2536 | if ($ok) { |
||
2537 | $version = $db->getVersion(); |
||
2538 | $versionarray = $db->getVersionArray(); |
||
2539 | print '<tr><td>' . $langs->trans("DatabaseVersion") . '</td>'; |
||
2540 | print '<td>' . $version . '</td></tr>'; |
||
2541 | //print '<td class="right">'.join('.',$versionarray).'</td></tr>'; |
||
2542 | |||
2543 | print '<tr><td>' . $langs->trans("DatabaseName") . '</td>'; |
||
2544 | print '<td>' . $db->database_name . '</td></tr>'; |
||
2545 | //print '<td class="right">'.join('.',$versionarray).'</td></tr>'; |
||
2546 | } |
||
2547 | |||
2548 | $requestnb = 0; |
||
2549 | |||
2550 | // To disable some code, so you can call step2 with url like |
||
2551 | // http://localhost/dolibarrnew/install/step2.php?action=set&token='.newToken().'&createtables=0&createkeys=0&createfunctions=0&createdata=llx_20_c_departements |
||
2552 | $createtables = GETPOSTISSET('createtables') ? GETPOST('createtables') : 1; |
||
2553 | $createkeys = GETPOSTISSET('createkeys') ? GETPOST('createkeys') : 1; |
||
2554 | $createfunctions = GETPOSTISSET('createfunctions') ? GETPOST('createfunction') : 1; |
||
2555 | $createdata = GETPOSTISSET('createdata') ? GETPOST('createdata') : 1; |
||
2556 | |||
2557 | |||
2558 | // To say that SQL we pass to query are already escaped for mysql, so we need to unescape them |
||
2559 | if (property_exists($db, 'unescapeslashquot')) { |
||
2560 | $db->unescapeslashquot = true; |
||
2561 | } |
||
2562 | |||
2563 | /************************************************************************************** |
||
2564 | * |
||
2565 | * Load files tables/*.sql (not the *.key.sql). Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx'). |
||
2566 | * To do before the files *.key.sql |
||
2567 | * |
||
2568 | ***************************************************************************************/ |
||
2569 | if ($ok && $createtables) { |
||
2570 | // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax) |
||
2571 | $dir = "mysql/tables/"; |
||
2572 | |||
2573 | $ok = 0; |
||
2574 | $handle = opendir($dir); |
||
2575 | dolibarr_install_syslog("step2: open tables directory " . $dir . " handle=" . $handle); |
||
2576 | $tablefound = 0; |
||
2577 | $tabledata = []; |
||
2578 | if (is_resource($handle)) { |
||
2579 | while (($file = readdir($handle)) !== false) { |
||
2580 | if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) { |
||
2581 | $tablefound++; |
||
2582 | $tabledata[] = $file; |
||
2583 | } |
||
2584 | } |
||
2585 | closedir($handle); |
||
2586 | } |
||
2587 | |||
2588 | // Sort list of sql files on alphabetical order (load order is important) |
||
2589 | sort($tabledata); |
||
2590 | foreach ($tabledata as $file) { |
||
2591 | $name = substr($file, 0, dol_strlen($file) - 4); |
||
2592 | $buffer = ''; |
||
2593 | $fp = fopen($dir . $file, "r"); |
||
2594 | if ($fp) { |
||
2595 | while (!feof($fp)) { |
||
2596 | $buf = fgets($fp, 4096); |
||
2597 | if (substr($buf, 0, 2) != '--') { |
||
2598 | $buf = preg_replace('/--(.+)*/', '', $buf); |
||
2599 | $buffer .= $buf; |
||
2600 | } |
||
2601 | } |
||
2602 | fclose($fp); |
||
2603 | |||
2604 | $buffer = trim($buffer); |
||
2605 | if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb |
||
2606 | $buffer = preg_replace('/type=innodb/i', 'ENGINE=innodb', $buffer); |
||
2607 | } else { |
||
2608 | // Keyword ENGINE is MySQL-specific, so scrub it for |
||
2609 | // other database types (mssql, pgsql) |
||
2610 | $buffer = preg_replace('/type=innodb/i', '', $buffer); |
||
2611 | $buffer = preg_replace('/ENGINE=innodb/i', '', $buffer); |
||
2612 | } |
||
2613 | |||
2614 | // Replace the prefix tables |
||
2615 | if ($dolibarr_main_db_prefix != 'llx_') { |
||
2616 | $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer); |
||
2617 | } |
||
2618 | |||
2619 | //print "<tr><td>Creation of table $name/td>"; |
||
2620 | $requestnb++; |
||
2621 | |||
2622 | dolibarr_install_syslog("step2: request: " . $buffer); |
||
2623 | $resql = $db->query($buffer, 0, 'dml'); |
||
2624 | if ($resql) { |
||
2625 | // print "<td>OK request ==== $buffer</td></tr>"; |
||
2626 | $db->free($resql); |
||
2627 | } else { |
||
2628 | if ( |
||
2629 | $db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS' || |
||
2630 | $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' |
||
2631 | ) { |
||
2632 | //print "<td>already existing</td></tr>"; |
||
2633 | } else { |
||
2634 | print "<tr><td>" . $langs->trans("CreateTableAndPrimaryKey", $name); |
||
2635 | print "<br>\n" . $langs->trans("Request") . ' ' . $requestnb . ' : ' . $buffer . ' <br>Executed query : ' . $db->lastquery; |
||
2636 | print "\n</td>"; |
||
2637 | print '<td><span class="error">' . $langs->trans("ErrorSQL") . " " . $db->errno() . " " . $db->error() . '</span></td></tr>'; |
||
2638 | $error++; |
||
2639 | } |
||
2640 | } |
||
2641 | } else { |
||
2642 | print "<tr><td>" . $langs->trans("CreateTableAndPrimaryKey", $name); |
||
2643 | print "</td>"; |
||
2644 | print '<td><span class="error">' . $langs->trans("Error") . ' Failed to open file ' . $dir . $file . '</span></td></tr>'; |
||
2645 | $error++; |
||
2646 | dolibarr_install_syslog("step2: failed to open file " . $dir . $file, LOG_ERR); |
||
2647 | } |
||
2648 | } |
||
2649 | |||
2650 | if ($tablefound) { |
||
2651 | if ($error == 0) { |
||
2652 | print '<tr><td>'; |
||
2653 | print $langs->trans("TablesAndPrimaryKeysCreation") . '</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2654 | $ok = 1; |
||
2655 | } |
||
2656 | } else { |
||
2657 | print '<tr><td>' . $langs->trans("ErrorFailedToFindSomeFiles", $dir) . '</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>'; |
||
2658 | dolibarr_install_syslog("step2: failed to find files to create database in directory " . $dir, LOG_ERR); |
||
2659 | } |
||
2660 | } |
||
2661 | |||
2662 | |||
2663 | /*************************************************************************************** |
||
2664 | * |
||
2665 | * Load files tables/*.key.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx'). |
||
2666 | * To do after the files *.sql |
||
2667 | * |
||
2668 | ***************************************************************************************/ |
||
2669 | if ($ok && $createkeys) { |
||
2670 | // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax) |
||
2671 | $dir = "mysql/tables/"; |
||
2672 | |||
2673 | $okkeys = 0; |
||
2674 | $handle = opendir($dir); |
||
2675 | dolibarr_install_syslog("step2: open keys directory " . $dir . " handle=" . $handle); |
||
2676 | $tablefound = 0; |
||
2677 | $tabledata = []; |
||
2678 | if (is_resource($handle)) { |
||
2679 | while (($file = readdir($handle)) !== false) { |
||
2680 | if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) { |
||
2681 | $tablefound++; |
||
2682 | $tabledata[] = $file; |
||
2683 | } |
||
2684 | } |
||
2685 | closedir($handle); |
||
2686 | } |
||
2687 | |||
2688 | // Sort list of sql files on alphabetical order (load order is important) |
||
2689 | sort($tabledata); |
||
2690 | foreach ($tabledata as $file) { |
||
2691 | $name = substr($file, 0, dol_strlen($file) - 4); |
||
2692 | //print "<tr><td>Creation of table $name</td>"; |
||
2693 | $buffer = ''; |
||
2694 | $fp = fopen($dir . $file, "r"); |
||
2695 | if ($fp) { |
||
2696 | while (!feof($fp)) { |
||
2697 | $buf = fgets($fp, 4096); |
||
2698 | |||
2699 | // Special case of lines allowed for some version only |
||
2700 | // MySQL |
||
2701 | if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg)) { |
||
2702 | $versioncommande = explode('.', $reg[1]); |
||
2703 | //var_dump($versioncommande); |
||
2704 | //var_dump($versionarray); |
||
2705 | if ( |
||
2706 | count($versioncommande) && count($versionarray) |
||
2707 | && versioncompare($versioncommande, $versionarray) <= 0 |
||
2708 | ) { |
||
2709 | // Version qualified, delete SQL comments |
||
2710 | $buf = preg_replace('/^--\sV([0-9\.]+)/i', '', $buf); |
||
2711 | //print "Ligne $i qualifiee par version: ".$buf.'<br>'; |
||
2712 | } |
||
2713 | } |
||
2714 | // PGSQL |
||
2715 | if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) { |
||
2716 | $versioncommande = explode('.', $reg[1]); |
||
2717 | //var_dump($versioncommande); |
||
2718 | //var_dump($versionarray); |
||
2719 | if ( |
||
2720 | count($versioncommande) && count($versionarray) |
||
2721 | && versioncompare($versioncommande, $versionarray) <= 0 |
||
2722 | ) { |
||
2723 | // Version qualified, delete SQL comments |
||
2724 | $buf = preg_replace('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', '', $buf); |
||
2725 | //print "Ligne $i qualifiee par version: ".$buf.'<br>'; |
||
2726 | } |
||
2727 | } |
||
2728 | |||
2729 | // Add line if no comment |
||
2730 | if (!preg_match('/^--/i', $buf)) { |
||
2731 | $buffer .= $buf; |
||
2732 | } |
||
2733 | } |
||
2734 | fclose($fp); |
||
2735 | |||
2736 | // If several requests, we loop on each |
||
2737 | $listesql = explode(';', $buffer); |
||
2738 | foreach ($listesql as $req) { |
||
2739 | $buffer = trim($req); |
||
2740 | if ($buffer) { |
||
2741 | // Replace the prefix tables |
||
2742 | if ($dolibarr_main_db_prefix != 'llx_') { |
||
2743 | $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer); |
||
2744 | } |
||
2745 | |||
2746 | //print "<tr><td>Creation of keys and table index $name: '$buffer'</td>"; |
||
2747 | $requestnb++; |
||
2748 | |||
2749 | dolibarr_install_syslog("step2: request: " . $buffer); |
||
2750 | $resql = $db->query($buffer, 0, 'dml'); |
||
2751 | if ($resql) { |
||
2752 | //print "<td>OK request ==== $buffer</td></tr>"; |
||
2753 | $db->free($resql); |
||
2754 | } else { |
||
2755 | if ( |
||
2756 | $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' || |
||
2757 | $db->errno() == 'DB_ERROR_CANNOT_CREATE' || |
||
2758 | $db->errno() == 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' || |
||
2759 | $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' || |
||
2760 | preg_match('/duplicate key name/i', $db->error()) |
||
2761 | ) { |
||
2762 | //print "<td>Deja existante</td></tr>"; |
||
2763 | $key_exists = 1; |
||
2764 | } else { |
||
2765 | print "<tr><td>" . $langs->trans("CreateOtherKeysForTable", $name); |
||
2766 | print "<br>\n" . $langs->trans("Request") . ' ' . $requestnb . ' : ' . $db->lastqueryerror(); |
||
2767 | print "\n</td>"; |
||
2768 | print '<td><span class="error">' . $langs->trans("ErrorSQL") . " " . $db->errno() . " " . $db->error() . '</span></td></tr>'; |
||
2769 | $error++; |
||
2770 | } |
||
2771 | } |
||
2772 | } |
||
2773 | } |
||
2774 | } else { |
||
2775 | print "<tr><td>" . $langs->trans("CreateOtherKeysForTable", $name); |
||
2776 | print "</td>"; |
||
2777 | print '<td><span class="error">' . $langs->trans("Error") . " Failed to open file " . $dir . $file . "</span></td></tr>"; |
||
2778 | $error++; |
||
2779 | dolibarr_install_syslog("step2: failed to open file " . $dir . $file, LOG_ERR); |
||
2780 | } |
||
2781 | } |
||
2782 | |||
2783 | if ($tablefound && $error == 0) { |
||
2784 | print '<tr><td>'; |
||
2785 | print $langs->trans("OtherKeysCreation") . '</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2786 | $okkeys = 1; |
||
2787 | } |
||
2788 | } |
||
2789 | |||
2790 | |||
2791 | /*************************************************************************************** |
||
2792 | * |
||
2793 | * Load the file 'functions.sql' |
||
2794 | * |
||
2795 | ***************************************************************************************/ |
||
2796 | if ($ok && $createfunctions) { |
||
2797 | // For this file, we use a directory according to database type |
||
2798 | if ($choix == 1) { |
||
2799 | $dir = "mysql/functions/"; |
||
2800 | } elseif ($choix == 2) { |
||
2801 | $dir = "pgsql/functions/"; |
||
2802 | } elseif ($choix == 3) { |
||
2803 | $dir = "mssql/functions/"; |
||
2804 | } elseif ($choix == 4) { |
||
2805 | $dir = "sqlite3/functions/"; |
||
2806 | } |
||
2807 | |||
2808 | // Creation of data |
||
2809 | $file = "functions.sql"; |
||
2810 | if (file_exists($dir . $file)) { |
||
2811 | $fp = fopen($dir . $file, "r"); |
||
2812 | dolibarr_install_syslog("step2: open function file " . $dir . $file . " handle=" . $fp); |
||
2813 | if ($fp) { |
||
2814 | $buffer = ''; |
||
2815 | while (!feof($fp)) { |
||
2816 | $buf = fgets($fp, 4096); |
||
2817 | if (substr($buf, 0, 2) != '--') { |
||
2818 | $buffer .= $buf . "§"; |
||
2819 | } |
||
2820 | } |
||
2821 | fclose($fp); |
||
2822 | } |
||
2823 | //$buffer=preg_replace('/;\';/',";'§",$buffer); |
||
2824 | |||
2825 | // If several requests, we loop on each of them |
||
2826 | $listesql = explode('§', $buffer); |
||
2827 | foreach ($listesql as $buffer) { |
||
2828 | $buffer = trim($buffer); |
||
2829 | if ($buffer) { |
||
2830 | // Replace the prefix in table names |
||
2831 | if ($dolibarr_main_db_prefix != 'llx_') { |
||
2832 | $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer); |
||
2833 | } |
||
2834 | dolibarr_install_syslog("step2: request: " . $buffer); |
||
2835 | print "<!-- Insert line : " . $buffer . "<br>-->\n"; |
||
2836 | $resql = $db->query($buffer, 0, 'dml'); |
||
2837 | if ($resql) { |
||
2838 | $ok = 1; |
||
2839 | $db->free($resql); |
||
2840 | } else { |
||
2841 | if ( |
||
2842 | $db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS' |
||
2843 | || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' |
||
2844 | ) { |
||
2845 | //print "Insert line : ".$buffer."<br>\n"; |
||
2846 | } else { |
||
2847 | $ok = 0; |
||
2848 | |||
2849 | print "<tr><td>" . $langs->trans("FunctionsCreation"); |
||
2850 | print "<br>\n" . $langs->trans("Request") . ' ' . $requestnb . ' : ' . $buffer; |
||
2851 | print "\n</td>"; |
||
2852 | print '<td><span class="error">' . $langs->trans("ErrorSQL") . " " . $db->errno() . " " . $db->error() . '</span></td></tr>'; |
||
2853 | $error++; |
||
2854 | } |
||
2855 | } |
||
2856 | } |
||
2857 | } |
||
2858 | |||
2859 | print "<tr><td>" . $langs->trans("FunctionsCreation") . "</td>"; |
||
2860 | if ($ok) { |
||
2861 | print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2862 | } else { |
||
2863 | print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>'; |
||
2864 | $ok = 1; |
||
2865 | } |
||
2866 | } |
||
2867 | } |
||
2868 | |||
2869 | |||
2870 | /*************************************************************************************** |
||
2871 | * |
||
2872 | * Load files data/*.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx'). |
||
2873 | * |
||
2874 | ***************************************************************************************/ |
||
2875 | if ($ok && $createdata) { |
||
2876 | // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax) |
||
2877 | $dir = "mysql/data/"; |
||
2878 | |||
2879 | // Insert data |
||
2880 | $handle = opendir($dir); |
||
2881 | dolibarr_install_syslog("step2: open directory data " . $dir . " handle=" . $handle); |
||
2882 | $tablefound = 0; |
||
2883 | $tabledata = []; |
||
2884 | if (is_resource($handle)) { |
||
2885 | while (($file = readdir($handle)) !== false) { |
||
2886 | if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\-/', $file)) { |
||
2887 | if (preg_match('/^llx_accounting_account_/', $file)) { |
||
2888 | continue; // We discard data file of chart of account. This will be loaded when a chart is selected. |
||
2889 | } |
||
2890 | |||
2891 | //print 'x'.$file.'-'.$createdata.'<br>'; |
||
2892 | if (is_numeric($createdata) || preg_match('/' . preg_quote($createdata) . '/i', $file)) { |
||
2893 | $tablefound++; |
||
2894 | $tabledata[] = $file; |
||
2895 | } |
||
2896 | } |
||
2897 | } |
||
2898 | closedir($handle); |
||
2899 | } |
||
2900 | |||
2901 | // Sort list of data files on alphabetical order (load order is important) |
||
2902 | sort($tabledata); |
||
2903 | foreach ($tabledata as $file) { |
||
2904 | $name = substr($file, 0, dol_strlen($file) - 4); |
||
2905 | $fp = fopen($dir . $file, "r"); |
||
2906 | dolibarr_install_syslog("step2: open data file " . $dir . $file . " handle=" . $fp); |
||
2907 | if ($fp) { |
||
2908 | $arrayofrequests = []; |
||
2909 | $linefound = 0; |
||
2910 | $linegroup = 0; |
||
2911 | $sizeofgroup = 1; // Grouping request to have 1 query for several requests does not works with mysql, so we use 1. |
||
2912 | |||
2913 | // Load all requests |
||
2914 | while (!feof($fp)) { |
||
2915 | $buffer = fgets($fp, 4096); |
||
2916 | $buffer = trim($buffer); |
||
2917 | if ($buffer) { |
||
2918 | if (substr($buffer, 0, 2) == '--') { |
||
2919 | continue; |
||
2920 | } |
||
2921 | |||
2922 | if ($linefound && ($linefound % $sizeofgroup) == 0) { |
||
2923 | $linegroup++; |
||
2924 | } |
||
2925 | if (empty($arrayofrequests[$linegroup])) { |
||
2926 | $arrayofrequests[$linegroup] = $buffer; |
||
2927 | } else { |
||
2928 | $arrayofrequests[$linegroup] .= " " . $buffer; |
||
2929 | } |
||
2930 | |||
2931 | $linefound++; |
||
2932 | } |
||
2933 | } |
||
2934 | fclose($fp); |
||
2935 | |||
2936 | dolibarr_install_syslog("step2: found " . $linefound . " records, defined " . count($arrayofrequests) . " group(s)."); |
||
2937 | |||
2938 | $okallfile = 1; |
||
2939 | $db->begin(); |
||
2940 | |||
2941 | // We loop on each requests of file |
||
2942 | foreach ($arrayofrequests as $buffer) { |
||
2943 | // Replace the tables prefixes |
||
2944 | if ($dolibarr_main_db_prefix != 'llx_') { |
||
2945 | $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer); |
||
2946 | } |
||
2947 | |||
2948 | //dolibarr_install_syslog("step2: request: " . $buffer); |
||
2949 | $resql = $db->query($buffer, 1); |
||
2950 | if ($resql) { |
||
2951 | //$db->free($resql); // Not required as request we launch here does not return memory needs. |
||
2952 | } else { |
||
2953 | if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { |
||
2954 | //print "<tr><td>Insertion ligne : $buffer</td><td>"; |
||
2955 | } else { |
||
2956 | $ok = 0; |
||
2957 | $okallfile = 0; |
||
2958 | print '<span class="error">' . $langs->trans("ErrorSQL") . " : " . $db->lasterrno() . " - " . $db->lastqueryerror() . " - " . $db->lasterror() . "</span><br>"; |
||
2959 | } |
||
2960 | } |
||
2961 | } |
||
2962 | |||
2963 | if ($okallfile) { |
||
2964 | $db->commit(); |
||
2965 | } else { |
||
2966 | $db->rollback(); |
||
2967 | } |
||
2968 | } |
||
2969 | } |
||
2970 | |||
2971 | print "<tr><td>" . $langs->trans("ReferenceDataLoading") . "</td>"; |
||
2972 | if ($ok) { |
||
2973 | print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>'; |
||
2974 | } else { |
||
2975 | print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>'; |
||
2976 | $ok = 1; // Data loading are not blocking errors |
||
2977 | } |
||
2978 | } |
||
2979 | print '</table>'; |
||
2980 | } else { |
||
2981 | print 'Parameter action=set not defined'; |
||
2982 | } |
||
2983 | |||
2984 | |||
2985 | $ret = 0; |
||
2986 | if (!$ok && isset($argv[1])) { |
||
2987 | $ret = 1; |
||
2988 | } |
||
2989 | dolibarr_install_syslog("Exit " . $ret); |
||
2990 | |||
2991 | dolibarr_install_syslog("- step2: end"); |
||
2992 | |||
2993 | |||
2994 | // Force here a value we need after because master.inc.php is not loaded into step2. |
||
2995 | // This code must be similar with the one into main.inc.php |
||
2996 | |||
2997 | $conf->file->instance_unique_id = (empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id); // Unique id of instance |
||
2998 | |||
2999 | $hash_unique_id = dol_hash('dolibarr' . $conf->file->instance_unique_id, 'sha256'); // Note: if the global salt changes, this hash changes too so ping may be counted twice. We don't mind. It is for statistics purpose only. |
||
3000 | |||
3001 | $out = '<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"' . ((getDolGlobalString('MAIN_FIRST_PING_OK_ID') == 'disabled') ? '' : ' value="checked" checked="true"') . '> '; |
||
3002 | $out .= '<label for="dolibarrpingno">' . $langs->trans("MakeAnonymousPing") . '</label>'; |
||
3003 | |||
3004 | $out .= '<!-- Add js script to manage the uncheck of option to not send the ping -->'; |
||
3005 | $out .= '<script type="text/javascript">'; |
||
3006 | $out .= 'jQuery(document).ready(function(){'; |
||
3007 | $out .= ' document.cookie = "DOLINSTALLNOPING_' . $hash_unique_id . '=0; path=/"' . "\n"; |
||
3008 | $out .= ' jQuery("#dolibarrpingno").click(function() {'; |
||
3009 | $out .= ' if (! $(this).is(\':checked\')) {'; |
||
3010 | $out .= ' console.log("We uncheck anonymous ping");'; |
||
3011 | $out .= ' document.cookie = "DOLINSTALLNOPING_' . $hash_unique_id . '=1; path=/"' . "\n"; |
||
3012 | $out .= ' } else {' . "\n"; |
||
3013 | $out .= ' console.log("We check anonymous ping");'; |
||
3014 | $out .= ' document.cookie = "DOLINSTALLNOPING_' . $hash_unique_id . '=0; path=/"' . "\n"; |
||
3015 | $out .= ' }' . "\n"; |
||
3016 | $out .= ' });'; |
||
3017 | $out .= '});'; |
||
3018 | $out .= '</script>'; |
||
3019 | |||
3020 | print $out; |
||
3021 | |||
3022 | pFooter($ok ? 0 : 1, $setuplang); |
||
3023 | |||
3024 | if (isset($db) && is_object($db)) { |
||
3025 | $db->close(); |
||
3026 | } |
||
3027 | |||
3028 | // Return code if ran from command line |
||
3029 | if ($ret) { |
||
3030 | exit($ret); |
||
3031 | } |
||
3032 | } |
||
3033 | |||
3034 | public function step4() |
||
3140 | } |
||
3141 | } |
||
3142 | |||
3143 | public function step5() |
||
3144 | { |
||
3659 | } |
||
3660 | } |
||
3663 |