Skip to content

Commit 99b04e3

Browse files
authored
fix: Fix SSH log export exception when logs are empty (#10114)
1 parent 2e06b78 commit 99b04e3

File tree

14 files changed

+103
-34
lines changed

14 files changed

+103
-34
lines changed

agent/app/api/v2/ssh.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ package v2
22

33
import (
44
"encoding/base64"
5-
"net/http"
6-
"net/url"
7-
"os"
8-
"strconv"
95

106
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
117
"github.com/1Panel-dev/1Panel/agent/app/dto"
@@ -231,7 +227,7 @@ func (b *BaseApi) LoadSSHLogs(c *gin.Context) {
231227
// @Summary Export host SSH logs
232228
// @Accept json
233229
// @Param request body dto.SearchSSHLog true "request"
234-
// @Success 200 {object} dto.PageResult
230+
// @Success 200 {string} path
235231
// @Security ApiKeyAuth
236232
// @Security Timestamp
237233
// @Router /hosts/ssh/log/export [post]
@@ -245,19 +241,7 @@ func (b *BaseApi) ExportSSHLogs(c *gin.Context) {
245241
helper.InternalServer(c, err)
246242
return
247243
}
248-
file, err := os.Open(tmpFile)
249-
if err != nil {
250-
helper.InternalServer(c, err)
251-
return
252-
}
253-
defer func() {
254-
_ = file.Close()
255-
_ = os.RemoveAll(tmpFile)
256-
}()
257-
info, _ := file.Stat()
258-
c.Header("Content-Length", strconv.FormatInt(info.Size(), 10))
259-
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name()))
260-
http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)
244+
helper.SuccessWithData(c, tmpFile)
261245
}
262246

263247
// @Tags SSH

