diff --git a/TODOLIST.md b/TODOLIST.md index 8170af2..f3daa46 100755 --- a/TODOLIST.md +++ b/TODOLIST.md @@ -76,7 +76,7 @@ 主要是优化和改bug - 增加代码可读性 [ok] -- 代码评审和优化 +- 代码评审和优化 [ok] - UI界面优化 - 交互逻辑优化 - [优化]面板数据加载很慢 @@ -90,8 +90,6 @@ - - [bug] 4. ipc信息读取不到 (有反爬,可以找替代或者解决反爬) ``` @@ -111,6 +109,43 @@ https://icp.5118.com/ ``` https://www.8300.cn/zst/ssqjbw4; ``` +19. monitor panic +```azure +panic: runtime error: invalid memory address or nil pointer dereference + panic: runtime error: invalid memory address or nil pointer dereference +[signal 0xc0000005 code=0x0 addr=0x68 pc=0xe1c56e] + +goroutine 15 [running]: +compress/gzip.(*Reader).Close(0xc000684380?) + D:/go1.22.2/src/compress/gzip/gunzip.go:290 +0xe +github.com/mangenotwork/gathertool.(*Context).Do.func1(...) + D:/go/pkg/mod/github.com/mangenotwork/gathertool@v0.4.7/context.go:264 +panic({0x1131ce0?, 0x16e0c80?}) + D:/go1.22.2/src/runtime/panic.go:770 +0x132 +compress/gzip.(*Reader).Read(0xc000842080?, {0xc000028200?, 0x0?, 0x80?}) + D:/go1.22.2/src/compress/gzip/gunzip.go:247 +0x22 +io.ReadAll({0x287715bd838, 0x0}) + D:/go1.22.2/src/io/io.go:712 +0x7e +github.com/mangenotwork/gathertool.(*Context).Do(0xc0003cea20) + D:/go/pkg/mod/github.com/mangenotwork/gathertool@v0.4.7/context.go:286 +0x136f +github.com/mangenotwork/gathertool.Get({0xc0004c04c8?, 0xc0001c0570?}, {0xc000039c88?, 0x7?, 0x11103a0?}) + D:/go/pkg/mod/github.com/mangenotwork/gathertool@v0.4.7/gathertool.go:31 +0x27 +website-monitor/monitor/business.request({0xc0004c04c8, 0x15}) + D:/go/src/github.com/mangenotwork/website-monitor/monitor/business/base.go:316 +0x117 +website-monitor/monitor/business.(*WebsiteItem).ContrastActive(0xc0003dc1c0, 0xc000039da0) + D:/go/src/github.com/mangenotwork/website-monitor/monitor/business/website.go:80 +0x45 +website-monitor/monitor/business.Business(0xc0003dc1c0) + D:/go/src/github.com/mangenotwork/website-monitor/monitor/business/base.go:119 +0x1df +website-monitor/monitor/business.Initialize.func1.1({0xc00003e360?, 0xc0000af6e0?}, {0x11864c0?, 0xc0003dc1c0?}) + D:/go/src/github.com/mangenotwork/website-monitor/monitor/business/base.go:50 +0x50 +sync.(*Map).Range(0xc0000d8690?, 0xc000039fc0) + D:/go1.22.2/src/sync/map.go:477 +0x1f8 +website-monitor/monitor/business.Initialize.func1() + D:/go/src/github.com/mangenotwork/website-monitor/monitor/business/base.go:47 +0x65 +created by website-monitor/monitor/business.Initialize in goroutine 1 + D:/go/src/github.com/mangenotwork/website-monitor/monitor/business/base.go:42 +0x59 +exit status 2 +``` diff --git a/master/dao/dns.go b/master/dao/dns.go index 9135937..fbdbd33 100755 --- a/master/dao/dns.go +++ b/master/dao/dns.go @@ -155,7 +155,7 @@ func NsLookUpAll(host string) ([]*entity.DNSInfo, []string) { } } - for k, _ := range allIPMap { + for k := range allIPMap { allIP = append(allIP, k) } diff --git a/master/dao/monitor_log.go b/master/dao/monitor_log.go index c6814e3..172fe09 100755 --- a/master/dao/monitor_log.go +++ b/master/dao/monitor_log.go @@ -34,7 +34,6 @@ func NewMonitorLogDao() MonitorLogEr { type monitorLogDao struct { } -// 写日志 func (m *monitorLogDao) Write(hostId, mLog string) { logPath, err := conf.YamlGetString("logPath") if err != nil { @@ -182,7 +181,6 @@ func (m *monitorLogDao) ToMonitorLogObj(str string) *entity.MonitorLog { } } -// DeleteLog 删除日志 func (m *monitorLogDao) DeleteLog(hostId string) error { logPath, err := conf.YamlGetString("logPath") if err != nil { diff --git a/master/dao/request_tool.go b/master/dao/request_tool.go index 1dc4d65..a698733 100755 --- a/master/dao/request_tool.go +++ b/master/dao/request_tool.go @@ -49,7 +49,7 @@ func (r *requestToolDao) GetAtID(id string) (*entity.RequestTool, error) { data := &entity.RequestTool{} err := DB.Get(RequestTable, id, &data) - if errors.Is(err, ISNULL) { // 空数据忽略 + if errors.Is(err, ISNULL) { err = nil data.Method = "GET" } diff --git a/master/dao/scan.go b/master/dao/scan.go index 53213a2..57f314b 100755 --- a/master/dao/scan.go +++ b/master/dao/scan.go @@ -13,7 +13,7 @@ import ( ) type HostScanUrl struct { - Host string + Host string // Depth int64 // 页面深度 UrlSet map[string]struct{} // 采集到host下的链接 CssLinks map[string]struct{} // 采集到的css文件链接 @@ -22,8 +22,8 @@ type HostScanUrl struct { ExtLinks map[string]struct{} // 采集到外链 BadLinks map[string]struct{} // 采集到死链接 NoneTDK map[string]string // 检查空tdk - Count int64 - MaxCount int64 + Count int64 // 采集到的数量 + MaxCount int64 // 采集到的最大数量 } func Scan(host, id string, depth int64) { @@ -182,6 +182,7 @@ G: } link := links[0] + // 请求并验证 scan.do(link, df) @@ -289,6 +290,6 @@ func cleanUrl(str string) string { if flag { return str[:len(str)-1] } - + return str } diff --git a/master/dao/website.go b/master/dao/website.go index f4b9c19..72a76a4 100755 --- a/master/dao/website.go +++ b/master/dao/website.go @@ -16,13 +16,18 @@ import ( type WebsiteEr interface { Add(data *entity.Website, alarmRule *entity.WebsiteAlarmRule, scan *entity.WebsiteScanCheckUp) error + Del(hostID string) error + Edit(base *entity.Website, alarmRule *entity.WebsiteAlarmRule, scan *entity.WebsiteScanCheckUp) error + SelectList() ([]*entity.Website, int, error) + Select(hostID string) (*entity.Website, error) - // GetConfAlarmRule GetConfScanCheckUp 获取网站的监测配置 + // GetConfAlarmRule 获取网站的监测配置 GetConfAlarmRule(hostID string) (*entity.WebsiteAlarmRule, error) + GetConfScanCheckUp(hostID string) (*entity.WebsiteScanCheckUp, error) // GetAlarmRule 获取监测报警规则 @@ -39,6 +44,8 @@ type WebsiteEr interface { // Collect 采集网站信息 Collect(host string) *entity.WebsiteInfo + + // SaveCollectInfo 保存采集网站信息 SaveCollectInfo(host, hostID string) error // GetInfo 获取网站信息 diff --git a/master/handler/api.go b/master/handler/api.go index fd18117..9da48da 100755 --- a/master/handler/api.go +++ b/master/handler/api.go @@ -52,6 +52,7 @@ func Login(c *gin.Context) { func Out(c *gin.Context) { c.SetCookie("sign", "", 60*60*24*7, "/", "", false, true) c.Redirect(http.StatusFound, "/") + return } func MailInit(c *ginHelper.GinCtx) { @@ -152,6 +153,7 @@ func ToolHistorySet(c *ginHelper.GinCtx) { func ToolHistoryGet(c *ginHelper.GinCtx) { toolID := c.GetQueryInt("toolID") + h, err := dao.NewHistory(toolID) if err != nil { c.APIOutPutError(err, err.Error()) @@ -175,6 +177,7 @@ func ToolHistoryGet(c *ginHelper.GinCtx) { func ToolHistoryClear(c *ginHelper.GinCtx) { toolID := c.GetQueryInt("toolID") + h, err := dao.NewHistory(toolID) if err != nil { c.APIOutPutError(err, err.Error()) diff --git a/master/handler/page.go b/master/handler/page.go index 0e2b878..a4c0062 100755 --- a/master/handler/page.go +++ b/master/handler/page.go @@ -20,19 +20,23 @@ func ginH(h gin.H) gin.H { func NotFond(c *gin.Context) { c.HTML( http.StatusOK, - "notfond.html", + "not_fond.html", ginH(gin.H{}), ) + return } -func ErrPage(c *gin.Context, err error) { +func ErrPage(c *gin.Context) { + msg := c.Query("msg") c.HTML( http.StatusOK, "err.html", ginH(gin.H{ - "err": err.Error(), + "err": msg, + "returnUrl": "/", }), ) + return } func LoginPage(c *gin.Context) { @@ -55,7 +59,7 @@ func LoginPage(c *gin.Context) { "csrf": ginHelper.FormSetCSRF(c.Request), }), ) - + return } func HomePage(c *gin.Context) { @@ -66,6 +70,7 @@ func HomePage(c *gin.Context) { "nav": "home", }), ) + return } func MonitorPage(c *gin.Context) { @@ -76,6 +81,7 @@ func MonitorPage(c *gin.Context) { "nav": "monitor", }), ) + return } func AlertPage(c *gin.Context) { @@ -86,6 +92,7 @@ func AlertPage(c *gin.Context) { "nav": "alert", }), ) + return } func ToolPage(c *gin.Context) { @@ -96,36 +103,40 @@ func ToolPage(c *gin.Context) { "nav": "tool", }), ) + return } func TestAPIPage(c *gin.Context) { c.HTML( http.StatusOK, - "testAPI.html", + "test_api.html", ginH(gin.H{ "nav": "api-test", }), ) + return } func TestStressPage(c *gin.Context) { c.HTML( http.StatusOK, - "testStress.html", + "test_stress.html", ginH(gin.H{ "nav": "stress-test", }), ) + return } func TestPenetrationPage(c *gin.Context) { c.HTML( http.StatusOK, - "testPenetration.html", + "test_penetration.html", ginH(gin.H{ "nav": "penetration-test", }), ) + return } func OperationPage(c *gin.Context) { @@ -136,6 +147,7 @@ func OperationPage(c *gin.Context) { "nav": "operation", }), ) + return } func InstructionsPage(c *gin.Context) { @@ -146,6 +158,7 @@ func InstructionsPage(c *gin.Context) { "nav": "instructions", }), ) + return } func RequesterPage(c *gin.Context) { @@ -156,4 +169,5 @@ func RequesterPage(c *gin.Context) { "nav": "requester", }), ) + return } diff --git a/master/handler/website_api.go b/master/handler/website_api.go index 8913b5b..99bcd67 100755 --- a/master/handler/website_api.go +++ b/master/handler/website_api.go @@ -176,9 +176,9 @@ func WebsiteList(c *ginHelper.GinCtx) { } data = append(data, &WebsiteListOutItem{ - v, - alertLen, - state, + Website: v, + AlertCount: alertLen, + State: state, }) } @@ -258,7 +258,11 @@ func WebsiteInfo(c *ginHelper.GinCtx) { return } - output.Base = WebsiteOutPut{base, utils.Timestamp2Date(base.Created)} + output.Base = WebsiteOutPut{ + Website: base, + Date: utils.Timestamp2Date(base.Created), + } + output.Info, err = website.GetInfo(hostId) output.AlarmRule, err = website.GetAlarmRule(hostId) output.ScanCheckUp, err = website.GetScanCheckUp(hostId) @@ -287,6 +291,7 @@ func WebsiteInfoRefresh(c *ginHelper.GinCtx) { func WebsiteUrls(c *ginHelper.GinCtx) { hostId := c.Param("hostId") + data, err := dao.NewWebsite().GetWebSiteUrl(hostId) if err != nil { c.APIOutPutError(err, err.Error()) @@ -328,7 +333,6 @@ func AllWebsite(c *ginHelper.GinCtx) { } for _, v := range websiteList { - rule, rErr := obj.GetAlarmRule(v.HostID) if rErr != nil { continue @@ -351,6 +355,11 @@ func GetWebsiteData(c *ginHelper.GinCtx) { obj := dao.NewWebsite() website, err := obj.Select(hostId) + if err != nil { + c.APIOutPutError(err, err.Error()) + return + } + rule, err := obj.GetAlarmRule(hostId) if err != nil { c.APIOutPutError(err, err.Error()) @@ -358,8 +367,8 @@ func GetWebsiteData(c *ginHelper.GinCtx) { } data := &WebsiteDataOut{ - website, - rule.WebsiteSlowResponseTime, + Website: website, + WebsiteSlowResponseTime: rule.WebsiteSlowResponseTime, } c.APIOutPut(data, "") @@ -368,6 +377,7 @@ func GetWebsiteData(c *ginHelper.GinCtx) { func WebsiteEdit(c *ginHelper.GinCtx) { hostId := c.Param("hostId") + param, err := analysisWebsiteAddParam(c) if err != nil { c.APIOutPutError(err, err.Error()) @@ -460,6 +470,7 @@ func WebsiteChart(c *ginHelper.GinCtx) { func MonitorLog(c *ginHelper.GinCtx) { hostId := c.Param("hostId") day := c.GetQuery("day") + data := dao.NewMonitorLogDao().ReadLog(hostId, day) c.APIOutPut(data, "") return @@ -467,6 +478,7 @@ func MonitorLog(c *ginHelper.GinCtx) { func MonitorLogList(c *ginHelper.GinCtx) { hostId := c.Param("hostId") + data, err := dao.NewMonitorLogDao().LogListDay(hostId) if err != nil { c.APIOutPutError(err, err.Error()) @@ -480,6 +492,7 @@ func MonitorLogList(c *ginHelper.GinCtx) { func MonitorLogUpload(c *ginHelper.GinCtx) { hostId := c.Param("hostId") day := c.GetQuery("day") + logPath, err := dao.NewMonitorLogDao().Upload(hostId, day) if err != nil { c.APIOutPutError(err, err.Error()) @@ -524,6 +537,7 @@ func WebsitePointAdd(c *ginHelper.GinCtx) { func WebsitePointList(c *ginHelper.GinCtx) { hostId := c.Param("hostId") + data, err := dao.NewWebsite().GetPoint(hostId) if err != nil { c.APIOutPutError(err, err.Error()) @@ -556,6 +570,7 @@ func WebsitePointDel(c *ginHelper.GinCtx) { func WebsitePointClear(c *ginHelper.GinCtx) { hostId := c.Param("hostId") + err := dao.NewWebsite().ClearPoint(hostId) if err != nil { c.APIOutPutError(err, err.Error()) @@ -619,6 +634,7 @@ func AlertWebsite(c *ginHelper.GinCtx) { func AlertRead(c *ginHelper.GinCtx) { id := c.Param("id") + err := dao.NewAlert().Read(id) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -631,6 +647,7 @@ func AlertRead(c *ginHelper.GinCtx) { func AlertInfo(c *ginHelper.GinCtx) { id := c.Param("id") + data, err := dao.NewAlert().Get(id) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -643,6 +660,7 @@ func AlertInfo(c *ginHelper.GinCtx) { func AlertDel(c *ginHelper.GinCtx) { id := c.Param("id") + err := dao.NewAlert().Del(id) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -655,6 +673,7 @@ func AlertDel(c *ginHelper.GinCtx) { func AlertClear(c *ginHelper.GinCtx) { hostId := c.Param("hostId") + err := dao.NewAlert().Clear(hostId) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -694,6 +713,7 @@ func RequesterCreateTab(c *ginHelper.GinCtx) { func RequesterCloseTab(c *ginHelper.GinCtx) { hostId := c.Param("reqId") + err := dao.NewRequestTool().DelRequestNowList(hostId) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -748,6 +768,7 @@ func RequesterExecute(c *ginHelper.GinCtx) { } switch param.Method { + case "GET": log.Info("get 请求...") ctx, err := gt.Get(param.Url) @@ -790,33 +811,44 @@ func RequesterExecute(c *ginHelper.GinCtx) { } c.APIOutPut(out, "") return + case "POST": log.Info("post 请求...") + case "PUT": log.Info("put 请求...") + case "DELETE": log.Info("delete 请求...") + case "OPTIONS": log.Info("options 请求...") + case "HEAD": log.Info("head 请求...") } + c.APIOutPut("todo...", "") + return } func isMethod(method string) bool { rse := false + method = strings.ToUpper(method) + for _, v := range []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD"} { if method == v { rse = true break } } + return rse } func RequesterGetData(c *ginHelper.GinCtx) { reqId := c.Param("reqId") + data, err := dao.NewRequestTool().GetAtID(reqId) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -869,6 +901,11 @@ func RequesterHistoryDelete(c *ginHelper.GinCtx) { reqId := c.Param("reqId") err := dao.NewRequestTool().HistoryDelete(reqId) + if err != nil { + c.APIOutPutError(nil, err.Error()) + return + } + err = dao.NewRequestTool().DelRequestNowList(reqId) if err != nil { c.APIOutPutError(nil, err.Error()) @@ -926,6 +963,7 @@ func RequesterGlobalHeaderGet(c *ginHelper.GinCtx) { func RequesterGlobalHeaderDel(c *ginHelper.GinCtx) { key := c.Query("key") + err := dao.NewRequestTool().DelGlobalHeader(key) if err != nil { c.APIOutPutError(nil, err.Error()) diff --git a/master/routers/base.go b/master/routers/base.go index f002e7d..88ab3c0 100755 --- a/master/routers/base.go +++ b/master/routers/base.go @@ -41,10 +41,12 @@ func Login() { } func Page() { + // 404 && 405 && err page Router.NoRoute(handler.NotFond) Router.NoMethod(handler.NotFond) - // page group + Router.GET("/err", handler.ErrPage) + pg := Router.Group("") pg.Use(AuthPG()) pg.GET("/home", handler.HomePage) @@ -89,7 +91,7 @@ func API() { // alert api.GET("/alert/list", ginHelper.Handle(handler.AlertList)) // 报警列表 - api.GET("/alert/wbesite/:hostId", ginHelper.Handle(handler.AlertWebsite)) // 指定网站的报警信息 + api.GET("/alert/website/:hostId", ginHelper.Handle(handler.AlertWebsite)) // 指定网站的报警信息 api.GET("/alert/read/:id", ginHelper.Handle(handler.AlertRead)) // 报警信息已读 api.GET("/alert/info/:id", ginHelper.Handle(handler.AlertInfo)) // 报警消息详细信息 api.GET("/alert/del/:id", ginHelper.Handle(handler.AlertDel)) // 报警消息删除 @@ -137,7 +139,7 @@ func API() { func Data() { // 提供监测器获取数据 data := Router.Group("/data") - data.GET("/allurl/:hostId", ginHelper.Handle(handler.WebsiteAllUrl)) // 获取网站下的所有url + data.GET("/allUrl/:hostId", ginHelper.Handle(handler.WebsiteAllUrl)) // 获取网站下的所有url data.GET("/all/website", ginHelper.Handle(handler.AllWebsite)) // 获取所有需要监测的网站 data.GET("/website/point/:hostId", ginHelper.Handle(handler.WebsitePointList)) // 获取网站监测点 data.GET("/website/:hostId", ginHelper.Handle(handler.GetWebsiteData)) // 获取指定网站信息 diff --git a/master/views/page/err.html b/master/views/page/err.html index 404cbb5..6f7417f 100755 --- a/master/views/page/err.html +++ b/master/views/page/err.html @@ -2,7 +2,7 @@

错误: {[ .err ]}

- 返回主页 + 返回主页
{[ template "__end__.html" . ]} \ No newline at end of file diff --git a/master/views/page/notfond.html b/master/views/page/not_fond.html old mode 100755 new mode 100644 similarity index 100% rename from master/views/page/notfond.html rename to master/views/page/not_fond.html diff --git a/master/views/page/testAPI.html b/master/views/page/test_api.html old mode 100755 new mode 100644 similarity index 100% rename from master/views/page/testAPI.html rename to master/views/page/test_api.html diff --git a/master/views/page/testPenetration.html b/master/views/page/test_penetration.html old mode 100755 new mode 100644 similarity index 100% rename from master/views/page/testPenetration.html rename to master/views/page/test_penetration.html diff --git a/master/views/page/testStress.html b/master/views/page/test_stress.html old mode 100755 new mode 100644 similarity index 100% rename from master/views/page/testStress.html rename to master/views/page/test_stress.html