/** * API functions for the configuration and server settings endpoints. */ import { del, get, post, put } from "./client"; import { ENDPOINTS } from "./endpoints"; import type { ActionConfig, ActionConfigUpdate, AddLogPathRequest, ConfFileContent, ConfFileCreateRequest, ConfFilesResponse, ConfFileUpdateRequest, FilterConfig, FilterConfigUpdate, GlobalConfig, GlobalConfigUpdate, JailConfigFileContent, JailConfigFileEnabledUpdate, JailConfigFilesResponse, JailConfigListResponse, JailConfigResponse, JailConfigUpdate, LogPreviewRequest, LogPreviewResponse, MapColorThresholdsResponse, MapColorThresholdsUpdate, RegexTestRequest, RegexTestResponse, ServerSettingsResponse, ServerSettingsUpdate, JailFileConfig, JailFileConfigUpdate, } from "../types/config"; // --------------------------------------------------------------------------- // Jail configuration // --------------------------------------------------------------------------- export async function fetchJailConfigs( ): Promise { return get(ENDPOINTS.configJails); } export async function fetchJailConfig( name: string ): Promise { return get(ENDPOINTS.configJail(name)); } export async function updateJailConfig( name: string, update: JailConfigUpdate ): Promise { await put(ENDPOINTS.configJail(name), update); } // --------------------------------------------------------------------------- // Global configuration // --------------------------------------------------------------------------- export async function fetchGlobalConfig( ): Promise { return get(ENDPOINTS.configGlobal); } export async function updateGlobalConfig( update: GlobalConfigUpdate ): Promise { await put(ENDPOINTS.configGlobal, update); } // --------------------------------------------------------------------------- // Reload // --------------------------------------------------------------------------- export async function reloadConfig( ): Promise { await post(ENDPOINTS.configReload, undefined); } // --------------------------------------------------------------------------- // Regex tester // --------------------------------------------------------------------------- export async function testRegex( req: RegexTestRequest ): Promise { return post(ENDPOINTS.configRegexTest, req); } // --------------------------------------------------------------------------- // Log path management // --------------------------------------------------------------------------- export async function addLogPath( jailName: string, req: AddLogPathRequest ): Promise { await post(ENDPOINTS.configJailLogPath(jailName), req); } export async function deleteLogPath( jailName: string, logPath: string ): Promise { await del( `${ENDPOINTS.configJailLogPath(jailName)}?log_path=${encodeURIComponent(logPath)}` ); } // --------------------------------------------------------------------------- // Log preview // --------------------------------------------------------------------------- export async function previewLog( req: LogPreviewRequest ): Promise { return post(ENDPOINTS.configPreviewLog, req); } // --------------------------------------------------------------------------- // Server settings // --------------------------------------------------------------------------- export async function fetchServerSettings( ): Promise { return get(ENDPOINTS.serverSettings); } export async function updateServerSettings( update: ServerSettingsUpdate ): Promise { await put(ENDPOINTS.serverSettings, update); } export async function flushLogs( ): Promise { const resp = await post<{ message: string }>( ENDPOINTS.serverFlushLogs, undefined, ); return resp.message; } // --------------------------------------------------------------------------- // Map color thresholds // --------------------------------------------------------------------------- export async function fetchMapColorThresholds( ): Promise { return get(ENDPOINTS.configMapColorThresholds); } export async function updateMapColorThresholds( update: MapColorThresholdsUpdate ): Promise { return put( ENDPOINTS.configMapColorThresholds, update, ); } // --------------------------------------------------------------------------- // Jail config files (Task 4a) // --------------------------------------------------------------------------- export async function fetchJailConfigFiles(): Promise { return get(ENDPOINTS.configJailFiles); } export async function createJailConfigFile( req: ConfFileCreateRequest ): Promise { return post(ENDPOINTS.configJailFiles, req); } export async function fetchJailConfigFileContent( filename: string ): Promise { return get(ENDPOINTS.configJailFile(filename)); } export async function updateJailConfigFile( filename: string, req: ConfFileUpdateRequest ): Promise { await put(ENDPOINTS.configJailFile(filename), req); } export async function setJailConfigFileEnabled( filename: string, update: JailConfigFileEnabledUpdate ): Promise { await put(ENDPOINTS.configJailFileEnabled(filename), update); } // --------------------------------------------------------------------------- // Filter files (Task 4d) // --------------------------------------------------------------------------- export async function fetchFilterFiles(): Promise { return get(ENDPOINTS.configFilters); } export async function fetchFilterFile(name: string): Promise { return get(ENDPOINTS.configFilter(name)); } export async function updateFilterFile( name: string, req: ConfFileUpdateRequest ): Promise { await put(ENDPOINTS.configFilter(name), req); } export async function createFilterFile( req: ConfFileCreateRequest ): Promise { return post(ENDPOINTS.configFilters, req); } // --------------------------------------------------------------------------- // Action files (Task 4e) // --------------------------------------------------------------------------- export async function fetchActionFiles(): Promise { return get(ENDPOINTS.configActions); } export async function fetchActionFile(name: string): Promise { return get(ENDPOINTS.configAction(name)); } export async function updateActionFile( name: string, req: ConfFileUpdateRequest ): Promise { await put(ENDPOINTS.configAction(name), req); } export async function createActionFile( req: ConfFileCreateRequest ): Promise { return post(ENDPOINTS.configActions, req); } // --------------------------------------------------------------------------- // Parsed filter config (Task 2.2) // --------------------------------------------------------------------------- export async function fetchParsedFilter(name: string): Promise { return get(ENDPOINTS.configFilterParsed(name)); } export async function updateParsedFilter( name: string, update: FilterConfigUpdate ): Promise { await put(ENDPOINTS.configFilterParsed(name), update); } // --------------------------------------------------------------------------- // Parsed action config (Task 3.2) // --------------------------------------------------------------------------- export async function fetchParsedAction(name: string): Promise { return get(ENDPOINTS.configActionParsed(name)); } export async function updateParsedAction( name: string, update: ActionConfigUpdate ): Promise { await put(ENDPOINTS.configActionParsed(name), update); } // --------------------------------------------------------------------------- // Parsed jail file config (Task 6.1 / 6.2) // --------------------------------------------------------------------------- export async function fetchParsedJailFile(filename: string): Promise { return get(ENDPOINTS.configJailFileParsed(filename)); } export async function updateParsedJailFile( filename: string, update: JailFileConfigUpdate ): Promise { await put(ENDPOINTS.configJailFileParsed(filename), update); }