// 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" "./routes" ) var ErrNoRoute = errors.New("That route doesn't exist.") // TODO: What about the /uploads/ route? x.x var RouteMap = map[string]interface{}{ "routeAPI": routeAPI, "routes.Overview": routes.Overview, "routes.CustomPage": routes.CustomPage, "routeForums": routeForums, "routeForum": routeForum, "routeChangeTheme": routeChangeTheme, "routeShowAttachment": routeShowAttachment, "routeWebsockets": routeWebsockets, "routeReportSubmit": routeReportSubmit, "routes.CreateTopic": routes.CreateTopic, "routeTopics": routeTopics, "routePanelForums": routePanelForums, "routePanelForumsCreateSubmit": routePanelForumsCreateSubmit, "routePanelForumsDelete": routePanelForumsDelete, "routePanelForumsDeleteSubmit": routePanelForumsDeleteSubmit, "routePanelForumsEdit": routePanelForumsEdit, "routePanelForumsEditSubmit": routePanelForumsEditSubmit, "routePanelForumsEditPermsSubmit": routePanelForumsEditPermsSubmit, "routePanelForumsEditPermsAdvance": routePanelForumsEditPermsAdvance, "routePanelForumsEditPermsAdvanceSubmit": routePanelForumsEditPermsAdvanceSubmit, "routePanelSettings": routePanelSettings, "routePanelSettingEdit": routePanelSettingEdit, "routePanelSettingEditSubmit": routePanelSettingEditSubmit, "routePanelWordFilters": routePanelWordFilters, "routePanelWordFiltersCreateSubmit": routePanelWordFiltersCreateSubmit, "routePanelWordFiltersEdit": routePanelWordFiltersEdit, "routePanelWordFiltersEditSubmit": routePanelWordFiltersEditSubmit, "routePanelWordFiltersDeleteSubmit": routePanelWordFiltersDeleteSubmit, "routePanelThemes": routePanelThemes, "routePanelThemesSetDefault": routePanelThemesSetDefault, "routePanelPlugins": routePanelPlugins, "routePanelPluginsActivate": routePanelPluginsActivate, "routePanelPluginsDeactivate": routePanelPluginsDeactivate, "routePanelPluginsInstall": routePanelPluginsInstall, "routePanelUsers": routePanelUsers, "routePanelUsersEdit": routePanelUsersEdit, "routePanelUsersEditSubmit": routePanelUsersEditSubmit, "routePanelAnalyticsViews": routePanelAnalyticsViews, "routePanelAnalyticsRoutes": routePanelAnalyticsRoutes, "routePanelAnalyticsAgents": routePanelAnalyticsAgents, "routePanelAnalyticsSystems": routePanelAnalyticsSystems, "routePanelAnalyticsRouteViews": routePanelAnalyticsRouteViews, "routePanelAnalyticsAgentViews": routePanelAnalyticsAgentViews, "routePanelAnalyticsSystemViews": routePanelAnalyticsSystemViews, "routePanelAnalyticsPosts": routePanelAnalyticsPosts, "routePanelAnalyticsTopics": routePanelAnalyticsTopics, "routePanelGroups": routePanelGroups, "routePanelGroupsEdit": routePanelGroupsEdit, "routePanelGroupsEditPerms": routePanelGroupsEditPerms, "routePanelGroupsEditSubmit": routePanelGroupsEditSubmit, "routePanelGroupsEditPermsSubmit": routePanelGroupsEditPermsSubmit, "routePanelGroupsCreateSubmit": routePanelGroupsCreateSubmit, "routePanelBackups": routePanelBackups, "routePanelLogsMod": routePanelLogsMod, "routePanelDebug": routePanelDebug, "routePanelDashboard": routePanelDashboard, "routes.AccountEditCritical": routes.AccountEditCritical, "routeAccountEditCriticalSubmit": routeAccountEditCriticalSubmit, "routeAccountEditAvatar": routeAccountEditAvatar, "routeAccountEditAvatarSubmit": routeAccountEditAvatarSubmit, "routeAccountEditUsername": routeAccountEditUsername, "routeAccountEditUsernameSubmit": routeAccountEditUsernameSubmit, "routeAccountEditEmail": routeAccountEditEmail, "routeAccountEditEmailTokenSubmit": routeAccountEditEmailTokenSubmit, "routeProfile": routeProfile, "routes.BanUserSubmit": routes.BanUserSubmit, "routes.UnbanUser": routes.UnbanUser, "routes.ActivateUser": routes.ActivateUser, "routes.IPSearch": routes.IPSearch, "routes.CreateTopicSubmit": routes.CreateTopicSubmit, "routes.EditTopicSubmit": routes.EditTopicSubmit, "routes.DeleteTopicSubmit": routes.DeleteTopicSubmit, "routes.StickTopicSubmit": routes.StickTopicSubmit, "routes.UnstickTopicSubmit": routes.UnstickTopicSubmit, "routes.LockTopicSubmit": routes.LockTopicSubmit, "routes.UnlockTopicSubmit": routes.UnlockTopicSubmit, "routes.MoveTopicSubmit": routes.MoveTopicSubmit, "routeLikeTopicSubmit": routeLikeTopicSubmit, "routes.ViewTopic": routes.ViewTopic, "routeCreateReplySubmit": routeCreateReplySubmit, "routes.ReplyEditSubmit": routes.ReplyEditSubmit, "routes.ReplyDeleteSubmit": routes.ReplyDeleteSubmit, "routeReplyLikeSubmit": routeReplyLikeSubmit, "routeProfileReplyCreateSubmit": routeProfileReplyCreateSubmit, "routes.ProfileReplyEditSubmit": routes.ProfileReplyEditSubmit, "routes.ProfileReplyDeleteSubmit": routes.ProfileReplyDeleteSubmit, "routes.PollVote": routes.PollVote, "routes.PollResults": routes.PollResults, "routes.AccountLogin": routes.AccountLogin, "routes.AccountRegister": routes.AccountRegister, "routeLogout": routeLogout, "routes.AccountLoginSubmit": routes.AccountLoginSubmit, "routes.AccountRegisterSubmit": routes.AccountRegisterSubmit, "routeDynamic": routeDynamic, "routeUploads": routeUploads, "BadRoute": BadRoute, } // ! NEVER RELY ON THESE REMAINING THE SAME BETWEEN COMMITS var routeMapEnum = map[string]int{ "routeAPI": 0, "routes.Overview": 1, "routes.CustomPage": 2, "routeForums": 3, "routeForum": 4, "routeChangeTheme": 5, "routeShowAttachment": 6, "routeWebsockets": 7, "routeReportSubmit": 8, "routes.CreateTopic": 9, "routeTopics": 10, "routePanelForums": 11, "routePanelForumsCreateSubmit": 12, "routePanelForumsDelete": 13, "routePanelForumsDeleteSubmit": 14, "routePanelForumsEdit": 15, "routePanelForumsEditSubmit": 16, "routePanelForumsEditPermsSubmit": 17, "routePanelForumsEditPermsAdvance": 18, "routePanelForumsEditPermsAdvanceSubmit": 19, "routePanelSettings": 20, "routePanelSettingEdit": 21, "routePanelSettingEditSubmit": 22, "routePanelWordFilters": 23, "routePanelWordFiltersCreateSubmit": 24, "routePanelWordFiltersEdit": 25, "routePanelWordFiltersEditSubmit": 26, "routePanelWordFiltersDeleteSubmit": 27, "routePanelThemes": 28, "routePanelThemesSetDefault": 29, "routePanelPlugins": 30, "routePanelPluginsActivate": 31, "routePanelPluginsDeactivate": 32, "routePanelPluginsInstall": 33, "routePanelUsers": 34, "routePanelUsersEdit": 35, "routePanelUsersEditSubmit": 36, "routePanelAnalyticsViews": 37, "routePanelAnalyticsRoutes": 38, "routePanelAnalyticsAgents": 39, "routePanelAnalyticsSystems": 40, "routePanelAnalyticsRouteViews": 41, "routePanelAnalyticsAgentViews": 42, "routePanelAnalyticsSystemViews": 43, "routePanelAnalyticsPosts": 44, "routePanelAnalyticsTopics": 45, "routePanelGroups": 46, "routePanelGroupsEdit": 47, "routePanelGroupsEditPerms": 48, "routePanelGroupsEditSubmit": 49, "routePanelGroupsEditPermsSubmit": 50, "routePanelGroupsCreateSubmit": 51, "routePanelBackups": 52, "routePanelLogsMod": 53, "routePanelDebug": 54, "routePanelDashboard": 55, "routes.AccountEditCritical": 56, "routeAccountEditCriticalSubmit": 57, "routeAccountEditAvatar": 58, "routeAccountEditAvatarSubmit": 59, "routeAccountEditUsername": 60, "routeAccountEditUsernameSubmit": 61, "routeAccountEditEmail": 62, "routeAccountEditEmailTokenSubmit": 63, "routeProfile": 64, "routes.BanUserSubmit": 65, "routes.UnbanUser": 66, "routes.ActivateUser": 67, "routes.IPSearch": 68, "routes.CreateTopicSubmit": 69, "routes.EditTopicSubmit": 70, "routes.DeleteTopicSubmit": 71, "routes.StickTopicSubmit": 72, "routes.UnstickTopicSubmit": 73, "routes.LockTopicSubmit": 74, "routes.UnlockTopicSubmit": 75, "routes.MoveTopicSubmit": 76, "routeLikeTopicSubmit": 77, "routes.ViewTopic": 78, "routeCreateReplySubmit": 79, "routes.ReplyEditSubmit": 80, "routes.ReplyDeleteSubmit": 81, "routeReplyLikeSubmit": 82, "routeProfileReplyCreateSubmit": 83, "routes.ProfileReplyEditSubmit": 84, "routes.ProfileReplyDeleteSubmit": 85, "routes.PollVote": 86, "routes.PollResults": 87, "routes.AccountLogin": 88, "routes.AccountRegister": 89, "routeLogout": 90, "routes.AccountLoginSubmit": 91, "routes.AccountRegisterSubmit": 92, "routeDynamic": 93, "routeUploads": 94, "BadRoute": 95, } var reverseRouteMapEnum = map[int]string{ 0: "routeAPI", 1: "routes.Overview", 2: "routes.CustomPage", 3: "routeForums", 4: "routeForum", 5: "routeChangeTheme", 6: "routeShowAttachment", 7: "routeWebsockets", 8: "routeReportSubmit", 9: "routes.CreateTopic", 10: "routeTopics", 11: "routePanelForums", 12: "routePanelForumsCreateSubmit", 13: "routePanelForumsDelete", 14: "routePanelForumsDeleteSubmit", 15: "routePanelForumsEdit", 16: "routePanelForumsEditSubmit", 17: "routePanelForumsEditPermsSubmit", 18: "routePanelForumsEditPermsAdvance", 19: "routePanelForumsEditPermsAdvanceSubmit", 20: "routePanelSettings", 21: "routePanelSettingEdit", 22: "routePanelSettingEditSubmit", 23: "routePanelWordFilters", 24: "routePanelWordFiltersCreateSubmit", 25: "routePanelWordFiltersEdit", 26: "routePanelWordFiltersEditSubmit", 27: "routePanelWordFiltersDeleteSubmit", 28: "routePanelThemes", 29: "routePanelThemesSetDefault", 30: "routePanelPlugins", 31: "routePanelPluginsActivate", 32: "routePanelPluginsDeactivate", 33: "routePanelPluginsInstall", 34: "routePanelUsers", 35: "routePanelUsersEdit", 36: "routePanelUsersEditSubmit", 37: "routePanelAnalyticsViews", 38: "routePanelAnalyticsRoutes", 39: "routePanelAnalyticsAgents", 40: "routePanelAnalyticsSystems", 41: "routePanelAnalyticsRouteViews", 42: "routePanelAnalyticsAgentViews", 43: "routePanelAnalyticsSystemViews", 44: "routePanelAnalyticsPosts", 45: "routePanelAnalyticsTopics", 46: "routePanelGroups", 47: "routePanelGroupsEdit", 48: "routePanelGroupsEditPerms", 49: "routePanelGroupsEditSubmit", 50: "routePanelGroupsEditPermsSubmit", 51: "routePanelGroupsCreateSubmit", 52: "routePanelBackups", 53: "routePanelLogsMod", 54: "routePanelDebug", 55: "routePanelDashboard", 56: "routes.AccountEditCritical", 57: "routeAccountEditCriticalSubmit", 58: "routeAccountEditAvatar", 59: "routeAccountEditAvatarSubmit", 60: "routeAccountEditUsername", 61: "routeAccountEditUsernameSubmit", 62: "routeAccountEditEmail", 63: "routeAccountEditEmailTokenSubmit", 64: "routeProfile", 65: "routes.BanUserSubmit", 66: "routes.UnbanUser", 67: "routes.ActivateUser", 68: "routes.IPSearch", 69: "routes.CreateTopicSubmit", 70: "routes.EditTopicSubmit", 71: "routes.DeleteTopicSubmit", 72: "routes.StickTopicSubmit", 73: "routes.UnstickTopicSubmit", 74: "routes.LockTopicSubmit", 75: "routes.UnlockTopicSubmit", 76: "routes.MoveTopicSubmit", 77: "routeLikeTopicSubmit", 78: "routes.ViewTopic", 79: "routeCreateReplySubmit", 80: "routes.ReplyEditSubmit", 81: "routes.ReplyDeleteSubmit", 82: "routeReplyLikeSubmit", 83: "routeProfileReplyCreateSubmit", 84: "routes.ProfileReplyEditSubmit", 85: "routes.ProfileReplyDeleteSubmit", 86: "routes.PollVote", 87: "routes.PollResults", 88: "routes.AccountLogin", 89: "routes.AccountRegister", 90: "routeLogout", 91: "routes.AccountLoginSubmit", 92: "routes.AccountRegisterSubmit", 93: "routeDynamic", 94: "routeUploads", 95: "BadRoute", } var osMapEnum = map[string]int{ "unknown": 0, "windows": 1, "linux": 2, "mac": 3, "android": 4, "iphone": 5, } var reverseOSMapEnum = map[int]string{ 0: "unknown", 1: "windows", 2: "linux", 3: "mac", 4: "android", 5: "iphone", } var agentMapEnum = map[string]int{ "unknown": 0, "firefox": 1, "chrome": 2, "opera": 3, "safari": 4, "edge": 5, "internetexplorer": 6, "trident": 7, "androidchrome": 8, "mobilesafari": 9, "samsung": 10, "ucbrowser": 11, "googlebot": 12, "yandex": 13, "bing": 14, "baidu": 15, "duckduckgo": 16, "seznambot": 17, "discord": 18, "twitter": 19, "cloudflare": 20, "uptimebot": 21, "discourse": 22, "lynx": 23, "blank": 24, "malformed": 25, "suspicious": 26, "zgrab": 27, } var reverseAgentMapEnum = map[int]string{ 0: "unknown", 1: "firefox", 2: "chrome", 3: "opera", 4: "safari", 5: "edge", 6: "internetexplorer", 7: "trident", 8: "androidchrome", 9: "mobilesafari", 10: "samsung", 11: "ucbrowser", 12: "googlebot", 13: "yandex", 14: "bing", 15: "baidu", 16: "duckduckgo", 17: "seznambot", 18: "discord", 19: "twitter", 20: "cloudflare", 21: "uptimebot", 22: "discourse", 23: "lynx", 24: "blank", 25: "malformed", 26: "suspicious", 27: "zgrab", } var markToAgent = map[string]string{ "OPR":"opera", "Chrome":"chrome", "Firefox":"firefox", "MSIE":"internetexplorer", "Trident":"trident", // Hack to support IE11 "Edge":"edge", "Lynx":"lynx", // There's a rare android variant of lynx which isn't covered by this "SamsungBrowser":"samsung", "UCBrowser":"ucbrowser", "Google":"googlebot", "Googlebot":"googlebot", "yandex": "yandex", // from the URL "DuckDuckBot":"duckduckgo", "Baiduspider":"baidu", "bingbot":"bing", "BingPreview":"bing", "SeznamBot":"seznambot", "CloudFlare":"cloudflare", // Track alwayson specifically in case there are other bots? "Uptimebot":"uptimebot", "Discordbot":"discord", "Twitterbot":"twitter", "Discourse":"discourse", "zgrab":"zgrab", } /*var agentRank = map[string]int{ "opera":9, "chrome":8, "safari":1, }*/ // TODO: Stop spilling these into the package scope? func init() { common.SetRouteMapEnum(routeMapEnum) common.SetReverseRouteMapEnum(reverseRouteMapEnum) common.SetAgentMapEnum(agentMapEnum) common.SetReverseAgentMapEnum(reverseAgentMapEnum) common.SetOSMapEnum(osMapEnum) common.SetReverseOSMapEnum(reverseOSMapEnum) } type GenRouter struct { UploadHandler func(http.ResponseWriter, *http.Request) extraRoutes 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, extraRoutes: 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() defer router.Unlock() router.extraRoutes[pattern] = handle } func (router *GenRouter) RemoveFunc(pattern string) error { router.Lock() defer router.Unlock() _, ok := router.extraRoutes[pattern] if !ok { return ErrNoRoute } delete(router.extraRoutes, pattern) return nil } func (router *GenRouter) DumpRequest(req *http.Request) { log.Print("UA: ", req.UserAgent()) log.Print("Method: ", req.Method) for key, value := range req.Header { for _, vvalue := range value { log.Print("Header '" + key + "': " + vvalue + "!!") } } log.Print("req.Host: ", req.Host) log.Print("req.URL.Path: ", req.URL.Path) log.Print("req.URL.RawQuery: ", req.URL.RawQuery) log.Print("req.Referer(): ", req.Referer()) log.Print("req.RemoteAddr: ", req.RemoteAddr) } func (router *GenRouter) SuspiciousRequest(req *http.Request) { log.Print("Suspicious Request") router.DumpRequest(req) common.AgentViewCounter.Bump(26) } // TODO: Pass the default route or config struct to the router rather than accessing it via a package global // TODO: SetDefaultRoute // TODO: GetDefaultRoute func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Redirect www. requests to the right place if req.Host == "www." + common.Site.Host { w.Header().Set("Connection", "close") var s string if common.Site.EnableSsl { s = "s" } dest := "http"+s+"://" + req.Host + req.URL.Path if len(req.URL.RawQuery) > 0 { dest += "?" + req.URL.RawQuery } http.Redirect(w, req, dest, http.StatusMovedPermanently) return } // Deflect malformed requests if len(req.URL.Path) == 0 || req.URL.Path[0] != '/' || req.Host != common.Site.Host { w.WriteHeader(200) // 400 w.Write([]byte("")) log.Print("Malformed Request") router.DumpRequest(req) common.AgentViewCounter.Bump(25) return } if common.Dev.DebugMode { // TODO: Cover more suspicious strings and at a lower layer than this for _, char := range req.URL.Path { if char != '&' && !(char > 44 && char < 58) && char != '=' && char != '?' && !(char > 64 && char < 91) && char != '\\' && char != '_' && !(char > 96 && char < 123) { router.SuspiciousRequest(req) break } } lowerPath := strings.ToLower(req.URL.Path) // TODO: Flag any requests which has a dot with anything but a number after that if strings.Contains(req.URL.Path,"..") || strings.Contains(req.URL.Path,"--") || strings.Contains(lowerPath,".php") || strings.Contains(lowerPath,".asp") || strings.Contains(lowerPath,".cgi") || strings.Contains(lowerPath,".py") || strings.Contains(lowerPath,".sql") { router.SuspiciousRequest(req) } } var prefix, extraData string prefix = req.URL.Path[0:strings.IndexByte(req.URL.Path[1:],'/') + 1] if req.URL.Path[len(req.URL.Path) - 1] != '/' { extraData = 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 routes.StaticFile") router.DumpRequest(req) } if prefix == "/static" { req.URL.Path += extraData routes.StaticFile(w, req) return } if common.Dev.SuperDebug { log.Print("before PreRoute") } // Increment the global view counter common.GlobalViewCounter.Bump() // Track the user agents. Unfortunately, everyone pretends to be Mozilla, so this'll be a little less efficient than I would like. // TODO: Add a setting to disable this? // TODO: Use a more efficient detector instead of smashing every possible combination in ua := strings.TrimSpace(strings.Replace(strings.TrimPrefix(req.UserAgent(),"Mozilla/5.0 ")," Safari/537.36","",-1)) // Noise, no one's going to be running this and it would require some sort of agent ranking system to determine which identifier should be prioritised over another if ua == "" { common.AgentViewCounter.Bump(24) if common.Dev.DebugMode { log.Print("Blank UA: ", req.UserAgent()) router.DumpRequest(req) } } else { var runeEquals = func(a []rune, b []rune) bool { if len(a) != len(b) { return false } for i, item := range a { if item != b[i] { return false } } return true } // WIP UA Parser var indices []int var items []string var buffer []rune for index, item := range ua { if (item > 64 && item < 91) || (item > 96 && item < 123) { buffer = append(buffer, item) } else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || (item == ':' && runeEquals(buffer,[]rune("http"))) || item == ',' || item == '/' { if len(buffer) != 0 { items = append(items, string(buffer)) indices = append(indices, index - 1) buffer = buffer[:0] } } else { // TODO: Test this items = items[:0] indices = indices[:0] router.SuspiciousRequest(req) log.Print("UA Buffer: ", buffer) log.Print("UA Buffer String: ", string(buffer)) break } } // Iterate over this in reverse as the real UA tends to be on the right side var agent string for i := len(items) - 1; i >= 0; i-- { fAgent, ok := markToAgent[items[i]] if ok { agent = fAgent if agent != "safari" { break } } } if common.Dev.SuperDebug { log.Print("parsed agent: ", agent) } var os string for _, mark := range items { switch(mark) { case "Windows": os = "windows" case "Linux": os = "linux" case "Mac": os = "mac" case "iPhone": os = "iphone" case "Android": os = "android" } } if os == "" { os = "unknown" } if common.Dev.SuperDebug { log.Print("os: ", os) log.Printf("items: %+v\n",items) } // Special handling switch(agent) { case "chrome": if os == "android" { agent = "androidchrome" } case "safari": if os == "iphone" { agent = "mobilesafari" } case "trident": // Hack to support IE11, change this after we start logging versions if strings.Contains(ua,"rv:11") { agent = "internetexplorer" } case "zgrab": router.SuspiciousRequest(req) } if agent == "" { common.AgentViewCounter.Bump(0) if common.Dev.DebugMode { log.Print("Unknown UA: ", req.UserAgent()) router.DumpRequest(req) } } else { common.AgentViewCounter.Bump(agentMapEnum[agent]) } common.OSViewCounter.Bump(osMapEnum[os]) } // Deal with the session stuff, etc. user, ok := common.PreRoute(w, req) if !ok { return } if common.Dev.SuperDebug { log.Print("after PreRoute") log.Print("routeMapEnum: ", routeMapEnum) } var err common.RouteError switch(prefix) { case "/api": common.RouteViewCounter.Bump(0) err = routeAPI(w,req,user) if err != nil { router.handleError(err,w,req,user) } case "/overview": common.RouteViewCounter.Bump(1) err = routes.Overview(w,req,user) if err != nil { router.handleError(err,w,req,user) } case "/pages": common.RouteViewCounter.Bump(2) err = routes.CustomPage(w,req,user,extraData) if err != nil { router.handleError(err,w,req,user) } case "/forums": common.RouteViewCounter.Bump(3) err = routeForums(w,req,user) if err != nil { router.handleError(err,w,req,user) } case "/forum": common.RouteViewCounter.Bump(4) err = routeForum(w,req,user,extraData) if err != nil { router.handleError(err,w,req,user) } case "/theme": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(5) err = routeChangeTheme(w,req,user) if err != nil { router.handleError(err,w,req,user) } case "/attachs": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(6) err = routeShowAttachment(w,req,user,extraData) if err != nil { router.handleError(err,w,req,user) } case "/ws": req.URL.Path += extraData common.RouteViewCounter.Bump(7) err = routeWebsockets(w,req,user) if err != nil { router.handleError(err,w,req,user) } case "/report": err = common.NoBanned(w,req,user) if err != nil { router.handleError(err,w,req,user) return } switch(req.URL.Path) { case "/report/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 } common.RouteViewCounter.Bump(8) err = routeReportSubmit(w,req,user,extraData) } 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 } common.RouteViewCounter.Bump(9) err = routes.CreateTopic(w,req,user,extraData) default: common.RouteViewCounter.Bump(10) 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/": common.RouteViewCounter.Bump(11) err = routePanelForums(w,req,user) case "/panel/forums/create/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(12) err = routePanelForumsCreateSubmit(w,req,user) case "/panel/forums/delete/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(13) err = routePanelForumsDelete(w,req,user,extraData) case "/panel/forums/delete/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(14) err = routePanelForumsDeleteSubmit(w,req,user,extraData) case "/panel/forums/edit/": common.RouteViewCounter.Bump(15) err = routePanelForumsEdit(w,req,user,extraData) case "/panel/forums/edit/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(16) err = routePanelForumsEditSubmit(w,req,user,extraData) case "/panel/forums/edit/perms/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(17) err = routePanelForumsEditPermsSubmit(w,req,user,extraData) case "/panel/forums/edit/perms/": common.RouteViewCounter.Bump(18) err = routePanelForumsEditPermsAdvance(w,req,user,extraData) case "/panel/forums/edit/perms/adv/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(19) err = routePanelForumsEditPermsAdvanceSubmit(w,req,user,extraData) case "/panel/settings/": common.RouteViewCounter.Bump(20) err = routePanelSettings(w,req,user) case "/panel/settings/edit/": common.RouteViewCounter.Bump(21) err = routePanelSettingEdit(w,req,user,extraData) case "/panel/settings/edit/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(22) err = routePanelSettingEditSubmit(w,req,user,extraData) case "/panel/settings/word-filters/": common.RouteViewCounter.Bump(23) err = routePanelWordFilters(w,req,user) case "/panel/settings/word-filters/create/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(24) err = routePanelWordFiltersCreateSubmit(w,req,user) case "/panel/settings/word-filters/edit/": common.RouteViewCounter.Bump(25) err = routePanelWordFiltersEdit(w,req,user,extraData) case "/panel/settings/word-filters/edit/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(26) err = routePanelWordFiltersEditSubmit(w,req,user,extraData) case "/panel/settings/word-filters/delete/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(27) err = routePanelWordFiltersDeleteSubmit(w,req,user,extraData) case "/panel/themes/": common.RouteViewCounter.Bump(28) err = routePanelThemes(w,req,user) case "/panel/themes/default/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(29) err = routePanelThemesSetDefault(w,req,user,extraData) case "/panel/plugins/": common.RouteViewCounter.Bump(30) err = routePanelPlugins(w,req,user) case "/panel/plugins/activate/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(31) err = routePanelPluginsActivate(w,req,user,extraData) case "/panel/plugins/deactivate/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(32) err = routePanelPluginsDeactivate(w,req,user,extraData) case "/panel/plugins/install/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(33) err = routePanelPluginsInstall(w,req,user,extraData) case "/panel/users/": common.RouteViewCounter.Bump(34) err = routePanelUsers(w,req,user) case "/panel/users/edit/": common.RouteViewCounter.Bump(35) err = routePanelUsersEdit(w,req,user,extraData) case "/panel/users/edit/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(36) err = routePanelUsersEditSubmit(w,req,user,extraData) case "/panel/analytics/views/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(37) err = routePanelAnalyticsViews(w,req,user) case "/panel/analytics/routes/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(38) err = routePanelAnalyticsRoutes(w,req,user) case "/panel/analytics/agents/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(39) err = routePanelAnalyticsAgents(w,req,user) case "/panel/analytics/systems/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(40) err = routePanelAnalyticsSystems(w,req,user) case "/panel/analytics/route/": common.RouteViewCounter.Bump(41) err = routePanelAnalyticsRouteViews(w,req,user,extraData) case "/panel/analytics/agent/": common.RouteViewCounter.Bump(42) err = routePanelAnalyticsAgentViews(w,req,user,extraData) case "/panel/analytics/system/": common.RouteViewCounter.Bump(43) err = routePanelAnalyticsSystemViews(w,req,user,extraData) case "/panel/analytics/posts/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(44) err = routePanelAnalyticsPosts(w,req,user) case "/panel/analytics/topics/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(45) err = routePanelAnalyticsTopics(w,req,user) case "/panel/groups/": common.RouteViewCounter.Bump(46) err = routePanelGroups(w,req,user) case "/panel/groups/edit/": common.RouteViewCounter.Bump(47) err = routePanelGroupsEdit(w,req,user,extraData) case "/panel/groups/edit/perms/": common.RouteViewCounter.Bump(48) err = routePanelGroupsEditPerms(w,req,user,extraData) case "/panel/groups/edit/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(49) err = routePanelGroupsEditSubmit(w,req,user,extraData) case "/panel/groups/edit/perms/submit/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(50) err = routePanelGroupsEditPermsSubmit(w,req,user,extraData) case "/panel/groups/create/": err = common.NoSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(51) err = routePanelGroupsCreateSubmit(w,req,user) case "/panel/backups/": err = common.SuperAdminOnly(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(52) err = routePanelBackups(w,req,user,extraData) case "/panel/logs/mod/": common.RouteViewCounter.Bump(53) err = routePanelLogsMod(w,req,user) case "/panel/debug/": err = common.AdminOnly(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(54) err = routePanelDebug(w,req,user) default: common.RouteViewCounter.Bump(55) err = routePanelDashboard(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 } common.RouteViewCounter.Bump(56) err = routes.AccountEditCritical(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 } common.RouteViewCounter.Bump(57) 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 } common.RouteViewCounter.Bump(58) 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 = common.HandleUploadRoute(w,req,user,common.Config.MaxRequestSize) if err != nil { router.handleError(err,w,req,user) return } err = common.NoUploadSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(59) 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 } common.RouteViewCounter.Bump(60) err = routeAccountEditUsername(w,req,user) case "/user/edit/username/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 } common.RouteViewCounter.Bump(61) 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 } common.RouteViewCounter.Bump(62) err = routeAccountEditEmail(w,req,user) case "/user/edit/token/": 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 } common.RouteViewCounter.Bump(63) err = routeAccountEditEmailTokenSubmit(w,req,user,extraData) default: req.URL.Path += extraData common.RouteViewCounter.Bump(64) err = routeProfile(w,req,user) } if err != nil { router.handleError(err,w,req,user) } case "/users": 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 = common.MemberOnly(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(65) err = routes.BanUserSubmit(w,req,user,extraData) case "/users/unban/": 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 } common.RouteViewCounter.Bump(66) err = routes.UnbanUser(w,req,user,extraData) case "/users/activate/": 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 } common.RouteViewCounter.Bump(67) err = routes.ActivateUser(w,req,user,extraData) case "/users/ips/": err = common.MemberOnly(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(68) err = routes.IPSearch(w,req,user) } if err != nil { router.handleError(err,w,req,user) } case "/topic": switch(req.URL.Path) { case "/topic/create/submit/": err = common.MemberOnly(w,req,user) if err != nil { router.handleError(err,w,req,user) return } err = common.HandleUploadRoute(w,req,user,common.Config.MaxRequestSize) if err != nil { router.handleError(err,w,req,user) return } err = common.NoUploadSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(69) err = routes.CreateTopicSubmit(w,req,user) case "/topic/edit/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 } common.RouteViewCounter.Bump(70) err = routes.EditTopicSubmit(w,req,user,extraData) case "/topic/delete/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 } req.URL.Path += extraData common.RouteViewCounter.Bump(71) err = routes.DeleteTopicSubmit(w,req,user) case "/topic/stick/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 } common.RouteViewCounter.Bump(72) err = routes.StickTopicSubmit(w,req,user,extraData) case "/topic/unstick/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 } common.RouteViewCounter.Bump(73) err = routes.UnstickTopicSubmit(w,req,user,extraData) case "/topic/lock/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 } req.URL.Path += extraData common.RouteViewCounter.Bump(74) err = routes.LockTopicSubmit(w,req,user) case "/topic/unlock/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 } common.RouteViewCounter.Bump(75) err = routes.UnlockTopicSubmit(w,req,user,extraData) case "/topic/move/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 } common.RouteViewCounter.Bump(76) err = routes.MoveTopicSubmit(w,req,user,extraData) case "/topic/like/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 } common.RouteViewCounter.Bump(77) err = routeLikeTopicSubmit(w,req,user,extraData) default: common.RouteViewCounter.Bump(78) err = routes.ViewTopic(w,req,user, extraData) } if err != nil { router.handleError(err,w,req,user) } case "/reply": switch(req.URL.Path) { case "/reply/create/": err = common.MemberOnly(w,req,user) if err != nil { router.handleError(err,w,req,user) return } err = common.HandleUploadRoute(w,req,user,common.Config.MaxRequestSize) if err != nil { router.handleError(err,w,req,user) return } err = common.NoUploadSessionMismatch(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(79) err = routeCreateReplySubmit(w,req,user) case "/reply/edit/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 } common.RouteViewCounter.Bump(80) err = routes.ReplyEditSubmit(w,req,user,extraData) case "/reply/delete/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 } common.RouteViewCounter.Bump(81) err = routes.ReplyDeleteSubmit(w,req,user,extraData) case "/reply/like/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 } common.RouteViewCounter.Bump(82) err = routeReplyLikeSubmit(w,req,user,extraData) } if err != nil { router.handleError(err,w,req,user) } case "/profile": switch(req.URL.Path) { case "/profile/reply/create/": 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 } common.RouteViewCounter.Bump(83) err = routeProfileReplyCreateSubmit(w,req,user) case "/profile/reply/edit/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 } common.RouteViewCounter.Bump(84) err = routes.ProfileReplyEditSubmit(w,req,user,extraData) case "/profile/reply/delete/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 } common.RouteViewCounter.Bump(85) err = routes.ProfileReplyDeleteSubmit(w,req,user,extraData) } if err != nil { router.handleError(err,w,req,user) } case "/poll": switch(req.URL.Path) { case "/poll/vote/": 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 } common.RouteViewCounter.Bump(86) err = routes.PollVote(w,req,user,extraData) case "/poll/results/": common.RouteViewCounter.Bump(87) err = routes.PollResults(w,req,user,extraData) } if err != nil { router.handleError(err,w,req,user) } case "/accounts": switch(req.URL.Path) { case "/accounts/login/": common.RouteViewCounter.Bump(88) err = routes.AccountLogin(w,req,user) case "/accounts/create/": common.RouteViewCounter.Bump(89) err = routes.AccountRegister(w,req,user) case "/accounts/logout/": 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 } common.RouteViewCounter.Bump(90) err = routeLogout(w,req,user) case "/accounts/login/submit/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(91) err = routes.AccountLoginSubmit(w,req,user) case "/accounts/create/submit/": err = common.ParseForm(w,req,user) if err != nil { router.handleError(err,w,req,user) return } common.RouteViewCounter.Bump(92) err = routes.AccountRegisterSubmit(w,req,user) } if err != nil { router.handleError(err,w,req,user) } /*case "/sitemaps": // TODO: Count these views req.URL.Path += extraData err = sitemapSwitch(w,req) if err != nil { router.handleError(err,w,req,user) }*/ case "/uploads": if extraData == "" { common.NotFound(w,req) return } common.RouteViewCounter.Bump(94) req.URL.Path += extraData // TODO: Find a way to propagate errors up from this? router.UploadHandler(w,req) // TODO: Count these views case "": // Stop the favicons, robots.txt file, etc. resolving to the topics list // TODO: Add support for favicons and robots.txt files switch(extraData) { case "robots.txt": err = routeRobotsTxt(w,req) // TODO: Count these views if err != nil { router.handleError(err,w,req,user) } return /*case "sitemap.xml": err = routeSitemapXml(w,req) // TODO: Count these views if err != nil { router.handleError(err,w,req,user) } return*/ } if extraData != "" { common.NotFound(w,req) return } handle, ok := RouteMap[common.Config.DefaultRoute] if !ok { // TODO: Make this a startup error not a runtime one log.Print("Unable to find the default route") common.NotFound(w,req) return } common.RouteViewCounter.Bump(routeMapEnum[common.Config.DefaultRoute]) handle.(func(http.ResponseWriter, *http.Request, common.User) common.RouteError)(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.extraRoutes[req.URL.Path] router.RUnlock() if ok { common.RouteViewCounter.Bump(93) // TODO: Be more specific about *which* dynamic route it is req.URL.Path += extraData err = handle(w,req,user) if err != nil { router.handleError(err,w,req,user) } return } // TODO: Log all bad routes for the admin to figure out where users are going wrong? lowerPath := strings.ToLower(req.URL.Path) if strings.Contains(lowerPath,"admin") || strings.Contains(lowerPath,"sql") || strings.Contains(lowerPath,"manage") || strings.Contains(lowerPath,"//") || strings.Contains(lowerPath,"\\\\") || strings.Contains(lowerPath,"wp") || strings.Contains(lowerPath,"wordpress") || strings.Contains(lowerPath,"config") || strings.Contains(lowerPath,"setup") || strings.Contains(lowerPath,"install") || strings.Contains(lowerPath,"update") || strings.Contains(lowerPath,"php") { router.SuspiciousRequest(req) } common.RouteViewCounter.Bump(95) common.NotFound(w,req) } }