2017-05-07 08:31:41 +00:00
|
|
|
/* 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-02 07:38:54 +00:00
|
|
|
"log"
|
2017-07-17 10:23:42 +00:00
|
|
|
"strings"
|
2017-06-05 11:57:27 +00:00
|
|
|
"time"
|
2016-12-17 03:39:53 +00:00
|
|
|
"io"
|
2017-08-13 11:22:34 +00:00
|
|
|
"os"
|
|
|
|
"net/http"
|
2016-12-02 07:38:54 +00:00
|
|
|
"html/template"
|
2017-01-17 07:55:46 +00:00
|
|
|
//"runtime/pprof"
|
2016-12-02 07:38:54 +00:00
|
|
|
)
|
|
|
|
|
2017-05-07 08:31:41 +00:00
|
|
|
var version Version = Version{Major:0,Minor:1,Patch:0,Tag:"dev"}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
const hour int = 60 * 60
|
|
|
|
const day int = hour * 24
|
|
|
|
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
|
2016-12-02 07:38:54 +00:00
|
|
|
const saltLength int = 32
|
|
|
|
const sessionLength int = 80
|
2017-05-11 13:04:43 +00:00
|
|
|
var enable_websockets bool = false // Don't change this, the value is overwritten by an initialiser
|
2016-12-04 06:16:59 +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-07-17 10:23:42 +00:00
|
|
|
//var timeLocation *time.Location
|
2017-01-21 18:16:27 +00:00
|
|
|
var templates = template.New("")
|
2017-07-17 10:23:42 +00:00
|
|
|
//var no_css_tmpl template.CSS = template.CSS("")
|
2017-08-06 15:22:18 +00:00
|
|
|
var external_sites map[string]string = map[string]string{
|
|
|
|
"YT":"https://www.youtube.com/",
|
|
|
|
}
|
2017-01-31 05:13:38 +00:00
|
|
|
var groups []Group
|
2017-06-19 08:06:54 +00:00
|
|
|
var groupCapCount int
|
2016-12-05 07:21:17 +00:00
|
|
|
var static_files map[string]SFile = make(map[string]SFile)
|
2017-08-13 11:22:34 +00:00
|
|
|
var logWriter io.Writer = io.MultiWriter(os.Stderr)
|
2017-01-01 15:45:43 +00:00
|
|
|
|
2017-08-13 11:22:34 +00:00
|
|
|
func interpreted_topic_template(pi TopicPage, w http.ResponseWriter) {
|
|
|
|
mapping, ok := themes[defaultTheme].TemplatesMap["topic"]
|
|
|
|
if !ok {
|
|
|
|
mapping = "topic"
|
|
|
|
}
|
|
|
|
err := templates.ExecuteTemplate(w,mapping + ".html", pi)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var template_topic_handle func(TopicPage,http.ResponseWriter) = interpreted_topic_template
|
|
|
|
var template_topic_alt_handle func(TopicPage,http.ResponseWriter) = interpreted_topic_template
|
|
|
|
var template_topics_handle func(TopicsPage,http.ResponseWriter) = func(pi TopicsPage, w http.ResponseWriter) {
|
|
|
|
mapping, ok := themes[defaultTheme].TemplatesMap["topics"]
|
|
|
|
if !ok {
|
|
|
|
mapping = "topics"
|
|
|
|
}
|
|
|
|
err := templates.ExecuteTemplate(w,mapping + ".html", pi)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var template_forum_handle func(ForumPage,http.ResponseWriter) = func(pi ForumPage, w http.ResponseWriter) {
|
|
|
|
mapping, ok := themes[defaultTheme].TemplatesMap["forum"]
|
|
|
|
if !ok {
|
|
|
|
mapping = "forum"
|
|
|
|
}
|
|
|
|
err := templates.ExecuteTemplate(w,mapping + ".html", pi)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var template_forums_handle func(ForumsPage,http.ResponseWriter) = func(pi ForumsPage, w http.ResponseWriter) {
|
|
|
|
mapping, ok := themes[defaultTheme].TemplatesMap["forums"]
|
|
|
|
if !ok {
|
|
|
|
mapping = "forums"
|
|
|
|
}
|
|
|
|
err := templates.ExecuteTemplate(w,mapping + ".html", pi)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var template_profile_handle func(ProfilePage,http.ResponseWriter) = func(pi ProfilePage, w http.ResponseWriter) {
|
|
|
|
mapping, ok := themes[defaultTheme].TemplatesMap["profile"]
|
|
|
|
if !ok {
|
|
|
|
mapping = "profile"
|
|
|
|
}
|
|
|
|
err := templates.ExecuteTemplate(w,mapping + ".html", pi)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var template_create_topic_handle func(CreateTopicPage,http.ResponseWriter) = func(pi CreateTopicPage, w http.ResponseWriter) {
|
|
|
|
mapping, ok := themes[defaultTheme].TemplatesMap["create-topic"]
|
|
|
|
if !ok {
|
|
|
|
mapping = "create-topic"
|
|
|
|
}
|
|
|
|
err := templates.ExecuteTemplate(w,mapping + ".html", pi)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w)
|
|
|
|
}
|
|
|
|
}
|
2016-12-16 10:37:42 +00:00
|
|
|
|
2017-06-28 12:05:26 +00:00
|
|
|
func compile_templates() error {
|
2016-12-16 10:37:42 +00:00
|
|
|
var c CTemplateSet
|
2017-07-29 14:04:20 +00:00
|
|
|
user := User{62,build_profile_url("fake-user",62),"Fake User","compiler@localhost",0,false,false,false,false,false,false,GuestPerms,make(map[string]bool),"",false,"","","","","",0,0,"0.0.0.0.0"}
|
2017-08-06 15:22:18 +00:00
|
|
|
// TO-DO: Do a more accurate level calculation for this?
|
|
|
|
user2 := User{1,build_profile_url("admin-alice",1),"Admin Alice","alice@localhost",1,true,true,true,true,false,false,AllPerms,make(map[string]bool),"",true,"","","","","",58,1000,"127.0.0.1"}
|
|
|
|
user3 := User{2,build_profile_url("admin-fred",62),"Admin Fred","fred@localhost",1,true,true,true,true,false,false,AllPerms,make(map[string]bool),"",true,"","","","","",42,900,"::1"}
|
2017-06-16 10:41:30 +00:00
|
|
|
headerVars := HeaderVars{
|
2017-07-17 10:23:42 +00:00
|
|
|
Site:site,
|
2017-06-16 10:41:30 +00:00
|
|
|
NoticeList:[]string{"test"},
|
|
|
|
Stylesheets:[]string{"panel"},
|
|
|
|
Scripts:[]string{"whatever"},
|
2017-06-25 09:56:39 +00:00
|
|
|
Widgets:PageWidgets{
|
|
|
|
LeftSidebar: template.HTML("lalala"),
|
2017-06-19 08:06:54 +00:00
|
|
|
},
|
2017-06-16 10:41:30 +00:00
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2016-12-16 10:37:42 +00:00
|
|
|
log.Print("Compiling the templates")
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-07-29 14:04:20 +00:00
|
|
|
topic := TopicUser{1,"blah","Blah","Hey there!",0,false,false,"Date","Date",0,"","127.0.0.1",0,1,"classname","weird-data",build_profile_url("fake-user",62),"Fake User",config.DefaultGroup,"",0,"","","","",58,false}
|
2016-12-21 02:30:32 +00:00
|
|
|
var replyList []Reply
|
2017-07-17 10:23:42 +00:00
|
|
|
replyList = append(replyList, Reply{0,0,"Yo!","Yo!",0,"alice","Alice",config.DefaultGroup,"",0,0,"","",0,"","","","",0,"127.0.0.1",false,1,"",""})
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2016-12-21 02:30:32 +00:00
|
|
|
var varList map[string]VarItem = make(map[string]VarItem)
|
2017-06-16 10:41:30 +00:00
|
|
|
tpage := TopicPage{"Title",user,headerVars,replyList,topic,1,1,extData}
|
2017-08-13 11:22:34 +00:00
|
|
|
topic_id_tmpl, err := c.compile_template("topic.html","templates/","TopicPage", tpage, varList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
topic_id_alt_tmpl, err := c.compile_template("topic_alt.html","templates/","TopicPage", tpage, varList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2016-12-16 10:37:42 +00:00
|
|
|
varList = make(map[string]VarItem)
|
2017-06-16 10:41:30 +00:00
|
|
|
ppage := ProfilePage{"User 526",user,headerVars,replyList,user,extData}
|
2017-08-13 11:22:34 +00:00
|
|
|
profile_tmpl, err := c.compile_template("profile.html","templates/","ProfilePage", ppage, varList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-01 15:45:43 +00:00
|
|
|
var forumList []Forum
|
2017-06-28 12:05:26 +00:00
|
|
|
forums, err := fstore.GetAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-12-18 12:56:06 +00:00
|
|
|
for _, forum := range forums {
|
|
|
|
if forum.Active {
|
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
|
|
|
forumList = append(forumList,*forum)
|
2016-12-18 12:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
varList = make(map[string]VarItem)
|
2017-06-16 10:41:30 +00:00
|
|
|
forums_page := ForumsPage{"Forum List",user,headerVars,forumList,extData}
|
2017-08-13 11:22:34 +00:00
|
|
|
forums_tmpl, err := c.compile_template("forums.html","templates/","ForumsPage",forums_page,varList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-08-06 15:22:18 +00:00
|
|
|
var topicsList []*TopicsRow
|
|
|
|
topicsList = append(topicsList,&TopicsRow{1,"topic-title","Topic Title","The topic content.",1,false,false,"Date","Date",user3.ID,1,"","127.0.0.1",0,1,"classname","",&user2,"",0,&user3,"General","/forum/general.2"})
|
2017-06-16 10:41:30 +00:00
|
|
|
topics_page := TopicsPage{"Topic List",user,headerVars,topicsList,extData}
|
2017-08-13 11:22:34 +00:00
|
|
|
topics_tmpl, err := c.compile_template("topics.html","templates/","TopicsPage",topics_page,varList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-08-06 15:22:18 +00:00
|
|
|
//var topicList []TopicUser
|
|
|
|
//topicList = append(topicList,TopicUser{1,"topic-title","Topic Title","The topic content.",1,false,false,"Date","Date",1,"","127.0.0.1",0,1,"classname","","admin-fred","Admin Fred",config.DefaultGroup,"",0,"","","","",58,false})
|
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
|
|
|
forum_item := Forum{1,"general","General Forum","Where the general stuff happens",true,"all",0,"",0,"","",0,"",0,""}
|
2017-08-06 15:22:18 +00:00
|
|
|
forum_page := ForumPage{"General Forum",user,headerVars,topicsList,forum_item,1,1,extData}
|
2017-08-13 11:22:34 +00:00
|
|
|
forum_tmpl, err := c.compile_template("forum.html","templates/","ForumPage",forum_page,varList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2016-12-16 10:37:42 +00:00
|
|
|
log.Print("Writing the templates")
|
2017-01-17 07:55:46 +00:00
|
|
|
go write_template("topic", topic_id_tmpl)
|
|
|
|
go write_template("topic_alt", topic_id_alt_tmpl)
|
|
|
|
go write_template("profile", profile_tmpl)
|
|
|
|
go write_template("forums", forums_tmpl)
|
|
|
|
go write_template("topics", topics_tmpl)
|
|
|
|
go write_template("forum", forum_tmpl)
|
2017-08-13 11:22:34 +00:00
|
|
|
go func() {
|
|
|
|
err := write_file("./template_list.go","package main\n\n" + c.FragOut)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2017-06-28 12:05:26 +00:00
|
|
|
|
|
|
|
return nil
|
2016-12-16 10:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func write_template(name string, content string) {
|
2017-05-02 17:24:33 +00:00
|
|
|
err := write_file("./template_" + name + ".go", content)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-12-16 10:37:42 +00:00
|
|
|
}
|
2016-12-02 07:38:54 +00:00
|
|
|
|
2017-01-21 18:16:27 +00:00
|
|
|
func init_templates() {
|
2017-07-17 10:23:42 +00:00
|
|
|
if dev.DebugMode {
|
2017-06-16 10:41:30 +00:00
|
|
|
log.Print("Initialising the template system")
|
|
|
|
}
|
2017-01-21 18:16:27 +00:00
|
|
|
compile_templates()
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-08-15 13:47:56 +00:00
|
|
|
// TO-DO: Add support for 64-bit integers
|
|
|
|
// TO-DO: Add support for floats
|
2017-05-07 08:31:41 +00:00
|
|
|
fmap := make(map[string]interface{})
|
2017-08-15 13:47:56 +00:00
|
|
|
fmap["add"] = func(left interface{}, right interface{})interface{} {
|
|
|
|
var left_int int
|
|
|
|
var right_int int
|
|
|
|
switch left := left.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: left_int = left.(int)
|
|
|
|
}
|
|
|
|
switch right := right.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: right_int = right.(int)
|
|
|
|
}
|
|
|
|
return left_int + right_int
|
|
|
|
}
|
|
|
|
|
|
|
|
fmap["subtract"] = func(left interface{}, right interface{})interface{} {
|
|
|
|
var left_int int
|
|
|
|
var right_int int
|
|
|
|
switch left := left.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: left_int = left.(int)
|
|
|
|
}
|
|
|
|
switch right := right.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: right_int = right.(int)
|
|
|
|
}
|
|
|
|
return left_int - right_int
|
|
|
|
}
|
|
|
|
|
|
|
|
fmap["multiply"] = func(left interface{}, right interface{})interface{} {
|
|
|
|
var left_int int
|
|
|
|
var right_int int
|
|
|
|
switch left := left.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: left_int = left.(int)
|
|
|
|
}
|
|
|
|
switch right := right.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: right_int = right.(int)
|
|
|
|
}
|
|
|
|
return left_int * right_int
|
|
|
|
}
|
|
|
|
|
|
|
|
fmap["divide"] = func(left interface{}, right interface{})interface{} {
|
|
|
|
var left_int int
|
|
|
|
var right_int int
|
|
|
|
switch left := left.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: left_int = left.(int)
|
|
|
|
}
|
|
|
|
switch right := right.(type) {
|
|
|
|
case uint, uint8, uint16, int, int32: right_int = right.(int)
|
|
|
|
}
|
|
|
|
if left_int == 0 || right_int == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return left_int / right_int
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-21 18:16:27 +00:00
|
|
|
// The interpreted templates...
|
2017-07-17 10:23:42 +00:00
|
|
|
if dev.DebugMode {
|
2017-06-16 10:41:30 +00:00
|
|
|
log.Print("Loading the template files...")
|
|
|
|
}
|
2017-01-21 18:16:27 +00:00
|
|
|
templates.Funcs(fmap)
|
|
|
|
template.Must(templates.ParseGlob("templates/*"))
|
|
|
|
template.Must(templates.ParseGlob("pages/*"))
|
|
|
|
}
|
|
|
|
|
2017-07-17 10:23:42 +00:00
|
|
|
func process_config() {
|
|
|
|
config.Noavatar = strings.Replace(config.Noavatar,"{site_url}",site.Url,-1)
|
|
|
|
if site.Port != "80" && site.Port != "443" {
|
|
|
|
site.Url = strings.TrimSuffix(site.Url,"/")
|
|
|
|
site.Url = strings.TrimSuffix(site.Url,"\\")
|
|
|
|
site.Url = strings.TrimSuffix(site.Url,":")
|
|
|
|
site.Url = site.Url + ":" + site.Port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func main(){
|
2017-08-13 11:22:34 +00:00
|
|
|
// TO-DO: Have a file for each run with the time/date the server started as the file name?
|
|
|
|
// TO-DO: Log panics with recover()
|
|
|
|
f, err := os.OpenFile("./operations.log",os.O_WRONLY|os.O_APPEND|os.O_CREATE,0755)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
logWriter = io.MultiWriter(os.Stderr,f)
|
|
|
|
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
|
|
|
//timeLocation = startTime.Location()
|
|
|
|
|
2017-08-13 11:22:34 +00:00
|
|
|
log.Print("Processing configuration data")
|
2017-07-17 10:23:42 +00:00
|
|
|
process_config()
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-01 15:45:43 +00:00
|
|
|
init_themes()
|
2017-08-13 11:22:34 +00:00
|
|
|
err = init_database()
|
2017-04-12 10:10:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-21 18:16:27 +00:00
|
|
|
init_templates()
|
2017-01-17 07:55:46 +00:00
|
|
|
err = init_errors()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-07-17 10:23:42 +00:00
|
|
|
if config.CacheTopicUser == CACHE_STATIC {
|
|
|
|
users = NewMemoryUserStore(config.UserCacheCapacity)
|
|
|
|
topics = NewMemoryTopicStore(config.TopicCacheCapacity)
|
2017-02-11 14:51:16 +00:00
|
|
|
} else {
|
|
|
|
users = NewSqlUserStore()
|
|
|
|
topics = NewSqlTopicStore()
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
init_static_files()
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-06-19 08:06:54 +00:00
|
|
|
log.Print("Initialising the widgets")
|
|
|
|
err = init_widgets()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-06-25 09:56:39 +00:00
|
|
|
log.Print("Initialising the authentication system")
|
|
|
|
auth = NewDefaultAuth()
|
|
|
|
|
2017-08-20 09:39:02 +00:00
|
|
|
// Run this goroutine once a second
|
|
|
|
second_ticker := time.NewTicker(1 * time.Second)
|
|
|
|
fifteen_minute_ticker := time.NewTicker(15 * time.Minute)
|
|
|
|
//hour_ticker := time.NewTicker(1 * time.Hour)
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <- second_ticker.C:
|
|
|
|
// TO-DO: Handle delayed moderation tasks
|
|
|
|
// TO-DO: Handle the daily clean-up. Move this to a 24 hour task?
|
|
|
|
// TO-DO: Sync with the database, if there are any changes
|
|
|
|
// TO-DO: Manage the TopicStore, UserStore, and ForumStore
|
|
|
|
// TO-DO: Alert the admin, if CPU usage, RAM usage, or the number of posts in the past second are too high
|
|
|
|
// TO-DO: Clean-up alerts with no unread matches which are over two weeks old. Move this to a 24 hour task?
|
|
|
|
case <- fifteen_minute_ticker.C:
|
|
|
|
// TO-DO: Handle temporary bans.
|
|
|
|
// TO-DO: Automatically lock topics, if they're really old, and the associated setting is enabled.
|
|
|
|
// TO-DO: Publish scheduled posts. Move this to a 15 minute task?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
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-04-13 09:26:40 +00:00
|
|
|
///router.HandleFunc("/static/", route_static)
|
|
|
|
///router.HandleFunc("/overview/", route_overview)
|
|
|
|
///router.HandleFunc("/topics/create/", route_topic_create)
|
|
|
|
///router.HandleFunc("/topics/", route_topics)
|
|
|
|
///router.HandleFunc("/forums/", route_forums)
|
2017-04-13 15:01:30 +00:00
|
|
|
///router.HandleFunc("/forum/", route_forum)
|
2017-07-12 11:05:18 +00:00
|
|
|
router.HandleFunc("/topic/create/submit/", route_topic_create_submit)
|
2017-01-03 07:47:31 +00:00
|
|
|
router.HandleFunc("/topic/", route_topic_id)
|
|
|
|
router.HandleFunc("/reply/create/", route_create_reply)
|
|
|
|
//router.HandleFunc("/reply/edit/", route_reply_edit)
|
|
|
|
//router.HandleFunc("/reply/delete/", route_reply_delete)
|
|
|
|
router.HandleFunc("/reply/edit/submit/", route_reply_edit_submit)
|
|
|
|
router.HandleFunc("/reply/delete/submit/", route_reply_delete_submit)
|
2017-02-10 13:39:13 +00:00
|
|
|
router.HandleFunc("/reply/like/submit/", route_reply_like_submit)
|
2017-05-02 17:24:33 +00:00
|
|
|
///router.HandleFunc("/report/submit/", route_report_submit)
|
2017-01-03 07:47:31 +00:00
|
|
|
router.HandleFunc("/topic/edit/submit/", route_edit_topic)
|
|
|
|
router.HandleFunc("/topic/delete/submit/", route_delete_topic)
|
|
|
|
router.HandleFunc("/topic/stick/submit/", route_stick_topic)
|
|
|
|
router.HandleFunc("/topic/unstick/submit/", route_unstick_topic)
|
2017-02-10 13:39:13 +00:00
|
|
|
router.HandleFunc("/topic/like/submit/", route_like_topic)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-03 07:47:31 +00:00
|
|
|
// Custom Pages
|
|
|
|
router.HandleFunc("/pages/", route_custom_page)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-03 07:47:31 +00:00
|
|
|
// Accounts
|
|
|
|
router.HandleFunc("/accounts/login/", route_login)
|
|
|
|
router.HandleFunc("/accounts/create/", route_register)
|
|
|
|
router.HandleFunc("/accounts/logout/", route_logout)
|
|
|
|
router.HandleFunc("/accounts/login/submit/", route_login_submit)
|
|
|
|
router.HandleFunc("/accounts/create/submit/", route_register_submit)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-01-03 07:47:31 +00:00
|
|
|
//router.HandleFunc("/accounts/list/", route_login) // Redirect /accounts/ and /user/ to here.. // Get a list of all of the accounts on the forum
|
|
|
|
//router.HandleFunc("/accounts/create/full/", route_logout) // Advanced account creator for admins?
|
|
|
|
//router.HandleFunc("/user/edit/", route_logout)
|
|
|
|
router.HandleFunc("/user/edit/critical/", route_account_own_edit_critical) // Password & Email
|
|
|
|
router.HandleFunc("/user/edit/critical/submit/", route_account_own_edit_critical_submit)
|
|
|
|
router.HandleFunc("/user/edit/avatar/", route_account_own_edit_avatar)
|
|
|
|
router.HandleFunc("/user/edit/avatar/submit/", route_account_own_edit_avatar_submit)
|
|
|
|
router.HandleFunc("/user/edit/username/", route_account_own_edit_username)
|
|
|
|
router.HandleFunc("/user/edit/username/submit/", route_account_own_edit_username_submit)
|
|
|
|
router.HandleFunc("/user/edit/email/", route_account_own_edit_email)
|
2017-03-18 07:23:02 +00:00
|
|
|
router.HandleFunc("/user/edit/token/", route_account_own_edit_email_token_submit)
|
2017-01-03 07:47:31 +00:00
|
|
|
router.HandleFunc("/user/", route_profile)
|
|
|
|
router.HandleFunc("/profile/reply/create/", route_profile_reply_create)
|
|
|
|
router.HandleFunc("/profile/reply/edit/submit/", route_profile_reply_edit_submit)
|
|
|
|
router.HandleFunc("/profile/reply/delete/submit/", route_profile_reply_delete_submit)
|
|
|
|
//router.HandleFunc("/user/edit/submit/", route_logout)
|
|
|
|
router.HandleFunc("/users/ban/", route_ban)
|
|
|
|
router.HandleFunc("/users/ban/submit/", route_ban_submit)
|
|
|
|
router.HandleFunc("/users/unban/", route_unban)
|
|
|
|
router.HandleFunc("/users/activate/", route_activate)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-04-13 10:55:51 +00:00
|
|
|
// The Control Panel
|
|
|
|
///router.HandleFunc("/panel/", route_panel)
|
|
|
|
///router.HandleFunc("/panel/forums/", route_panel_forums)
|
|
|
|
///router.HandleFunc("/panel/forums/create/", route_panel_forums_create_submit)
|
|
|
|
///router.HandleFunc("/panel/forums/delete/", route_panel_forums_delete)
|
|
|
|
///router.HandleFunc("/panel/forums/delete/submit/", route_panel_forums_delete_submit)
|
|
|
|
///router.HandleFunc("/panel/forums/edit/", route_panel_forums_edit)
|
|
|
|
///router.HandleFunc("/panel/forums/edit/submit/", route_panel_forums_edit_submit)
|
2017-06-05 11:57:27 +00:00
|
|
|
///router.HandleFunc("/panel/forums/edit/perms/submit/", route_panel_forums_edit_perms_submit)
|
2017-04-13 15:01:30 +00:00
|
|
|
///router.HandleFunc("/panel/settings/", route_panel_settings)
|
|
|
|
///router.HandleFunc("/panel/settings/edit/", route_panel_setting)
|
|
|
|
///router.HandleFunc("/panel/settings/edit/submit/", route_panel_setting_edit)
|
|
|
|
///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-05-02 17:24:33 +00:00
|
|
|
///router.HandleFunc("/api/", route_api)
|
|
|
|
//router.HandleFunc("/exit/", route_exit)
|
2017-04-13 09:26:40 +00:00
|
|
|
///router.HandleFunc("/", default_route)
|
2017-05-11 13:04:43 +00:00
|
|
|
router.HandleFunc("/ws/", route_websockets)
|
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")
|
|
|
|
init_plugins()
|
|
|
|
|
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-08-06 15:22:18 +00:00
|
|
|
// TO-DO: 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-07-17 10:23:42 +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
|
|
|
|
// TO-DO: Redirect to port 443
|
|
|
|
go func() {
|
|
|
|
err = http.ListenAndServe(":80", &HttpsRedirect{})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2017-01-03 07:47:31 +00:00
|
|
|
}
|
2017-07-17 10:23:42 +00:00
|
|
|
err = http.ListenAndServeTLS(":" + site.Port, config.SslFullchain, config.SslPrivkey, router)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|