Add Config.DisableBadRouteLog setting.

Surface more errors in template_init.go
Dump unknown UAs properly when DisableSuspLog is enabled.
This commit is contained in:
Azareal 2021-03-26 09:06:35 +10:00
parent f6a94d39d6
commit 6b645f7b88
5 changed files with 39 additions and 15 deletions

View File

@ -135,8 +135,9 @@ type config struct {
WriteTimeout int
IdleTimeout int
LogDir string
DisableSuspLog bool
LogDir string
DisableSuspLog bool
DisableBadRouteLog bool
}
type devConfig struct {

View File

@ -249,7 +249,10 @@ func compileCommons(c *tmpl.CTemplateSet, head, head2 *Header, forumList []Forum
var replyList []*ReplyUser
reply := Reply{1, 1, "Yo!", 1 /*, Config.DefaultGroup*/, now, 0, 0, 1, "::1", true, 1, 1, ""}
ru := &ReplyUser{ClassName: "", Reply: reply, CreatedByName: "Alice", Avatar: avatar, Group: Config.DefaultGroup, Level: 0, Attachments: miniAttach}
ru.Init(user2)
_, err := ru.Init(user2)
if err != nil {
return err
}
replyList = append(replyList, ru)
tpage := TopicPage{htitle("Topic Name"), replyList, tu, &Forum{ID: 1, Name: "Hahaha"}, &poll, Paginator{[]int{1}, 1, 1}}
tpage.Forum.Link = BuildForumURL(NameToSlug(tpage.Forum.Name), tpage.Forum.ID)
@ -279,7 +282,10 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
//avatar, microAvatar = BuildAvatar(0, "")
reply := Reply{1, 1, "Yo!", 1 /*, Config.DefaultGroup*/, now, 0, 0, 1, "::1", true, 1, 1, ""}
ru := &ReplyUser{ClassName: "", Reply: reply, CreatedByName: "Alice", Avatar: "", Group: Config.DefaultGroup, Level: 0, Attachments: miniAttach}
ru.Init(user)
_, err := ru.Init(user)
if err != nil {
return err
}
replyList = append(replyList, ru)
// TODO: Use a dummy forum list to avoid o(n) problems
@ -302,7 +308,7 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
return header
}
t := TItemHold(make(map[string]TItem))
err := compileCommons(c, header, header2, forumList, t)
err = compileCommons(c, header, header2, forumList, t)
if err != nil {
return err
}
@ -556,7 +562,10 @@ func compileJSTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName stri
avatar, microAvatar = BuildAvatar(0, "")
reply := Reply{1, 1, "Yo!", 1 /*, Config.DefaultGroup*/, now, 0, 0, 1, "::1", true, 1, 1, ""}
ru := &ReplyUser{ClassName: "", Reply: reply, CreatedByName: "Alice", Avatar: avatar, Group: Config.DefaultGroup, Level: 0, Attachments: miniAttach}
ru.Init(user)
_, err = ru.Init(user)
if err != nil {
return err
}
replyList = append(replyList, ru)
varList = make(map[string]tmpl.VarItem)

View File

@ -148,7 +148,9 @@ IdleTimeout - The number of seconds that a Keep-Alive connection will be kept op
LogDir - The directory in which logs are stored, with the exception of ops log, until a related bug is resolved. Default: ./logs/
DisableSuspLog - Whether suspicious requests are logged in the suspicious request logs. Enabling this may make a site faster. Defaults to false.
DisableSuspLog - Whether suspicious requests are logged in the suspicious request logs. Enabling this may make a site faster. Defaults: false.
DisableBadRouteLog - Whether requests referencing routes which don't exist should be individually logged. Enabling this may make a site faster. Default: false
Related: https://support.cloudflare.com/hc/en-us/articles/212794707-General-Best-Practices-for-Load-Balancing-at-your-origin-with-Cloudflare

View File

@ -1120,8 +1120,12 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
} else {
// TODO: Test this
items = items[:0]
r.SuspiciousRequest(req,"Illegal char "+strconv.Itoa(int(it))+" in UA")
r.reqLogger.Print("UA Buf: ", buf,"\nUA Buf String: ", string(buf))
if c.Config.DisableSuspLog {
r.reqLogger.Print("Illegal char "+strconv.Itoa(int(it))+" in UA\nUA Buf: ", buf,"\nUA Buf String: ", string(buf))
} else {
r.SuspiciousRequest(req,"Illegal char "+strconv.Itoa(int(it))+" in UA")
r.reqLogger.Print("UA Buf: ", buf,"\nUA Buf String: ", string(buf))
}
break
}
}
@ -2610,12 +2614,12 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
co.RouteViewCounter.Bump3(150, cn)
}
case "/profile":
err = c.NoSessionMismatch(w,req,user)
err = c.MemberOnly(w,req,user)
if err != nil {
return err
}
err = c.MemberOnly(w,req,user)
err = c.NoSessionMismatch(w,req,user)
if err != nil {
return err
}
@ -2809,7 +2813,9 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
}
}
r.DumpRequest(req,"Bad Route")
if !c.Config.DisableBadRouteLog {
r.DumpRequest(req,"Bad Route")
}
ae := req.Header.Get("Accept-Encoding")
likelyBot := ae == "gzip" || ae == ""
if likelyBot {

View File

@ -709,8 +709,12 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
} else {
// TODO: Test this
items = items[:0]
r.SuspiciousRequest(req,"Illegal char "+strconv.Itoa(int(it))+" in UA")
r.reqLogger.Print("UA Buf: ", buf,"\nUA Buf String: ", string(buf))
if c.Config.DisableSuspLog {
r.reqLogger.Print("Illegal char "+strconv.Itoa(int(it))+" in UA\nUA Buf: ", buf,"\nUA Buf String: ", string(buf))
} else {
r.SuspiciousRequest(req,"Illegal char "+strconv.Itoa(int(it))+" in UA")
r.reqLogger.Print("UA Buf: ", buf,"\nUA Buf String: ", string(buf))
}
break
}
}
@ -973,7 +977,9 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
}
}
r.DumpRequest(req,"Bad Route")
if !c.Config.DisableBadRouteLog {
r.DumpRequest(req,"Bad Route")
}
ae := req.Header.Get("Accept-Encoding")
likelyBot := ae == "gzip" || ae == ""
if likelyBot {