Files
dns-server/dns/staticbak/static/api/js/index.js
T
Alex Yang cdac4fcf43 update
2026-01-16 11:09:11 +08:00

1791 lines
95 KiB
JavaScript

// 定义API文档的JSON
const swaggerDocument = {
"openapi": "3.0.3",
"info": {
"title": "DNS Server API",
"description": "DNS服务器完整API文档,包括统计信息、Shield管理、主机管理等功能。",
"version": "1.2.5",
"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": {
"/login": {
"post": {
"summary": "用户登录",
"description": "使用用户名和密码登录DNS服务器API。",
"tags": ["auth"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"username": {"type": "string", "description": "用户名"},
"password": {"type": "string", "description": "密码"}
}
},
"example": {
"username": "admin",
"password": "admin"
}
}
}
},
"responses": {
"200": {
"description": "登录成功",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "操作状态"},
"message": {"type": "string", "description": "操作信息"}
}
},
"example": {
"status": "success",
"message": "登录成功"
}
}
}
},
"400": {
"description": "请求参数错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {
"error": "无效的请求体"
}
}
}
},
"401": {
"description": "用户名或密码错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {
"error": "用户名或密码错误"
}
}
}
}
}
}
},
"/logout": {
"post": {
"summary": "用户注销",
"description": "注销当前登录的用户会话。",
"tags": ["auth"],
"responses": {
"200": {
"description": "注销成功",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "操作状态"},
"message": {"type": "string", "description": "操作信息"}
}
},
"example": {
"status": "success",
"message": "注销成功"
}
}
}
}
}
}
},
"/change-password": {
"post": {
"summary": "修改密码",
"description": "修改当前登录用户的密码。",
"tags": ["auth"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"currentPassword": {"type": "string", "description": "当前密码"},
"newPassword": {"type": "string", "description": "新密码"}
}
},
"example": {
"currentPassword": "admin",
"newPassword": "newpassword"
}
}
}
},
"responses": {
"200": {
"description": "密码修改成功",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "操作状态"},
"message": {"type": "string", "description": "操作信息"}
}
},
"example": {
"status": "success",
"message": "密码修改成功"
}
}
}
},
"400": {
"description": "请求参数错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {
"error": "无效的请求体"
}
}
}
},
"401": {
"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": "保存密码失败"
}
}
}
}
}
}
},
"/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使用率(百分比)"},
"DNSSECQueries": {"type": "integer", "description": "DNSSEC查询次数"},
"DNSSECSuccess": {"type": "integer", "description": "DNSSEC成功次数"},
"DNSSECFailed": {"type": "integer", "description": "DNSSEC失败次数"},
"DNSSECEnabled": {"type": "boolean", "description": "是否启用DNSSEC"}
}
},
"shield": {"type": "object", "description": "Shield统计信息"},
"topQueryType": {"type": "string", "description": "最常见的查询类型"},
"activeIPs": {"type": "integer", "description": "活跃IP数量"},
"avgResponseTime": {"type": "number", "description": "平均响应时间(毫秒)"},
"cpuUsage": {"type": "number", "description": "CPU使用率(百分比)"},
"dnssecEnabled": {"type": "boolean", "description": "是否启用DNSSEC"},
"dnssecQueries": {"type": "integer", "description": "DNSSEC查询次数"},
"dnssecSuccess": {"type": "integer", "description": "DNSSEC成功次数"},
"dnssecFailed": {"type": "integer", "description": "DNSSEC失败次数"},
"dnssecUsage": {"type": "number", "description": "DNSSEC使用率(百分比)"},
"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,
"DNSSECQueries": 500,
"DNSSECSuccess": 480,
"DNSSECFailed": 20,
"DNSSECEnabled": true
},
"shield": {},
"topQueryType": "A",
"activeIPs": 2,
"avgResponseTime": 12.5,
"cpuUsage": 0.15,
"dnssecEnabled": true,
"dnssecQueries": 500,
"dnssecSuccess": 480,
"dnssecFailed": 20,
"dnssecUsage": 40.0,
"time": "2023-07-15T14:30:45Z"
}
}
}
}
}
},
"500": {
"description": "服务器内部错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {"error": "无法获取统计信息"}
}
}
}
}
}
},
"/top-blocked": {
"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": "ad.example.com", "count": 150},
{"domain": "tracker.example.net", "count": 120}
]
}
}
}
}
}
},
"/top-resolved": {
"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": "google.com", "count": 200},
{"domain": "facebook.com", "count": 150}
]
}
}
}
}
}
},
"/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}
]
}
}
}
}
}
},
"/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}
]
}
}
}
}
}
},
"/recent-blocked": {
"get": {
"summary": "获取最近被阻止的域名",
"description": "获取最近被Shield阻止的域名列表。",
"tags": ["stats"],
"responses": {
"200": {
"description": "成功获取最近被阻止的域名",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"domain": {"type": "string", "description": "域名"},
"timestamp": {"type": "string", "description": "阻止时间"}
}
}
},
"example": [
{"domain": "ad.example.com", "timestamp": "2023-07-15T14:30:45Z"},
{"domain": "tracker.example.net", "timestamp": "2023-07-15T14:29:30Z"}
]
}
}
}
}
}
},
"/hourly-stats": {
"get": {
"summary": "获取小时统计",
"description": "获取按小时统计的DNS查询数据。",
"tags": ["stats"],
"responses": {
"200": {
"description": "成功获取小时统计",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"labels": {"type": "array", "items": {"type": "string"}, "description": "小时标签"},
"data": {"type": "array", "items": {"type": "integer"}, "description": "查询次数数据"}
}
},
"example": {
"labels": ["15:00", "16:00", "17:00"],
"data": [120, 90, 150]
}
}
}
}
}
}
},
"/daily-stats": {
"get": {
"summary": "获取每日统计",
"description": "获取最近7天的DNS查询统计数据。",
"tags": ["stats"],
"responses": {
"200": {
"description": "成功获取每日统计",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"labels": {"type": "array", "items": {"type": "string"}, "description": "日期标签"},
"data": {"type": "array", "items": {"type": "integer"}, "description": "查询次数数据"}
}
},
"example": {
"labels": ["01-02", "01-03", "01-04"],
"data": [2500, 2700, 2300]
}
}
}
}
}
}
},
"/monthly-stats": {
"get": {
"summary": "获取每月统计",
"description": "获取最近30天的DNS查询统计数据。",
"tags": ["stats"],
"responses": {
"200": {
"description": "成功获取每月统计",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"labels": {"type": "array", "items": {"type": "string"}, "description": "日期标签"},
"data": {"type": "array", "items": {"type": "integer"}, "description": "查询次数数据"}
}
},
"example": {
"labels": ["01-01", "01-02", "01-03"],
"data": [2500, 2700, 2300]
}
}
}
}
}
}
},
"/query/type": {
"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}
]
}
}
}
}
}
},
"/logs/stats": {
"get": {
"summary": "获取日志统计信息",
"description": "获取DNS查询日志的统计信息。",
"tags": ["logs"],
"responses": {
"200": {
"description": "成功获取日志统计信息",
"content": {
"application/json": {
"schema": {
"type": "object",
"description": "日志统计信息"}
}
}
}
}
}
},
"/logs/query": {
"get": {
"summary": "查询日志",
"description": "根据条件查询DNS查询日志。",
"tags": ["logs"],
"parameters": [
{
"name": "limit",
"in": "query",
"schema": {
"type": "integer",
"default": 100
},
"description": "返回结果数量限制"
},
{
"name": "offset",
"in": "query",
"schema": {
"type": "integer",
"default": 0
},
"description": "结果偏移量"
},
{
"name": "sort",
"in": "query",
"schema": {
"type": "string"
},
"description": "排序字段"
},
{
"name": "direction",
"in": "query",
"schema": {
"type": "string"
},
"description": "排序方向"
},
{
"name": "result",
"in": "query",
"schema": {
"type": "string"
},
"description": "查询结果过滤"
},
{
"name": "search",
"in": "query",
"schema": {
"type": "string"
},
"description": "搜索关键词"
}
],
"responses": {
"200": {
"description": "成功查询日志",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"description": "日志条目"
}
}
}
}
}
}
}
},
"/logs/count": {
"get": {
"summary": "获取日志总数",
"description": "获取DNS查询日志的总数。",
"tags": ["logs"],
"responses": {
"200": {
"description": "成功获取日志总数",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"count": {"type": "integer", "description": "日志总数"}
}
},
"example": {
"count": 1000
}
}
}
}
}
}
},
"/shield": {
"get": {
"summary": "获取Shield配置和统计信息",
"description": "获取Shield的配置信息和规则统计,包括更新间隔、屏蔽方法、黑名单数量等。",
"deprecated": false,
"tags": ["shield"],
"responses": {
"200": {
"description": "成功获取配置和统计信息",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"updateInterval": {"type": "integer", "description": "更新间隔(秒)"},
"blockMethod": {"type": "string", "description": "屏蔽方法"},
"blacklistCount": {"type": "integer", "description": "黑名单数量"},
"domainRulesCount": {"type": "integer", "description": "域名规则数量"},
"domainExceptionsCount": {"type": "integer", "description": "域名例外规则数量"},
"regexRulesCount": {"type": "integer", "description": "正则规则数量"},
"regexExceptionsCount": {"type": "integer", "description": "正则例外规则数量"},
"hostsRulesCount": {"type": "integer", "description": "Hosts规则数量"}
}
},
"example": {
"updateInterval": 3600,
"blockMethod": "NXDOMAIN",
"blacklistCount": 4,
"domainRulesCount": 1000,
"domainExceptionsCount": 100,
"regexRulesCount": 50,
"regexExceptionsCount": 10,
"hostsRulesCount": 200
}
}
}
},
"500": {
"description": "服务器内部错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {"error": "无法获取Shield配置"}
}
}
}
}
},
"post": {
"summary": "添加屏蔽规则",
"description": "添加新的屏蔽规则到Shield。",
"deprecated": false,
"tags": ["shield"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"rule": {"type": "string", "description": "屏蔽规则"}
}
},
"example": {
"rule": "example.com"
}
}
}
},
"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": "添加规则失败"}
}
}
}
}
},
"delete": {
"summary": "删除屏蔽规则",
"description": "从Shield中删除指定的屏蔽规则。",
"deprecated": false,
"tags": ["shield"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"rule": {"type": "string", "description": "要删除的屏蔽规则"}
}
},
"example": {
"rule": "example.com"
}
}
}
},
"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": "重新加载规则",
"description": "重新加载和应用Shield规则。",
"deprecated": false,
"tags": ["shield"],
"responses": {
"200": {
"description": "成功重新加载规则",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "操作状态"},
"message": {"type": "string", "description": "操作信息"}
}
},
"example": {
"status": "success",
"message": "规则重新加载成功"
}
}
}
},
"500": {
"description": "服务器内部错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {"error": "重新加载规则失败"}
}
}
}
}
}
},
"/shield/blacklists": {
"get": {
"summary": "获取黑名单列表",
"description": "获取Shield的黑名单列表,包括内置黑名单和自定义黑名单。",
"deprecated": false,
"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到Shield。",
"deprecated": false,
"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": "更新黑名单列表(包括启用/禁用状态)。",
"deprecated": false,
"tags": ["shield"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"blacklists": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string", "description": "黑名单名称"},
"url": {"type": "string", "description": "黑名单URL"},
"enabled": {"type": "boolean", "description": "是否启用"}
}
}
}
}
},
"example": {
"blacklists": [
{
"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": "无效的请求体"}
}
}
},
"500": {
"description": "服务器内部错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {"error": "更新黑名单列表失败"}
}
}
}
}
}
},
"/shield/localrules": {
"get": {
"summary": "获取自定义规则",
"description": "获取Shield的自定义规则列表。",
"deprecated": false,
"tags": ["shield"],
"responses": {
"200": {
"description": "成功获取自定义规则",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string", "description": "规则ID"},
"pattern": {"type": "string", "description": "规则模式"},
"description": {"type": "string", "description": "规则描述"}
}
}
},
"example": [
{"id": "1", "pattern": ".*malware.*", "description": "恶意软件域名"}
]
}
}
}
}
},
"post": {
"summary": "添加自定义规则",
"description": "添加新的自定义规则。",
"deprecated": false,
"tags": ["shield"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"pattern": {"type": "string", "description": "规则模式"},
"description": {"type": "string", "description": "规则描述"}
}
},
"example": {
"pattern": ".*ad\.com$",
"description": "广告域名"
}
}
}
},
"responses": {
"200": {
"description": "成功添加规则",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "操作状态"}
}
},
"example": {"status": "success"}
}
}
}
}
},
"delete": {
"summary": "删除自定义规则",
"description": "删除指定的自定义规则。",
"deprecated": false,
"tags": ["shield"],
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "string"
},
"description": "规则ID"
}
],
"responses": {
"200": {
"description": "成功删除规则",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "操作状态"}
}
},
"example": {"status": "success"}
}
}
}
}
}
},
"/shield/remoterules": {
"get": {
"summary": "获取远程规则状态",
"description": "获取远程规则的更新状态和版本信息。",
"deprecated": false,
"tags": ["shield"],
"responses": {
"200": {
"description": "成功获取远程规则",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string", "description": "规则ID"},
"pattern": {"type": "string", "description": "规则模式"},
"source": {"type": "string", "description": "规则来源"}
}
}
},
"example": [
{"id": "1001", "pattern": ".*phishing.*", "source": "malwarelist"}
]
}
}
}
}
}
},
"/shield/hosts": {
"get": {
"summary": "获取hosts内容",
"description": "获取当前的hosts文件内容。",
"deprecated": false,
"tags": ["shield"],
"responses": {
"200": {
"description": "成功获取hosts列表",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ip": {"type": "string", "description": "IP地址"},
"domain": {"type": "string", "description": "域名"}
}
}
},
"example": [
{"ip": "127.0.0.1", "domain": "localhost"}
]
}
}
}
}
},
"post": {
"summary": "添加hosts记录",
"description": "添加新的hosts记录。",
"deprecated": false,
"tags": ["shield"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["ip", "domain"],
"properties": {
"ip": {"type": "string", "description": "IP地址"},
"domain": {"type": "string", "description": "域名"}
}
},
"example": {
"ip": "127.0.0.1",
"domain": "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": "IP和域名是必填项"}
}
}
},
"500": {
"description": "服务器内部错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {"error": "添加hosts记录失败"}
}
}
}
}
},
"delete": {
"summary": "删除hosts记录",
"description": "删除指定域名的hosts记录。",
"deprecated": false,
"tags": ["shield"],
"parameters": [
{
"name": "domain",
"in": "query",
"required": true,
"schema": {
"type": "string"
},
"description": "要删除的域名"
}
],
"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": "域名是必填项"}
}
}
},
"500": {
"description": "服务器内部错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string", "description": "错误信息"}
}
},
"example": {"error": "删除hosts记录失败"}
}
}
}
}
}
},
"/dns/query": {
"post": {
"summary": "查询DNS记录",
"description": "查询指定域名的DNS记录,可以指定记录类型。",
"tags": ["dns"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"domain": {
"type": "string",
"description": "要查询的域名"
},
"recordType": {
"type": "string",
"description": "DNS记录类型(如A、AAAA、MX、NS等)"
}
},
"required": ["domain"]
},
"example": {
"domain": "example.com",
"recordType": "A"
}
}
}
},
"responses": {
"200": {
"description": "成功获取DNS记录",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Type": {
"type": "string",
"description": "DNS记录类型"
},
"Value": {
"type": "string",
"description": "DNS记录值"
},
"TTL": {
"type": "integer",
"description": "生存时间"
},
"Preference": {
"type": "integer",
"description": "MX记录优先级"
}
}
}
},
"example": [
{"Type": "A", "Value": "93.184.216.34", "TTL": 172800},
{"Type": "A", "Value": "93.184.216.35", "TTL": 172800}
]
}
}
},
"400": {
"description": "请求参数错误",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string",
"description": "错误信息"
}
}
},
"example": {
"error": "Domain parameter is required"
}
}
}
}
}
}
},
"/status": {
"get": {
"summary": "获取服务器状态",
"description": "获取DNS服务器的状态信息,包括查询统计、运行时间等。",
"tags": ["server"],
"responses": {
"200": {
"description": "成功获取服务器状态",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "description": "服务器状态"},
"queries": {"type": "integer", "description": "总查询次数"},
"blocked": {"type": "integer", "description": "被阻止的查询次数"},
"allowed": {"type": "integer", "description": "允许的查询次数"},
"errors": {"type": "integer", "description": "错误查询次数"},
"lastQuery": {"type": "string", "description": "最近一次查询时间"},
"avgResponseTime": {"type": "number", "description": "平均响应时间(毫秒)"},
"activeIPs": {"type": "integer", "description": "活跃IP数量"},
"startTime": {"type": "string", "description": "服务器启动时间"},
"uptime": {"type": "integer", "description": "运行时间(毫秒)"},
"cpuUsage": {"type": "number", "description": "CPU使用率(百分比)"},
"timestamp": {"type": "string", "description": "当前时间"}
}
},
"example": {
"status": "running",
"queries": 1250,
"blocked": 230,
"allowed": 1020,
"errors": 0,
"lastQuery": "2023-07-15T14:30:45Z",
"avgResponseTime": 12.5,
"activeIPs": 2,
"startTime": "2023-07-15T10:00:00Z",
"uptime": 16200000,
"cpuUsage": 0.15,
"timestamp": "2023-07-15T14:30:45Z"
}
}
}
}
}
}
},
"/config": {
"get": {
"summary": "获取服务器配置",
"description": "获取DNS服务器的配置信息,包括Shield配置。",
"tags": ["server"],
"responses": {
"200": {
"description": "成功获取服务器配置",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"shield": {
"type": "object",
"properties": {
"blockMethod": {"type": "string", "description": "屏蔽方法"},
"customBlockIP": {"type": "string", "description": "自定义屏蔽IP"},
"blacklists": {"type": "array", "description": "黑名单列表", "items": {"type": "object"}},
"updateInterval": {"type": "integer", "description": "更新间隔(秒)"}
}
}
}
},
"example": {
"shield": {
"blockMethod": "NXDOMAIN",
"customBlockIP": "",
"blacklists": [
{
"name": "AdGuard DNS filter",
"url": "https://example.com/ads.txt",
"enabled": true
}
],
"updateInterval": 3600
}
}
}
}
}
}
},
"post": {
"summary": "更新服务器配置",
"description": "更新DNS服务器的配置信息,包括Shield配置。",
"tags": ["server"],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"shield": {
"type": "object",
"properties": {
"blockMethod": {"type": "string", "description": "屏蔽方法"},
"customBlockIP": {"type": "string", "description": "自定义屏蔽IP"},
"blacklists": {"type": "array", "description": "黑名单列表", "items": {"type": "object"}},
"updateInterval": {"type": "integer", "description": "更新间隔(秒)"}
}
}
}
},
"example": {
"shield": {
"blockMethod": "NXDOMAIN",
"customBlockIP": "",
"blacklists": [
{
"name": "AdGuard DNS filter",
"url": "https://example.com/ads.txt",
"enabled": true
}
],
"updateInterval": 3600
}
}
}
}
},
"responses": {
"200": {
"description": "成功更新服务器配置",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {"type": "boolean", "description": "是否成功"},
"message": {"type": "string", "description": "操作信息"}
}
},
"example": {
"success": true,
"message": "配置已更新"
}
}
}
},
"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": "保存配置失败"
}
}
}
}
}
}
},
"/config/restart": {
"post": {
"summary": "重启服务器",
"description": "重启DNS服务器。",
"tags": ["server"],
"responses": {
"200": {
"description": "成功重启服务器",
"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": "重启服务器失败"}
}
}
}
}
}
}
},
"tags": [
{
"name": "auth",
"description": "认证相关API"
},
{
"name": "stats",
"description": "统计相关API"
},
{
"name": "shield",
"description": "Shield相关API"
},
{
"name": "server",
"description": "服务器相关API"
},
{
"name": "logs",
"description": "日志相关API"
}
]
};
// 初始化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"
});
window.ui = ui;
};