Fix: master.inc.php im globalen Scope laden — behebt 500 beim Login [deploy]
All checks were successful
Deploy netdiag / deploy (push) Successful in 14s
All checks were successful
Deploy netdiag / deploy (push) Successful in 14s
netdiag_api_bootstrap() includete master.inc.php innerhalb der Funktion. Dadurch landeten $conf/$db/$langs/$user im Funktions-Scope und waren nach return weg — der erste DB-Zugriff (checkLoginPassEntity -> global $db) lief gegen null: Call to a member function query() on null. master.inc.php wird jetzt im File-Scope der Lib geladen, die Funktion macht nur noch CORS + OPTIONS-Preflight. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
44abdbbc95
commit
2989ec10ed
1 changed files with 41 additions and 30 deletions
|
|
@ -47,14 +47,14 @@ if (!defined('NOREQUIRESOC')) {
|
||||||
define('NOREQUIRESOC', '1');
|
define('NOREQUIRESOC', '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// ===================================================================
|
||||||
* Dolibarr-Umgebung laden (master.inc.php) und CORS-Header setzen.
|
// Dolibarr-Umgebung laden — MUSS im globalen Scope passieren.
|
||||||
*
|
// master.inc.php innerhalb einer Funktion zu includen würde $conf,
|
||||||
* @return void
|
// $db, $langs, $user ... in den Funktions-Scope legen; nach return
|
||||||
*/
|
// wären sie weg und jeder DB-Zugriff liefe gegen null -> HTTP 500.
|
||||||
function netdiag_api_bootstrap()
|
// Dieser Block läuft, sobald ein Endpunkt die Lib per require_once
|
||||||
{
|
// einbindet, also im File-Scope des Endpunkts = global.
|
||||||
// master.inc.php aus dem Webroot finden
|
// ===================================================================
|
||||||
$res = 0;
|
$res = 0;
|
||||||
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
||||||
$tmp2 = realpath(__FILE__);
|
$tmp2 = realpath(__FILE__);
|
||||||
|
|
@ -82,7 +82,18 @@ function netdiag_api_bootstrap()
|
||||||
echo json_encode(array('error' => 'Dolibarr environment not found'));
|
echo json_encode(array('error' => 'Dolibarr environment not found'));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
unset($res, $tmp, $tmp2, $i, $j);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CORS-Header setzen und Preflight (OPTIONS) sofort beantworten.
|
||||||
|
*
|
||||||
|
* Dolibarr selbst ist zu diesem Zeitpunkt bereits geladen (siehe Block
|
||||||
|
* oben, der beim require_once dieser Lib im globalen Scope läuft).
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function netdiag_api_bootstrap()
|
||||||
|
{
|
||||||
// CORS: Bearer-Token-Auth, daher Wildcard-Origin erlaubt (keine Cookies)
|
// CORS: Bearer-Token-Auth, daher Wildcard-Origin erlaubt (keine Cookies)
|
||||||
header('Access-Control-Allow-Origin: *');
|
header('Access-Control-Allow-Origin: *');
|
||||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue