| 19 | ) |
| 20 | |
| 21 | func AddScanTask(taskItem *task.Task, clam model.Clam, timeNow string) { |
| 22 | taskItem.AddSubTask(i18n.GetWithName("Clamscan", clam.Path), func(t *task.Task) error { |
| 23 | strategy := "" |
| 24 | switch clam.InfectedStrategy { |
| 25 | case "remove": |
| 26 | strategy = "--remove" |
| 27 | case "move", "copy": |
| 28 | dir := path.Join(clam.InfectedDir, "1panel-infected", clam.Name, timeNow) |
| 29 | taskItem.Log("infected dir: " + dir) |
| 30 | if _, err := os.Stat(dir); err != nil { |
| 31 | _ = os.MkdirAll(dir, os.ModePerm) |
| 32 | } |
| 33 | strategy = fmt.Sprintf("--%s=%s", clam.InfectedStrategy, dir) |
| 34 | } |
| 35 | args := []string{"--fdpass"} |
| 36 | if strategy != "" { |
| 37 | args = append(args, strategy) |
| 38 | } |
| 39 | args = append(args, clam.Path) |
| 40 | taskItem.Logf("clamdscan %s", strings.Join(args, " ")) |
| 41 | mgr := cmd.NewCommandMgr(cmd.WithIgnoreExist1(), cmd.WithTimeout(time.Duration(clam.Timeout)*time.Second), cmd.WithTask(*taskItem)) |
| 42 | if err := mgr.Run("clamdscan", args...); err != nil { |
| 43 | return fmt.Errorf("clamdscan failed, %v", err) |
| 44 | } |
| 45 | return nil |
| 46 | }, nil) |
| 47 | } |
| 48 | |
| 49 | func AnalysisFromLog(pathItem string, record *model.ClamRecord) { |
| 50 | file, err := os.ReadFile(pathItem) |