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"
"text/template"
2017-12-10 03:43:30 +00:00
)
2017-09-10 16:57:22 +00:00
2017-10-31 07:26:44 +00:00
var routeList [ ] * RouteImpl
2017-10-30 09:57:08 +00:00
var routeGroups [ ] * RouteGroup
2017-04-12 10:10:36 +00:00
2017-12-19 03:53:13 +00:00
type TmplVars struct {
RouteList [ ] * RouteImpl
RouteGroups [ ] * RouteGroup
AllRouteNames [ ] string
AllRouteMap map [ string ] int
2018-01-09 07:39:29 +00:00
AllAgentNames [ ] string
AllAgentMap map [ string ] int
2018-02-04 08:15:20 +00:00
AllOSNames [ ] string
AllOSMap map [ string ] int
2017-12-19 03:53:13 +00:00
}
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...
routes ( )
2017-09-10 16:57:22 +00:00
2017-12-19 03:53:13 +00:00
var tmplVars = TmplVars {
RouteList : routeList ,
RouteGroups : routeGroups ,
}
var allRouteNames [ ] string
var allRouteMap = make ( map [ string ] int )
var out string
2017-12-10 03:43:30 +00:00
var mapIt = func ( name string ) {
2017-12-19 03:53:13 +00:00
allRouteNames = append ( allRouteNames , name )
allRouteMap [ name ] = len ( allRouteNames ) - 1
2017-12-10 03:43:30 +00:00
}
var countToIndents = func ( indent int ) ( indentor string ) {
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
}
var runBefore = func ( runnables [ ] Runnable , indent int ) ( out string ) {
var indentor = countToIndents ( indent )
if len ( runnables ) > 0 {
for _ , runnable := range runnables {
2017-11-05 09:55:34 +00:00
if runnable . Literal {
2017-12-10 03:43:30 +00:00
out += "\n\t" + indentor + runnable . Contents
2017-11-05 09:55:34 +00:00
} else {
2017-12-10 03:43:30 +00:00
out += "\n" + indentor + "err = common." + runnable . Contents + "(w,req,user)\n" +
indentor + "if err != nil {\n" +
indentor + "\trouter.handleError(err,w,req,user)\n" +
indentor + "\treturn\n" +
indentor + "}\n" + indentor
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
}
for _ , route := range routeList {
2017-12-19 03:53:13 +00:00
mapIt ( route . Name )
2017-12-10 03:43:30 +00:00
var end = len ( route . Path ) - 1
out += "\n\t\tcase \"" + route . Path [ 0 : end ] + "\":"
out += runBefore ( route . RunBefore , 4 )
2018-02-19 04:26:01 +00:00
out += "\n\t\t\tcounters.RouteViewCounter.Bump(" + strconv . Itoa ( allRouteMap [ route . Name ] ) + ")"
2017-10-30 09:57:08 +00:00
out += "\n\t\t\terr = " + route . Name + "(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 += ` ) `
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
for _ , group := range routeGroups {
2017-11-12 07:18:25 +00:00
var 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) {"
2017-10-31 07:26:44 +00:00
var 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 + "\":"
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 += `
2017-11-11 04:06:16 +00:00
err = common . ` + runnable.Contents + ` ( w , req , user )
2017-11-05 09:55:34 +00:00
if err != nil {
router . handleError ( err , w , req , user )
return
}
`
}
}
2017-04-13 09:26:40 +00:00
}
2018-02-19 04:26:01 +00:00
out += "\n\t\t\t\t\tcounters.RouteViewCounter.Bump(" + strconv . Itoa ( allRouteMap [ route . Name ] ) + ")"
2017-10-30 09:57:08 +00:00
out += "\n\t\t\t\t\terr = " + route . Name + "(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 += ")"
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:"
2017-12-10 03:43:30 +00:00
out += runBefore ( defaultRoute . RunBefore , 4 )
2018-02-19 04:26:01 +00:00
out += "\n\t\t\t\t\tcounters.RouteViewCounter.Bump(" + strconv . Itoa ( allRouteMap [ defaultRoute . Name ] ) + ")"
2017-10-30 09:57:08 +00:00
out += "\n\t\t\t\t\terr = " + defaultRoute . Name + "(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 += ")"
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" )
2018-05-15 05:59:52 +00:00
mapIt ( "routes.BadRoute" )
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" ,
"baidu" ,
"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" ,
2018-02-03 05:47:14 +00:00
"cloudflare" ,
2018-01-25 04:57:33 +00:00
"uptimebot" ,
2018-03-08 03:59:47 +00:00
"slackbot" ,
2018-02-04 08:15:20 +00:00
"discourse" ,
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" ,
2018-02-03 05:47:14 +00:00
"zgrab" ,
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-07-13 11:27:58 +00:00
var 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"
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-08-21 08:00:35 +00:00
"io"
2018-04-03 04:34:07 +00:00
"os"
2017-11-11 04:06:16 +00:00
"net/http"
"./common"
2018-02-19 04:26:01 +00:00
"./common/counters"
2018-01-18 12:31:25 +00:00
"./routes"
2018-05-27 09:36:35 +00:00
"./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 } }
"{{.}}" : { { . } } , { { end } }
}
// ! NEVER RELY ON THESE REMAINING THE SAME BETWEEN COMMITS
var routeMapEnum = map [ string ] int { { { range $ index , $ element := . AllRouteNames } }
"{{$element}}" : { { $ index } } , { { end } }
}
var reverseRouteMapEnum = map [ int ] string { { { range $ index , $ element := . AllRouteNames } }
{ { $ index } } : "{{$element}}" , { { end } }
}
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-02-03 05:47:14 +00:00
var markToAgent = map [ string ] string {
"OPR" : "opera" ,
"Chrome" : "chrome" ,
"Firefox" : "firefox" ,
"MSIE" : "internetexplorer" ,
2018-02-04 08:15:20 +00:00
"Trident" : "trident" , // Hack to support IE11
2018-02-03 05:47:14 +00:00
"Edge" : "edge" ,
"Lynx" : "lynx" , // There's a rare android variant of lynx which isn't covered by this
2018-02-04 08:15:20 +00:00
"SamsungBrowser" : "samsung" ,
2018-02-03 05:47:14 +00:00
"UCBrowser" : "ucbrowser" ,
"Google" : "googlebot" ,
"Googlebot" : "googlebot" ,
"yandex" : "yandex" , // from the URL
"DuckDuckBot" : "duckduckgo" ,
"Baiduspider" : "baidu" ,
"bingbot" : "bing" ,
"BingPreview" : "bing" ,
2018-02-04 08:15:20 +00:00
"SeznamBot" : "seznambot" ,
2018-02-03 05:47:14 +00:00
"CloudFlare" : "cloudflare" , // Track alwayson specifically in case there are other bots?
"Uptimebot" : "uptimebot" ,
2018-03-08 03:59:47 +00:00
"Slackbot" : "slackbot" ,
2018-02-03 05:47:14 +00:00
"Discordbot" : "discord" ,
2018-02-04 08:15:20 +00:00
"Twitterbot" : "twitter" ,
"Discourse" : "discourse" ,
2018-02-03 05:47:14 +00:00
"zgrab" : "zgrab" ,
}
/ * 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 ( ) {
2018-02-19 04:26:01 +00:00
counters . SetRouteMapEnum ( routeMapEnum )
counters . SetReverseRouteMapEnum ( reverseRouteMapEnum )
counters . SetAgentMapEnum ( agentMapEnum )
counters . SetReverseAgentMapEnum ( reverseAgentMapEnum )
counters . SetOSMapEnum ( osMapEnum )
counters . SetReverseOSMapEnum ( reverseOSMapEnum )
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-21 08:00:35 +00:00
type gzipResponseWriter struct {
io . Writer
http . ResponseWriter
}
func ( w gzipResponseWriter ) Write ( b [ ] byte ) ( int , error ) {
return w . Writer . Write ( b )
}
2018-03-31 05:25:27 +00:00
type WriterIntercept struct {
w http . ResponseWriter
code int
}
func NewWriterIntercept ( w http . ResponseWriter ) * WriterIntercept {
return & WriterIntercept { w : w , code : 200 }
}
func ( writ * WriterIntercept ) Header ( ) http . Header {
return writ . w . Header ( )
}
func ( writ * WriterIntercept ) Write ( pieces [ ] byte ) ( int , error ) {
return writ . w . Write ( pieces )
}
func ( writ * WriterIntercept ) WriteHeader ( code int ) {
writ . w . WriteHeader ( code )
writ . code = code
}
func ( writ * WriterIntercept ) GetCode ( ) int {
return writ . code
}
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 )
2017-12-19 03:53:13 +00:00
extraRoutes map [ string ] func ( http . ResponseWriter , * http . Request , common . User ) common . 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 ) {
f , err := os . OpenFile ( "./logs/requests.log" , os . O_WRONLY | os . O_APPEND | os . O_CREATE , 0755 )
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 ) {
writ := NewWriterIntercept ( w )
http . StripPrefix ( "/uploads/" , uploads ) . ServeHTTP ( writ , req )
if writ . GetCode ( ) == 200 {
2018-05-14 08:56:56 +00:00
w . Header ( ) . Set ( "Cache-Control" , "max-age=" + strconv . Itoa ( int ( common . Day ) ) )
2018-03-31 05:25:27 +00:00
w . Header ( ) . Set ( "Vary" , "Accept-Encoding" )
}
} ,
2017-12-19 03:53:13 +00:00
extraRoutes : make ( map [ string ] func ( http . ResponseWriter , * http . Request , common . User ) common . RouteError ) ,
2018-04-03 04:34:07 +00:00
requestLogger : log . New ( f , "" , log . LstdFlags ) ,
} , nil
2017-04-12 10:10:36 +00:00
}
2017-11-11 04:06:16 +00:00
func ( router * GenRouter ) handleError ( err common . RouteError , w http . ResponseWriter , r * http . Request , user common . User ) {
2017-10-30 09:57:08 +00:00
if err . Handled ( ) {
return
}
if err . Type ( ) == "system" {
2017-11-11 04:06:16 +00:00
common . InternalErrorJSQ ( err , w , r , err . JSON ( ) )
2017-10-30 09:57:08 +00:00
return
}
2017-11-11 04:06:16 +00:00
common . LocalErrorJSQ ( err . Error ( ) , w , r , user , err . JSON ( ) )
2017-10-30 09:57:08 +00:00
}
2017-04-13 09:26:40 +00:00
func ( router * GenRouter ) Handle ( _ string , _ http . Handler ) {
2017-04-12 10:10:36 +00:00
}
2017-11-11 04:06:16 +00:00
func ( router * GenRouter ) HandleFunc ( pattern string , handle func ( http . ResponseWriter , * http . Request , common . User ) common . RouteError ) {
2017-04-12 13:39:03 +00:00
router . Lock ( )
2017-12-10 03:43:30 +00:00
defer router . Unlock ( )
2017-12-19 03:53:13 +00:00
router . extraRoutes [ pattern ] = handle
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
}
func ( router * GenRouter ) RemoveFunc ( pattern string ) error {
router . Lock ( )
2017-12-10 03:43:30 +00:00
defer router . Unlock ( )
2017-12-19 03:53:13 +00:00
_ , ok := router . 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
}
2017-12-19 03:53:13 +00:00
delete ( router . 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
}
2018-03-08 03:59:47 +00:00
func ( router * GenRouter ) DumpRequest ( req * http . Request , prepend 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 {
2018-05-31 06:51:31 +00:00
heads += "Header '" + common . SanitiseSingleLine ( key ) + "': " + common . SanitiseSingleLine ( vvalue ) + "!!\n"
2018-01-27 07:30:44 +00:00
}
}
2018-02-26 09:07:00 +00:00
2018-04-03 04:34:07 +00:00
router . requestLogger . Print ( prepend +
2018-05-31 06:51:31 +00:00
"\nUA: " + common . SanitiseSingleLine ( req . UserAgent ( ) ) + "\n" +
"Method: " + common . SanitiseSingleLine ( req . Method ) + "\n" + heads +
"req.Host: " + common . SanitiseSingleLine ( req . Host ) + "\n" +
"req.URL.Path: " + common . SanitiseSingleLine ( req . URL . Path ) + "\n" +
"req.URL.RawQuery: " + common . SanitiseSingleLine ( req . URL . RawQuery ) + "\n" +
"req.Referer(): " + common . SanitiseSingleLine ( req . Referer ( ) ) + "\n" +
2018-02-26 09:07:00 +00:00
"req.RemoteAddr: " + req . RemoteAddr + "\n" )
2018-01-27 07:30:44 +00:00
}
2018-04-03 04:34:07 +00:00
func ( router * GenRouter ) SuspiciousRequest ( req * http . Request , prepend string ) {
if prepend != "" {
prepend += "\n"
}
router . DumpRequest ( req , prepend + "Suspicious Request" )
2018-02-19 04:26:01 +00:00
counters . AgentViewCounter . Bump ( { { . AllAgentMap . suspicious } } )
2018-01-27 07:30:44 +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
2017-04-12 10:10:36 +00:00
func ( router * GenRouter ) ServeHTTP ( w http . ResponseWriter , req * http . Request ) {
2018-01-28 14:30:24 +00:00
// Redirect www. requests to the right place
if req . Host == "www." + common . Site . Host {
w . Header ( ) . Set ( "Connection" , "close" )
var s string
if common . Site . EnableSsl {
s = "s"
}
dest := "http" + s + "://" + req . Host + req . URL . Path
if len ( req . URL . RawQuery ) > 0 {
dest += "?" + req . URL . RawQuery
}
http . Redirect ( w , req , dest , http . StatusMovedPermanently )
return
}
// Deflect malformed requests
2018-01-25 04:57:33 +00:00
if len ( req . URL . Path ) == 0 || req . URL . Path [ 0 ] != '/' || req . Host != common . Site . Host {
2018-01-27 07:30:44 +00:00
w . WriteHeader ( 200 ) // 400
2017-04-12 13:39:03 +00:00
w . Write ( [ ] byte ( "" ) )
2018-03-08 03:59:47 +00:00
router . DumpRequest ( req , "Malformed Request" )
2018-02-19 04:26:01 +00:00
counters . AgentViewCounter . Bump ( { { . AllAgentMap . malformed } } )
2017-04-12 13:39:03 +00:00
return
}
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
2018-03-08 03:59:47 +00:00
for _ , char := range req . URL . Path {
if char != '&' && ! ( char > 44 && char < 58 ) && char != '=' && char != '?' && ! ( char > 64 && char < 91 ) && char != '\\' && char != '_' && ! ( char > 96 && char < 123 ) {
2018-06-24 13:49:29 +00:00
router . SuspiciousRequest ( req , "Bad char 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
}
lowerPath := strings . ToLower ( req . URL . Path )
// TODO: Flag any requests which has a dot with anything but a number after that
if strings . Contains ( req . URL . Path , ".." ) || strings . Contains ( req . URL . Path , "--" ) || strings . Contains ( lowerPath , ".php" ) || strings . Contains ( lowerPath , ".asp" ) || strings . Contains ( lowerPath , ".cgi" ) || strings . Contains ( lowerPath , ".py" ) || strings . Contains ( lowerPath , ".sql" ) || strings . Contains ( lowerPath , ".action" ) {
2018-06-24 13:49:29 +00:00
router . 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 == "/" {
req . URL . Path = common . Config . DefaultPath
}
2018-01-18 12:51:35 +00:00
var prefix , extraData string
prefix = req . URL . Path [ 0 : strings . IndexByte ( req . URL . Path [ 1 : ] , '/' ) + 1 ]
if req . URL . Path [ len ( req . URL . Path ) - 1 ] != '/' {
2017-12-19 03:53:13 +00:00
extraData = req . URL . Path [ strings . LastIndexByte ( req . URL . Path , '/' ) + 1 : ]
2017-04-12 10:10:36 +00:00
req . URL . Path = req . URL . Path [ : strings . LastIndexByte ( req . URL . Path , '/' ) + 1 ]
2017-04-13 09:26:40 +00:00
}
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
// TODO: Set the content policy header
h . Set ( "X-Content-Type-Options" , "nosniff" )
}
2017-08-06 15:22:18 +00:00
2017-11-11 04:06:16 +00:00
if common . Dev . SuperDebug {
2018-03-08 03:59:47 +00:00
router . 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
counters . 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
if prefix == "/static" {
2018-02-19 04:26:01 +00:00
counters . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.StaticFile" } } )
2017-12-19 03:53:13 +00:00
req . URL . Path += extraData
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
}
2018-07-15 10:29:31 +00:00
if atomic . LoadInt32 ( & common . IsDBDown ) == 1 {
common . DatabaseError ( w , req )
return
}
2017-11-11 04:06:16 +00:00
if common . Dev . SuperDebug {
2018-04-03 04:34:07 +00:00
router . requestLogger . Print ( "before PreRoute" )
2017-07-17 10:23:42 +00:00
}
2017-12-10 03:43:30 +00:00
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
2018-02-03 05:47:14 +00:00
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
if ua == "" {
2018-02-19 04:26:01 +00:00
counters . AgentViewCounter . Bump ( { { . AllAgentMap . blank } } )
2018-01-11 09:29:25 +00:00
if common . Dev . DebugMode {
2018-03-08 03:59:47 +00:00
var prepend string
for _ , char := range req . UserAgent ( ) {
prepend += strconv . Itoa ( int ( char ) ) + " "
}
router . DumpRequest ( req , "Blank UA: " + prepend )
2018-01-11 09:29:25 +00:00
}
2018-02-03 05:47:14 +00:00
} else {
2018-02-04 08:15:20 +00:00
var runeEquals = func ( a [ ] rune , b [ ] rune ) bool {
if len ( a ) != len ( b ) {
return false
}
for i , item := range a {
if item != b [ i ] {
return false
}
}
return true
}
2018-02-03 05:47:14 +00:00
// WIP UA Parser
var indices [ ] int
var items [ ] string
var buffer [ ] rune
for index , item := range ua {
if ( item > 64 && item < 91 ) || ( item > 96 && item < 123 ) {
buffer = append ( buffer , item )
2018-02-04 09:33:04 +00:00
} else if item == ' ' || item == '(' || item == ')' || item == '-' || ( item > 47 && item < 58 ) || item == '_' || item == ';' || item == '.' || item == '+' || ( item == ':' && ( runeEquals ( buffer , [ ] rune ( "http" ) ) || runeEquals ( buffer , [ ] rune ( "rv" ) ) ) ) || item == ',' || item == '/' {
2018-02-04 08:15:20 +00:00
if len ( buffer ) != 0 {
items = append ( items , string ( buffer ) )
indices = append ( indices , index - 1 )
buffer = buffer [ : 0 ]
}
} else {
// TODO: Test this
items = items [ : 0 ]
indices = indices [ : 0 ]
2018-06-24 13:49:29 +00:00
router . SuspiciousRequest ( req , "Illegal char in UA" )
2018-04-03 04:34:07 +00:00
router . requestLogger . Print ( "UA Buffer: " , buffer )
router . requestLogger . Print ( "UA Buffer 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
var agent string
for i := len ( items ) - 1 ; i >= 0 ; i -- {
fAgent , ok := markToAgent [ items [ i ] ]
if ok {
agent = fAgent
if agent != "safari" {
break
}
}
}
2018-02-04 08:15:20 +00:00
if common . Dev . SuperDebug {
2018-04-03 04:34:07 +00:00
router . requestLogger . Print ( "parsed agent: " , agent )
2018-02-04 08:15:20 +00:00
}
2018-02-03 05:47:14 +00:00
2018-02-04 08:15:20 +00:00
var os string
for _ , mark := range items {
switch ( mark ) {
case "Windows" :
os = "windows"
case "Linux" :
os = "linux"
case "Mac" :
os = "mac"
case "iPhone" :
os = "iphone"
case "Android" :
os = "android"
}
}
if os == "" {
os = "unknown"
}
if common . Dev . SuperDebug {
2018-04-03 04:34:07 +00:00
router . requestLogger . Print ( "os: " , os )
router . requestLogger . Printf ( "items: %+v\n" , items )
2018-02-03 05:47:14 +00:00
}
// Special handling
switch ( agent ) {
case "chrome" :
2018-02-04 08:15:20 +00:00
if os == "android" {
agent = "androidchrome"
}
case "safari" :
if os == "iphone" {
agent = "mobilesafari"
}
case "trident" :
// Hack to support IE11, change this after we start logging versions
if strings . Contains ( ua , "rv:11" ) {
agent = "internetexplorer"
2018-02-03 05:47:14 +00:00
}
case "zgrab" :
2018-04-03 04:34:07 +00:00
router . SuspiciousRequest ( req , "Vulnerability Scanner" )
2018-02-03 05:47:14 +00:00
}
if agent == "" {
2018-02-19 04:26:01 +00:00
counters . AgentViewCounter . Bump ( { { . AllAgentMap . unknown } } )
2018-02-03 05:47:14 +00:00
if common . Dev . DebugMode {
2018-03-08 03:59:47 +00:00
var prepend string
for _ , char := range req . UserAgent ( ) {
prepend += strconv . Itoa ( int ( char ) ) + " "
}
router . DumpRequest ( req , "Blank UA: " + prepend )
2018-02-03 05:47:14 +00:00
}
} else {
2018-02-19 04:26:01 +00:00
counters . AgentViewCounter . Bump ( agentMapEnum [ agent ] )
2018-01-10 03:32:48 +00:00
}
2018-02-19 04:26:01 +00:00
counters . OSViewCounter . Bump ( osMapEnum [ 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"?
lang := req . Header . Get ( "Accept-Language" )
if lang != "" {
lang = strings . TrimSpace ( lang )
lLang := strings . Split ( lang , "-" )
common . DebugDetail ( "lLang:" , lLang )
counters . LangViewCounter . Bump ( lLang [ 0 ] )
2018-03-17 08:16:43 +00:00
} else {
counters . LangViewCounter . Bump ( "none" )
2018-03-08 03:59:47 +00:00
}
2018-02-05 10:29:13 +00:00
referrer := req . Header . Get ( "Referer" ) // Check the 'referrer' header too? :P
if referrer != "" {
// ? Optimise this a little?
referrer = strings . TrimPrefix ( strings . TrimPrefix ( referrer , "http://" ) , "https://" )
referrer = strings . Split ( referrer , "/" ) [ 0 ]
portless := strings . Split ( referrer , ":" ) [ 0 ]
if portless != "localhost" && portless != "127.0.0.1" && portless != common . Site . Host {
2018-02-19 04:26:01 +00:00
counters . ReferrerTracker . Bump ( referrer )
2018-02-05 10:29:13 +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.
2017-11-11 04:06:16 +00:00
user , ok := common . 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
}
2017-11-11 04:06:16 +00:00
if common . Dev . SuperDebug {
2018-04-03 04:34:07 +00:00
router . requestLogger . Print (
"after PreRoute\n" +
"routeMapEnum: " , routeMapEnum )
2017-07-17 10:23:42 +00:00
}
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" ) {
2018-08-21 08:00:35 +00:00
w . Header ( ) . Set ( "Content-Encoding" , "gzip" )
2018-08-22 11:02:50 +00:00
w . Header ( ) . Set ( "Content-Type" , "text/html; charset=utf-8" )
2018-08-21 08:00:35 +00:00
gz := gzip . NewWriter ( w )
2018-08-22 07:10:29 +00:00
defer func ( ) {
if w . Header ( ) . Get ( "Content-Encoding" ) == "gzip" {
gz . Close ( )
}
} ( )
2018-08-21 08:00:35 +00:00
w = gzipResponseWriter { Writer : gz , ResponseWriter : w }
}
2018-08-11 15:53:42 +00:00
router . routeSwitch ( w , req , user , prefix , extraData )
}
2017-07-17 10:23:42 +00:00
2018-08-11 15:53:42 +00:00
func ( router * GenRouter ) routeSwitch ( w http . ResponseWriter , req * http . Request , user common . User , prefix string , extraData string ) {
2017-11-11 04:06:16 +00:00
var err common . RouteError
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 ) * /
2018-08-22 02:13:17 +00:00
case "/uploads" :
if extraData == "" {
common . NotFound ( w , req , nil )
return
}
gzw , ok := w . ( gzipResponseWriter )
if ok {
w = gzw . ResponseWriter
w . Header ( ) . Del ( "Content-Type" )
w . Header ( ) . Del ( "Content-Encoding" )
}
counters . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.UploadedFile" } } )
req . URL . Path += extraData
// TODO: Find a way to propagate errors up from this?
router . UploadHandler ( w , req ) // TODO: Count these views
2018-08-22 02:29:11 +00:00
return
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" :
2018-03-17 08:16:43 +00:00
counters . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.RobotsTxt" } } )
err = routes . RobotsTxt ( w , req )
2017-10-30 09:57:08 +00:00
if err != nil {
router . handleError ( err , w , req , user )
}
2017-08-06 15:22:18 +00:00
return
2017-12-24 07:38:46 +00:00
/ * case "sitemap.xml" :
2018-03-17 08:16:43 +00:00
counters . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.SitemapXml" } } )
err = routes . SitemapXml ( w , req )
2017-12-24 07:38:46 +00:00
if err != nil {
router . handleError ( err , w , req , user )
}
return * /
2017-08-06 15:22:18 +00:00
}
2018-06-17 07:28:18 +00:00
common . NotFound ( w , req , nil )
return
2017-10-30 09:57:08 +00:00
default :
// A fallback for the routes which haven't been converted to the new router yet or plugins
router . RLock ( )
2017-12-19 03:53:13 +00:00
handle , ok := router . extraRoutes [ req . URL . Path ]
2017-10-30 09:57:08 +00:00
router . RUnlock ( )
if ok {
2018-05-15 05:59:52 +00:00
counters . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.DynamicRoute" } } ) // TODO: Be more specific about *which* dynamic route it is
2017-12-19 03:53:13 +00:00
req . URL . Path += extraData
2017-12-24 22:08:35 +00:00
err = handle ( w , req , user )
2017-10-30 09:57:08 +00:00
if err != nil {
router . handleError ( err , w , req , user )
}
return
}
2018-01-26 05:53:34 +00:00
2018-01-27 07:30:44 +00:00
lowerPath := strings . ToLower ( req . URL . Path )
2018-02-04 08:15:20 +00:00
if strings . Contains ( lowerPath , "admin" ) || strings . Contains ( lowerPath , "sql" ) || strings . Contains ( lowerPath , "manage" ) || strings . Contains ( lowerPath , "//" ) || strings . Contains ( lowerPath , "\\\\" ) || strings . Contains ( lowerPath , "wp" ) || strings . Contains ( lowerPath , "wordpress" ) || strings . Contains ( lowerPath , "config" ) || strings . Contains ( lowerPath , "setup" ) || strings . Contains ( lowerPath , "install" ) || strings . Contains ( lowerPath , "update" ) || strings . Contains ( lowerPath , "php" ) {
2018-04-03 04:34:07 +00:00
router . SuspiciousRequest ( req , "Bad Route" )
} else {
router . DumpRequest ( req , "Bad Route" )
2018-01-27 07:30:44 +00:00
}
2018-05-15 05:59:52 +00:00
counters . RouteViewCounter . Bump ( { { index . AllRouteMap "routes.BadRoute" } } )
2018-02-19 04:26:01 +00:00
common . NotFound ( w , req , nil )
2018-08-22 02:29:11 +00:00
return
}
if err != nil {
router . handleError ( err , w , req , user )
2017-04-12 13:39:03 +00:00
}
2017-04-12 10:10:36 +00:00
}
`
2017-12-19 03:53:13 +00:00
var tmpl = template . Must ( template . New ( "router" ) . Parse ( fileData ) )
var b bytes . Buffer
err := tmpl . Execute ( & b , tmplVars )
if err != nil {
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
}
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
func writeFile ( name string , 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 )
}
f . Sync ( )
f . Close ( )
}