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