0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php"; if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php"; if (!$res) die("Include of main fails"); require_once __DIR__.'/../class/bericht.class.php'; require_once __DIR__.'/../lib/bericht.lib.php'; // Same-Origin: PWA (/baustelle/) und API (/custom/bericht/api/) laufen auf derselben Domain. // Deshalb KEIN CORS mehr (Access-Control-Allow-Origin: * ist mit Cookies ohnehin unzulaessig). // Das HttpOnly-Cookie awl_sso wird per credentials:'same-origin' automatisch mitgeschickt. header('Content-Type: application/json; charset=utf-8'); function api_send($data, $code = 200) { http_response_code($code); echo json_encode($data, JSON_UNESCAPED_UNICODE); exit; } function api_fail($msg, $code = 400) { api_send(array('error' => $msg), $code); } function api_ok($data = array()) { api_send(array_merge(array('ok' => true), $data)); } function api_input() { $body = file_get_contents('php://input'); if (!$body) return $_POST; $json = json_decode($body, true); return is_array($json) ? $json : $_POST; } /** * Authentifiziert den Request über das zentrale SSO-Cookie awl_sso. * awlauth_require prüft Cookie-Signatur, same-origin-Herkunft (CSRF) und die * Berechtigung; bei Fehler beendet es selbst mit 401/403. Der zurückgegebene * User ist voll geladen (inkl. Rechte) — die granularen hasRight('bericht',...)- * Checks in den Endpoints bleiben dadurch unverändert gültig. */ function api_authenticate($db_param = null) { global $db, $user, $conf; if ($db_param) $db = $db_param; if (!dol_include_once('/awlauth/lib/awlauth.lib.php') || !function_exists('awlauth_require')) { api_fail('SSO-Modul (awlauth) nicht verfügbar', 500); } $user = awlauth_require('bericht', 'read'); // CSRF + 401/403 + exit inklusive return $user; }