| 345 | } |
| 346 | |
| 347 | func (u *BackupService) checkBackupConn(backup *model.BackupAccount) (bool, error) { |
| 348 | client, err := newClient(backup, false) |
| 349 | if err != nil { |
| 350 | return false, err |
| 351 | } |
| 352 | fileItem := path.Join(global.Dir.BaseDir, "1panel/tmp/test/1panel") |
| 353 | if _, err := os.Stat(path.Dir(fileItem)); err != nil && os.IsNotExist(err) { |
| 354 | if err = os.MkdirAll(path.Dir(fileItem), os.ModePerm); err != nil { |
| 355 | return false, err |
| 356 | } |
| 357 | } |
| 358 | file, err := os.OpenFile(fileItem, os.O_WRONLY|os.O_CREATE, constant.FilePerm) |
| 359 | if err != nil { |
| 360 | return false, err |
| 361 | } |
| 362 | defer file.Close() |
| 363 | write := bufio.NewWriter(file) |
| 364 | _, _ = write.WriteString("1Panel 备份账号测试文件。\n") |
| 365 | _, _ = write.WriteString("1Panel 備份賬號測試文件。\n") |
| 366 | _, _ = write.WriteString("1Panel Backs up account test files.\n") |
| 367 | _, _ = write.WriteString("1Panelアカウントのテストファイルをバックアップします。\n") |
| 368 | write.Flush() |
| 369 | |
| 370 | targetPath := path.Join(backup.BackupPath, "test/1panel") |
| 371 | if backup.Type != constant.Sftp && backup.Type != constant.Local && targetPath != "/" { |
| 372 | targetPath = strings.TrimPrefix(targetPath, "/") |
| 373 | } |
| 374 | |
| 375 | if _, err := client.Upload(fileItem, targetPath); err != nil { |
| 376 | return false, err |
| 377 | } |
| 378 | _, _ = client.Delete(path.Join(backup.BackupPath, "test/1panel")) |
| 379 | return true, nil |
| 380 | } |
| 381 | |
| 382 | func (u *BackupService) LoadBackupOptions() ([]dto.BackupOption, error) { |
| 383 | accounts, err := backupRepo.List(repo.WithOrderDesc("created_at")) |