f30ea7a9bb
Moved more queries out of the global stmt holder. Refactored several things.
423 lines
11 KiB
Go
423 lines
11 KiB
Go
// Code generated by. DO NOT EDIT.
|
|
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"strings"
|
|
"sync"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"./common"
|
|
)
|
|
|
|
var ErrNoRoute = errors.New("That route doesn't exist.")
|
|
|
|
type GenRouter struct {
|
|
UploadHandler func(http.ResponseWriter, *http.Request)
|
|
extra_routes map[string]func(http.ResponseWriter, *http.Request, common.User) common.RouteError
|
|
|
|
sync.RWMutex
|
|
}
|
|
|
|
func NewGenRouter(uploads http.Handler) *GenRouter {
|
|
return &GenRouter{
|
|
UploadHandler: http.StripPrefix("/uploads/",uploads).ServeHTTP,
|
|
extra_routes: make(map[string]func(http.ResponseWriter, *http.Request, common.User) common.RouteError),
|
|
}
|
|
}
|
|
|
|
func (router *GenRouter) handleError(err common.RouteError, w http.ResponseWriter, r *http.Request, user common.User) {
|
|
if err.Handled() {
|
|
return
|
|
}
|
|
|
|
if err.Type() == "system" {
|
|
common.InternalErrorJSQ(err, w, r, err.JSON())
|
|
return
|
|
}
|
|
common.LocalErrorJSQ(err.Error(), w, r, user,err.JSON())
|
|
}
|
|
|
|
func (router *GenRouter) Handle(_ string, _ http.Handler) {
|
|
}
|
|
|
|
func (router *GenRouter) HandleFunc(pattern string, handle func(http.ResponseWriter, *http.Request, common.User) common.RouteError) {
|
|
router.Lock()
|
|
router.extra_routes[pattern] = handle
|
|
router.Unlock()
|
|
}
|
|
|
|
func (router *GenRouter) RemoveFunc(pattern string) error {
|
|
router.Lock()
|
|
_, ok := router.extra_routes[pattern]
|
|
if !ok {
|
|
router.Unlock()
|
|
return ErrNoRoute
|
|
}
|
|
delete(router.extra_routes, pattern)
|
|
router.Unlock()
|
|
return nil
|
|
}
|
|
|
|
func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
//if req.URL.Path == "/" {
|
|
// default_route(w,req)
|
|
// return
|
|
//}
|
|
if len(req.URL.Path) == 0 || req.URL.Path[0] != '/' {
|
|
w.WriteHeader(405)
|
|
w.Write([]byte(""))
|
|
return
|
|
}
|
|
|
|
var prefix, extra_data string
|
|
prefix = req.URL.Path[0:strings.IndexByte(req.URL.Path[1:],'/') + 1]
|
|
if req.URL.Path[len(req.URL.Path) - 1] != '/' {
|
|
extra_data = req.URL.Path[strings.LastIndexByte(req.URL.Path,'/') + 1:]
|
|
req.URL.Path = req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/') + 1]
|
|
}
|
|
|
|
if common.Dev.SuperDebug {
|
|
log.Print("before routeStatic")
|
|
log.Print("prefix: ", prefix)
|
|
log.Print("req.URL.Path: ", req.URL.Path)
|
|
log.Print("extra_data: ", extra_data)
|
|
log.Print("req.Referer(): ", req.Referer())
|
|
}
|
|
|
|
if prefix == "/static" {
|
|
req.URL.Path += extra_data
|
|
routeStatic(w, req)
|
|
return
|
|
}
|
|
|
|
if common.Dev.SuperDebug {
|
|
log.Print("before PreRoute")
|
|
}
|
|
|
|
// Deal with the session stuff, etc.
|
|
user, ok := common.PreRoute(w, req)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
if common.Dev.SuperDebug {
|
|
log.Print("after PreRoute")
|
|
}
|
|
|
|
var err common.RouteError
|
|
switch(prefix) {
|
|
case "/api":
|
|
err = routeAPI(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/overview":
|
|
err = routeOverview(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/forums":
|
|
err = routeForums(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/forum":
|
|
err = routeForum(w,req,user,extra_data)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/theme":
|
|
err = routeChangeTheme(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/attachs":
|
|
err = routeShowAttachment(w,req,user,extra_data)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/report":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = common.NoBanned(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = common.NoSessionMismatch(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
switch(req.URL.Path) {
|
|
case "/report/submit/":
|
|
err = routeReportSubmit(w,req,user,extra_data)
|
|
}
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/topics":
|
|
switch(req.URL.Path) {
|
|
case "/topics/create/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeTopicCreate(w,req,user,extra_data)
|
|
default:
|
|
err = routeTopics(w,req,user)
|
|
}
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/panel":
|
|
err = common.SuperModOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
switch(req.URL.Path) {
|
|
case "/panel/forums/":
|
|
err = routePanelForums(w,req,user)
|
|
case "/panel/forums/create/":
|
|
err = routePanelForumsCreateSubmit(w,req,user)
|
|
case "/panel/forums/delete/":
|
|
err = routePanelForumsDelete(w,req,user,extra_data)
|
|
case "/panel/forums/delete/submit/":
|
|
err = routePanelForumsDeleteSubmit(w,req,user,extra_data)
|
|
case "/panel/forums/edit/":
|
|
err = routePanelForumsEdit(w,req,user,extra_data)
|
|
case "/panel/forums/edit/submit/":
|
|
err = routePanelForumsEditSubmit(w,req,user,extra_data)
|
|
case "/panel/forums/edit/perms/submit/":
|
|
err = routePanelForumsEditPermsSubmit(w,req,user,extra_data)
|
|
case "/panel/settings/":
|
|
err = routePanelSettings(w,req,user)
|
|
case "/panel/settings/edit/":
|
|
err = routePanelSetting(w,req,user,extra_data)
|
|
case "/panel/settings/edit/submit/":
|
|
err = routePanelSettingEdit(w,req,user,extra_data)
|
|
case "/panel/settings/word-filters/":
|
|
err = routePanelWordFilters(w,req,user)
|
|
case "/panel/settings/word-filters/create/":
|
|
err = routePanelWordFiltersCreate(w,req,user)
|
|
case "/panel/settings/word-filters/edit/":
|
|
err = routePanelWordFiltersEdit(w,req,user,extra_data)
|
|
case "/panel/settings/word-filters/edit/submit/":
|
|
err = routePanelWordFiltersEditSubmit(w,req,user,extra_data)
|
|
case "/panel/settings/word-filters/delete/submit/":
|
|
err = routePanelWordFiltersDeleteSubmit(w,req,user,extra_data)
|
|
case "/panel/themes/":
|
|
err = routePanelThemes(w,req,user)
|
|
case "/panel/themes/default/":
|
|
err = routePanelThemesSetDefault(w,req,user,extra_data)
|
|
case "/panel/plugins/":
|
|
err = routePanelPlugins(w,req,user)
|
|
case "/panel/plugins/activate/":
|
|
err = routePanelPluginsActivate(w,req,user,extra_data)
|
|
case "/panel/plugins/deactivate/":
|
|
err = routePanelPluginsDeactivate(w,req,user,extra_data)
|
|
case "/panel/plugins/install/":
|
|
err = routePanelPluginsInstall(w,req,user,extra_data)
|
|
case "/panel/users/":
|
|
err = routePanelUsers(w,req,user)
|
|
case "/panel/users/edit/":
|
|
err = routePanelUsersEdit(w,req,user,extra_data)
|
|
case "/panel/users/edit/submit/":
|
|
err = routePanelUsersEditSubmit(w,req,user,extra_data)
|
|
case "/panel/groups/":
|
|
err = routePanelGroups(w,req,user)
|
|
case "/panel/groups/edit/":
|
|
err = routePanelGroupsEdit(w,req,user,extra_data)
|
|
case "/panel/groups/edit/perms/":
|
|
err = routePanelGroupsEditPerms(w,req,user,extra_data)
|
|
case "/panel/groups/edit/submit/":
|
|
err = routePanelGroupsEditSubmit(w,req,user,extra_data)
|
|
case "/panel/groups/edit/perms/submit/":
|
|
err = routePanelGroupsEditPermsSubmit(w,req,user,extra_data)
|
|
case "/panel/groups/create/":
|
|
err = routePanelGroupsCreateSubmit(w,req,user)
|
|
case "/panel/backups/":
|
|
err = routePanelBackups(w,req,user,extra_data)
|
|
case "/panel/logs/mod/":
|
|
err = routePanelLogsMod(w,req,user)
|
|
case "/panel/debug/":
|
|
err = routePanelDebug(w,req,user)
|
|
default:
|
|
err = routePanel(w,req,user)
|
|
}
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/user":
|
|
switch(req.URL.Path) {
|
|
case "/user/edit/critical/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditCritical(w,req,user)
|
|
case "/user/edit/critical/submit/":
|
|
err = common.NoSessionMismatch(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditCriticalSubmit(w,req,user)
|
|
case "/user/edit/avatar/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditAvatar(w,req,user)
|
|
case "/user/edit/avatar/submit/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditAvatarSubmit(w,req,user)
|
|
case "/user/edit/username/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditUsername(w,req,user)
|
|
case "/user/edit/username/submit/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditUsernameSubmit(w,req,user)
|
|
case "/user/edit/email/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditEmail(w,req,user)
|
|
case "/user/edit/token/":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeAccountEditEmailTokenSubmit(w,req,user,extra_data)
|
|
default:
|
|
req.URL.Path += extra_data
|
|
err = routeProfile(w,req,user)
|
|
}
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/users":
|
|
err = common.MemberOnly(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
switch(req.URL.Path) {
|
|
case "/users/ban/submit/":
|
|
err = common.NoSessionMismatch(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeBanSubmit(w,req,user)
|
|
case "/users/unban/":
|
|
err = common.NoSessionMismatch(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeUnban(w,req,user)
|
|
case "/users/activate/":
|
|
err = common.NoSessionMismatch(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
return
|
|
}
|
|
|
|
err = routeActivate(w,req,user)
|
|
case "/users/ips/":
|
|
err = routeIps(w,req,user)
|
|
}
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
case "/uploads":
|
|
if extra_data == "" {
|
|
common.NotFound(w,req)
|
|
return
|
|
}
|
|
req.URL.Path += extra_data
|
|
// TODO: Find a way to propagate errors up from this?
|
|
router.UploadHandler(w,req)
|
|
case "":
|
|
// Stop the favicons, robots.txt file, etc. resolving to the topics list
|
|
// TODO: Add support for favicons and robots.txt files
|
|
switch(extra_data) {
|
|
case "robots.txt":
|
|
err = routeRobotsTxt(w,req)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
return
|
|
}
|
|
|
|
if extra_data != "" {
|
|
common.NotFound(w,req)
|
|
return
|
|
}
|
|
common.Config.DefaultRoute(w,req,user)
|
|
default:
|
|
// A fallback for the routes which haven't been converted to the new router yet or plugins
|
|
router.RLock()
|
|
handle, ok := router.extra_routes[req.URL.Path]
|
|
router.RUnlock()
|
|
|
|
if ok {
|
|
req.URL.Path += extra_data
|
|
err = handle(w,req,user)
|
|
if err != nil {
|
|
router.handleError(err,w,req,user)
|
|
}
|
|
return
|
|
}
|
|
common.NotFound(w,req)
|
|
}
|
|
}
|