MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / LoadBaseInfo

Method LoadBaseInfo

agent/app/service/clam.go:56–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54}
55
56func (c *ClamService) LoadBaseInfo() (dto.ClamBaseInfo, error) {
57 var baseInfo dto.ClamBaseInfo
58 baseInfo.Version = "-"
59 baseInfo.FreshVersion = "-"
60
61 clamSvc, err := controller.LoadServiceName("clam")
62 if err != nil {
63 baseInfo.IsExist = false
64 return baseInfo, nil
65 }
66 c.serviceName = clamSvc
67 exist, _ := controller.CheckExist(clamSvc)
68 if exist {
69 baseInfo.IsExist = true
70 baseInfo.IsActive, _ = controller.CheckActive(clamSvc)
71 }
72
73 freshSvc, err := controller.LoadServiceName("freshclam")
74 if err != nil {
75 baseInfo.FreshIsExist = false
76 return baseInfo, nil
77 }
78 c.freshClamService = freshSvc
79 freshExist, _ := controller.CheckExist(freshSvc)
80 if freshExist {
81 baseInfo.FreshIsExist = true
82 baseInfo.FreshIsActive, _ = controller.CheckActive(freshSvc)
83 }
84
85 if !cmd.Which("clamdscan") {
86 baseInfo.IsActive = false
87 }
88
89 cmdMgr := cmd.NewCommandMgr(cmd.WithTimeout(20 * time.Second))
90 if baseInfo.IsActive {
91 version, err := cmdMgr.RunWithStdout("clamdscan", "--version")
92 if err == nil {
93 if strings.Contains(version, "/") {
94 baseInfo.Version = strings.TrimPrefix(strings.Split(version, "/")[0], "ClamAV ")
95 } else {
96 baseInfo.Version = strings.TrimPrefix(version, "ClamAV ")
97 }
98 }
99 } else {
100 _ = clam.CheckWithStopAll(false, clamRepo)
101 }
102 if baseInfo.FreshIsActive {
103 version, err := cmdMgr.RunWithStdout("freshclam", "--version")
104 if err == nil {
105 if strings.Contains(version, "/") {
106 baseInfo.FreshVersion = strings.TrimPrefix(strings.Split(version, "/")[0], "ClamAV ")
107 } else {
108 baseInfo.FreshVersion = strings.TrimPrefix(version, "ClamAV ")
109 }
110 }
111 }
112 return baseInfo, nil
113}

Callers

nothing calls this directly

Calls 2

CheckExistMethod · 0.65
RunWithStdoutMethod · 0.45

Tested by

no test coverage detected