fix: fix ClamAV scan failure issue (#12892)

This commit is contained in:
ssongliu
2026-05-28 18:04:29 +08:00
committed by GitHub
parent 4956b96193
commit f5b47cf74d
7 changed files with 56 additions and 10 deletions
+7 -2
View File
@@ -32,9 +32,14 @@ func AddScanTask(taskItem *task.Task, clam model.Clam, timeNow string) {
}
strategy = fmt.Sprintf("--%s=%s", clam.InfectedStrategy, dir)
}
taskItem.Logf("clamdscan --fdpass %s %s", strategy, clam.Path)
args := []string{"--fdpass"}
if strategy != "" {
args = append(args, strategy)
}
args = append(args, clam.Path)
taskItem.Logf("clamdscan %s", strings.Join(args, " "))
mgr := cmd.NewCommandMgr(cmd.WithIgnoreExist1(), cmd.WithTimeout(time.Duration(clam.Timeout)*time.Second), cmd.WithTask(*taskItem))
if err := mgr.Run("clamdscan", "--fdpass", strategy, clam.Path); err != nil {
if err := mgr.Run("clamdscan", args...); err != nil {
return fmt.Errorf("clamdscan failed, %v", err)
}
return nil
+16 -1
View File
@@ -240,7 +240,7 @@ func (c *CommandHelper) pipeContext() (context.Context, context.CancelFunc) {
func (c *CommandHelper) buildPipeCommands(ctx context.Context, commands []PipeCommand) []*exec.Cmd {
cmds := make([]*exec.Cmd, 0, len(commands))
for _, item := range commands {
cmdItem := exec.CommandContext(ctx, item.Name, item.Args...)
cmdItem := exec.CommandContext(ctx, item.Name, filterEmptyArgs(item.Args)...)
cmdItem.Env = append(os.Environ(), c.env...)
cmdItem.Env = append(cmdItem.Env, item.Env...)
cmdItem.Dir = c.workDir
@@ -305,6 +305,7 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
var newContext context.Context
var cancel context.CancelFunc
var outputFile *os.File
arg = filterEmptyArgs(arg)
if c.timeout != 0 {
if c.context == nil {
@@ -411,6 +412,20 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
}
}
func filterEmptyArgs(args []string) []string {
if len(args) == 0 {
return args
}
filtered := args[:0]
for _, arg := range args {
if arg == "" {
continue
}
filtered = append(filtered, arg)
}
return filtered
}
func contextDone(ctx context.Context) <-chan struct{} {
if ctx == nil {
return nil
+6 -2
View File
@@ -63,7 +63,7 @@ func (b *BaseApi) Login(c *gin.Context) {
if user == nil || user.MfaStatus != constant.StatusEnable {
go saveLoginLogs(c, req.Name, wrapLoginErr(msgKey, err))
}
if msgKey == "ErrAuth" || msgKey == "ErrEntrance" {
if msgKey == "ErrAuth" || msgKey == "ErrEntrance" || msgKey == "ErrNoneNode" {
if msgKey == "ErrAuth" {
global.IPTracker.RecordFailure(ip)
global.IPTracker.SetNeedCaptcha(ip)
@@ -109,6 +109,10 @@ func (b *BaseApi) MFALogin(c *gin.Context) {
user, msgKey, err := xpack.AuthProvider.MFALogin(c, req, string(entrance))
go saveLoginLogs(c, loginLogUserName(user, req.SessionID), wrapLoginErr(msgKey, err))
if msgKey == "ErrNoneNode" {
helper.BadAuth(c, msgKey, err)
return
}
if msgKey == "ErrMFA" {
global.IPTracker.RecordFailure(ip)
failures := initauth.GetMFASessionStore().RecordFailure(req.SessionID)
@@ -164,7 +168,7 @@ func (b *BaseApi) PasskeyFinishLogin(c *gin.Context) {
entrance := loadEntranceFromRequest(c)
user, msgKey, err := xpack.AuthProvider.PasskeyFinishLogin(c, sessionID, entrance)
go saveLoginLogs(c, loginLogUserName(user, ""), wrapLoginErr(msgKey, err))
if msgKey == "ErrAuth" || msgKey == "ErrEntrance" {
if msgKey == "ErrAuth" || msgKey == "ErrEntrance" || msgKey == "ErrNoneNode" {
if msgKey == "ErrAuth" {
global.IPTracker.SetNeedCaptcha(common.GetRealClientIP(c))
}
+9 -2
View File
@@ -183,14 +183,21 @@ func OperationLog() gin.HandlerFunc {
func loadOperationUser(c *gin.Context) string {
sessionUser, ok := c.Get(psessionUtils.GinContextSessionUserKey)
if ok {
psession, ok := sessionUser.(psessionUtils.SessionUser)
if ok {
return psession.Name
}
}
apiUsername, ok := c.Get("API_AUTH_USERNAME")
if !ok {
return ""
}
psession, ok := sessionUser.(psessionUtils.SessionUser)
username, ok := apiUsername.(string)
if !ok {
return ""
}
return psession.Name
return username
}
func fillOperationDetail(operationDic *operationJson, formatMap map[string]interface{}) {
+16 -1
View File
@@ -219,7 +219,7 @@ func (c *CommandHelper) pipeContext() (context.Context, context.CancelFunc) {
func (c *CommandHelper) buildPipeCommands(ctx context.Context, commands []PipeCommand) []*exec.Cmd {
cmds := make([]*exec.Cmd, 0, len(commands))
for _, item := range commands {
cmdItem := exec.CommandContext(ctx, item.Name, item.Args...)
cmdItem := exec.CommandContext(ctx, item.Name, filterEmptyArgs(item.Args)...)
cmdItem.Env = append(os.Environ(), c.env...)
cmdItem.Env = append(cmdItem.Env, item.Env...)
cmdItem.Dir = c.workDir
@@ -284,6 +284,7 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
var newContext context.Context
var cancel context.CancelFunc
var outputFile *os.File
arg = filterEmptyArgs(arg)
if c.timeout != 0 {
if c.context == nil {
@@ -378,6 +379,20 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
}
}
func filterEmptyArgs(args []string) []string {
if len(args) == 0 {
return args
}
filtered := args[:0]
for _, arg := range args {
if arg == "" {
continue
}
filtered = append(filtered, arg)
}
return filtered
}
func contextDone(ctx context.Context) <-chan struct{} {
if ctx == nil {
return nil
@@ -104,7 +104,7 @@
<el-table-column min-width="230px">
<template #default="{ row }">
<span v-if="row.id === currentRecord.id" class="select-sign"></span>
<Status class="mr-2 ml-1 float-left w-20" :status="row.status" />
<Status class="mr-2 mt-1 ml-1 float-left w-20" :status="row.status" />
<div class="mt-0.5">
<span>
{{ row.startTime }}
@@ -80,7 +80,7 @@
<el-table-column>
<template #default="{ row }">
<span v-if="row.id === currentRecord.id" class="select-sign"></span>
<Status class="mr-2 ml-1 float-left" :status="row.status" />
<Status class="mr-2 mt-1 ml-1 float-left" :status="row.status" />
<div class="mt-0.5 float-left">
<span>
{{ dateFormat(0, 0, row.startTime) }}