feat: Restrict the size of log files to read. (#9147)

This commit is contained in:
CityFun 2025-06-17 16:59:23 +08:00 committed by GitHub
parent 0c31fcc8a3
commit 146b628cc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 26 additions and 1 deletions

View file

@ -108,6 +108,7 @@ ErrSourcePathNotFound: 'Source directory does not exist'
ErrFavoriteExist: 'This path has already been favorited'
ErrInvalidChar: 'Illegal characters are not allowed'
ErrPathNotDelete: 'The selected directory cannot be deleted'
ErrLogFileToLarge: "The log file exceeds 500MB and cannot be opened"
#website
ErrAliasIsExist: 'Alias already exists'

View file

@ -108,6 +108,7 @@ ErrSourcePathNotFound: 'ソース ディレクトリが存在しません'
ErrFavoriteExist: 'このパスはすでにお気に入りに登録されています'
ErrInvalidChar: '不正な文字は許可されません'
ErrPathNotDelete: '選択されたディレクトリは削除できません'
ErrLogFileToLarge: "ログファイルが500MBを超えており、開くことができません"
#website
ErrAliasIsExist: 'エイリアスがすでに存在します'

View file

@ -108,6 +108,7 @@ ErrSourcePathNotFound: '소스 디렉토리가 존재하지 않습니다'
ErrFavoriteExist: '이 경로는 이미 즐겨찾기되었습니다'
ErrInvalidChar: '불법 문자는 허용되지 않습니다'
ErrPathNotDelete: '선택한 디렉토리를 삭제할 수 없습니다'
ErrLogFileToLarge: "로그 파일이 500MB를 초과하여 열 수 없습니다"
#웹사이트
ErrAliasIsExist: '별칭이 이미 존재합니다'

View file

@ -108,6 +108,7 @@ ErrSourcePathNotFound: 'O diretório de origem não existe'
ErrFavoriteExist: 'Este caminho já foi favorito'
ErrInvalidChar: 'Caracteres ilegais não são permitidos'
ErrPathNotDelete: 'O diretório selecionado não pode ser excluído'
ErrLogFileToLarge: "Fail log melebihi 500MB, tidak boleh dibuka"
#site
ErrAliasIsExist: 'Alias já existe'

View file

@ -108,6 +108,7 @@ ErrSourcePathNotFound: 'Исходный каталог не существуе
ErrFavoriteExist: 'Этот путь уже добавлен в избранное'
ErrInvalidChar: 'Недопустимые символы не допускаются'
ErrPathNotDelete: 'Выбранный каталог не может быть удален'
ErrLogFileToLarge: "Файл журнала превышает 500MB и не может быть открыт"
#веб-сайт
ErrAliasIsExist: 'Псевдоним уже существует'

View file

@ -107,6 +107,7 @@ ErrSourcePathNotFound: '來源目錄不存在'
ErrFavoriteExist: '已收藏此路徑'
ErrInvalidChar: '禁止使用非法字元'
ErrPathNotDelete: '所選目錄不可刪除'
ErrLogFileToLarge: "日志文件超过 500M無法打開"
#website
ErrAliasIsExist: '代號已存在'

View file

@ -107,6 +107,7 @@ ErrSourcePathNotFound: "源目录不存在"
ErrFavoriteExist: "已收藏此路径"
ErrInvalidChar: "禁止使用非法字符"
ErrPathNotDelete: "所选目录不可删除"
ErrLogFileToLarge: "日志文件超过 500M无法打开"
#website
ErrAliasIsExist: "代号已存在"

View file

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"github.com/1Panel-dev/1Panel/agent/buserr"
"github.com/1Panel-dev/1Panel/agent/constant"
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
"io"
@ -103,6 +104,16 @@ func ReadFileByLine(filename string, page, pageSize int, latest bool) (lines []s
}
defer file.Close()
fi, err := file.Stat()
if err != nil {
return
}
if fi.Size() > 500*1024*1024 {
err = buserr.New("ErrLogFileToLarge")
return
}
totalLines, err := countLines(filename)
if err != nil {
return

View file

@ -205,7 +205,14 @@ const getContent = async (pre: boolean) => {
isLoading.value = true;
emit('update:isReading', true);
const res = await readByLine(readReq, props.config.operateNode || '');
let res;
try {
res = await readByLine(readReq, props.config.operateNode || '');
} catch (error) {
isLoading.value = false;
firstLoading.value = false;
}
logPath.value = res.data.path;
firstLoading.value = false;