Added the Plugin section to config.json

Added support for ZIP files to the backups route.
The post counter won't be incremented if json marshalling fails now.

Added the router_pre_route hook.
Added the router_end hook.
Added the action_end_create_topic hook.
Added the action_end_create_reply hook.
This commit is contained in:
Azareal 2019-04-06 11:08:49 +10:00
parent af9a56a9a9
commit 1115c0a4c5
8 changed files with 72 additions and 22 deletions

View File

@ -76,10 +76,17 @@ var hookTable = &HookTable{
"topic_reply_row_assign": nil,
"create_group_preappend": nil, // What is this? Investigate!
"topic_create_pre_loop": nil,
"router_end": nil,
},
map[string]func(...interface{}) (bool, RouteError){
"simple_forum_check_pre_perms": nil,
"forum_check_pre_perms": nil,
"action_end_create_topic": nil,
"action_end_create_reply": nil,
"router_pre_route": nil,
},
map[string][]func(string) string{
"preparse_preassign": nil,

View File

@ -21,6 +21,8 @@ var Config = new(config)
// Dev holds build flags and other things which should only be modified during developers or to gather additional test data
var Dev = new(devConfig)
var PluginConfig = map[string]string{}
type site struct {
ShortName string
Name string
@ -120,6 +122,7 @@ type configHolder struct {
Config *config
Database *dbConfig
Dev *devConfig
Plugin map[string]string
}
func LoadConfig() error {
@ -138,6 +141,7 @@ func LoadConfig() error {
Config = config.Config
DbConfig = config.Database
Dev = config.Dev
PluginConfig = config.Plugin
return nil
}

View File

@ -2,9 +2,17 @@
For configuring the system, Gosora has a file called `config/config.json` which you can tweak to change various behaviours, it also has a few settings in the Setting Manager in the Control Panel.
The configuration file has four categories you may be familiar with from poring through it's contents. Site, Config, Database and Dev.
The configuration file has five categories you may be familiar with from poring through it's contents. Site, Config, Database, Dev and Plugin.
Site is for critical settings, Config is for lower priority yet still important settings, Database contains the credentials for the database (you will be able to pass these via parameters to the binary in a future version), and Dev is for a few flags which help out with the development of Gosora.
Site is for critical settings.
Config is for lower priority yet still important settings.
Database contains the credentials for the database (you will be able to pass these via parameters to the binary in a future version).
Dev is for a few flags which help out with the development of Gosora.
Plugin which you may not have run into is a category in which plugins can define their own custom configuration settings.
An example of what the file might look like: https://github.com/Azareal/Gosora/blob/master/config/config_example.json

View File

@ -994,10 +994,18 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w = common.GzipResponseWriter{Writer: gz, ResponseWriter: w}
}
ferr := r.routeSwitch(w, req, user, prefix, extraData)
// TODO: Use the same hook table as downstream
hTbl := common.GetHookTable()
skip, ferr := hTbl.VhookSkippable("router_pre_route", w, req, user, prefix, extraData)
if skip || ferr != nil {
r.handleError(ferr,w,req,user)
}
ferr = r.routeSwitch(w, req, user, prefix, extraData)
if ferr != nil {
r.handleError(ferr,w,req,user)
}
hTbl.VhookNoRet("router_end", w, req, user, prefix, extraData)
//common.StoppedServer("Profile end")
}

View File

@ -773,10 +773,18 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w = common.GzipResponseWriter{Writer: gz, ResponseWriter: w}
}
ferr := r.routeSwitch(w, req, user, prefix, extraData)
// TODO: Use the same hook table as downstream
hTbl := common.GetHookTable()
skip, ferr := hTbl.VhookSkippable("router_pre_route", w, req, user, prefix, extraData)
if skip || ferr != nil {
r.handleError(ferr,w,req,user)
}
ferr = r.routeSwitch(w, req, user, prefix, extraData)
if ferr != nil {
r.handleError(ferr,w,req,user)
}
hTbl.VhookNoRet("router_end", w, req, user, prefix, extraData)
//common.StoppedServer("Profile end")
}

View File

