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
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 )
2017-12-19 03:53:13 +00:00
out += "\n\t\t\tcommon.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
}
2017-10-30 09:57:08 +00:00
out += ` )
if err != nil {
router . handleError ( err , w , req , user )
} `
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
}
2017-12-19 03:53:13 +00:00
out += "\n\t\t\t\t\tcommon.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 )
2017-12-19 03:53:13 +00:00
out += "\n\t\t\t\t\tcommon.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 += `
}
if err != nil {
router . handleError ( err , w , req , user )
} `
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
mapIt ( "routeDynamic" )
mapIt ( "routeUploads" )
2018-01-26 05:53:34 +00:00
mapIt ( "BadRoute" )
2017-12-19 03:53:13 +00:00
tmplVars . AllRouteNames = allRouteNames
tmplVars . AllRouteMap = allRouteMap
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-01-09 07:39:29 +00:00
"googlebot" ,
"yandex" ,
"bing" ,
"baidu" ,
"duckduckgo" ,
2018-01-11 08:03:17 +00:00
"discord" ,
2018-01-15 08:24:18 +00:00
"cloudflarealwayson" ,
2018-01-25 04:57:33 +00:00
"uptimebot" ,
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-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
2017-12-10 03:43:30 +00:00
var fileData = ` // Code generated by. DO NOT EDIT.
/* 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"
"sync"
"errors"
"net/http"
"./common"
2018-01-18 12:31:25 +00:00
"./routes"
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-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 } }
}
2017-12-19 03:53:13 +00:00
// TODO: Stop spilling these into the package scope?
func init ( ) {
common . SetRouteMapEnum ( routeMapEnum )
common . SetReverseRouteMapEnum ( reverseRouteMapEnum )
2018-01-09 07:39:29 +00:00
common . SetAgentMapEnum ( agentMapEnum )
common . SetReverseAgentMapEnum ( reverseAgentMapEnum )
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
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
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
}
2017-04-13 09:26:40 +00:00
func NewGenRouter ( uploads http . Handler ) * GenRouter {
2017-04-12 13:39:03 +00:00
return & GenRouter {
2017-04-13 09:26:40 +00:00
UploadHandler : http . StripPrefix ( "/uploads/" , uploads ) . ServeHTTP ,
2017-12-19 03:53:13 +00:00
extraRoutes : make ( map [ string ] func ( http . ResponseWriter , * http . Request , common . User ) common . RouteError ) ,
2017-04-12 13:39:03 +00:00
}
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-01-27 07:30:44 +00:00
func ( router * GenRouter ) DumpRequest ( req * http . Request ) {
log . Print ( "UA: " , req . UserAgent ( ) )
log . Print ( "Method: " , req . Method )
for key , value := range req . Header {
for _ , vvalue := range value {
log . Print ( "Header '" + key + "': " + vvalue + "!!" )
}
}
log . Print ( "req.Host: " , req . Host )
log . Print ( "req.URL.Path: " , req . URL . Path )
log . Print ( "req.URL.RawQuery: " , req . URL . RawQuery )
log . Print ( "req.Referer(): " , req . Referer ( ) )
log . Print ( "req.RemoteAddr: " , req . RemoteAddr )
}
func ( router * GenRouter ) SuspiciousRequest ( req * http . Request ) {
log . Print ( "Supicious Request" )
router . DumpRequest ( req )
common . AgentViewCounter . Bump ( { { . AllAgentMap . suspicious } } )
}
2017-12-22 03:32:23 +00:00
// TODO: Pass the default route or config struct to the router rather than accessing it via a package global
// TODO: SetDefaultRoute
// TODO: GetDefaultRoute
2017-04-12 10:10:36 +00:00
func ( router * GenRouter ) ServeHTTP ( w http . ResponseWriter , req * http . Request ) {
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-01-25 04:57:33 +00:00
log . Print ( "Malformed Request" )
2018-01-27 07:30:44 +00:00
router . DumpRequest ( req )
2018-01-25 04:57:33 +00:00
common . AgentViewCounter . Bump ( { { . AllAgentMap . malformed } } )
2017-04-12 13:39:03 +00:00
return
}
2018-01-18 12:51:35 +00:00
2018-01-20 06:50:29 +00:00
if common . Dev . DebugMode {
// TODO: Cover more suspicious strings and at a lower layer than this
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-01-27 07:30:44 +00:00
router . SuspiciousRequest ( req )
2018-01-20 06:50:29 +00:00
break
}
}
2018-01-27 07:30:44 +00:00
lowerPath := strings . ToLower ( req . URL . Path )
2018-01-26 05:53:34 +00:00
// TODO: Flag any requests which has a dot with anything but a number after that
2018-01-27 07:30:44 +00:00
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" ) {
router . SuspiciousRequest ( req )
2018-01-17 11:13:08 +00:00
}
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
}
2017-08-06 15:22:18 +00:00
2017-11-11 04:06:16 +00:00
if common . Dev . SuperDebug {
2017-09-11 10:24:03 +00:00
log . Print ( "before routeStatic" )
2018-01-12 10:22:28 +00:00
log . Print ( "Method: " , req . Method )
for key , value := range req . Header {
for _ , vvalue := range value {
log . Print ( "Header '" + key + "': " + vvalue + "!!" )
}
}
2017-09-10 16:57:22 +00:00
log . Print ( "prefix: " , prefix )
2018-01-25 04:57:33 +00:00
log . Print ( "req.Host: " , req . Host )
2017-09-10 16:57:22 +00:00
log . Print ( "req.URL.Path: " , req . URL . Path )
2018-01-20 06:50:29 +00:00
log . Print ( "req.URL.RawQuery: " , req . URL . RawQuery )
2017-12-19 03:53:13 +00:00
log . Print ( "extraData: " , extraData )
2017-09-10 16:57:22 +00:00
log . Print ( "req.Referer(): " , req . Referer ( ) )
2018-01-14 12:03:20 +00:00
log . Print ( "req.RemoteAddr: " , req . RemoteAddr )
2017-08-06 15:22:18 +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
if prefix == "/static" {
2017-12-19 03:53:13 +00:00
req . URL . Path += extraData
2017-11-11 04:06:16 +00:00
routeStatic ( 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
}
2017-11-11 04:06:16 +00:00
if common . Dev . SuperDebug {
2017-08-13 11:22:34 +00:00
log . Print ( "before PreRoute" )
2017-07-17 10:23:42 +00:00
}
2017-12-10 03:43:30 +00:00
// Increment the global view counter
common . GlobalViewCounter . Bump ( )
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-01-11 08:03:17 +00:00
ua := strings . TrimSpace ( strings . TrimSuffix ( strings . TrimPrefix ( req . UserAgent ( ) , "Mozilla/5.0 " ) , " Safari/537.36" ) ) // Noise, no one's going to be running this and it complicates implementing an efficient UA parser, particularly the more efficient right-to-left one I have in mind
2018-01-09 07:39:29 +00:00
switch {
case strings . Contains ( ua , "Google" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . googlebot } } )
2018-01-09 08:46:16 +00:00
case strings . Contains ( ua , "Yandex" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . yandex } } )
case strings . Contains ( ua , "bingbot" ) , strings . Contains ( ua , "BingPreview" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . bing } } )
2018-01-09 07:39:29 +00:00
case strings . Contains ( ua , "OPR" ) : // Pretends to be Chrome, needs to run before that
common . AgentViewCounter . Bump ( { { . AllAgentMap . opera } } )
2018-01-09 10:37:14 +00:00
case strings . Contains ( ua , "Edge" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . edge } } )
2018-01-09 07:39:29 +00:00
case strings . Contains ( ua , "Chrome" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . chrome } } )
case strings . Contains ( ua , "Firefox" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . firefox } } )
case strings . Contains ( ua , "Safari" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . safari } } )
2018-01-09 08:46:16 +00:00
case strings . Contains ( ua , "MSIE" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . internetexplorer } } )
case strings . Contains ( ua , "Baiduspider" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . baidu } } )
2018-01-09 10:37:14 +00:00
case strings . Contains ( ua , "DuckDuckBot" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . duckduckgo } } )
2018-01-11 08:03:17 +00:00
case strings . Contains ( ua , "Discordbot" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . discord } } )
case strings . Contains ( ua , "Lynx" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . lynx } } )
2018-01-15 08:24:18 +00:00
case strings . Contains ( ua , "CloudFlare-AlwaysOnline" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . cloudflarealwayson } } )
2018-01-25 04:57:33 +00:00
case strings . Contains ( ua , "Uptimebot" ) :
common . AgentViewCounter . Bump ( { { . AllAgentMap . uptimebot } } )
2018-01-11 08:03:17 +00:00
case ua == "" :
common . AgentViewCounter . Bump ( { { . AllAgentMap . blank } } )
2018-01-11 09:29:25 +00:00
if common . Dev . DebugMode {
2018-01-12 10:22:28 +00:00
log . Print ( "Blank UA: " , req . UserAgent ( ) )
2018-01-27 07:30:44 +00:00
router . DumpRequest ( req )
2018-01-11 09:29:25 +00:00
}
2018-01-09 07:39:29 +00:00
default :
common . AgentViewCounter . Bump ( { { . AllAgentMap . unknown } } )
2018-01-10 03:32:48 +00:00
if common . Dev . DebugMode {
2018-01-10 04:35:34 +00:00
log . Print ( "Unknown UA: " , req . UserAgent ( ) )
2018-01-27 07:30:44 +00:00
router . DumpRequest ( req )
2018-01-10 03:32:48 +00:00
}
2018-01-09 07:39:29 +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 {
2017-08-13 11:22:34 +00:00
log . Print ( "after PreRoute" )
2017-12-19 03:53:13 +00:00
log . Print ( "routeMapEnum: " , routeMapEnum )
2017-07-17 10:23:42 +00:00
}
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
err = sitemapSwitch ( w , req )
if err != nil {
router . handleError ( err , w , req , user )
} * /
2017-04-13 09:26:40 +00:00
case "/uploads" :
2017-12-19 03:53:13 +00:00
if extraData == "" {
2017-11-11 04:06:16 +00:00
common . NotFound ( w , req )
2017-04-13 09:26:40 +00:00
return
}
2017-12-24 22:08:35 +00:00
common . RouteViewCounter . Bump ( { { . AllRouteMap . routeUploads } } )
2017-12-19 03:53:13 +00:00
req . URL . Path += extraData
2017-10-30 09:57:08 +00:00
// TODO: Find a way to propagate errors up from this?
2017-12-19 03:53:13 +00:00
router . UploadHandler ( w , req ) // TODO: Count these views
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" :
2017-12-19 03:53:13 +00:00
err = routeRobotsTxt ( w , req ) // TODO: Count these views
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" :
err = routeSitemapXml ( w , req ) // TODO: Count these views
if err != nil {
router . handleError ( err , w , req , user )
}
return * /
2017-08-06 15:22:18 +00:00
}
2017-12-19 03:53:13 +00:00
if extraData != "" {
2017-11-11 04:06:16 +00:00
common . NotFound ( w , req )
2017-08-06 15:22:18 +00:00
return
}
2017-12-22 03:32:23 +00:00
handle , ok := RouteMap [ common . Config . DefaultRoute ]
if ! ok {
// TODO: Make this a startup error not a runtime one
log . Print ( "Unable to find the default route" )
common . NotFound ( w , req )
return
}
common . RouteViewCounter . Bump ( routeMapEnum [ common . Config . DefaultRoute ] )
handle . ( func ( http . ResponseWriter , * http . Request , common . User ) common . RouteError ) ( w , req , user )
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 {
2017-12-24 22:08:35 +00:00
common . RouteViewCounter . Bump ( { { . AllRouteMap . routeDynamic } } ) // 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 )
if strings . Contains ( lowerPath , "admin" ) || strings . Contains ( lowerPath , "sql" ) || strings . Contains ( lowerPath , "manage" ) {
router . SuspiciousRequest ( req )
}
2018-01-26 05:53:34 +00:00
common . RouteViewCounter . Bump ( { { . AllRouteMap . BadRoute } } )
common . NotFound ( w , req )
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 ( )
}