feat(ftp): support receive ftp connection (#6)

Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
Li4n0
2021-04-25 13:39:27 +08:00
committed by GitHub
co-authored by E99p1ant
parent 5e24f9530d
commit 26755351f7
36 changed files with 1446 additions and 141 deletions
+2
View File
@@ -2,6 +2,7 @@ package server
import (
"github.com/li4n0/revsuit/pkg/dns"
"github.com/li4n0/revsuit/pkg/ftp"
"github.com/li4n0/revsuit/pkg/mysql"
"github.com/li4n0/revsuit/pkg/rhttp"
"github.com/li4n0/revsuit/pkg/rmi"
@@ -24,4 +25,5 @@ type Config struct {
DNS dns.Config
MySQL mysql.Config
RMI rmi.Config
FTP ftp.Config
}
+14
View File
@@ -7,6 +7,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/li4n0/revsuit/frontend"
"github.com/li4n0/revsuit/pkg/dns"
"github.com/li4n0/revsuit/pkg/ftp"
"github.com/li4n0/revsuit/pkg/mysql"
"github.com/li4n0/revsuit/pkg/rhttp"
"github.com/li4n0/revsuit/pkg/rmi"
@@ -15,6 +16,11 @@ import (
func (revsuit *Revsuit) registerRouter() {
revsuit.http.Router = gin.Default()
if revsuit.logLevel != log.LevelTrace {
revsuit.http.Router = gin.New()
revsuit.http.Router.Use(gin.Recovery())
}
revsuit.registerPlatformRouter()
revsuit.registerHttpRouter()
}
@@ -61,6 +67,9 @@ func (revsuit *Revsuit) registerHttpRouter() {
rmiGroup := recordGroup.Group("/rmi")
rmiGroup.GET("", rmi.ListRecords)
ftpGroup := recordGroup.Group("/ftp")
ftpGroup.GET("", ftp.ListRecords)
// init rule router group
ruleGroup := revsuit.http.ApiGroup.Group("/rule")
@@ -84,6 +93,11 @@ func (revsuit *Revsuit) registerHttpRouter() {
rmiGroup.POST("", rmi.UpsertRules)
rmiGroup.DELETE("", rmi.DeleteRules)
ftpGroup = ruleGroup.Group("/ftp")
ftpGroup.GET("", ftp.ListRules)
ftpGroup.POST("", ftp.UpsertRules)
ftpGroup.DELETE("", ftp.DeleteRules)
// init file router group
fileGroup := revsuit.http.ApiGroup.Group("/file")
fileGroup.GET("/mysql/:id", mysql.GetFile)
+24 -5
View File
@@ -5,6 +5,7 @@ import (
"github.com/li4n0/revsuit/internal/database"
"github.com/li4n0/revsuit/internal/notice"
"github.com/li4n0/revsuit/pkg/dns"
"github.com/li4n0/revsuit/pkg/ftp"
"github.com/li4n0/revsuit/pkg/mysql"
http "github.com/li4n0/revsuit/pkg/rhttp"
"github.com/li4n0/revsuit/pkg/rmi"
@@ -13,10 +14,13 @@ import (
)
type Revsuit struct {
logLevel log.Level
http *http.Server
dns *dns.Server
mysql *mysql.Server
rmi *rmi.Server
ftp *ftp.Server
}
func initDatabase(dsn string) {
@@ -61,11 +65,18 @@ func initDatabase(dsn string) {
if err != nil {
log.Fatal(err.Error())
}
err = database.DB.AutoMigrate(&ftp.Record{})
if err != nil {
log.Fatal(err.Error())
}
err = database.DB.AutoMigrate(&ftp.Rule{})
if err != nil {
log.Fatal(err.Error())
}
}
func initLog(level string) {
var logLevel log.Level
func initLog(level string) (logLevel log.Level) {
switch level {
case "debug":
@@ -93,7 +104,7 @@ func initLog(level string) {
log.ConsoleConfig{
Level: logLevel,
})
return logLevel
}
func initNotice(nc noticeConfig) {
@@ -123,11 +134,12 @@ func initNotice(nc noticeConfig) {
func New(c *Config) *Revsuit {
initDatabase(c.Database)
initLog(c.LogLevel)
logLevel := initLog(c.LogLevel)
initNotice(c.Notice)
s := &Revsuit{
http: http.GetServer(),
logLevel: logLevel,
http: http.GetServer(),
}
if c.DNS.Enable {
s.dns = dns.GetServer()
@@ -140,6 +152,10 @@ func New(c *Config) *Revsuit {
s.rmi = rmi.GetServer()
s.rmi.Config = c.RMI
}
if c.FTP.Enable {
s.ftp = ftp.GetServer()
s.ftp.Config = c.FTP
}
if c.Addr != "" {
s.http.SetAddr(c.Addr)
@@ -166,6 +182,9 @@ func (revsuit *Revsuit) Run() {
if revsuit.rmi != nil {
go revsuit.rmi.Run()
}
if revsuit.ftp != nil {
go revsuit.ftp.Run()
}
revsuit.http.Run()
}