diff --git a/backend/app/repo/backup.go b/backend/app/repo/backup.go index 28d6f4a6c..2e4609b51 100644 --- a/backend/app/repo/backup.go +++ b/backend/app/repo/backup.go @@ -19,6 +19,7 @@ type IBackupRepo interface { Update(id uint, vars map[string]interface{}) error Delete(opts ...DBOption) error DeleteRecord(ctx context.Context, opts ...DBOption) error + UpdateRecord(record *model.BackupRecord) error WithByDetailName(detailName string) DBOption WithByFileName(fileName string) DBOption WithByType(backupType string) DBOption @@ -105,6 +106,10 @@ func (u *BackupRepo) CreateRecord(record *model.BackupRecord) error { return global.DB.Create(record).Error } +func (u *BackupRepo) UpdateRecord(record *model.BackupRecord) error { + return global.DB.Save(record).Error +} + func (u *BackupRepo) Update(id uint, vars map[string]interface{}) error { return global.DB.Model(&model.BackupAccount{}).Where("id = ?", id).Updates(vars).Error } diff --git a/backend/app/service/backup_website.go b/backend/app/service/backup_website.go index b96d797e2..fadcb3423 100644 --- a/backend/app/service/backup_website.go +++ b/backend/app/service/backup_website.go @@ -25,7 +25,7 @@ func (u *BackupService) WebsiteBackup(req dto.CommonBackup) error { if err != nil { return err } - website, err := websiteRepo.GetFirst(websiteRepo.WithDomain(req.Name)) + website, err := websiteRepo.GetFirst(websiteRepo.WithAlias(req.DetailName)) if err != nil { return err } @@ -40,7 +40,7 @@ func (u *BackupService) WebsiteBackup(req dto.CommonBackup) error { record := &model.BackupRecord{ Type: "website", Name: website.PrimaryDomain, - DetailName: "", + DetailName: req.DetailName, Source: "LOCAL", BackupType: "LOCAL", FileDir: backupDir, @@ -54,14 +54,14 @@ func (u *BackupService) WebsiteBackup(req dto.CommonBackup) error { } func (u *BackupService) WebsiteRecover(req dto.CommonRecover) error { - website, err := websiteRepo.GetFirst(websiteRepo.WithDomain(req.Name)) - if err != nil { - return err - } fileOp := files.NewFileOp() if !fileOp.Stat(req.File) { return errors.New(fmt.Sprintf("%s file is not exist", req.File)) } + website, err := websiteRepo.GetFirst(websiteRepo.WithAlias(req.DetailName)) + if err != nil { + return err + } global.LOG.Infof("recover website %s from backup file %s", req.Name, req.File) if err := handleWebsiteRecover(&website, req.File, false); err != nil { return err @@ -79,15 +79,6 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback _ = os.RemoveAll(tmpPath) }() - temPathWithName := tmpPath + "/" + website.Alias - if !fileOp.Stat(tmpPath+"/website.json") || !fileOp.Stat(temPathWithName+".conf") || !fileOp.Stat(temPathWithName+".web.tar.gz") { - return buserr.WithDetail(constant.ErrBackupExist, ".conf or .web.tar.gz", nil) - } - if website.Type == constant.Deployment { - if !fileOp.Stat(temPathWithName + ".app.tar.gz") { - return buserr.WithDetail(constant.ErrBackupExist, ".app.tar.gz", nil) - } - } var oldWebsite model.Website websiteJson, err := os.ReadFile(tmpPath + "/website.json") if err != nil { @@ -101,6 +92,16 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback return err } + temPathWithName := tmpPath + "/" + website.Alias + if !fileOp.Stat(tmpPath+"/website.json") || !fileOp.Stat(temPathWithName+".conf") || !fileOp.Stat(temPathWithName+".web.tar.gz") { + return buserr.WithDetail(constant.ErrBackupExist, ".conf or .web.tar.gz", nil) + } + if website.Type == constant.Deployment { + if !fileOp.Stat(temPathWithName + ".app.tar.gz") { + return buserr.WithDetail(constant.ErrBackupExist, ".app.tar.gz", nil) + } + } + isOk := false if !isRollback { rollbackFile := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("website/%s_%s.tar.gz", website.Alias, time.Now().Format("20060102150405"))) diff --git a/backend/app/service/firewall.go b/backend/app/service/firewall.go index 28541f418..85b180807 100644 --- a/backend/app/service/firewall.go +++ b/backend/app/service/firewall.go @@ -582,24 +582,6 @@ func (u *FirewallService) addAddressRecord(req dto.AddrRuleOperate) error { return nil } -func listIpRules(strategy string) ([]string, error) { - client, err := firewall.NewFirewallClient() - if err != nil { - return nil, err - } - addrs, err := client.ListAddress() - if err != nil { - return nil, err - } - var rules []string - for _, addr := range addrs { - if addr.Strategy == strategy { - rules = append(rules, addr.Address) - } - } - return rules, nil -} - func checkPortUsed(ports, proto string, apps []portOfApp) string { var portList []int if strings.Contains(ports, "-") || strings.Contains(ports, ",") { diff --git a/backend/app/service/website_ca.go b/backend/app/service/website_ca.go index 768ec29f0..607f6653a 100644 --- a/backend/app/service/website_ca.go +++ b/backend/app/service/website_ca.go @@ -104,6 +104,9 @@ func (w WebsiteCAService) Create(create request.WebsiteCACreate) (*request.Websi return nil, err } rootCert, err := x509.ParseCertificate(rootDer) + if err != nil { + return nil, err + } certBlock := &pem.Block{ Type: "CERTIFICATE", Bytes: rootCert.Raw, diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 7ba892d5e..13bae5e4a 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -60,6 +60,7 @@ func Init() { migrations.AddDatabaseSSL, migrations.AddDefaultCA, migrations.AddSettingRecycleBin, + migrations.UpdateWebsiteBackupRecord, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index f6393c14e..2c212b621 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -3,6 +3,7 @@ package migrations import ( "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/model" + "github.com/1Panel-dev/1Panel/backend/app/repo" "github.com/1Panel-dev/1Panel/backend/app/service" "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" @@ -87,3 +88,18 @@ var AddSettingRecycleBin = &gormigrate.Migration{ return nil }, } + +var UpdateWebsiteBackupRecord = &gormigrate.Migration{ + ID: "20231218-update-backup-record-for-website", + Migrate: func(tx *gorm.DB) error { + backupRepo := repo.NewIBackupRepo() + websitesBackups, _ := backupRepo.ListRecord(repo.NewCommonRepo().WithByType("website")) + if len(websitesBackups) > 0 { + for _, backup := range websitesBackups { + backup.DetailName = backup.Name + _ = backupRepo.UpdateRecord(&backup) + } + } + return nil + }, +} diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index 853245eb8..f8a0a7ce6 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -88,13 +88,6 @@ func IsCrossVersion(version1, version2 string) bool { return v2num > v1num } -func min(a, b int) int { - if a < b { - return a - } - return b -} - func GetUuid() string { b := make([]byte, 16) _, _ = io.ReadFull(rand.Reader, b) diff --git a/frontend/src/components/upload/index.vue b/frontend/src/components/upload/index.vue index 2f78b1178..097a5b097 100644 --- a/frontend/src/components/upload/index.vue +++ b/frontend/src/components/upload/index.vue @@ -142,6 +142,9 @@ const acceptParams = async (params: DialogProps): Promise => { } else { baseDir.value = `${pathRes.data}/uploads/${dir}/${name.value}/`; } + if (type.value === 'website') { + baseDir.value = `${pathRes.data}/uploads/database/${type.value}/${detailName.value}/`; + } upVisible.value = true; search(); }; diff --git a/frontend/src/views/website/website/config/basic/other/index.vue b/frontend/src/views/website/website/config/basic/other/index.vue index 93a44b7a1..026be266b 100644 --- a/frontend/src/views/website/website/config/basic/other/index.vue +++ b/frontend/src/views/website/website/config/basic/other/index.vue @@ -5,6 +5,9 @@ + + + + {{ $t('commons.button.save') }} @@ -58,6 +62,7 @@ const form = reactive({ remark: '', webSiteGroupId: 0, IPV6: false, + alias: '', }); const rules = ref({ primaryDomain: [Rules.requiredInput], @@ -91,6 +96,7 @@ const search = async () => { form.remark = res.data.remark; form.webSiteGroupId = res.data.webSiteGroupId; form.IPV6 = res.data.IPV6; + form.alias = res.data.alias; }); }; diff --git a/frontend/src/views/website/website/index.vue b/frontend/src/views/website/website/index.vue index 305b8a99f..03eeb8d44 100644 --- a/frontend/src/views/website/website/index.vue +++ b/frontend/src/views/website/website/index.vue @@ -379,7 +379,7 @@ const buttons = [ let params = { type: 'website', name: row.primaryDomain, - detailName: '', + detailName: row.alias, }; dialogBackupRef.value!.acceptParams(params); }, @@ -390,7 +390,7 @@ const buttons = [ let params = { type: 'website', name: row.primaryDomain, - detailName: '', + detailName: row.alias, }; uploadRef.value!.acceptParams(params); },