agent/app/service/ssh.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ func (u *SSHService) ExportLog(ctx *gin.Context, req dto.SearchSSHLog) (string,
478478
if err != nil {
479479
return "", err
480480
}
481+
if len(logs) == 0 {
482+
return "", buserr.New("ErrRecordNotFound")
483+
}
481484
tmpFileName := path.Join(global.Dir.TmpDir, "export/ssh-log", fmt.Sprintf("1panel-ssh-log-%s.csv", time.Now().Format(constant.DateTimeSlimLayout)))
482485
if _, err := os.Stat(path.Dir(tmpFileName)); err != nil {
483486
_ = os.MkdirAll(path.Dir(tmpFileName), constant.DirPerm)

agent/i18n/lang/en.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ ErrAppVersionDeprecated: "The {{ .name }} application is not compatible with the
9393
ErrDockerFailed: "The state of Docker is abnormal, please check the service status"
9494
ErrDockerComposeCmdNotFound: "The Docker Compose command does not exist, please install this command on the host machine first"
9595

96+
#ssh
97+
ExportIP: "Login IP"
98+
ExportArea: "Location"
99+
ExportPort: "Port"
100+
ExportAuthMode: "Login Method"
101+
ExportUser: "User"
102+
ExportStatus: "Login Status"
103+
ExportDate: "Time"
104+
96105
#file
97106
ErrFileCanNotRead: 'This file does not support preview'
98107
ErrFileToLarge: 'The file is larger than 10M and cannot be opened'

agent/i18n/lang/ja.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ ErrAppVersionDeprecated: "{{ .name }} アプリケーションは現在の 1Pane
9393
ErrDockerFailed: "Docker の状態が異常です。サービス状態を確認してください"
9494
ErrDockerComposeCmdNotFound: "Docker Compose コマンドは存在しません。ホストマシンにこのコマンドを先にインストールしてください"
9595

96+
#ssh
97+
ExportIP: "ログインIP"
98+
ExportArea: "地域"
99+
ExportPort: "ポート"
100+
ExportAuthMode: "ログイン方式"
101+
ExportUser: "ユーザー"
102+
ExportStatus: "ログイン状態"
103+
ExportDate: "時間"
104+
96105
#file
97106
ErrFileCanNotRead: 'このファイルはプレビューをサポートしていません'
98107
ErrFileToLarge: 'ファイルは 10M より大きいため開けません'

agent/i18n/lang/ko.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ ErrAppVersionDeprecated: "{{ .name }} 응용 프로그램은 현재 1Panel 버
9393
ErrDockerFailed: "Docker의 상태가 비정상입니다. 서비스 상태를 확인하세요"
9494
ErrDockerComposeCmdNotFound: "Docker Compose 명령이 없습니다. 호스트 머신에 먼저 이 명령을 설치하세요"
9595

96+
#ssh
97+
ExportIP: "로그인 IP"
98+
ExportArea: "위치"
99+
ExportPort: "포트"
100+
ExportAuthMode: "로그인 방식"
101+
ExportUser: "사용자"
102+
ExportStatus: "로그인 상태"
103+
ExportDate: "시간"
104+
96105
#파일
97106
ErrFileCanNotRead: '이 파일은 미리보기를 지원하지 않습니다'
98107
ErrFileToLarge: '파일이 10M보다 커서 열 수 없습니다'

agent/i18n/lang/ms.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ ErrAppVersionDeprecated: "Aplikasi {{ .name }} tidak sesuai dengan versi 1Panel
9696
ErrDockerFailed: "Keadaan Docker tidak normal, sila periksa status perkhidmatan"
9797
ErrDockerComposeCmdNotFound: "Perintah Docker Compose tidak wujud, sila pasang perintah ini di mesin tuan terlebih dahulu"
9898

99+
#ssh
100+
ExportIP: "IP Log Masuk"
101+
ExportArea: "Lokasi"
102+
ExportPort: "Port"
103+
ExportAuthMode: "Kaedah Log Masuk"
104+
ExportUser: "Pengguna"
105+
ExportStatus: "Status Log Masuk"
106+
ExportDate: "Masa"
107+
99108
#fail
100109
ErrFileCanNotRead: 'Fail ini tidak menyokong pratonton'
101110
ErrFileToLarge: 'Fail lebih besar daripada 10M dan tidak boleh dibuka'

agent/i18n/lang/pt-BR.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ ErrAppVersionDeprecated: "O aplicativo {{ .name }} não é compatível com a ver
9696
ErrDockerFailed: "O estado do Docker está anormal, verifique o status do serviço"
9797
ErrDockerComposeCmdNotFound: "O comando Docker Compose não existe, por favor, instale este comando na máquina host primeiro"
9898

99+
#ssh
100+
ExportIP: "IP de Login"
101+
ExportArea: "Localização"
102+
ExportPort: "Porta"
103+
ExportAuthMode: "Método de Login"
104+
ExportUser: "Usuário"
105+
ExportStatus: "Status de Login"
106+
ExportDate: "Hora"
107+
99108
#arquivo
100109
ErrFileCanNotRead: 'Este arquivo não suporta visualização'
101110
ErrFileToLarge: 'O arquivo é maior que 10M e não pode ser aberto'

agent/i18n/lang/ru.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ ErrAppVersionDeprecated: "Приложение {{ .name }} несовмести
9696
ErrDockerFailed: "Состояние Docker аномально, проверьте состояние сервиса"
9797
ErrDockerComposeCmdNotFound: "Команда Docker Compose отсутствует, пожалуйста, установите эту команду на хост-машине сначала"
9898

99+
#ssh
100+
ExportIP: "IP входа"
101+
ExportArea: "Местоположение"
102+
ExportPort: "Порт"
103+
ExportAuthMode: "Способ входа"
104+
ExportUser: "Пользователь"
105+
ExportStatus: "Статус входа"
106+
ExportDate: "Время"
107+
99108
#файл
100109
ErrFileCanNotRead: 'Этот файл не поддерживает предварительный просмотр'
101110
ErrFileToLarge: 'Файл больше 10 МБ и не может быть открыт'

agent/i18n/lang/tr.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ ErrAppVersionDeprecated: "{{ .name }} uygulaması mevcut 1Panel sürümü ile uy
9696
ErrDockerFailed: "Docker durumu anormal, lütfen servis durumunu kontrol edin"
9797
ErrDockerComposeCmdNotFound: "Docker Compose komutu mevcut değil, lütfen önce bu komutu host makinesine yükleyin"
9898

99+
#ssh
100+
ExportIP: "Giriş IP"
101+
ExportArea: "Konum"
102+
ExportPort: "Port"
103+
ExportAuthMode: "Giriş Yöntemi"
104+
ExportUser: "Kullanıcı"
105+
ExportStatus: "Giriş Durumu"
106+
ExportDate: "Zaman"
107+
99108
#file
100109
ErrFileCanNotRead: 'Bu dosya önizlemeyi desteklemiyor'
101110
ErrFileToLarge: 'Dosya 10M'dan büyük ve açılamıyor'

agent/i18n/lang/zh-Hant.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ ErrAppVersionDeprecated: "{{ .name }} 應用不適配目前 1Panel 版本,跳
9292
ErrDockerFailed: "Docker 狀態異常,請檢查服務狀態"
9393
ErrDockerComposeCmdNotFound: "Docker Compose 命令不存在,請先在宿主機安裝此命令"
9494

95+
#ssh
96+
ExportIP: "登入IP"
97+
ExportArea: "歸屬地"
98+
ExportPort: "端口"
99+
ExportAuthMode: "登入方式"
100+
ExportUser: "使用者"
101+
ExportStatus: "登入狀態"
102+
ExportDate: "時間"
103+
95104
#file
96105
ErrFileCanNotRead: '此檔案不支援預覽'
97106
ErrFileToLarge: '檔案超過10M,無法開啟'

0 commit comments

Comments
 (0)