1001 lines
53 KiB
JavaScript
1001 lines
53 KiB
JavaScript
// 定义API文档的JSON
|
||
const swaggerDocument = {
|
||
"openapi": "3.0.3",
|
||
"info": {
|
||
"title": "DNS Server API",
|
||
"description": "DNS服务器完整API文档,包括统计信息、Shield管理、主机管理等功能。",
|
||
"version": "1.1.0",
|
||
"contact": {
|
||
"name": "DNS Server 支持",
|
||
"email": "support@dnsserver.com"
|
||
},
|
||
"license": {
|
||
"name": "Apache 2.0",
|
||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||
}
|
||
},
|
||
"servers": [
|
||
{
|
||
"url": "http://localhost:8080/api",
|
||
"description": "本地开发服务器"
|
||
},
|
||
{
|
||
"url": "http://{host}:{port}/api",
|
||
"description": "自定义服务器",
|
||
"variables": {
|
||
"host": {
|
||
"default": "localhost"
|
||
},
|
||
"port": {
|
||
"default": "8080"
|
||
}
|
||
}
|
||
}
|
||
],
|
||
"paths": {
|
||
"/stats": {
|
||
"get": {
|
||
"summary": "获取系统统计信息",
|
||
"description": "获取DNS服务器和Shield的详细统计信息,包括查询量、CPU使用率等。",
|
||
"tags": ["stats"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取统计信息",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"dns": {
|
||
"type": "object",
|
||
"properties": {
|
||
"Queries": {"type": "integer", "description": "总查询次数"},
|
||
"Blocked": {"type": "integer", "description": "被阻止的查询次数"},
|
||
"Allowed": {"type": "integer", "description": "允许的查询次数"},
|
||
"Errors": {"type": "integer", "description": "错误查询次数"},
|
||
"LastQuery": {"type": "string", "description": "最近一次查询时间"},
|
||
"AvgResponseTime": {"type": "number", "description": "平均响应时间(毫秒)"},
|
||
"TotalResponseTime": {"type": "number", "description": "总响应时间(毫秒)"},
|
||
"QueryTypes": {"type": "object", "description": "查询类型统计"},
|
||
"SourceIPs": {"type": "object", "description": "来源IP统计"},
|
||
"CpuUsage": {"type": "number", "description": "CPU使用率(百分比)"}
|
||
}
|
||
},
|
||
"shield": {"type": "object", "description": "Shield统计信息"},
|
||
"topQueryType": {"type": "string", "description": "最常见的查询类型"},
|
||
"activeIPs": {"type": "integer", "description": "活跃IP数量"},
|
||
"avgResponseTime": {"type": "number", "description": "平均响应时间(毫秒)"},
|
||
"cpuUsage": {"type": "number", "description": "CPU使用率(百分比)"},
|
||
"time": {"type": "string", "description": "统计时间"}
|
||
}
|
||
},
|
||
"examples": {
|
||
"default": {
|
||
"value": {
|
||
"dns": {
|
||
"Queries": 1250,
|
||
"Blocked": 230,
|
||
"Allowed": 1020,
|
||
"Errors": 0,
|
||
"LastQuery": "2023-07-15T14:30:45Z",
|
||
"AvgResponseTime": 12.5,
|
||
"TotalResponseTime": 15625,
|
||
"QueryTypes": {"A": 850, "AAAA": 250, "CNAME": 150},
|
||
"SourceIPs": {"192.168.1.100": 500, "192.168.1.101": 750},
|
||
"CpuUsage": 0.15
|
||
},
|
||
"shield": {},
|
||
"topQueryType": "A",
|
||
"activeIPs": 2,
|
||
"avgResponseTime": 12.5,
|
||
"cpuUsage": 0.15,
|
||
"time": "2023-07-15T14:30:45Z"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "无法获取统计信息"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/stats/query-types": {
|
||
"get": {
|
||
"summary": "获取查询类型统计",
|
||
"description": "获取DNS查询类型的详细统计信息。",
|
||
"tags": ["stats"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取查询类型统计",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"type": {"type": "string", "description": "查询类型"},
|
||
"count": {"type": "integer", "description": "查询次数"}
|
||
}
|
||
}
|
||
},
|
||
"example": [
|
||
{"type": "A", "count": 850},
|
||
{"type": "AAAA", "count": 250},
|
||
{"type": "CNAME", "count": 150}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/stats/top-clients": {
|
||
"get": {
|
||
"summary": "获取TOP客户端",
|
||
"description": "获取查询量最多的客户端IP列表。",
|
||
"tags": ["stats"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取TOP客户端",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"ip": {"type": "string", "description": "客户端IP地址"},
|
||
"count": {"type": "integer", "description": "查询次数"}
|
||
}
|
||
}
|
||
},
|
||
"example": [
|
||
{"ip": "192.168.1.100", "count": 500},
|
||
{"ip": "192.168.1.101", "count": 750}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/stats/top-domains": {
|
||
"get": {
|
||
"summary": "获取TOP域名",
|
||
"description": "获取查询量最多的域名列表。",
|
||
"tags": ["stats"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取TOP域名",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"domain": {"type": "string", "description": "域名"},
|
||
"count": {"type": "integer", "description": "查询次数"}
|
||
}
|
||
}
|
||
},
|
||
"example": [
|
||
{"domain": "example.com", "count": 150},
|
||
{"domain": "google.com", "count": 120}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield": {
|
||
"get": {
|
||
"summary": "获取Shield配置",
|
||
"description": "获取Shield的完整配置信息,包括启用状态、规则等。",
|
||
"tags": ["shield"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取配置信息",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"enabled": {"type": "boolean", "description": "是否启用Shield"},
|
||
"rulesCount": {"type": "integer", "description": "规则数量"},
|
||
"lastUpdate": {"type": "string", "description": "最后更新时间"},
|
||
"blacklists": {"type": "array", "description": "黑名单列表", "items": {"type": "object"}}
|
||
}
|
||
},
|
||
"example": {
|
||
"enabled": true,
|
||
"rulesCount": 5000,
|
||
"lastUpdate": "2023-07-15T10:00:00Z",
|
||
"blacklists": []
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "无法获取Shield配置"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"post": {
|
||
"summary": "更新Shield配置",
|
||
"description": "更新Shield的全局配置信息。",
|
||
"tags": ["shield"],
|
||
"requestBody": {
|
||
"required": true,
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"enabled": {"type": "boolean", "description": "是否启用Shield"},
|
||
"updateInterval": {"type": "integer", "description": "更新间隔(秒)"}
|
||
}
|
||
},
|
||
"example": {
|
||
"enabled": true,
|
||
"updateInterval": 3600
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功更新配置",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
},
|
||
"400": {
|
||
"description": "请求参数错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "参数格式错误"}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "更新配置失败"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"put": {
|
||
"summary": "重启Shield",
|
||
"description": "重新加载和应用Shield规则。",
|
||
"tags": ["shield"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功重启Shield",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "重启失败"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield/stats": {
|
||
"get": {
|
||
"summary": "获取Shield统计信息",
|
||
"description": "获取Shield的详细统计信息,包括拦截数量等。",
|
||
"tags": ["shield"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取统计信息",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"blockedCount": {"type": "integer", "description": "已拦截数量"},
|
||
"rulesCount": {"type": "integer", "description": "规则数量"},
|
||
"lastBlocked": {"type": "string", "description": "最近拦截时间"}
|
||
}
|
||
},
|
||
"example": {
|
||
"blockedCount": 1500,
|
||
"rulesCount": 5000,
|
||
"lastBlocked": "2023-07-15T14:25:30Z"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield/top-blocked-domains": {
|
||
"get": {
|
||
"summary": "获取TOP被拦截域名",
|
||
"description": "获取被Shield拦截最多的域名列表。",
|
||
"tags": ["shield"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取TOP被拦截域名",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"domain": {"type": "string", "description": "被拦截的域名"},
|
||
"count": {"type": "integer", "description": "拦截次数"},
|
||
"lastSeen": {"type": "string", "description": "最近一次拦截时间"}
|
||
}
|
||
}
|
||
},
|
||
"example": [
|
||
{"domain": "ads.example.com", "count": 150, "lastSeen": "2023-07-15T14:25:30Z"},
|
||
{"domain": "tracking.example.org", "count": 120, "lastSeen": "2023-07-15T14:20:15Z"}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield/recent-blocked-domains": {
|
||
"get": {
|
||
"summary": "获取最近被拦截域名",
|
||
"description": "获取最近被Shield拦截的域名列表。",
|
||
"tags": ["shield"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取最近被拦截域名",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"domain": {"type": "string", "description": "被拦截的域名"},
|
||
"ip": {"type": "string", "description": "请求来源IP"},
|
||
"timestamp": {"type": "string", "description": "拦截时间"}
|
||
}
|
||
}
|
||
},
|
||
"example": [
|
||
{"domain": "ads.example.com", "ip": "192.168.1.100", "timestamp": "2023-07-15T14:25:30Z"},
|
||
{"domain": "tracking.example.org", "ip": "192.168.1.101", "timestamp": "2023-07-15T14:20:15Z"}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield/blacklists": {
|
||
"get": {
|
||
"summary": "获取黑名单列表",
|
||
"description": "获取所有远程黑名单的列表及详细信息。",
|
||
"tags": ["shield"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取黑名单列表",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "黑名单名称"},
|
||
"url": {"type": "string", "description": "黑名单URL"},
|
||
"enabled": {"type": "boolean", "description": "是否启用"},
|
||
"lastUpdate": {"type": "string", "description": "最后更新时间"},
|
||
"status": {"type": "string", "description": "状态"},
|
||
"rulesCount": {"type": "integer", "description": "规则数量"}
|
||
}
|
||
}
|
||
},
|
||
"example": [
|
||
{
|
||
"name": "AdBlock List",
|
||
"url": "https://example.com/ads.txt",
|
||
"enabled": true,
|
||
"lastUpdate": "2023-07-15T10:00:00Z",
|
||
"status": "active",
|
||
"rulesCount": 1500
|
||
}
|
||
]
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "获取黑名单列表失败"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"post": {
|
||
"summary": "添加黑名单",
|
||
"description": "添加新的远程黑名单URL。",
|
||
"tags": ["shield"],
|
||
"requestBody": {
|
||
"required": true,
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"required": ["name", "url"],
|
||
"properties": {
|
||
"name": {"type": "string", "description": "黑名单名称"},
|
||
"url": {"type": "string", "description": "黑名单URL"},
|
||
"enabled": {"type": "boolean", "description": "是否启用", "default": true}
|
||
}
|
||
},
|
||
"example": {
|
||
"name": "AdBlock List",
|
||
"url": "https://example.com/ads.txt",
|
||
"enabled": true
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功添加黑名单",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
},
|
||
"400": {
|
||
"description": "请求参数错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "名称和URL为必填项"}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "添加黑名单失败"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"put": {
|
||
"summary": "更新黑名单",
|
||
"description": "更新黑名单的配置信息。",
|
||
"tags": ["shield"],
|
||
"requestBody": {
|
||
"required": true,
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"required": ["name"],
|
||
"properties": {
|
||
"name": {"type": "string", "description": "黑名单名称"},
|
||
"url": {"type": "string", "description": "黑名单URL"},
|
||
"enabled": {"type": "boolean", "description": "是否启用"}
|
||
}
|
||
},
|
||
"example": {
|
||
"name": "AdBlock List",
|
||
"url": "https://example.com/ads_new.txt",
|
||
"enabled": false
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功更新黑名单",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
},
|
||
"400": {
|
||
"description": "请求参数错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "参数格式错误"}
|
||
}
|
||
}
|
||
},
|
||
"404": {
|
||
"description": "黑名单不存在",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "黑名单不存在"}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "更新黑名单失败"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"patch": {
|
||
"summary": "批量更新黑名单状态",
|
||
"description": "批量更新多个黑名单的启用状态。",
|
||
"tags": ["shield"],
|
||
"requestBody": {
|
||
"required": true,
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"names": {"type": "array", "description": "黑名单名称列表", "items": {"type": "string"}},
|
||
"enabled": {"type": "boolean", "description": "是否启用"}
|
||
}
|
||
},
|
||
"example": {
|
||
"names": ["AdBlock List", "Tracking List"],
|
||
"enabled": true
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功批量更新",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield/blacklists/{name}": {
|
||
"delete": {
|
||
"summary": "删除黑名单",
|
||
"description": "根据名称删除指定的远程黑名单。",
|
||
"tags": ["shield"],
|
||
"parameters": [
|
||
{
|
||
"name": "name",
|
||
"in": "path",
|
||
"required": true,
|
||
"schema": {
|
||
"type": "string"
|
||
},
|
||
"description": "黑名单名称"
|
||
}
|
||
],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功删除黑名单",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
},
|
||
"404": {
|
||
"description": "黑名单不存在",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "黑名单不存在"}
|
||
}
|
||
}
|
||
},
|
||
"500": {
|
||
"description": "服务器内部错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "删除黑名单失败"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/shield/blacklists/{name}/update": {
|
||
"post": {
|
||
"summary": "手动更新黑名单",
|
||
"description": "手动触发指定黑名单的更新操作。",
|
||
"tags": ["shield"],
|
||
"parameters": [
|
||
{
|
||
"name": "name",
|
||
"in": "path",
|
||
"required": true,
|
||
"schema": {
|
||
"type": "string"
|
||
},
|
||
"description": "黑名单名称"
|
||
}
|
||
],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功开始更新",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "updating"}
|
||
}
|
||
}
|
||
},
|
||
"404": {
|
||
"description": "黑名单不存在",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "黑名单不存在"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/hosts": {
|
||
"get": {
|
||
"summary": "获取主机配置",
|
||
"description": "获取当前的hosts配置信息。",
|
||
"tags": ["hosts"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取hosts配置",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"entries": {"type": "array", "description": "hosts条目列表", "items": {"type": "object"}},
|
||
"count": {"type": "integer", "description": "条目数量"}
|
||
}
|
||
},
|
||
"example": {
|
||
"entries": [],
|
||
"count": 0
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"post": {
|
||
"summary": "更新hosts配置",
|
||
"description": "更新hosts配置内容。",
|
||
"tags": ["hosts"],
|
||
"requestBody": {
|
||
"required": true,
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"content": {"type": "string", "description": "hosts文件内容"}
|
||
}
|
||
},
|
||
"example": {
|
||
"content": "127.0.0.1 localhost\n192.168.1.1 example.com"
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功更新hosts",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态"}
|
||
}
|
||
},
|
||
"example": {"status": "success"}
|
||
}
|
||
}
|
||
},
|
||
"400": {
|
||
"description": "请求参数错误",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"example": {"error": "参数格式错误"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/server/status": {
|
||
"get": {
|
||
"summary": "获取服务器状态",
|
||
"description": "获取DNS服务器的运行状态信息。",
|
||
"tags": ["server"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取服务器状态",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "服务器状态"},
|
||
"uptime": {"type": "integer", "description": "运行时间(秒)"},
|
||
"version": {"type": "string", "description": "服务器版本"}
|
||
}
|
||
},
|
||
"example": {
|
||
"status": "running",
|
||
"uptime": 3600,
|
||
"version": "1.0.0"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/server/config": {
|
||
"get": {
|
||
"summary": "获取服务器配置",
|
||
"description": "获取DNS服务器的配置信息。",
|
||
"tags": ["server"],
|
||
"responses": {
|
||
"200": {
|
||
"description": "成功获取服务器配置",
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {
|
||
"type": "object",
|
||
"properties": {
|
||
"port": {"type": "integer", "description": "DNS服务端口"},
|
||
"httpPort": {"type": "integer", "description": "HTTP服务端口"},
|
||
"upstreamServers": {"type": "array", "description": "上游DNS服务器", "items": {"type": "string"}}
|
||
}
|
||
},
|
||
"example": {
|
||
"port": 53,
|
||
"httpPort": 8080,
|
||
"upstreamServers": ["8.8.8.8", "1.1.1.1"]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"tags": [
|
||
{
|
||
"name": "stats",
|
||
"description": "统计信息相关API - 获取系统运行统计、查询类型、客户端和域名统计等"
|
||
},
|
||
{
|
||
"name": "shield",
|
||
"description": "Shield功能相关API - 管理拦截规则、黑名单配置和拦截统计"
|
||
},
|
||
{
|
||
"name": "hosts",
|
||
"description": "主机配置API - 管理hosts文件配置"
|
||
},
|
||
{
|
||
"name": "server",
|
||
"description": "服务器管理API - 获取服务器状态和配置信息"
|
||
}
|
||
],
|
||
"components": {
|
||
"schemas": {
|
||
"ErrorResponse": {
|
||
"type": "object",
|
||
"properties": {
|
||
"error": {"type": "string", "description": "错误信息"}
|
||
}
|
||
},
|
||
"SuccessResponse": {
|
||
"type": "object",
|
||
"properties": {
|
||
"status": {"type": "string", "description": "操作状态", "enum": ["success", "error", "updating"]}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
// 移除了主题切换功能
|
||
|
||
// 初始化Swagger UI
|
||
window.onload = function() {
|
||
const ui = SwaggerUIBundle({
|
||
spec: swaggerDocument,
|
||
dom_id: '#swagger-ui',
|
||
deepLinking: true,
|
||
presets: [
|
||
SwaggerUIBundle.presets.apis,
|
||
SwaggerUIStandalonePreset
|
||
],
|
||
plugins: [
|
||
SwaggerUIBundle.plugins.DownloadUrl
|
||
],
|
||
layout: "StandaloneLayout",
|
||
// 添加自定义UI配置
|
||
tryItOutEnabled: true,
|
||
showRequestHeaders: true,
|
||
filter: true,
|
||
docExpansion: "list",
|
||
defaultModelsExpandDepth: 2,
|
||
defaultModelExpandDepth: 2,
|
||
persistAuthorization: true
|
||
});
|
||
window.ui = ui;
|
||
}; |