201 lines
12 KiB
Go
201 lines
12 KiB
Go
|
|
package proto
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"gorm.io/gorm"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
const (
|
|||
|
|
DNS_STATUS_STOPPED = 0 // DNS服务器状态:已停止
|
|||
|
|
DNS_STATUS_RUNNING = 1 // DNS服务器状态:运行中
|
|||
|
|
DNS_STATUS_ERROR = 2 // DNS服务器状态:错误
|
|||
|
|
|
|||
|
|
RECORD_TYPE_A = 1 // A记录
|
|||
|
|
RECORD_TYPE_AAAA = 28 // AAAA记录
|
|||
|
|
RECORD_TYPE_CNAME = 5 // CNAME记录
|
|||
|
|
RECORD_TYPE_MX = 15 // MX记录
|
|||
|
|
RECORD_TYPE_NS = 2 // NS记录
|
|||
|
|
RECORD_TYPE_SOA = 6 // SOA记录
|
|||
|
|
RECORD_TYPE_TXT = 16 // TXT记录
|
|||
|
|
RECORD_TYPE_SRV = 33 // SRV记录
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
type DNSServer struct {
|
|||
|
|
gorm.Model
|
|||
|
|
UserID uint `gorm:"column:user_id;index" json:"user_id" form:"user_id"` // 用户ID
|
|||
|
|
Name string `gorm:"column:name;type:varchar(255)" json:"name" form:"name"` // DNS服务器名称
|
|||
|
|
Port uint `gorm:"column:port;default:53" json:"port" form:"port"` // 监听端口,默认53
|
|||
|
|
ListenIP string `gorm:"column:listen_ip;type:varchar(255)" json:"listen_ip" form:"listen_ip"` // 监听IP,默认0.0.0.0
|
|||
|
|
UpstreamDNS string `gorm:"column:upstream_dns;type:varchar(255)" json:"upstream_dns" form:"upstream_dns"` // 上游DNS服务器,多个用逗号分隔
|
|||
|
|
EnableRecursion bool `gorm:"column:enable_recursion;default:true" json:"enable_recursion" form:"enable_recursion"` // 是否启用递归查询
|
|||
|
|
Status uint `gorm:"column:status;default:0" json:"status" form:"status"` // 状态:0停止,1运行中,2错误
|
|||
|
|
Description string `gorm:"column:description;type:text" json:"description" form:"description"` // 描述
|
|||
|
|
Zones []DNSZone `gorm:"foreignKey:ServerID" json:"zones,omitempty"` // 关联的Zone
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
type DNSZone struct {
|
|||
|
|
gorm.Model
|
|||
|
|
ServerID uint `gorm:"column:server_id;index" json:"server_id" form:"server_id"` // 所属DNS服务器ID
|
|||
|
|
Domain string `gorm:"column:domain;type:varchar(255);index" json:"domain" form:"domain"` // 域名,如 example.com
|
|||
|
|
SOA_MName string `gorm:"column:soa_mname;type:varchar(255)" json:"soa_mname" form:"soa_mname"` // SOA记录的主域名服务器
|
|||
|
|
SOA_RName string `gorm:"column:soa_rname;type:varchar(255)" json:"soa_rname" form:"soa_rname"` // SOA记录的管理员邮箱
|
|||
|
|
SOA_Serial uint `gorm:"column:soa_serial;default:1" json:"soa_serial" form:"soa_serial"` // SOA记录的序列号
|
|||
|
|
SOA_Refresh uint `gorm:"column:soa_refresh;default:86400" json:"soa_refresh" form:"soa_refresh"` // SOA记录的刷新时间(秒)
|
|||
|
|
SOA_Retry uint `gorm:"column:soa_retry;default:7200" json:"soa_retry" form:"soa_retry"` // SOA记录的重试时间(秒)
|
|||
|
|
SOA_Expire uint `gorm:"column:soa_expire;default:3600000" json:"soa_expire" form:"soa_expire"` // SOA记录的过期时间(秒)
|
|||
|
|
SOA_Minimum uint `gorm:"column:soa_minimum;default:3600" json:"soa_minimum" form:"soa_minimum"` // SOA记录的最小TTL(秒)
|
|||
|
|
TTL uint `gorm:"column:ttl;default:3600" json:"ttl" form:"ttl"` // 默认TTL(秒)
|
|||
|
|
Description string `gorm:"column:description;type:text" json:"description" form:"description"` // 描述
|
|||
|
|
Server DNSServer `gorm:"foreignKey:ServerID" json:"server,omitempty"` // 关联的DNS服务器
|
|||
|
|
Records []DNSRecord `gorm:"foreignKey:ZoneID" json:"records,omitempty"` // 关联的记录
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
type DNSRecord struct {
|
|||
|
|
gorm.Model
|
|||
|
|
ZoneID uint `gorm:"column:zone_id;index" json:"zone_id" form:"zone_id"` // 所属Zone ID
|
|||
|
|
Name string `gorm:"column:name;type:varchar(255);index" json:"name" form:"name"` // 记录名称,如 www 或 @
|
|||
|
|
Type uint `gorm:"column:type;index" json:"type" form:"type"` // 记录类型:1=A, 28=AAAA, 5=CNAME, 15=MX等
|
|||
|
|
Value string `gorm:"column:value;type:text" json:"value" form:"value"` // 记录值
|
|||
|
|
TTL uint `gorm:"column:ttl;default:3600" json:"ttl" form:"ttl"` // TTL(秒),如果为0则使用Zone的默认TTL
|
|||
|
|
Priority uint `gorm:"column:priority;default:0" json:"priority" form:"priority"` // 优先级(用于MX、SRV等记录)
|
|||
|
|
Weight uint `gorm:"column:weight;default:0" json:"weight" form:"weight"` // 权重(用于SRV记录)
|
|||
|
|
Port uint `gorm:"column:port;default:0" json:"port" form:"port"` // 端口(用于SRV记录)
|
|||
|
|
Target string `gorm:"column:target;type:varchar(255)" json:"target" form:"target"` // 目标(用于SRV记录)
|
|||
|
|
Zone DNSZone `gorm:"foreignKey:ZoneID" json:"zone,omitempty"` // 关联的Zone
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSServer 创建请求
|
|||
|
|
type CreateDNSServerReq struct {
|
|||
|
|
Name string `json:"name" form:"name"` // DNS服务器名称
|
|||
|
|
Port uint `json:"port" form:"port"` // 监听端口,默认53
|
|||
|
|
ListenIP string `json:"listen_ip" form:"listen_ip"` // 监听IP,默认0.0.0.0
|
|||
|
|
UpstreamDNS string `json:"upstream_dns" form:"upstream_dns"` // 上游DNS服务器,多个用逗号分隔
|
|||
|
|
EnableRecursion bool `json:"enable_recursion" form:"enable_recursion"` // 是否启用递归查询
|
|||
|
|
Description string `json:"description" form:"description"` // 描述
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSServer 更新请求
|
|||
|
|
type UpdateDNSServerReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id"` // DNS服务器ID
|
|||
|
|
Name string `json:"name" form:"name"` // DNS服务器名称
|
|||
|
|
Port uint `json:"port" form:"port"` // 监听端口
|
|||
|
|
ListenIP string `json:"listen_ip" form:"listen_ip"` // 监听IP
|
|||
|
|
UpstreamDNS string `json:"upstream_dns" form:"upstream_dns"` // 上游DNS服务器
|
|||
|
|
EnableRecursion bool `json:"enable_recursion" form:"enable_recursion"` // 是否启用递归查询
|
|||
|
|
Status uint `json:"status" form:"status"` // 状态:0停止,1运行中,2错误
|
|||
|
|
Description string `json:"description" form:"description"` // 描述
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSServer 获取请求
|
|||
|
|
type GetDNSServerReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id"` // DNS服务器ID,0表示获取全部
|
|||
|
|
GetType int `json:"get_type" form:"get_type"` // 获取类型:0获取自己的,1获取全部(管理员)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSServer 删除请求
|
|||
|
|
type DeleteDNSServerReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id"` // DNS服务器ID
|
|||
|
|
DelType uint `json:"del_type" form:"del_type"` // 删除类型:0删除单条,1删除所有
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSZone 创建请求
|
|||
|
|
type CreateDNSZoneReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id"` // 所属DNS服务器ID
|
|||
|
|
Domain string `json:"domain" form:"domain"` // 域名,如 example.com
|
|||
|
|
SOA_MName string `json:"soa_mname" form:"soa_mname"` // SOA记录的主域名服务器
|
|||
|
|
SOA_RName string `json:"soa_rname" form:"soa_rname"` // SOA记录的管理员邮箱
|
|||
|
|
SOA_Serial uint `json:"soa_serial" form:"soa_serial"` // SOA记录的序列号
|
|||
|
|
SOA_Refresh uint `json:"soa_refresh" form:"soa_refresh"` // SOA记录的刷新时间(秒)
|
|||
|
|
SOA_Retry uint `json:"soa_retry" form:"soa_retry"` // SOA记录的重试时间(秒)
|
|||
|
|
SOA_Expire uint `json:"soa_expire" form:"soa_expire"` // SOA记录的过期时间(秒)
|
|||
|
|
SOA_Minimum uint `json:"soa_minimum" form:"soa_minimum"` // SOA记录的最小TTL(秒)
|
|||
|
|
TTL uint `json:"ttl" form:"ttl"` // 默认TTL(秒)
|
|||
|
|
Description string `json:"description" form:"description"` // 描述
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSZone 更新请求
|
|||
|
|
type UpdateDNSZoneReq struct {
|
|||
|
|
ZoneID uint `json:"zone_id" form:"zone_id"` // Zone ID
|
|||
|
|
Domain string `json:"domain" form:"domain"` // 域名
|
|||
|
|
SOA_MName string `json:"soa_mname" form:"soa_mname"` // SOA记录的主域名服务器
|
|||
|
|
SOA_RName string `json:"soa_rname" form:"soa_rname"` // SOA记录的管理员邮箱
|
|||
|
|
SOA_Serial uint `json:"soa_serial" form:"soa_serial"` // SOA记录的序列号
|
|||
|
|
SOA_Refresh uint `json:"soa_refresh" form:"soa_refresh"` // SOA记录的刷新时间(秒)
|
|||
|
|
SOA_Retry uint `json:"soa_retry" form:"soa_retry"` // SOA记录的重试时间(秒)
|
|||
|
|
SOA_Expire uint `json:"soa_expire" form:"soa_expire"` // SOA记录的过期时间(秒)
|
|||
|
|
SOA_Minimum uint `json:"soa_minimum" form:"soa_minimum"` // SOA记录的最小TTL(秒)
|
|||
|
|
TTL uint `json:"ttl" form:"ttl"` // 默认TTL(秒)
|
|||
|
|
Description string `json:"description" form:"description"` // 描述
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSZone 获取请求
|
|||
|
|
type GetDNSZoneReq struct {
|
|||
|
|
ZoneID uint `json:"zone_id" form:"zone_id"` // Zone ID,0表示获取全部
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id"` // DNS服务器ID,用于过滤
|
|||
|
|
GetType int `json:"get_type" form:"get_type"` // 获取类型:0获取自己的,1获取全部(管理员)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSZone 删除请求
|
|||
|
|
type DeleteDNSZoneReq struct {
|
|||
|
|
ZoneID uint `json:"zone_id" form:"zone_id"` // Zone ID
|
|||
|
|
DelType uint `json:"del_type" form:"del_type"` // 删除类型:0删除单条,1删除所有
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSRecord 创建请求
|
|||
|
|
type CreateDNSRecordReq struct {
|
|||
|
|
ZoneID uint `json:"zone_id" form:"zone_id"` // 所属Zone ID
|
|||
|
|
Name string `json:"name" form:"name"` // 记录名称,如 www 或 @
|
|||
|
|
Type uint `json:"type" form:"type"` // 记录类型:1=A, 28=AAAA, 5=CNAME, 15=MX等
|
|||
|
|
Value string `json:"value" form:"value"` // 记录值
|
|||
|
|
TTL uint `json:"ttl" form:"ttl"` // TTL(秒)
|
|||
|
|
Priority uint `json:"priority" form:"priority"` // 优先级(用于MX、SRV等记录)
|
|||
|
|
Weight uint `json:"weight" form:"weight"` // 权重(用于SRV记录)
|
|||
|
|
Port uint `json:"port" form:"port"` // 端口(用于SRV记录)
|
|||
|
|
Target string `json:"target" form:"target"` // 目标(用于SRV记录)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSRecord 更新请求
|
|||
|
|
type UpdateDNSRecordReq struct {
|
|||
|
|
RecordID uint `json:"record_id" form:"record_id"` // 记录ID
|
|||
|
|
Name string `json:"name" form:"name"` // 记录名称
|
|||
|
|
Type uint `json:"type" form:"type"` // 记录类型
|
|||
|
|
Value string `json:"value" form:"value"` // 记录值
|
|||
|
|
TTL uint `json:"ttl" form:"ttl"` // TTL(秒)
|
|||
|
|
Priority uint `json:"priority" form:"priority"` // 优先级
|
|||
|
|
Weight uint `json:"weight" form:"weight"` // 权重
|
|||
|
|
Port uint `json:"port" form:"port"` // 端口
|
|||
|
|
Target string `json:"target" form:"target"` // 目标
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSRecord 获取请求
|
|||
|
|
type GetDNSRecordReq struct {
|
|||
|
|
RecordID uint `json:"record_id" form:"record_id"` // 记录ID,0表示获取全部
|
|||
|
|
ZoneID uint `json:"zone_id" form:"zone_id"` // Zone ID,用于过滤
|
|||
|
|
GetType int `json:"get_type" form:"get_type"` // 获取类型:0获取自己的,1获取全部(管理员)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DNSRecord 删除请求
|
|||
|
|
type DeleteDNSRecordReq struct {
|
|||
|
|
RecordID uint `json:"record_id" form:"record_id"` // 记录ID
|
|||
|
|
DelType uint `json:"del_type" form:"del_type"` // 删除类型:0删除单条,1删除所有
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 启动DNS服务器请求
|
|||
|
|
type StartDNSServerReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id" binding:"required"` // DNS服务器ID
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 停止DNS服务器请求
|
|||
|
|
type StopDNSServerReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id" binding:"required"` // DNS服务器ID
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 重启DNS服务器请求
|
|||
|
|
type RestartDNSServerReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id" binding:"required"` // DNS服务器ID
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 获取DNS服务器状态请求
|
|||
|
|
type GetDNSServerStatusReq struct {
|
|||
|
|
ServerID uint `json:"server_id" form:"server_id" binding:"required"` // DNS服务器ID
|
|||
|
|
}
|