1- <!-- NetAlertX CSS -->
2- <link rel="stylesheet" href="css/app.css">
3-
41<?php
52
63require_once $ _SERVER ['DOCUMENT_ROOT ' ].'/php/server/db.php ' ;
2118
2219/* =====================================================
2320 LDAP Configuration
24- $configLines is already loaded by security.php
21+ $configLines and $api_token are already loaded by security.php
2522===================================================== */
2623
27- /**
28- * Read LDAP_enabled from environment or app.conf.
29- * Returns true only when the value is literally "true" (case-insensitive) or "1".
30- */
31- $ ldap_enabled = false ;
32- $ env_ldap = getenv ('LDAP_ENABLED ' );
33- if ($ env_ldap === false ) $ env_ldap = getenv ('LDAP_enabled ' );
34-
35- if ($ env_ldap !== false && $ env_ldap !== '' ) {
36- $ ldap_enabled = strtolower (trim ($ env_ldap )) === 'true ' || trim ($ env_ldap ) === '1 ' ;
37- } else {
38- $ ldap_enabled_line = getConfigLine ('/^LDAP_enabled.*=/ ' , $ configLines );
39- if ($ ldap_enabled_line !== null && isset ($ ldap_enabled_line [1 ])) {
40- $ ldap_enabled_value = strtolower (trim ($ ldap_enabled_line [1 ]));
41- $ ldap_enabled = $ ldap_enabled_value === 'true ' || $ ldap_enabled_value === '1 ' ;
42- }
43- }
24+ // Config file is the single source of truth (Python backend resolves env vars at startup)
25+ $ ldap_enabled = strtolower (trim (getConfigLine ('/^LDAP_enabled\s*=/ ' , $ configLines )[1 ] ?? 'false ' )) === 'true ' ;
4426
4527/**
4628 * Derive the Python API port from the GRAPHQL_PORT setting in app.conf.
5739
5840$ ldap_login_url = "http://127.0.0.1: {$ graphql_port }/api/auth/login " ;
5941
60- function get_api_token_from_config (array $ configLines ): string {
61- $ token_line = getConfigLine ('/^API_TOKEN.*=/ ' , $ configLines );
62- if ($ token_line === null || !isset ($ token_line [1 ])) {
63- return '' ;
64- }
65-
66- return trim ($ token_line [1 ], " \t\n\r\0\x0B\"' " );
67- }
68-
6942/* =====================================================
7043 Helper Functions
7144===================================================== */
@@ -136,27 +109,22 @@ function is_authenticated(): bool {
136109function login_user (): void {
137110 global $ nax_Password , $ api_token , $ configLines ;
138111
139- $ resolved_api_token = !empty ($ api_token )
140- ? $ api_token
141- : get_api_token_from_config ($ configLines );
142-
143- if (empty ($ resolved_api_token )) {
144- throw new RuntimeException ('API_TOKEN is not configured ' );
145- }
146-
147112 $ _SESSION ['login ' ] = 1 ;
148113 session_regenerate_id (true );
149114 $ _SESSION ['csrf_token ' ] = bin2hex (random_bytes (32 ));
150115
151- // Set remember-me cookie with HMAC (not raw password hash)
152- $ cookie_value = hash_hmac ('sha256 ' , $ nax_Password , $ resolved_api_token );
153- setcookie (COOKIE_SAVE_LOGIN_NAME , $ cookie_value , [
154- 'expires ' => time () + 3600 * 24 * 7 ,
155- 'path ' => '/ ' ,
156- 'httponly ' => true ,
157- 'secure ' => !empty ($ _SERVER ['HTTPS ' ]),
158- 'samesite ' => 'Strict ' ,
159- ]);
116+ // Set remember-me cookie with HMAC when API_TOKEN is available.
117+ // On first boot the token may not exist yet — skip the cookie gracefully.
118+ if (!empty ($ api_token )) {
119+ $ cookie_value = hash_hmac ('sha256 ' , $ nax_Password , $ api_token );
120+ setcookie (COOKIE_SAVE_LOGIN_NAME , $ cookie_value , [
121+ 'expires ' => time () + 3600 * 24 * 7 ,
122+ 'path ' => '/ ' ,
123+ 'httponly ' => true ,
124+ 'secure ' => !empty ($ _SERVER ['HTTPS ' ]),
125+ 'samesite ' => 'Strict ' ,
126+ ]);
127+ }
160128}
161129
162130
@@ -193,11 +161,7 @@ function logout_user(): void {
193161 if ($ ldap_enabled ) {
194162 // LDAP path: delegate credential validation to the Python API.
195163 // The API token is required so only server-side callers can reach the endpoint.
196- $ resolved_api_token = !empty ($ api_token )
197- ? $ api_token
198- : get_api_token_from_config ($ configLines );
199-
200- if (empty ($ resolved_api_token )) {
164+ if (empty ($ api_token )) {
201165 throw new RuntimeException ('API_TOKEN is not configured ' );
202166 }
203167
@@ -209,7 +173,7 @@ function logout_user(): void {
209173 'http ' => [
210174 'method ' => 'POST ' ,
211175 'header ' => "Content-Type: application/json \r\n"
212- . "Authorization: Bearer " . $ resolved_api_token . "\r\n"
176+ . "Authorization: Bearer " . $ api_token . "\r\n"
213177 . "X-Forwarded-For: " . ($ _SERVER ['REMOTE_ADDR ' ] ?? '127.0.0.1 ' ) . "\r\n" ,
214178 'content ' => $ ldap_payload ,
215179 'timeout ' => 5 ,
@@ -290,6 +254,9 @@ function logout_user(): void {
290254 <!-- Favicon -->
291255 <link id="favicon" rel="icon" type="image/x-icon" href="img/NetAlertX_logo.png">
292256 <link rel="stylesheet" href="/css/offline-font.css">
257+
258+ <!-- NetAlertX CSS -->
259+ <link rel="stylesheet" href="css/app.css">
293260</head>
294261<body class="hold-transition login-page col-sm-12 col-sx-12">
295262<div class="login-box login-custom">
0 commit comments