diff --git a/backend/app/api/v1/database_postgresql.go b/backend/app/api/v1/database_postgresql.go index 9a434b3e0..5bd5f093a 100644 --- a/backend/app/api/v1/database_postgresql.go +++ b/backend/app/api/v1/database_postgresql.go @@ -164,24 +164,6 @@ func (b *BaseApi) SearchPostgresql(c *gin.Context) { }) } -// @Tags Database Postgresql -// @Summary List postgresql database names -// @Description 获取 postgresql 数据库列表 -// @Accept json -// @Param request body dto.PageInfo true "request" -// @Success 200 {array} dto.PostgresqlOption -// @Security ApiKeyAuth -// @Router /databases/pg/options [get] -func (b *BaseApi) ListPostgresqlDBName(c *gin.Context) { - list, err := postgresqlService.ListDBOption() - if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - helper.SuccessWithData(c, list) -} - // @Tags Database Postgresql // @Summary Load postgresql database from remote // @Description 从服务器获取 diff --git a/backend/init/cache/badger_db/badger_db.go b/backend/init/cache/badger_db/badger_db.go index c711f3524..a1508503a 100644 --- a/backend/init/cache/badger_db/badger_db.go +++ b/backend/init/cache/badger_db/badger_db.go @@ -5,7 +5,6 @@ import ( "time" "github.com/dgraph-io/badger/v4" - "github.com/pkg/errors" ) type Cache struct { @@ -18,18 +17,6 @@ func NewCacheDB(db *badger.DB) *Cache { } } -func (c *Cache) SetNX(key string, value interface{}) error { - err := c.db.Update(func(txn *badger.Txn) error { - _, err := txn.Get([]byte(key)) - if errors.Is(err, badger.ErrKeyNotFound) { - v := []byte(fmt.Sprintf("%v", value)) - return txn.Set([]byte(key), v) - } - return err - }) - return err -} - func (c *Cache) Set(key string, value interface{}) error { err := c.db.Update(func(txn *badger.Txn) error { v := []byte(fmt.Sprintf("%v", value)) diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index 7b4423791..687f5b25b 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -3,7 +3,6 @@ package common import ( "crypto/rand" "fmt" - "golang.org/x/net/idna" "io" mathRand "math/rand" "net" @@ -15,6 +14,8 @@ import ( "time" "unicode" + "golang.org/x/net/idna" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" ) @@ -143,15 +144,6 @@ func ScanPortWithProto(port int, proto string) bool { return ScanPort(port) } -func ExistWithStrArray(str string, arr []string) bool { - for _, a := range arr { - if strings.Contains(a, str) { - return true - } - } - return false -} - func IsNum(s string) bool { _, err := strconv.ParseFloat(s, 64) return err == nil diff --git a/backend/utils/docker/compose.go b/backend/utils/docker/compose.go index 6d2f1fca5..ffe145780 100644 --- a/backend/utils/docker/compose.go +++ b/backend/utils/docker/compose.go @@ -2,6 +2,11 @@ package docker import ( "context" + "path" + "regexp" + "strings" + "time" + "github.com/compose-spec/compose-go/v2/loader" "github.com/compose-spec/compose-go/v2/types" "github.com/docker/cli/cli/command" @@ -10,10 +15,6 @@ import ( "github.com/docker/compose/v2/pkg/compose" "github.com/docker/docker/client" "github.com/joho/godotenv" - "path" - "regexp" - "strings" - "time" ) type ComposeService struct { @@ -21,50 +22,6 @@ type ComposeService struct { project *types.Project } -func (s ComposeService) SetProject(project *types.Project) { - s.project = project - for i, s := range project.Services { - s.CustomLabels = map[string]string{ - api.ProjectLabel: project.Name, - api.ServiceLabel: s.Name, - api.VersionLabel: api.ComposeVersion, - api.WorkingDirLabel: project.WorkingDir, - api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","), - api.OneoffLabel: "False", - } - project.Services[i] = s - } -} - -func (s ComposeService) ComposeUp() error { - return s.Up(context.Background(), s.project, api.UpOptions{ - Create: api.CreateOptions{ - Timeout: getComposeTimeout(), - }, - Start: api.StartOptions{ - WaitTimeout: *getComposeTimeout(), - }, - }) -} - -func NewComposeService(ops ...command.DockerCliOption) (*ComposeService, error) { - apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) - if err != nil { - return nil, err - } - ops = append(ops, command.WithAPIClient(apiClient), command.WithDefaultContextStoreConfig()) - cli, err := command.NewDockerCli(ops...) - if err != nil { - return nil, err - } - cliOp := flags.NewClientOptions() - if err := cli.Initialize(cliOp); err != nil { - return nil, err - } - service := compose.NewComposeService(cli) - return &ComposeService{service, nil}, nil -} - func UpComposeProject(project *types.Project) error { for i, s := range project.Services { s.CustomLabels = map[string]string{ diff --git a/backend/utils/docker/docker.go b/backend/utils/docker/docker.go index d557ff911..260fe5d6a 100644 --- a/backend/utils/docker/docker.go +++ b/backend/utils/docker/docker.go @@ -2,6 +2,7 @@ package docker import ( "context" + "github.com/docker/docker/api/types/container" "github.com/1Panel-dev/1Panel/backend/app/model" @@ -45,15 +46,6 @@ func NewDockerClient() (*client.Client, error) { return cli, nil } -func (c Client) ListAllContainers() ([]types.Container, error) { - var options container.ListOptions - containers, err := c.cli.ContainerList(context.Background(), options) - if err != nil { - return nil, err - } - return containers, nil -} - func (c Client) ListContainersByName(names []string) ([]types.Container, error) { var ( options container.ListOptions diff --git a/backend/utils/encrypt/encrypt.go b/backend/utils/encrypt/encrypt.go index fe4a35ca7..62d4e1cde 100644 --- a/backend/utils/encrypt/encrypt.go +++ b/backend/utils/encrypt/encrypt.go @@ -4,10 +4,8 @@ import ( "bytes" "crypto/aes" "crypto/cipher" - "crypto/md5" "crypto/rand" "encoding/base64" - "encoding/hex" "fmt" "io" @@ -61,12 +59,6 @@ func StringDecrypt(text string) (string, error) { return "", err } -func Md5(str string) string { - h := md5.New() - h.Write([]byte(str)) - return hex.EncodeToString(h.Sum(nil)) -} - func padding(plaintext []byte, blockSize int) []byte { padding := blockSize - len(plaintext)%blockSize padtext := bytes.Repeat([]byte{byte(padding)}, padding) diff --git a/backend/utils/files/file_op.go b/backend/utils/files/file_op.go index 50460c6c6..489c3f409 100644 --- a/backend/utils/files/file_op.go +++ b/backend/utils/files/file_op.go @@ -7,11 +7,6 @@ import ( "crypto/tls" "encoding/json" "fmt" - "github.com/1Panel-dev/1Panel/backend/utils/cmd" - http2 "github.com/1Panel-dev/1Panel/backend/utils/http" - cZip "github.com/klauspost/compress/zip" - "golang.org/x/text/encoding/simplifiedchinese" - "golang.org/x/text/transform" "io" "io/fs" "net/http" @@ -23,6 +18,12 @@ import ( "sync" "time" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" + http2 "github.com/1Panel-dev/1Panel/backend/utils/http" + cZip "github.com/klauspost/compress/zip" + "golang.org/x/text/encoding/simplifiedchinese" + "golang.org/x/text/transform" + "github.com/1Panel-dev/1Panel/backend/global" "github.com/mholt/archiver/v4" "github.com/pkg/errors" @@ -85,10 +86,6 @@ func (f FileOp) DeleteFile(dst string) error { return f.Fs.Remove(dst) } -func (f FileOp) Delete(dst string) error { - return os.RemoveAll(dst) -} - func (f FileOp) CleanDir(dst string) error { return cmd.ExecCmd(fmt.Sprintf("rm -rf %s/*", dst)) } @@ -129,14 +126,6 @@ func (f FileOp) SaveFile(dst string, content string, mode fs.FileMode) error { return nil } -func (f FileOp) Chmod(dst string, mode fs.FileMode) error { - return f.Fs.Chmod(dst, mode) -} - -func (f FileOp) Chown(dst string, uid int, gid int) error { - return f.Fs.Chown(dst, uid, gid) -} - func (f FileOp) ChownR(dst string, uid string, gid string, sub bool) error { cmdStr := fmt.Sprintf(`chown %s:%s "%s"`, uid, gid, dst) if sub { @@ -563,40 +552,6 @@ func (f FileOp) Decompress(srcFile string, dst string, cType CompressType) error return nil } -func (f FileOp) Backup(srcFile string) (string, error) { - backupPath := srcFile + "_bak" - info, _ := f.Fs.Stat(backupPath) - if info != nil { - if info.IsDir() { - _ = f.DeleteDir(backupPath) - } else { - _ = f.DeleteFile(backupPath) - } - } - if err := f.Rename(srcFile, backupPath); err != nil { - return backupPath, err - } - - return backupPath, nil -} - -func (f FileOp) CopyAndBackup(src string) (string, error) { - backupPath := src + "_bak" - info, _ := f.Fs.Stat(backupPath) - if info != nil { - if info.IsDir() { - _ = f.DeleteDir(backupPath) - } else { - _ = f.DeleteFile(backupPath) - } - } - _ = f.CreateDir(backupPath, 0755) - if err := f.Copy(src, backupPath); err != nil { - return backupPath, err - } - return backupPath, nil -} - func ZipFile(files []archiver.File, dst afero.File) error { zw := zip.NewWriter(dst) defer zw.Close() diff --git a/backend/utils/ini_conf/ini.go b/backend/utils/ini_conf/ini.go index b2ee144a3..4ea80a2a6 100644 --- a/backend/utils/ini_conf/ini.go +++ b/backend/utils/ini_conf/ini.go @@ -17,20 +17,3 @@ func GetIniValue(filePath, Group, Key string) (string, error) { } return startKey.Value(), nil } - -func SetIniValue(filePath, Group, Key, value string) error { - cfg, err := ini.Load(filePath) - if err != nil { - return err - } - service, err := cfg.GetSection(Group) - if err != nil { - return err - } - targetKey := service.Key(Key) - if err != nil { - return err - } - targetKey.SetValue(value) - return cfg.SaveTo(filePath) -} diff --git a/backend/utils/mysql/client/info.go b/backend/utils/mysql/client/info.go index 9f2ffb6b1..8b9320a49 100644 --- a/backend/utils/mysql/client/info.go +++ b/backend/utils/mysql/client/info.go @@ -102,25 +102,6 @@ var formatMap = map[string]string{ "big5": "big5_chinese_ci", } -func VerifyPeerCertFunc(pool *x509.CertPool) func([][]byte, [][]*x509.Certificate) error { - return func(rawCerts [][]byte, _ [][]*x509.Certificate) error { - if len(rawCerts) == 0 { - return errors.New("no certificates available to verify") - } - - cert, err := x509.ParseCertificate(rawCerts[0]) - if err != nil { - return err - } - - opts := x509.VerifyOptions{Roots: pool} - if _, err = cert.Verify(opts); err != nil { - return err - } - return nil - } -} - func ConnWithSSL(ssl, skipVerify bool, clientKey, clientCert, rootCert string) (string, error) { if !ssl { return "", nil diff --git a/backend/utils/mysql/helper/dump.go b/backend/utils/mysql/helper/dump.go index 4e1f85e4d..4c14503b8 100644 --- a/backend/utils/mysql/helper/dump.go +++ b/backend/utils/mysql/helper/dump.go @@ -38,18 +38,6 @@ func WithData() DumpOption { } } -func WithTables(tables ...string) DumpOption { - return func(option *dumpOption) { - option.tables = tables - } -} - -func WithAllTable() DumpOption { - return func(option *dumpOption) { - option.isAllTable = true - } -} - func WithWriter(writer io.Writer) DumpOption { return func(option *dumpOption) { option.writer = writer diff --git a/backend/utils/mysql/helper/source.go b/backend/utils/mysql/helper/source.go index 91fa75e97..ab9a2d15e 100644 --- a/backend/utils/mysql/helper/source.go +++ b/backend/utils/mysql/helper/source.go @@ -19,24 +19,12 @@ type sourceOption struct { } type SourceOption func(*sourceOption) -func WithDryRun() SourceOption { - return func(o *sourceOption) { - o.dryRun = true - } -} - func WithMergeInsert(size int) SourceOption { return func(o *sourceOption) { o.mergeInsert = size } } -func WithDebug() SourceOption { - return func(o *sourceOption) { - o.debug = true - } -} - type dbWrapper struct { DB *sql.DB debug bool diff --git a/backend/utils/nginx/components/config.go b/backend/utils/nginx/components/config.go index b3a4a59c7..7f9b5bce9 100644 --- a/backend/utils/nginx/components/config.go +++ b/backend/utils/nginx/components/config.go @@ -5,19 +5,6 @@ type Config struct { FilePath string } -func (c *Config) FindDirectives(directiveName string) []IDirective { - return c.Block.FindDirectives(directiveName) -} - -func (c *Config) FindUpstreams() []*Upstream { - var upstreams []*Upstream - directives := c.Block.FindDirectives("upstream") - for _, directive := range directives { - upstreams = append(upstreams, directive.(*Upstream)) - } - return upstreams -} - func (c *Config) FindServers() []*Server { var servers []*Server directives := c.Block.FindDirectives("server") diff --git a/backend/utils/nginx/nginx.go b/backend/utils/nginx/nginx.go deleted file mode 100644 index 9e7ffb792..000000000 --- a/backend/utils/nginx/nginx.go +++ /dev/null @@ -1,14 +0,0 @@ -package nginx - -import ( - "github.com/1Panel-dev/1Panel/backend/utils/nginx/components" - "github.com/1Panel-dev/1Panel/backend/utils/nginx/parser" -) - -func GetConfig(path string) (*components.Config, error) { - p, err := parser.NewParser(path) - if err != nil { - return nil, err - } - return p.Parse() -} diff --git a/backend/utils/nginx/nginx_test.go b/backend/utils/nginx/nginx_test.go deleted file mode 100644 index e31134639..000000000 --- a/backend/utils/nginx/nginx_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package nginx - -import ( - "fmt" - "testing" -) - -func TestNginx(t *testing.T) { - //config, err := GetConfig("/opt/1Panel/data/apps/nginx/nginx-1/conf/conf.d/word-1.conf") - config, err := GetConfig("/opt/1Panel/data/apps/nginx/nginx-new/conf/conf.d/1panel.cloud.conf") - if err != nil { - panic(err) - } - - //server := config.FindServers()[0] - //fmt.Println(server) - //serverD := config.FindServers()[0] - //serverD.AddListen("8989", false) - - fmt.Println(DumpConfig(config, IndentedStyle)) -} diff --git a/backend/utils/nginx/parser/flag/flag.go b/backend/utils/nginx/parser/flag/flag.go index 88bf9d6e1..b39d9e7ac 100644 --- a/backend/utils/nginx/parser/flag/flag.go +++ b/backend/utils/nginx/parser/flag/flag.go @@ -1,9 +1,5 @@ package flag -import ( - "fmt" -) - type Type int const ( @@ -47,33 +43,13 @@ type Flag struct { Column int } -func (t Flag) String() string { - return fmt.Sprintf("{Type:%s,Literal:\"%s\",Line:%d,Column:%d}", t.Type, t.Literal, t.Line, t.Column) -} - func (t Flag) Lit(literal string) Flag { t.Literal = literal return t } -func (t Flag) EqualTo(t2 Flag) bool { - return t.Type == t2.Type && t.Literal == t2.Literal -} - type Flags []Flag -func (fs Flags) EqualTo(flags Flags) bool { - if len(fs) != len(flags) { - return false - } - for i, t := range fs { - if !t.EqualTo(flags[i]) { - return false - } - } - return true -} - func (t Flag) Is(typ Type) bool { return t.Type == typ } diff --git a/backend/utils/ssl/client.go b/backend/utils/ssl/client.go index e25da5518..f624d6c1e 100644 --- a/backend/utils/ssl/client.go +++ b/backend/utils/ssl/client.go @@ -3,6 +3,8 @@ package ssl import ( "crypto" "encoding/json" + "time" + "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/go-acme/lego/v4/acme" "github.com/go-acme/lego/v4/acme/api" @@ -21,7 +23,6 @@ import ( "github.com/go-acme/lego/v4/providers/http/webroot" "github.com/go-acme/lego/v4/registration" "github.com/pkg/errors" - "time" ) type AcmeUser struct { @@ -204,23 +205,6 @@ func (c *AcmeClient) ObtainSSL(domains []string, privateKey crypto.PrivateKey) ( return *certificates, nil } -func (c *AcmeClient) RenewSSL(certUrl string) (certificate.Resource, error) { - certificates, err := c.Client.Certificate.Get(certUrl, true) - if err != nil { - return certificate.Resource{}, err - } - certificates, err = c.Client.Certificate.RenewWithOptions(*certificates, &certificate.RenewOptions{ - Bundle: true, - PreferredChain: "", - MustStaple: true, - }) - if err != nil { - return certificate.Resource{}, err - } - - return *certificates, nil -} - type Resolve struct { Key string Value string diff --git a/backend/utils/websocket/process_data.go b/backend/utils/websocket/process_data.go index 9f83db33f..529256ba6 100644 --- a/backend/utils/websocket/process_data.go +++ b/backend/utils/websocket/process_data.go @@ -3,15 +3,16 @@ package websocket import ( "encoding/json" "fmt" + "sort" + "strings" + "sync" + "time" + "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/net" "github.com/shirou/gopsutil/v3/process" - "sort" - "strings" - "sync" - "time" ) type WsInput struct { @@ -86,18 +87,6 @@ type processConnect struct { type ProcessConnects []processConnect -func (p ProcessConnects) Len() int { - return len(p) -} - -func (p ProcessConnects) Less(i, j int) bool { - return p[i].PID < p[j].PID -} - -func (p ProcessConnects) Swap(i, j int) { - p[i], p[j] = p[j], p[i] -} - type sshSession struct { Username string `json:"username"` PID int32 `json:"PID"` diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 60a791651..f640ab313 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1,5 +1,5 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" @@ -4954,45 +4954,6 @@ const docTemplate = `{ } } }, - "/databases/pg/options": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "获取 postgresql 数据库列表", - "consumes": [ - "application/json" - ], - "tags": [ - "Database Postgresql" - ], - "summary": "List postgresql database names", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.PageInfo" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/dto.PostgresqlOption" - } - } - } - } - } - }, "/databases/pg/password": { "post": { "security": [ @@ -17203,26 +17164,6 @@ const docTemplate = `{ } } }, - "dto.PostgresqlOption": { - "type": "object", - "properties": { - "database": { - "type": "string" - }, - "from": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "dto.RecordSearch": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 38fd1885e..89d2e7c47 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -4947,45 +4947,6 @@ } } }, - "/databases/pg/options": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "获取 postgresql 数据库列表", - "consumes": [ - "application/json" - ], - "tags": [ - "Database Postgresql" - ], - "summary": "List postgresql database names", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.PageInfo" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/dto.PostgresqlOption" - } - } - } - } - } - }, "/databases/pg/password": { "post": { "security": [ @@ -17196,26 +17157,6 @@ } } }, - "dto.PostgresqlOption": { - "type": "object", - "properties": { - "database": { - "type": "string" - }, - "from": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "dto.RecordSearch": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index ef7cf3410..da9fb4e92 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -2119,19 +2119,6 @@ definitions: - from - type type: object - dto.PostgresqlOption: - properties: - database: - type: string - from: - type: string - id: - type: integer - name: - type: string - type: - type: string - type: object dto.RecordSearch: properties: detailName: @@ -8140,30 +8127,6 @@ paths: [description] formatZH: postgresql 数据库 [name] 描述信息修改 [description] paramKeys: [] - /databases/pg/options: - get: - consumes: - - application/json - description: 获取 postgresql 数据库列表 - parameters: - - description: request - in: body - name: request - required: true - schema: - $ref: '#/definitions/dto.PageInfo' - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/dto.PostgresqlOption' - type: array - security: - - ApiKeyAuth: [] - summary: List postgresql database names - tags: - - Database Postgresql /databases/pg/password: post: consumes: