$sql, 'params' => $params, ]; return true; } function db_table_exists($table) { return $table == 'user_auth_cache'; } function get_guest_account() { return (int) read_config_option('guest_user'); } require_once $root . '/lib/auth.php'; switch ($argv[1] ?? '') { case 'cookie-authorization': $GLOBALS['auth_integration_config'] = ['guest_user' => 0]; $GLOBALS['auth_integration_realms'] = 0; $GLOBALS['auth_integration_groups'] = []; $verdict = [ 'disabled' => auth_cookie_user_currently_allowed([ 'id' => 10, 'username' => 'disabled', 'enabled' => '', 'show_tree' => '', 'show_list' => '', 'show_preview' => '', ]), 'noaccess' => auth_cookie_user_currently_allowed([ 'id' => 11, 'username' => 'noaccess', 'enabled' => 'on', 'show_tree' => '', 'show_list' => '', 'show_preview' => '', ]), ]; $GLOBALS['auth_integration_realms'] = 1; $verdict['allowed'] = auth_cookie_user_currently_allowed([ 'id' => 12, 'username' => 'allowed', 'enabled' => 'on', 'show_tree' => '', 'show_list' => '', 'show_preview' => '', ]); break; case 'cookie-token-check': $GLOBALS['auth_integration_config'] = [ 'auth_cache_enabled' => 'on', 'guest_user' => 0, ]; $GLOBALS['auth_integration_realms'] = 1; $GLOBALS['auth_integration_groups'] = []; $GLOBALS['auth_integration_users'] = [ 42 => [ 'id' => 42, 'username' => 'disabled', 'realm' => 0, 'enabled' => '', 'show_tree' => '', 'show_list' => '', 'show_preview' => '', ], ]; $GLOBALS['auth_integration_cache'] = [ [ 'user_id' => 42, 'token' => hash('sha512', 'valid-token', false), ], ]; $GLOBALS['auth_integration_executed'] = []; $_COOKIE['cacti_remembers'] = '42,-1,forged-token'; $verdict = [ 'forged' => [ 'result' => check_auth_cookie(), 'executed' => $GLOBALS['auth_integration_executed'], ], ]; $GLOBALS['auth_integration_executed'] = []; $_COOKIE['cacti_remembers'] = '42,-1,valid-token'; $verdict['valid'] = [ 'result' => check_auth_cookie(), 'executed' => $GLOBALS['auth_integration_executed'], ]; break; default: fwrite(STDERR, 'unknown scenario "' . ($argv[1] ?? '') . '"' . PHP_EOL); exit(2); } echo json_encode($verdict);