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-11-29 02:34:02 +00:00
|
|
|
"os/signal"
|
2017-12-01 02:04:29 +00:00
|
|
|
"strings"
|
2017-11-29 02:34:02 +00:00
|
|
|
"syscall"
|
2017-09-03 04:50:31 +00:00
|
|
|
"time"
|
2017-01-17 07:55:46 +00:00
|
|
|
//"runtime/pprof"
|
2017-11-11 04:06:16 +00:00
|
|
|
"./common"
|
2017-12-01 02:04:29 +00:00
|
|
|
"github.com/fsnotify/fsnotify"
|
2016-12-02 07:38:54 +00:00
|
|
|
)
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
var version = common.Version{Major: 0, Minor: 1, Patch: 0, Tag: "dev"}
|
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-03 04:50:31 +00:00
|
|
|
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-11-23 05:37:08 +00:00
|
|
|
func afterDBInit() (err error) {
|
|
|
|
common.Rstore, err = common.NewSQLReplyStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
common.Prstore, err = common.NewSQLProfileReplyStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = common.InitTemplates()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = common.InitPhrases()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("Loading the static files.")
|
|
|
|
err = common.StaticFiles.Init()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Print("Initialising the widgets")
|
|
|
|
err = common.InitWidgets()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Print("Initialising the authentication system")
|
|
|
|
common.Auth, err = common.NewDefaultAuth()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = common.LoadWordFilters()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
common.ModLogs, err = common.NewModLogStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
common.AdminLogs, err = common.NewAdminLogStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-21 11:17:43 +00:00
|
|
|
common.IPSearch, err = common.NewDefaultIPSearcher()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-22 08:15:45 +00:00
|
|
|
common.Subscriptions, err = common.NewDefaultSubscriptionStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
common.Attachments, err = common.NewDefaultAttachmentStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-25 04:57:33 +00:00
|
|
|
common.Polls, err = common.NewDefaultPollStore(common.NewMemoryPollCache(100)) // TODO: Max number of polls held in cache, make this a config item
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-21 11:17:43 +00:00
|
|
|
|
2018-01-14 12:03:20 +00:00
|
|
|
common.GlobalViewCounter, err = common.NewGlobalViewCounter()
|
2017-12-19 03:53:13 +00:00
|
|
|
if err != nil {
|
2018-01-09 07:39:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
common.AgentViewCounter, err = common.NewDefaultAgentViewCounter()
|
|
|
|
if err != nil {
|
2017-12-19 03:53:13 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-12-24 07:38:46 +00:00
|
|
|
common.RouteViewCounter, err = common.NewDefaultRouteViewCounter()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-14 12:03:20 +00:00
|
|
|
common.PostCounter, err = common.NewPostCounter()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-18 12:31:25 +00:00
|
|
|
common.TopicCounter, err = common.NewTopicCounter()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-24 07:38:46 +00:00
|
|
|
common.TopicViewCounter, err = common.NewDefaultTopicViewCounter()
|
2017-12-10 03:43:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-06 04:02:35 +00:00
|
|
|
// TODO: Split this function up
|
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-11-07 22:38:15 +00:00
|
|
|
// WIP: Mango Test
|
|
|
|
/*res, err := ioutil.ReadFile("./templates/topic.html")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
tagIndices, err := mangoParse(string(res))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Printf("tagIndices: %+v\n", tagIndices)
|
|
|
|
log.Fatal("")*/
|
|
|
|
|
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()
|
2018-01-17 11:13:08 +00:00
|
|
|
f, err := os.OpenFile("./ops.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-11-11 04:06:16 +00:00
|
|
|
err = common.ProcessConfig()
|
2017-10-14 07:39:22 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.InitThemes()
|
2017-04-12 10:10:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
err = InitDatabase()
|
2017-09-03 04:50:31 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-11-29 02:34:02 +00:00
|
|
|
defer db.Close()
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
err = afterDBInit()
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.VerifyConfig()
|
2017-09-23 19:57:13 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-12-01 02:04:29 +00:00
|
|
|
watcher, err := fsnotify.NewWatcher()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer watcher.Close()
|
|
|
|
|
|
|
|
go func() {
|
2017-12-10 03:43:30 +00:00
|
|
|
var modifiedFileEvent = func(path string) error {
|
|
|
|
var pathBits = strings.Split(path, "\\")
|
|
|
|
if len(pathBits) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if pathBits[0] == "themes" {
|
|
|
|
var themeName string
|
|
|
|
if len(pathBits) >= 2 {
|
|
|
|
themeName = pathBits[1]
|
|
|
|
}
|
|
|
|
if len(pathBits) >= 3 && pathBits[2] == "public" {
|
|
|
|
// TODO: Handle new themes freshly plopped into the folder?
|
|
|
|
theme, ok := common.Themes[themeName]
|
|
|
|
if ok {
|
|
|
|
return theme.LoadStaticFiles()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
2017-12-01 02:04:29 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case event := <-watcher.Events:
|
|
|
|
log.Println("event:", event)
|
2017-12-10 03:43:30 +00:00
|
|
|
// TODO: Handle file deletes (and renames more graciously by removing the old version of it)
|
2017-12-01 02:04:29 +00:00
|
|
|
if event.Op&fsnotify.Write == fsnotify.Write {
|
|
|
|
log.Println("modified file:", event.Name)
|
2017-12-10 03:43:30 +00:00
|
|
|
err = modifiedFileEvent(event.Name)
|
2017-12-01 02:04:29 +00:00
|
|
|
} else if event.Op&fsnotify.Create == fsnotify.Create {
|
|
|
|
log.Println("new file:", event.Name)
|
2017-12-10 03:43:30 +00:00
|
|
|
err = modifiedFileEvent(event.Name)
|
2017-12-01 02:04:29 +00:00
|
|
|
}
|
2017-12-10 03:43:30 +00:00
|
|
|
if err != nil {
|
|
|
|
common.LogError(err)
|
|
|
|
}
|
|
|
|
case err = <-watcher.Errors:
|
|
|
|
common.LogError(err)
|
2017-12-01 02:04:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-12-10 03:43:30 +00:00
|
|
|
// TODO: Keep tabs on the (non-resource) theme stuff, and the langpacks
|
2017-12-01 02:04:29 +00:00
|
|
|
err = watcher.Add("./public")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
err = watcher.Add("./templates")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, theme := range common.Themes {
|
|
|
|
err = watcher.Add("./themes/" + theme.Name + "/public")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-24 22:08:35 +00:00
|
|
|
var runTasks = func(tasks []func() error) {
|
|
|
|
for _, task := range tasks {
|
|
|
|
if task() != nil {
|
|
|
|
common.LogError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 08:03:17 +00:00
|
|
|
// Run this goroutine once every half second
|
|
|
|
halfSecondTicker := time.NewTicker(time.Second / 2)
|
2017-09-03 04:50:31 +00:00
|
|
|
secondTicker := time.NewTicker(1 * time.Second)
|
|
|
|
fifteenMinuteTicker := time.NewTicker(15 * time.Minute)
|
2017-11-29 02:34:02 +00:00
|
|
|
//hourTicker := time.NewTicker(1 * time.Hour)
|
2017-08-20 09:39:02 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
2018-01-11 08:03:17 +00:00
|
|
|
case <-halfSecondTicker.C:
|
|
|
|
// TODO: Add a plugin hook here
|
|
|
|
runTasks(common.ScheduledHalfSecondTasks)
|
|
|
|
// TODO: Add a plugin hook here
|
2017-09-03 04:50:31 +00:00
|
|
|
case <-secondTicker.C:
|
2017-09-22 02:21:17 +00:00
|
|
|
// TODO: Add a plugin hook here
|
2017-12-24 22:08:35 +00:00
|
|
|
runTasks(common.ScheduledSecondTasks)
|
2017-09-22 02:21:17 +00:00
|
|
|
|
2017-12-24 22:08:35 +00:00
|
|
|
// TODO: Stop hard-coding this
|
2017-11-11 04:06:16 +00:00
|
|
|
err := common.HandleExpiredScheduledGroups()
|
2017-09-03 04:50:31 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
common.LogError(err)
|
2017-09-03 04:50:31 +00:00
|
|
|
}
|
2017-09-10 16:57:22 +00:00
|
|
|
|
|
|
|
// TODO: Handle delayed moderation tasks
|
|
|
|
|
|
|
|
// Sync with the database, if there are any changes
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.HandleServerSync()
|
2017-09-10 16:57:22 +00:00
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
common.LogError(err)
|
2017-09-10 16:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-12-24 22:08:35 +00:00
|
|
|
runTasks(common.ScheduledFifteenMinuteTasks)
|
2017-12-10 03:43:30 +00:00
|
|
|
|
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-12-24 22:08:35 +00:00
|
|
|
|
|
|
|
// TODO: Handle the daily clean-up.
|
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")))
|
|
|
|
|
|
|
|
log.Print("Initialising the plugins")
|
2017-11-11 04:06:16 +00:00
|
|
|
common.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
|
|
|
|
2017-11-29 02:34:02 +00:00
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
sig := <-sigs
|
|
|
|
// TODO: Gracefully shutdown the HTTP server
|
2017-12-24 22:08:35 +00:00
|
|
|
runTasks(common.ShutdownTasks)
|
2017-11-29 02:34:02 +00:00
|
|
|
log.Fatal("Received a signal to shutdown: ", sig)
|
|
|
|
}()
|
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-12-22 03:32:23 +00:00
|
|
|
// We might not need the timeouts, if we're behind a reverse-proxy like Nginx
|
|
|
|
var newServer = func(addr string, handler http.Handler) *http.Server {
|
|
|
|
return &http.Server{
|
|
|
|
Addr: addr,
|
|
|
|
Handler: handler,
|
|
|
|
|
|
|
|
ReadTimeout: 5 * time.Second,
|
|
|
|
WriteTimeout: 10 * time.Second,
|
|
|
|
IdleTimeout: 120 * time.Second,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-11-11 04:06:16 +00:00
|
|
|
if !common.Site.EnableSsl {
|
|
|
|
if common.Site.Port == "" {
|
|
|
|
common.Site.Port = "80"
|
2017-01-03 07:47:31 +00:00
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
log.Print("Listening on port " + common.Site.Port)
|
2017-12-22 03:32:23 +00:00
|
|
|
err = newServer(":"+common.Site.Port, router).ListenAndServe()
|
2017-01-03 07:47:31 +00:00
|
|
|
} else {
|
2017-11-11 04:06:16 +00:00
|
|
|
if common.Site.Port == "" {
|
|
|
|
common.Site.Port = "443"
|
2017-08-13 11:22:34 +00:00
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
if common.Site.Port == "80" || common.Site.Port == "443" {
|
2017-08-13 11:22:34 +00:00
|
|
|
// 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")
|
2017-12-22 03:32:23 +00:00
|
|
|
err = newServer(":80", &HTTPSRedirect{}).ListenAndServe()
|
2017-08-13 11:22:34 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2017-01-03 07:47:31 +00:00
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
log.Printf("Listening on port %s", common.Site.Port)
|
2017-12-22 03:32:23 +00:00
|
|
|
err = newServer(":"+common.Site.Port, router).ListenAndServeTLS(common.Config.SslFullchain, common.Config.SslPrivkey)
|
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
|
|
|
}
|