$validate_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "Content-Type: application/xml" ], ]); $response = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($httpCode === 200) { $data = json_decode($response, true); if ( is_array($data) && isset($data['valid']) && $data['valid'] === true && isset($data['logged_in_user']) && is_array($data['logged_in_user']) ) { // Copy all returned user fields into the session foreach ($data['logged_in_user'] as $key => $value) { $_SESSION[$key] = $value; } } } else { // Token rejected by the SSO server — clear the stale cookie so the // browser stops sending it. Domain `.lupmis4luspa.org` covers all // subdomains (so SSO logout works from the PWA too). setcookie('sso_auth_token', '', time() - 3600, '/', '.lupmis4luspa.org'); } } // ──────────────────────────────────────────────────────────────────────────── // Build the payload exposed to the PWA as window.LUPMIS_SESSION // ──────────────────────────────────────────────────────────────────────────── $payload = []; if (isset($_SESSION['user_id'])) { $payload = [ 'user_id' => $_SESSION['user_id'] ?? null, 'ua_id' => $_SESSION['ua_id'] ?? null, 'username' => $_SESSION['username'] ?? null, 'title' => $_SESSION['title'] ?? null, 'full_name' => $_SESSION['full_name'] ?? null, 'email' => $_SESSION['email'] ?? null, 'user_type' => $_SESSION['user_type'] ?? null, 'phone' => $_SESSION['phone'] ?? null, 'ua_position' => $_SESSION['ua_position'] ?? null, 'region_id' => $_SESSION['region_id'] ?? null, 'district_id' => $_SESSION['district_id'] ?? null, ]; } // ──────────────────────────────────────────────────────────────────────────── // Read the built index.html and inject the session as a JS global // ──────────────────────────────────────────────────────────────────────────── $indexPath = __DIR__ . '/index.html'; $html = is_readable($indexPath) ? file_get_contents($indexPath) : '

LUPMIS2 PWA

index.html is missing from this deployment.

'; // Encode safely for inline "; // Insert right after the opening tag $html = preg_replace('/]*>/i', '$0' . "\n " . $inject, $html, 1); // ──────────────────────────────────────────────────────────────────────────── // Serve // ──────────────────────────────────────────────────────────────────────────── header('Content-Type: text/html; charset=utf-8'); // Don't let intermediaries cache an authenticated response — the next visit // might be a different user. Asset hashes still let static files be cached. header('Cache-Control: no-store, must-revalidate'); header('Pragma: no-cache'); echo $html;