Skip to content

Commit

Permalink
feat: 代码评审和优化
Browse files Browse the repository at this point in the history
  • Loading branch information
mangenotwork committed Dec 10, 2024
1 parent d29c603 commit 621b3f6
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 30 deletions.
41 changes: 38 additions & 3 deletions TODOLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
主要是优化和改bug

- 增加代码可读性 [ok]
- 代码评审和优化
- 代码评审和优化 [ok]
- UI界面优化
- 交互逻辑优化
- [优化]面板数据加载很慢
Expand All @@ -90,8 +90,6 @@





[bug]
4. ipc信息读取不到 (有反爬,可以找替代或者解决反爬)
```
Expand All @@ -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
```



Expand Down
2 changes: 1 addition & 1 deletion master/dao/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func NsLookUpAll(host string) ([]*entity.DNSInfo, []string) {
}
}

for k, _ := range allIPMap {
for k := range allIPMap {
allIP = append(allIP, k)
}

Expand Down
2 changes: 0 additions & 2 deletions master/dao/monitor_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion master/dao/request_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
9 changes: 5 additions & 4 deletions master/dao/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type HostScanUrl struct {
Host string
Host string //
Depth int64 // 页面深度
UrlSet map[string]struct{} // 采集到host下的链接
CssLinks map[string]struct{} // 采集到的css文件链接
Expand All @@ -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) {
Expand Down Expand Up @@ -182,6 +182,7 @@ G:
}

link := links[0]

// 请求并验证
scan.do(link, df)

Expand Down Expand Up @@ -289,6 +290,6 @@ func cleanUrl(str string) string {
if flag {
return str[:len(str)-1]
}

return str
}
9 changes: 8 additions & 1 deletion master/dao/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 获取监测报警规则
Expand All @@ -39,6 +44,8 @@ type WebsiteEr interface {

// Collect 采集网站信息
Collect(host string) *entity.WebsiteInfo

// SaveCollectInfo 保存采集网站信息
SaveCollectInfo(host, hostID string) error

// GetInfo 获取网站信息
Expand Down
3 changes: 3 additions & 0 deletions master/handler/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand Down
28 changes: 21 additions & 7 deletions master/handler/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -55,7 +59,7 @@ func LoginPage(c *gin.Context) {
"csrf": ginHelper.FormSetCSRF(c.Request),
}),
)

return
}

func HomePage(c *gin.Context) {
Expand All @@ -66,6 +70,7 @@ func HomePage(c *gin.Context) {
"nav": "home",
}),
)
return
}

func MonitorPage(c *gin.Context) {
Expand All @@ -76,6 +81,7 @@ func MonitorPage(c *gin.Context) {
"nav": "monitor",
}),
)
return
}

func AlertPage(c *gin.Context) {
Expand All @@ -86,6 +92,7 @@ func AlertPage(c *gin.Context) {
"nav": "alert",
}),
)
return
}

func ToolPage(c *gin.Context) {
Expand All @@ -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) {
Expand All @@ -136,6 +147,7 @@ func OperationPage(c *gin.Context) {
"nav": "operation",
}),
)
return
}

func InstructionsPage(c *gin.Context) {
Expand All @@ -146,6 +158,7 @@ func InstructionsPage(c *gin.Context) {
"nav": "instructions",
}),
)
return
}

func RequesterPage(c *gin.Context) {
Expand All @@ -156,4 +169,5 @@ func RequesterPage(c *gin.Context) {
"nav": "requester",
}),
)
return
}
Loading

0 comments on commit 621b3f6

Please sign in to comment.