1 | <?php |
||
2 | |||
3 | /* Copyright (C) 2004-2005 Rodolphe Quiedeville <[email protected]> |
||
4 | * Copyright (C) 2004-2015 Laurent Destailleur <[email protected]> |
||
5 | * Copyright (C) 2005 Marc Barilley / Ocebo <[email protected]> |
||
6 | * Copyright (C) 2005-2012 Regis Houssin <[email protected]> |
||
7 | * Copyright (C) 2013-2014 Juanjo Menent <[email protected]> |
||
8 | * Copyright (C) 2014 Marcos García <[email protected]> |
||
9 | * Copyright (C) 2015-2016 Raphaël Doursenaud <[email protected]> |
||
10 | * Copyright (C) 2024 Rafael San José <[email protected]> |
||
11 | * |
||
12 | * This program is free software; you can redistribute it and/or modify |
||
13 | * it under the terms of the GNU General Public License as published by |
||
14 | * the Free Software Foundation; either version 3 of the License, or |
||
15 | * (at your option) any later version. |
||
16 | * |
||
17 | * This program is distributed in the hope that it will be useful, |
||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
20 | * GNU General Public License for more details. |
||
21 | * |
||
22 | * You should have received a copy of the GNU General Public License |
||
23 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
24 | */ |
||
25 | |||
26 | use Dolibarr\Lib\Version; |
||
27 | |||
28 | /** |
||
29 | * \file htdocs/install/check.php |
||
30 | * \ingroup install |
||
31 | * \brief Test if file conf can be modified and if does not exists, test if install process can create it |
||
32 | */ |
||
33 | |||
34 | define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1); |
||
35 | |||
36 | include_once constant('DOL_DOCUMENT_ROOT') . '/install/inc.php'; |
||
37 | |||
38 | global $langs; |
||
39 | |||
40 | $err = 0; |
||
41 | $allowinstall = 0; |
||
42 | $allowupgrade = false; |
||
43 | $checksok = 1; |
||
44 | |||
45 | $setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang(); |
||
46 | $langs->setDefaultLang($setuplang); |
||
47 | |||
48 | $langs->load("install"); |
||
49 | |||
50 | // Now we load forced/pre-set values from install.forced.php file. |
||
51 | $useforcedwizard = false; |
||
52 | $forcedfile = "./install.forced.php"; |
||
53 | if ($conffile == "/etc/dolibarr/conf.php") { |
||
54 | $forcedfile = "/etc/dolibarr/install.forced.php"; |
||
55 | } |
||
56 | if (@file_exists($forcedfile)) { |
||
57 | $useforcedwizard = true; |
||
58 | include_once $forcedfile; |
||
59 | } |
||
60 | |||
61 | dolibarr_install_syslog("- check: Dolibarr install/upgrade process started"); |
||
62 | |||
63 | /* |
||
64 | * View |
||
65 | */ |
||
66 | |||
67 | pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links. |
||
68 | |||
69 | |||
70 | //print "<br>\n"; |
||
71 | //print $langs->trans("InstallEasy")."<br><br>\n"; |
||
72 | |||
73 | print '<h3><img class="valignmiddle inline-block paddingright" src="' . constant('DOL_URL_ROOT') . '/theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> '; |
||
74 | print '<span class="inline-block">' . $langs->trans("MiscellaneousChecks") . "</span></h3>\n"; |
||
75 | |||
76 | // Check browser |
||
77 | $useragent = $_SERVER['HTTP_USER_AGENT']; |
||
78 | if (!empty($useragent)) { |
||
79 | $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]); |
||
80 | $browserversion = $tmp['browserversion']; |
||
81 | $browsername = $tmp['browsername']; |
||
82 | if ($browsername == 'ie' && $browserversion < 7) { |
||
83 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("WarningBrowserTooOld") . "<br>\n"; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | // Check PHP version min |
||
88 | $arrayphpminversionerror = array(7, 0, 0); |
||
89 | $arrayphpminversionwarning = array(7, 1, 0); |
||
90 | if (Version::compare(Version::arrayPhp(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower) |
||
91 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPVersionTooLow", Version::toString($arrayphpminversionerror)); |
||
92 | $checksok = 0; // 0=error, 1=warning |
||
93 | } elseif (Version::compare(Version::arrayPhp(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower) |
||
94 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPVersionTooLow", Version::toString($arrayphpminversionwarning)); |
||
95 | $checksok = 1; // 0=error, 1=warning |
||
96 | } else { |
||
97 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPVersion") . " " . Version::toString(Version::arrayPhp()); |
||
98 | } |
||
99 | if (empty($force_install_nophpinfo)) { |
||
100 | print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">' . $langs->trans("MoreInformation") . '</a>)'; |
||
101 | } |
||
102 | print "<br>\n"; |
||
103 | |||
104 | // Check PHP version max |
||
105 | $arrayphpmaxversionwarning = array(8, 2, 0); |
||
106 | if (Version::compare(Version::arrayPhp(), $arrayphpmaxversionwarning) > 0 && Version::compare(Version::arrayPhp(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher) |
||
107 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPVersionTooHigh", Version::toString($arrayphpmaxversionwarning)); |
||
108 | $checksok = 1; // 0=error, 1=warning |
||
109 | print "<br>\n"; |
||
110 | } |
||
111 | |||
112 | |||
113 | // Check PHP support for $_GET and $_POST |
||
114 | if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here |
||
115 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> ' . $langs->trans("PHPSupportPOSTGETKo"); |
||
116 | print ' (<a href="' . dol_escape_htmltag($_SERVER["PHP_SELF"]) . '?testget=ok">' . $langs->trans("Recheck") . '</a>)'; |
||
117 | print "<br>\n"; |
||
118 | $checksok = 0; |
||
119 | } else { |
||
120 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupportPOSTGETOk") . "<br>\n"; |
||
121 | } |
||
122 | |||
123 | |||
124 | // Check if session_id is enabled |
||
125 | if (!function_exists("session_id")) { |
||
126 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupportSessions") . "<br>\n"; |
||
127 | $checksok = 0; |
||
128 | } else { |
||
129 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupportSessions") . "<br>\n"; |
||
130 | } |
||
131 | |||
132 | |||
133 | // Check for mbstring extension |
||
134 | if (!extension_loaded("mbstring")) { |
||
135 | $langs->load("errors"); |
||
136 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "MBString") . "<br>\n"; |
||
137 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
138 | } else { |
||
139 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "MBString") . "<br>\n"; |
||
140 | } |
||
141 | |||
142 | // Check for json extension |
||
143 | if (!extension_loaded("json")) { |
||
144 | $langs->load("errors"); |
||
145 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "JSON") . "<br>\n"; |
||
146 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
147 | } else { |
||
148 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "JSON") . "<br>\n"; |
||
149 | } |
||
150 | |||
151 | // Check if GD is supported (we need GD for image conversion) |
||
152 | if (!function_exists("imagecreate")) { |
||
153 | $langs->load("errors"); |
||
154 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "GD") . "<br>\n"; |
||
155 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
156 | } else { |
||
157 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "GD") . "<br>\n"; |
||
158 | } |
||
159 | |||
160 | // Check if Curl is supported |
||
161 | if (!function_exists("curl_init")) { |
||
162 | $langs->load("errors"); |
||
163 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Curl") . "<br>\n"; |
||
164 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
165 | } else { |
||
166 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Curl") . "<br>\n"; |
||
167 | } |
||
168 | |||
169 | // Check if PHP calendar extension is available |
||
170 | if (!function_exists("easter_date")) { |
||
171 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Calendar") . "<br>\n"; |
||
172 | } else { |
||
173 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Calendar") . "<br>\n"; |
||
174 | } |
||
175 | |||
176 | // Check if Xml is supported |
||
177 | if (!function_exists("simplexml_load_string")) { |
||
178 | $langs->load("errors"); |
||
179 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Xml") . "<br>\n"; |
||
180 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
181 | } else { |
||
182 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Xml") . "<br>\n"; |
||
183 | } |
||
184 | |||
185 | // Check if UTF8 is supported |
||
186 | if (!function_exists("utf8_encode")) { |
||
187 | $langs->load("errors"); |
||
188 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "UTF8") . "<br>\n"; |
||
189 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
190 | } else { |
||
191 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "UTF8") . "<br>\n"; |
||
192 | } |
||
193 | |||
194 | // Check if intl methods are supported if install is not from DoliWamp. TODO Why ? |
||
195 | if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') { |
||
196 | if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) { |
||
197 | $langs->load("errors"); |
||
198 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "Intl") . "<br>\n"; |
||
199 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
200 | } else { |
||
201 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "Intl") . "<br>\n"; |
||
202 | } |
||
203 | } |
||
204 | |||
205 | // Check if Imap is supported |
||
206 | if (PHP_VERSION_ID <= 80300) { |
||
207 | if (!function_exists("imap_open")) { |
||
208 | $langs->load("errors"); |
||
209 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "IMAP") . "<br>\n"; |
||
210 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
211 | } else { |
||
212 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "IMAP") . "<br>\n"; |
||
213 | } |
||
214 | } |
||
215 | |||
216 | // Check if Zip is supported |
||
217 | if (!class_exists('ZipArchive')) { |
||
218 | $langs->load("errors"); |
||
219 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ErrorPHPDoesNotSupport", "ZIP") . "<br>\n"; |
||
220 | // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) |
||
221 | } else { |
||
222 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPSupport", "ZIP") . "<br>\n"; |
||
223 | } |
||
224 | |||
225 | // Check memory |
||
226 | $memrequiredorig = '64M'; |
||
227 | $memrequired = 64 * 1024 * 1024; |
||
228 | $memmaxorig = @ini_get("memory_limit"); |
||
229 | $memmax = @ini_get("memory_limit"); |
||
230 | if ($memmaxorig != '') { |
||
231 | preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg); |
||
232 | if ($reg[2]) { |
||
233 | if (strtoupper($reg[2]) == 'G') { |
||
234 | $memmax = $reg[1] * 1024 * 1024 * 1024; |
||
235 | } |
||
236 | if (strtoupper($reg[2]) == 'M') { |
||
237 | $memmax = $reg[1] * 1024 * 1024; |
||
238 | } |
||
239 | if (strtoupper($reg[2]) == 'K') { |
||
240 | $memmax = $reg[1] * 1024; |
||
241 | } |
||
242 | } |
||
243 | if ($memmax >= $memrequired || $memmax == -1) { |
||
244 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ' . $langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig) . "<br>\n"; |
||
245 | } else { |
||
246 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> ' . $langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig) . "<br>\n"; |
||
247 | } |
||
248 | } |
||
249 | |||
250 | // If that config file is present and filled |
||
251 | clearstatcache(); |
||
252 | if (is_readable($conffile) && filesize($conffile) > 8) { |
||
253 | dolibarr_install_syslog("check: conf file '" . $conffile . "' already defined"); |
||
254 | $confexists = 1; |
||
255 | include_once $conffile; |
||
256 | |||
257 | $databaseok = 1; |
||
258 | if ($databaseok) { |
||
259 | // Already installed for all parts (config and database). We can propose upgrade. |
||
260 | $allowupgrade = true; |
||
261 | } else { |
||
262 | $allowupgrade = false; |
||
263 | } |
||
264 | } else { |
||
265 | // If not, we create it |
||
266 | dolibarr_install_syslog("check: we try to create conf file '" . $conffile . "'"); |
||
267 | $confexists = 0; |
||
268 | |||
269 | // First we try by copying example |
||
270 | if (@copy($conffile . ".example", $conffile)) { |
||
271 | // Success |
||
272 | dolibarr_install_syslog("check: successfully copied file " . $conffile . ".example into " . $conffile); |
||
273 | } else { |
||
274 | // If failed, we try to create an empty file |
||
275 | dolibarr_install_syslog("check: failed to copy file " . $conffile . ".example into " . $conffile . ". We try to create it.", LOG_WARNING); |
||
276 | |||
277 | $fp = @fopen($conffile, "w"); |
||
278 | if ($fp) { |
||
279 | @fwrite($fp, '<?php'); |
||
0 ignored issues
–
show
|
|||
280 | @fwrite($fp, "\n"); |
||
281 | fclose($fp); |
||
282 | } else { |
||
283 | dolibarr_install_syslog("check: failed to create a new file " . $conffile . " into current dir " . getcwd() . ". Please check permissions.", LOG_ERR); |
||
284 | } |
||
285 | } |
||
286 | |||
287 | // First install: no upgrade necessary/required |
||
288 | $allowupgrade = false; |
||
289 | } |
||
290 | |||
291 | |||
292 | // File is missing and cannot be created |
||
293 | if (!file_exists($conffile)) { |
||
294 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Error" class="valignmiddle"> ' . $langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow); |
||
295 | print '<br><br><div class="error">'; |
||
296 | print $langs->trans("YouMustCreateWithPermission", $conffiletoshow); |
||
297 | print '</div><br><br>' . "\n"; |
||
298 | |||
299 | print '<span class="opacitymedium">' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</span>'; |
||
300 | $err++; |
||
301 | } else { |
||
302 | if (dol_is_dir($conffile)) { |
||
303 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/error.png" alt="Warning"> ' . $langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow); |
||
304 | |||
305 | $allowinstall = 0; |
||
306 | } elseif (!is_writable($conffile)) { |
||
307 | // File exists but cannot be modified |
||
308 | if ($confexists) { |
||
309 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileExists", $conffiletoshow); |
||
310 | } else { |
||
311 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileCouldBeCreated", $conffiletoshow); |
||
312 | } |
||
313 | print "<br>"; |
||
314 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Warning"> ' . $langs->trans("ConfFileIsNotWritable", $conffiletoshow); |
||
315 | print "<br>\n"; |
||
316 | |||
317 | $allowinstall = 0; |
||
318 | } else { |
||
319 | // File exists and can be modified |
||
320 | if ($confexists) { |
||
321 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileExists", $conffiletoshow); |
||
322 | } else { |
||
323 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileCouldBeCreated", $conffiletoshow); |
||
324 | } |
||
325 | print "<br>"; |
||
326 | print '<img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok"> ' . $langs->trans("ConfFileIsWritable", $conffiletoshow); |
||
327 | print "<br>\n"; |
||
328 | |||
329 | $allowinstall = 1; |
||
330 | } |
||
331 | print "<br>\n"; |
||
332 | |||
333 | // Requirements met/all ok: display the next step button |
||
334 | if ($checksok) { |
||
335 | $ok = 0; |
||
336 | |||
337 | // Try to create db connection |
||
338 | if (file_exists($conffile)) { |
||
339 | include_once $conffile; |
||
340 | if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) { |
||
341 | if (!file_exists($dolibarr_main_document_root . "/core/lib/admin.lib.php")) { |
||
342 | 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"; |
||
343 | 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); |
||
344 | } else { |
||
345 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/admin.lib.php'; |
||
346 | |||
347 | // If password is encoded, we decode it |
||
348 | if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) { |
||
349 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/security.lib.php'; |
||
350 | if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) { |
||
351 | $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 |
||
352 | $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); |
||
353 | } else { |
||
354 | $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); |
||
355 | } |
||
356 | } |
||
357 | |||
358 | // $conf already created in inc.php |
||
359 | $conf->db->type = $dolibarr_main_db_type; |
||
360 | $conf->db->host = $dolibarr_main_db_host; |
||
361 | $conf->db->port = $dolibarr_main_db_port; |
||
362 | $conf->db->name = $dolibarr_main_db_name; |
||
363 | $conf->db->user = $dolibarr_main_db_user; |
||
364 | $conf->db->pass = $dolibarr_main_db_pass; |
||
365 | $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int)$conf->db->port); |
||
366 | if ($db->connected && $db->database_selected) { |
||
367 | $ok = true; |
||
368 | } |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | |||
373 | // If database access is available, we set more variables |
||
374 | if ($ok) { |
||
375 | if (empty($dolibarr_main_db_encryption)) { |
||
376 | $dolibarr_main_db_encryption = 0; |
||
377 | } |
||
378 | $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; |
||
379 | if (empty($dolibarr_main_db_cryptkey)) { |
||
380 | $dolibarr_main_db_cryptkey = ''; |
||
381 | } |
||
382 | $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; |
||
383 | |||
384 | $conf->setValues($db); |
||
385 | // Reset forced setup after the setValues |
||
386 | if (defined('SYSLOG_FILE')) { |
||
387 | $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); |
||
388 | } |
||
389 | $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; |
||
390 | |||
391 | // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE |
||
392 | // Version to install is DOL_VERSION |
||
393 | $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 : '')); |
||
394 | $dolibarrversiontoinstallarray = Version::toArray(); |
||
395 | } |
||
396 | |||
397 | // Show title |
||
398 | if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) { |
||
399 | 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> - '; |
||
400 | print $langs->trans("VersionProgram") . ': <b><span class="ok">' . DOL_VERSION . '</span></b>'; |
||
401 | //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired")); |
||
402 | print '<br>'; |
||
403 | print '<br>'; |
||
404 | } else { |
||
405 | print "<br>\n"; |
||
406 | } |
||
407 | |||
408 | //print $langs->trans("InstallEasy")." "; |
||
409 | print '<h3><span class="soustitre">' . $langs->trans("ChooseYourSetupMode") . '</span></h3>'; |
||
410 | |||
411 | $foundrecommandedchoice = 0; |
||
412 | |||
413 | $available_choices = array(); |
||
414 | $notavailable_choices = array(); |
||
415 | |||
416 | if (empty($dolibarr_main_db_host)) { // This means install process was not run |
||
417 | $foundrecommandedchoice = 1; // To show only once |
||
418 | } |
||
419 | |||
420 | // Show line of first install choice |
||
421 | $choice = '<tr class="trlineforchoice' . ($foundrecommandedchoice ? ' choiceselected' : '') . '">' . "\n"; |
||
422 | $choice .= '<td class="nowrap center"><b>' . $langs->trans("FreshInstall") . '</b>'; |
||
423 | $choice .= '</td>'; |
||
424 | $choice .= '<td class="listofchoicesdesc">'; |
||
425 | $choice .= $langs->trans("FreshInstallDesc"); |
||
426 | if (empty($dolibarr_main_db_host)) { // This means install process was not run |
||
427 | $choice .= '<br>'; |
||
428 | //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); |
||
429 | $choice .= '<div class="center"><div class="ok suggestedchoice">' . $langs->trans("InstallChoiceSuggested") . '</div></div>'; |
||
430 | // <img src="' . constant('DOL_URL_ROOT') . '/theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '; |
||
431 | } |
||
432 | |||
433 | $choice .= '</td>'; |
||
434 | $choice .= '<td class="center">'; |
||
435 | if ($allowinstall) { |
||
436 | $choice .= '<a class="button" href="fileconf.php?selectlang=' . $setuplang . '">' . $langs->trans("Start") . '</a>'; |
||
437 | } else { |
||
438 | $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '') . $langs->trans("InstallNotAllowed") . ($foundrecommandedchoice ? '</span>' : ''); |
||
439 | } |
||
440 | $choice .= '</td>' . "\n"; |
||
441 | $choice .= '</tr>' . "\n"; |
||
442 | |||
443 | $positionkey = ($foundrecommandedchoice ? 999 : 0); |
||
444 | if ($allowinstall) { |
||
445 | $available_choices[$positionkey] = $choice; |
||
446 | } else { |
||
447 | $notavailable_choices[$positionkey] = $choice; |
||
448 | } |
||
449 | |||
450 | // Show upgrade lines |
||
451 | $allowupgrade = true; |
||
452 | if (empty($dolibarr_main_db_host)) { // This means install process was not run |
||
453 | $allowupgrade = false; |
||
454 | } |
||
455 | if (getDolGlobalInt("MAIN_NOT_INSTALLED")) { |
||
456 | $allowupgrade = false; |
||
457 | } |
||
458 | if (GETPOST('allowupgrade')) { |
||
459 | $allowupgrade = true; |
||
460 | } |
||
461 | |||
462 | $dir = DOL_DOCUMENT_ROOT . "/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver |
||
463 | dolibarr_install_syslog("Scan sql files for migration files in " . $dir); |
||
464 | |||
465 | // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration |
||
466 | $migrationscript = array(); |
||
467 | $handle = opendir($dir); |
||
468 | if (is_resource($handle)) { |
||
469 | $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION); |
||
470 | while (($file = readdir($handle)) !== false) { |
||
471 | $reg = array(); |
||
472 | if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) { |
||
473 | //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2])); |
||
474 | if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) { |
||
475 | $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]); |
||
476 | } |
||
477 | } |
||
478 | } |
||
479 | $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1); |
||
480 | } else { |
||
481 | print '<div class="error">' . $langs->trans("ErrorCanNotReadDir", $dir) . '</div>'; |
||
482 | } |
||
483 | |||
484 | $count = 0; |
||
485 | foreach ($migrationscript as $migarray) { |
||
486 | $choice = ''; |
||
487 | |||
488 | $count++; |
||
489 | $recommended_choice = false; |
||
490 | $version = DOL_VERSION; |
||
491 | $versionfrom = $migarray['from']; |
||
492 | $versionto = $migarray['to']; |
||
493 | $versionarray = preg_split('/[.-]/', $version); |
||
494 | $dolibarrversionfromarray = preg_split('/[.-]/', $versionfrom); |
||
495 | $dolibarrversiontoarray = preg_split('/[.-]/', $versionto); |
||
496 | // Define string newversionxxx that are used for text to show |
||
497 | $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom); |
||
498 | $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto); |
||
499 | $newversionfrombis = ''; |
||
500 | if (Version::compare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1 |
||
501 | $newversionfrombis = ' ' . $langs->trans("or") . ' ' . $versionto; |
||
502 | } |
||
503 | |||
504 | if ($ok) { |
||
505 | if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known |
||
506 | // Now we check if this is the first qualified choice |
||
507 | if ( |
||
508 | $allowupgrade && empty($foundrecommandedchoice) && |
||
509 | (Version::compare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || Version::compare($dolibarrversiontoarray, $versionarray) < -2) |
||
510 | ) { |
||
511 | $foundrecommandedchoice = 1; // To show only once |
||
512 | $recommended_choice = true; |
||
513 | } |
||
514 | } else { |
||
515 | // We cannot recommend a choice. |
||
516 | // A version of install may be known, but we need last upgrade. |
||
517 | } |
||
518 | } |
||
519 | |||
520 | $choice .= "\n" . '<!-- choice ' . $count . ' -->' . "\n"; |
||
521 | $choice .= '<tr' . ($recommended_choice ? ' class="choiceselected"' : '') . '>'; |
||
522 | $choice .= '<td class="nowrap center"><b>' . $langs->trans("Upgrade") . '<br>' . $newversionfrom . $newversionfrombis . ' -> ' . $newversionto . '</b></td>'; |
||
523 | $choice .= '<td class="listofchoicesdesc">'; |
||
524 | $choice .= $langs->trans("UpgradeDesc"); |
||
525 | |||
526 | if ($recommended_choice) { |
||
527 | $choice .= '<br>'; |
||
528 | //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); |
||
529 | $choice .= '<div class="center">'; |
||
530 | $choice .= '<div class="ok suggestedchoice">' . $langs->trans("InstallChoiceSuggested") . '</div>'; |
||
531 | if ($count < count($migarray)) { // There are other choices after |
||
532 | print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION); |
||
533 | } |
||
534 | $choice .= '</div>'; |
||
535 | } |
||
536 | |||
537 | $choice .= '</td>'; |
||
538 | $choice .= '<td class="center">'; |
||
539 | if ($allowupgrade) { |
||
540 | $disabled = false; |
||
541 | if ($foundrecommandedchoice == 2) { |
||
542 | $disabled = true; |
||
543 | } |
||
544 | if ($foundrecommandedchoice == 1) { |
||
545 | $foundrecommandedchoice = 2; |
||
546 | } |
||
547 | if ($disabled) { |
||
548 | $choice .= '<span class="opacitymedium">' . $langs->trans("NotYetAvailable") . '</span>'; |
||
549 | } else { |
||
550 | $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade' . ($count < count($migrationscript) ? '_' . $versionto : '') . '&selectlang=' . $setuplang . '&versionfrom=' . $versionfrom . '&versionto=' . $versionto . '">' . $langs->trans("Start") . '</a>'; |
||
551 | } |
||
552 | } else { |
||
553 | $choice .= $langs->trans("NotAvailable"); |
||
554 | } |
||
555 | $choice .= '</td>'; |
||
556 | $choice .= '</tr>' . "\n"; |
||
557 | |||
558 | if ($allowupgrade) { |
||
559 | $available_choices[$count] = $choice; |
||
560 | } else { |
||
561 | $notavailable_choices[$count] = $choice; |
||
562 | } |
||
563 | } |
||
564 | |||
565 | // If there is no choice at all, we show all of them. |
||
566 | if (empty($available_choices)) { |
||
567 | $available_choices = $notavailable_choices; |
||
568 | $notavailable_choices = array(); |
||
569 | } |
||
570 | |||
571 | // Array of install choices |
||
572 | krsort($available_choices, SORT_NATURAL); |
||
573 | print"\n"; |
||
574 | print '<table width="100%" class="listofchoices">'; |
||
575 | foreach ($available_choices as $choice) { |
||
576 | print $choice; |
||
577 | } |
||
578 | |||
579 | print '</table>' . "\n"; |
||
580 | |||
581 | if (count($notavailable_choices)) { |
||
582 | print '<br><div id="AShowChoices" style="opacity: 0.5">'; |
||
583 | print '> ' . $langs->trans('ShowNotAvailableOptions') . '...'; |
||
584 | print '</div>'; |
||
585 | |||
586 | print '<div id="navail_choices" style="display:none">'; |
||
587 | print "<br>\n"; |
||
588 | print '<table width="100%" class="listofchoices">'; |
||
589 | foreach ($notavailable_choices as $choice) { |
||
590 | print $choice; |
||
591 | } |
||
592 | |||
593 | print '</table>' . "\n"; |
||
594 | print '</div>'; |
||
595 | } |
||
596 | } |
||
597 | } |
||
598 | |||
599 | print '<script type="text/javascript"> |
||
600 | |||
601 | $("div#AShowChoices").click(function() { |
||
602 | |||
603 | $("div#navail_choices").toggle(); |
||
604 | |||
605 | if ($("div#navail_choices").css("display") == "none") { |
||
606 | $(this).text("> ' . $langs->trans('ShowNotAvailableOptions') . '..."); |
||
607 | } else { |
||
608 | $(this).text("' . $langs->trans('HideNotAvailableOptions') . '..."); |
||
609 | } |
||
610 | |||
611 | }); |
||
612 | |||
613 | /* |
||
614 | $(".runupgrade").click(function() { |
||
615 | return confirm("' . dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1) . '"); |
||
616 | }); |
||
617 | */ |
||
618 | |||
619 | </script>'; |
||
620 | |||
621 | dolibarr_install_syslog("- check: end"); |
||
622 | pFooter(1); // Never display next button |
||
623 |
If you suppress an error, we recommend checking for the error condition explicitly: