- configStyles.ts: add listDetailRoot, listPane, listItem, listItemSelected, detailPane style slots - index.ts: export ConfigListDetail and RawConfigSection - api/config.ts: add writeFilterFile and writeActionFile API helpers - setupTests.ts: add ResizeObserver and matchMedia mocks for Fluent UI v9 - ConfigPageLogPath.test.tsx: update to render inside FluentProvider - Docs/Tasks.md: mark config view redesign task as complete
293 lines
8.7 KiB
TypeScript
293 lines
8.7 KiB
TypeScript
/**
|
|
* 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<JailConfigListResponse> {
|
|
return get<JailConfigListResponse>(ENDPOINTS.configJails);
|
|
}
|
|
|
|
export async function fetchJailConfig(
|
|
name: string
|
|
): Promise<JailConfigResponse> {
|
|
return get<JailConfigResponse>(ENDPOINTS.configJail(name));
|
|
}
|
|
|
|
export async function updateJailConfig(
|
|
name: string,
|
|
update: JailConfigUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configJail(name), update);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Global configuration
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchGlobalConfig(
|
|
): Promise<GlobalConfig> {
|
|
return get<GlobalConfig>(ENDPOINTS.configGlobal);
|
|
}
|
|
|
|
export async function updateGlobalConfig(
|
|
update: GlobalConfigUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configGlobal, update);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Reload
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function reloadConfig(
|
|
): Promise<void> {
|
|
await post<undefined>(ENDPOINTS.configReload, undefined);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Regex tester
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function testRegex(
|
|
req: RegexTestRequest
|
|
): Promise<RegexTestResponse> {
|
|
return post<RegexTestResponse>(ENDPOINTS.configRegexTest, req);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Log path management
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function addLogPath(
|
|
jailName: string,
|
|
req: AddLogPathRequest
|
|
): Promise<void> {
|
|
await post<undefined>(ENDPOINTS.configJailLogPath(jailName), req);
|
|
}
|
|
|
|
export async function deleteLogPath(
|
|
jailName: string,
|
|
logPath: string
|
|
): Promise<void> {
|
|
await del<undefined>(
|
|
`${ENDPOINTS.configJailLogPath(jailName)}?log_path=${encodeURIComponent(logPath)}`
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Log preview
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function previewLog(
|
|
req: LogPreviewRequest
|
|
): Promise<LogPreviewResponse> {
|
|
return post<LogPreviewResponse>(ENDPOINTS.configPreviewLog, req);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Server settings
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchServerSettings(
|
|
): Promise<ServerSettingsResponse> {
|
|
return get<ServerSettingsResponse>(ENDPOINTS.serverSettings);
|
|
}
|
|
|
|
export async function updateServerSettings(
|
|
update: ServerSettingsUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.serverSettings, update);
|
|
}
|
|
|
|
export async function flushLogs(
|
|
): Promise<string> {
|
|
const resp = await post<{ message: string }>(
|
|
ENDPOINTS.serverFlushLogs,
|
|
undefined,
|
|
);
|
|
return resp.message;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Map color thresholds
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchMapColorThresholds(
|
|
): Promise<MapColorThresholdsResponse> {
|
|
return get<MapColorThresholdsResponse>(ENDPOINTS.configMapColorThresholds);
|
|
}
|
|
|
|
export async function updateMapColorThresholds(
|
|
update: MapColorThresholdsUpdate
|
|
): Promise<MapColorThresholdsResponse> {
|
|
return put<MapColorThresholdsResponse>(
|
|
ENDPOINTS.configMapColorThresholds,
|
|
update,
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Jail config files (Task 4a)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchJailConfigFiles(): Promise<JailConfigFilesResponse> {
|
|
return get<JailConfigFilesResponse>(ENDPOINTS.configJailFiles);
|
|
}
|
|
|
|
export async function createJailConfigFile(
|
|
req: ConfFileCreateRequest
|
|
): Promise<ConfFileContent> {
|
|
return post<ConfFileContent>(ENDPOINTS.configJailFiles, req);
|
|
}
|
|
|
|
export async function fetchJailConfigFileContent(
|
|
filename: string
|
|
): Promise<JailConfigFileContent> {
|
|
return get<JailConfigFileContent>(ENDPOINTS.configJailFile(filename));
|
|
}
|
|
|
|
export async function updateJailConfigFile(
|
|
filename: string,
|
|
req: ConfFileUpdateRequest
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configJailFile(filename), req);
|
|
}
|
|
|
|
export async function setJailConfigFileEnabled(
|
|
filename: string,
|
|
update: JailConfigFileEnabledUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configJailFileEnabled(filename), update);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Filter files (Task 4d)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchFilterFiles(): Promise<ConfFilesResponse> {
|
|
return get<ConfFilesResponse>(ENDPOINTS.configFilters);
|
|
}
|
|
|
|
export async function fetchFilterFile(name: string): Promise<ConfFileContent> {
|
|
return get<ConfFileContent>(ENDPOINTS.configFilter(name));
|
|
}
|
|
|
|
export async function updateFilterFile(
|
|
name: string,
|
|
req: ConfFileUpdateRequest
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configFilter(name), req);
|
|
}
|
|
|
|
export async function createFilterFile(
|
|
req: ConfFileCreateRequest
|
|
): Promise<ConfFileContent> {
|
|
return post<ConfFileContent>(ENDPOINTS.configFilters, req);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Action files (Task 4e)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchActionFiles(): Promise<ConfFilesResponse> {
|
|
return get<ConfFilesResponse>(ENDPOINTS.configActions);
|
|
}
|
|
|
|
export async function fetchActionFile(name: string): Promise<ConfFileContent> {
|
|
return get<ConfFileContent>(ENDPOINTS.configAction(name));
|
|
}
|
|
|
|
export async function updateActionFile(
|
|
name: string,
|
|
req: ConfFileUpdateRequest
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configAction(name), req);
|
|
}
|
|
|
|
export async function createActionFile(
|
|
req: ConfFileCreateRequest
|
|
): Promise<ConfFileContent> {
|
|
return post<ConfFileContent>(ENDPOINTS.configActions, req);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Parsed filter config (Task 2.2)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchParsedFilter(name: string): Promise<FilterConfig> {
|
|
return get<FilterConfig>(ENDPOINTS.configFilterParsed(name));
|
|
}
|
|
|
|
export async function updateParsedFilter(
|
|
name: string,
|
|
update: FilterConfigUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configFilterParsed(name), update);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Parsed action config (Task 3.2)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchParsedAction(name: string): Promise<ActionConfig> {
|
|
return get<ActionConfig>(ENDPOINTS.configActionParsed(name));
|
|
}
|
|
|
|
export async function updateParsedAction(
|
|
name: string,
|
|
update: ActionConfigUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configActionParsed(name), update);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Parsed jail file config (Task 6.1 / 6.2)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function fetchParsedJailFile(filename: string): Promise<JailFileConfig> {
|
|
return get<JailFileConfig>(ENDPOINTS.configJailFileParsed(filename));
|
|
}
|
|
|
|
export async function updateParsedJailFile(
|
|
filename: string,
|
|
update: JailFileConfigUpdate
|
|
): Promise<void> {
|
|
await put<undefined>(ENDPOINTS.configJailFileParsed(filename), update);
|
|
}
|