$sql, 'params' => $params, ]; $GLOBALS['auth_integration_events'][] = ['database', $sql]; return true; } function db_table_exists($table) { return $table == 'user_auth_cache'; } function get_guest_account() { return (int) read_config_option('guest_user'); } function get_client_addr() { return '192.0.2.10'; } function cacti_cookie_session_set($user, $realm, $secret) { $GLOBALS['auth_integration_cookie_calls'][] = ['set', $user, $realm, $secret]; } function cacti_cookie_session_logout() { $GLOBALS['auth_integration_cookie_calls'][] = ['logout']; $GLOBALS['auth_integration_events'][] = ['cookie', 'logout']; } function cacti_log(...$args) { } require_once $root . '/lib/auth.php'; $scenario = json_decode(stream_get_contents(STDIN), true); if (!is_array($scenario) || !isset($scenario['calls'])) { fwrite(STDERR, 'AuthCookieProbe: invalid scenario JSON on stdin'); exit(1); } $GLOBALS['auth_integration_config'] = $scenario['config'] ?? []; $GLOBALS['auth_integration_group_realms'] = $scenario['group_realms'] ?? 0; $GLOBALS['auth_integration_groups'] = $scenario['groups'] ?? []; $GLOBALS['auth_integration_users'] = $scenario['users'] ?? []; $GLOBALS['auth_integration_usernames'] = $scenario['usernames'] ?? []; $GLOBALS['auth_integration_cache'] = $scenario['cache'] ?? []; $results = []; foreach ($scenario['calls'] as $call) { $GLOBALS['auth_integration_realms'] = $call['realms'] ?? $scenario['realms'] ?? 0; $GLOBALS['auth_integration_executed'] = []; $GLOBALS['auth_integration_cookie_calls'] = []; $GLOBALS['auth_integration_events'] = []; $warnings = []; set_error_handler(function (int $severity, string $message) use (&$warnings) : bool { $warnings[] = [$severity, $message]; return true; }); try { if ($call['type'] === 'auth_cookie_user_currently_allowed') { $return = auth_cookie_user_currently_allowed($call['user']); } elseif ($call['type'] === 'check_auth_cookie' || $call['type'] === 'clear_auth_cookie') { if (array_key_exists('cookie', $call)) { $_COOKIE['cacti_remembers'] = $call['cookie']; } else { unset($_COOKIE['cacti_remembers']); } if ($call['type'] === 'check_auth_cookie') { $return = check_auth_cookie(); } else { clear_auth_cookie(); $return = null; } } elseif ($call['type'] === 'set_auth_cookie') { unset($_COOKIE['cacti_remembers']); set_auth_cookie($call['user']); $return = null; } else { fwrite(STDERR, 'AuthCookieProbe: unknown call type ' . $call['type']); exit(1); } } finally { restore_error_handler(); } $results[] = [ 'return' => $return, 'executed' => $GLOBALS['auth_integration_executed'], 'cookie_calls' => $GLOBALS['auth_integration_cookie_calls'], 'events' => $GLOBALS['auth_integration_events'], 'warnings' => $warnings, ]; } print json_encode(['results' => $results]);