2017-11-10 03:33:11 +00:00
package common
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-02-10 15:07:21 +00:00
import (
2022-02-21 03:53:13 +00:00
"fmt"
"log"
"net/http"
"runtime/debug"
"strings"
"sync"
"sync/atomic"
2022-02-21 03:32:53 +00:00
2022-02-21 03:53:13 +00:00
p "git.tuxpa.in/a/gosora/common/phrases"
2018-02-10 15:07:21 +00:00
)
2016-12-02 07:38:54 +00:00
2018-05-31 06:51:31 +00:00
type ErrorItem struct {
2022-02-21 03:32:53 +00:00
error
Stack [ ] byte
2018-05-31 06:51:31 +00:00
}
// ! The errorBuffer uses o(n) memory, we should probably do something about that
// TODO: Use the errorBuffer variable to construct the system log in the Control Panel. Should we log errors caused by users too? Or just collect statistics on those or do nothing? Intercept recover()? Could we intercept the logger instead here? We might get too much information, if we intercept the logger, maybe make it part of the Debug page?
2018-04-22 12:33:56 +00:00
// ? - Should we pass Header / HeaderLite rather than forcing the errors to pull the global Header instance?
2017-09-03 04:50:31 +00:00
var errorBufferMutex sync . RWMutex
2021-04-28 08:39:08 +00:00
//var errorBuffer []ErrorItem
var ErrorCountSinceStartup int64
2017-09-03 04:50:31 +00:00
2017-09-18 17:03:52 +00:00
//var notfoundCountPerSecond int
//var nopermsCountPerSecond int
2017-01-17 07:55:46 +00:00
2017-11-10 03:33:11 +00:00
// A blank list to fill out that parameter in Page for routes which don't use it
var tList [ ] interface { }
2017-10-30 09:57:08 +00:00
// WIP, a new system to propagate errors up from routes
type RouteError interface {
2022-02-21 03:32:53 +00:00
Type ( ) string
Error ( ) string
Cause ( ) string
JSON ( ) bool
Handled ( ) bool
2018-11-13 06:51:34 +00:00
2022-02-21 03:32:53 +00:00
Wrap ( string )
2017-10-30 09:57:08 +00:00
}
type RouteErrorImpl struct {
2022-02-21 03:32:53 +00:00
userText string
sysText string
system bool
json bool
handled bool
2017-10-30 09:57:08 +00:00
}
func ( err * RouteErrorImpl ) Type ( ) string {
2022-02-21 03:32:53 +00:00
// System errors may contain sensitive information we don't want the user to see
if err . system {
return "system"
}
return "user"
2017-10-30 09:57:08 +00:00
}
func ( err * RouteErrorImpl ) Error ( ) string {
2022-02-21 03:32:53 +00:00
return err . userText
2018-11-13 06:51:34 +00:00
}
func ( err * RouteErrorImpl ) Cause ( ) string {
2022-02-21 03:32:53 +00:00
if err . sysText == "" {
return err . Error ( )
}
return err . sysText
2017-10-30 09:57:08 +00:00
}
// Respond with JSON?
2017-11-11 04:06:16 +00:00
func ( err * RouteErrorImpl ) JSON ( ) bool {
2022-02-21 03:32:53 +00:00
return err . json
2017-10-30 09:57:08 +00:00
}
// Has this error been dealt with elsewhere?
func ( err * RouteErrorImpl ) Handled ( ) bool {
2022-02-21 03:32:53 +00:00
return err . handled
2017-10-30 09:57:08 +00:00
}
2018-11-13 06:51:34 +00:00
// Move the current error into the system error slot and add a new one to the user error slot to show the user
func ( err * RouteErrorImpl ) Wrap ( userErr string ) {
2022-02-21 03:32:53 +00:00
err . sysText = err . userText
err . userText = userErr
2018-11-13 06:51:34 +00:00
}
2017-10-30 09:57:08 +00:00
func HandledRouteError ( ) RouteError {
2022-02-21 03:32:53 +00:00
return & RouteErrorImpl { "" , "" , false , false , true }
2018-11-13 06:51:34 +00:00
}
func Error ( errmsg string ) RouteError {
2022-02-21 03:32:53 +00:00
return & RouteErrorImpl { errmsg , "" , false , false , false }
2018-11-13 06:51:34 +00:00
}
func FromError ( err error ) RouteError {
2022-02-21 03:32:53 +00:00
return & RouteErrorImpl { err . Error ( ) , "" , false , false , false }
2018-11-13 06:51:34 +00:00
}
2019-09-29 05:10:05 +00:00
func ErrorJSQ ( errmsg string , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
return & RouteErrorImpl { errmsg , "" , false , js , false }
2018-11-13 06:51:34 +00:00
}
func SysError ( errmsg string ) RouteError {
2022-02-21 03:32:53 +00:00
return & RouteErrorImpl { errmsg , errmsg , true , false , false }
2017-10-30 09:57:08 +00:00
}
2017-10-21 00:27:47 +00:00
// LogError logs internal handler errors which can't be handled with InternalError() as a wrapper for log.Fatal(), we might do more with it in the future.
2018-07-13 11:27:58 +00:00
// TODO: Clean-up extra as a way of passing additional context
func LogError ( err error , extra ... string ) {
2022-02-21 03:32:53 +00:00
LogWarning ( err , extra ... )
ErrLogger . Fatal ( "" )
2017-10-21 00:27:47 +00:00
}
2018-07-13 11:27:58 +00:00
func LogWarning ( err error , extra ... string ) {
2022-02-21 03:32:53 +00:00
var esb strings . Builder
for _ , extraBit := range extra {
esb . WriteString ( extraBit )
esb . WriteRune ( 10 )
}
if err == nil {
esb . WriteString ( "nil error found" )
} else {
esb . WriteString ( err . Error ( ) )
}
esb . WriteRune ( 10 )
errmsg := esb . String ( )
errorBufferMutex . Lock ( )
defer errorBufferMutex . Unlock ( )
stack := debug . Stack ( ) // debug.Stack() can't be executed concurrently, so we'll guard this with a mutex too
Err ( errmsg , string ( stack ) )
//errorBuffer = append(errorBuffer, ErrorItem{err, stack})
atomic . AddInt64 ( & ErrorCountSinceStartup , 1 )
2017-06-25 09:56:39 +00:00
}
2021-04-28 08:39:08 +00:00
func errorHeader ( w http . ResponseWriter , u * User , title string ) * Header {
2022-02-21 03:32:53 +00:00
h := DefaultHeader ( w , u )
h . Title = title
h . Zone = "error"
return h
2018-06-06 00:21:22 +00:00
}
2017-10-30 09:57:08 +00:00
// TODO: Dump the request?
2017-09-03 04:50:31 +00:00
// InternalError is the main function for handling internal errors, while simultaneously printing out a page for the end-user to let them know that *something* has gone wrong
2017-09-22 02:21:17 +00:00
// ? - Add a user parameter?
2019-04-18 01:00:39 +00:00
// ! Do not call CustomError here or we might get an error loop
2017-10-30 09:57:08 +00:00
func InternalError ( err error , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
pi := ErrorPage { errorHeader ( w , & GuestUser , p . GetErrorPhrase ( "internal_error_title" ) ) , p . GetErrorPhrase ( "internal_error_body" ) }
handleErrorTemplate ( w , r , pi , 500 )
LogError ( err )
return HandledRouteError ( )
2016-12-02 07:38:54 +00:00
}
2017-09-03 04:50:31 +00:00
// InternalErrorJSQ is the JSON "maybe" version of InternalError which can handle both JSON and normal requests
2017-09-22 02:21:17 +00:00
// ? - Add a user parameter?
2019-09-29 05:10:05 +00:00
func InternalErrorJSQ ( err error , w http . ResponseWriter , r * http . Request , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return InternalError ( err , w , r )
}
return InternalErrorJS ( err , w , r )
2016-12-02 07:38:54 +00:00
}
2017-09-03 04:50:31 +00:00
// InternalErrorJS is the JSON version of InternalError on routes we know will only be requested via JSON. E.g. An API.
2017-09-22 02:21:17 +00:00
// ? - Add a user parameter?
2017-10-30 09:57:08 +00:00
func InternalErrorJS ( err error , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 500 )
writeJsonError ( p . GetErrorPhrase ( "internal_error_body" ) , w )
LogError ( err )
return HandledRouteError ( )
2017-02-28 09:27:28 +00:00
}
2019-01-21 12:27:59 +00:00
// When the task system detects if the database is down, some database errors might slip by this
2018-07-15 10:29:31 +00:00
func DatabaseError ( w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
pi := ErrorPage { errorHeader ( w , & GuestUser , p . GetErrorPhrase ( "internal_error_title" ) ) , p . GetErrorPhrase ( "internal_error_body" ) }
handleErrorTemplate ( w , r , pi , 500 )
return HandledRouteError ( )
2018-07-15 10:29:31 +00:00
}
2017-12-26 07:17:26 +00:00
func InternalErrorXML ( err error , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . Header ( ) . Set ( "Content-Type" , "application/xml" )
w . WriteHeader ( 500 )
w . Write ( [ ] byte ( ` < ? xml version = "1.0" encoding = "UTF-8" ? >
2021-04-28 08:39:08 +00:00
< error > ` + p.GetErrorPhrase("internal_error_body") + ` < / error > ` ) )
2022-02-21 03:32:53 +00:00
LogError ( err )
return HandledRouteError ( )
2017-12-26 07:17:26 +00:00
}
// TODO: Stop killing the instance upon hitting an error with InternalError* and deprecate this
func SilentInternalErrorXML ( err error , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . Header ( ) . Set ( "Content-Type" , "application/xml" )
w . WriteHeader ( 500 )
w . Write ( [ ] byte ( ` < ? xml version = "1.0" encoding = "UTF-8" ? >
2021-04-28 08:39:08 +00:00
< error > ` + p.GetErrorPhrase("internal_error_body") + ` < / error > ` ) )
2022-02-21 03:32:53 +00:00
log . Print ( "InternalError: " , err )
return HandledRouteError ( )
2017-12-26 07:17:26 +00:00
}
2019-04-18 01:00:39 +00:00
// ! Do not call CustomError here otherwise we might get an error loop
2017-10-30 09:57:08 +00:00
func PreError ( errmsg string , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
pi := ErrorPage { errorHeader ( w , & GuestUser , p . GetErrorPhrase ( "error_title" ) ) , errmsg }
handleErrorTemplate ( w , r , pi , 500 )
return HandledRouteError ( )
2016-12-02 07:38:54 +00:00
}
2017-10-30 09:57:08 +00:00
func PreErrorJS ( errmsg string , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 500 )
writeJsonError ( errmsg , w )
return HandledRouteError ( )
2017-08-18 12:16:56 +00:00
}
2019-09-29 05:10:05 +00:00
func PreErrorJSQ ( errmsg string , w http . ResponseWriter , r * http . Request , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return PreError ( errmsg , w , r )
}
return PreErrorJS ( errmsg , w , r )
2017-02-05 16:36:54 +00:00
}
2017-09-18 17:03:52 +00:00
// LocalError is an error shown to the end-user when something goes wrong and it's not the software's fault
2018-06-06 00:21:22 +00:00
// TODO: Pass header in for this and similar errors instead of having to pass in both user and w? Would also allow for more stateful things, although this could be a problem
2020-03-18 09:21:34 +00:00
/ * func LocalError ( errmsg string , w http . ResponseWriter , r * http . Request , user * User ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 500 )
pi := ErrorPage { errorHeader ( w , user , p . GetErrorPhrase ( "local_error_title" ) ) , errmsg }
handleErrorTemplate ( w , r , pi )
return HandledRouteError ( )
2019-07-28 04:58:01 +00:00
} * /
2021-04-28 08:39:08 +00:00
func LocalError ( errmsg string , w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
return SimpleError ( errmsg , w , r , errorHeader ( w , u , "" ) )
2019-07-28 04:58:01 +00:00
}
2021-04-28 08:39:08 +00:00
func LocalErrorf ( errmsg string , w http . ResponseWriter , r * http . Request , u * User , params ... interface { } ) RouteError {
2022-02-21 03:32:53 +00:00
return LocalError ( fmt . Sprintf ( errmsg , params ) , w , r , u )
2021-04-07 02:10:05 +00:00
}
2020-03-18 09:21:34 +00:00
func SimpleError ( errmsg string , w http . ResponseWriter , r * http . Request , h * Header ) RouteError {
2022-02-21 03:32:53 +00:00
if h == nil {
h = errorHeader ( w , & GuestUser , p . GetErrorPhrase ( "local_error_title" ) )
} else {
h . Title = p . GetErrorPhrase ( "local_error_title" )
}
pi := ErrorPage { h , errmsg }
handleErrorTemplate ( w , r , pi , 500 )
return HandledRouteError ( )
2017-09-18 17:03:52 +00:00
}
2021-04-28 08:39:08 +00:00
func LocalErrorJSQ ( errmsg string , w http . ResponseWriter , r * http . Request , u * User , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return SimpleError ( errmsg , w , r , errorHeader ( w , u , "" ) )
}
return LocalErrorJS ( errmsg , w , r )
2016-12-02 07:38:54 +00:00
}
2017-10-30 09:57:08 +00:00
func LocalErrorJS ( errmsg string , w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 500 )
writeJsonError ( errmsg , w )
return HandledRouteError ( )
2017-02-28 09:27:28 +00:00
}
2017-10-30 09:57:08 +00:00
// TODO: We might want to centralise the error logic in the future and just return what the error handler needs to construct the response rather than handling it here
2017-09-18 17:03:52 +00:00
// NoPermissions is an error shown to the end-user when they try to access an area which they aren't authorised to access
2020-03-27 03:41:28 +00:00
func NoPermissions ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
pi := ErrorPage { errorHeader ( w , u , p . GetErrorPhrase ( "no_permissions_title" ) ) , p . GetErrorPhrase ( "no_permissions_body" ) }
handleErrorTemplate ( w , r , pi , 403 )
return HandledRouteError ( )
2016-12-03 10:25:39 +00:00
}
2021-04-28 08:39:08 +00:00
func NoPermissionsJSQ ( w http . ResponseWriter , r * http . Request , u * User , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return NoPermissions ( w , r , u )
}
return NoPermissionsJS ( w , r , u )
2016-12-04 10:44:28 +00:00
}
2021-04-28 08:39:08 +00:00
func NoPermissionsJS ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 403 )
writeJsonError ( p . GetErrorPhrase ( "no_permissions_body" ) , w )
return HandledRouteError ( )
2017-09-22 02:21:17 +00:00
}
2017-09-18 17:03:52 +00:00
// ? - Is this actually used? Should it be used? A ban in Gosora should be more of a permission revocation to stop them posting rather than something which spits up an error page, right?
2021-04-28 08:39:08 +00:00
func Banned ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
pi := ErrorPage { errorHeader ( w , u , p . GetErrorPhrase ( "banned_title" ) ) , p . GetErrorPhrase ( "banned_body" ) }
handleErrorTemplate ( w , r , pi , 403 )
return HandledRouteError ( )
2016-12-04 10:44:28 +00:00
}
2017-09-03 04:50:31 +00:00
// nolint
2017-09-18 17:03:52 +00:00
// BannedJSQ is the version of the banned error page which handles both JavaScript requests and normal page loads
2020-03-18 09:21:34 +00:00
func BannedJSQ ( w http . ResponseWriter , r * http . Request , user * User , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return Banned ( w , r , user )
}
return BannedJS ( w , r , user )
2016-12-02 07:38:54 +00:00
}
2021-04-28 08:39:08 +00:00
func BannedJS ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 403 )
writeJsonError ( p . GetErrorPhrase ( "banned_body" ) , w )
return HandledRouteError ( )
2017-09-22 02:21:17 +00:00
}
2017-09-03 04:50:31 +00:00
// nolint
2021-04-28 08:39:08 +00:00
func LoginRequiredJSQ ( w http . ResponseWriter , r * http . Request , u * User , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return LoginRequired ( w , r , u )
}
return LoginRequiredJS ( w , r , u )
2017-11-11 04:06:16 +00:00
}
// ? - Where is this used? Should we use it more?
// LoginRequired is an error shown to the end-user when they try to access an area which requires them to login
2021-04-28 08:39:08 +00:00
func LoginRequired ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
return CustomError ( p . GetErrorPhrase ( "login_required_body" ) , 401 , p . GetErrorPhrase ( "no_permissions_title" ) , w , r , nil , u )
2017-11-11 04:06:16 +00:00
}
// nolint
2021-04-28 08:39:08 +00:00
func LoginRequiredJS ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 401 )
writeJsonError ( p . GetErrorPhrase ( "login_required_body" ) , w )
return HandledRouteError ( )
2016-12-02 07:38:54 +00:00
}
2017-09-22 02:21:17 +00:00
// SecurityError is used whenever a session mismatch is found
// ? - Should we add JS and JSQ versions of this?
2021-04-28 08:39:08 +00:00
func SecurityError ( w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
pi := ErrorPage { errorHeader ( w , u , p . GetErrorPhrase ( "security_error_title" ) ) , p . GetErrorPhrase ( "security_error_body" ) }
w . Header ( ) . Set ( "Content-Type" , "text/html;charset=utf-8" )
w . WriteHeader ( 403 )
e := RenderTemplateAlias ( "error" , "security_error" , w , r , pi . Header , pi )
if e != nil {
LogError ( e )
}
return HandledRouteError ( )
2016-12-06 10:26:48 +00:00
}
2021-04-28 08:39:08 +00:00
var microNotFoundBytes = [ ] byte ( "file not found" )
2019-02-28 07:28:17 +00:00
func MicroNotFound ( w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . Header ( ) . Set ( "Content-Type" , "text/html;charset=utf-8" )
w . WriteHeader ( 404 )
_ , _ = w . Write ( microNotFoundBytes )
return HandledRouteError ( )
2019-02-28 07:28:17 +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
// NotFound is used when the requested page doesn't exist
2018-12-27 05:42:41 +00:00
// ? - Add a JSQ version of this?
2017-09-22 02:21:17 +00:00
// ? - Add a user parameter?
2020-03-18 09:21:34 +00:00
func NotFound ( w http . ResponseWriter , r * http . Request , h * Header ) RouteError {
2022-02-21 03:32:53 +00:00
return CustomError ( p . GetErrorPhrase ( "not_found_body" ) , 404 , p . GetErrorPhrase ( "not_found_title" ) , w , r , h , & GuestUser )
2016-12-06 10:26:48 +00:00
}
2018-12-27 05:42:41 +00:00
// ? - Add a user parameter?
func NotFoundJS ( w http . ResponseWriter , r * http . Request ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( 404 )
writeJsonError ( p . GetErrorPhrase ( "not_found_body" ) , w )
return HandledRouteError ( )
2018-12-27 05:42:41 +00:00
}
2020-03-18 09:21:34 +00:00
func NotFoundJSQ ( w http . ResponseWriter , r * http . Request , h * Header , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if js {
return NotFoundJS ( w , r )
}
if h == nil {
h = DefaultHeader ( w , & GuestUser )
}
return NotFound ( w , r , h )
2018-12-27 05:42:41 +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
// CustomError lets us make custom error types which aren't covered by the generic functions above
2020-03-27 03:41:28 +00:00
func CustomError ( errmsg string , errcode int , errtitle string , w http . ResponseWriter , r * http . Request , h * Header , u * User ) ( rerr RouteError ) {
2022-02-21 03:32:53 +00:00
if h == nil {
h , rerr = UserCheck ( w , r , u )
if rerr != nil {
h = errorHeader ( w , u , errtitle )
}
}
h . Title = errtitle
h . Zone = "error"
pi := ErrorPage { h , errmsg }
handleErrorTemplate ( w , r , pi , errcode )
return HandledRouteError ( )
2017-01-03 07:47:31 +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
// CustomErrorJSQ is a version of CustomError which lets us handle both JSON and regular pages depending on how it's being accessed
2021-04-28 08:39:08 +00:00
func CustomErrorJSQ ( errmsg string , errcode int , errtitle string , w http . ResponseWriter , r * http . Request , h * Header , u * User , js bool ) RouteError {
2022-02-21 03:32:53 +00:00
if ! js {
return CustomError ( errmsg , errcode , errtitle , w , r , h , u )
}
return CustomErrorJS ( errmsg , errcode , w , r , u )
2016-12-02 07:38:54 +00:00
}
2017-09-22 02:21:17 +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
// CustomErrorJS is the pure JSON version of CustomError
2020-03-27 03:41:28 +00:00
func CustomErrorJS ( errmsg string , errcode int , w http . ResponseWriter , r * http . Request , u * User ) RouteError {
2022-02-21 03:32:53 +00:00
w . WriteHeader ( errcode )
writeJsonError ( errmsg , w )
return HandledRouteError ( )
2017-09-22 02:21:17 +00:00
}
2017-12-01 02:04:29 +00:00
2018-06-17 07:28:18 +00:00
// TODO: Should we optimise this by caching these json strings?
func writeJsonError ( errmsg string , w http . ResponseWriter ) {
2022-02-21 03:32:53 +00:00
_ , _ = w . Write ( [ ] byte ( ` { "errmsg":" ` + strings . Replace ( errmsg , "\"" , "" , - 1 ) + ` "} ` ) )
2018-06-17 07:28:18 +00:00
}
2020-03-27 03:41:28 +00:00
func handleErrorTemplate ( w http . ResponseWriter , r * http . Request , pi ErrorPage , errcode int ) {
2022-02-21 03:32:53 +00:00
w . Header ( ) . Set ( "Content-Type" , "text/html;charset=utf-8" )
w . WriteHeader ( errcode )
err := RenderTemplateAlias ( "error" , "error" , w , r , pi . Header , pi )
if err != nil {
LogError ( err )
}
2017-12-01 02:04:29 +00:00
}
2019-04-19 09:34:16 +00:00
// Alias of routes.renderTemplate
2020-03-18 09:21:34 +00:00
var RenderTemplateAlias func ( tmplName , hookName string , w http . ResponseWriter , r * http . Request , h * Header , pi interface { } ) error