diff --git a/CONFIG.md b/CONFIG.md index ff18b0f..a607242 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -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 diff --git a/CONFIG.zh-CN.md b/CONFIG.zh-CN.md index b14fa39..e56305f 100644 --- a/CONFIG.zh-CN.md +++ b/CONFIG.zh-CN.md @@ -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 diff --git a/internal/cli/config.tpl.yaml b/internal/cli/config.tpl.yaml index d9b8b62..c1cc148 100644 --- a/internal/cli/config.tpl.yaml +++ b/internal/cli/config.tpl.yaml @@ -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 diff --git a/pkg/dns/dns.go b/pkg/dns/dns.go index 66dee5b..8159135 100644 --- a/pkg/dns/dns.go +++ b/pkg/dns/dns.go @@ -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) diff --git a/pkg/ftp/ftp.go b/pkg/ftp/ftp.go index 9b0c3c6..3e2ddef 100644 --- a/pkg/ftp/ftp.go +++ b/pkg/ftp/ftp.go @@ -393,6 +393,7 @@ func (s *Server) Run() { if !s.Enable { _ = listener.Close() } + s.livingLock.Unlock() }() for { diff --git a/pkg/ldap/ldap.go b/pkg/ldap/ldap.go index a0dc4b1..a9451c0 100644 --- a/pkg/ldap/ldap.go +++ b/pkg/ldap/ldap.go @@ -180,6 +180,7 @@ func (s *Server) Run() { if !s.Enable { _ = listener.Close() } + s.livingLock.Unlock() }() for { diff --git a/pkg/mysql/mysql.go b/pkg/mysql/mysql.go index 960047b..f8c47e5 100644 --- a/pkg/mysql/mysql.go +++ b/pkg/mysql/mysql.go @@ -310,6 +310,7 @@ func (s *Server) Run() { if !s.Enable { s.listener.Close() } + s.livingLock.Unlock() }() s.listener.Accept() diff --git a/pkg/rmi/rmi.go b/pkg/rmi/rmi.go index 2d6a50e..6016f79 100644 --- a/pkg/rmi/rmi.go +++ b/pkg/rmi/rmi.go @@ -189,6 +189,7 @@ func (s *Server) Run() { if !s.Enable { _ = listener.Close() } + s.livingLock.Unlock() }() for { diff --git a/pkg/server/config.go b/pkg/server/config.go index b07b150..6749b42 100644 --- a/pkg/server/config.go +++ b/pkg/server/config.go @@ -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 diff --git a/pkg/server/server.go b/pkg/server/server.go index b5cbc28..07cbaf5 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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) diff --git a/pkg/server/settings.go b/pkg/server/settings.go index 5160c33..bebc512 100644 --- a/pkg/server/settings.go +++ b/pkg/server/settings.go @@ -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) {