diff --git a/backend/server/server.go b/backend/server/server.go index 0464acc9c..988949dd2 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -4,14 +4,11 @@ import ( "net" "net/http" + "github.com/1Panel-dev/1Panel/backend/cron" + "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/i18n" - "github.com/1Panel-dev/1Panel/backend/init/app" "github.com/1Panel-dev/1Panel/backend/init/business" - - "github.com/1Panel-dev/1Panel/backend/cron" - - "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/init/db" "github.com/1Panel-dev/1Panel/backend/init/hook" "github.com/1Panel-dev/1Panel/backend/init/log" @@ -40,10 +37,10 @@ func Start() { rootRouter := router.Routers() server := &http.Server{ - Addr: ":9999", + Addr: "0.0.0.0:9998", Handler: rootRouter, } - ln, err := net.Listen("tcp4", ":9999") + ln, err := net.Listen("tcp4", "0.0.0.0:9998") if err != nil { panic(err) } @@ -51,7 +48,7 @@ func Start() { *net.TCPListener } - global.LOG.Info("listen at http://0.0.0.0:9999") + global.LOG.Info("listen at http://0.0.0.0:9998") if err := server.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)}); err != nil { panic(err) } diff --git a/cmd/server/main.go b/cmd/server/main.go index 7a45faa10..e9af05c8d 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,8 +3,8 @@ package main import ( _ "net/http/pprof" + "github.com/1Panel-dev/1Panel/backend/server" _ "github.com/1Panel-dev/1Panel/cmd/server/docs" - "github.com/1Panel-dev/1Panel/server" ) // @title 1Panel diff --git a/core/cmd/server/conf/app.yaml b/core/cmd/server/conf/app.yaml index 0da0e5163..61c29db47 100644 --- a/core/cmd/server/conf/app.yaml +++ b/core/cmd/server/conf/app.yaml @@ -1,5 +1,6 @@ system: - db_file: 1Panel.db + db_core_file: 1Panel_Core.db + db_file: 1Panel_Core.db base_dir: /opt mode: dev repo_url: https://resource.fit2cloud.com/1panel/package diff --git a/core/configs/system.go b/core/configs/system.go index 57a24be67..1f165c489 100644 --- a/core/configs/system.go +++ b/core/configs/system.go @@ -5,7 +5,7 @@ type System struct { Ipv6 string `mapstructure:"ipv6"` BindAddress string `mapstructure:"bindAddress"` SSL string `mapstructure:"ssl"` - DbFile string `mapstructure:"db_file"` + DbCoreFile string `mapstructure:"db_core_file"` DbPath string `mapstructure:"db_path"` LogPath string `mapstructure:"log_path"` DataDir string `mapstructure:"data_dir"` diff --git a/core/init/db/db.go b/core/init/db/db.go index c8aaf9f0e..63051b6b5 100644 --- a/core/init/db/db.go +++ b/core/init/db/db.go @@ -18,7 +18,7 @@ func Init() { panic(fmt.Errorf("init db dir failed, err: %v", err)) } } - fullPath := global.CONF.System.DbPath + "/" + global.CONF.System.DbFile + fullPath := global.CONF.System.DbPath + "/" + global.CONF.System.DbCoreFile if _, err := os.Stat(fullPath); err != nil { f, err := os.Create(fullPath) if err != nil { @@ -44,7 +44,6 @@ func Init() { if err != nil { panic(err) } - _ = db.Exec("PRAGMA journal_mode = WAL;") sqlDB, dbError := db.DB() if dbError != nil { panic(dbError) diff --git a/core/init/migration/migrations/init.go b/core/init/migration/migrations/init.go index 5285d20f9..4e3bed392 100644 --- a/core/init/migration/migrations/init.go +++ b/core/init/migration/migrations/init.go @@ -50,7 +50,14 @@ var InitSetting = &gormigrate.Migration{ if err := tx.Create(&model.Setting{Key: "SessionTimeout", Value: "86400"}).Error; err != nil { return err } - if err := tx.Create(&model.Setting{Key: "LocalTime", Value: ""}).Error; err != nil { + + if err := tx.Create(&model.Setting{Key: "SSLType", Value: "self"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "SSLID", Value: "0"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "SSL", Value: "disable"}).Error; err != nil { return err } @@ -75,7 +82,7 @@ var InitSetting = &gormigrate.Migration{ if err := tx.Create(&model.Setting{Key: "PrsoxyPasswdKeep", Value: ""}).Error; err != nil { return err } - if err := tx.Create(&model.Setting{Key: "XpackHideMenu", Value: "{\"id\":\"1\",\"label\":\"/xpack\",\"isCheck\":true,\"title\":\"xpack.menu\",\"children\":[{\"id\":\"2\",\"title\":\"xpack.waf.name\",\"path\":\"/xpack/waf/dashboard\",\"label\":\"Dashboard\",\"isCheck\":true},{\"id\":\"3\",\"title\":\"xpack.tamper.tamper\",\"path\":\"/xpack/tamper\",\"label\":\"Tamper\",\"isCheck\":true},{\"id\":\"4\",\"title\":\"xpack.gpu.gpu\",\"path\":\"/xpack/gpu\",\"label\":\"GPU\",\"isCheck\":true},{\"id\":\"5\",\"title\":\"xpack.setting.setting\",\"path\":\"/xpack/setting\",\"label\":\"XSetting\",\"isCheck\":true},{\"id\":\"6\",\"title\":\"xpack.monitor.name\",\"path\":\"/xpack/monitor/dashboard\",\"label\":\"MonitorDashboard\",\"isCheck\":true},{\"id\":\"7\",\"title\":\"xpack.multihost\",\"path\":\"/xpack/multihost/manage\",\"label\":\"Multihost\",\"isCheck\":true}]}"}).Error; err != nil { + if err := tx.Create(&model.Setting{Key: "XpackHideMenu", Value: "{\"id\":\"1\",\"label\":\"/xpack\",\"isCheck\":true,\"title\":\"xpack.menu\",\"children\":[{\"id\":\"2\",\"title\":\"xpack.waf.name\",\"path\":\"/xpack/waf/dashboard\",\"label\":\"Dashboard\",\"isCheck\":true},{\"id\":\"3\",\"title\":\"xpack.tamper.tamper\",\"path\":\"/xpack/tamper\",\"label\":\"Tamper\",\"isCheck\":true},{\"id\":\"4\",\"title\":\"xpack.gpu.gpu\",\"path\":\"/xpack/gpu\",\"label\":\"GPU\",\"isCheck\":true},{\"id\":\"5\",\"title\":\"xpack.setting.setting\",\"path\":\"/xpack/setting\",\"label\":\"XSetting\",\"isCheck\":true},{\"id\":\"6\",\"title\":\"xpack.monitor.name\",\"path\":\"/xpack/monitor/dashboard\",\"label\":\"MonitorDashboard\",\"isCheck\":true},{\"id\":\"7\",\"title\":\"xpack.multihost.agentManagement\",\"path\":\"/xpack/multihost/manage\",\"label\":\"Multihost\",\"isCheck\":true}]}"}).Error; err != nil { return err } @@ -109,12 +116,21 @@ var InitSetting = &gormigrate.Migration{ if err := tx.Create(&model.Setting{Key: "SystemVersion", Value: global.CONF.System.Version}).Error; err != nil { return err } + if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil { + return err + } if err := tx.Create(&model.Setting{Key: "BindAddress", Value: "0.0.0.0"}).Error; err != nil { return err } if err := tx.Create(&model.Setting{Key: "Ipv6", Value: "disable"}).Error; err != nil { return err } + if err := tx.Create(&model.Setting{Key: "BindDomain", Value: ""}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "AllowIPs", Value: ""}).Error; err != nil { + return err + } if err := tx.Create(&model.Setting{Key: "NoAuthSetting", Value: "200"}).Error; err != nil { return err } diff --git a/core/init/router/router.go b/core/init/router/router.go index ba39d1274..bc302f6d1 100644 --- a/core/init/router/router.go +++ b/core/init/router/router.go @@ -52,6 +52,7 @@ func Routers() *gin.Engine { }) Router.Use(i18n.UseI18n()) + Router.Use(middleware.Proxy()) swaggerRouter := Router.Group("1panel") docs.SwaggerInfo.BasePath = "/api/v1" diff --git a/core/middleware/proxy.go b/core/middleware/proxy.go new file mode 100644 index 000000000..0c06e5e08 --- /dev/null +++ b/core/middleware/proxy.go @@ -0,0 +1,30 @@ +package middleware + +import ( + "fmt" + "net/http/httputil" + "net/url" + "strings" + + "github.com/gin-gonic/gin" +) + +func Proxy() gin.HandlerFunc { + return func(c *gin.Context) { + if strings.HasPrefix(c.Request.URL.Path, "/api/v1/auth") || + strings.HasPrefix(c.Request.URL.Path, "/api/v1/setting") || + strings.HasPrefix(c.Request.URL.Path, "/api/v1/log") { + c.Next() + return + } + target, err := url.Parse("http://127.0.0.1:9998") + if err != nil { + fmt.Printf("Failed to parse target URL: %v", err) + } + proxy := httputil.NewSingleHostReverseProxy(target) + c.Request.Host = target.Host + c.Request.URL.Scheme = target.Scheme + c.Request.URL.Host = target.Host + proxy.ServeHTTP(c.Writer, c.Request) + } +}