parent
3adee57b37
commit
b53577a126
|
@ -37,8 +37,7 @@ var defaultServerPort = "80" // 8080's a good one, if you're testing and don't w
|
|||
func main() {
|
||||
// Capture panics instead of closing the window at a superhuman speed before the user can read the message on Windows
|
||||
defer func() {
|
||||
r := recover()
|
||||
if r != nil {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println(r)
|
||||
debug.PrintStack()
|
||||
pressAnyKey()
|
||||
|
|
|
@ -322,6 +322,7 @@ func SecurityError(w http.ResponseWriter, r *http.Request, user *User) RouteErro
|
|||
}
|
||||
|
||||
func MicroNotFound(w http.ResponseWriter, r *http.Request) RouteError {
|
||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||
w.WriteHeader(404)
|
||||
_, _ = w.Write([]byte("file not found"))
|
||||
return HandledRouteError()
|
||||
|
|
|
@ -2817,21 +2817,21 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
|||
r.RLock()
|
||||
h, ok := r.extraRoutes[req.URL.Path]
|
||||
r.RUnlock()
|
||||
req.URL.Path += extraData
|
||||
|
||||
if ok {
|
||||
req.URL.Path += extraData
|
||||
// TODO: Be more specific about *which* dynamic route it is
|
||||
co.RouteViewCounter.Bump(165)
|
||||
return h(w,req,user)
|
||||
}
|
||||
co.RouteViewCounter.Bump3(172, cn)
|
||||
|
||||
lp := strings.ToLower(req.URL.Path)
|
||||
if strings.Contains(lp,"admin") || strings.Contains(lp,"sql") || strings.Contains(lp,"manage") || strings.Contains(lp,"//") || strings.Contains(lp,"\\\\") || strings.Contains(lp,"wp") || strings.Contains(lp,"wordpress") || strings.Contains(lp,"config") || strings.Contains(lp,"setup") || strings.Contains(lp,"install") || strings.Contains(lp,"update") || strings.Contains(lp,"php") || strings.Contains(lp,"pl") || strings.Contains(lp,"wget") || strings.Contains(lp,"wp-") || strings.Contains(lp,"include") || strings.Contains(lp,"vendor") || strings.Contains(lp,"bin") || strings.Contains(lp,"system") || strings.Contains(lp,"eval") || strings.Contains(lp,"config") {
|
||||
r.SuspiciousRequest(req,"Bad Route")
|
||||
} else {
|
||||
r.DumpRequest(req,"Bad Route")
|
||||
return c.MicroNotFound(w,req)
|
||||
}
|
||||
co.RouteViewCounter.Bump3(172, cn)
|
||||
r.DumpRequest(req,"Bad Route")
|
||||
return c.NotFound(w,req,nil)
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -1007,21 +1007,21 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
|||
r.RLock()
|
||||
h, ok := r.extraRoutes[req.URL.Path]
|
||||
r.RUnlock()
|
||||
req.URL.Path += extraData
|
||||
|
||||
if ok {
|
||||
req.URL.Path += extraData
|
||||
// TODO: Be more specific about *which* dynamic route it is
|
||||
co.RouteViewCounter.Bump({{index .AllRouteMap "routes.DynamicRoute"}})
|
||||
return h(w,req,user)
|
||||
}
|
||||
co.RouteViewCounter.Bump3({{index .AllRouteMap "routes.BadRoute"}}, cn)
|
||||
|
||||
lp := strings.ToLower(req.URL.Path)
|
||||
if strings.Contains(lp,"admin") || strings.Contains(lp,"sql") || strings.Contains(lp,"manage") || strings.Contains(lp,"//") || strings.Contains(lp,"\\\\") || strings.Contains(lp,"wp") || strings.Contains(lp,"wordpress") || strings.Contains(lp,"config") || strings.Contains(lp,"setup") || strings.Contains(lp,"install") || strings.Contains(lp,"update") || strings.Contains(lp,"php") || strings.Contains(lp,"pl") || strings.Contains(lp,"wget") || strings.Contains(lp,"wp-") || strings.Contains(lp,"include") || strings.Contains(lp,"vendor") || strings.Contains(lp,"bin") || strings.Contains(lp,"system") || strings.Contains(lp,"eval") || strings.Contains(lp,"config") {
|
||||
r.SuspiciousRequest(req,"Bad Route")
|
||||
} else {
|
||||
r.DumpRequest(req,"Bad Route")
|
||||
return c.MicroNotFound(w,req)
|
||||
}
|
||||
co.RouteViewCounter.Bump3({{index .AllRouteMap "routes.BadRoute"}}, cn)
|
||||
r.DumpRequest(req,"Bad Route")
|
||||
return c.NotFound(w,req,nil)
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -23,8 +23,8 @@ func ParseSEOURL(urlBit string) (slug string, id int, err error) {
|
|||
return halves[0], tid, err
|
||||
}
|
||||
|
||||
var slen1 = len("</s/>; rel=preload; as=script,")
|
||||
var slen2 = len("</s/>; rel=preload; as=style,")
|
||||
var slen1 = len("</s/>;rel=preload;as=script,")
|
||||
var slen2 = len("</s/>;rel=preload;as=style,")
|
||||
|
||||
func doPush(w http.ResponseWriter, header *c.Header) {
|
||||
//fmt.Println("in doPush")
|
||||
|
@ -32,11 +32,11 @@ func doPush(w http.ResponseWriter, header *c.Header) {
|
|||
// TODO: Cache these in a sync.Pool?
|
||||
var sb strings.Builder
|
||||
push := func(in []string) {
|
||||
sb.Grow((slen1 + 5) * len(in))
|
||||
sb.Grow((slen1 + 6) * len(in))
|
||||
for _, path := range in {
|
||||
sb.WriteString("</s/")
|
||||
sb.WriteString(path)
|
||||
sb.WriteString(">; rel=preload; as=script,")
|
||||
sb.WriteString(">;rel=preload;as=script,")
|
||||
}
|
||||
}
|
||||
push(header.Scripts)
|
||||
|
@ -44,11 +44,11 @@ func doPush(w http.ResponseWriter, header *c.Header) {
|
|||
push(header.ScriptsAsync)
|
||||
|
||||
if len(header.Stylesheets) > 0 {
|
||||
sb.Grow((slen2 + 6) * len(header.Stylesheets))
|
||||
sb.Grow((slen2 + 7) * len(header.Stylesheets))
|
||||
for _, path := range header.Stylesheets {
|
||||
sb.WriteString("</s/")
|
||||
sb.WriteString(path)
|
||||
sb.WriteString(">; rel=preload; as=style,")
|
||||
sb.WriteString(">;rel=preload;as=style,")
|
||||
}
|
||||
}
|
||||
// TODO: Push avatars?
|
||||
|
@ -67,6 +67,7 @@ func doPush(w http.ResponseWriter, header *c.Header) {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
//panic("has pusher")
|
||||
//fmt.Println("has pusher")
|
||||
|
||||
push := func(in []string) {
|
||||
|
@ -162,11 +163,7 @@ func renderTemplate3(tmplName, hookName string, w http.ResponseWriter, r *http.R
|
|||
if c.RunPreRenderHook("pre_render_"+hookName, w, r, h.CurrentUser, pi) {
|
||||
return nil
|
||||
}
|
||||
err := h.Theme.RunTmpl(tmplName, pi, w)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return h.Theme.RunTmpl(tmplName, pi, w)
|
||||
}
|
||||
|
||||
// TODO: Rename renderTemplate to RenderTemplate instead of using this hack to avoid breaking things
|
||||
|
|
Loading…
Reference in New Issue