2017-09-13 15:09:13 +00:00
/ *
*
* Gosora Main File
* Copyright Azareal 2016 - 2018
*
* /
2016-12-02 07:38:54 +00:00
package main
import (
2017-05-07 08:31:41 +00:00
"fmt"
2016-12-17 03:39:53 +00:00
"io"
2017-09-03 04:50:31 +00:00
"log"
"net/http"
2017-08-13 11:22:34 +00:00
"os"
2017-09-03 04:50:31 +00:00
"time"
2017-01-17 07:55:46 +00:00
//"runtime/pprof"
2016-12-02 07:38:54 +00:00
)
2017-09-03 04:50:31 +00:00
var version = Version { Major : 0 , Minor : 1 , Patch : 0 , Tag : "dev" }
2017-05-07 08:31:41 +00:00
2016-12-02 07:38:54 +00:00
const hour int = 60 * 60
const day int = hour * 24
2017-08-27 09:33:45 +00:00
const week int = day * 7
2016-12-02 07:38:54 +00:00
const month int = day * 30
const year int = day * 365
2016-12-02 15:03:31 +00:00
const kilobyte int = 1024
2017-04-12 10:10:36 +00:00
const megabyte int = kilobyte * 1024
2017-05-07 08:31:41 +00:00
const gigabyte int = megabyte * 1024
const terabyte int = gigabyte * 1024
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
const petabyte int = terabyte * 1024
2016-12-02 07:38:54 +00:00
const saltLength int = 32
const sessionLength int = 80
2017-09-03 04:50:31 +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 router * GenRouter
2017-06-05 11:57:27 +00:00
var startTime time . Time
2017-09-11 00:56:09 +00:00
// ? - Make this more customisable?
2017-09-03 04:50:31 +00:00
var externalSites = map [ string ] string {
"YT" : "https://www.youtube.com/" ,
2017-08-06 15:22:18 +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
type StringList [ ] string
// ? - Should we allow users to upload .php or .go files? It could cause security issues. We could store them with a mangled extension to render them inert
// TODO: Let admins manage this from the Control Panel
var allowedFileExts = StringList {
2017-10-12 03:24:14 +00:00
"png" , "jpg" , "jpeg" , "svg" , "bmp" , "gif" , "tif" , "webp" , "apng" , // images
2017-10-30 09:57:08 +00:00
"txt" , "xml" , "json" , "yaml" , "toml" , "ini" , "md" , "html" , "rtf" , "js" , "py" , "rb" , "css" , "scss" , "less" , "eqcss" , "pcss" , "java" , "ts" , "cs" , "c" , "cc" , "cpp" , "cxx" , "C" , "c++" , "h" , "hh" , "hpp" , "hxx" , "h++" , "rs" , "rlib" , "htaccess" , "gitignore" , // text
2017-10-12 03:24:14 +00:00
"mp3" , "mp4" , "avi" , "wmv" , "webm" , // video
"otf" , "woff2" , "woff" , "ttf" , "eot" , // fonts
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
}
var imageFileExts = StringList {
2017-10-12 03:24:14 +00:00
"png" , "jpg" , "jpeg" , "svg" , "bmp" , "gif" , "tif" , "webp" , "apng" ,
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
}
2017-10-21 00:27:47 +00:00
var archiveFileExts = StringList {
"bz2" , "zip" , "gz" , "7z" , "tar" , "cab" ,
}
var executableFileExts = StringList {
"exe" , "jar" , "phar" , "shar" , "iso" ,
}
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
// TODO: Write a test for this
func ( slice StringList ) Contains ( needle string ) bool {
for _ , item := range slice {
if item == needle {
return true
}
}
return false
}
2017-09-03 04:50:31 +00:00
var staticFiles = make ( map [ string ] SFile )
var logWriter = io . MultiWriter ( os . Stderr )
2017-01-01 15:45:43 +00:00
2017-11-05 09:55:34 +00:00
// TODO: Wrap the globals in here so we can pass pointers to them to subpackages
var globs * Globs
type Globs struct {
stmts * Stmts
}
2017-09-03 04:50:31 +00:00
func main ( ) {
2017-10-21 00:27:47 +00:00
// TODO: Recover from panics
/ * defer func ( ) {
r := recover ( )
if r != nil {
log . Print ( r )
debug . PrintStack ( )
return
}
} ( ) * /
2017-09-10 16:57:22 +00:00
// TODO: Have a file for each run with the time/date the server started as the file name?
// TODO: Log panics with recover()
2017-09-03 04:50:31 +00:00
f , err := os . OpenFile ( "./operations.log" , os . O_WRONLY | os . O_APPEND | os . O_CREATE , 0755 )
2017-08-13 11:22:34 +00:00
if err != nil {
log . Fatal ( err )
}
2017-09-03 04:50:31 +00:00
logWriter = io . MultiWriter ( os . Stderr , f )
2017-08-13 11:22:34 +00:00
log . SetOutput ( logWriter )
2017-01-17 07:55:46 +00:00
//if profiling {
// f, err := os.Create("startup_cpu.prof")
// if err != nil {
// log.Fatal(err)
// }
// pprof.StartCPUProfile(f)
//}
2017-06-05 11:57:27 +00:00
2017-05-07 08:31:41 +00:00
log . Print ( "Running Gosora v" + version . String ( ) )
fmt . Println ( "" )
2017-06-05 11:57:27 +00:00
startTime = time . Now ( )
2017-07-17 10:23:42 +00:00
2017-08-13 11:22:34 +00:00
log . Print ( "Processing configuration data" )
2017-10-14 07:39:22 +00:00
err = processConfig ( )
if err != nil {
log . Fatal ( err )
}
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
err = initThemes ( )
2017-04-12 10:10:36 +00:00
if err != nil {
log . Fatal ( err )
}
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
err = initDatabase ( )
if err != nil {
log . Fatal ( err )
}
2017-10-12 03:24:14 +00:00
rstore = NewSQLReplyStore ( )
prstore = NewSQLProfileReplyStore ( )
2017-09-03 04:50:31 +00:00
initTemplates ( )
2017-06-05 11:57:27 +00:00
2017-09-11 00:56:09 +00:00
err = initPhrases ( )
if err != nil {
log . Fatal ( err )
}
2017-09-03 04:50:31 +00:00
log . Print ( "Loading the static files." )
err = initStaticFiles ( )
if err != nil {
log . Fatal ( err )
}
2017-06-05 11:57:27 +00:00
2017-06-19 08:06:54 +00:00
log . Print ( "Initialising the widgets" )
2017-09-03 04:50:31 +00:00
err = initWidgets ( )
2017-06-19 08:06:54 +00:00
if err != nil {
log . Fatal ( err )
}
2017-06-25 09:56:39 +00:00
log . Print ( "Initialising the authentication system" )
auth = NewDefaultAuth ( )
2017-09-10 16:57:22 +00:00
err = LoadWordFilters ( )
2017-08-27 09:33:45 +00:00
if err != nil {
log . Fatal ( err )
}
2017-09-23 19:57:13 +00:00
err = verifyConfig ( )
if err != nil {
log . Fatal ( err )
}
2017-08-20 09:39:02 +00:00
// Run this goroutine once a second
2017-09-03 04:50:31 +00:00
secondTicker := time . NewTicker ( 1 * time . Second )
fifteenMinuteTicker := time . NewTicker ( 15 * time . Minute )
2017-08-20 09:39:02 +00:00
//hour_ticker := time.NewTicker(1 * time.Hour)
go func ( ) {
for {
select {
2017-09-03 04:50:31 +00:00
case <- secondTicker . C :
//log.Print("Running the second ticker")
2017-09-22 02:21:17 +00:00
// TODO: Add a plugin hook here
2017-09-03 04:50:31 +00:00
err := handleExpiredScheduledGroups ( )
if err != nil {
LogError ( err )
}
2017-09-10 16:57:22 +00:00
// TODO: Handle delayed moderation tasks
// TODO: Handle the daily clean-up. Move this to a 24 hour task?
// Sync with the database, if there are any changes
err = handleServerSync ( )
if err != nil {
LogError ( err )
}
// TODO: Manage the TopicStore, UserStore, and ForumStore
// TODO: Alert the admin, if CPU usage, RAM usage, or the number of posts in the past second are too high
// TODO: Clean-up alerts with no unread matches which are over two weeks old. Move this to a 24 hour task?
2017-09-23 19:57:13 +00:00
// TODO: Rescan the static files for changes
2017-09-22 02:21:17 +00:00
// TODO: Add a plugin hook here
2017-09-03 04:50:31 +00:00
case <- fifteenMinuteTicker . C :
2017-09-22 02:21:17 +00:00
// TODO: Add a plugin hook here
2017-09-10 16:57:22 +00:00
// TODO: Automatically lock topics, if they're really old, and the associated setting is enabled.
// TODO: Publish scheduled posts.
2017-09-22 02:21:17 +00:00
// TODO: Add a plugin hook here
2017-08-20 09:39:02 +00:00
}
}
} ( )
2017-06-19 08:06:54 +00:00
log . Print ( "Initialising the router" )
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
router = NewGenRouter ( http . FileServer ( http . Dir ( "./uploads" ) ) )
2017-09-11 10:24:03 +00:00
////router.HandleFunc("/static/", routeStatic)
////router.HandleFunc("/overview/", routeOverview)
////router.HandleFunc("/topics/create/", routeTopicCreate)
////router.HandleFunc("/topics/", routeTopics)
////router.HandleFunc("/forums/", routeForums)
////router.HandleFunc("/forum/", routeForum)
router . HandleFunc ( "/topic/create/submit/" , routeTopicCreateSubmit )
router . HandleFunc ( "/topic/" , routeTopicID )
router . HandleFunc ( "/reply/create/" , routeCreateReply )
//router.HandleFunc("/reply/edit/", routeReplyEdit)
//router.HandleFunc("/reply/delete/", routeReplyDelete)
router . HandleFunc ( "/reply/edit/submit/" , routeReplyEditSubmit )
router . HandleFunc ( "/reply/delete/submit/" , routeReplyDeleteSubmit )
router . HandleFunc ( "/reply/like/submit/" , routeReplyLikeSubmit )
2017-05-02 17:24:33 +00:00
///router.HandleFunc("/report/submit/", route_report_submit)
2017-09-11 10:24:03 +00:00
router . HandleFunc ( "/topic/edit/submit/" , routeEditTopic )
router . HandleFunc ( "/topic/delete/submit/" , routeDeleteTopic )
router . HandleFunc ( "/topic/stick/submit/" , routeStickTopic )
router . HandleFunc ( "/topic/unstick/submit/" , routeUnstickTopic )
2017-09-22 02:21:17 +00:00
router . HandleFunc ( "/topic/lock/submit/" , routeLockTopic )
router . HandleFunc ( "/topic/unlock/submit/" , routeUnlockTopic )
2017-09-11 10:24:03 +00:00
router . HandleFunc ( "/topic/like/submit/" , routeLikeTopic )
2017-06-05 11:57:27 +00:00
2017-01-03 07:47:31 +00:00
// Custom Pages
2017-09-11 10:24:03 +00:00
router . HandleFunc ( "/pages/" , routeCustomPage )
2017-06-05 11:57:27 +00:00
2017-01-03 07:47:31 +00:00
// Accounts
2017-09-11 10:24:03 +00:00
router . HandleFunc ( "/accounts/login/" , routeLogin )
router . HandleFunc ( "/accounts/create/" , routeRegister )
router . HandleFunc ( "/accounts/logout/" , routeLogout )
router . HandleFunc ( "/accounts/login/submit/" , routeLoginSubmit )
router . HandleFunc ( "/accounts/create/submit/" , routeRegisterSubmit )
//router.HandleFunc("/accounts/list/", routeLogin) // Redirect /accounts/ and /user/ to here.. // Get a list of all of the accounts on the forum
//router.HandleFunc("/accounts/create/full/", routeLogout) // Advanced account creator for admins?
//router.HandleFunc("/user/edit/", routeLogout)
2017-11-05 09:55:34 +00:00
////router.HandleFunc("/user/edit/critical/", routeAccountOwnEditCritical) // Password & Email
////router.HandleFunc("/user/edit/critical/submit/", routeAccountOwnEditCriticalSubmit)
////router.HandleFunc("/user/edit/avatar/", routeAccountOwnEditAvatar)
////router.HandleFunc("/user/edit/avatar/submit/", routeAccountOwnEditAvatarSubmit)
////router.HandleFunc("/user/edit/username/", routeAccountOwnEditUsername)
////router.HandleFunc("/user/edit/username/submit/", routeAccountOwnEditUsernameSubmit)
////router.HandleFunc("/user/edit/email/", routeAccountOwnEditEmail)
////router.HandleFunc("/user/edit/token/", routeAccountOwnEditEmailTokenSubmit)
////router.HandleFunc("/user/", routeProfile)
// TODO: Move these into /user/?
2017-09-11 10:24:03 +00:00
router . HandleFunc ( "/profile/reply/create/" , routeProfileReplyCreate )
router . HandleFunc ( "/profile/reply/edit/submit/" , routeProfileReplyEditSubmit )
router . HandleFunc ( "/profile/reply/delete/submit/" , routeProfileReplyDeleteSubmit )
2017-11-05 09:55:34 +00:00
2017-09-11 10:24:03 +00:00
//router.HandleFunc("/user/edit/submit/", routeLogout) // routeLogout? what on earth? o.o
//router.HandleFunc("/users/ban/", routeBan)
router . HandleFunc ( "/users/ban/submit/" , routeBanSubmit )
router . HandleFunc ( "/users/unban/" , routeUnban )
router . HandleFunc ( "/users/activate/" , routeActivate )
router . HandleFunc ( "/users/ips/" , routeIps )
2017-06-05 11:57:27 +00:00
2017-04-13 10:55:51 +00:00
// The Control Panel
2017-09-11 10:24:03 +00:00
// TODO: Rename the commented route handlers to the new camelCase format :'(
2017-09-22 02:21:17 +00:00
////router.HandleFunc("/panel/", routePanel)
////router.HandleFunc("/panel/forums/", routePanelForums)
////router.HandleFunc("/panel/forums/create/", routePanelForumsCreateSubmit)
////router.HandleFunc("/panel/forums/delete/", routePanelForumsDelete)
////router.HandleFunc("/panel/forums/delete/submit/", routePanelForumsDeleteSubmit)
////router.HandleFunc("/panel/forums/edit/", routePanelForumsEdit)
////router.HandleFunc("/panel/forums/edit/submit/", routePanelForumsEditSubmit)
////router.HandleFunc("/panel/forums/edit/perms/submit/", routePanelForumsEditPermsSubmit)
////router.HandleFunc("/panel/settings/", routePanelSettings)
////router.HandleFunc("/panel/settings/edit/", routePanelSetting)
////router.HandleFunc("/panel/settings/edit/submit/", routePanelSettingEdit)
2017-04-13 15:01:30 +00:00
///router.HandleFunc("/panel/themes/", route_panel_themes)
///router.HandleFunc("/panel/themes/default/", route_panel_themes_default)
///router.HandleFunc("/panel/plugins/", route_panel_plugins)
///router.HandleFunc("/panel/plugins/activate/", route_panel_plugins_activate)
///router.HandleFunc("/panel/plugins/deactivate/", route_panel_plugins_deactivate)
///router.HandleFunc("/panel/users/", route_panel_users)
///router.HandleFunc("/panel/users/edit/", route_panel_users_edit)
///router.HandleFunc("/panel/users/edit/submit/", route_panel_users_edit_submit)
///router.HandleFunc("/panel/groups/", route_panel_groups)
///router.HandleFunc("/panel/groups/edit/", route_panel_groups_edit)
///router.HandleFunc("/panel/groups/edit/perms/", route_panel_groups_edit_perms)
///router.HandleFunc("/panel/groups/edit/submit/", route_panel_groups_edit_submit)
///router.HandleFunc("/panel/groups/edit/perms/submit/", route_panel_groups_edit_perms_submit)
///router.HandleFunc("/panel/groups/create/", route_panel_groups_create_submit)
///router.HandleFunc("/panel/logs/mod/", route_panel_logs_mod)
2017-08-15 13:47:56 +00:00
///router.HandleFunc("/panel/debug/", route_panel_debug)
2017-06-05 11:57:27 +00:00
2017-09-22 02:21:17 +00:00
////router.HandleFunc("/api/", routeAPI)
//router.HandleFunc("/exit/", routeExit)
////router.HandleFunc("/", config.DefaultRoute)
2017-09-11 10:24:03 +00:00
router . HandleFunc ( "/ws/" , routeWebsockets )
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
log . Print ( "Initialising the plugins" )
2017-09-03 04:50:31 +00:00
initPlugins ( )
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
2016-12-02 07:38:54 +00:00
defer db . Close ( )
2017-06-05 11:57:27 +00:00
2017-01-17 07:55:46 +00:00
//if profiling {
// pprof.StopCPUProfile()
//}
2017-06-05 11:57:27 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Let users run *both* HTTP and HTTPS
2017-06-19 08:06:54 +00:00
log . Print ( "Initialising the HTTP server" )
2017-07-17 10:23:42 +00:00
if ! site . EnableSsl {
if site . Port == "" {
2017-08-13 11:22:34 +00:00
site . Port = "80"
2017-01-03 07:47:31 +00:00
}
2017-09-10 16:57:22 +00:00
log . Print ( "Listening on port " + site . Port )
2017-09-03 04:50:31 +00:00
err = http . ListenAndServe ( ":" + site . Port , router )
2017-01-03 07:47:31 +00:00
} else {
2017-07-17 10:23:42 +00:00
if site . Port == "" {
2017-08-13 11:22:34 +00:00
site . Port = "443"
}
if site . Port == "80" || site . Port == "443" {
// We should also run the server on port 80
2017-09-10 16:57:22 +00:00
// TODO: Redirect to port 443
2017-08-13 11:22:34 +00:00
go func ( ) {
2017-09-10 16:57:22 +00:00
log . Print ( "Listening on port 80" )
err = http . ListenAndServe ( ":80" , & HTTPSRedirect { } )
2017-08-13 11:22:34 +00:00
if err != nil {
log . Fatal ( err )
}
} ( )
2017-01-03 07:47:31 +00:00
}
2017-09-10 16:57:22 +00:00
log . Print ( "Listening on port " + site . Port )
2017-09-03 04:50:31 +00:00
err = http . ListenAndServeTLS ( ":" + site . Port , config . SslFullchain , config . SslPrivkey , router )
2017-07-17 10:23:42 +00:00
}
// Why did the server stop?
if err != nil {
log . Fatal ( err )
2017-01-03 07:47:31 +00:00
}
2017-04-13 15:01:30 +00:00
}