2017-04-12 10:10:36 +00:00
/* WIP Under Construction */
package main
2017-12-10 03:43:30 +00:00
import (
2017-12-19 03:53:13 +00:00
"bytes"
2017-12-10 03:43:30 +00:00
"log"
"os"
2017-12-19 03:53:13 +00:00
"strconv"
2019-04-19 07:16:09 +00:00
"strings"
2017-12-19 03:53:13 +00:00
"text/template"
2017-12-10 03:43:30 +00:00
)
2017-09-10 16:57:22 +00:00
2017-12-19 03:53:13 +00:00
type TmplVars struct {
2018-12-31 09:03:49 +00:00
RouteList [ ] * RouteImpl
RouteGroups [ ] * RouteGroup
2019-04-19 07:16:09 +00:00
AllRouteNames [ ] RouteName
2018-12-31 09:03:49 +00:00
AllRouteMap map [ string ] int
AllAgentNames [ ] string
AllAgentMap map [ string ] int
AllAgentMarkNames [ ] string
AllAgentMarks map [ string ] string
2020-03-08 04:15:27 +00:00
AllAgentMarkIDs map [ string ] int
2018-12-31 09:03:49 +00:00
AllOSNames [ ] string
AllOSMap map [ string ] int
2017-12-19 03:53:13 +00:00
}
2019-04-19 07:16:09 +00:00
type RouteName struct {
Plain string
Short string
}
2017-04-12 10:10:36 +00:00
func main ( ) {
2017-08-13 11:22:34 +00:00
log . Println ( "Generating the router..." )
2017-09-10 16:57:22 +00:00
2017-04-12 10:10:36 +00:00
// Load all the routes...
2018-11-13 04:43:05 +00:00
r := & Router { }
routes ( r )
2017-09-10 16:57:22 +00:00
2019-10-20 01:42:19 +00:00
tmplVars := TmplVars {
2018-11-13 04:43:05 +00:00
RouteList : r . routeList ,
RouteGroups : r . routeGroups ,
2017-12-19 03:53:13 +00:00
}
2019-04-19 07:16:09 +00:00
var allRouteNames [ ] RouteName
2019-10-20 01:42:19 +00:00
allRouteMap := make ( map [ string ] int )
2017-12-19 03:53:13 +00:00
var out string
2019-10-20 01:42:19 +00:00
mapIt := func ( name string ) {
2019-04-19 07:16:09 +00:00
allRouteNames = append ( allRouteNames , RouteName { name , strings . Replace ( name , "common." , "c." , - 1 ) } )
2017-12-19 03:53:13 +00:00
allRouteMap [ name ] = len ( allRouteNames ) - 1
2017-12-10 03:43:30 +00:00
}
2020-02-26 10:34:38 +00:00
mapIt ( "routes.Error" )
2019-10-20 01:42:19 +00:00
countToIndents := func ( indent int ) ( indentor string ) {
2017-12-10 03:43:30 +00:00
for i := 0 ; i < indent ; i ++ {
indentor += "\t"
2017-04-13 09:26:40 +00:00
}
2017-12-10 03:43:30 +00:00
return indentor
}
2020-02-26 10:34:38 +00:00
runBefore := func ( runnables [ ] Runnable , indentCount int ) ( out string ) {
indent := countToIndents ( indentCount )
2017-12-10 03:43:30 +00:00
if len ( runnables ) > 0 {
for _ , runnable := range runnables {
2017-11-05 09:55:34 +00:00
if runnable . Literal {
2020-02-26 10:34:38 +00:00
out += "\n\t" + indent + runnable . Contents
2017-11-05 09:55:34 +00:00
} else {
2020-02-26 10:34:38 +00:00
out += "\n" + indent + "err = c." + runnable . Contents + "(w,req,user)\n" +
indent + "if err != nil {\n" +
indent + "\treturn err\n" +
indent + "}\n" + indent
2017-11-05 09:55:34 +00:00
}
}
2017-04-13 09:26:40 +00:00
}
2017-12-10 03:43:30 +00:00
return out
}
2018-11-13 04:43:05 +00:00
for _ , route := range r . routeList {
2017-12-19 03:53:13 +00:00
mapIt ( route . Name )
2019-10-20 01:42:19 +00:00
end := len ( route . Path ) - 1
2017-12-10 03:43:30 +00:00
out += "\n\t\tcase \"" + route . Path [ 0 : end ] + "\":"
2020-02-26 10:34:38 +00:00
//out += "\n\t\t\tid = " + strconv.Itoa(allRouteMap[route.Name])
2017-12-10 03:43:30 +00:00
out += runBefore ( route . RunBefore , 4 )
2018-11-12 09:23:36 +00:00
if ! route . Action && ! route . NoHead {
2020-03-18 09:21:34 +00:00
//out += "\n\t\t\th, err := c.UserCheck(w,req,user)"
out += "\n\t\t\th, err := c.UserCheckNano(w,req,user,cn)"
2018-11-12 09:23:36 +00:00
out += "\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}"
vcpy := route . Vars
2020-02-26 10:34:38 +00:00
route . Vars = [ ] string { "h" }
2018-11-12 09:23:36 +00:00
route . Vars = append ( route . Vars , vcpy ... )
2020-03-06 03:07:28 +00:00
} / * else if route . Name != "common.RouteWebsockets" {
2020-02-28 23:11:07 +00:00
//out += "\n\t\t\tsa := time.Now()"
2020-02-29 01:10:39 +00:00
//out += "\n\t\t\tcn := uutils.Nanotime()"
} * /
2019-04-19 07:25:49 +00:00
out += "\n\t\t\terr = " + strings . Replace ( route . Name , "common." , "c." , - 1 ) + "(w,req,user"
2017-04-12 10:10:36 +00:00
for _ , item := range route . Vars {
2017-04-13 15:01:30 +00:00
out += "," + item
2017-04-12 10:10:36 +00:00
}
2018-08-22 02:29:11 +00:00
out += ` ) `
2020-02-29 01:10:39 +00:00
/ * if ! route . Action && ! route . NoHead {
2020-02-26 10:34:38 +00:00
out += "\n\t\t\tco.RouteViewCounter.Bump2(" + strconv . Itoa ( allRouteMap [ route . Name ] ) + ", h.StartedAt)"
2020-02-29 01:10:39 +00:00
} else * / if route . Name != "common.RouteWebsockets" {
2020-02-28 23:11:07 +00:00
//out += "\n\t\t\tco.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[route.Name]) + ")"
//out += "\n\t\t\tco.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", sa)"
out += "\n\t\t\tco.RouteViewCounter.Bump3(" + strconv . Itoa ( allRouteMap [ route . Name ] ) + ", cn)"
2020-02-26 10:34:38 +00:00
}
2017-04-13 09:26:40 +00:00
}
2017-09-10 16:57:22 +00:00
2018-11-13 04:43:05 +00:00
for _ , group := range r . routeGroups {
2019-10-20 01:42:19 +00:00
end := len ( group . Path ) - 1
2017-12-10 03:43:30 +00:00
out += "\n\t\tcase \"" + group . Path [ 0 : end ] + "\":"
out += runBefore ( group . RunBefore , 3 )
2017-10-30 09:57:08 +00:00
out += "\n\t\t\tswitch(req.URL.Path) {"
2019-10-20 01:42:19 +00:00
defaultRoute := blankRoute ( )
2017-10-30 09:57:08 +00:00
for _ , route := range group . RouteList {
2017-04-13 10:55:51 +00:00
if group . Path == route . Path {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
defaultRoute = route
2017-04-13 10:55:51 +00:00
continue
}
2017-12-19 03:53:13 +00:00
mapIt ( route . Name )
2017-09-10 16:57:22 +00:00
2017-04-13 09:26:40 +00:00
out += "\n\t\t\t\tcase \"" + route . Path + "\":"
2020-02-26 10:34:38 +00:00
//out += "\n\t\t\t\t\tid = " + strconv.Itoa(allRouteMap[route.Name])
2017-11-05 09:55:34 +00:00
if len ( route . RunBefore ) > 0 {
2017-11-12 07:18:25 +00:00
skipRunnable :
2017-11-05 09:55:34 +00:00
for _ , runnable := range route . RunBefore {
2017-11-12 07:18:25 +00:00
for _ , gRunnable := range group . RunBefore {
if gRunnable . Contents == runnable . Contents {
continue
}
// TODO: Stop hard-coding these
if gRunnable . Contents == "AdminOnly" && runnable . Contents == "MemberOnly" {
continue skipRunnable
}
if gRunnable . Contents == "AdminOnly" && runnable . Contents == "SuperModOnly" {
continue skipRunnable
}
if gRunnable . Contents == "SuperModOnly" && runnable . Contents == "MemberOnly" {
continue skipRunnable
}
}
2017-11-05 09:55:34 +00:00
if runnable . Literal {
out += "\n\t\t\t\t\t" + runnable . Contents
} else {
out += `
2019-04-19 07:16:09 +00:00
err = c . ` + runnable.Contents + ` ( w , req , user )
2017-11-05 09:55:34 +00:00
if err != nil {
2018-11-12 09:23:36 +00:00
return err
2017-11-05 09:55:34 +00:00
}
`
}
}
2017-04-13 09:26:40 +00:00
}
2018-11-12 09:23:36 +00:00
if ! route . Action && ! route . NoHead && ! group . NoHead {
2020-03-18 09:21:34 +00:00
//out += "\n\t\t\t\th, err := c.UserCheck(w,req,user)"
out += "\n\t\t\t\th, err := c.UserCheckNano(w,req,user,cn)"
2018-11-12 09:23:36 +00:00
out += "\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}"
vcpy := route . Vars
2020-02-26 10:34:38 +00:00
route . Vars = [ ] string { "h" }
2018-11-12 09:23:36 +00:00
route . Vars = append ( route . Vars , vcpy ... )
2020-02-28 23:11:07 +00:00
} else {
2020-02-29 01:10:39 +00:00
//out += "\n\t\t\t\t\tcn := uutils.Nanotime()"
2018-11-12 09:23:36 +00:00
}
2019-04-19 07:25:49 +00:00
out += "\n\t\t\t\t\terr = " + strings . Replace ( route . Name , "common." , "c." , - 1 ) + "(w,req,user"
2017-04-13 09:26:40 +00:00
for _ , item := range route . Vars {
2017-04-13 15:01:30 +00:00
out += "," + item
2017-04-13 09:26:40 +00:00
}
2017-10-30 09:57:08 +00:00
out += ")"
2020-02-29 01:10:39 +00:00
/ * if ! route . Action && ! route . NoHead && ! group . NoHead {
2020-02-26 10:34:38 +00:00
out += "\n\t\t\t\t\tco.RouteViewCounter.Bump2(" + strconv . Itoa ( allRouteMap [ route . Name ] ) + ", h.StartedAt)"
2020-02-29 01:10:39 +00:00
} else { * /
2020-03-06 03:07:28 +00:00
//out += "\n\t\t\t\t\tco.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[route.Name]) + ")"
out += "\n\t\t\t\t\tco.RouteViewCounter.Bump3(" + strconv . Itoa ( allRouteMap [ route . Name ] ) + ", cn)"
2020-02-29 01:10:39 +00:00
//}
2017-04-13 09:26:40 +00:00
}
2017-09-10 16:57:22 +00:00
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if defaultRoute . Name != "" {
2017-12-19 03:53:13 +00:00
mapIt ( defaultRoute . Name )
2017-04-13 10:55:51 +00:00
out += "\n\t\t\t\tdefault:"
2020-02-26 10:34:38 +00:00
//out += "\n\t\t\t\t\tid = " + strconv.Itoa(allRouteMap[defaultRoute.Name])
2017-12-10 03:43:30 +00:00
out += runBefore ( defaultRoute . RunBefore , 4 )
2018-11-12 09:23:36 +00:00
if ! defaultRoute . Action && ! defaultRoute . NoHead && ! group . NoHead {
2020-03-18 09:21:34 +00:00
//out += "\n\t\t\t\t\th, err := c.UserCheck(w,req,user)"
out += "\n\t\t\t\t\th, err := c.UserCheckNano(w,req,user,cn)"
2018-11-12 09:23:36 +00:00
out += "\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}"
vcpy := defaultRoute . Vars
2020-02-26 10:34:38 +00:00
defaultRoute . Vars = [ ] string { "h" }
2018-11-12 09:23:36 +00:00
defaultRoute . Vars = append ( defaultRoute . Vars , vcpy ... )
}
2019-04-19 07:25:49 +00:00
out += "\n\t\t\t\t\terr = " + strings . Replace ( defaultRoute . Name , "common." , "c." , - 1 ) + "(w,req,user"
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
for _ , item := range defaultRoute . Vars {
2017-04-13 10:55:51 +00:00
out += ", " + item
}
2017-10-30 09:57:08 +00:00
out += ")"
2020-02-29 01:10:39 +00:00
/ * if ! defaultRoute . Action && ! defaultRoute . NoHead && ! group . NoHead {
2020-02-26 10:34:38 +00:00
out += "\n\t\t\t\t\tco.RouteViewCounter.Bump2(" + strconv . Itoa ( allRouteMap [ defaultRoute . Name ] ) + ", h.StartedAt)"
2020-02-29 01:10:39 +00:00
} else { * /
2020-03-06 03:07:28 +00:00
//out += "\n\t\t\t\t\tco.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[defaultRoute.Name]) + ")"
out += "\n\t\t\tco.RouteViewCounter.Bump3(" + strconv . Itoa ( allRouteMap [ defaultRoute . Name ] ) + ", cn)"
2020-02-29 01:10:39 +00:00
//}
2017-04-13 10:55:51 +00:00
}
2017-10-30 09:57:08 +00:00
out += `
} `
2017-04-12 10:10:36 +00:00
}
2017-09-10 16:57:22 +00:00
2017-12-24 22:08:35 +00:00
// Stubs for us to refer to these routes through
2018-05-15 05:59:52 +00:00
mapIt ( "routes.DynamicRoute" )
mapIt ( "routes.UploadedFile" )
2018-02-19 04:26:01 +00:00
mapIt ( "routes.StaticFile" )
2018-03-17 08:16:43 +00:00
mapIt ( "routes.RobotsTxt" )
mapIt ( "routes.SitemapXml" )
2019-05-08 05:08:38 +00:00
mapIt ( "routes.OpenSearchXml" )
2020-02-26 10:34:38 +00:00
mapIt ( "routes.Favicon" )
2018-05-15 05:59:52 +00:00
mapIt ( "routes.BadRoute" )
2019-03-21 22:59:41 +00:00
mapIt ( "routes.HTTPSRedirect" )
2017-12-19 03:53:13 +00:00
tmplVars . AllRouteNames = allRouteNames
tmplVars . AllRouteMap = allRouteMap
2018-02-04 08:15:20 +00:00
tmplVars . AllOSNames = [ ] string {
"unknown" ,
"windows" ,
"linux" ,
"mac" ,
"android" ,
"iphone" ,
}
tmplVars . AllOSMap = make ( map [ string ] int )
for id , os := range tmplVars . AllOSNames {
tmplVars . AllOSMap [ os ] = id
}
2018-01-09 07:39:29 +00:00
tmplVars . AllAgentNames = [ ] string {
"unknown" ,
"firefox" ,
"chrome" ,
"opera" ,
"safari" ,
"edge" ,
2018-01-09 08:46:16 +00:00
"internetexplorer" ,
2018-02-04 08:15:20 +00:00
"trident" , // Hack to support IE11
2018-01-09 07:39:29 +00:00
2018-02-03 05:47:14 +00:00
"androidchrome" ,
2018-02-04 08:15:20 +00:00
"mobilesafari" ,
"samsung" ,
2018-02-03 05:47:14 +00:00
"ucbrowser" ,
2018-01-09 07:39:29 +00:00
"googlebot" ,
"yandex" ,
"bing" ,
2020-03-07 03:25:50 +00:00
"slurp" ,
"exabot" ,
2020-03-11 08:54:11 +00:00
"mojeek" ,
2020-03-13 06:37:18 +00:00
"cliqz" ,
2020-03-21 07:44:33 +00:00
"datenbank" ,
2018-01-09 07:39:29 +00:00
"baidu" ,
2020-03-07 03:25:50 +00:00
"sogou" ,
2020-03-07 05:28:25 +00:00
"toutiao" ,
2020-03-08 00:50:23 +00:00
"haosou" ,
2018-01-09 07:39:29 +00:00
"duckduckgo" ,
2018-02-04 08:15:20 +00:00
"seznambot" ,
2018-01-11 08:03:17 +00:00
"discord" ,
2018-02-04 08:15:20 +00:00
"twitter" ,
2019-03-03 02:28:17 +00:00
"facebook" ,
2018-02-03 05:47:14 +00:00
"cloudflare" ,
2020-03-07 03:49:44 +00:00
"archive_org" ,
2018-01-25 04:57:33 +00:00
"uptimebot" ,
2018-03-08 03:59:47 +00:00
"slackbot" ,
2019-06-01 02:03:04 +00:00
"apple" ,
2018-02-04 08:15:20 +00:00
"discourse" ,
2020-03-28 05:39:05 +00:00
"mattermost" ,
2020-03-07 03:25:50 +00:00
"alexa" ,
2018-01-11 08:03:17 +00:00
"lynx" ,
"blank" ,
2018-01-25 04:57:33 +00:00
"malformed" ,
2018-01-26 05:53:34 +00:00
"suspicious" ,
2019-02-10 09:32:05 +00:00
"semrush" ,
2019-02-23 06:29:19 +00:00
"dotbot" ,
2020-03-07 11:08:25 +00:00
"ahrefs" ,
2020-03-08 00:50:23 +00:00
"proximic" ,
2020-03-07 10:46:27 +00:00
"majestic" ,
2020-04-04 09:03:11 +00:00
"netcraft" ,
2020-03-13 06:37:18 +00:00
"blexbot" ,
2020-04-04 03:21:59 +00:00
"burf" ,
2020-03-06 09:12:41 +00:00
"aspiegel" ,
2020-03-08 00:50:23 +00:00
"mail_ru" ,
2020-03-31 13:10:29 +00:00
"ccbot" ,
2018-02-03 05:47:14 +00:00
"zgrab" ,
2020-04-04 03:10:18 +00:00
"cloudsystemnetworks" ,
2020-03-13 06:37:18 +00:00
"curl" ,
2020-03-22 04:37:45 +00:00
"python" ,
"go" ,
2018-01-09 07:39:29 +00:00
}
tmplVars . AllAgentMap = make ( map [ string ] int )
for id , agent := range tmplVars . AllAgentNames {
tmplVars . AllAgentMap [ agent ] = id
}
2017-12-19 03:53:13 +00:00
2018-12-31 09:03:49 +00:00
tmplVars . AllAgentMarkNames = [ ] string {
"OPR" ,
"Chrome" ,
"Firefox" ,
2020-03-08 04:36:27 +00:00
"Safari" ,
2018-12-31 09:03:49 +00:00
"MSIE" ,
"Trident" ,
"Edge" ,
"Lynx" ,
"SamsungBrowser" ,
"UCBrowser" ,
"Google" ,
"Googlebot" ,
"yandex" ,
"DuckDuckBot" ,
2020-03-09 10:49:22 +00:00
"DuckDuckGo" ,
2018-12-31 09:03:49 +00:00
"Baiduspider" ,
2020-03-07 03:25:50 +00:00
"Sogou" ,
2020-03-07 05:28:25 +00:00
"ToutiaoSpider" ,
2020-03-08 00:50:23 +00:00
"360Spider" ,
2018-12-31 09:03:49 +00:00
"bingbot" ,
"BingPreview" ,
2020-03-18 21:21:06 +00:00
"msnbot" ,
2020-03-07 03:25:50 +00:00
"Slurp" ,
"Exabot" ,
2020-03-11 08:54:11 +00:00
"MojeekBot" ,
2020-03-13 06:37:18 +00:00
"Cliqzbot" ,
2020-03-21 07:44:33 +00:00
"netEstate" ,
2018-12-31 09:03:49 +00:00
"SeznamBot" ,
"CloudFlare" ,
2020-03-08 00:50:23 +00:00
"archive" , //archive.org_bot
2018-12-31 09:03:49 +00:00
"Uptimebot" ,
"Slackbot" ,
2020-03-07 05:28:25 +00:00
"Slack" ,
2018-12-31 09:03:49 +00:00
"Discordbot" ,
"Twitterbot" ,
2019-03-03 02:28:17 +00:00
"facebookexternalhit" ,
"Facebot" ,
2019-06-01 02:03:04 +00:00
"Applebot" ,
2018-12-31 09:03:49 +00:00
"Discourse" ,
2020-03-28 05:39:05 +00:00
"mattermost" ,
2020-03-07 03:25:50 +00:00
"ia_archiver" ,
2018-12-31 09:03:49 +00:00
2019-02-10 09:32:05 +00:00
"SemrushBot" ,
2019-02-23 06:29:19 +00:00
"DotBot" ,
2020-03-07 11:08:25 +00:00
"AhrefsBot" ,
2020-03-08 00:50:23 +00:00
"proximic" ,
2020-03-07 10:46:27 +00:00
"MJ12bot" ,
2020-04-04 09:03:11 +00:00
"mj12bot" ,
"NetcraftSurveyAgent" ,
2020-03-13 06:37:18 +00:00
"BLEXBot" ,
2020-04-04 03:21:59 +00:00
"Burf" ,
2020-03-07 03:25:50 +00:00
"AspiegelBot" ,
2020-03-08 00:50:23 +00:00
"RU_Bot" , // Mail.RU_Bot
2020-03-31 13:10:29 +00:00
"CCBot" ,
2018-12-31 09:03:49 +00:00
"zgrab" ,
2020-04-04 03:10:18 +00:00
"Nimbostratus" ,
2020-03-13 06:37:18 +00:00
"curl" ,
2020-03-22 04:37:45 +00:00
"python" ,
"Go" ,
2018-12-31 09:03:49 +00:00
}
tmplVars . AllAgentMarks = map [ string ] string {
"OPR" : "opera" ,
"Chrome" : "chrome" ,
"Firefox" : "firefox" ,
2020-03-08 04:36:27 +00:00
"Safari" : "safari" ,
2018-12-31 09:03:49 +00:00
"MSIE" : "internetexplorer" ,
"Trident" : "trident" , // Hack to support IE11
"Edge" : "edge" ,
"Lynx" : "lynx" , // There's a rare android variant of lynx which isn't covered by this
"SamsungBrowser" : "samsung" ,
"UCBrowser" : "ucbrowser" ,
2019-03-03 02:28:17 +00:00
"Google" : "googlebot" ,
"Googlebot" : "googlebot" ,
"yandex" : "yandex" , // from the URL
"DuckDuckBot" : "duckduckgo" ,
2020-03-11 03:26:33 +00:00
"DuckDuckGo" : "duckduckgo" ,
2019-03-03 02:28:17 +00:00
"Baiduspider" : "baidu" ,
2020-03-07 03:25:50 +00:00
"Sogou" : "sogou" ,
2020-03-07 05:28:25 +00:00
"ToutiaoSpider" : "toutiao" ,
2020-03-08 00:50:23 +00:00
"360Spider" : "haosou" ,
2019-03-03 02:28:17 +00:00
"bingbot" : "bing" ,
"BingPreview" : "bing" ,
2020-03-22 04:37:45 +00:00
"msnbot" : "bing" ,
2020-03-07 03:25:50 +00:00
"Slurp" : "slurp" ,
"Exabot" : "exabot" ,
2020-03-11 08:54:11 +00:00
"MojeekBot" : "mojeek" ,
2020-03-13 06:37:18 +00:00
"Cliqzbot" : "cliqz" ,
2020-03-22 04:37:45 +00:00
"netEstate" : "datenbank" ,
2019-03-03 02:28:17 +00:00
"SeznamBot" : "seznambot" ,
2020-03-08 00:50:23 +00:00
"CloudFlare" : "cloudflare" , // Track alwayson specifically in case there are other bots?
"archive" : "archive_org" , //archive.org_bot
2019-03-03 02:28:17 +00:00
"Uptimebot" : "uptimebot" ,
"Slackbot" : "slackbot" ,
2020-03-07 05:28:25 +00:00
"Slack" : "slackbot" ,
2019-03-03 02:28:17 +00:00
"Discordbot" : "discord" ,
"Twitterbot" : "twitter" ,
"facebookexternalhit" : "facebook" ,
"Facebot" : "facebook" ,
2019-10-20 01:42:19 +00:00
"Applebot" : "apple" ,
2019-03-03 02:28:17 +00:00
"Discourse" : "discourse" ,
2020-03-31 13:10:29 +00:00
"mattermost" : "mattermost" ,
2020-03-07 03:25:50 +00:00
"ia_archiver" : "alexa" ,
2018-12-31 09:03:49 +00:00
2020-04-04 09:03:11 +00:00
"SemrushBot" : "semrush" ,
"DotBot" : "dotbot" ,
"AhrefsBot" : "ahrefs" ,
"proximic" : "proximic" ,
"MJ12bot" : "majestic" ,
"mj12bot" : "majestic" ,
"NetcraftSurveyAgent" : "netcraft" ,
"BLEXBot" : "blexbot" ,
"Burf" : "burf" ,
"AspiegelBot" : "aspiegel" ,
"RU_Bot" : "mail_ru" , // Mail.RU_Bot
"CCBot" : "ccbot" ,
"zgrab" : "zgrab" ,
"Nimbostratus" : "cloudsystemnetworks" ,
"curl" : "curl" ,
"python" : "python" ,
"Go" : "go" ,
2018-12-31 09:03:49 +00:00
}
2020-03-08 04:15:27 +00:00
tmplVars . AllAgentMarkIDs = make ( map [ string ] int )
for mark , agent := range tmplVars . AllAgentMarks {
tmplVars . AllAgentMarkIDs [ mark ] = tmplVars . AllAgentMap [ agent ]
}
2019-10-20 01:42:19 +00:00
fileData := ` // Code generated by Gosora's Router Generator. DO NOT EDIT.
2017-12-10 03:43:30 +00:00
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
package main
2017-04-12 10:10:36 +00:00
2017-11-11 04:06:16 +00:00
import (
"log"
"strings"
2020-03-22 23:14:08 +00:00
//"bytes"
2018-03-08 03:59:47 +00:00
"strconv"
2018-08-21 08:00:35 +00:00
"compress/gzip"
2017-11-11 04:06:16 +00:00
"sync"
2018-07-15 10:29:31 +00:00
"sync/atomic"
2017-11-11 04:06:16 +00:00
"errors"
2018-04-03 04:34:07 +00:00
"os"
2017-11-11 04:06:16 +00:00
"net/http"
2020-02-28 23:11:07 +00:00
"time"
2017-11-11 04:06:16 +00:00
2019-04-19 07:16:09 +00:00
c "github.com/Azareal/Gosora/common"
2019-10-29 07:13:04 +00:00
co "github.com/Azareal/Gosora/common/counters"
2020-02-28 23:11:07 +00:00
"github.com/Azareal/Gosora/uutils"
2018-10-27 03:21:02 +00:00
"github.com/Azareal/Gosora/routes"
"github.com/Azareal/Gosora/routes/panel"
2017-11-11 04:06:16 +00:00
)
2017-04-12 10:10:36 +00:00
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
var ErrNoRoute = errors . New ( "That route doesn't exist." )
2017-12-19 03:53:13 +00:00
// TODO: What about the /uploads/ route? x.x
var RouteMap = map [ string ] interface { } { { { range . AllRouteNames } }
2019-04-19 07:16:09 +00:00
"{{.Plain}}" : { { . Short } } , { { end } }
2017-12-19 03:53:13 +00:00
}
// ! NEVER RELY ON THESE REMAINING THE SAME BETWEEN COMMITS
var routeMapEnum = map [ string ] int { { { range $ index , $ element := . AllRouteNames } }
2019-04-19 07:16:09 +00:00
"{{$element.Plain}}" : { { $ index } } , { { end } }
2017-12-19 03:53:13 +00:00
}
var reverseRouteMapEnum = map [ int ] string { { { range $ index , $ element := . AllRouteNames } }
2019-04-19 07:16:09 +00:00
{ { $ index } } : "{{$element.Plain}}" , { { end } }
2017-12-19 03:53:13 +00:00
}
2018-02-04 08:15:20 +00:00
var osMapEnum = map [ string ] int { { { range $ index , $ element := . AllOSNames } }
"{{$element}}" : { { $ index } } , { { end } }
}
var reverseOSMapEnum = map [ int ] string { { { range $ index , $ element := . AllOSNames } }
{ { $ index } } : "{{$element}}" , { { end } }
}
2018-01-09 07:39:29 +00:00
var agentMapEnum = map [ string ] int { { { range $ index , $ element := . AllAgentNames } }
"{{$element}}" : { { $ index } } , { { end } }
}
var reverseAgentMapEnum = map [ int ] string { { { range $ index , $ element := . AllAgentNames } }
{ { $ index } } : "{{$element}}" , { { end } }
}
2018-12-31 09:03:49 +00:00
var markToAgent = map [ string ] string { { { range $ index , $ element := . AllAgentMarkNames } }
"{{$element}}" : "{{index $.AllAgentMarks $element}}" , { { end } }
2018-02-03 05:47:14 +00:00
}
2020-03-08 04:15:27 +00:00
var markToID = map [ string ] int { { { range $ index , $ element := . AllAgentMarkNames } }
"{{$element}}" : { { index $ . AllAgentMarkIDs $ element } } , { { end } }
}
2018-02-03 05:47:14 +00:00
/ * var agentRank = map [ string ] int {
"opera" : 9 ,
"chrome" : 8 ,
"safari" : 1 ,
} * /
2017-12-19 03:53:13 +00:00
// TODO: Stop spilling these into the package scope?
func init ( ) {
2020-02-28 23:11:07 +00:00
_ = time . Now ( )
2019-10-29 07:13:04 +00:00
co . SetRouteMapEnum ( routeMapEnum )
co . SetReverseRouteMapEnum ( reverseRouteMapEnum )
co . SetAgentMapEnum ( agentMapEnum )
co . SetReverseAgentMapEnum ( reverseAgentMapEnum )
co . SetOSMapEnum ( osMapEnum )
co . SetReverseOSMapEnum ( reverseOSMapEnum )
2020-03-08 04:15:27 +00:00
c . Chrome = agentMapEnum [ "chrome" ]
c . Firefox = agentMapEnum [ "firefox" ]
2020-03-22 06:24:31 +00:00
ame := agentMapEnum
2020-03-22 04:37:45 +00:00
c . SimpleBots = [ ] int {
2020-03-22 06:24:31 +00:00
ame [ "semrush" ] ,
ame [ "ahrefs" ] ,
ame [ "python" ] ,
ame [ "go" ] ,
ame [ "curl" ] ,
2020-03-22 04:37:45 +00:00
}
2017-12-19 03:53:13 +00:00
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
2018-08-23 12:18:15 +00:00
type WriterIntercept struct {
2018-08-24 06:24:27 +00:00
http . ResponseWriter
2018-08-23 12:18:15 +00:00
}
func NewWriterIntercept ( w http . ResponseWriter ) * WriterIntercept {
2018-08-24 06:24:27 +00:00
return & WriterIntercept { w }
2018-08-23 12:18:15 +00:00
}
2019-04-19 07:16:09 +00:00
var wiMaxAge = "max-age=" + strconv . Itoa ( int ( c . Day ) )
2020-03-12 06:52:26 +00:00
func ( wi * WriterIntercept ) WriteHeader ( code int ) {
2018-08-24 06:24:27 +00:00
if code == 200 {
2020-03-12 06:52:26 +00:00
h := wi . ResponseWriter . Header ( )
2019-07-12 08:33:25 +00:00
h . Set ( "Cache-Control" , wiMaxAge )
h . Set ( "Vary" , "Accept-Encoding" )
2018-08-24 06:24:27 +00:00
}
2020-03-12 06:52:26 +00:00
wi . ResponseWriter . WriteHeader ( code )
2018-08-23 12:18:15 +00:00
}
2019-03-21 22:59:41 +00:00
// HTTPSRedirect is a connection handler which redirects all HTTP requests to HTTPS
2019-07-12 08:33:25 +00:00
type HTTPSRedirect struct { }
2019-03-21 22:59:41 +00:00
func ( red * HTTPSRedirect ) ServeHTTP ( w http . ResponseWriter , req * http . Request ) {
w . Header ( ) . Set ( "Connection" , "close" )
2019-10-29 07:13:04 +00:00
co . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.HTTPSRedirect" } } )
2019-03-21 22:59:41 +00:00
dest := "https://" + req . Host + req . URL . String ( )
http . Redirect ( w , req , dest , http . StatusTemporaryRedirect )
}
2017-04-12 10:10:36 +00:00
type GenRouter struct {
2017-04-12 13:39:03 +00:00
UploadHandler func ( http . ResponseWriter , * http . Request )
2020-03-18 09:21:34 +00:00
extraRoutes map [ string ] func ( http . ResponseWriter , * http . Request , * c . User ) c . RouteError
2018-04-03 04:34:07 +00:00
requestLogger * log . Logger
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
sync . RWMutex
2017-04-12 10:10:36 +00:00
}
2018-04-03 04:34:07 +00:00
func NewGenRouter ( uploads http . Handler ) ( * GenRouter , error ) {
2019-04-19 07:16:09 +00:00
f , err := os . OpenFile ( "./logs/reqs-" + strconv . FormatInt ( c . StartTime . Unix ( ) , 10 ) + ".log" , os . O_WRONLY | os . O_APPEND | os . O_CREATE , 0755 )
2018-04-03 04:34:07 +00:00
if err != nil {
return nil , err
}
2017-04-12 13:39:03 +00:00
return & GenRouter {
2018-03-31 05:25:27 +00:00
UploadHandler : func ( w http . ResponseWriter , req * http . Request ) {
2018-08-23 12:18:15 +00:00
writ := NewWriterIntercept ( w )
http . StripPrefix ( "/uploads/" , uploads ) . ServeHTTP ( writ , req )
2018-03-31 05:25:27 +00:00
} ,
2020-03-18 09:21:34 +00:00
extraRoutes : make ( map [ string ] func ( http . ResponseWriter , * http . Request , * c . User ) c . RouteError ) ,
2018-04-03 04:34:07 +00:00
requestLogger : log . New ( f , "" , log . LstdFlags ) ,
} , nil
2017-04-12 10:10:36 +00:00
}
2020-03-22 04:37:45 +00:00
func ( r * GenRouter ) handleError ( err c . RouteError , w http . ResponseWriter , req * http . Request , u * c . User ) {
2017-10-30 09:57:08 +00:00
if err . Handled ( ) {
return
}
if err . Type ( ) == "system" {
2019-04-19 07:16:09 +00:00
c . InternalErrorJSQ ( err , w , req , err . JSON ( ) )
2017-10-30 09:57:08 +00:00
return
}
2020-03-22 04:37:45 +00:00
c . LocalErrorJSQ ( err . Error ( ) , w , req , u , err . JSON ( ) )
2017-10-30 09:57:08 +00:00
}
2018-11-13 06:51:34 +00:00
func ( r * GenRouter ) Handle ( _ string , _ http . Handler ) {
2017-04-12 10:10:36 +00:00
}
2020-03-18 09:21:34 +00:00
func ( r * GenRouter ) HandleFunc ( pattern string , h func ( http . ResponseWriter , * http . Request , * c . User ) c . RouteError ) {
2018-11-13 06:51:34 +00:00
r . Lock ( )
defer r . Unlock ( )
2020-02-25 04:25:50 +00:00
r . extraRoutes [ pattern ] = h
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
2018-11-13 06:51:34 +00:00
func ( r * GenRouter ) RemoveFunc ( pattern string ) error {
r . Lock ( )
defer r . Unlock ( )
_ , ok := r . extraRoutes [ pattern ]
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
if ! ok {
return ErrNoRoute
}
2018-11-13 06:51:34 +00:00
delete ( r . extraRoutes , pattern )
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
return nil
2017-04-12 10:10:36 +00:00
}
2020-03-08 04:15:27 +00:00
// TODO: Use strings builder?
func ( r * GenRouter ) DumpRequest ( req * http . Request , pre string ) {
2018-02-26 09:07:00 +00:00
var heads string
2018-01-27 07:30:44 +00:00
for key , value := range req . Header {
for _ , vvalue := range value {
2020-03-28 05:39:05 +00:00
heads += "Head " + c . SanitiseSingleLine ( key ) + ": " + c . SanitiseSingleLine ( vvalue ) + "\n"
2018-01-27 07:30:44 +00:00
}
}
2018-02-26 09:07:00 +00:00
2020-03-08 04:15:27 +00:00
r . requestLogger . Print ( pre +
2019-04-19 07:16:09 +00:00
"\nUA: " + c . SanitiseSingleLine ( req . UserAgent ( ) ) + "\n" +
"Method: " + c . SanitiseSingleLine ( req . Method ) + "\n" + heads +
2020-02-25 04:25:50 +00:00
"Host: " + c . SanitiseSingleLine ( req . Host ) + "\n" +
"URL.Path: " + c . SanitiseSingleLine ( req . URL . Path ) + "\n" +
"URL.RawQuery: " + c . SanitiseSingleLine ( req . URL . RawQuery ) + "\n" +
2020-03-07 05:28:25 +00:00
"Ref: " + c . SanitiseSingleLine ( req . Referer ( ) ) + "\n" +
"IP: " + req . RemoteAddr + "\n" )
2018-01-27 07:30:44 +00:00
}
2020-03-08 04:15:27 +00:00
func ( r * GenRouter ) SuspiciousRequest ( req * http . Request , pre string ) {
if pre != "" {
pre += "\n"
2018-04-03 04:34:07 +00:00
}
2020-03-08 04:15:27 +00:00
r . DumpRequest ( req , pre + "Suspicious Request" )
2019-10-29 07:13:04 +00:00
co . AgentViewCounter . Bump ( { { . AllAgentMap . suspicious } } )
2018-01-27 07:30:44 +00:00
}
2020-02-25 04:25:50 +00:00
func isLocalHost ( h string ) bool {
return h == "localhost" || h == "127.0.0.1" || h == "::1"
2019-04-01 05:44:38 +00:00
}
2018-06-17 07:28:18 +00:00
// TODO: Pass the default path or config struct to the router rather than accessing it via a package global
// TODO: SetDefaultPath
// TODO: GetDefaultPath
2018-11-13 06:51:34 +00:00
func ( r * GenRouter ) ServeHTTP ( w http . ResponseWriter , req * http . Request ) {
2019-10-29 07:13:04 +00:00
malformedRequest := func ( typ int ) {
2019-04-01 05:44:38 +00:00
w . WriteHeader ( 200 ) // 400
w . Write ( [ ] byte ( "" ) )
2019-04-14 00:13:32 +00:00
r . DumpRequest ( req , "Malformed Request T" + strconv . Itoa ( typ ) )
2019-10-29 07:13:04 +00:00
co . AgentViewCounter . Bump ( { { . AllAgentMap . malformed } } )
2019-04-01 05:44:38 +00:00
}
// Split the Host and Port string
var shost , sport string
if req . Host [ 0 ] == '[' {
spl := strings . Split ( req . Host , "]" )
if len ( spl ) > 2 {
2019-04-14 00:13:32 +00:00
malformedRequest ( 0 )
2019-04-01 05:44:38 +00:00
return
}
shost = strings . TrimPrefix ( spl [ 0 ] , "[" )
sport = strings . TrimPrefix ( spl [ 1 ] , ":" )
2020-03-27 06:05:35 +00:00
} else if strings . Contains ( req . Host , ":" ) {
2019-04-01 05:44:38 +00:00
spl := strings . Split ( req . Host , ":" )
if len ( spl ) > 2 {
2019-04-14 00:13:32 +00:00
malformedRequest ( 1 )
2019-04-01 05:44:38 +00:00
return
}
shost = spl [ 0 ]
2020-03-27 06:05:35 +00:00
//if len(spl)==2 {
2019-04-01 05:44:38 +00:00
sport = spl [ 1 ]
2020-03-27 06:05:35 +00:00
//}
} else {
shost = req . Host
2019-04-01 05:44:38 +00:00
}
// TODO: Reject requests from non-local IPs, if the site host is set to localhost or a localhost IP
2019-04-19 07:16:09 +00:00
if ! c . Config . LoosePort && c . Site . PortInt != 80 && c . Site . PortInt != 443 && sport != c . Site . Port {
2019-04-14 00:13:32 +00:00
malformedRequest ( 2 )
2019-04-01 05:44:38 +00:00
return
}
// Redirect www. and local IP requests to the right place
2020-03-06 03:07:28 +00:00
if strings . HasPrefix ( shost , "www." ) || c . Site . LocalHost {
2019-04-19 07:16:09 +00:00
if shost == "www." + c . Site . Host || ( c . Site . LocalHost && shost != c . Site . Host && isLocalHost ( shost ) ) {
2019-03-31 01:50:59 +00:00
// TODO: Abstract the redirect logic?
2018-01-28 14:30:24 +00:00
w . Header ( ) . Set ( "Connection" , "close" )
var s string
2019-11-04 11:55:52 +00:00
if c . Config . SslSchema {
2018-01-28 14:30:24 +00:00
s = "s"
}
2019-04-01 05:44:38 +00:00
var p string
2019-04-19 07:16:09 +00:00
if c . Site . PortInt != 80 && c . Site . PortInt != 443 {
p = ":" + c . Site . Port
2019-04-01 05:44:38 +00:00
}
2019-04-19 07:16:09 +00:00
dest := "http" + s + "://" + c . Site . Host + p + req . URL . Path
2018-01-28 14:30:24 +00:00
if len ( req . URL . RawQuery ) > 0 {
dest += "?" + req . URL . RawQuery
}
http . Redirect ( w , req , dest , http . StatusMovedPermanently )
return
}
2020-03-06 03:07:28 +00:00
}
2018-01-28 14:30:24 +00:00
// Deflect malformed requests
2019-04-19 07:16:09 +00:00
if len ( req . URL . Path ) == 0 || req . URL . Path [ 0 ] != '/' || ( ! c . Config . LooseHost && shost != c . Site . Host ) {
2019-04-14 00:13:32 +00:00
malformedRequest ( 3 )
2017-04-12 13:39:03 +00:00
return
}
2019-04-19 07:16:09 +00:00
if c . Dev . FullReqLog {
2019-03-16 12:50:31 +00:00
r . DumpRequest ( req , "" )
}
2018-01-18 12:51:35 +00:00
2018-02-26 09:07:00 +00:00
// TODO: Cover more suspicious strings and at a lower layer than this
2019-11-04 11:55:52 +00:00
for _ , ch := range req . URL . Path { //char
if ch != '&' && ! ( ch > 44 && ch < 58 ) && ch != '=' && ch != '?' && ! ( ch > 64 && ch < 91 ) && ch != '\\' && ch != '_' && ! ( ch > 96 && ch < 123 ) {
2020-03-27 06:05:35 +00:00
r . SuspiciousRequest ( req , "Bad char '" + string ( ch ) + "' in path" )
2018-03-08 03:59:47 +00:00
break
2018-01-17 11:13:08 +00:00
}
2018-03-08 03:59:47 +00:00
}
2020-02-26 10:34:38 +00:00
lp := strings . ToLower ( req . URL . Path )
2018-03-08 03:59:47 +00:00
// TODO: Flag any requests which has a dot with anything but a number after that
2020-03-27 06:05:35 +00:00
// TODO: Use HasSuffix to avoid over-scanning?
2020-02-26 10:34:38 +00:00
if strings . Contains ( lp , ".." ) /* || strings.Contains(lp,"--")*/ || strings . Contains ( lp , ".php" ) || strings . Contains ( lp , ".asp" ) || strings . Contains ( lp , ".cgi" ) || strings . Contains ( lp , ".py" ) || strings . Contains ( lp , ".sql" ) || strings . Contains ( lp , ".action" ) {
2018-11-13 06:51:34 +00:00
r . SuspiciousRequest ( req , "Bad snippet in path" )
2018-03-08 03:59:47 +00:00
}
2018-06-17 07:28:18 +00:00
// Indirect the default route onto a different one
if req . URL . Path == "/" {
2019-04-19 07:16:09 +00:00
req . URL . Path = c . Config . DefaultPath
2018-06-17 07:28:18 +00:00
}
2020-02-26 10:34:38 +00:00
//log.Print("URL.Path: ", req.URL.Path)
2020-03-22 06:24:31 +00:00
prefix := req . URL . Path [ 0 : strings . IndexByte ( req . URL . Path [ 1 : ] , '/' ) + 1 ]
2018-08-21 08:00:35 +00:00
2019-04-10 07:40:47 +00:00
// TODO: Use the same hook table as downstream
2019-04-19 07:16:09 +00:00
hTbl := c . GetHookTable ( )
2020-03-22 06:24:31 +00:00
skip , ferr := hTbl . VhookSkippable ( "router_after_filters" , w , req , prefix )
2019-04-10 07:40:47 +00:00
if skip || ferr != nil {
return
}
2018-08-21 08:00:35 +00:00
if prefix != "/ws" {
h := w . Header ( )
h . Set ( "X-Frame-Options" , "deny" )
h . Set ( "X-XSS-Protection" , "1; mode=block" ) // TODO: Remove when we add a CSP? CSP's are horrendously glitchy things, tread with caution before removing
h . Set ( "X-Content-Type-Options" , "nosniff" )
2019-11-04 11:55:52 +00:00
if c . Config . RefNoRef || ! c . Config . SslSchema {
2019-08-14 10:39:04 +00:00
h . Set ( "Referrer-Policy" , "no-referrer" )
} else {
h . Set ( "Referrer-Policy" , "strict-origin" )
}
2018-08-21 08:00:35 +00:00
}
2017-08-06 15:22:18 +00:00
2019-04-19 07:16:09 +00:00
if c . Dev . SuperDebug {
2018-11-13 06:51:34 +00:00
r . DumpRequest ( req , "before routes.StaticFile" )
2017-08-06 15:22:18 +00:00
}
2018-02-19 04:26:01 +00:00
// Increment the request counter
2020-02-26 10:34:38 +00:00
if ! c . Config . DisableAnalytics {
co . GlobalViewCounter . Bump ( )
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
2019-08-14 10:39:04 +00:00
if prefix == "/s" { //old prefix: /static
2020-02-26 10:34:38 +00:00
if ! c . Config . DisableAnalytics {
co . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.StaticFile" } } )
}
2018-02-03 05:47:14 +00:00
routes . StaticFile ( w , req )
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
return
}
2020-03-27 06:05:35 +00:00
// TODO: Handle JS routes
2019-04-19 07:16:09 +00:00
if atomic . LoadInt32 ( & c . IsDBDown ) == 1 {
c . DatabaseError ( w , req )
2018-07-15 10:29:31 +00:00
return
}
2019-04-19 07:16:09 +00:00
if c . Dev . SuperDebug {
2018-11-13 06:51:34 +00:00
r . requestLogger . Print ( "before PreRoute" )
2017-07-17 10:23:42 +00:00
}
2017-12-10 03:43:30 +00:00
2020-02-25 04:25:50 +00:00
/ * if c . Dev . QuicPort != 0 {
w . Header ( ) . Set ( "Alt-Svc" , "quic=\":" + strconv . Itoa ( c . Dev . QuicPort ) + "\"; ma=2592000; v=\"44,43,39\", h3-23=\":" + strconv . Itoa ( c . Dev . QuicPort ) + "\"; ma=3600, h3-24=\":" + strconv . Itoa ( c . Dev . QuicPort ) + "\"; ma=3600, h2=\":443\"; ma=3600" )
} * /
2018-01-09 07:39:29 +00:00
// Track the user agents. Unfortunately, everyone pretends to be Mozilla, so this'll be a little less efficient than I would like.
// TODO: Add a setting to disable this?
// TODO: Use a more efficient detector instead of smashing every possible combination in
2020-03-08 04:15:27 +00:00
var agent int
2020-02-26 10:34:38 +00:00
if ! c . Config . DisableAnalytics {
ua := strings . TrimSpace ( strings . Replace ( strings . TrimPrefix ( req . UserAgent ( ) , "Mozilla/5.0 " ) , " Safari/537.36" , "" , - 1 ) ) // Noise, no one's going to be running this and it would require some sort of agent ranking system to determine which identifier should be prioritised over another
2018-02-03 05:47:14 +00:00
if ua == "" {
2019-10-29 07:13:04 +00:00
co . AgentViewCounter . Bump ( { { . AllAgentMap . blank } } )
2019-04-19 07:16:09 +00:00
if c . Dev . DebugMode {
2020-03-08 04:15:27 +00:00
var pre string
2018-03-08 03:59:47 +00:00
for _ , char := range req . UserAgent ( ) {
2020-03-08 04:15:27 +00:00
pre += strconv . Itoa ( int ( char ) ) + " "
2018-03-08 03:59:47 +00:00
}
2020-03-08 04:15:27 +00:00
r . DumpRequest ( req , "Blank UA: " + pre )
2018-01-11 09:29:25 +00:00
}
2018-12-31 09:03:49 +00:00
} else {
2018-02-03 05:47:14 +00:00
// WIP UA Parser
var items [ ] string
2018-12-31 09:03:49 +00:00
var buffer [ ] byte
2020-02-28 05:47:43 +00:00
var os int
2020-02-28 23:11:07 +00:00
for _ , it := range uutils . StringToBytes ( ua ) {
2020-03-08 08:04:37 +00:00
if ( it > 64 && it < 91 ) || ( it > 96 && it < 123 ) || it == '_' {
2020-03-27 06:05:35 +00:00
// TODO: Store an index and slice that instead?
2020-02-25 04:25:50 +00:00
buffer = append ( buffer , it )
2020-03-22 23:14:08 +00:00
} else if it == ' ' || it == '(' || it == ')' || it == '-' || ( it > 47 && it < 58 ) || it == ';' || it == ':' || it == '.' || it == '+' || it == '~' || it == '@' /*|| (it == ':' && bytes.Equal(buffer,[]byte("http")))*/ || it == ',' || it == '/' {
2018-02-04 08:15:20 +00:00
if len ( buffer ) != 0 {
2018-12-31 09:03:49 +00:00
if len ( buffer ) > 2 {
// Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append
2020-02-28 23:11:07 +00:00
switch ( uutils . BytesToString ( buffer ) ) {
2018-12-31 09:03:49 +00:00
case "Windows" :
2020-02-28 05:47:43 +00:00
os = { { . AllOSMap . windows } }
2018-12-31 09:03:49 +00:00
case "Linux" :
2020-02-28 05:47:43 +00:00
os = { { . AllOSMap . linux } }
2018-12-31 09:03:49 +00:00
case "Mac" :
2020-02-28 05:47:43 +00:00
os = { { . AllOSMap . mac } }
2018-12-31 09:03:49 +00:00
case "iPhone" :
2020-02-28 05:47:43 +00:00
os = { { . AllOSMap . iphone } }
2018-12-31 09:03:49 +00:00
case "Android" :
2020-02-28 05:47:43 +00:00
os = { { . AllOSMap . android } }
2019-02-10 09:32:05 +00:00
case "like" , "compatible" :
// Skip these words
2018-12-31 09:03:49 +00:00
default :
items = append ( items , string ( buffer ) )
}
}
2018-02-04 08:15:20 +00:00
buffer = buffer [ : 0 ]
}
} else {
// TODO: Test this
items = items [ : 0 ]
2020-02-25 04:25:50 +00:00
r . SuspiciousRequest ( req , "Illegal char " + strconv . Itoa ( int ( it ) ) + " in UA" )
2020-03-22 23:14:08 +00:00
r . requestLogger . Print ( "UA Buf: " , buffer )
r . requestLogger . Print ( "UA Buf String: " , string ( buffer ) )
2018-02-04 08:15:20 +00:00
break
2018-02-03 05:47:14 +00:00
}
}
// Iterate over this in reverse as the real UA tends to be on the right side
for i := len ( items ) - 1 ; i >= 0 ; i -- {
2020-03-08 04:15:27 +00:00
//fAgent, ok := markToAgent[items[i]]
fAgent , ok := markToID [ items [ i ] ]
2018-02-03 05:47:14 +00:00
if ok {
agent = fAgent
2020-03-08 04:15:27 +00:00
if agent != { { . AllAgentMap . safari } } {
2018-02-03 05:47:14 +00:00
break
}
}
}
2019-04-19 07:16:09 +00:00
if c . Dev . SuperDebug {
2018-11-13 06:51:34 +00:00
r . requestLogger . Print ( "parsed agent: " , agent )
r . requestLogger . Print ( "os: " , os )
r . requestLogger . Printf ( "items: %+v\n" , items )
2018-02-03 05:47:14 +00:00
}
// Special handling
switch ( agent ) {
2020-03-08 04:15:27 +00:00
case { { . AllAgentMap . chrome } } :
2020-02-28 05:47:43 +00:00
if os == { { . AllOSMap . android } } {
2020-03-08 04:15:27 +00:00
agent = { { . AllAgentMap . androidchrome } }
2018-02-04 08:15:20 +00:00
}
2020-03-08 04:15:27 +00:00
case { { . AllAgentMap . safari } } :
2020-02-28 05:47:43 +00:00
if os == { { . AllOSMap . iphone } } {
2020-03-08 04:15:27 +00:00
agent = { { . AllAgentMap . mobilesafari } }
2018-02-04 08:15:20 +00:00
}
2020-03-08 04:15:27 +00:00
case { { . AllAgentMap . trident } } :
2018-02-04 08:15:20 +00:00
// Hack to support IE11, change this after we start logging versions
if strings . Contains ( ua , "rv:11" ) {
2020-03-08 04:15:27 +00:00
agent = { { . AllAgentMap . internetexplorer } }
2018-02-03 05:47:14 +00:00
}
2020-03-08 04:15:27 +00:00
case { { . AllAgentMap . zgrab } } :
2018-11-13 06:51:34 +00:00
r . SuspiciousRequest ( req , "Vulnerability Scanner" )
2018-02-03 05:47:14 +00:00
}
2020-03-08 04:15:27 +00:00
if agent == 0 {
2019-10-29 07:13:04 +00:00
co . AgentViewCounter . Bump ( { { . AllAgentMap . unknown } } )
2019-04-19 07:16:09 +00:00
if c . Dev . DebugMode {
2020-03-08 04:15:27 +00:00
var pre string
2018-03-08 03:59:47 +00:00
for _ , char := range req . UserAgent ( ) {
2020-03-08 04:15:27 +00:00
pre += strconv . Itoa ( int ( char ) ) + " "
2018-03-08 03:59:47 +00:00
}
2020-03-08 04:15:27 +00:00
r . DumpRequest ( req , "Blank UA: " + pre )
2020-03-07 04:20:42 +00:00
} else {
r . requestLogger . Print ( "unknown ua: " , c . SanitiseSingleLine ( ua ) )
2018-02-03 05:47:14 +00:00
}
} else {
2020-03-08 04:15:27 +00:00
//co.AgentViewCounter.Bump(agentMapEnum[agent])
co . AgentViewCounter . Bump ( agent )
2018-01-10 03:32:48 +00:00
}
2020-02-28 05:47:43 +00:00
co . OSViewCounter . Bump ( os )
2018-01-09 07:39:29 +00:00
}
2018-02-05 10:29:13 +00:00
2018-03-08 03:59:47 +00:00
// TODO: Do we want to track missing language headers too? Maybe as it's own type, e.g. "noheader"?
2020-03-08 04:15:27 +00:00
// TODO: Default to anything other than en, if anything else is present, to avoid over-representing it for multi-linguals?
2018-03-08 03:59:47 +00:00
lang := req . Header . Get ( "Accept-Language" )
if lang != "" {
2020-03-27 06:05:35 +00:00
// TODO: Reduce allocs here
2020-02-26 10:34:38 +00:00
lLang := strings . Split ( strings . TrimSpace ( lang ) , "-" )
2019-02-28 07:28:17 +00:00
tLang := strings . Split ( strings . Split ( lLang [ 0 ] , ";" ) [ 0 ] , "," )
2019-04-19 07:16:09 +00:00
c . DebugDetail ( "tLang:" , tLang )
2019-02-28 07:28:17 +00:00
var llLang string
for _ , seg := range tLang {
if seg == "*" {
continue
}
llLang = seg
2019-03-03 02:28:17 +00:00
break
2019-02-28 07:28:17 +00:00
}
2019-04-19 07:16:09 +00:00
c . DebugDetail ( "llLang:" , llLang )
2020-03-08 04:15:27 +00:00
if ! co . LangViewCounter . Bump ( llLang ) {
2020-02-25 04:25:50 +00:00
r . DumpRequest ( req , "Invalid ISO Code" )
2019-02-23 06:29:19 +00:00
}
2018-03-17 08:16:43 +00:00
} else {
2020-03-08 04:15:27 +00:00
co . LangViewCounter . Bump2 ( 0 )
2018-03-08 03:59:47 +00:00
}
2019-08-14 10:39:04 +00:00
if ! c . Config . RefNoTrack {
2019-10-29 07:13:04 +00:00
ref := req . Header . Get ( "Referer" ) // Check the 'referrer' header too? :P
if ref != "" {
2019-08-14 10:39:04 +00:00
// ? Optimise this a little?
2019-10-29 07:13:04 +00:00
ref = strings . TrimPrefix ( strings . TrimPrefix ( ref , "http://" ) , "https://" )
ref = strings . Split ( ref , "/" ) [ 0 ]
portless := strings . Split ( ref , ":" ) [ 0 ]
2020-02-26 10:34:38 +00:00
// TODO: Handle c.Site.Host in uppercase too?
2019-08-14 10:39:04 +00:00
if portless != "localhost" && portless != "127.0.0.1" && portless != c . Site . Host {
2019-10-29 07:13:04 +00:00
co . ReferrerTracker . Bump ( ref )
2019-08-14 10:39:04 +00:00
}
2018-02-05 10:29:13 +00:00
}
}
2020-02-26 10:34:38 +00:00
}
2017-07-17 10:23:42 +00:00
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
// Deal with the session stuff, etc.
2020-03-18 09:21:34 +00:00
ucpy , ok := c . PreRoute ( w , req )
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
if ! ok {
return
}
2020-03-18 09:21:34 +00:00
user := & ucpy
2019-04-02 07:43:11 +00:00
user . LastAgent = agent
2019-04-19 07:16:09 +00:00
if c . Dev . SuperDebug {
2018-11-13 06:51:34 +00:00
r . requestLogger . Print (
2018-04-03 04:34:07 +00:00
"after PreRoute\n" +
"routeMapEnum: " , routeMapEnum )
2017-07-17 10:23:42 +00:00
}
2020-03-27 06:05:35 +00:00
//log.Println("req: ", req)
2018-08-11 15:53:42 +00:00
2018-08-21 08:00:35 +00:00
// Disable Gzip when SSL is disabled for security reasons?
2018-08-22 02:13:17 +00:00
if prefix != "/ws" && strings . Contains ( req . Header . Get ( "Accept-Encoding" ) , "gzip" ) {
2019-04-27 10:22:39 +00:00
h := w . Header ( )
h . Set ( "Content-Encoding" , "gzip" )
gzw := c . GzipResponseWriter { Writer : gzip . NewWriter ( w ) , ResponseWriter : w }
2018-08-22 07:10:29 +00:00
defer func ( ) {
2020-03-27 06:05:35 +00:00
//h := w.Header()
2019-04-27 10:22:39 +00:00
if h . Get ( "Content-Encoding" ) == "gzip" && h . Get ( "X-I" ) == "" {
2020-03-27 06:05:35 +00:00
//log.Print("push gzip close")
2019-04-27 10:22:39 +00:00
gzw . Writer . ( * gzip . Writer ) . Close ( )
2018-08-22 07:10:29 +00:00
}
} ( )
2019-04-27 10:22:39 +00:00
w = gzw
2018-08-21 08:00:35 +00:00
}
2018-11-12 09:23:36 +00:00
2020-03-27 06:05:35 +00:00
skip , ferr = hTbl . VhookSkippable ( "router_pre_route" , w , req , user , prefix )
if skip || ferr != nil {
r . handleError ( ferr , w , req , user )
return
}
2020-03-22 23:14:08 +00:00
var extraData string
if req . URL . Path [ len ( req . URL . Path ) - 1 ] != '/' {
extraData = req . URL . Path [ strings . LastIndexByte ( req . URL . Path , '/' ) + 1 : ]
req . URL . Path = req . URL . Path [ : strings . LastIndexByte ( req . URL . Path , '/' ) + 1 ]
}
2019-04-06 01:08:49 +00:00
ferr = r . routeSwitch ( w , req , user , prefix , extraData )
2018-11-12 09:23:36 +00:00
if ferr != nil {
2018-11-13 06:51:34 +00:00
r . handleError ( ferr , w , req , user )
2020-03-27 06:05:35 +00:00
return
2018-11-12 09:23:36 +00:00
}
2020-02-26 10:34:38 +00:00
/ * if ! c . Config . DisableAnalytics {
co . RouteViewCounter . Bump ( id )
} * /
2019-04-06 01:08:49 +00:00
hTbl . VhookNoRet ( "router_end" , w , req , user , prefix , extraData )
2019-04-19 07:16:09 +00:00
//c.StoppedServer("Profile end")
2018-08-11 15:53:42 +00:00
}
2017-07-17 10:23:42 +00:00
2020-03-18 09:21:34 +00:00
func ( r * GenRouter ) routeSwitch ( w http . ResponseWriter , req * http . Request , user * c . User , prefix , extraData string ) /*(id int, orerr */ c . RouteError /*)*/ {
2019-04-19 07:16:09 +00:00
var err c . RouteError
2020-02-29 01:10:39 +00:00
cn := uutils . Nanotime ( )
2017-04-13 09:26:40 +00:00
switch ( prefix ) { ` + out + `
2017-12-24 07:38:46 +00:00
/ * case "/sitemaps" : // TODO: Count these views
req . URL . Path += extraData
2018-08-22 02:29:11 +00:00
err = sitemapSwitch ( w , req ) * /
2020-03-13 06:37:18 +00:00
// ! Temporary fix for certain bots
case "/static" :
w . Header ( ) . Set ( "Connection" , "close" )
http . Redirect ( w , req , "/s/" + extraData , http . StatusTemporaryRedirect )
2018-08-22 02:13:17 +00:00
case "/uploads" :
if extraData == "" {
2020-03-07 05:28:25 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.UploadedFile" } } , cn )
2019-04-19 07:16:09 +00:00
return c . NotFound ( w , req , nil )
2018-08-22 02:13:17 +00:00
}
2019-04-19 07:16:09 +00:00
gzw , ok := w . ( c . GzipResponseWriter )
2018-08-22 02:13:17 +00:00
if ok {
w = gzw . ResponseWriter
2019-07-23 10:34:44 +00:00
h := w . Header ( )
h . Del ( "Content-Encoding" )
2018-08-22 02:13:17 +00:00
}
req . URL . Path += extraData
// TODO: Find a way to propagate errors up from this?
2018-11-13 06:51:34 +00:00
r . UploadHandler ( w , req ) // TODO: Count these views
2020-03-07 05:28:25 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.UploadedFile" } } , cn )
2018-11-12 09:23:36 +00:00
return nil
2017-04-13 09:26:40 +00:00
case "" :
2017-08-06 15:22:18 +00:00
// Stop the favicons, robots.txt file, etc. resolving to the topics list
2017-09-10 16:57:22 +00:00
// TODO: Add support for favicons and robots.txt files
2017-12-19 03:53:13 +00:00
switch ( extraData ) {
2017-08-06 15:22:18 +00:00
case "robots.txt" :
2020-03-07 05:28:25 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.RobotsTxt" } } , cn )
2018-11-12 09:23:36 +00:00
return routes . RobotsTxt ( w , req )
2019-02-28 07:28:17 +00:00
case "favicon.ico" :
2019-07-23 10:34:44 +00:00
gzw , ok := w . ( c . GzipResponseWriter )
if ok {
w = gzw . ResponseWriter
h := w . Header ( )
h . Del ( "Content-Encoding" )
}
2019-08-14 10:39:04 +00:00
req . URL . Path = "/s/favicon.ico"
2019-02-28 07:28:17 +00:00
routes . StaticFile ( w , req )
2020-03-04 23:56:45 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.Favicon" } } , cn )
2019-02-28 07:28:17 +00:00
return nil
2019-05-08 05:08:38 +00:00
case "opensearch.xml" :
2020-03-07 05:28:25 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.OpenSearchXml" } } , cn )
2019-05-08 05:08:38 +00:00
return routes . OpenSearchXml ( w , req )
2017-12-24 07:38:46 +00:00
/ * case "sitemap.xml" :
2020-03-07 05:28:25 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.SitemapXml" } } , cn )
2018-11-12 09:23:36 +00:00
return routes . SitemapXml ( w , req ) * /
2017-08-06 15:22:18 +00:00
}
2020-02-26 10:34:38 +00:00
co . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.Error" } } )
2019-04-19 07:16:09 +00:00
return c . NotFound ( w , req , nil )
2017-10-30 09:57:08 +00:00
default :
2018-11-13 06:51:34 +00:00
// A fallback for dynamic routes, e.g. ones declared by plugins
r . RLock ( )
2020-02-26 10:34:38 +00:00
h , ok := r . extraRoutes [ req . URL . Path ]
2018-11-13 06:51:34 +00:00
r . RUnlock ( )
2020-03-27 12:00:29 +00:00
req . URL . Path += extraData
2017-10-30 09:57:08 +00:00
if ok {
2020-02-26 10:34:38 +00:00
// TODO: Be more specific about *which* dynamic route it is
co . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.DynamicRoute" } } )
return h ( w , req , user )
2017-10-30 09:57:08 +00:00
}
2020-03-27 12:00:29 +00:00
co . RouteViewCounter . Bump3 ( { { index . AllRouteMap "routes.BadRoute" } } , cn )
2018-01-26 05:53:34 +00:00
2020-02-25 04:25:50 +00:00
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" ) {
2018-11-13 06:51:34 +00:00
r . SuspiciousRequest ( req , "Bad Route" )
2020-03-27 12:00:29 +00:00
return c . MicroNotFound ( w , req )
2018-01-27 07:30:44 +00:00
}
2020-03-27 12:00:29 +00:00
r . DumpRequest ( req , "Bad Route" )
2019-04-19 07:16:09 +00:00
return c . NotFound ( w , req , nil )
2017-04-12 13:39:03 +00:00
}
2018-11-12 09:23:36 +00:00
return err
2017-04-12 10:10:36 +00:00
}
`
2019-10-20 01:42:19 +00:00
tmpl := template . Must ( template . New ( "router" ) . Parse ( fileData ) )
2017-12-19 03:53:13 +00:00
var b bytes . Buffer
2019-10-20 01:42:19 +00:00
if err := tmpl . Execute ( & b , tmplVars ) ; err != nil {
2017-12-19 03:53:13 +00:00
log . Fatal ( err )
}
writeFile ( "./gen_router.go" , string ( b . Bytes ( ) ) )
2017-08-13 11:22:34 +00:00
log . Println ( "Successfully generated the router" )
2017-04-12 10:10:36 +00:00
}
2020-02-25 04:25:50 +00:00
func writeFile ( name , content string ) {
2017-04-12 10:10:36 +00:00
f , err := os . Create ( name )
if err != nil {
log . Fatal ( err )
}
_ , err = f . WriteString ( content )
if err != nil {
log . Fatal ( err )
}
2020-02-25 04:25:50 +00:00
err = f . Sync ( )
if err != nil {
log . Fatal ( err )
}
2020-02-26 10:34:38 +00:00
err = f . Close ( )
if err != nil {
log . Fatal ( err )
}
2017-04-12 10:10:36 +00:00
}