@ -21,20 +21,27 @@ func Backups(w http.ResponseWriter, r *http.Request, user common.User, backupURL
backupURL = common.Stripslashes(backupURL)
var ext = filepath.Ext("./backups/" + backupURL)
if ext == ".sql" {
info, err := os.Stat("./backups/" + backupURL)
if err != nil {
return common.NotFound(w, r, basePage.Header)
}
// TODO: Change the served filename to gosora_backup_%timestamp%.sql, the time the file was generated, not when it was modified aka what the name of it should be
w.Header().Set("Content-Disposition", "attachment; filename=gosora_backup.sql")
w.Header().Set("Content-Length", strconv.FormatInt(info.Size(), 10))
w.Header().Set("Content-Type", "application/sql")
// TODO: Fix the problem where non-existent files aren't greeted with custom 404s on ServeFile()'s side
http.ServeFile(w, r, "./backups/"+backupURL)
return nil
if ext != ".sql" && ext != ".zip" {
return common.NotFound(w, r, basePage.Header)
}
return common.NotFound(w, r, basePage.Header)
info, err := os.Stat("./backups/" + backupURL)
if err != nil {
return common.NotFound(w, r, basePage.Header)
}
w.Header().Set("Content-Length", strconv.FormatInt(info.Size(), 10))
if ext == ".sql" {
// TODO: Change the served filename to gosora_backup_%timestamp%.sql, the time the file was generated, not when it was modified aka what the name of it should be
w.Header().Set("Content-Disposition", "attachment; filename=gosora_backup.sql")
w.Header().Set("Content-Type", "application/sql")
} else {
// TODO: Change the served filename to gosora_backup_%timestamp%.zip, the time the file was generated, not when it was modified aka what the name of it should be
w.Header().Set("Content-Disposition", "attachment; filename=gosora_backup.zip")
w.Header().Set("Content-Type", "application/zip")
}
// TODO: Fix the problem where non-existent files aren't greeted with custom 404s on ServeFile()'s side
http.ServeFile(w, r, "./backups/"+backupURL)
return nil
}
var backupList []common.BackupItem

View File

@ -40,7 +40,6 @@ type JsonReply struct {
func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
// TODO: Use this
js := r.FormValue("js") == "1"
tid, err := strconv.Atoi(r.PostFormValue("tid"))
if err != nil {
return common.PreErrorJSQ("Failed to convert the Topic ID", w, r, js)
@ -54,7 +53,7 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User)
}
// TODO: Add hooks to make use of headerLite
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
if ferr != nil {
return ferr
}
@ -189,6 +188,12 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User)
page = common.LastPage(nTopic.PostCount-(len(rids)+offset), common.Config.ItemsPerPage)
}
counters.PostCounter.Bump()
skip, rerr := lite.Hooks.VhookSkippable("action_end_create_reply", reply.ID)
if skip || rerr != nil {
return rerr
}
prid, _ := strconv.Atoi(r.FormValue("prid"))
if js && (prid == 0 || rids[0] == prid) {
outBytes, err := json.Marshal(JsonReply{common.ParseMessage(reply.Content, topic.ParentID, "forums")})
@ -203,8 +208,6 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User)
}
http.Redirect(w, r, "/topic/"+strconv.Itoa(tid)+spage+"#post-"+strconv.Itoa(reply.ID), http.StatusSeeOther)
}
counters.PostCounter.Bump()
return nil
}

View File

@ -444,7 +444,7 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
}
// TODO: Add hooks to make use of headerLite
_, ferr := common.SimpleForumUserCheck(w, r, &user, fid)
lite, ferr := common.SimpleForumUserCheck(w, r, &user, fid)
if ferr != nil {
return ferr
}
@ -537,6 +537,11 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
counters.PostCounter.Bump()
counters.TopicCounter.Bump()
// TODO: Pass more data to this hook?
skip, rerr := lite.Hooks.VhookSkippable("action_end_create_topic", tid)
if skip || rerr != nil {
return rerr
}
http.Redirect(w, r, "/topic/"+strconv.Itoa(tid), http.StatusSeeOther)
return nil
}