diff --git a/extend.go b/extend.go index 9c10f52b..dbe2767f 100644 --- a/extend.go +++ b/extend.go @@ -68,7 +68,11 @@ func (plugin *Plugin) RemoveHook(name string, handler interface{}) { case func(interface{})interface{}: key := plugin.Hooks[name] hook := hooks[name] - hook = append(hook[:key], hook[key + 1:]...) + if len(hook) == 1 { + hook = []func(interface{})interface{}{} + } else { + hook = append(hook[:key], hook[key + 1:]...) + } hooks[name] = hook case func(...interface{}) interface{}: delete(vhooks, name) diff --git a/gen_router.go b/gen_router.go index 4c7bb8c9..59421e10 100644 --- a/gen_router.go +++ b/gen_router.go @@ -57,16 +57,16 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { case "/overview": route_overview(w,req) return - case "/pages": - route_custom_page(w,req) - return case "/forums": route_forums(w,req) return + case "/forum": + route_forum(w,req,extra_data) + return case "/topics": switch(req.URL.Path) { case "/topics/create/": - route_topic_create(w,req, extra_data) + route_topic_create(w,req,extra_data) return default: route_topics(w,req) @@ -81,16 +81,70 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { route_panel_forums_create_submit(w,req) return case "/panel/forums/delete/": - route_panel_forums_delete(w,req, extra_data) + route_panel_forums_delete(w,req,extra_data) return case "/panel/forums/delete/submit/": - route_panel_forums_delete_submit(w,req, extra_data) + route_panel_forums_delete_submit(w,req,extra_data) return case "/panel/forums/edit/": - route_panel_forums_edit(w,req, extra_data) + route_panel_forums_edit(w,req,extra_data) return case "/panel/forums/edit/submit/": - route_panel_forums_edit_submit(w,req, extra_data) + route_panel_forums_edit_submit(w,req,extra_data) + return + case "/panel/settings/": + route_panel_settings(w,req) + return + case "/panel/settings/edit/": + route_panel_setting(w,req,extra_data) + return + case "/panel/settings/edit/submit/": + route_panel_setting_edit(w,req,extra_data) + return + case "/panel/themes/": + route_panel_themes(w,req) + return + case "/panel/themes/default/": + route_panel_themes_default(w,req,extra_data) + return + case "/panel/plugins/": + route_panel_plugins(w,req) + return + case "/panel/plugins/activate/": + route_panel_plugins_activate(w,req,extra_data) + return + case "/panel/plugins/deactivate/": + route_panel_plugins_deactivate(w,req,extra_data) + return + case "/panel/users/": + route_panel_users(w,req) + return + case "/panel/users/edit/": + route_panel_users_edit(w,req,extra_data) + return + case "/panel/users/edit/submit/": + route_panel_users_edit_submit(w,req,extra_data) + return + case "/panel/groups/": + route_panel_groups(w,req) + return + case "/panel/groups/edit/": + route_panel_groups_edit(w,req,extra_data) + return + case "/panel/groups/edit/perms/": + route_panel_groups_edit_perms(w,req,extra_data) + return + case "/panel/groups/edit/submit/": + route_panel_groups_edit_submit(w,req,extra_data) + return + case "/panel/groups/edit/perms/submit/": + route_panel_groups_edit_perms_submit(w,req,extra_data) + return + case "/panel/groups/create/": + route_panel_groups_create_submit(w,req) + return + case "/panel/logs/mod/": + route_panel_logs_mod(w,req) return default: route_panel(w,req) diff --git a/main.go b/main.go index f8ff2523..b7ae8463 100644 --- a/main.go +++ b/main.go @@ -192,7 +192,7 @@ func main(){ ///router.HandleFunc("/topics/create/", route_topic_create) ///router.HandleFunc("/topics/", route_topics) ///router.HandleFunc("/forums/", route_forums) - router.HandleFunc("/forum/", route_forum) + ///router.HandleFunc("/forum/", route_forum) router.HandleFunc("/topic/create/submit/", route_create_topic) router.HandleFunc("/topic/", route_topic_id) router.HandleFunc("/reply/create/", route_create_reply) @@ -247,24 +247,24 @@ func main(){ ///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) - 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) + ///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) router.HandleFunc("/api/", route_api) //router.HandleFunc("/exit/", route_exit) @@ -286,4 +286,4 @@ func main(){ } http.ListenAndServeTLS(":" + server_port, ssl_fullchain, ssl_privkey, router) } -} \ No newline at end of file +} diff --git a/panel_routes.go b/panel_routes.go index 314e981f..3f67420f 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -272,9 +272,7 @@ func route_panel_settings(w http.ResponseWriter, r *http.Request){ } defer rows.Close() - var sname string - var scontent string - var stype string + var sname, scontent, stype string for rows.Next() { err := rows.Scan(&sname,&scontent,&stype) if err != nil { @@ -310,7 +308,7 @@ func route_panel_settings(w http.ResponseWriter, r *http.Request){ templates.ExecuteTemplate(w,"panel-settings.html",pi) } -func route_panel_setting(w http.ResponseWriter, r *http.Request){ +func route_panel_setting(w http.ResponseWriter, r *http.Request, sname string){ user, noticeList, ok := SessionCheck(w,r) if !ok { return @@ -319,9 +317,7 @@ func route_panel_setting(w http.ResponseWriter, r *http.Request){ NoPermissions(w,r,user) return } - - setting := Setting{"","","",""} - setting.Name = r.URL.Path[len("/panel/settings/edit/"):] + setting := Setting{sname,"","",""} err := db.QueryRow("select content, type from settings where name = ?", setting.Name).Scan(&setting.Content,&setting.Type) if err == sql.ErrNoRows { @@ -360,7 +356,7 @@ func route_panel_setting(w http.ResponseWriter, r *http.Request){ templates.ExecuteTemplate(w,"panel-setting.html",pi) } -func route_panel_setting_edit(w http.ResponseWriter, r *http.Request) { +func route_panel_setting_edit(w http.ResponseWriter, r *http.Request, sname string) { user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -382,7 +378,6 @@ func route_panel_setting_edit(w http.ResponseWriter, r *http.Request) { var stype string var sconstraints string - sname := r.URL.Path[len("/panel/settings/edit/submit/"):] scontent := r.PostFormValue("setting-value") err = db.QueryRow("select name, type, constraints from settings where name = ?", sname).Scan(&sname, &stype, &sconstraints) @@ -435,7 +430,7 @@ func route_panel_plugins(w http.ResponseWriter, r *http.Request){ templates.ExecuteTemplate(w,"panel-plugins.html",pi) } -func route_panel_plugins_activate(w http.ResponseWriter, r *http.Request){ +func route_panel_plugins_activate(w http.ResponseWriter, r *http.Request, uname string){ user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -449,7 +444,6 @@ func route_panel_plugins_activate(w http.ResponseWriter, r *http.Request){ return } - uname := r.URL.Path[len("/panel/plugins/activate/"):] plugin, ok := plugins[uname] if !ok { LocalError("The plugin isn't registered in the system",w,r,user) @@ -497,7 +491,7 @@ func route_panel_plugins_activate(w http.ResponseWriter, r *http.Request){ http.Redirect(w,r,"/panel/plugins/",http.StatusSeeOther) } -func route_panel_plugins_deactivate(w http.ResponseWriter, r *http.Request){ +func route_panel_plugins_deactivate(w http.ResponseWriter, r *http.Request, uname string){ user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -512,7 +506,6 @@ func route_panel_plugins_deactivate(w http.ResponseWriter, r *http.Request){ return } - uname := r.URL.Path[len("/panel/plugins/deactivate/"):] plugin, ok := plugins[uname] if !ok { LocalError("The plugin isn't registered in the system",w,r,user) @@ -601,7 +594,7 @@ func route_panel_users(w http.ResponseWriter, r *http.Request){ } } -func route_panel_users_edit(w http.ResponseWriter, r *http.Request){ +func route_panel_users_edit(w http.ResponseWriter, r *http.Request,suid string){ user, noticeList, ok := SessionCheck(w,r) if !ok { return @@ -613,7 +606,7 @@ func route_panel_users_edit(w http.ResponseWriter, r *http.Request){ return } - uid, err := strconv.Atoi(r.URL.Path[len("/panel/users/edit/"):]) + uid, err := strconv.Atoi(suid) if err != nil { LocalError("The provided User ID is not a valid number.",w,r,user) return @@ -651,7 +644,7 @@ func route_panel_users_edit(w http.ResponseWriter, r *http.Request){ } } -func route_panel_users_edit_submit(w http.ResponseWriter, r *http.Request){ +func route_panel_users_edit_submit(w http.ResponseWriter, r *http.Request, suid string){ user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -665,13 +658,13 @@ func route_panel_users_edit_submit(w http.ResponseWriter, r *http.Request){ return } - tid, err := strconv.Atoi(r.URL.Path[len("/panel/users/edit/submit/"):]) + uid, err := strconv.Atoi(suid) if err != nil { LocalError("The provided User ID is not a valid number.",w,r,user) return } - targetUser, err := users.CascadeGet(tid) + targetUser, err := users.CascadeGet(uid) if err == sql.ErrNoRows { LocalError("The user you're trying to edit doesn't exist.",w,r,user) return @@ -687,13 +680,13 @@ func route_panel_users_edit_submit(w http.ResponseWriter, r *http.Request){ newname := html.EscapeString(r.PostFormValue("user-name")) if newname == "" { - LocalError("You didn't put in a username.", w, r, user) + LocalError("You didn't put in a username.",w,r,user) return } newemail := html.EscapeString(r.PostFormValue("user-email")) if newemail == "" { - LocalError("You didn't put in an email address.", w, r, user) + LocalError("You didn't put in an email address.",w,r,user) return } if (newemail != targetUser.Email) && !user.Perms.EditUserEmail { @@ -734,7 +727,7 @@ func route_panel_users_edit_submit(w http.ResponseWriter, r *http.Request){ } if newpassword != "" { - SetPassword(targetUser.ID, newpassword) + SetPassword(targetUser.ID,newpassword) } err = users.Load(targetUser.ID) @@ -790,7 +783,7 @@ func route_panel_groups(w http.ResponseWriter, r *http.Request){ templates.ExecuteTemplate(w,"panel-groups.html",pi) } -func route_panel_groups_edit(w http.ResponseWriter, r *http.Request){ +func route_panel_groups_edit(w http.ResponseWriter, r *http.Request, sgid string){ user, noticeList, ok := SessionCheck(w,r) if !ok { return @@ -800,7 +793,7 @@ func route_panel_groups_edit(w http.ResponseWriter, r *http.Request){ return } - gid, err := strconv.Atoi(r.URL.Path[len("/panel/groups/edit/"):]) + gid, err := strconv.Atoi(sgid) if err != nil { LocalError("The Group ID is not a valid integer.",w,r,user) return @@ -844,7 +837,7 @@ func route_panel_groups_edit(w http.ResponseWriter, r *http.Request){ } } -func route_panel_groups_edit_perms(w http.ResponseWriter, r *http.Request){ +func route_panel_groups_edit_perms(w http.ResponseWriter, r *http.Request, sgid string){ user, noticeList, ok := SessionCheck(w,r) if !ok { return @@ -854,7 +847,7 @@ func route_panel_groups_edit_perms(w http.ResponseWriter, r *http.Request){ return } - gid, err := strconv.Atoi(r.URL.Path[len("/panel/groups/edit/perms/"):]) + gid, err := strconv.Atoi(sgid) if err != nil { LocalError("The Group ID is not a valid integer.",w,r,user) return @@ -917,7 +910,7 @@ func route_panel_groups_edit_perms(w http.ResponseWriter, r *http.Request){ } } -func route_panel_groups_edit_submit(w http.ResponseWriter, r *http.Request){ +func route_panel_groups_edit_submit(w http.ResponseWriter, r *http.Request, sgid string){ user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -931,7 +924,7 @@ func route_panel_groups_edit_submit(w http.ResponseWriter, r *http.Request){ return } - gid, err := strconv.Atoi(r.URL.Path[len("/panel/groups/edit/submit/"):]) + gid, err := strconv.Atoi(sgid) if err != nil { LocalError("The Group ID is not a valid integer.",w,r,user) return @@ -1049,7 +1042,7 @@ func route_panel_groups_edit_submit(w http.ResponseWriter, r *http.Request){ http.Redirect(w,r,"/panel/groups/edit/" + strconv.Itoa(gid),http.StatusSeeOther) } -func route_panel_groups_edit_perms_submit(w http.ResponseWriter, r *http.Request){ +func route_panel_groups_edit_perms_submit(w http.ResponseWriter, r *http.Request, sgid string){ user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -1063,7 +1056,7 @@ func route_panel_groups_edit_perms_submit(w http.ResponseWriter, r *http.Request return } - gid, err := strconv.Atoi(r.URL.Path[len("/panel/groups/edit/perms/submit/"):]) + gid, err := strconv.Atoi(sgid) if err != nil { LocalError("The Group ID is not a valid integer.",w,r,user) return @@ -1091,11 +1084,7 @@ func route_panel_groups_edit_perms_submit(w http.ResponseWriter, r *http.Request pplist := LocalPermList for _, perm := range pplist { pvalue := r.PostFormValue("group-perm-" + perm) - if pvalue == "1" { - pmap[perm] = true - } else { - pmap[perm] = false - } + pmap[perm] = (pvalue == "1") } } @@ -1104,11 +1093,7 @@ func route_panel_groups_edit_perms_submit(w http.ResponseWriter, r *http.Request gplist := GlobalPermList for _, perm := range gplist { pvalue := r.PostFormValue("group-perm-" + perm) - if pvalue == "1" { - pmap[perm] = true - } else { - pmap[perm] = false - } + pmap[perm] = (pvalue == "1") } } @@ -1154,9 +1139,7 @@ func route_panel_groups_create_submit(w http.ResponseWriter, r *http.Request){ } group_tag := r.PostFormValue("group-tag") - var is_admin bool - var is_mod bool - var is_banned bool + var is_admin, is_mod, is_banned bool if user.Perms.EditGroupGlobalPerms { group_type := r.PostFormValue("group-type") if group_type == "Admin" { @@ -1196,8 +1179,7 @@ func route_panel_themes(w http.ResponseWriter, r *http.Request){ return } - var pThemeList []Theme - var vThemeList []Theme + var pThemeList, vThemeList []Theme for _, theme := range themes { if theme.HideFromThemes { continue @@ -1217,7 +1199,7 @@ func route_panel_themes(w http.ResponseWriter, r *http.Request){ } } -func route_panel_themes_default(w http.ResponseWriter, r *http.Request){ +func route_panel_themes_default(w http.ResponseWriter, r *http.Request, uname string){ user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -1231,7 +1213,6 @@ func route_panel_themes_default(w http.ResponseWriter, r *http.Request){ return } - uname := r.URL.Path[len("/panel/themes/default/"):] theme, ok := themes[uname] if !ok { LocalError("The theme isn't registered in the system",w,r,user) diff --git a/router_gen/main.go b/router_gen/main.go index 5717e861..22228610 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -31,7 +31,7 @@ func main() { } out += "\n\t\t\t" + route.Name + "(w,req" for _, item := range route.Vars { - out += ", " + item + out += "," + item } out += ")\n\t\t\treturn" } @@ -59,7 +59,7 @@ func main() { } out += "\n\t\t\t\t\t" + route.Name + "(w,req" for _, item := range route.Vars { - out += ", " + item + out += "," + item } out += ")\n\t\t\t\t\treturn" } diff --git a/router_gen/routes.go b/router_gen/routes.go index b5c20e22..f146d131 100644 --- a/router_gen/routes.go +++ b/router_gen/routes.go @@ -24,8 +24,9 @@ func routes() { //addRoute("default_route","","") addRoute("route_static","/static/","req.URL.Path += extra_data") addRoute("route_overview","/overview/","") - addRoute("route_custom_page","/pages/",""/*,"&extra_data"*/) + //addRoute("route_custom_page","/pages/",""/*,"&extra_data"*/) addRoute("route_forums","/forums/",""/*,"&forums"*/) + addRoute("route_forum","/forum/","","extra_data") //addRoute("route_topic_create","/topics/create/","","extra_data") //addRoute("route_topics","/topics/",""/*,"&groups","&forums"*/) @@ -43,5 +44,29 @@ func routes() { Route{"route_panel_forums_delete_submit","/panel/forums/delete/submit/","",[]string{"extra_data"}}, Route{"route_panel_forums_edit","/panel/forums/edit/","",[]string{"extra_data"}}, Route{"route_panel_forums_edit_submit","/panel/forums/edit/submit/","",[]string{"extra_data"}}, + + Route{"route_panel_settings","/panel/settings/","",[]string{}}, + Route{"route_panel_setting","/panel/settings/edit/","",[]string{"extra_data"}}, + Route{"route_panel_setting_edit","/panel/settings/edit/submit/","",[]string{"extra_data"}}, + + Route{"route_panel_themes","/panel/themes/","",[]string{}}, + Route{"route_panel_themes_default","/panel/themes/default/","",[]string{"extra_data"}}, + + Route{"route_panel_plugins","/panel/plugins/","",[]string{}}, + Route{"route_panel_plugins_activate","/panel/plugins/activate/","",[]string{"extra_data"}}, + Route{"route_panel_plugins_deactivate","/panel/plugins/deactivate/","",[]string{"extra_data"}}, + + Route{"route_panel_users","/panel/users/","",[]string{}}, + Route{"route_panel_users_edit","/panel/users/edit/","",[]string{"extra_data"}}, + Route{"route_panel_users_edit_submit","/panel/users/edit/submit/","",[]string{"extra_data"}}, + + Route{"route_panel_groups","/panel/groups/","",[]string{}}, + Route{"route_panel_groups_edit","/panel/groups/edit/","",[]string{"extra_data"}}, + Route{"route_panel_groups_edit_perms","/panel/groups/edit/perms/","",[]string{"extra_data"}}, + Route{"route_panel_groups_edit_submit","/panel/groups/edit/submit/","",[]string{"extra_data"}}, + Route{"route_panel_groups_edit_perms_submit","/panel/groups/edit/perms/submit/","",[]string{"extra_data"}}, + Route{"route_panel_groups_create_submit","/panel/groups/create/","",[]string{}}, + + Route{"route_panel_logs_mod","/panel/logs/mod/","",[]string{}}, ) } diff --git a/routes.go b/routes.go index fa9951a5..b25ce42e 100644 --- a/routes.go +++ b/routes.go @@ -167,9 +167,9 @@ func route_topics(w http.ResponseWriter, r *http.Request){ } } -func route_forum(w http.ResponseWriter, r *http.Request){ +func route_forum(w http.ResponseWriter, r *http.Request, sfid string){ page, _ := strconv.Atoi(r.FormValue("page")) - fid, err := strconv.Atoi(r.URL.Path[len("/forum/"):]) + fid, err := strconv.Atoi(sfid) if err != nil { PreError("The provided ForumID is not a valid number.",w,r) return