From 653213a2a47abe0511cbcccdccb658390f516eb5 Mon Sep 17 00:00:00 2001 From: zhangjianjun_code <7844966+zhangjianjun_code@user.noreply.gitee.com> Date: Wed, 3 Feb 2021 17:44:08 +0800 Subject: [PATCH] Generate cvrf data repair; update the issue statistics mailing list --- common/common.go | 11 ++ conf/app.conf | 14 +- conf/product_app.conf | 6 +- controllers/file.go | 60 ++++---- cve-py/issue_statistics/to_email.xlsx | Bin 10694 -> 12011 bytes models/cve.go | 3 +- models/excel.go | 6 + taskhandler/cve.go | 65 ++++++--- taskhandler/cvrf.go | 190 ++++++++++++++++++-------- taskhandler/excel.go | 32 +++-- taskhandler/issuestatistics.go | 4 +- taskhandler/sendemail.go | 17 ++- util/http.go | 1 - 13 files changed, 276 insertions(+), 133 deletions(-) diff --git a/common/common.go b/common/common.go index 6693f3a..52bd155 100644 --- a/common/common.go +++ b/common/common.go @@ -5,6 +5,7 @@ import ( "github.com/astaxie/beego" "github.com/astaxie/beego/config" "github.com/astaxie/beego/logs" + "os" "strings" "time" ) @@ -432,3 +433,13 @@ func GetSpecialDate(beforeDate int) string { } return startDate } + +func CreateDir(Dir string) error{ + _, err := os.Stat(Dir) + if err != nil{ + if os.IsNotExist(err){ + os.Mkdir(Dir, 0777) + } + } + return err +} diff --git a/conf/app.conf b/conf/app.conf index 218c759..c8a4ae4 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -22,8 +22,8 @@ labelFixed = "CVE/FIXED" labelUnFix = "CVE/UNFIXED" labeUnaffected = "CVE/UNAFFECTED" fileDir = "download" -# release package download url -rpUrl = "http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv" +# release package download url http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv +rpUrl = "https://gitee.com/unsunghero/obs_pkg_rpms/raw/master/latest_rpm/openEuler-20.03-LTS.csv" [mysql] @@ -48,11 +48,11 @@ maxsize=204800 ymalflag = 2 getymal = 0 0 1 * * 1 cveflag = 2 -getcve = 0 4 16 * * * +getcve = 0 14 11 * * * oricveflag = 2 oricvecheck = 0 16 19 * * * getissueflag = 2 -getissue = 0 57 15 * * * +getissue = 0 50 10 * * * issueflag = 2 createissue = 0 7 16 * * * test = 0/10 * * * * * @@ -62,7 +62,7 @@ genexcelflag = 2 genexcel = 0 0/10 * * * * days = -30 prcnum = 50 -printlogflag = 1 +printlogflag = 2 printlog = 0 0/20 * * * * unlockflag = 2 unlock = 0 30 19 * * * @@ -75,7 +75,7 @@ exceptcve = 0 3 19 * * * gensaflag = 2 gensa = 0 3 19 * * * issuestatisticflag = 2 -issuestatistic = 0 53 15 * * * +issuestatistic = 0 11 10 * * * cvecredflag = 2 cvecredit = 0 53 14 * * * urgenttaskflag = 2 @@ -149,7 +149,7 @@ snsuffix = 1002 # Version package excel download address # example: openEuler-20.03-LTS@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv; # openEuler-20.03-LTS-SP1@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS-SP1.csv -v_pack_20_03_url = "openEuler-20.03-LTS@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv;openEuler-20.03-LTS-SP1@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS-SP1.csv" +v_pack_20_03_url = "openEuler-20.03-LTS@https;openEuler-20.03-LTS-SP1@https" # Time difference in different time zones sa_timestamp_zone = 28800 diff --git a/conf/product_app.conf b/conf/product_app.conf index 6ebdb55..6d95624 100644 --- a/conf/product_app.conf +++ b/conf/product_app.conf @@ -23,7 +23,7 @@ labelUnFix = "CVE/UNFIXED" labeUnaffected = "CVE/UNAFFECTED" fileDir = "download" # release package download url -rpUrl = "http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv" +rpUrl = "https://gitee.com/unsunghero/obs_pkg_rpms/raw/master/latest_rpm/openEuler-20.03-LTS.csv" @@ -76,7 +76,7 @@ exceptcve = 0 0 4 * * * gensaflag = 1 gensa = 0 1 0 * * * issuestatisticflag = 1 -issuestatistic = 0 35 8 * * * +issuestatistic = 0 1 10 * * 1,3,5 cvecredflag = 1 cvecredit = 0 0 5 * * * urgenttaskflag = 1 @@ -145,7 +145,7 @@ snsuffix = 1002 # Version package excel download address # example: openEuler-20.03-LTS@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv; # openEuler-20.03-LTS-SP1@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS-SP1.csv -v_pack_20_03_url = "openEuler-20.03-LTS@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv;openEuler-20.03-LTS-SP1@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS-SP1.csv" +v_pack_20_03_url = "openEuler-20.03-LTS@https://openEuler-20.03-LTS.csv;openEuler-20.03-LTS-SP1@https://openEuler-20.03-LTS-SP1.csv" # Time difference in different time zones sa_timestamp_zone = 28800 diff --git a/controllers/file.go b/controllers/file.go index 81af0e4..b4b9ea0 100644 --- a/controllers/file.go +++ b/controllers/file.go @@ -25,10 +25,7 @@ type FileController struct { // @router /lastExcel [get] func (f *FileController) DownloadLastExcel() { fd := beego.AppConfig.DefaultString("fileDir", "download") - err := util.MakeDir(fd) - if err != nil { - logs.Error(err) - } + err := common.CreateDir(fd) er := models.ExportRecord{} err = er.QueryLast() if err != nil { @@ -45,6 +42,7 @@ func (f *FileController) DownloadLastExcel() { //@router /downloadExcel func (f *FileController) DownLoadExcelByFileCode() { fd := beego.AppConfig.DefaultString("fileDir", "download") + common.CreateDir(fd) fc := f.GetString("fileCode") if fc == "" { _ = f.Ctx.Output.Body([]byte("err: fileCode is a required parameter ")) @@ -120,12 +118,13 @@ func (f *FileController) TriggerCveData() { cvrfFileList := make(map[string][]string) cvrfFileMap := make(map[string]taskhandler.CvrfSa) affectBranchSlice := make([]string, 0) - du := "openEuler-20.03-LTS@http://119.3.219.20:88/mkb/obs_update_info/openEuler-20.03-LTS.csv" + du := "openEuler-20.03-LTS@https://gitee.com/unsunghero/obs_pkg_rpms/raw/master/latest_rpm/openEuler-20.03-LTS.csv" //du := beego.AppConfig.String("excel::v_pack_20_03_url") du = beego.AppConfig.DefaultString("excel::v_pack_20_03_url", du) csvPathList := strings.Split(du, ";") if len(csvPathList) > 0 { for _, csvP := range csvPathList { + time.Sleep(time.Second) openBranchx := strings.Split(csvP, "@") if len(openBranchx) == 2 { affectBranch := openBranchx[0] @@ -143,7 +142,7 @@ func (f *FileController) TriggerCveData() { // return the success notice // Need to be executed sequentially wgCrvf.Add(1) - go taskhandler.GenerateExcelTrigger(&wgCrvf, en, startTime, fileCode, affectBranch, + taskhandler.GenerateExcelTrigger(&wgCrvf, en, startTime, fileCode, affectBranch, csvDownPath, dir, cvrfFileList, componentMap, cvrfFileMap) // Return the result first, continue processing the data f.Ctx.WriteString(fmt.Sprintf("Success:The name of the excel file generated this time is: %s. "+ @@ -167,6 +166,7 @@ func GenAndUploadCvrf(cvrfFileMap map[string]taskhandler.CvrfSa, // taskhandler.WriteCvrfXml(cvrfKey, &cvrfVule) // } //} + common.CreateDir(dir) writeCvrfSlice := make([]string, 0) totalFileSlice := make([]string, 0) if len(componentMap) > 0 { @@ -183,12 +183,15 @@ func GenAndUploadCvrf(cvrfFileMap map[string]taskhandler.CvrfSa, if isEque { cvrfFileName := componentMap[comKey].CvrfFileName cvrfVule := cvrfFileMap[cvrfFileName] - if !taskhandler.QueryCveMd5(componentMap[comKey].CveNum, componentMap[comKey].OwnedComponent, - componentMap[comKey].OpenEulerSANum, taskhandler.FIXEDFLAGE) { - taskhandler.WriteCvrfXml(cvrfFileName, &cvrfVule) - writeCvrfSlice = append(writeCvrfSlice, cvrfFileName) - } else { - UpdateOpenEulerSaNumStatus(comValue.OpenEulerSANum) + md5Ok, tmpOpenEulerSANum := taskhandler.QueryCveMd5(componentMap[comKey].CveNum, componentMap[comKey].OwnedComponent, + componentMap[comKey].OpenEulerSANum, taskhandler.FIXEDFLAGE) + taskhandler.WriteCvrfXml(cvrfFileName, &cvrfVule) + writeCvrfSlice = append(writeCvrfSlice, cvrfFileName) + if md5Ok { + UpdateOpenEulerSaNumStatus(tmpOpenEulerSANum) + var saf models.SaFileList + saf.FileName = "cvrf-" + tmpOpenEulerSANum + ".xml" + models.DeleteCvrfFileName(&saf, "FileName") } for _, br := range comValue.CveNumMap { UpdateOpenEulerSaNumStatus(br.OpenEulerSANum) @@ -197,12 +200,15 @@ func GenAndUploadCvrf(cvrfFileMap map[string]taskhandler.CvrfSa, for _, br := range comValue.CveNumMap { cvrfFileName := br.CvrfFileName cvrfVule := cvrfFileMap[br.CvrfFileName] - if !taskhandler.QueryCveMd5(br.CveNumSlice, componentMap[comKey].OwnedComponent, - br.OpenEulerSANum, taskhandler.FIXEDFLAGE) { - taskhandler.WriteCvrfXml(cvrfFileName, &cvrfVule) - writeCvrfSlice = append(writeCvrfSlice, cvrfFileName) - } else { - UpdateOpenEulerSaNumStatus(br.OpenEulerSANum) + md5Ok, tmpOpenEulerSANum := taskhandler.QueryCveMd5(br.CveNumSlice, componentMap[comKey].OwnedComponent, + br.OpenEulerSANum, taskhandler.FIXEDFLAGE) + taskhandler.WriteCvrfXml(cvrfFileName, &cvrfVule) + writeCvrfSlice = append(writeCvrfSlice, cvrfFileName) + if md5Ok { + UpdateOpenEulerSaNumStatus(tmpOpenEulerSANum) + var saf models.SaFileList + saf.FileName = "cvrf-" + tmpOpenEulerSANum + ".xml" + models.DeleteCvrfFileName(&saf, "FileName") } } UpdateOpenEulerSaNumStatus(comValue.OpenEulerSANum) @@ -210,12 +216,15 @@ func GenAndUploadCvrf(cvrfFileMap map[string]taskhandler.CvrfSa, } else { cvrfFileName := componentMap[comKey].CvrfFileName cvrfVule := cvrfFileMap[cvrfFileName] - if !taskhandler.QueryCveMd5(componentMap[comKey].CveNum, componentMap[comKey].OwnedComponent, - componentMap[comKey].OpenEulerSANum, taskhandler.FIXEDFLAGE) { - taskhandler.WriteCvrfXml(cvrfFileName, &cvrfVule) - writeCvrfSlice = append(writeCvrfSlice, cvrfFileName) - } else { - UpdateOpenEulerSaNumStatus(comValue.OpenEulerSANum) + md5Ok, tmpOpenEulerSANum := taskhandler.QueryCveMd5(componentMap[comKey].CveNum, componentMap[comKey].OwnedComponent, + componentMap[comKey].OpenEulerSANum, taskhandler.FIXEDFLAGE) + taskhandler.WriteCvrfXml(cvrfFileName, &cvrfVule) + writeCvrfSlice = append(writeCvrfSlice, cvrfFileName) + if md5Ok { + UpdateOpenEulerSaNumStatus(tmpOpenEulerSANum) + var saf models.SaFileList + saf.FileName = "cvrf-" + tmpOpenEulerSANum + ".xml" + models.DeleteCvrfFileName(&saf, "FileName") } for _, br := range comValue.CveNumMap { UpdateOpenEulerSaNumStatus(br.OpenEulerSANum) @@ -257,9 +266,10 @@ func uploadCvrfFile(cvrfFileList map[string][]string, totalFileSlice []string, d sfl := models.GetCvrfAllFile() indexFilePath := filepath.Join(dir, "index.txt") updateFilePath := filepath.Join(dir, "update_fixed.txt") + curYears := strconv.Itoa(time.Now().Year()) if len(sfl) > 0 { for _, l := range sfl { - totalSlice = append(totalSlice, l.FileName) + totalSlice = append(totalSlice, curYears+"/"+l.FileName) } //totalSlice = append(totalSlice, subFileSlice...) readErr := taskhandler.ReadWriteFile(indexFilePath, totalSlice) diff --git a/cve-py/issue_statistics/to_email.xlsx b/cve-py/issue_statistics/to_email.xlsx index 9d5ced369808b0b11e80745974ad2b0704fd1326..9575d691e239b399e5aebc2902998f8554c91e7e 100644 GIT binary patch delta 5837 zcmZvAcQ72_)Bl~`olcxyPKg@5_uis+POs6Tmm`Si<(w{hk9r6}5G{y)f{0$DOGpsq zmGAGJ-|u~Ae*4EW&$Ij4ot=4RcXmI+28UKnZ-FqC^(BBX5CBj{0{}<>0Dyy+y`Ha^ zw;!Lqm#-slkf%p-x|Qw#Bl+u7?OS5PKRivfOKRhrssTHsWX?jXBx1{NVoBw??n2Fu z50b2d)K}x;{(x(*Cxw=*R8-yOoqq)732| zK#$pddiQJV8iM?TmH;HW$M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wQn?U8D!M zIZof%|9&5ei~-1CpGygyIpknVk%?U7ZW1gB-|TvO$sSJNQ&JuxC+_5&d^ocvS?gHw zo_LMFV!%+YQ>pcGHUn4FKsQ2pG--j6wBUbffdT(J2kK}9`iQ{4xq(?hHSh#Gz$zpO zK4J$@LaESyH79^&A#?B{7@#Ib0MeqYfS)iW5g!mCEDq-61geE)z`C4(5f7^f%76$= zf0aG|e@m?TO5iXqAc~g};1i-`{ZBMOpd0_T^516g|9}{PeqO5obGiR?1wbIi q|8*z`0;IqYfVS98@Lkd?l^J+0CImJk2Od)}1CwIZBv_t*@c#u7A5>=m diff --git a/models/cve.go b/models/cve.go index 0fc67d1..109707e 100644 --- a/models/cve.go +++ b/models/cve.go @@ -936,7 +936,8 @@ d.affect_product,d.reference_link,d.affect_status, e.public_date,e.openeuler_sa_num,a.cve_level,b.organizate_id FROM cve_issue_template a RIGHT JOIN -(SELECT (SELECT COUNT(*) FROM cve_vuln_center WHERE cve_num = ?) num ,bc.cve_id,bc.cve_num,bc.organizate_id +(SELECT (SELECT COUNT(*) FROM cve_vuln_center WHERE cve_num = ? AND is_export = 3) num , +bc.cve_id,bc.cve_num,bc.organizate_id FROM cve_vuln_center bc WHERE bc.cve_num = ? AND bc.is_export = 3 ) b ON a.cve_id = b.cve_id LEFT JOIN cve_score c diff --git a/models/excel.go b/models/excel.go index 9d144be..d4f3308 100644 --- a/models/excel.go +++ b/models/excel.go @@ -120,3 +120,9 @@ func UpdateCvrfFileName(afl *SaFileList, fields ...string) error { _, err := o.Update(afl, fields...) return err } + +func DeleteCvrfFileName(afl *SaFileList, fields ...string) error { + o := orm.NewOrm() + _, err := o.Delete(afl, fields...) + return err +} diff --git a/taskhandler/cve.go b/taskhandler/cve.go index 6d4ed78..4a39365 100644 --- a/taskhandler/cve.go +++ b/taskhandler/cve.go @@ -4,13 +4,13 @@ import ( "cvevulner/common" "cvevulner/models" "cvevulner/util" + "encoding/base64" "encoding/json" "errors" "fmt" "github.com/astaxie/beego" "github.com/astaxie/beego/config" "github.com/astaxie/beego/logs" - "io" "io/ioutil" "net/http" "net/url" @@ -1983,7 +1983,7 @@ func GenerateExcelTrigger(wgx *sync.WaitGroup, fileName, startTime, fileCode, af } fileName = filepath.Join(dir, fileName) localPath := filepath.Join(dir, affectBranch+"_release-package.CSV") - err = downloadPackageFile(localPath, csvDownPath) + err = downloadPackageFile(localPath, csvDownPath, affectBranch) if err != nil { logs.Error(err) fr.State = 2 @@ -2007,7 +2007,6 @@ func GenerateExcelTrigger(wgx *sync.WaitGroup, fileName, startTime, fileCode, af fr.State = 1 } _ = fr.Update("state") - // zip file zipFileList := []string{fileName, filePath} //zipFileList := []string{"download/cve与安全公告openEuler-20.03-LTS_1607081986.xlsx", "download/updateinfo.xml"} @@ -2031,29 +2030,53 @@ func GenerateExcelTrigger(wgx *sync.WaitGroup, fileName, startTime, fileCode, af logs.Info(affectBranch, ", GenerateExcelTrigger: end") } -func downloadPackageFile(localPath, url string) error { - resp, err := http.Get(url) +func downloadPackageFile(localPath, url, affectBranch string) error { + logs.Info("The csv file currently being downloaded is: ", url) + pkgLock.Lock() + err := GiteeDownCsv(localPath, affectBranch) + pkgLock.Unlock() + return err +} + +func GiteeDownCsv(localPath, branch string) (error) { + accessToken := os.Getenv("GITEE_TOKEN") + owner := "unsunghero" + repo := "obs_pkg_rpms" + path := fmt.Sprintf("latest_rpm/%v.csv", branch) + gitUrl := fmt.Sprintf("https://gitee.com/api/v5/repos/%v/%v/contents/%v?access_token=%v", owner, repo, path, accessToken) + resp, err := http.Get(gitUrl) if err != nil { + logs.Error("get error, url:", gitUrl, "error: ", err) return err } defer resp.Body.Close() - if resp.StatusCode == http.StatusOK { - pkgLock.Lock() - defer pkgLock.Unlock() - if ex, _ := util.IsExistPath(localPath); ex { - err := os.Remove(localPath) - if err != nil { - logs.Error(err) - } - } - out, err := os.Create(localPath) - if err != nil { - return err - } - defer out.Close() - _, err = io.Copy(out, resp.Body) + body, err := ioutil.ReadAll(resp.Body) + if err != nil || body == nil { + logs.Error(err) + return err + } + logs.Info("body: \n", string(body), "url: ", gitUrl) + var contents map[string]interface{} + err = json.Unmarshal(body, &contents) + if err != nil { + logs.Error(err) return err + } + f, ferr := os.Create(localPath) + if ferr != nil { + logs.Error(ferr) + return ferr + } + fileType := contents["type"].(string) + encoding := contents["encoding"].(string) + content := contents["content"].(string) + if fileType == "file" && encoding == "base64" { + data, baseErr := base64.StdEncoding.DecodeString(content) + if baseErr == nil { + f.Write(data) + } } else { - return errors.New("download file request fail") + f.WriteString(content) } + return nil } diff --git a/taskhandler/cvrf.go b/taskhandler/cvrf.go index 83b8d02..5a8e21f 100644 --- a/taskhandler/cvrf.go +++ b/taskhandler/cvrf.go @@ -260,6 +260,7 @@ type BrachCveInfo struct { OpenEulerSANum string CvrfFileName string CveNumSlice []string + OpenEulerScore []float64 } type ComponentInfo struct { @@ -516,7 +517,7 @@ func BranchExist(affectBranch string, cvrfFileList map[string][]string) []string func BuilddocumentNotes(cvrfsa *CvrfSa, v models.ExcelExport, introduction, topic, affectBranch string, componentMap map[string]ComponentInfo, - branchList []string) { + branchList []string, branchFlag int) { documentNotes := cvrfsa.DocumentNotes if documentNotes == nil || cvrfsa.DocumentNotes.Note == nil || len(cvrfsa.DocumentNotes.Note) == 0 { @@ -595,32 +596,53 @@ func BuilddocumentNotes(cvrfsa *CvrfSa, v models.ExcelExport, te.Note = te.Note } if te.Title == "Topic" { - vcn := strings.Join(componentInfo.CveNum, ";\n") - theme, err := models.GetCanExportTheme(vcn, v.InfluenceComponent, affectBranch) - if err == nil && len(theme) > 1 { - theme = strings.ReplaceAll(theme, "\n\n", "\r\n\r\n") - if branchCount <= 1 { + vcn := "" + if branchFlag == 1 { + vcn = strings.Join(componentInfo.CveNum, ";\n") + theme, err := models.GetCanExportTheme(vcn, v.InfluenceComponent, affectBranch) + if err == nil && len(theme) > 1 { + theme = strings.ReplaceAll(theme, "\n\n", "\r\n\r\n") + if branchCount <= 1 { + te.Note = theme + } else if branchCount == 2 { + te.Note = strings.ReplaceAll(theme, affectBranch, strings.Join(branchList, " and ")) + } else { + reBanch := strings.Join(branchList[:len(branchList)-1], ",") + " and " + branchList[len(branchList)-1] + te.Note = strings.ReplaceAll(theme, affectBranch, reBanch) + } + } + } else { + vcn = strings.Join(componentInfo.CveNumMap[affectBranch].CveNumSlice, ";\n") + theme, err := models.GetCanExportTheme(vcn, v.InfluenceComponent, affectBranch) + if err == nil && len(theme) > 1 { + theme = strings.ReplaceAll(theme, "\n\n", "\r\n\r\n") te.Note = theme - } else if branchCount == 2 { - te.Note = strings.ReplaceAll(theme, affectBranch, strings.Join(branchList, " and ")) - } else { - reBanch := strings.Join(branchList[:len(branchList)-1], ",") + " and " + branchList[len(branchList)-1] - te.Note = strings.ReplaceAll(theme, affectBranch, reBanch) } } } if te.Title == "Summary" { - if branchCount <= 1 { - te.Note = v.Introduction - } else if branchCount == 2 { - te.Note = strings.ReplaceAll(v.Introduction, affectBranch, strings.Join(branchList, " and ")) + if branchFlag == 1 { + if branchCount <= 1 { + te.Note = v.Introduction + } else if branchCount == 2 { + te.Note = strings.ReplaceAll(v.Introduction, affectBranch, strings.Join(branchList, " and ")) + } else { + reBanch := strings.Join(branchList[:len(branchList)-1], ",") + " and " + branchList[len(branchList)-1] + te.Note = strings.ReplaceAll(v.Introduction, affectBranch, reBanch) + } } else { - reBanch := strings.Join(branchList[:len(branchList)-1], ",") + " and " + branchList[len(branchList)-1] - te.Note = strings.ReplaceAll(v.Introduction, affectBranch, reBanch) + te.Note = v.Introduction } + } if te.Title == "Severity" { - openEulerScoreSlice := componentInfo.OpenEulerScore + var openEulerScoreSlice []float64 + if branchFlag == 1 { + openEulerScoreSlice = componentInfo.OpenEulerScore + } else { + openEulerScoreSlice = componentInfo.CveNumMap[affectBranch].OpenEulerScore + } + if len(openEulerScoreSlice) > 1 { sort.Float64s(openEulerScoreSlice) } @@ -637,22 +659,38 @@ func BuilddocumentNotes(cvrfsa *CvrfSa, v models.ExcelExport, func BuildDocumentTitle(cvrfsa *CvrfSa, v models.ExcelExport, affectBranch string, cvrfFileList map[string][]string, componentMap map[string]ComponentInfo, - curDate string, branchList []string) { + curDate string, branchList []string, branchFlag int) { var documt DocumentTitle introduction := "" topic := "" branchCount := len(branchList) - if branchCount <= 1 { + ownedComponent := "" + if len(v.InfluenceComponent) > 1 { + ownedComponent = v.InfluenceComponent + } else { + ownedComponent = v.OwnedComponent + } + componentInfo := componentMap[ownedComponent] + localOpenEulerSANum := "" + if branchFlag == 1 { + localOpenEulerSANum = componentInfo.OpenEulerSANum + if branchCount <= 1 { + introduction = v.Introduction + topic = v.Theme + } else if branchCount == 2 { + introduction = strings.ReplaceAll(v.Introduction, affectBranch, strings.Join(branchList, " and ")) + topic = strings.ReplaceAll(v.Theme, affectBranch, strings.Join(branchList, " and ")) + } else { + reBanch := strings.Join(branchList[:len(branchList)-1], ",") + " and " + branchList[len(branchList)-1] + introduction = strings.ReplaceAll(v.Introduction, affectBranch, reBanch) + topic = strings.ReplaceAll(v.Theme, affectBranch, reBanch) + } + } else { introduction = v.Introduction topic = v.Theme - } else if branchCount == 2 { - introduction = strings.ReplaceAll(v.Introduction, affectBranch, strings.Join(branchList, " and ")) - topic = strings.ReplaceAll(v.Theme, affectBranch, strings.Join(branchList, " and ")) - } else { - reBanch := strings.Join(branchList[:len(branchList)-1], ",") + " and " + branchList[len(branchList)-1] - introduction = strings.ReplaceAll(v.Introduction, affectBranch, reBanch) - topic = strings.ReplaceAll(v.Theme, affectBranch, reBanch) + localOpenEulerSANum = componentInfo.CveNumMap[affectBranch].OpenEulerSANum } + if len(introduction) > 1 { documt.DocumentTitle = introduction[:len(introduction)-1] } else { @@ -668,14 +706,7 @@ func BuildDocumentTitle(cvrfsa *CvrfSa, v models.ExcelExport, affectBranch strin cvrfsa.DocumentPublisher = &documentPublisher var documentTracking DocumentTracking var identification Identification - ownedComponent := "" - if len(v.InfluenceComponent) > 1 { - ownedComponent = v.InfluenceComponent - } else { - ownedComponent = v.OwnedComponent - } - componentInfo := componentMap[ownedComponent] - identification.Id = componentInfo.OpenEulerSANum + identification.Id = localOpenEulerSANum documentTracking.Identification = &identification documentTracking.Status = "Final" documentTracking.Version = "1.0" @@ -713,11 +744,21 @@ func BuildDocumentTitle(cvrfsa *CvrfSa, v models.ExcelExport, affectBranch strin documentTracking.Generator = &generator cvrfsa.DocumentTracking = &documentTracking BuilddocumentNotes(cvrfsa, v, introduction, topic, - affectBranch, componentMap, branchList) + affectBranch, componentMap, branchList, branchFlag) } -func BuildDocumentRef(cvrfsa *CvrfSa, v models.ExcelExport, componentMap map[string]ComponentInfo) { +func BuildDocumentRef(cvrfsa *CvrfSa, v models.ExcelExport, + componentMap map[string]ComponentInfo, branchFlag int, affectBranch string) { componentInfo, comOk := componentMap[v.InfluenceComponent] + localOpenEulerSANum := "" + localCveNum := []string{} + if branchFlag == 1 { + localOpenEulerSANum = componentInfo.OpenEulerSANum + localCveNum = componentInfo.CveNum + } else { + localOpenEulerSANum = componentInfo.CveNumMap[affectBranch].OpenEulerSANum + localCveNum = componentInfo.CveNumMap[affectBranch].CveNumSlice + } if comOk { if cvrfsa.DocumentReferences != nil && len(cvrfsa.DocumentReferences.CveReference) > 0 { cveReference := cvrfsa.DocumentReferences.CveReference @@ -758,14 +799,14 @@ func BuildDocumentRef(cvrfsa *CvrfSa, v models.ExcelExport, componentMap map[str var cveReference0 CveReference cveUrlSlice0 := make([]CveUrl, 0) var cveUrl0 CveUrl - cveUrl0.Url = "https://openeuler.org/en/security/safety-bulletin/detail.html?id=" + componentInfo.OpenEulerSANum + cveUrl0.Url = "https://openeuler.org/en/security/safety-bulletin/detail.html?id=" + localOpenEulerSANum cveUrlSlice0 = append(cveUrlSlice0, cveUrl0) cveReference0.Type = "Self" cveReference0.CveUrl = cveUrlSlice0 cveReferenceSlice = append(cveReferenceSlice, cveReference0) var cveReference1 CveReference cveUrlSlice1 := make([]CveUrl, 0) - for _, cveNum := range componentInfo.CveNum { + for _, cveNum := range localCveNum { var cveUrl1 CveUrl cveUrl1.Url = "https://openeuler.org/en/security/cve/detail.html?id=" + cveNum cveUrlSlice1 = append(cveUrlSlice1, cveUrl1) @@ -775,7 +816,7 @@ func BuildDocumentRef(cvrfsa *CvrfSa, v models.ExcelExport, componentMap map[str cveReferenceSlice = append(cveReferenceSlice, cveReference1) var cveReference2 CveReference cveUrlSlice2 := make([]CveUrl, 0) - for _, cveNum := range componentInfo.CveNum { + for _, cveNum := range localCveNum { var cveUrl2 CveUrl cveUrl2.Url = "https://nvd.nist.gov/vuln/detail/" + cveNum cveUrlSlice2 = append(cveUrlSlice2, cveUrl2) @@ -789,8 +830,9 @@ func BuildDocumentRef(cvrfsa *CvrfSa, v models.ExcelExport, componentMap map[str } } -func BuildProductTree(cvrfsa *CvrfSa, v models.ExcelExport, pkg []models.Package, affectBranch string) { - if cvrfsa.ProductTree != nil && len(cvrfsa.ProductTree.OpenEulerBranch) > 0 { +func BuildProductTree(cvrfsa *CvrfSa, v models.ExcelExport, pkg []models.Package, + affectBranch string, branchFlag int) { + if cvrfsa.ProductTree != nil && len(cvrfsa.ProductTree.OpenEulerBranch) > 0 && branchFlag == 1 { affectBranchListx := strings.Split(affectBranch, "-") cpe := fmt.Sprintf("cpe:/a:%v:%v:%v", affectBranchListx[0], affectBranchListx[0], strings.Join(affectBranchListx[1:], "-")) @@ -1004,7 +1046,7 @@ func BuildProductTree(cvrfsa *CvrfSa, v models.ExcelExport, pkg []models.Package } func BuildVulnerability(vlLenth int, v models.ExcelExport, - componentMap map[string]ComponentInfo, cpe string) []Vulnerability { + componentMap map[string]ComponentInfo, cpe string, branchFlag int) []Vulnerability { vulnerabilitySlice := make([]Vulnerability, 0) var vulnerability Vulnerability vulnerability.Xmlns = "http://www.icasi.org/CVRF/schema/vuln/1.1" @@ -1054,7 +1096,13 @@ func BuildVulnerability(vlLenth int, v models.ExcelExport, ownedComponent = v.OwnedComponent } componentInfo := componentMap[ownedComponent] - remediation.Url = "https://openeuler.org/en/security/safety-bulletin/detail.html?id=" + componentInfo.OpenEulerSANum + localOpenEulerSANum := "" + if branchFlag == 1 { + localOpenEulerSANum = componentInfo.OpenEulerSANum + } else { + localOpenEulerSANum = componentInfo.CveNumMap[cpe].OpenEulerSANum + } + remediation.Url = "https://openeuler.org/en/security/safety-bulletin/detail.html?id=" + localOpenEulerSANum remediations.Remediation = &remediation vulnerability.Remediations = &remediations vulnerabilitySlice = append(vulnerabilitySlice, vulnerability) @@ -1062,7 +1110,7 @@ func BuildVulnerability(vlLenth int, v models.ExcelExport, } func BuildVulnerabilitySlice(vulnerability []Vulnerability, v models.ExcelExport, - affectBranch string, componentMap map[string]ComponentInfo) []Vulnerability { + affectBranch string, componentMap map[string]ComponentInfo, branchFlag int) []Vulnerability { //affectBranchListx := strings.Split(affectBranch, "-") //cpe := fmt.Sprintf("cpe:/a:%v:%v:%v", // affectBranchListx[0], affectBranchListx[0], strings.Join(affectBranchListx[1:], "-")) @@ -1081,7 +1129,14 @@ func BuildVulnerabilitySlice(vulnerability []Vulnerability, v models.ExcelExport if !cpeExist { var productId ProductId productId.ProductId = cpe - vl.ProductStatuses.Status.ProductId = append(vl.ProductStatuses.Status.ProductId, productId) + if branchFlag == 1 { + vl.ProductStatuses.Status.ProductId = append(vl.ProductStatuses.Status.ProductId, productId) + } else { + productIdSlice := make([]ProductId, 0) + productIdSlice = append(productIdSlice, productId) + vl.ProductStatuses.Status.ProductId = productIdSlice + } + } cveExist = true break @@ -1089,21 +1144,21 @@ func BuildVulnerabilitySlice(vulnerability []Vulnerability, v models.ExcelExport } if !cveExist { vlLenth := len(vulnerability) + 1 - vulnerabilitySlice := BuildVulnerability(vlLenth, v, componentMap, cpe) + vulnerabilitySlice := BuildVulnerability(vlLenth, v, componentMap, cpe, branchFlag) if len(vulnerabilitySlice) > 0 { vulnerability = append(vulnerability, vulnerabilitySlice...) } } } else { vlLenth := 1 - vulnerabilitySlice := BuildVulnerability(vlLenth, v, componentMap, cpe) + vulnerabilitySlice := BuildVulnerability(vlLenth, v, componentMap, cpe, branchFlag) vulnerability = append(vulnerability, vulnerabilitySlice...) } return vulnerability } func BuildVulnerabilitySet(cvrfsa *CvrfSa, v models.ExcelExport, - affectBranch string, componentMap map[string]ComponentInfo) { + affectBranch string, componentMap map[string]ComponentInfo, branchFlag int) { vulnerability := make([]Vulnerability, 0) if cvrfsa.Vulnerability != nil && len(cvrfsa.Vulnerability) > 0 { for _, vuln := range cvrfsa.Vulnerability { @@ -1111,27 +1166,28 @@ func BuildVulnerabilitySet(cvrfsa *CvrfSa, v models.ExcelExport, } } vulnerabilityx := BuildVulnerabilitySlice(vulnerability, v, - affectBranch, componentMap) + affectBranch, componentMap, branchFlag) cvrfsa.Vulnerability = vulnerabilityx } func BuildCvrfXml(cvrfsa *CvrfSa, v models.ExcelExport, affectBranch string, cvrfFileList map[string][]string, componentMap map[string]ComponentInfo, - pkg []models.Package) { + pkg []models.Package, branchFlag int) { curDate := common.GetCurDate() - v.Description = strings.ReplaceAll(v.Description, "\n\n", " ") - v.Theme = strings.ReplaceAll(v.Theme, "\n\n", " ") + //v.Description = strings.ReplaceAll(v.Description, "\n\n", " ") + //v.Theme = strings.ReplaceAll(v.Theme, "\n\n", " ") branchList := BranchExist(affectBranch, cvrfFileList) cvrfsa.Xmlns = "http://www.icasi.org/CVRF/schema/cvrf/1.1" cvrfsa.XmlnsCvrf = "http://www.icasi.org/CVRF/schema/cvrf/1.1" - BuildDocumentTitle(cvrfsa, v, affectBranch, cvrfFileList, componentMap, curDate, branchList) - BuildDocumentRef(cvrfsa, v, componentMap) - BuildProductTree(cvrfsa, v, pkg, affectBranch) - BuildVulnerabilitySet(cvrfsa, v, affectBranch, componentMap) + BuildDocumentTitle(cvrfsa, v, affectBranch, cvrfFileList, componentMap, curDate, branchList, branchFlag) + BuildDocumentRef(cvrfsa, v, componentMap, branchFlag, affectBranch) + BuildProductTree(cvrfsa, v, pkg, affectBranch, branchFlag) + BuildVulnerabilitySet(cvrfsa, v, affectBranch, componentMap, branchFlag) } -func QueryCveMd5(cveNum []string, OwnedComponent, openEulerSANum string, fixFlag int8) bool { +func QueryCveMd5(cveNum []string, OwnedComponent, openEulerSANum string, fixFlag int8) (bool, string) { sort.Strings(cveNum) + tmpOpenEulerSANum := "" cveStr := strings.Join(cveNum, ",") cveStrx := cveStr + "," + OwnedComponent fileMd5 := common.EncryptMd5(cveStrx) @@ -1139,7 +1195,21 @@ func QueryCveMd5(cveNum []string, OwnedComponent, openEulerSANum string, fixFlag cfr.Md5 = fileMd5 tbErr := models.GetCvrfRecord(&cfr, "cur_md5") if tbErr == nil { - return true + tmpOpenEulerSANum = cfr.OpenEulerSANum + cfr.UpdateTime = common.GetCurTime() + cfr.Md5 = fileMd5 + cfr.OpenEulerSANum = openEulerSANum + cfr.Status = 1 + cfr.IsExport = 1 + cfr.CveNum = cveStr + cfr.PackName = OwnedComponent + cfr.AffectFlag = fixFlag + updateErr := models.UpdateCvrfRecord(&cfr, "UpdateTime", + "OpenEulerSANum", "Status", "IsExport", "CveNum", "PackName", "AffectFlag") + if updateErr != nil { + logs.Error("UpdateCvrfRecord, ", updateErr) + } + return true, tmpOpenEulerSANum } else { cfr.CreateTime = common.GetCurTime() cfr.Md5 = fileMd5 @@ -1153,7 +1223,7 @@ func QueryCveMd5(cveNum []string, OwnedComponent, openEulerSANum string, fixFlag if iErr != nil || num == 0 { logs.Error("InsertCvrfRecord, ", iErr) } - return false + return false, tmpOpenEulerSANum } } diff --git a/taskhandler/excel.go b/taskhandler/excel.go index bfd875e..053c20c 100644 --- a/taskhandler/excel.go +++ b/taskhandler/excel.go @@ -516,6 +516,7 @@ func procUnaffectCvrfData(v models.ExcelExport, affectBranch string, cvrfFileList map[string][]string, componentMap map[string]ComponentInfo) { fileDir := beego.AppConfig.String("fileDir") + common.CreateDir(fileDir) cvrffileName := filepath.Join(fileDir, "cvrf-unaffected-cve-"+common.GetCurDate()+".xml") cvrfFileSlice, cvrfOk := cvrfFileList[UNAFFECTCVRFKEY] if cvrfOk && len(cvrfFileSlice) > 0 { @@ -544,6 +545,7 @@ func (ec *CveExcel) handleWriteContentSync(list []models.ExcelExport, lz := len(list) if lz > 0 { for _, v := range list { + logs.Info("handleWriteContentSync, v====>", v) if v.OrganizateId == 2 { logs.Error("opengauss, data: ", v) continue @@ -716,13 +718,14 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, repFlag := false influenceComponent := "" fileDir := beego.AppConfig.String("fileDir") + common.CreateDir(fileDir) if len(v.InfluenceComponent) > 1 { influenceComponent = v.InfluenceComponent } else { influenceComponent = v.OwnedComponent } packNameStruct, pOk := componentMap[influenceComponent] - if !pOk && len(packNameStruct.OpenEulerSANum) < 1 { + if !pOk || len(packNameStruct.OpenEulerSANum) < 3 { var coponentInfo ComponentInfo openEulerSANum := GetOpenEulerSaNum() if openEulerSANum == "" { @@ -746,6 +749,7 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, brachCveInfo.OpenEulerSANum = openEulerSANum1 brachCveInfo.CvrfFileName = filepath.Join(fileDir, "cvrf-"+openEulerSANum1+".xml") brachCveInfo.CveNumSlice = cveNumSlice + brachCveInfo.OpenEulerScore = openEulerScoreSlice branchCve[affectBranch] = brachCveInfo coponentInfo.CveNumMap = branchCve coponentInfo.CveNum = cveNumSlice @@ -776,7 +780,8 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, if branchCvex, brOk := packNameStruct.CveNumMap[affectBranch]; !brOk { cveNumSlice := make([]string, 0) cveNumSlice = append(cveNumSlice, v.CveNum) - branchCve := make(map[string]BrachCveInfo) + openEulerScoreSlice := make([]float64, 0) + openEulerScoreSlice = append(openEulerScoreSlice, v.OpenEulerScore) var brachCveInfo BrachCveInfo openEulerSANum1 := GetOpenEulerSaNum() if openEulerSANum1 == "" { @@ -785,8 +790,8 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, brachCveInfo.OpenEulerSANum = openEulerSANum1 brachCveInfo.CvrfFileName = filepath.Join(fileDir, "cvrf-"+openEulerSANum1+".xml") brachCveInfo.CveNumSlice = cveNumSlice - branchCve[affectBranch] = brachCveInfo - packNameStruct.CveNumMap = branchCve + brachCveInfo.OpenEulerScore = openEulerScoreSlice + packNameStruct.CveNumMap[affectBranch] = brachCveInfo } else { for _, cve := range branchCvex.CveNumSlice { if cve == v.CveNum { @@ -796,6 +801,7 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, } if !repFlag { branchCvex.CveNumSlice = append(branchCvex.CveNumSlice, v.CveNum) + branchCvex.OpenEulerScore = append(branchCvex.OpenEulerScore, v.OpenEulerScore) packNameStruct.CveNumMap[affectBranch] = branchCvex } } @@ -803,6 +809,8 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, branchCve := make(map[string]BrachCveInfo) cveNumSlice := make([]string, 0) cveNumSlice = append(cveNumSlice, v.CveNum) + openEulerScoreSlice := make([]float64, 0) + openEulerScoreSlice = append(openEulerScoreSlice, v.OpenEulerScore) var brachCveInfo BrachCveInfo openEulerSANum1 := GetOpenEulerSaNum() if openEulerSANum1 == "" { @@ -811,6 +819,7 @@ func StoreComponentInfo(componentMap map[string]ComponentInfo, brachCveInfo.OpenEulerSANum = openEulerSANum1 brachCveInfo.CvrfFileName = filepath.Join(fileDir, "cvrf-"+openEulerSANum1+".xml") brachCveInfo.CveNumSlice = cveNumSlice + brachCveInfo.OpenEulerScore = openEulerScoreSlice branchCve[affectBranch] = brachCveInfo packNameStruct.CveNumMap = branchCve } @@ -868,10 +877,12 @@ func BranchCvrfData(v models.ExcelExport, componentMap[v.InfluenceComponent] = componentInfo } } - BuildCvrfXml(&cvrfsa, v, affectBranch, cvrfFileList, componentMap, pkg) + BuildCvrfXml(&cvrfsa, v, affectBranch, cvrfFileList, componentMap, pkg, branchFlag) cvfrFileMap[cvrffileName] = cvrfsa + logs.Info("xxxx1====>", cvrfsa, v, affectBranch, cvrfFileList, componentMap, pkg) } else { - BuildCvrfXml(&branchCvrfSaStruct, v, affectBranch, cvrfFileList, componentMap, pkg) + BuildCvrfXml(&branchCvrfSaStruct, v, affectBranch, cvrfFileList, componentMap, pkg, branchFlag) + logs.Info("xxxx2====>", branchCvrfSaStruct, v, affectBranch, cvrfFileList, componentMap, pkg) cvfrFileMap[cvrffileName] = branchCvrfSaStruct } saveCvrfName(cvrfFileList, cvrffileName, CVRFFKEY) @@ -1080,7 +1091,9 @@ func ExtractPackageData(lp string) (pkgList []models.ExcelPackage, err error) { } else if err != nil { return pkgList, err } - pkgList = append(pkgList, models.ExcelPackage{PubTime: line[0], Repo: line[1], Packages: line[2]}) + if len(line) >= 3 && len(line[0]) > 3 { + pkgList = append(pkgList, models.ExcelPackage{PubTime: line[0], Repo: line[1], Packages: line[2]}) + } } return } @@ -1098,6 +1111,7 @@ func getDateByGite(pkgList []models.ExcelPackage, startTime string, c chan<- []I st := util.TimeStrToInt(startTime, "2006-01-02") chData := make([]IssueAndPkg, 0) for _, v := range pkgList { + logs.Info("excel, v===>", v) rt := util.TimeStrToInt(v.PubTime, "20060102 15-04-05") + saTimeStampZone // 查询当前需要处理的issue issueTemp, err := models.GetIssueNumber(v.Repo) @@ -1130,6 +1144,7 @@ func (ec *CveExcel) handleGiteData(c <-chan []IssueAndPkg, affectBranch string, data := <-c var pkgList []string for _, v := range data { + logs.Info("v====>", v) //parse package string to list pkgList = strings.Split(v.IssuePkg, " ") if len(pkgList) == 0 { @@ -1206,7 +1221,7 @@ func getRepoIssueAllPR(affectBranch, token, owner, repo string, startTime, mt := util.TimeStrToInt(closedAt[:19], "2006-01-02T15:04:05") mergedAt := v["merged_at"].(string) ct := util.TimeStrToInt(mergedAt[:19], "2006-01-02T15:04:05") - //logs.Info("******, pr: ", v, ",mt: ", mt, ", startTime: ", startTime, ",releaseTime: ", releaseTime, ":ct:", ct) + logs.Info("******, pr: ", v, ",mt: ", mt, ", startTime: ", startTime, ",releaseTime: ", releaseTime, ":ct:", ct, ",repo:", repo) //ct := v["merged_at"].(string).(time.Time).Local().Unix() var pt int64 if mt > 0 && ct > 0 { @@ -1227,6 +1242,7 @@ func getRepoIssueAllPR(affectBranch, token, owner, repo string, startTime, pr.CveNumber = isTemp.CveNum pr.Repo = repo prList = append(prList, pr) + logs.Info("prList====>", prList) } } } diff --git a/taskhandler/issuestatistics.go b/taskhandler/issuestatistics.go index 27c8528..6758728 100644 --- a/taskhandler/issuestatistics.go +++ b/taskhandler/issuestatistics.go @@ -29,6 +29,7 @@ func GetIssueData(beforeDate, prcnum int, templateId int64) ([]models.IssueTempl func createExcel() (string, string) { // File storage directory dir := beego.AppConfig.String("fileDir") + common.CreateDir(dir) excelName := "CVE_ISSUE_" + common.GetCurDate() + ".xlsx" excelPath := filepath.Join(dir, excelName) xlsx := excelize.NewFile() @@ -58,6 +59,7 @@ func createExcel() (string, string) { func CveCredExcel() (string, string) { // File storage directory dir := beego.AppConfig.String("fileDir") + common.CreateDir(dir) excelName := "CVE_Low_Credibility_" + common.GetCurDate() + ".xlsx" excelPath := filepath.Join(dir, excelName) xlsx := excelize.NewFile() @@ -93,7 +95,7 @@ func procCredData(org models.OriginUpstream, desc models.OriginUpstreamDesc) []i func ReadWriteExcel(excelPath, owner string, iss []models.IssueTemplate, is *IssueStr) (int64, error) { file, openErr := excelize.OpenFile(excelPath) if openErr != nil { - logs.Error("fail to open the file, ", excelPath) + logs.Error("fail to open the file, excelPath: ", excelPath, ", openErr: ", openErr) return iss[len(iss)-1].TemplateId, openErr } var templateId = int64(0) diff --git a/taskhandler/sendemail.go b/taskhandler/sendemail.go index 5c6623e..5697565 100644 --- a/taskhandler/sendemail.go +++ b/taskhandler/sendemail.go @@ -61,6 +61,11 @@ func ZipFiles(filename string, files []string, oldform, newform string) error { zipWriter := zip.NewWriter(newZipFile) defer zipWriter.Close() for _, file := range files { + fisExist, _ := PathExists(file) + if !fisExist { + logs.Error("ZipFiles, not exist, file: ", file) + continue + } zipfile, err := os.Open(file) if err != nil { return err @@ -108,12 +113,12 @@ func SendEmail(attchStr string, flag int, cBody, subject string) error { mail = &SendMail{user: emailName, password: emailPwd, host: emailHost, port: emailPort} if flag == 1 { message := Message{from: emailName, - to: toEmailName, - cc: []string{}, - bcc: []string{}, - subject: "The file name of the cvrf format currently to be manually reviewed is as follows.date: " + common.GetCurTime(), - body: fmt.Sprintf("hi all: \r\n The list of cvrf format files that have been " + - "uploaded to the file server is as follows: \r\n" + strings.ReplaceAll(attchStr,"download/", "")), + to: toEmailName, + cc: []string{}, + bcc: []string{}, + subject: "The file name of the cvrf format currently to be manually reviewed is as follows.date: " + common.GetCurTime(), + body: fmt.Sprintf("hi all: \r\n The list of cvrf format files that have been " + + "uploaded to the file server is as follows: \r\n" + strings.ReplaceAll(attchStr, "download/", "")), contentType: "text/plain;charset=utf-8", attachment: Attachment{ name: attchStr, diff --git a/util/http.go b/util/http.go index c94762e..fc8d023 100644 --- a/util/http.go +++ b/util/http.go @@ -195,7 +195,6 @@ func HTTPGet(url string) ([]map[string]interface{}, error) { //HTTPGetCom common get request func HTTPGetCom(urls string) ([]byte, error) { - logs.Info("httpgetcom: ", urls) resp, err := http.Get(urls) if err != nil { logs.Error("get error, url:", urls, "error: ", err) -- Gitee