diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index f46171f74..f2184c027 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -1,12 +1,14 @@ package v1 import ( + "errors" + "reflect" + "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/gin-gonic/gin" - "reflect" ) func (b *BaseApi) SearchAppInstalled(c *gin.Context) { @@ -37,6 +39,20 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { } } +func (b *BaseApi) CheckAppInstalld(c *gin.Context) { + key, ok := c.Params.Get("key") + if !ok { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path")) + return + } + checkData, err := appInstallService.CheckExist(key) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, checkData) +} + func (b *BaseApi) SyncInstalled(c *gin.Context) { if err := appInstallService.SyncAll(); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) diff --git a/backend/app/api/v1/database_mysql.go b/backend/app/api/v1/database_mysql.go index 48091b31b..adf71c09c 100644 --- a/backend/app/api/v1/database_mysql.go +++ b/backend/app/api/v1/database_mysql.go @@ -95,13 +95,7 @@ func (b *BaseApi) UpdateMysqlVariables(c *gin.Context) { return } - mysqlName, ok := c.Params.Get("mysqlName") - if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error mysqlName in path")) - return - } - - if err := mysqlService.UpdateVariables(mysqlName, req); err != nil { + if err := mysqlService.UpdateVariables(req); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } @@ -124,7 +118,7 @@ func (b *BaseApi) UpdateMysqlConfByFile(c *gin.Context) { } func (b *BaseApi) SearchMysql(c *gin.Context) { - var req dto.SearchDBWithPage + var req dto.PageInfo if err := c.ShouldBindJSON(&req); err != nil { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) return @@ -142,14 +136,8 @@ func (b *BaseApi) SearchMysql(c *gin.Context) { }) } -func (b *BaseApi) ListDBNameByVersion(c *gin.Context) { - name, ok := c.Params.Get("name") - if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error name in path")) - return - } - - list, err := mysqlService.ListDBByVersion(name) +func (b *BaseApi) ListDBName(c *gin.Context) { + list, err := mysqlService.ListDBName() if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return @@ -232,37 +220,16 @@ func (b *BaseApi) DeleteMysql(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) return } - name, ok := c.Params.Get("name") - if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error name in path")) - return - } - if err := mysqlService.Delete(name, req.Ids); err != nil { + if err := mysqlService.Delete(req.Ids); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } helper.SuccessWithData(c, nil) } -func (b *BaseApi) LoadVersions(c *gin.Context) { - data, err := mysqlService.LoadRunningVersion() - if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - helper.SuccessWithData(c, data) -} - func (b *BaseApi) LoadBaseinfo(c *gin.Context) { - name, ok := c.Params.Get("name") - if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error name in path")) - return - } - - data, err := mysqlService.LoadBaseInfo(name) + data, err := mysqlService.LoadBaseInfo() if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return @@ -272,13 +239,7 @@ func (b *BaseApi) LoadBaseinfo(c *gin.Context) { } func (b *BaseApi) LoadStatus(c *gin.Context) { - name, ok := c.Params.Get("name") - if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error name in path")) - return - } - - data, err := mysqlService.LoadStatus(name) + data, err := mysqlService.LoadStatus() if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return @@ -288,12 +249,7 @@ func (b *BaseApi) LoadStatus(c *gin.Context) { } func (b *BaseApi) LoadVariables(c *gin.Context) { - name, ok := c.Params.Get("name") - if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error name in path")) - return - } - data, err := mysqlService.LoadVariables(name) + data, err := mysqlService.LoadVariables() if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index c41170445..c0486d64a 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -39,6 +39,12 @@ type AppInstallRequest struct { Services map[string]string `json:"services"` } +type CheckInstalled struct { + IsExist bool `json:"isExist"` + Name string `json:"name"` + Version string `json:"version"` +} + type AppInstalled struct { model.AppInstall Total int `json:"total"` diff --git a/backend/app/dto/cronjob.go b/backend/app/dto/cronjob.go index bc58efb00..7da9b97b9 100644 --- a/backend/app/dto/cronjob.go +++ b/backend/app/dto/cronjob.go @@ -14,7 +14,6 @@ type CronjobCreate struct { Script string `json:"script"` Website string `json:"website"` ExclusionRules string `json:"exclusionRules"` - Database string `json:"database"` DBName string `json:"dbName"` URL string `json:"url"` SourceDir string `json:"sourceDir"` @@ -34,7 +33,6 @@ type CronjobUpdate struct { Script string `json:"script"` Website string `json:"website"` ExclusionRules string `json:"exclusionRules"` - Database string `json:"database"` DBName string `json:"dbName"` URL string `json:"url"` SourceDir string `json:"sourceDir"` @@ -66,7 +64,6 @@ type CronjobInfo struct { Script string `json:"script"` Website string `json:"website"` ExclusionRules string `json:"exclusionRules"` - Database string `json:"database"` DBName string `json:"dbName"` URL string `json:"url"` SourceDir string `json:"sourceDir"` diff --git a/backend/app/dto/database.go b/backend/app/dto/database.go index 0447183c7..f7d25c56f 100644 --- a/backend/app/dto/database.go +++ b/backend/app/dto/database.go @@ -16,7 +16,6 @@ type MysqlDBInfo struct { type MysqlDBCreate struct { Name string `json:"name" validate:"required"` - MysqlName string `json:"mysqlName" validate:"required"` Format string `json:"format" validate:"required,oneof=utf8mb4 utf-8 gbk big5"` Username string `json:"username" validate:"required"` Password string `json:"password" validate:"required"` @@ -106,7 +105,6 @@ type DBBaseInfo struct { Port int64 `json:"port"` Password string `json:"password"` RemoteConn bool `json:"remoteConn"` - MysqlKey string `json:"mysqlKey"` } type SearchDBWithPage struct { diff --git a/backend/app/model/cronjob.go b/backend/app/model/cronjob.go index 2d5d7d5e1..a436fb312 100644 --- a/backend/app/model/cronjob.go +++ b/backend/app/model/cronjob.go @@ -16,7 +16,6 @@ type Cronjob struct { Script string `gorm:"longtext" json:"script"` Website string `gorm:"type:varchar(64)" json:"website"` - Database string `gorm:"type:varchar(64)" json:"database"` DBName string `gorm:"type:varchar(64)" json:"dbName"` URL string `gorm:"type:varchar(256)" json:"url"` SourceDir string `gorm:"type:varchar(256)" json:"sourceDir"` diff --git a/backend/app/repo/databse_mysql.go b/backend/app/repo/databse_mysql.go index b458ac6f7..757fbce3d 100644 --- a/backend/app/repo/databse_mysql.go +++ b/backend/app/repo/databse_mysql.go @@ -20,9 +20,7 @@ type IMysqlRepo interface { Create(ctx context.Context, mysql *model.DatabaseMysql) error Delete(ctx context.Context, opts ...DBOption) error Update(id uint, vars map[string]interface{}) error - LoadRunningVersion(keys []string) ([]string, error) - LoadBaseInfoByName(name string) (*RootInfo, error) - LoadRedisBaseInfo() (*RootInfo, error) + LoadBaseInfoByKey(key string) (*RootInfo, error) UpdateDatabaseInfo(id uint, vars map[string]interface{}) error } @@ -62,26 +60,6 @@ func (u *MysqlRepo) Page(page, size int, opts ...DBOption) (int64, []model.Datab return count, users, err } -func (u *MysqlRepo) LoadRunningVersion(keys []string) ([]string, error) { - var ( - apps []model.App - appInstall []model.AppInstall - results []string - ) - if err := global.DB.Where("name in (?)", keys).Find(&apps).Error; err != nil { - return nil, err - } - for _, app := range apps { - if err := global.DB.Where("app_id = ?", app.ID).Find(&appInstall).Error; err != nil { - return nil, err - } - for _, item := range appInstall { - results = append(results, item.Name) - } - } - return results, nil -} - type RootInfo struct { ID uint `json:"id"` Name string `json:"name"` @@ -91,52 +69,16 @@ type RootInfo struct { Param string `json:"param"` Env string `json:"env"` Key string `json:"key"` + Version string `json:"version"` } -func (u *MysqlRepo) LoadBaseInfoByName(name string) (*RootInfo, error) { - var ( - app model.App - appInstall model.AppInstall - info RootInfo - ) - if err := global.DB.Where("name = ?", name).First(&appInstall).Error; err != nil { - return nil, err - } - if err := global.DB.Where("id = ?", appInstall.AppId).First(&app).Error; err != nil { - return nil, err - } - envMap := make(map[string]interface{}) - if err := json.Unmarshal([]byte(appInstall.Env), &envMap); err != nil { - return nil, err - } - password, ok := envMap["PANEL_DB_ROOT_PASSWORD"].(string) - if ok { - info.Password = password - } else { - return nil, errors.New("error password in db") - } - port, ok := envMap["PANEL_APP_PORT_HTTP"].(float64) - if ok { - info.Port = int64(port) - } else { - return nil, errors.New("error port in db") - } - info.ID = appInstall.ID - info.Key = app.Key - info.ContainerName = appInstall.ContainerName - info.Name = appInstall.Name - info.Env = appInstall.Env - info.Param = appInstall.Param - return &info, nil -} - -func (u *MysqlRepo) LoadRedisBaseInfo() (*RootInfo, error) { +func (u *MysqlRepo) LoadBaseInfoByKey(key string) (*RootInfo, error) { var ( app model.App appInstall model.AppInstall info RootInfo ) - if err := global.DB.Where("key = ?", "redis").First(&app).Error; err != nil { + if err := global.DB.Where("key = ?", key).First(&app).Error; err != nil { return nil, err } if err := global.DB.Where("app_id = ?", app.ID).First(&appInstall).Error; err != nil { @@ -163,6 +105,7 @@ func (u *MysqlRepo) LoadRedisBaseInfo() (*RootInfo, error) { info.Name = appInstall.Name info.Env = appInstall.Env info.Param = appInstall.Param + info.Version = appInstall.Version return &info, nil } diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 8bb747df4..453225d13 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -3,6 +3,12 @@ package service import ( "context" "fmt" + "io/ioutil" + "os" + "path" + "strconv" + "strings" + "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/constant" @@ -12,11 +18,6 @@ import ( "github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/pkg/errors" - "io/ioutil" - "os" - "path" - "strconv" - "strings" ) type AppInstallService struct { @@ -38,6 +39,18 @@ func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppIn return total, installDTOs, nil } +func (a AppInstallService) CheckExist(key string) (*dto.CheckInstalled, error) { + app, err := appRepo.GetFirst(appRepo.WithKey(key)) + if err != nil { + return nil, err + } + appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID)) + if appInstall.ID != 0 { + return &dto.CheckInstalled{Name: appInstall.Name, IsExist: true, Version: appInstall.Version}, nil + } + return &dto.CheckInstalled{IsExist: false}, nil +} + func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstalled, error) { var installs []model.AppInstall var err error @@ -221,7 +234,7 @@ func (a AppInstallService) ChangeAppPort(req dto.PortUpdate) error { files []string newFiles []string ) - app, err := mysqlRepo.LoadBaseInfoByName(req.Name) + app, err := mysqlRepo.LoadBaseInfoByKey(req.Key) if err != nil { return err } diff --git a/backend/app/service/cornjob.go b/backend/app/service/cornjob.go index f944ef399..257f9a9a5 100644 --- a/backend/app/service/cornjob.go +++ b/backend/app/service/cornjob.go @@ -216,7 +216,6 @@ func (u *CronjobService) Update(id uint, req dto.CronjobUpdate) error { upMap["minute"] = req.Minute upMap["website"] = req.Website upMap["exclusion_rules"] = req.ExclusionRules - upMap["database"] = req.Database upMap["db_name"] = req.DBName upMap["url"] = req.URL upMap["source_dir"] = req.SourceDir diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 53325e5d9..744e15b05 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -78,7 +78,7 @@ func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Tim if err != nil { return "", err } - app, err := mysqlRepo.LoadBaseInfoByName(cronjob.Database) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return "", err } @@ -94,8 +94,8 @@ func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Tim if cronjob.Type == "database" { fileName = fmt.Sprintf("db_%s_%s.sql.gz", cronjob.DBName, time.Now().Format("20060102150405")) - backupDir = fmt.Sprintf("database/%s/%s/%s", app.Key, cronjob.Database, cronjob.DBName) - err = backupMysql(backup.Type, baseDir, backupDir, cronjob.Database, cronjob.DBName, fileName) + backupDir = fmt.Sprintf("database/mysql/%s/%s", app.Name, cronjob.DBName) + err = backupMysql(backup.Type, baseDir, backupDir, app.Name, cronjob.DBName, fileName) if err != nil { return "", err } diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index 8a2f6a787..632e47644 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -31,12 +31,12 @@ import ( type MysqlService struct{} type IMysqlService interface { - SearchWithPage(search dto.SearchDBWithPage) (int64, interface{}, error) - ListDBByVersion(name string) ([]string, error) + SearchWithPage(search dto.PageInfo) (int64, interface{}, error) + ListDBName() ([]string, error) SearchBackupsWithPage(search dto.SearchBackupsWithPage) (int64, interface{}, error) Create(mysqlDto dto.MysqlDBCreate) error ChangeInfo(info dto.ChangeDBInfo) error - UpdateVariables(mysqlName string, updatas []dto.MysqlVariablesUpdate) error + UpdateVariables(updatas []dto.MysqlVariablesUpdate) error UpdateConfByFile(info dto.MysqlConfUpdateByFile) error UpFile(mysqlName string, files []*multipart.FileHeader) error @@ -45,19 +45,18 @@ type IMysqlService interface { Backup(db dto.BackupDB) error Recover(db dto.RecoverDB) error - Delete(name string, ids []uint) error - LoadStatus(name string) (*dto.MysqlStatus, error) - LoadVariables(vernamesion string) (*dto.MysqlVariables, error) - LoadRunningVersion() ([]string, error) - LoadBaseInfo(name string) (*dto.DBBaseInfo, error) + Delete(ids []uint) error + LoadStatus() (*dto.MysqlStatus, error) + LoadVariables() (*dto.MysqlVariables, error) + LoadBaseInfo() (*dto.DBBaseInfo, error) } func NewIMysqlService() IMysqlService { return &MysqlService{} } -func (u *MysqlService) SearchWithPage(search dto.SearchDBWithPage) (int64, interface{}, error) { - total, mysqls, err := mysqlRepo.Page(search.Page, search.PageSize, mysqlRepo.WithByMysqlName(search.MysqlName)) +func (u *MysqlService) SearchWithPage(search dto.PageInfo) (int64, interface{}, error) { + total, mysqls, err := mysqlRepo.Page(search.Page, search.PageSize) var dtoMysqls []dto.MysqlDBInfo for _, mysql := range mysqls { var item dto.MysqlDBInfo @@ -74,11 +73,11 @@ func (u *MysqlService) SearchUpListWithPage(req dto.SearchDBWithPage) (int64, in list []dto.DatabaseFileRecords backDatas []dto.DatabaseFileRecords ) - localDir, appKey, err := loadBackupDirAndKey(req.MysqlName) + localDir, err := loadLocalDir() if err != nil { return 0, list, nil } - uploadDir := fmt.Sprintf("%s/database/%s/%s/upload", localDir, appKey, req.MysqlName) + uploadDir := fmt.Sprintf("%s/database/mysql/%s/upload", localDir, req.MysqlName) if _, err := os.Stat(uploadDir); err != nil { return 0, list, nil } @@ -109,11 +108,11 @@ func (u *MysqlService) SearchUpListWithPage(req dto.SearchDBWithPage) (int64, in } func (u *MysqlService) UpFile(mysqlName string, files []*multipart.FileHeader) error { - localDir, appKey, err := loadBackupDirAndKey(mysqlName) + localDir, err := loadLocalDir() if err != nil { return err } - dstDir := fmt.Sprintf("%s/database/%s/%s/upload", localDir, appKey, mysqlName) + dstDir := fmt.Sprintf("%s/database/mysql/%s/upload", localDir, mysqlName) if _, err := os.Stat(dstDir); err != nil && os.IsNotExist(err) { if err = os.MkdirAll(dstDir, os.ModePerm); err != nil { if err != nil { @@ -138,7 +137,7 @@ func (u *MysqlService) UpFile(mysqlName string, files []*multipart.FileHeader) e } func (u *MysqlService) RecoverByUpload(req dto.UploadRecover) error { - app, err := mysqlRepo.LoadBaseInfoByName(req.MysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } @@ -150,7 +149,7 @@ func (u *MysqlService) RecoverByUpload(req dto.UploadRecover) error { if !strings.HasSuffix(req.FileName, ".sql") && !strings.HasSuffix(req.FileName, ".gz") { fileOp := files.NewFileOp() fileNameItem := time.Now().Format("20060102150405") - dstDir := fmt.Sprintf("%s/database/%s/%s/upload/tmp/%s", localDir, app.Key, req.MysqlName, fileNameItem) + dstDir := fmt.Sprintf("%s/database/mysql/%s/upload/tmp/%s", localDir, req.MysqlName, fileNameItem) if _, err := os.Stat(dstDir); err != nil && os.IsNotExist(err) { if err = os.MkdirAll(dstDir, os.ModePerm); err != nil { if err != nil { @@ -215,8 +214,8 @@ func (u *MysqlService) RecoverByUpload(req dto.UploadRecover) error { return nil } -func (u *MysqlService) ListDBByVersion(name string) ([]string, error) { - mysqls, err := mysqlRepo.List(mysqlRepo.WithByMysqlName(name)) +func (u *MysqlService) ListDBName() ([]string, error) { + mysqls, err := mysqlRepo.List() var dbNames []string for _, mysql := range mysqls { dbNames = append(dbNames, mysql.Name) @@ -225,7 +224,7 @@ func (u *MysqlService) ListDBByVersion(name string) ([]string, error) { } func (u *MysqlService) SearchBackupsWithPage(search dto.SearchBackupsWithPage) (int64, interface{}, error) { - app, err := mysqlRepo.LoadBaseInfoByName(search.MysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return 0, nil, err } @@ -239,19 +238,15 @@ func (u *MysqlService) SearchBackupsWithPage(search dto.SearchBackupsWithPage) ( return NewIBackupService().SearchRecordWithPage(searchDto) } -func (u *MysqlService) LoadRunningVersion() ([]string, error) { - return mysqlRepo.LoadRunningVersion([]string{"Mysql5.7", "Mysql8.0"}) -} - func (u *MysqlService) Create(mysqlDto dto.MysqlDBCreate) error { if mysqlDto.Username == "root" { return errors.New("Cannot set root as user name") } - app, err := mysqlRepo.LoadBaseInfoByName(mysqlDto.MysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } - mysql, _ := mysqlRepo.Get(commonRepo.WithByName(mysqlDto.Name), mysqlRepo.WithByMysqlName(app.Key)) + mysql, _ := mysqlRepo.Get(commonRepo.WithByName(mysqlDto.Name)) if mysql.ID != 0 { return constant.ErrRecordExist } @@ -267,12 +262,13 @@ func (u *MysqlService) Create(mysqlDto dto.MysqlDBCreate) error { return err } grantStr := fmt.Sprintf("grant all privileges on %s.* to '%s'@'%s'", mysqlDto.Name, mysqlDto.Username, tmpPermission) - if app.Key == "mysql5.7" { + if app.Version == "5.7.39" { grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, mysqlDto.Password) } if err := excuteSql(app.ContainerName, app.Password, grantStr); err != nil { return err } + mysql.MysqlName = app.Name if err := mysqlRepo.Create(context.TODO(), &mysql); err != nil { return err } @@ -280,11 +276,11 @@ func (u *MysqlService) Create(mysqlDto dto.MysqlDBCreate) error { } func (u *MysqlService) Backup(db dto.BackupDB) error { - localDir, appKey, err := loadBackupDirAndKey(db.MysqlName) + localDir, err := loadLocalDir() if err != nil { return err } - backupDir := fmt.Sprintf("database/%s/%s/%s", appKey, db.MysqlName, db.DBName) + backupDir := fmt.Sprintf("database/mysql/%s/%s", db.MysqlName, db.DBName) fileName := fmt.Sprintf("%s_%s.sql.gz", db.DBName, time.Now().Format("20060102150405")) if err := backupMysql("LOCAL", localDir, backupDir, db.MysqlName, db.DBName, fileName); err != nil { return err @@ -293,7 +289,7 @@ func (u *MysqlService) Backup(db dto.BackupDB) error { } func (u *MysqlService) Recover(db dto.RecoverDB) error { - app, err := mysqlRepo.LoadBaseInfoByName(db.MysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } @@ -317,8 +313,8 @@ func (u *MysqlService) Recover(db dto.RecoverDB) error { return nil } -func (u *MysqlService) Delete(name string, ids []uint) error { - app, err := mysqlRepo.LoadBaseInfoByName(name) +func (u *MysqlService) Delete(ids []uint) error { + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } @@ -353,7 +349,7 @@ func (u *MysqlService) ChangeInfo(info dto.ChangeDBInfo) error { return err } } - app, err := mysqlRepo.LoadBaseInfoByName(info.MysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } @@ -402,7 +398,7 @@ func (u *MysqlService) ChangeInfo(info dto.ChangeDBInfo) error { return err } grantStr := fmt.Sprintf("grant all privileges on %s.* to '%s'@'%s'", mysql.Name, mysql.Username, info.Value) - if app.Key == "mysql5.7" { + if app.Version == "5.7.39" { grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, mysql.Password) } if err := excuteSql(app.ContainerName, app.Password, grantStr); err != nil { @@ -421,11 +417,11 @@ func (u *MysqlService) ChangeInfo(info dto.ChangeDBInfo) error { } func (u *MysqlService) UpdateConfByFile(info dto.MysqlConfUpdateByFile) error { - app, err := mysqlRepo.LoadBaseInfoByName(info.MysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } - path := fmt.Sprintf("%s/%s/%s/conf/my.cnf", constant.AppInstallDir, app.Key, app.Name) + path := fmt.Sprintf("%s/mysql/%s/conf/my.cnf", constant.AppInstallDir, app.Name) file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0640) if err != nil { return err @@ -434,20 +430,20 @@ func (u *MysqlService) UpdateConfByFile(info dto.MysqlConfUpdateByFile) error { write := bufio.NewWriter(file) _, _ = write.WriteString(info.File) write.Flush() - if _, err := compose.Restart(fmt.Sprintf("%s/%s/%s/docker-compose.yml", constant.AppInstallDir, app.Key, app.Name)); err != nil { + if _, err := compose.Restart(fmt.Sprintf("%s/mysql/%s/docker-compose.yml", constant.AppInstallDir, app.Name)); err != nil { return err } return nil } -func (u *MysqlService) UpdateVariables(mysqlName string, updatas []dto.MysqlVariablesUpdate) error { - app, err := mysqlRepo.LoadBaseInfoByName(mysqlName) +func (u *MysqlService) UpdateVariables(updatas []dto.MysqlVariablesUpdate) error { + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } var files []string - path := fmt.Sprintf("%s/%s/%s/conf/my.cnf", constant.AppInstallDir, app.Key, app.Name) + path := fmt.Sprintf("%s/mysql/%s/conf/my.cnf", constant.AppInstallDir, app.Name) lineBytes, err := ioutil.ReadFile(path) if err != nil { return err @@ -474,16 +470,16 @@ func (u *MysqlService) UpdateVariables(mysqlName string, updatas []dto.MysqlVari return err } - if _, err := compose.Restart(fmt.Sprintf("%s/%s/%s/docker-compose.yml", constant.AppInstallDir, app.Key, app.Name)); err != nil { + if _, err := compose.Restart(fmt.Sprintf("%s/mysql/%s/docker-compose.yml", constant.AppInstallDir, app.Name)); err != nil { return err } return nil } -func (u *MysqlService) LoadBaseInfo(name string) (*dto.DBBaseInfo, error) { +func (u *MysqlService) LoadBaseInfo() (*dto.DBBaseInfo, error) { var data dto.DBBaseInfo - app, err := mysqlRepo.LoadBaseInfoByName(name) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return nil, err } @@ -491,7 +487,6 @@ func (u *MysqlService) LoadBaseInfo(name string) (*dto.DBBaseInfo, error) { data.Name = app.Name data.Port = int64(app.Port) data.Password = app.Password - data.MysqlKey = app.Key hosts, err := excuteSqlForRows(app.ContainerName, app.Password, "select host from mysql.user where user='root';") if err != nil { @@ -506,8 +501,8 @@ func (u *MysqlService) LoadBaseInfo(name string) (*dto.DBBaseInfo, error) { return &data, nil } -func (u *MysqlService) LoadVariables(name string) (*dto.MysqlVariables, error) { - app, err := mysqlRepo.LoadBaseInfoByName(name) +func (u *MysqlService) LoadVariables() (*dto.MysqlVariables, error) { + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return nil, err } @@ -524,8 +519,8 @@ func (u *MysqlService) LoadVariables(name string) (*dto.MysqlVariables, error) { return &info, nil } -func (u *MysqlService) LoadStatus(name string) (*dto.MysqlStatus, error) { - app, err := mysqlRepo.LoadBaseInfoByName(name) +func (u *MysqlService) LoadStatus() (*dto.MysqlStatus, error) { + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return nil, err } @@ -609,7 +604,7 @@ func excuteSql(containerName, password, command string) error { } func backupMysql(backupType, baseDir, backupDir, mysqlName, dbName, fileName string) error { - app, err := mysqlRepo.LoadBaseInfoByName(mysqlName) + app, err := mysqlRepo.LoadBaseInfoByKey("mysql") if err != nil { return err } @@ -690,15 +685,3 @@ func updateMyCnf(oldFiles []string, group string, param string, value interface{ } return newFiles } - -func loadBackupDirAndKey(mysqlName string) (string, string, error) { - app, err := mysqlRepo.LoadBaseInfoByName(mysqlName) - if err != nil { - return "", "", err - } - localDir, err := loadLocalDir() - if err != nil { - return "", "", err - } - return localDir, app.Key, nil -} diff --git a/backend/app/service/database_redis.go b/backend/app/service/database_redis.go index 3c1d2d438..086bcad64 100644 --- a/backend/app/service/database_redis.go +++ b/backend/app/service/database_redis.go @@ -37,7 +37,7 @@ func NewIRedisService() IRedisService { } func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return err } @@ -70,7 +70,7 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error { } func (u *RedisService) UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate) error { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return err } @@ -97,7 +97,7 @@ func (u *RedisService) UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate) } func (u *RedisService) LoadStatus() (*dto.RedisStatus, error) { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return nil, err } @@ -125,7 +125,7 @@ func (u *RedisService) LoadStatus() (*dto.RedisStatus, error) { } func (u *RedisService) LoadConf() (*dto.RedisConf, error) { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return nil, err } @@ -150,7 +150,7 @@ func (u *RedisService) LoadConf() (*dto.RedisConf, error) { } func (u *RedisService) LoadPersistenceConf() (*dto.RedisPersistence, error) { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return nil, err } @@ -169,7 +169,7 @@ func (u *RedisService) LoadPersistenceConf() (*dto.RedisPersistence, error) { } func (u *RedisService) Backup() error { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return err } @@ -214,7 +214,7 @@ func (u *RedisService) Backup() error { } func (u *RedisService) Recover(req dto.RedisBackupRecover) error { - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return err } @@ -254,7 +254,7 @@ func (u *RedisService) SearchBackupListWithPage(req dto.PageInfo) (int64, interf list []dto.DatabaseFileRecords backDatas []dto.DatabaseFileRecords ) - redisInfo, err := mysqlRepo.LoadRedisBaseInfo() + redisInfo, err := mysqlRepo.LoadBaseInfoByKey("redis") if err != nil { return 0, nil, err } diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 2277ee972..d8ceec8a1 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -5,9 +5,12 @@ import ( "encoding/json" "io/ioutil" "os" + "os/exec" "strings" "github.com/1Panel-dev/1Panel/backend/app/dto" + "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/pkg/errors" ) type DockerService struct{} @@ -32,7 +35,7 @@ type daemonJsonItem struct { } func (u *DockerService) LoadDockerConf() (*dto.DaemonJsonConf, error) { - file, err := ioutil.ReadFile("/opt/1Panel/docker/daemon.json") + file, err := ioutil.ReadFile(constant.DaemonJsonDir) if err != nil { return nil, err } @@ -68,7 +71,7 @@ func (u *DockerService) LoadDockerConf() (*dto.DaemonJsonConf, error) { } func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { - file, err := ioutil.ReadFile("/opt/1Panel/docker/daemon.json") + file, err := ioutil.ReadFile(constant.DaemonJsonDir) if err != nil { return err } @@ -100,9 +103,15 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { if err != nil { return err } - if err := ioutil.WriteFile("/opt/1Panel/docker/daemon.json", newJson, 0640); err != nil { + if err := ioutil.WriteFile(constant.DaemonJsonDir, newJson, 0640); err != nil { return err } + + cmd := exec.Command("systemctl", "restart", "docker") + stdout, err := cmd.CombinedOutput() + if err != nil { + return errors.New(string(stdout)) + } return nil } @@ -116,10 +125,10 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error { _, _ = write.WriteString(req.File) write.Flush() - // cmd := exec.Command("systemctl", "restart", "docker") - // stdout, err := cmd.CombinedOutput() - // if err != nil { - // return errors.New(string(stdout)) - // } + cmd := exec.Command("systemctl", "restart", "docker") + stdout, err := cmd.CombinedOutput() + if err != nil { + return errors.New(string(stdout)) + } return nil } diff --git a/backend/app/service/docker_test.go b/backend/app/service/docker_test.go deleted file mode 100644 index 35ea8f031..000000000 --- a/backend/app/service/docker_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package service - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "strings" - "testing" -) - -func TestDocker(t *testing.T) { - file, err := ioutil.ReadFile("/opt/1Panel/docker/daemon.json") - if err != nil { - fmt.Println(err) - } - var conf daemonJsonItem - deamonMap := make(map[string]interface{}) - if err := json.Unmarshal(file, &deamonMap); err != nil { - fmt.Println(err) - } - arr, err := json.Marshal(deamonMap) - if err != nil { - fmt.Println(err) - } - _ = json.Unmarshal(arr, &conf) - - for _, opt := range conf.ExecOpts { - if strings.HasPrefix(opt, "native.cgroupdriver=") { - fmt.Println(strings.ReplaceAll(opt, "native.cgroupdriver=", "")) - } - } -} diff --git a/backend/constant/container.go b/backend/constant/container.go index 353179268..6b74d4db0 100644 --- a/backend/constant/container.go +++ b/backend/constant/container.go @@ -14,7 +14,7 @@ const ( ComposeOpRestart = "restart" ComposeOpRemove = "remove" - DaemonJsonDir = "/System/Volumes/Data/Users/slooop/.docker/daemon.json" + DaemonJsonDir = "/opt/1Panel/docker/config/daemon.json" TmpDockerBuildDir = "/opt/1Panel/data/docker/build" TmpComposeBuildDir = "/opt/1Panel/data/docker/compose" ) diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index f114c3c30..b20ee65fe 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -21,6 +21,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { appRouter.GET("/detail/:appId/:version", baseApi.GetAppDetail) appRouter.POST("/install", baseApi.InstallApp) appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions) + appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalld) appRouter.POST("/installed", baseApi.SearchAppInstalled) appRouter.POST("/installed/op", baseApi.OperateInstalled) appRouter.POST("/installed/sync", baseApi.SyncInstalled) diff --git a/backend/router/ro_database.go b/backend/router/ro_database.go index 4e307a9f1..ad817f1d1 100644 --- a/backend/router/ro_database.go +++ b/backend/router/ro_database.go @@ -30,14 +30,13 @@ func (s *DatabaseRouter) InitDatabaseRouter(Router *gin.RouterGroup) { withRecordRouter.POST("/recover", baseApi.RecoverMysql) withRecordRouter.POST("/backups/search", baseApi.SearchDBBackups) withRecordRouter.POST("/del", baseApi.DeleteMysql) - withRecordRouter.POST("/variables/update/:mysqlName", baseApi.UpdateMysqlVariables) + withRecordRouter.POST("/variables/update", baseApi.UpdateMysqlVariables) withRecordRouter.POST("/conf/update/byfile", baseApi.UpdateMysqlConfByFile) cmdRouter.POST("/search", baseApi.SearchMysql) - cmdRouter.GET("/variables/:name", baseApi.LoadVariables) - cmdRouter.GET("/status/:name", baseApi.LoadStatus) - cmdRouter.GET("/baseinfo/:name", baseApi.LoadBaseinfo) - cmdRouter.GET("/versions", baseApi.LoadVersions) - cmdRouter.GET("/dbs/:name", baseApi.ListDBNameByVersion) + cmdRouter.GET("/variables", baseApi.LoadVariables) + cmdRouter.GET("/status", baseApi.LoadStatus) + cmdRouter.GET("/baseinfo", baseApi.LoadBaseinfo) + cmdRouter.GET("/dbs", baseApi.ListDBName) cmdRouter.GET("/redis/persistence/conf", baseApi.LoadPersistenceConf) cmdRouter.GET("/redis/status", baseApi.LoadRedisStatus) diff --git a/backend/utils/qqwry/qqwry.go b/backend/utils/qqwry/qqwry.go index 9ec412bfa..bd2b3d46a 100644 --- a/backend/utils/qqwry/qqwry.go +++ b/backend/utils/qqwry/qqwry.go @@ -2,10 +2,10 @@ package qqwry import ( "encoding/binary" - "io/ioutil" "net" "strings" + "github.com/1Panel-dev/1Panel/cmd/server/qqwry" "golang.org/x/text/encoding/simplifiedchinese" ) @@ -23,10 +23,7 @@ type QQwry struct { } func NewQQwry() (*QQwry, error) { - IpCommonDictionary, err := ioutil.ReadFile("/opt/1Panel/conf/qqwry.dat") - if err != nil { - return nil, err - } + IpCommonDictionary := qqwry.QQwryByte return &QQwry{Data: IpCommonDictionary}, nil } diff --git a/cmd/server/qqwry/qqwey.go b/cmd/server/qqwry/qqwey.go new file mode 100644 index 000000000..94ee4abb8 --- /dev/null +++ b/cmd/server/qqwry/qqwey.go @@ -0,0 +1,6 @@ +package qqwry + +import _ "embed" + +//go:embed qqwry.dat +var QQwryByte []byte diff --git a/cmd/server/qqwry/qqwry.dat b/cmd/server/qqwry/qqwry.dat new file mode 100644 index 000000000..251572e03 Binary files /dev/null and b/cmd/server/qqwry/qqwry.dat differ diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index f0e868076..9713ffb4f 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -82,6 +82,12 @@ export namespace App { app: App; } + export interface CheckInstalled { + name: string; + version: string; + isExist: boolean; + } + export interface AppInstalledOp { installId: number; operate: string; diff --git a/frontend/src/api/interface/cronjob.ts b/frontend/src/api/interface/cronjob.ts index 99c79d44b..d2dc11c03 100644 --- a/frontend/src/api/interface/cronjob.ts +++ b/frontend/src/api/interface/cronjob.ts @@ -14,7 +14,6 @@ export namespace Cronjob { script: string; website: string; exclusionRules: string; - database: string; dbName: string; url: string; sourceDir: string; @@ -36,7 +35,6 @@ export namespace Cronjob { script: string; website: string; exclusionRules: string; - database: string; dbName: string; url: string; sourceDir: string; @@ -55,7 +53,6 @@ export namespace Cronjob { script: string; website: string; exclusionRules: string; - database: string; dbName: string; url: string; sourceDir: string; diff --git a/frontend/src/api/interface/database.ts b/frontend/src/api/interface/database.ts index 221a457b1..ab07ee9e3 100644 --- a/frontend/src/api/interface/database.ts +++ b/frontend/src/api/interface/database.ts @@ -1,9 +1,6 @@ import { ReqPage } from '.'; export namespace Database { - export interface Search extends ReqPage { - mysqlName: string; - } export interface SearchBackupRecord extends ReqPage { mysqlName: string; dbName: string; @@ -47,7 +44,6 @@ export namespace Database { } export interface MysqlDBCreate { name: string; - mysqlName: string; format: string; username: string; password: string; diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index 45d7d8a78..1067d9125 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -30,6 +30,10 @@ export const GetAppInstalled = (info: ReqPage) => { return http.post>('apps/installed', info); }; +export const CheckAppInstalled = (key: string) => { + return http.get(`apps/installed/check/${key}`); +}; + export const SearchAppInstalled = (search: App.AppInstalledSearch) => { return http.post('apps/installed', search); }; diff --git a/frontend/src/api/modules/database.ts b/frontend/src/api/modules/database.ts index 0368a30ca..1b8fc12df 100644 --- a/frontend/src/api/modules/database.ts +++ b/frontend/src/api/modules/database.ts @@ -4,14 +4,11 @@ import { Backup } from '../interface/backup'; import { Database } from '../interface/database'; import { File } from '@/api/interface/file'; -export const searchMysqlDBs = (params: Database.Search) => { +export const searchMysqlDBs = (params: ReqPage) => { return http.post>(`/databases/search`, params); }; -export const listDBByVersion = (params: string) => { - return http.get(`/databases/dbs/${params}`); -}; -export const searchUpList = (params: Database.Search) => { +export const searchUpList = (params: ReqPage) => { return http.post>(`/databases/uplist`, params); }; export const uploadFile = (mysqlName: string, params: FormData) => { @@ -36,8 +33,8 @@ export const addMysqlDB = (params: Database.MysqlDBCreate) => { export const updateMysqlDBInfo = (params: Database.ChangeInfo) => { return http.put(`/databases/${params.id}`, params); }; -export const updateMysqlVariables = (mysqlName: string, params: Array) => { - return http.post(`/databases/variables/update/${mysqlName}`, params); +export const updateMysqlVariables = (params: Array) => { + return http.post(`/databases/variables/update`, params); }; export const updateMysqlConfByFile = (params: Database.MysqlConfUpdateByFile) => { return http.post(`/databases/conf/update/byfile`, params); @@ -46,17 +43,17 @@ export const deleteMysqlDB = (params: { ids: number[] }) => { return http.post(`/databases/del`, params); }; -export const loadMysqlBaseInfo = (param: string) => { - return http.get(`/databases/baseinfo/${param}`); +export const loadMysqlBaseInfo = () => { + return http.get(`/databases/baseinfo`); }; -export const loadMysqlVariables = (param: string) => { - return http.get(`/databases/variables/${param}`); +export const loadMysqlVariables = () => { + return http.get(`/databases/variables`); }; -export const loadMysqlStatus = (param: string) => { - return http.get(`/databases/status/${param}`); +export const loadMysqlStatus = () => { + return http.get(`/databases/status`); }; -export const loadVersions = () => { - return http.get(`/databases/versions`); +export const loadDBNames = () => { + return http.get>(`/databases/dbs`); }; // redis diff --git a/frontend/src/components/codemirror-dialog/codemirror.vue b/frontend/src/components/codemirror-dialog/codemirror.vue new file mode 100644 index 000000000..335b8390d --- /dev/null +++ b/frontend/src/components/codemirror-dialog/codemirror.vue @@ -0,0 +1,53 @@ + + + diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 72e1eda64..0076b4207 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -157,6 +157,8 @@ export default { logout: 'Logout', }, database: { + noMysql: 'No {0} database is detected, please go to App Store and click Install!', + goInstall: 'Go to install', source: 'Source', backup: 'Database backup', permission: 'Permission', @@ -637,7 +639,7 @@ export default { issue: 'Feedback', chat: 'Community Discussion', star: 'Star', - description: 'A modern Linux panel tool', + description: '1Panel, A modern open source Linux panel.', }, app: { installed: 'installed', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 6edac7f34..2a055c2a7 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -157,6 +157,8 @@ export default { logout: '退出登录', }, database: { + noMysql: '当前未检测到 {0} 数据库,请进入应用商店点击安装!', + goInstall: '去安装', source: '来源', backup: '备份数据库', permission: '权限', @@ -649,7 +651,7 @@ export default { issue: '问题反馈', chat: '参与讨论', star: '点亮 Star', - description: '一个现代化的 Linux 面板工具', + description: '1Panel,一款现代化的开源 Linux 面板。', }, app: { app: '应用', diff --git a/frontend/src/routers/modules/log.ts b/frontend/src/routers/modules/log.ts index 9b710015a..22f758931 100644 --- a/frontend/src/routers/modules/log.ts +++ b/frontend/src/routers/modules/log.ts @@ -1,7 +1,7 @@ import { Layout } from '@/routers/constant'; const logsRouter = { - sort: 10, + sort: 7, path: '/logs', component: Layout, redirect: '/logs', @@ -12,17 +12,17 @@ const logsRouter = { children: [ { path: '', - name: 'LoginLog', - component: () => import('@/views/log/login/index.vue'), + name: 'OperationLog', + component: () => import('@/views/log/operation/index.vue'), hidden: true, meta: { activeMenu: '/logs', }, }, { - path: 'operation', - name: 'OperationLog', - component: () => import('@/views/log/operation/index.vue'), + path: 'login', + name: 'LoginLog', + component: () => import('@/views/log/login/index.vue'), hidden: true, meta: { activeMenu: '/logs', diff --git a/frontend/src/routers/modules/setting.ts b/frontend/src/routers/modules/setting.ts index e8185035e..9575d6f15 100644 --- a/frontend/src/routers/modules/setting.ts +++ b/frontend/src/routers/modules/setting.ts @@ -1,7 +1,7 @@ import { Layout } from '@/routers/constant'; const settingRouter = { - sort: 7, + sort: 8, path: '/settings', component: Layout, redirect: '/setting', diff --git a/frontend/src/views/container/network/index.vue b/frontend/src/views/container/network/index.vue index b921e354f..c61ed7163 100644 --- a/frontend/src/views/container/network/index.vue +++ b/frontend/src/views/container/network/index.vue @@ -50,33 +50,7 @@ - - - - - - + @@ -84,10 +58,8 @@ diff --git a/frontend/src/views/container/volume/index.vue b/frontend/src/views/container/volume/index.vue index d8751b82a..fdc54b9aa 100644 --- a/frontend/src/views/container/volume/index.vue +++ b/frontend/src/views/container/volume/index.vue @@ -34,33 +34,7 @@ - - - - - - + @@ -69,9 +43,7 @@ import ComplexTable from '@/components/complex-table/index.vue'; import CreateDialog from '@/views/container/volume/create/index.vue'; import Submenu from '@/views/container/index.vue'; -import { Codemirror } from 'vue-codemirror'; -import { javascript } from '@codemirror/lang-javascript'; -import { oneDark } from '@codemirror/theme-one-dark'; +import CodemirrorDialog from '@/components/codemirror-dialog/codemirror.vue'; import { reactive, onMounted, ref } from 'vue'; import { dateFromat } from '@/utils/util'; import { deleteVolume, searchVolume, inspect } from '@/api/modules/container'; @@ -79,9 +51,8 @@ import { Container } from '@/api/interface/container'; import i18n from '@/lang'; import { useDeleteData } from '@/hooks/use-delete-data'; -const detailVisiable = ref(false); const detailInfo = ref(); -const extensions = [javascript(), oneDark]; +const codemirror = ref(); const data = ref(); const selects = ref([]); @@ -116,7 +87,11 @@ const search = async () => { const onInspect = async (id: string) => { const res = await inspect({ id: id, type: 'volume' }); detailInfo.value = JSON.stringify(JSON.parse(res.data), null, 2); - detailVisiable.value = true; + let param = { + header: i18n.global.t('commons.button.view'), + detailInfo: detailInfo.value, + }; + codemirror.value!.acceptParams(param); }; const batchDelete = async (row: Container.VolumeInfo | null) => { diff --git a/frontend/src/views/cronjob/operate/index.vue b/frontend/src/views/cronjob/operate/index.vue index da6edc879..9e8683041 100644 --- a/frontend/src/views/cronjob/operate/index.vue +++ b/frontend/src/views/cronjob/operate/index.vue @@ -12,7 +12,11 @@ style="width: 100%" v-model="dialogData.rowData!.type" > - + + + + + @@ -76,14 +80,9 @@
- - - - - - +
@@ -170,7 +169,8 @@ import i18n from '@/lang'; import { ElForm, ElMessage } from 'element-plus'; import { Cronjob } from '@/api/interface/cronjob'; import { addCronjob, editCronjob } from '@/api/modules/cronjob'; -import { listDBByVersion, loadVersions } from '@/api/modules/database'; +import { loadDBNames } from '@/api/modules/database'; +import { CheckAppInstalled } from '@/api/modules/app'; interface DialogProps { title: string; @@ -186,12 +186,10 @@ const acceptParams = (params: DialogProps): void => { dialogData.value = params; title.value = i18n.global.t('commons.button.' + dialogData.value.title); cronjobVisiable.value = true; - loadRunningOptions(); + checkMysqlInstalled(); loadBackups(); }; -const mysqlVersionOptions = ref(); -const dbOptions = ref(); const localDirID = ref(); const websiteOptions = ref([ @@ -203,6 +201,13 @@ const backupOptions = ref(); const emit = defineEmits<{ (e: 'search'): void }>(); +const mysqlInfo = reactive({ + isExist: false, + name: '', + version: '', + dbNames: [] as Array, +}); + const varifySpec = (rule: any, value: any, callback: any) => { switch (dialogData.value.rowData!.specType) { case 'perMonth': @@ -247,13 +252,6 @@ const varifySpec = (rule: any, value: any, callback: any) => { } callback(); }; -const typeOptions = [ - { label: i18n.global.t('cronjob.shell'), value: 'shell' }, - { label: i18n.global.t('cronjob.website'), value: 'website' }, - { label: i18n.global.t('cronjob.database'), value: 'database' }, - { label: i18n.global.t('cronjob.directory'), value: 'directory' }, - { label: i18n.global.t('cronjob.curl') + ' URL', value: 'curl' }, -]; const specOptions = [ { label: i18n.global.t('cronjob.perMonth'), value: 'perMonth' }, @@ -287,7 +285,6 @@ const rules = reactive({ script: [Rules.requiredInput], website: [Rules.requiredSelect], - database: [Rules.requiredSelect], dbName: [Rules.requiredSelect], url: [Rules.requiredInput], sourceDir: [Rules.requiredSelect], @@ -313,20 +310,14 @@ const loadBackups = async () => { } }; -const loadRunningOptions = async () => { - const res = await loadVersions(); - mysqlVersionOptions.value = res.data; - if (mysqlVersionOptions.value.length != 0) { - dialogData.value.rowData!.database = mysqlVersionOptions.value[0]; - changeDBVersion(); - } -}; -const changeDBVersion = async () => { - dialogData.value.rowData!.dbName = ''; - const res = await listDBByVersion(dialogData.value.rowData!.database); - dbOptions.value = res.data; - if (dbOptions.value.length != 0) { - dialogData.value.rowData!.dbName = dbOptions.value[0]; +const checkMysqlInstalled = async () => { + const res = await CheckAppInstalled('mysql'); + mysqlInfo.isExist = res.data.isExist; + mysqlInfo.name = res.data.name; + mysqlInfo.version = res.data.version; + if (mysqlInfo.isExist) { + const data = await loadDBNames(); + mysqlInfo.dbNames = data.data; } }; diff --git a/frontend/src/views/cronjob/record/index.vue b/frontend/src/views/cronjob/record/index.vue index 675cdc0fd..001e7407d 100644 --- a/frontend/src/views/cronjob/record/index.vue +++ b/frontend/src/views/cronjob/record/index.vue @@ -114,7 +114,7 @@ - {{ dialogData.rowData!.database }} + {{ dialogData.rowData!.dbName }} diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue index ac63d59c4..a4d190b97 100644 --- a/frontend/src/views/database/mysql/index.vue +++ b/frontend/src/views/database/mysql/index.vue @@ -1,86 +1,77 @@