diff --git a/main.go b/main.go index 6cde263..f6f1ec2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "dt_automate/nessus" "dt_automate/tool" "flag" "fmt" @@ -87,7 +88,7 @@ func main() { //安全事件表格生成(需要先执行互联网区防火墙截图) // attackevent.Fw_event(attackevent.HW_fw1_cookie(), "2025-03-10") //将防火墙安全事件存放到xlsx文件中 //nessus的csv文件生成docx报告 - // wps.CSV_damo() + nessus.CSV_damo() //翻译模块调用腾讯xt翻译月500万字限制 // log.Println(wps.Translate("hello")) // wps.Weekly_word() diff --git a/wps/csv_safety.go b/nessus/csv_safety.go similarity index 64% rename from wps/csv_safety.go rename to nessus/csv_safety.go index c2e8d23..d9a872a 100644 --- a/wps/csv_safety.go +++ b/nessus/csv_safety.go @@ -1,4 +1,4 @@ -package wps +package nessus import ( "dt_automate/tool" @@ -8,7 +8,9 @@ import ( "os" "time" + "github.com/Esword618/unioffice/color" "github.com/Esword618/unioffice/document" + "github.com/Esword618/unioffice/measurement" "github.com/Esword618/unioffice/schema/soo/wml" "github.com/gocarina/gocsv" @@ -42,10 +44,10 @@ func CSV_damo() { } log.Println("开始将数据填入报告模板") - table := doc.Tables()[3] - var host string - var con int - var tables []document.Table + // table := doc.Tables()[3] + // var host string + // var con int + // var tables []document.Table // for _, csvstr := range people { // if csvstr.Host == host { // row := table.AddRow() @@ -100,61 +102,153 @@ func CSV_damo() { // } // host = csvstr.Host // } + //根据ip创建表格 + // 定义一个 map 用于记录已经出现过的 IP 地址 + var ip []string + ipMap := make(map[string]bool) for _, csvstr := range people { + // 检查当前 IP 是否已经在 map 中 + if _, exists := ipMap[csvstr.Host]; !exists { + // 如果不存在,则将其添加到数组和 map 中 + ip = append(ip, csvstr.Host) + ipMap[csvstr.Host] = true + } + } + log.Println(ip) + for _, ip := range ip { + //创建一个段落添加IP: + // 创建一个段落 + paragraph := doc.AddParagraph() + // 设置段落样式 + paragraph.Properties().SetStyle("Normal") + // 添加文本 + run := paragraph.AddRun() + run.AddText("IP:" + ip) + // 创建表格 + table := doc.AddTable() + // 设置表格宽度 + table.Properties().SetWidthPercent(100) + // 设置表格边框 + borderProps := table.Properties().Borders() + borderProps.SetTop(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetBottom(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetLeft(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetRight(wml.ST_BorderSingle, color.Black, measurement.Point) - if csvstr.Host == host { - row := table.AddRow() - row.Properties().SetHeight(22, wml.ST_HeightRuleExact) - // text_s(row.AddCell(), csvstr.Host) //主机IP - text_s(row.AddCell(), csvstr.Name) //风险项 - if csvstr.Risk == "None" { - text_s(row.AddCell(), "无") //危险程度 - } else { - text_s(row.AddCell(), csvstr.Risk) //危险程度 - } + // 添加表头 + headerRow := table.AddRow() + headerRow.Properties().SetHeight(22, wml.ST_HeightRuleExact) - if csvstr.Risk_Factor == "None" { - text_s(row.AddCell(), "无") //危险因素 - } else { - text_s(row.AddCell(), csvstr.Risk_Factor) //危险因素 - } - text_s(row.AddCell(), csvstr.Synopsisk) //摘要 - text_s(row.AddCell(), csvstr.Description) //描述 - if csvstr.Solution == "n/a" { - text_s(row.AddCell(), "无") //解决方案 - } else { - text_s(row.AddCell(), csvstr.Solution) //解决方案 - } - - } else { - con++ - tables[con] = doc.Tables()[3] - table = tables[con] - row := table.AddRow() - row.Properties().SetHeight(22, wml.ST_HeightRuleExact) - // text_s(row.AddCell(), csvstr.Host) //主机IP - text_s(row.AddCell(), csvstr.Name) //风险项 - if csvstr.Risk == "None" { - text_s(row.AddCell(), "无") //危险程度 - } else { - text_s(row.AddCell(), csvstr.Risk) //危险程度 - } - - if csvstr.Risk_Factor == "None" { - text_s(row.AddCell(), "无") //危险因素 - } else { - text_s(row.AddCell(), csvstr.Risk_Factor) //危险因素 - } - text_s(row.AddCell(), csvstr.Synopsisk) //摘要 - text_s(row.AddCell(), csvstr.Description) //描述 - if csvstr.Solution == "n/a" { - text_s(row.AddCell(), "无") //解决方案 - } else { - text_s(row.AddCell(), csvstr.Solution) //解决方案 + text_s(headerRow.AddCell(), "风险项") + text_s(headerRow.AddCell(), "危险程度") + text_s(headerRow.AddCell(), "危险因素") + text_s(headerRow.AddCell(), "摘要") + text_s(headerRow.AddCell(), "描述") + text_s(headerRow.AddCell(), "解决方案") + // 设置表头单元格的边框(包含内边框) + for _, cell := range headerRow.Cells() { + borderProps := cell.Properties().Borders() + borderProps.SetTop(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetBottom(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetLeft(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetRight(wml.ST_BorderSingle, color.Black, measurement.Point) + } + // 添加数据行 + for _, csvstr := range people { + if csvstr.Host == ip { + row := table.AddRow() + row.Properties().SetHeight(22, wml.ST_HeightRuleExact) + // text_s(row.AddCell(), csvstr.Host) //主机IP + text_s(row.AddCell(), csvstr.Name) //风险项 + if csvstr.Risk == "None" { + text_s(row.AddCell(), "无") //危险程度 + } else { + text_s(row.AddCell(), csvstr.Risk) //危险程度 + } + if csvstr.Risk_Factor == "None" { + text_s(row.AddCell(), "无") //危险因素 + } else { + text_s(row.AddCell(), csvstr.Risk_Factor) //危险因素 + } + text_s(row.AddCell(), csvstr.Synopsisk) //摘要 + text_s(row.AddCell(), csvstr.Description) //描述 + if csvstr.Solution == "n/a" { + text_s(row.AddCell(), "无") //解决方案 + } else { + text_s(row.AddCell(), csvstr.Solution) //解决方案 + } + // 设置单元格的边框(包含内边框) + for _, cell := range row.Cells() { + borderProps := cell.Properties().Borders() + borderProps.SetTop(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetBottom(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetLeft(wml.ST_BorderSingle, color.Black, measurement.Point) + borderProps.SetRight(wml.ST_BorderSingle, color.Black, measurement.Point) + } } } - host = csvstr.Host + + //添加一个空行 + paragraph = doc.AddParagraph() + paragraph.Properties().SetStyle("Normal") + run = paragraph.AddRun() + run.AddBreak() } + // for _, csvstr := range people { + + // if csvstr.Host == host { + // row := table.AddRow() + // row.Properties().SetHeight(22, wml.ST_HeightRuleExact) + // // text_s(row.AddCell(), csvstr.Host) //主机IP + // text_s(row.AddCell(), csvstr.Name) //风险项 + // if csvstr.Risk == "None" { + // text_s(row.AddCell(), "无") //危险程度 + // } else { + // text_s(row.AddCell(), csvstr.Risk) //危险程度 + // } + + // if csvstr.Risk_Factor == "None" { + // text_s(row.AddCell(), "无") //危险因素 + // } else { + // text_s(row.AddCell(), csvstr.Risk_Factor) //危险因素 + // } + // text_s(row.AddCell(), csvstr.Synopsisk) //摘要 + // text_s(row.AddCell(), csvstr.Description) //描述 + // if csvstr.Solution == "n/a" { + // text_s(row.AddCell(), "无") //解决方案 + // } else { + // text_s(row.AddCell(), csvstr.Solution) //解决方案 + // } + + // } else { + // con++ + // tables[con] = doc.Tables()[3] + // table = tables[con] + // row := table.AddRow() + // row.Properties().SetHeight(22, wml.ST_HeightRuleExact) + // // text_s(row.AddCell(), csvstr.Host) //主机IP + // text_s(row.AddCell(), csvstr.Name) //风险项 + // if csvstr.Risk == "None" { + // text_s(row.AddCell(), "无") //危险程度 + // } else { + // text_s(row.AddCell(), csvstr.Risk) //危险程度 + // } + + // if csvstr.Risk_Factor == "None" { + // text_s(row.AddCell(), "无") //危险因素 + // } else { + // text_s(row.AddCell(), csvstr.Risk_Factor) //危险因素 + // } + // text_s(row.AddCell(), csvstr.Synopsisk) //摘要 + // text_s(row.AddCell(), csvstr.Description) //描述 + // if csvstr.Solution == "n/a" { + // text_s(row.AddCell(), "无") //解决方案 + // } else { + // text_s(row.AddCell(), csvstr.Solution) //解决方案 + // } + // } + // host = csvstr.Host + // } // cvs_word() //写入CSV // file, err := os.OpenFile("output.csv", os.O_RDWR|os.O_CREATE, os.ModePerm) @@ -222,12 +316,12 @@ func (cd *CustomDate) UnmarshalCSV(csv string) error { // 批量填入表格内容方法 func text_s(cell document.Cell, ss string) { // 设置单元格垂直居中对齐 - cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter) + // cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter) //在单元格中添加段落 p := cell.AddParagraph().AddRun() p.Properties().SetFontFamily("微软雅黑") - p.Properties().SetSize(11) - p.Properties().SetBold(true) + p.Properties().SetSize(12) + // p.Properties().SetBold(true) p.AddText(ss) } diff --git a/大同信创云平台漏扫报告20250308.docx b/大同信创云平台漏扫报告20250308.docx new file mode 100644 index 0000000..53f3b43 Binary files /dev/null and b/大同信创云平台漏扫报告20250308.docx differ