feat(dns): support use multiple root domains (#51)

This commit is contained in:
Li4n0
2022-01-07 23:48:45 +08:00
committed by GitHub
parent fc505b0733
commit 913e0f78db
11 changed files with 59 additions and 41 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ RevSuit will generate a profile template the first time it is run, and you can e
version: 1.3
addr: :10000 # Address of the HTTP service will listen
token: # Authentication Token, both the admin page and the client need to be authenticated by this Token
domain: # The domain name used by the platform
domains: [] # The domain names used by the platform
external_ip: # The external IP of the platform, you need to make sure that the target you want to test can access the platform through this IP
admin_path_prefix: "/revsuit" # The http path prefix for the admin page, the page will be located at: /admin_path_prefix/admin
database: revsuit.db # Database connection information, support using Sqlite3, MySQL, Postgres
+1 -1
View File
@@ -4,7 +4,7 @@
version: 1.3
addr: :10000 # HTTP 服务监听的地址
token: # 鉴权Token,管理页面和客户端都需要通过该 Token 进行鉴权
domain: # 反连平台绑定的域名
domains: [] # 反连平台绑定的域名
external_ip: # 反连平台的外部IP,需要确保你想测试的目标能通过该 IP 访问到平台
admin_path_prefix: "/revsuit" # 管理页面的 http path 前缀,管理页面将位于:/admin_path_prefix/admin
database: revsuit.db # 数据库连接信息 支持Sqlite3、MySQL、Postgres
+2 -2
View File
@@ -1,7 +1,7 @@
version: 1.4
version: 1.5
addr: :10000
token:
domain:
domains: []
external_ip: # You need to make sure that your target can access the server through this ip.
admin_path_prefix: "/revsuit"
database: revsuit.db
+32 -29
View File
@@ -17,11 +17,11 @@ import (
type Server struct {
Config
serverDomain string
serverIP string
rules []*Rule
rulesLock sync.RWMutex
livingLock sync.Mutex
serverDomains []string
serverIP string
rules []*Rule
rulesLock sync.RWMutex
livingLock sync.Mutex
}
var (
@@ -37,8 +37,8 @@ func GetServer() *Server {
return server
}
func (s *Server) SetServerDomain(serverDomain string) *Server {
s.serverDomain = serverDomain
func (s *Server) SetServerDomain(serverDomains []string) *Server {
s.serverDomains = serverDomains
return s
}
@@ -217,39 +217,42 @@ func (s *Server) Run() {
// create server
server := newdns.NewServer(newdns.Config{
Handler: func(name string) (*newdns.Zone, error) {
if name == s.serverDomain+"." {
return &newdns.Zone{
Name: getZoneName(s.serverDomain),
MasterNameServer: "ns1.hostmaster.com.",
AllNameServers: []string{
"ns1.hostmaster.com.",
"ns2.hostmaster.com.",
"ns3.hostmaster.com.",
},
Handler: func(_, remoteAddr string) ([]newdns.Set, error) {
return []newdns.Set{
{
Name: name,
Type: newdns.A,
TTL: 10,
Records: []newdns.Record{
{
Address: s.serverIP,
},
}}}, nil
}}, nil
for _, serverDomain := range s.serverDomains {
if name == serverDomain+"." {
return &newdns.Zone{
Name: getZoneName(serverDomain),
MasterNameServer: "ns1.hostmaster.com.",
AllNameServers: []string{
"ns1.hostmaster.com.",
"ns2.hostmaster.com.",
"ns3.hostmaster.com.",
},
Handler: func(_, remoteAddr string) ([]newdns.Set, error) {
return []newdns.Set{
{
Name: name,
Type: newdns.A,
TTL: 10,
Records: []newdns.Record{
{
Address: s.serverIP,
},
}}}, nil
}}, nil
}
}
return s.newZone(name), nil
},
})
// run server
log.Info("Starting DNS Server at :53, resolve %s to %s", s.serverDomain, s.serverIP)
log.Info("Starting DNS Server at :53, resolve %v to %s", s.serverDomains, s.serverIP)
go func() {
s.livingLock.Lock()
if !s.Enable {
server.Close()
}
s.livingLock.Unlock()
}()
err := server.Run(s.Addr)
+1
View File
@@ -393,6 +393,7 @@ func (s *Server) Run() {
if !s.Enable {
_ = listener.Close()
}
s.livingLock.Unlock()
}()
for {
+1
View File
@@ -180,6 +180,7 @@ func (s *Server) Run() {
if !s.Enable {
_ = listener.Close()
}
s.livingLock.Unlock()
}()
for {
+1
View File
@@ -310,6 +310,7 @@ func (s *Server) Run() {
if !s.Enable {
s.listener.Close()
}
s.livingLock.Unlock()
}()
s.listener.Accept()
+1
View File
@@ -189,6 +189,7 @@ func (s *Server) Run() {
if !s.Enable {
_ = listener.Close()
}
s.livingLock.Unlock()
}()
for {
+1 -1
View File
@@ -21,7 +21,7 @@ type Config struct {
Version float64
Addr string
Token string
Domain string
Domains []string
ExternalIP string `yaml:"external_ip"`
AdminPathPrefix string `yaml:"admin_path_prefix"`
Database string
+2 -2
View File
@@ -195,8 +195,8 @@ func New(c *Config) *Revsuit {
if c.HTTP.IpHeader != "" {
s.http.SetIpHeader(c.HTTP.IpHeader)
}
if c.Domain != "" {
s.dns.SetServerDomain(c.Domain)
if len(c.Domains) != 0 {
s.dns.SetServerDomain(c.Domains)
}
if c.ExternalIP != "" {
s.dns.SetServerIP(c.ExternalIP)
+16 -5
View File
@@ -3,6 +3,7 @@ package server
import (
"fmt"
"io"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -166,7 +167,7 @@ func (revsuit *Revsuit) getPlatformConfig(c *gin.Context) {
var res = make(map[string]string)
res["Addr"] = revsuit.config.Addr
res["Token"] = revsuit.config.Token
res["Domain"] = revsuit.config.Domain
res["Domains"] = strings.Join(revsuit.config.Domains, ",")
res["AdminPathPrefix"] = revsuit.config.AdminPathPrefix
res["ExternalIP"] = revsuit.config.ExternalIP
res["Database"] = revsuit.config.Database
@@ -215,10 +216,10 @@ func (revsuit *Revsuit) updatePlatformConfig(c *gin.Context) {
log.Info("Update http config [ip_header] to %s", form["IpHeader"])
}
if form["Domain"] != revsuit.config.Domain {
revsuit.config.Domain = form["Domain"]
revsuit.dns.SetServerDomain(form["Domain"])
log.Info("Update platform config [domain] to %s", form["Domain"])
if form["Domains"] != strings.Join(revsuit.config.Domains, ",") {
revsuit.config.Domains = strings.Split(form["Domains"], ",")
revsuit.dns.SetServerDomain(revsuit.config.Domains)
log.Info("Update platform config [domain] to %v", revsuit.config.Domains)
if revsuit.dns.Enable {
revsuit.dns.Restart()
}
@@ -307,6 +308,11 @@ func (revsuit *Revsuit) updateDnsConfig(c *gin.Context) {
return
}
if form.Addr != revsuit.dns.Addr {
revsuit.dns.Addr = form.Addr
log.Info("Update dns config [addr] to %s", form.Addr)
}
if form.Enable != revsuit.dns.Enable {
log.Info("Update dns config [enable] to %v", form.Enable)
if form.Enable {
@@ -316,6 +322,11 @@ func (revsuit *Revsuit) updateDnsConfig(c *gin.Context) {
}
return
}
if revsuit.dns.Enable {
revsuit.dns.Restart()
}
}
func (revsuit *Revsuit) getMySQLConfig(c *gin.Context) {