mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-21 22:30:46 +08:00
feat: add domain and external ip configuration items (#18)
This commit is contained in:
@@ -16,11 +16,14 @@ type noticeConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Addr string
|
||||
Token string
|
||||
Database string
|
||||
LogLevel string `yaml:"log_level"`
|
||||
Notice noticeConfig
|
||||
Version float64
|
||||
Addr string
|
||||
Token string
|
||||
Domain string
|
||||
ExternalIP string `yaml:"external_ip"`
|
||||
Database string
|
||||
LogLevel string `yaml:"log_level"`
|
||||
Notice noticeConfig
|
||||
rhttp.Config
|
||||
DNS dns.Config
|
||||
MySQL mysql.Config
|
||||
|
||||
@@ -59,8 +59,8 @@ func (revsuit *Revsuit) registerHttpRouter() {
|
||||
settingsGroup := revsuit.http.ApiGroup.Group("setting")
|
||||
settingsGroup.GET("/exportRules", exportRules)
|
||||
settingsGroup.POST("/importRules", importRules)
|
||||
settingsGroup.GET("/getHttpConfig", revsuit.getHttpConfig)
|
||||
settingsGroup.POST("/updateHttpConfig", revsuit.updateHttpConfig)
|
||||
settingsGroup.GET("/getPlatformConfig", revsuit.getPlatformConfig)
|
||||
settingsGroup.POST("/updatePlatformConfig", revsuit.updatePlatformConfig)
|
||||
settingsGroup.GET("/getDnsConfig", revsuit.getDnsConfig)
|
||||
settingsGroup.POST("/updateDnsConfig", revsuit.updateDnsConfig)
|
||||
settingsGroup.GET("/getRmiConfig", revsuit.getRmiConfig)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
log "unknwon.dev/clog/v2"
|
||||
)
|
||||
|
||||
const VERSION = "0.1.1-beta"
|
||||
const VERSION = "0.1.2-beta"
|
||||
|
||||
type Revsuit struct {
|
||||
config *Config
|
||||
@@ -181,6 +181,13 @@ func New(c *Config) *Revsuit {
|
||||
if c.IpHeader != "" {
|
||||
s.http.SetIpHeader(c.IpHeader)
|
||||
}
|
||||
if c.Domain != "" {
|
||||
s.dns.SetServerDomain(c.Domain)
|
||||
}
|
||||
if c.ExternalIP != "" {
|
||||
s.dns.SetServerIP(c.ExternalIP)
|
||||
s.ftp.SetPasvIP(c.ExternalIP)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
+32
-7
@@ -138,10 +138,12 @@ func importRules(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (revsuit *Revsuit) getHttpConfig(c *gin.Context) {
|
||||
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["ExternalIP"] = revsuit.config.ExternalIP
|
||||
res["Database"] = revsuit.config.Database
|
||||
res["LogLevel"] = revsuit.config.LogLevel
|
||||
res["IpHeader"] = revsuit.config.IpHeader
|
||||
@@ -149,7 +151,7 @@ func (revsuit *Revsuit) getHttpConfig(c *gin.Context) {
|
||||
c.JSON(200, res)
|
||||
}
|
||||
|
||||
func (revsuit *Revsuit) updateHttpConfig(c *gin.Context) {
|
||||
func (revsuit *Revsuit) updatePlatformConfig(c *gin.Context) {
|
||||
var form = make(map[string]string)
|
||||
|
||||
if err := c.ShouldBindJSON(&form); err != nil {
|
||||
@@ -188,6 +190,34 @@ func (revsuit *Revsuit) updateHttpConfig(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 revsuit.dns.Enable {
|
||||
revsuit.dns.Restart()
|
||||
}
|
||||
}
|
||||
|
||||
if form["ExternalIP"] != revsuit.config.ExternalIP {
|
||||
revsuit.config.ExternalIP = form["ExternalIP"]
|
||||
revsuit.dns.SetServerIP(form["ExternalIP"])
|
||||
revsuit.ftp.SetPasvIP(form["ExternalIP"])
|
||||
log.Info("Update platform config [ExternalIP] to %s", form["ExternalIP"])
|
||||
if revsuit.dns.Enable {
|
||||
revsuit.dns.Restart()
|
||||
}
|
||||
if revsuit.ftp.Enable {
|
||||
revsuit.ftp.Restart()
|
||||
}
|
||||
}
|
||||
|
||||
if form["Token"] != revsuit.config.Token {
|
||||
revsuit.config.Token = form["Token"]
|
||||
revsuit.http.SetToken(form["Token"])
|
||||
log.Info("Update platform config [token] to %s", form["Token"])
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"status": "succeed",
|
||||
"error": nil,
|
||||
@@ -216,11 +246,6 @@ func (revsuit *Revsuit) updateFtpConfig(c *gin.Context) {
|
||||
log.Info("Update ftp config [addr] to %s", form.Addr)
|
||||
}
|
||||
|
||||
if form.PasvIP != revsuit.ftp.PasvIP {
|
||||
revsuit.ftp.PasvIP = form.PasvIP
|
||||
log.Info("Update ftp config [pasv_ip] to %s", form.PasvIP)
|
||||
}
|
||||
|
||||
if form.PasvPort != revsuit.ftp.PasvPort {
|
||||
revsuit.ftp.PasvPort = form.PasvPort
|
||||
log.Info("Update ftp config [pasv_port] to %d", form.PasvPort)
|
||||
|
||||
Reference in New Issue
Block a user