From a9a1d667c046fe92d737634c09561b56e3a3887f Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 12 Aug 2018 01:53:42 +1000 Subject: [PATCH] Added the /api/me/ API endpoint. Moved a script block into an API endpoint. Split the gigantic switch in ServeHTTP into it's own function. Scripts should load more efficiently now. --- common/routes_common.go | 3 + common/user.go | 33 ++ gen_router.go | 712 ++++++++++++++++++++-------------------- public/global.js | 89 ++--- router_gen/main.go | 4 + router_gen/routes.go | 1 + routes/api.go | 33 ++ templates/header.html | 6 - 8 files changed, 486 insertions(+), 395 deletions(-) diff --git a/common/routes_common.go b/common/routes_common.go index 1702a19f..8af46e29 100644 --- a/common/routes_common.go +++ b/common/routes_common.go @@ -138,6 +138,9 @@ func panelUserCheck(w http.ResponseWriter, r *http.Request, user *User) (header } } + //h := w.Header() + //h.Set("Content-Security-Policy", "default-src 'self'") + // TODO: GDPR. Add a global control panel notice warning the admins of staff members who don't have 2FA enabled stats.Users = Users.GlobalCount() stats.Groups = Groups.GlobalCount() diff --git a/common/user.go b/common/user.go index 7e07e068..4b666f4e 100644 --- a/common/user.go +++ b/common/user.go @@ -78,6 +78,39 @@ type WsJSONUser struct { Liked int } +func (user *User) Me() *MeUser { + var groupID = user.Group + if user.TempGroup != 0 { + groupID = user.TempGroup + } + return &MeUser{user.ID, user.Link, user.Name, groupID, user.Active, user.IsMod, user.IsSuperMod, user.IsAdmin, user.IsBanned, user.Session, user.Avatar, user.MicroAvatar, user.Tag, user.Level, user.Score, user.Liked} +} + +// For when users need to see their own data, I've omitted some redundancies and less useful items, so we don't wind up sending them on every request +type MeUser struct { + ID int + Link string + Name string + Group int + Active bool + IsMod bool + IsSuperMod bool + IsAdmin bool + IsBanned bool + + // TODO: Implement these as copies (might already be the case for Perms, but we'll want to look at it's definition anyway) + //Perms Perms + //PluginPerms map[string]bool + + Session string + Avatar string + MicroAvatar string + Tag string + Level int + Score int + Liked int +} + type UserStmts struct { activate *sql.Stmt changeGroup *sql.Stmt diff --git a/gen_router.go b/gen_router.go index 4e2de353..a4efdab5 100644 --- a/gen_router.go +++ b/gen_router.go @@ -29,6 +29,7 @@ var RouteMap = map[string]interface{}{ "routes.ShowAttachment": routes.ShowAttachment, "common.RouteWebsockets": common.RouteWebsockets, "routeAPIPhrases": routeAPIPhrases, + "routes.APIMe": routes.APIMe, "routeJSAntispam": routeJSAntispam, "routeAPI": routeAPI, "routes.ReportSubmit": routes.ReportSubmit, @@ -158,123 +159,124 @@ var routeMapEnum = map[string]int{ "routes.ShowAttachment": 5, "common.RouteWebsockets": 6, "routeAPIPhrases": 7, - "routeJSAntispam": 8, - "routeAPI": 9, - "routes.ReportSubmit": 10, - "routes.CreateTopic": 11, - "routes.TopicList": 12, - "panel.Forums": 13, - "panel.ForumsCreateSubmit": 14, - "panel.ForumsDelete": 15, - "panel.ForumsDeleteSubmit": 16, - "panel.ForumsEdit": 17, - "panel.ForumsEditSubmit": 18, - "panel.ForumsEditPermsSubmit": 19, - "panel.ForumsEditPermsAdvance": 20, - "panel.ForumsEditPermsAdvanceSubmit": 21, - "panel.Settings": 22, - "panel.SettingEdit": 23, - "panel.SettingEditSubmit": 24, - "panel.WordFilters": 25, - "panel.WordFiltersCreateSubmit": 26, - "panel.WordFiltersEdit": 27, - "panel.WordFiltersEditSubmit": 28, - "panel.WordFiltersDeleteSubmit": 29, - "panel.Pages": 30, - "panel.PagesCreateSubmit": 31, - "panel.PagesEdit": 32, - "panel.PagesEditSubmit": 33, - "panel.PagesDeleteSubmit": 34, - "routePanelThemes": 35, - "routePanelThemesSetDefault": 36, - "routePanelThemesMenus": 37, - "routePanelThemesMenusEdit": 38, - "routePanelThemesMenuItemEdit": 39, - "routePanelThemesMenuItemEditSubmit": 40, - "routePanelThemesMenuItemCreateSubmit": 41, - "routePanelThemesMenuItemDeleteSubmit": 42, - "routePanelThemesMenuItemOrderSubmit": 43, - "panel.Plugins": 44, - "panel.PluginsActivate": 45, - "panel.PluginsDeactivate": 46, - "panel.PluginsInstall": 47, - "panel.Users": 48, - "panel.UsersEdit": 49, - "panel.UsersEditSubmit": 50, - "panel.AnalyticsViews": 51, - "panel.AnalyticsRoutes": 52, - "panel.AnalyticsAgents": 53, - "panel.AnalyticsSystems": 54, - "panel.AnalyticsLanguages": 55, - "panel.AnalyticsReferrers": 56, - "panel.AnalyticsRouteViews": 57, - "panel.AnalyticsAgentViews": 58, - "panel.AnalyticsForumViews": 59, - "panel.AnalyticsSystemViews": 60, - "panel.AnalyticsLanguageViews": 61, - "panel.AnalyticsReferrerViews": 62, - "panel.AnalyticsPosts": 63, - "panel.AnalyticsTopics": 64, - "panel.AnalyticsForums": 65, - "routePanelGroups": 66, - "routePanelGroupsEdit": 67, - "routePanelGroupsEditPerms": 68, - "routePanelGroupsEditSubmit": 69, - "routePanelGroupsEditPermsSubmit": 70, - "routePanelGroupsCreateSubmit": 71, - "panel.Backups": 72, - "panel.LogsRegs": 73, - "panel.LogsMod": 74, - "panel.Debug": 75, - "routePanelDashboard": 76, - "routes.AccountEdit": 77, - "routes.AccountEditPassword": 78, - "routes.AccountEditPasswordSubmit": 79, - "routes.AccountEditAvatarSubmit": 80, - "routes.AccountEditUsernameSubmit": 81, - "routes.AccountEditMFA": 82, - "routes.AccountEditMFASetup": 83, - "routes.AccountEditMFASetupSubmit": 84, - "routes.AccountEditMFADisableSubmit": 85, - "routes.AccountEditEmail": 86, - "routes.AccountEditEmailTokenSubmit": 87, - "routes.ViewProfile": 88, - "routes.BanUserSubmit": 89, - "routes.UnbanUser": 90, - "routes.ActivateUser": 91, - "routes.IPSearch": 92, - "routes.CreateTopicSubmit": 93, - "routes.EditTopicSubmit": 94, - "routes.DeleteTopicSubmit": 95, - "routes.StickTopicSubmit": 96, - "routes.UnstickTopicSubmit": 97, - "routes.LockTopicSubmit": 98, - "routes.UnlockTopicSubmit": 99, - "routes.MoveTopicSubmit": 100, - "routes.LikeTopicSubmit": 101, - "routes.ViewTopic": 102, - "routes.CreateReplySubmit": 103, - "routes.ReplyEditSubmit": 104, - "routes.ReplyDeleteSubmit": 105, - "routes.ReplyLikeSubmit": 106, - "routes.ProfileReplyCreateSubmit": 107, - "routes.ProfileReplyEditSubmit": 108, - "routes.ProfileReplyDeleteSubmit": 109, - "routes.PollVote": 110, - "routes.PollResults": 111, - "routes.AccountLogin": 112, - "routes.AccountRegister": 113, - "routes.AccountLogout": 114, - "routes.AccountLoginSubmit": 115, - "routes.AccountLoginMFAVerify": 116, - "routes.AccountLoginMFAVerifySubmit": 117, - "routes.AccountRegisterSubmit": 118, - "routes.DynamicRoute": 119, - "routes.UploadedFile": 120, - "routes.StaticFile": 121, - "routes.RobotsTxt": 122, - "routes.SitemapXml": 123, - "routes.BadRoute": 124, + "routes.APIMe": 8, + "routeJSAntispam": 9, + "routeAPI": 10, + "routes.ReportSubmit": 11, + "routes.CreateTopic": 12, + "routes.TopicList": 13, + "panel.Forums": 14, + "panel.ForumsCreateSubmit": 15, + "panel.ForumsDelete": 16, + "panel.ForumsDeleteSubmit": 17, + "panel.ForumsEdit": 18, + "panel.ForumsEditSubmit": 19, + "panel.ForumsEditPermsSubmit": 20, + "panel.ForumsEditPermsAdvance": 21, + "panel.ForumsEditPermsAdvanceSubmit": 22, + "panel.Settings": 23, + "panel.SettingEdit": 24, + "panel.SettingEditSubmit": 25, + "panel.WordFilters": 26, + "panel.WordFiltersCreateSubmit": 27, + "panel.WordFiltersEdit": 28, + "panel.WordFiltersEditSubmit": 29, + "panel.WordFiltersDeleteSubmit": 30, + "panel.Pages": 31, + "panel.PagesCreateSubmit": 32, + "panel.PagesEdit": 33, + "panel.PagesEditSubmit": 34, + "panel.PagesDeleteSubmit": 35, + "routePanelThemes": 36, + "routePanelThemesSetDefault": 37, + "routePanelThemesMenus": 38, + "routePanelThemesMenusEdit": 39, + "routePanelThemesMenuItemEdit": 40, + "routePanelThemesMenuItemEditSubmit": 41, + "routePanelThemesMenuItemCreateSubmit": 42, + "routePanelThemesMenuItemDeleteSubmit": 43, + "routePanelThemesMenuItemOrderSubmit": 44, + "panel.Plugins": 45, + "panel.PluginsActivate": 46, + "panel.PluginsDeactivate": 47, + "panel.PluginsInstall": 48, + "panel.Users": 49, + "panel.UsersEdit": 50, + "panel.UsersEditSubmit": 51, + "panel.AnalyticsViews": 52, + "panel.AnalyticsRoutes": 53, + "panel.AnalyticsAgents": 54, + "panel.AnalyticsSystems": 55, + "panel.AnalyticsLanguages": 56, + "panel.AnalyticsReferrers": 57, + "panel.AnalyticsRouteViews": 58, + "panel.AnalyticsAgentViews": 59, + "panel.AnalyticsForumViews": 60, + "panel.AnalyticsSystemViews": 61, + "panel.AnalyticsLanguageViews": 62, + "panel.AnalyticsReferrerViews": 63, + "panel.AnalyticsPosts": 64, + "panel.AnalyticsTopics": 65, + "panel.AnalyticsForums": 66, + "routePanelGroups": 67, + "routePanelGroupsEdit": 68, + "routePanelGroupsEditPerms": 69, + "routePanelGroupsEditSubmit": 70, + "routePanelGroupsEditPermsSubmit": 71, + "routePanelGroupsCreateSubmit": 72, + "panel.Backups": 73, + "panel.LogsRegs": 74, + "panel.LogsMod": 75, + "panel.Debug": 76, + "routePanelDashboard": 77, + "routes.AccountEdit": 78, + "routes.AccountEditPassword": 79, + "routes.AccountEditPasswordSubmit": 80, + "routes.AccountEditAvatarSubmit": 81, + "routes.AccountEditUsernameSubmit": 82, + "routes.AccountEditMFA": 83, + "routes.AccountEditMFASetup": 84, + "routes.AccountEditMFASetupSubmit": 85, + "routes.AccountEditMFADisableSubmit": 86, + "routes.AccountEditEmail": 87, + "routes.AccountEditEmailTokenSubmit": 88, + "routes.ViewProfile": 89, + "routes.BanUserSubmit": 90, + "routes.UnbanUser": 91, + "routes.ActivateUser": 92, + "routes.IPSearch": 93, + "routes.CreateTopicSubmit": 94, + "routes.EditTopicSubmit": 95, + "routes.DeleteTopicSubmit": 96, + "routes.StickTopicSubmit": 97, + "routes.UnstickTopicSubmit": 98, + "routes.LockTopicSubmit": 99, + "routes.UnlockTopicSubmit": 100, + "routes.MoveTopicSubmit": 101, + "routes.LikeTopicSubmit": 102, + "routes.ViewTopic": 103, + "routes.CreateReplySubmit": 104, + "routes.ReplyEditSubmit": 105, + "routes.ReplyDeleteSubmit": 106, + "routes.ReplyLikeSubmit": 107, + "routes.ProfileReplyCreateSubmit": 108, + "routes.ProfileReplyEditSubmit": 109, + "routes.ProfileReplyDeleteSubmit": 110, + "routes.PollVote": 111, + "routes.PollResults": 112, + "routes.AccountLogin": 113, + "routes.AccountRegister": 114, + "routes.AccountLogout": 115, + "routes.AccountLoginSubmit": 116, + "routes.AccountLoginMFAVerify": 117, + "routes.AccountLoginMFAVerifySubmit": 118, + "routes.AccountRegisterSubmit": 119, + "routes.DynamicRoute": 120, + "routes.UploadedFile": 121, + "routes.StaticFile": 122, + "routes.RobotsTxt": 123, + "routes.SitemapXml": 124, + "routes.BadRoute": 125, } var reverseRouteMapEnum = map[int]string{ 0: "routes.Overview", @@ -285,123 +287,124 @@ var reverseRouteMapEnum = map[int]string{ 5: "routes.ShowAttachment", 6: "common.RouteWebsockets", 7: "routeAPIPhrases", - 8: "routeJSAntispam", - 9: "routeAPI", - 10: "routes.ReportSubmit", - 11: "routes.CreateTopic", - 12: "routes.TopicList", - 13: "panel.Forums", - 14: "panel.ForumsCreateSubmit", - 15: "panel.ForumsDelete", - 16: "panel.ForumsDeleteSubmit", - 17: "panel.ForumsEdit", - 18: "panel.ForumsEditSubmit", - 19: "panel.ForumsEditPermsSubmit", - 20: "panel.ForumsEditPermsAdvance", - 21: "panel.ForumsEditPermsAdvanceSubmit", - 22: "panel.Settings", - 23: "panel.SettingEdit", - 24: "panel.SettingEditSubmit", - 25: "panel.WordFilters", - 26: "panel.WordFiltersCreateSubmit", - 27: "panel.WordFiltersEdit", - 28: "panel.WordFiltersEditSubmit", - 29: "panel.WordFiltersDeleteSubmit", - 30: "panel.Pages", - 31: "panel.PagesCreateSubmit", - 32: "panel.PagesEdit", - 33: "panel.PagesEditSubmit", - 34: "panel.PagesDeleteSubmit", - 35: "routePanelThemes", - 36: "routePanelThemesSetDefault", - 37: "routePanelThemesMenus", - 38: "routePanelThemesMenusEdit", - 39: "routePanelThemesMenuItemEdit", - 40: "routePanelThemesMenuItemEditSubmit", - 41: "routePanelThemesMenuItemCreateSubmit", - 42: "routePanelThemesMenuItemDeleteSubmit", - 43: "routePanelThemesMenuItemOrderSubmit", - 44: "panel.Plugins", - 45: "panel.PluginsActivate", - 46: "panel.PluginsDeactivate", - 47: "panel.PluginsInstall", - 48: "panel.Users", - 49: "panel.UsersEdit", - 50: "panel.UsersEditSubmit", - 51: "panel.AnalyticsViews", - 52: "panel.AnalyticsRoutes", - 53: "panel.AnalyticsAgents", - 54: "panel.AnalyticsSystems", - 55: "panel.AnalyticsLanguages", - 56: "panel.AnalyticsReferrers", - 57: "panel.AnalyticsRouteViews", - 58: "panel.AnalyticsAgentViews", - 59: "panel.AnalyticsForumViews", - 60: "panel.AnalyticsSystemViews", - 61: "panel.AnalyticsLanguageViews", - 62: "panel.AnalyticsReferrerViews", - 63: "panel.AnalyticsPosts", - 64: "panel.AnalyticsTopics", - 65: "panel.AnalyticsForums", - 66: "routePanelGroups", - 67: "routePanelGroupsEdit", - 68: "routePanelGroupsEditPerms", - 69: "routePanelGroupsEditSubmit", - 70: "routePanelGroupsEditPermsSubmit", - 71: "routePanelGroupsCreateSubmit", - 72: "panel.Backups", - 73: "panel.LogsRegs", - 74: "panel.LogsMod", - 75: "panel.Debug", - 76: "routePanelDashboard", - 77: "routes.AccountEdit", - 78: "routes.AccountEditPassword", - 79: "routes.AccountEditPasswordSubmit", - 80: "routes.AccountEditAvatarSubmit", - 81: "routes.AccountEditUsernameSubmit", - 82: "routes.AccountEditMFA", - 83: "routes.AccountEditMFASetup", - 84: "routes.AccountEditMFASetupSubmit", - 85: "routes.AccountEditMFADisableSubmit", - 86: "routes.AccountEditEmail", - 87: "routes.AccountEditEmailTokenSubmit", - 88: "routes.ViewProfile", - 89: "routes.BanUserSubmit", - 90: "routes.UnbanUser", - 91: "routes.ActivateUser", - 92: "routes.IPSearch", - 93: "routes.CreateTopicSubmit", - 94: "routes.EditTopicSubmit", - 95: "routes.DeleteTopicSubmit", - 96: "routes.StickTopicSubmit", - 97: "routes.UnstickTopicSubmit", - 98: "routes.LockTopicSubmit", - 99: "routes.UnlockTopicSubmit", - 100: "routes.MoveTopicSubmit", - 101: "routes.LikeTopicSubmit", - 102: "routes.ViewTopic", - 103: "routes.CreateReplySubmit", - 104: "routes.ReplyEditSubmit", - 105: "routes.ReplyDeleteSubmit", - 106: "routes.ReplyLikeSubmit", - 107: "routes.ProfileReplyCreateSubmit", - 108: "routes.ProfileReplyEditSubmit", - 109: "routes.ProfileReplyDeleteSubmit", - 110: "routes.PollVote", - 111: "routes.PollResults", - 112: "routes.AccountLogin", - 113: "routes.AccountRegister", - 114: "routes.AccountLogout", - 115: "routes.AccountLoginSubmit", - 116: "routes.AccountLoginMFAVerify", - 117: "routes.AccountLoginMFAVerifySubmit", - 118: "routes.AccountRegisterSubmit", - 119: "routes.DynamicRoute", - 120: "routes.UploadedFile", - 121: "routes.StaticFile", - 122: "routes.RobotsTxt", - 123: "routes.SitemapXml", - 124: "routes.BadRoute", + 8: "routes.APIMe", + 9: "routeJSAntispam", + 10: "routeAPI", + 11: "routes.ReportSubmit", + 12: "routes.CreateTopic", + 13: "routes.TopicList", + 14: "panel.Forums", + 15: "panel.ForumsCreateSubmit", + 16: "panel.ForumsDelete", + 17: "panel.ForumsDeleteSubmit", + 18: "panel.ForumsEdit", + 19: "panel.ForumsEditSubmit", + 20: "panel.ForumsEditPermsSubmit", + 21: "panel.ForumsEditPermsAdvance", + 22: "panel.ForumsEditPermsAdvanceSubmit", + 23: "panel.Settings", + 24: "panel.SettingEdit", + 25: "panel.SettingEditSubmit", + 26: "panel.WordFilters", + 27: "panel.WordFiltersCreateSubmit", + 28: "panel.WordFiltersEdit", + 29: "panel.WordFiltersEditSubmit", + 30: "panel.WordFiltersDeleteSubmit", + 31: "panel.Pages", + 32: "panel.PagesCreateSubmit", + 33: "panel.PagesEdit", + 34: "panel.PagesEditSubmit", + 35: "panel.PagesDeleteSubmit", + 36: "routePanelThemes", + 37: "routePanelThemesSetDefault", + 38: "routePanelThemesMenus", + 39: "routePanelThemesMenusEdit", + 40: "routePanelThemesMenuItemEdit", + 41: "routePanelThemesMenuItemEditSubmit", + 42: "routePanelThemesMenuItemCreateSubmit", + 43: "routePanelThemesMenuItemDeleteSubmit", + 44: "routePanelThemesMenuItemOrderSubmit", + 45: "panel.Plugins", + 46: "panel.PluginsActivate", + 47: "panel.PluginsDeactivate", + 48: "panel.PluginsInstall", + 49: "panel.Users", + 50: "panel.UsersEdit", + 51: "panel.UsersEditSubmit", + 52: "panel.AnalyticsViews", + 53: "panel.AnalyticsRoutes", + 54: "panel.AnalyticsAgents", + 55: "panel.AnalyticsSystems", + 56: "panel.AnalyticsLanguages", + 57: "panel.AnalyticsReferrers", + 58: "panel.AnalyticsRouteViews", + 59: "panel.AnalyticsAgentViews", + 60: "panel.AnalyticsForumViews", + 61: "panel.AnalyticsSystemViews", + 62: "panel.AnalyticsLanguageViews", + 63: "panel.AnalyticsReferrerViews", + 64: "panel.AnalyticsPosts", + 65: "panel.AnalyticsTopics", + 66: "panel.AnalyticsForums", + 67: "routePanelGroups", + 68: "routePanelGroupsEdit", + 69: "routePanelGroupsEditPerms", + 70: "routePanelGroupsEditSubmit", + 71: "routePanelGroupsEditPermsSubmit", + 72: "routePanelGroupsCreateSubmit", + 73: "panel.Backups", + 74: "panel.LogsRegs", + 75: "panel.LogsMod", + 76: "panel.Debug", + 77: "routePanelDashboard", + 78: "routes.AccountEdit", + 79: "routes.AccountEditPassword", + 80: "routes.AccountEditPasswordSubmit", + 81: "routes.AccountEditAvatarSubmit", + 82: "routes.AccountEditUsernameSubmit", + 83: "routes.AccountEditMFA", + 84: "routes.AccountEditMFASetup", + 85: "routes.AccountEditMFASetupSubmit", + 86: "routes.AccountEditMFADisableSubmit", + 87: "routes.AccountEditEmail", + 88: "routes.AccountEditEmailTokenSubmit", + 89: "routes.ViewProfile", + 90: "routes.BanUserSubmit", + 91: "routes.UnbanUser", + 92: "routes.ActivateUser", + 93: "routes.IPSearch", + 94: "routes.CreateTopicSubmit", + 95: "routes.EditTopicSubmit", + 96: "routes.DeleteTopicSubmit", + 97: "routes.StickTopicSubmit", + 98: "routes.UnstickTopicSubmit", + 99: "routes.LockTopicSubmit", + 100: "routes.UnlockTopicSubmit", + 101: "routes.MoveTopicSubmit", + 102: "routes.LikeTopicSubmit", + 103: "routes.ViewTopic", + 104: "routes.CreateReplySubmit", + 105: "routes.ReplyEditSubmit", + 106: "routes.ReplyDeleteSubmit", + 107: "routes.ReplyLikeSubmit", + 108: "routes.ProfileReplyCreateSubmit", + 109: "routes.ProfileReplyEditSubmit", + 110: "routes.ProfileReplyDeleteSubmit", + 111: "routes.PollVote", + 112: "routes.PollResults", + 113: "routes.AccountLogin", + 114: "routes.AccountRegister", + 115: "routes.AccountLogout", + 116: "routes.AccountLoginSubmit", + 117: "routes.AccountLoginMFAVerify", + 118: "routes.AccountLoginMFAVerifySubmit", + 119: "routes.AccountRegisterSubmit", + 120: "routes.DynamicRoute", + 121: "routes.UploadedFile", + 122: "routes.StaticFile", + 123: "routes.RobotsTxt", + 124: "routes.SitemapXml", + 125: "routes.BadRoute", } var osMapEnum = map[string]int{ "unknown": 0, @@ -697,7 +700,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { counters.GlobalViewCounter.Bump() if prefix == "/static" { - counters.RouteViewCounter.Bump(121) + counters.RouteViewCounter.Bump(122) req.URL.Path += extraData routes.StaticFile(w, req) return @@ -864,7 +867,11 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { "after PreRoute\n" + "routeMapEnum: ", routeMapEnum) } + + router.routeSwitch(w, req, user, prefix, extraData) +} +func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user common.User, prefix string, extraData string) { var err common.RouteError switch(prefix) { case "/overview": @@ -927,11 +934,14 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { case "/api/phrases/": counters.RouteViewCounter.Bump(7) err = routeAPIPhrases(w,req,user) - case "/api/watches/": + case "/api/me/": counters.RouteViewCounter.Bump(8) + err = routes.APIMe(w,req,user) + case "/api/watches/": + counters.RouteViewCounter.Bump(9) err = routeJSAntispam(w,req,user) default: - counters.RouteViewCounter.Bump(9) + counters.RouteViewCounter.Bump(10) err = routeAPI(w,req,user) } if err != nil { @@ -958,7 +968,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(10) + counters.RouteViewCounter.Bump(11) err = routes.ReportSubmit(w,req,user,extraData) } if err != nil { @@ -973,10 +983,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(11) + counters.RouteViewCounter.Bump(12) err = routes.CreateTopic(w,req,user,extraData) default: - counters.RouteViewCounter.Bump(12) + counters.RouteViewCounter.Bump(13) err = routes.TopicList(w,req,user) } if err != nil { @@ -991,7 +1001,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { switch(req.URL.Path) { case "/panel/forums/": - counters.RouteViewCounter.Bump(13) + counters.RouteViewCounter.Bump(14) err = panel.Forums(w,req,user) case "/panel/forums/create/": err = common.NoSessionMismatch(w,req,user) @@ -1000,7 +1010,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(14) + counters.RouteViewCounter.Bump(15) err = panel.ForumsCreateSubmit(w,req,user) case "/panel/forums/delete/": err = common.NoSessionMismatch(w,req,user) @@ -1009,7 +1019,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(15) + counters.RouteViewCounter.Bump(16) err = panel.ForumsDelete(w,req,user,extraData) case "/panel/forums/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1018,10 +1028,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(16) + counters.RouteViewCounter.Bump(17) err = panel.ForumsDeleteSubmit(w,req,user,extraData) case "/panel/forums/edit/": - counters.RouteViewCounter.Bump(17) + counters.RouteViewCounter.Bump(18) err = panel.ForumsEdit(w,req,user,extraData) case "/panel/forums/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1030,7 +1040,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(18) + counters.RouteViewCounter.Bump(19) err = panel.ForumsEditSubmit(w,req,user,extraData) case "/panel/forums/edit/perms/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1039,10 +1049,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(19) + counters.RouteViewCounter.Bump(20) err = panel.ForumsEditPermsSubmit(w,req,user,extraData) case "/panel/forums/edit/perms/": - counters.RouteViewCounter.Bump(20) + counters.RouteViewCounter.Bump(21) err = panel.ForumsEditPermsAdvance(w,req,user,extraData) case "/panel/forums/edit/perms/adv/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1051,13 +1061,13 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(21) + counters.RouteViewCounter.Bump(22) err = panel.ForumsEditPermsAdvanceSubmit(w,req,user,extraData) case "/panel/settings/": - counters.RouteViewCounter.Bump(22) + counters.RouteViewCounter.Bump(23) err = panel.Settings(w,req,user) case "/panel/settings/edit/": - counters.RouteViewCounter.Bump(23) + counters.RouteViewCounter.Bump(24) err = panel.SettingEdit(w,req,user,extraData) case "/panel/settings/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1066,10 +1076,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(24) + counters.RouteViewCounter.Bump(25) err = panel.SettingEditSubmit(w,req,user,extraData) case "/panel/settings/word-filters/": - counters.RouteViewCounter.Bump(25) + counters.RouteViewCounter.Bump(26) err = panel.WordFilters(w,req,user) case "/panel/settings/word-filters/create/": err = common.NoSessionMismatch(w,req,user) @@ -1078,10 +1088,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(26) + counters.RouteViewCounter.Bump(27) err = panel.WordFiltersCreateSubmit(w,req,user) case "/panel/settings/word-filters/edit/": - counters.RouteViewCounter.Bump(27) + counters.RouteViewCounter.Bump(28) err = panel.WordFiltersEdit(w,req,user,extraData) case "/panel/settings/word-filters/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1090,7 +1100,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(28) + counters.RouteViewCounter.Bump(29) err = panel.WordFiltersEditSubmit(w,req,user,extraData) case "/panel/settings/word-filters/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1099,7 +1109,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(29) + counters.RouteViewCounter.Bump(30) err = panel.WordFiltersDeleteSubmit(w,req,user,extraData) case "/panel/pages/": err = common.AdminOnly(w,req,user) @@ -1108,7 +1118,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(30) + counters.RouteViewCounter.Bump(31) err = panel.Pages(w,req,user) case "/panel/pages/create/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1123,7 +1133,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(31) + counters.RouteViewCounter.Bump(32) err = panel.PagesCreateSubmit(w,req,user) case "/panel/pages/edit/": err = common.AdminOnly(w,req,user) @@ -1132,7 +1142,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(32) + counters.RouteViewCounter.Bump(33) err = panel.PagesEdit(w,req,user,extraData) case "/panel/pages/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1147,7 +1157,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(33) + counters.RouteViewCounter.Bump(34) err = panel.PagesEditSubmit(w,req,user,extraData) case "/panel/pages/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1162,10 +1172,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(34) + counters.RouteViewCounter.Bump(35) err = panel.PagesDeleteSubmit(w,req,user,extraData) case "/panel/themes/": - counters.RouteViewCounter.Bump(35) + counters.RouteViewCounter.Bump(36) err = routePanelThemes(w,req,user) case "/panel/themes/default/": err = common.NoSessionMismatch(w,req,user) @@ -1174,16 +1184,16 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(36) + counters.RouteViewCounter.Bump(37) err = routePanelThemesSetDefault(w,req,user,extraData) case "/panel/themes/menus/": - counters.RouteViewCounter.Bump(37) + counters.RouteViewCounter.Bump(38) err = routePanelThemesMenus(w,req,user) case "/panel/themes/menus/edit/": - counters.RouteViewCounter.Bump(38) + counters.RouteViewCounter.Bump(39) err = routePanelThemesMenusEdit(w,req,user,extraData) case "/panel/themes/menus/item/edit/": - counters.RouteViewCounter.Bump(39) + counters.RouteViewCounter.Bump(40) err = routePanelThemesMenuItemEdit(w,req,user,extraData) case "/panel/themes/menus/item/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1192,7 +1202,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(40) + counters.RouteViewCounter.Bump(41) err = routePanelThemesMenuItemEditSubmit(w,req,user,extraData) case "/panel/themes/menus/item/create/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1201,7 +1211,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(41) + counters.RouteViewCounter.Bump(42) err = routePanelThemesMenuItemCreateSubmit(w,req,user) case "/panel/themes/menus/item/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1210,7 +1220,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(42) + counters.RouteViewCounter.Bump(43) err = routePanelThemesMenuItemDeleteSubmit(w,req,user,extraData) case "/panel/themes/menus/item/order/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1219,10 +1229,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(43) + counters.RouteViewCounter.Bump(44) err = routePanelThemesMenuItemOrderSubmit(w,req,user,extraData) case "/panel/plugins/": - counters.RouteViewCounter.Bump(44) + counters.RouteViewCounter.Bump(45) err = panel.Plugins(w,req,user) case "/panel/plugins/activate/": err = common.NoSessionMismatch(w,req,user) @@ -1231,7 +1241,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(45) + counters.RouteViewCounter.Bump(46) err = panel.PluginsActivate(w,req,user,extraData) case "/panel/plugins/deactivate/": err = common.NoSessionMismatch(w,req,user) @@ -1240,7 +1250,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(46) + counters.RouteViewCounter.Bump(47) err = panel.PluginsDeactivate(w,req,user,extraData) case "/panel/plugins/install/": err = common.NoSessionMismatch(w,req,user) @@ -1249,13 +1259,13 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(47) + counters.RouteViewCounter.Bump(48) err = panel.PluginsInstall(w,req,user,extraData) case "/panel/users/": - counters.RouteViewCounter.Bump(48) + counters.RouteViewCounter.Bump(49) err = panel.Users(w,req,user) case "/panel/users/edit/": - counters.RouteViewCounter.Bump(49) + counters.RouteViewCounter.Bump(50) err = panel.UsersEdit(w,req,user,extraData) case "/panel/users/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1264,7 +1274,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(50) + counters.RouteViewCounter.Bump(51) err = panel.UsersEditSubmit(w,req,user,extraData) case "/panel/analytics/views/": err = common.ParseForm(w,req,user) @@ -1273,7 +1283,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(51) + counters.RouteViewCounter.Bump(52) err = panel.AnalyticsViews(w,req,user) case "/panel/analytics/routes/": err = common.ParseForm(w,req,user) @@ -1282,7 +1292,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(52) + counters.RouteViewCounter.Bump(53) err = panel.AnalyticsRoutes(w,req,user) case "/panel/analytics/agents/": err = common.ParseForm(w,req,user) @@ -1291,7 +1301,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(53) + counters.RouteViewCounter.Bump(54) err = panel.AnalyticsAgents(w,req,user) case "/panel/analytics/systems/": err = common.ParseForm(w,req,user) @@ -1300,7 +1310,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(54) + counters.RouteViewCounter.Bump(55) err = panel.AnalyticsSystems(w,req,user) case "/panel/analytics/langs/": err = common.ParseForm(w,req,user) @@ -1309,7 +1319,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(55) + counters.RouteViewCounter.Bump(56) err = panel.AnalyticsLanguages(w,req,user) case "/panel/analytics/referrers/": err = common.ParseForm(w,req,user) @@ -1318,25 +1328,25 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(56) + counters.RouteViewCounter.Bump(57) err = panel.AnalyticsReferrers(w,req,user) case "/panel/analytics/route/": - counters.RouteViewCounter.Bump(57) + counters.RouteViewCounter.Bump(58) err = panel.AnalyticsRouteViews(w,req,user,extraData) case "/panel/analytics/agent/": - counters.RouteViewCounter.Bump(58) + counters.RouteViewCounter.Bump(59) err = panel.AnalyticsAgentViews(w,req,user,extraData) case "/panel/analytics/forum/": - counters.RouteViewCounter.Bump(59) + counters.RouteViewCounter.Bump(60) err = panel.AnalyticsForumViews(w,req,user,extraData) case "/panel/analytics/system/": - counters.RouteViewCounter.Bump(60) + counters.RouteViewCounter.Bump(61) err = panel.AnalyticsSystemViews(w,req,user,extraData) case "/panel/analytics/lang/": - counters.RouteViewCounter.Bump(61) + counters.RouteViewCounter.Bump(62) err = panel.AnalyticsLanguageViews(w,req,user,extraData) case "/panel/analytics/referrer/": - counters.RouteViewCounter.Bump(62) + counters.RouteViewCounter.Bump(63) err = panel.AnalyticsReferrerViews(w,req,user,extraData) case "/panel/analytics/posts/": err = common.ParseForm(w,req,user) @@ -1345,7 +1355,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(63) + counters.RouteViewCounter.Bump(64) err = panel.AnalyticsPosts(w,req,user) case "/panel/analytics/topics/": err = common.ParseForm(w,req,user) @@ -1354,7 +1364,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(64) + counters.RouteViewCounter.Bump(65) err = panel.AnalyticsTopics(w,req,user) case "/panel/analytics/forums/": err = common.ParseForm(w,req,user) @@ -1363,16 +1373,16 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(65) + counters.RouteViewCounter.Bump(66) err = panel.AnalyticsForums(w,req,user) case "/panel/groups/": - counters.RouteViewCounter.Bump(66) + counters.RouteViewCounter.Bump(67) err = routePanelGroups(w,req,user) case "/panel/groups/edit/": - counters.RouteViewCounter.Bump(67) + counters.RouteViewCounter.Bump(68) err = routePanelGroupsEdit(w,req,user,extraData) case "/panel/groups/edit/perms/": - counters.RouteViewCounter.Bump(68) + counters.RouteViewCounter.Bump(69) err = routePanelGroupsEditPerms(w,req,user,extraData) case "/panel/groups/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1381,7 +1391,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(69) + counters.RouteViewCounter.Bump(70) err = routePanelGroupsEditSubmit(w,req,user,extraData) case "/panel/groups/edit/perms/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1390,7 +1400,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(70) + counters.RouteViewCounter.Bump(71) err = routePanelGroupsEditPermsSubmit(w,req,user,extraData) case "/panel/groups/create/": err = common.NoSessionMismatch(w,req,user) @@ -1399,7 +1409,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(71) + counters.RouteViewCounter.Bump(72) err = routePanelGroupsCreateSubmit(w,req,user) case "/panel/backups/": err = common.SuperAdminOnly(w,req,user) @@ -1408,13 +1418,13 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(72) + counters.RouteViewCounter.Bump(73) err = panel.Backups(w,req,user,extraData) case "/panel/logs/regs/": - counters.RouteViewCounter.Bump(73) + counters.RouteViewCounter.Bump(74) err = panel.LogsRegs(w,req,user) case "/panel/logs/mod/": - counters.RouteViewCounter.Bump(74) + counters.RouteViewCounter.Bump(75) err = panel.LogsMod(w,req,user) case "/panel/debug/": err = common.AdminOnly(w,req,user) @@ -1423,10 +1433,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(75) + counters.RouteViewCounter.Bump(76) err = panel.Debug(w,req,user) default: - counters.RouteViewCounter.Bump(76) + counters.RouteViewCounter.Bump(77) err = routePanelDashboard(w,req,user) } if err != nil { @@ -1441,7 +1451,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(77) + counters.RouteViewCounter.Bump(78) err = routes.AccountEdit(w,req,user) case "/user/edit/password/": err = common.MemberOnly(w,req,user) @@ -1450,7 +1460,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(78) + counters.RouteViewCounter.Bump(79) err = routes.AccountEditPassword(w,req,user) case "/user/edit/password/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1465,7 +1475,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(79) + counters.RouteViewCounter.Bump(80) err = routes.AccountEditPasswordSubmit(w,req,user) case "/user/edit/avatar/submit/": err = common.MemberOnly(w,req,user) @@ -1485,7 +1495,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(80) + counters.RouteViewCounter.Bump(81) err = routes.AccountEditAvatarSubmit(w,req,user) case "/user/edit/username/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1500,7 +1510,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(81) + counters.RouteViewCounter.Bump(82) err = routes.AccountEditUsernameSubmit(w,req,user) case "/user/edit/mfa/": err = common.MemberOnly(w,req,user) @@ -1509,7 +1519,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(82) + counters.RouteViewCounter.Bump(83) err = routes.AccountEditMFA(w,req,user) case "/user/edit/mfa/setup/": err = common.MemberOnly(w,req,user) @@ -1518,7 +1528,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(83) + counters.RouteViewCounter.Bump(84) err = routes.AccountEditMFASetup(w,req,user) case "/user/edit/mfa/setup/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1533,7 +1543,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(84) + counters.RouteViewCounter.Bump(85) err = routes.AccountEditMFASetupSubmit(w,req,user) case "/user/edit/mfa/disable/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1548,7 +1558,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(85) + counters.RouteViewCounter.Bump(86) err = routes.AccountEditMFADisableSubmit(w,req,user) case "/user/edit/email/": err = common.MemberOnly(w,req,user) @@ -1557,7 +1567,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(86) + counters.RouteViewCounter.Bump(87) err = routes.AccountEditEmail(w,req,user) case "/user/edit/token/": err = common.NoSessionMismatch(w,req,user) @@ -1572,11 +1582,11 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(87) + counters.RouteViewCounter.Bump(88) err = routes.AccountEditEmailTokenSubmit(w,req,user,extraData) default: req.URL.Path += extraData - counters.RouteViewCounter.Bump(88) + counters.RouteViewCounter.Bump(89) err = routes.ViewProfile(w,req,user) } if err != nil { @@ -1597,7 +1607,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(89) + counters.RouteViewCounter.Bump(90) err = routes.BanUserSubmit(w,req,user,extraData) case "/users/unban/": err = common.NoSessionMismatch(w,req,user) @@ -1612,7 +1622,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(90) + counters.RouteViewCounter.Bump(91) err = routes.UnbanUser(w,req,user,extraData) case "/users/activate/": err = common.NoSessionMismatch(w,req,user) @@ -1627,7 +1637,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(91) + counters.RouteViewCounter.Bump(92) err = routes.ActivateUser(w,req,user,extraData) case "/users/ips/": err = common.MemberOnly(w,req,user) @@ -1636,7 +1646,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(92) + counters.RouteViewCounter.Bump(93) err = routes.IPSearch(w,req,user) } if err != nil { @@ -1662,7 +1672,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(93) + counters.RouteViewCounter.Bump(94) err = routes.CreateTopicSubmit(w,req,user) case "/topic/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1677,7 +1687,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(94) + counters.RouteViewCounter.Bump(95) err = routes.EditTopicSubmit(w,req,user,extraData) case "/topic/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1693,7 +1703,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { } req.URL.Path += extraData - counters.RouteViewCounter.Bump(95) + counters.RouteViewCounter.Bump(96) err = routes.DeleteTopicSubmit(w,req,user) case "/topic/stick/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1708,7 +1718,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(96) + counters.RouteViewCounter.Bump(97) err = routes.StickTopicSubmit(w,req,user,extraData) case "/topic/unstick/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1723,7 +1733,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(97) + counters.RouteViewCounter.Bump(98) err = routes.UnstickTopicSubmit(w,req,user,extraData) case "/topic/lock/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1739,7 +1749,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { } req.URL.Path += extraData - counters.RouteViewCounter.Bump(98) + counters.RouteViewCounter.Bump(99) err = routes.LockTopicSubmit(w,req,user) case "/topic/unlock/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1754,7 +1764,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(99) + counters.RouteViewCounter.Bump(100) err = routes.UnlockTopicSubmit(w,req,user,extraData) case "/topic/move/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1769,7 +1779,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(100) + counters.RouteViewCounter.Bump(101) err = routes.MoveTopicSubmit(w,req,user,extraData) case "/topic/like/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1790,10 +1800,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(101) + counters.RouteViewCounter.Bump(102) err = routes.LikeTopicSubmit(w,req,user,extraData) default: - counters.RouteViewCounter.Bump(102) + counters.RouteViewCounter.Bump(103) err = routes.ViewTopic(w,req,user, extraData) } if err != nil { @@ -1819,7 +1829,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(103) + counters.RouteViewCounter.Bump(104) err = routes.CreateReplySubmit(w,req,user) case "/reply/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1834,7 +1844,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(104) + counters.RouteViewCounter.Bump(105) err = routes.ReplyEditSubmit(w,req,user,extraData) case "/reply/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1849,7 +1859,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(105) + counters.RouteViewCounter.Bump(106) err = routes.ReplyDeleteSubmit(w,req,user,extraData) case "/reply/like/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1870,7 +1880,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(106) + counters.RouteViewCounter.Bump(107) err = routes.ReplyLikeSubmit(w,req,user,extraData) } if err != nil { @@ -1891,7 +1901,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(107) + counters.RouteViewCounter.Bump(108) err = routes.ProfileReplyCreateSubmit(w,req,user) case "/profile/reply/edit/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1906,7 +1916,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(108) + counters.RouteViewCounter.Bump(109) err = routes.ProfileReplyEditSubmit(w,req,user,extraData) case "/profile/reply/delete/submit/": err = common.NoSessionMismatch(w,req,user) @@ -1921,7 +1931,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(109) + counters.RouteViewCounter.Bump(110) err = routes.ProfileReplyDeleteSubmit(w,req,user,extraData) } if err != nil { @@ -1942,10 +1952,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(110) + counters.RouteViewCounter.Bump(111) err = routes.PollVote(w,req,user,extraData) case "/poll/results/": - counters.RouteViewCounter.Bump(111) + counters.RouteViewCounter.Bump(112) err = routes.PollResults(w,req,user,extraData) } if err != nil { @@ -1954,10 +1964,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { case "/accounts": switch(req.URL.Path) { case "/accounts/login/": - counters.RouteViewCounter.Bump(112) + counters.RouteViewCounter.Bump(113) err = routes.AccountLogin(w,req,user) case "/accounts/create/": - counters.RouteViewCounter.Bump(113) + counters.RouteViewCounter.Bump(114) err = routes.AccountRegister(w,req,user) case "/accounts/logout/": err = common.NoSessionMismatch(w,req,user) @@ -1972,7 +1982,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(114) + counters.RouteViewCounter.Bump(115) err = routes.AccountLogout(w,req,user) case "/accounts/login/submit/": err = common.ParseForm(w,req,user) @@ -1981,10 +1991,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(115) + counters.RouteViewCounter.Bump(116) err = routes.AccountLoginSubmit(w,req,user) case "/accounts/mfa_verify/": - counters.RouteViewCounter.Bump(116) + counters.RouteViewCounter.Bump(117) err = routes.AccountLoginMFAVerify(w,req,user) case "/accounts/mfa_verify/submit/": err = common.ParseForm(w,req,user) @@ -1993,7 +2003,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(117) + counters.RouteViewCounter.Bump(118) err = routes.AccountLoginMFAVerifySubmit(w,req,user) case "/accounts/create/submit/": err = common.ParseForm(w,req,user) @@ -2002,7 +2012,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - counters.RouteViewCounter.Bump(118) + counters.RouteViewCounter.Bump(119) err = routes.AccountRegisterSubmit(w,req,user) } if err != nil { @@ -2019,7 +2029,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { common.NotFound(w,req,nil) return } - counters.RouteViewCounter.Bump(120) + counters.RouteViewCounter.Bump(121) req.URL.Path += extraData // TODO: Find a way to propagate errors up from this? router.UploadHandler(w,req) // TODO: Count these views @@ -2028,14 +2038,14 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // TODO: Add support for favicons and robots.txt files switch(extraData) { case "robots.txt": - counters.RouteViewCounter.Bump(122) + counters.RouteViewCounter.Bump(123) err = routes.RobotsTxt(w,req) if err != nil { router.handleError(err,w,req,user) } return /*case "sitemap.xml": - counters.RouteViewCounter.Bump(123) + counters.RouteViewCounter.Bump(124) err = routes.SitemapXml(w,req) if err != nil { router.handleError(err,w,req,user) @@ -2051,7 +2061,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { router.RUnlock() if ok { - counters.RouteViewCounter.Bump(119) // TODO: Be more specific about *which* dynamic route it is + counters.RouteViewCounter.Bump(120) // TODO: Be more specific about *which* dynamic route it is req.URL.Path += extraData err = handle(w,req,user) if err != nil { @@ -2066,7 +2076,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { } else { router.DumpRequest(req,"Bad Route") } - counters.RouteViewCounter.Bump(124) + counters.RouteViewCounter.Bump(125) common.NotFound(w,req,nil) } } diff --git a/public/global.js b/public/global.js index f9e53e8f..e9400cf1 100644 --- a/public/global.js +++ b/public/global.js @@ -7,6 +7,7 @@ var alertList = []; var alertCount = 0; var moreTopicCount = 0; var conn; +var me = {}; var selectedTopics = []; var attachItemCallback = function(){} var hooks = { @@ -196,7 +197,7 @@ function runWebSockets() { console.log("The WebSockets connection was opened"); conn.send("page " + document.location.pathname + '\r'); // TODO: Don't ask again, if it's denied. We could have a setting in the UCP which automatically requests this when someone flips desktop notifications on - if(loggedIn) { + if(me.User.ID > 0) { Notification.requestPermission(); } } @@ -258,14 +259,11 @@ function runWebSockets() { for(var i = 0; i < messages.length; i++) { let message = messages[i]; //console.log("Message: ",message); + let msgblocks = SplitN(message," ",3); + if(msgblocks.length < 3) continue; if(message.startsWith("set ")) { - //msgblocks = message.split(' ',3); - let msgblocks = SplitN(message," ",3); - if(msgblocks.length < 3) continue; document.querySelector(msgblocks[1]).innerHTML = msgblocks[2]; } else if(message.startsWith("set-class ")) { - let msgblocks = SplitN(message," ",3); - if(msgblocks.length < 3) continue; document.querySelector(msgblocks[1]).className = msgblocks[2]; } } @@ -278,7 +276,7 @@ function len(item) { } function loadScript(name, callback) { - let url = "//" +siteURL+"/static/"+name + let url = "//" +me.Site.URL+"/static/"+name $.getScript(url) .done(callback) .fail((e,xhr,settings,ex) => { @@ -296,7 +294,7 @@ function DoNothingButPassBack(item) { } function fetchPhrases() { - fetch("//" +siteURL+"/api/phrases/?query=status,topic_list") + fetch("//" +me.Site.URL+"/api/phrases/?query=status,topic_list") .then((resp) => resp.json()) .then((data) => { console.log("loaded phrase endpoint data"); @@ -328,29 +326,44 @@ function fetchPhrases() { }); } -$(document).ready(function(){ - runHook("start_init"); - if(loggedIn) { - let toLoad = 1; - loadScript("template_topics_topic.js", () => { - console.log("Loaded template_topics_topic.js"); - toLoad--; - if(toLoad===0) fetchPhrases(); +(() => { + runHook("pre_me"); + fetch("/api/me/") + .then((resp) => resp.json()) + .then((data) => { + console.log("loaded me endpoint data"); + console.log("data:",data); + me = data; + runHook("pre_init"); + + if(me.User.ID > 0) { + let toLoad = 1; + loadScript("template_topics_topic.js", () => { + console.log("Loaded template_topics_topic.js"); + toLoad--; + if(toLoad===0) fetchPhrases(); + }); + } + + // We can only get away with this because template_alert has no phrases, otherwise it too would have to be part of the "dance", I miss Go concurrency :( + loadScript("template_alert.js", () => { + console.log("Loaded template_alert.js"); + alertsInitted = true; + var alertMenuList = document.getElementsByClassName("menu_alerts"); + for(var i = 0; i < alertMenuList.length; i++) { + loadAlerts(alertMenuList[i]); + } + }); + + if(window["WebSocket"]) runWebSockets(); + else conn = false; + + $(document).ready(mainInit); }); - } +})(); - // We can only get away with this because template_alert has no phrases, otherwise it too would have to be part of the "dance", I miss Go concurrency :( - loadScript("template_alert.js", () => { - console.log("Loaded template_alert.js"); - alertsInitted = true; - var alertMenuList = document.getElementsByClassName("menu_alerts"); - for(var i = 0; i < alertMenuList.length; i++) { - loadAlerts(alertMenuList[i]); - } - }); - - if(window["WebSocket"]) runWebSockets(); - else conn = false; +function mainInit(){ + runHook("start_init"); $(".more_topics").click((event) => { event.preventDefault(); @@ -484,7 +497,7 @@ $(document).ready(function(){ let formAction = $(this).closest('a').attr("href"); //console.log("Form Action:", formAction); $.ajax({ - url: formAction + "?session=" + session, + url: formAction + "?session=" + me.User.Session, type: "POST", dataType: "json", error: ajaxError, @@ -559,7 +572,7 @@ $(document).ready(function(){ var formAction = $(this).closest('a').attr("href"); //console.log("Form Action:", formAction); //console.log(outData); - $.ajax({ url: formAction + "?session=" + session, type:"POST", dataType:"json", data: outData, error: ajaxError }); + $.ajax({ url: formAction + "?session=" + me.User.Session, type:"POST", dataType:"json", data: outData, error: ajaxError }); blockParent.find('.hide_on_edit').show(); blockParent.find('.show_on_edit').hide(); }); @@ -654,8 +667,8 @@ $(document).ready(function(){ console.log("content.value", content.value); let attachItem; - if(content.value == "") attachItem = "//" + siteURL + "/attachs/" + hash + "." + ext; - else attachItem = "\r\n//" + siteURL + "/attachs/" + hash + "." + ext; + if(content.value == "") attachItem = "//" + me.Site.URL + "/attachs/" + hash + "." + ext; + else attachItem = "\r\n//" + me.Site.URL + "/attachs/" + hash + "." + ext; content.value = content.value + attachItem; console.log("content.value", content.value); @@ -667,9 +680,9 @@ $(document).ready(function(){ } reader.readAsDataURL(files[i]); } - if(totalSize>maxRequestSize) { + if(totalSize > me.Site.MaxRequestSize) { // TODO: Use a notice instead - alert("You can't upload this much data at once, max: " + maxRequestSize); + alert("You can't upload this much data at once, max: " + me.Site.MaxRequestSize); } } @@ -696,7 +709,7 @@ $(document).ready(function(){ }); let bulkActionSender = function(action, selectedTopics, fragBit) { - let url = "/topic/"+action+"/submit/"+fragBit+"?session=" + session; + let url = "/topic/"+action+"/submit/"+fragBit+"?session=" + me.User.Session; $.ajax({ url: url, type: "POST", @@ -746,7 +759,7 @@ $(document).ready(function(){ $("#themeSelectorSelect").change(function(){ console.log("Changing the theme to " + this.options[this.selectedIndex].getAttribute("val")); $.ajax({ - url: this.form.getAttribute("action") + "?session=" + session, + url: this.form.getAttribute("action") + "?session=" + me.User.Session, type: "POST", dataType: "json", data: { "newTheme": this.options[this.selectedIndex].getAttribute("val"), isJs: "1" }, @@ -825,4 +838,4 @@ $(document).ready(function(){ }); runHook("end_init"); -}); +}; diff --git a/router_gen/main.go b/router_gen/main.go index 5f2476eb..a5e7243b 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -644,7 +644,11 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { "after PreRoute\n" + "routeMapEnum: ", routeMapEnum) } + + router.routeSwitch(w, req, user, prefix, extraData) +} +func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user common.User, prefix string, extraData string) { var err common.RouteError switch(prefix) {` + out + ` /*case "/sitemaps": // TODO: Count these views diff --git a/router_gen/routes.go b/router_gen/routes.go index 0f59c2a1..11ab54a6 100644 --- a/router_gen/routes.go +++ b/router_gen/routes.go @@ -14,6 +14,7 @@ func routes() { apiGroup := newRouteGroup("/api/", View("routeAPI", "/api/"), View("routeAPIPhrases", "/api/phrases/"), // TODO: Be careful with exposing the panel phrases here + View("routes.APIMe", "/api/me/"), View("routeJSAntispam", "/api/watches/"), ) addRouteGroup(apiGroup) diff --git a/routes/api.go b/routes/api.go index 7f8f4dd8..64141a36 100644 --- a/routes/api.go +++ b/routes/api.go @@ -1,6 +1,7 @@ package routes import ( + "encoding/json" "errors" "net/http" "strconv" @@ -220,3 +221,35 @@ func SitemapUsers(w http.ResponseWriter, r *http.Request) common.RouteError { w.Write([]byte("\n")) return nil } + +type JsonMe struct { + User *common.MeUser + Site MeSite +} + +// We don't want to expose too much information about the site, so we'll make this a small subset of common.site +type MeSite struct { + URL string + MaxRequestSize int +} + +// APIMe returns information about the current logged-in user +// TODO: Find some way to stop intermediaries from doing compression to avoid the BREACH attack +// TODO: Decouple site settings into a different API? I'd like to avoid having too many requests, if possible, maybe we can use a different name for this? +func APIMe(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError { + // TODO: Don't make this too JSON dependent so that we can swap in newer more efficient formats + w.Header().Set("Content-Type", "application/json") + // We don't want an intermediary accidentally caching this + // TODO: Use this header anywhere with a user check? + w.Header().Set("Cache-Control", "private") + + me := JsonMe{(&user).Me(), MeSite{common.Site.URL, common.Site.MaxRequestSize}} + + jsonBytes, err := json.Marshal(me) + if err != nil { + return common.InternalErrorJS(err, w, r) + } + w.Write(jsonBytes) + + return nil +} diff --git a/templates/header.html b/templates/header.html index 0ff74b7d..d48e6ef2 100644 --- a/templates/header.html +++ b/templates/header.html @@ -11,12 +11,6 @@ {{range .Header.Scripts}} {{end}} - {{if .Header.MetaDesc}}{{end}}