diff --git a/config.example.yml b/config.example.yml index 9e27d34c36..0bcb6353fb 100644 --- a/config.example.yml +++ b/config.example.yml @@ -1,5 +1,3 @@ -# 警告:未经指导私自修改此配置文件可能导致严重后果 -# Warning: Modifying this configuration file without guidance may cause serious consequences app: debug: false key: a-long-string-with-32-characters diff --git a/go.mod b/go.mod index 5c73b5c2d1..0b810b025a 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/TheTNB/panel go 1.23 require ( + github.com/bddjr/hlfhr v1.1.2 github.com/beevik/ntp v1.4.3 github.com/docker/docker v27.3.1+incompatible github.com/docker/go-connections v0.5.0 @@ -19,7 +20,6 @@ require ( github.com/go-rat/utils v1.0.3 github.com/go-resty/resty/v2 v2.15.3 github.com/go-sql-driver/mysql v1.8.1 - github.com/goccy/go-yaml v1.12.0 github.com/gorilla/websocket v1.5.3 github.com/hashicorp/go-version v1.7.0 github.com/klauspost/compress v1.17.11 @@ -46,6 +46,7 @@ require ( golang.org/x/crypto v0.28.0 golang.org/x/net v0.30.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 + gopkg.in/yaml.v3 v3.0.1 gorm.io/gorm v1.25.12 moul.io/zapgorm2 v1.3.0 ) @@ -54,7 +55,6 @@ require ( filippo.io/edwards25519 v1.1.0 // indirect github.com/Microsoft/go-winio v0.4.14 // indirect github.com/andybalholm/brotli v1.0.4 // indirect - github.com/bddjr/hlfhr v1.1.2 // indirect github.com/bodgit/plumbing v1.2.0 // indirect github.com/bodgit/sevenzip v1.3.0 // indirect github.com/bodgit/windows v1.0.0 // indirect @@ -66,7 +66,6 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/fatih/color v1.10.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gabriel-vasile/mimetype v1.4.5 // indirect @@ -88,7 +87,6 @@ require ( github.com/klauspost/pgzip v1.2.6 // indirect github.com/knadh/koanf/maps v0.1.1 // indirect github.com/leodido/go-urn v1.4.0 // indirect - github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect @@ -120,11 +118,9 @@ require ( go4.org v0.0.0-20200411211856-f5505b9728dd // indirect golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 // indirect - golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect modernc.org/libc v1.60.1 // indirect modernc.org/mathutil v1.6.0 // indirect modernc.org/memory v1.8.0 // indirect diff --git a/go.sum b/go.sum index 074fdfaf29..1314ed9bf9 100644 --- a/go.sum +++ b/go.sum @@ -71,8 +71,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI= github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= @@ -122,8 +120,6 @@ github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpv github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAprG2mQfMfc= github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= -github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM= -github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= github.com/gofiber/schema v1.2.0 h1:j+ZRrNnUa/0ZuWrn/6kAtAufEr4jCJ+JuTURAMxNSZg= github.com/gofiber/schema v1.2.0/go.mod h1:YYwj01w3hVfaNjhtJzaqetymL56VW642YS3qZPhuE6c= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -228,9 +224,6 @@ github.com/libdns/libdns v0.2.2 h1:O6ws7bAfRPaBsgAYt8MDe2HcNBGC29hkZ9MX2eUSX3s= github.com/libdns/libdns v0.2.2/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ= github.com/libdns/tencentcloud v1.0.0 h1:u4LXnYu/lu/9P5W+MCVPeSDnwI+6w+DxYhQ1wSnQOuU= github.com/libdns/tencentcloud v1.0.0/go.mod h1:NlCgPumzUsZWSOo1+Q/Hfh8G6TNRAaTUeWQdg6LbtUI= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mholt/archiver/v4 v4.0.0-alpha.8 h1:tRGQuDVPh66WCOelqe6LIGh0gwmfwxUrSSDunscGsRM= @@ -444,7 +437,6 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -520,8 +512,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= diff --git a/internal/data/setting.go b/internal/data/setting.go index c36b85ec62..32392bf975 100644 --- a/internal/data/setting.go +++ b/internal/data/setting.go @@ -8,8 +8,8 @@ import ( "slices" "github.com/go-rat/utils/hash" - "github.com/goccy/go-yaml" "github.com/spf13/cast" + "gopkg.in/yaml.v3" "gorm.io/gorm" "github.com/TheTNB/panel/internal/app" @@ -194,12 +194,11 @@ func (r *settingRepo) UpdatePanelSetting(ctx context.Context, setting *request.P // 面板主配置 config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return false, err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return false, err } @@ -221,7 +220,7 @@ func (r *settingRepo) UpdatePanelSetting(ctx context.Context, setting *request.P return false, err } - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return false, err } diff --git a/internal/service/cli.go b/internal/service/cli.go index 34b5a68426..d391426af4 100644 --- a/internal/service/cli.go +++ b/internal/service/cli.go @@ -8,9 +8,9 @@ import ( "time" "github.com/go-rat/utils/hash" - "github.com/goccy/go-yaml" "github.com/spf13/cast" "github.com/urfave/cli/v3" + "gopkg.in/yaml.v3" "gorm.io/gorm" "github.com/TheTNB/panel/internal/app" @@ -237,18 +237,17 @@ func (s *CliService) UserPassword(ctx context.Context, cmd *cli.Command) error { func (s *CliService) HTTPSOn(ctx context.Context, cmd *cli.Command) error { config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return err } config.HTTP.TLS = true - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return err } @@ -263,18 +262,17 @@ func (s *CliService) HTTPSOn(ctx context.Context, cmd *cli.Command) error { func (s *CliService) HTTPSOff(ctx context.Context, cmd *cli.Command) error { config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return err } config.HTTP.TLS = false - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return err } @@ -320,18 +318,17 @@ func (s *CliService) HTTPSGenerate(ctx context.Context, cmd *cli.Command) error func (s *CliService) EntranceOn(ctx context.Context, cmd *cli.Command) error { config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return err } config.HTTP.Entrance = "/" + str.RandomString(6) - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return err } @@ -347,18 +344,17 @@ func (s *CliService) EntranceOn(ctx context.Context, cmd *cli.Command) error { func (s *CliService) EntranceOff(ctx context.Context, cmd *cli.Command) error { config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return err } config.HTTP.Entrance = "/" - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return err } @@ -378,18 +374,17 @@ func (s *CliService) Port(ctx context.Context, cmd *cli.Command) error { } config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return err } config.HTTP.Port = port - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return err } @@ -776,19 +771,18 @@ func (s *CliService) Init(ctx context.Context, cmd *cli.Command) error { } config := new(types.PanelConfig) - cm := yaml.CommentMap{} raw, err := io.Read("/usr/local/etc/panel/config.yml") if err != nil { return err } - if err = yaml.UnmarshalWithOptions([]byte(raw), config, yaml.CommentToMap(cm)); err != nil { + if err = yaml.Unmarshal([]byte(raw), config); err != nil { return err } config.App.Key = str.RandomString(32) config.HTTP.Entrance = "/" + str.RandomString(6) - encoded, err := yaml.MarshalWithOptions(config, yaml.WithComment(cm)) + encoded, err := yaml.Marshal(config) if err != nil { return err }