progress on migration to chi

This commit is contained in:
a 2022-02-22 10:31:07 +00:00
parent 9970be19e5
commit edd0e5c018
9 changed files with 446 additions and 304 deletions

370
chi_router.go Normal file
View File

@ -0,0 +1,370 @@
package main
import (
"context"
"log"
"net/http"
"git.tuxpa.in/a/gosora/common"
"git.tuxpa.in/a/gosora/routes"
"git.tuxpa.in/a/gosora/routes/panel"
"git.tuxpa.in/a/gosora/uutils"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
type ContextKey string
var ContextKey_USER ContextKey = "gosora_user"
var ContextKey_EXTRADATA ContextKey = "gosora_extradata"
func AuthContextMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user_copy, ok := common.PreRoute(w, r)
if !ok {
return
}
user := &user_copy
ctx := context.WithValue(r.Context(), ContextKey_USER, user)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
func ParseFormMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
u, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := common.ParseForm(w, r, u)
if err != nil {
log.Println("error parsing form middleware")
return
}
next.ServeHTTP(w, r)
})
}
func NoBannedMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := common.NoBanned(w, r, user)
if err != nil {
log.Println(err)
return
}
next.ServeHTTP(w, r)
})
}
func NoSessionMismatchMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := common.NoSessionMismatch(w, r, user)
if err != nil {
log.Println(err)
return
}
next.ServeHTTP(w, r)
})
}
func MemberOnlyMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := common.MemberOnly(w, r, user)
if err != nil {
log.Println(err)
return
}
next.ServeHTTP(w, r)
})
}
func SuperModOnlyMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := common.SuperModOnly(w, r, user)
if err != nil {
log.Println(err)
return
}
next.ServeHTTP(w, r)
})
}
func SuperAdminOnlyMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := common.SuperAdminOnly(w, r, user)
if err != nil {
log.Println(err)
return
}
next.ServeHTTP(w, r)
})
}
type UserRoute = func(w http.ResponseWriter, r *http.Request, u *common.User) common.RouteError
type ExtraRoute = func(w http.ResponseWriter, r *http.Request, u *common.User, s string) common.RouteError
type HeaderRoute = func(w http.ResponseWriter, r *http.Request, u *common.User, h *common.Header) common.RouteError
type HeaderExtraRoute = func(w http.ResponseWriter, r *http.Request, u *common.User, h *common.Header, s string) common.RouteError
func ConvertUserRoute(fn UserRoute) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
u, ok := r.Context().Value(ContextKey_USER).(*common.User)
if !ok {
log.Println("error grabbing user from context")
return
}
err := fn(w, r, u)
if err != nil {
log.Println("error handling %s %s", fn, err)
}
})
}
func ConvertHeaderRoute(fn HeaderRoute) http.HandlerFunc {
return ConvertUserRoute(func(w http.ResponseWriter, r *http.Request, u *common.User) common.RouteError {
h, err := common.UserCheckNano(w, r, u, uutils.Nanotime())
if err != nil {
return err
}
return fn(w, r, u, h)
})
}
func ConvertExtraRoute(fn ExtraRoute) http.HandlerFunc {
return ConvertUserRoute(func(w http.ResponseWriter, r *http.Request, u *common.User) common.RouteError {
s := chi.URLParam(r, "extra")
return fn(w, r, u, s)
})
}
func ConvertHeaderExtraRoute(fn HeaderExtraRoute) http.HandlerFunc {
return ConvertHeaderRoute(func(w http.ResponseWriter, r *http.Request, u *common.User, h *common.Header) common.RouteError {
s := chi.URLParam(r, "extra")
return fn(w, r, u, h, s)
})
}
func NewChiRouter() {
r := chi.NewRouter()
// A good base middleware stack
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(AuthContextMiddleware)
r.Route("/overview", func(r chi.Router) {
r.Get("/", ConvertHeaderRoute(routes.Overview))
})
r.Route("/pages", func(r chi.Router) {
r.Get("/{extra}", ConvertHeaderExtraRoute(routes.CustomPage))
})
r.Route("/forums", func(r chi.Router) {
r.Get("/", ConvertHeaderRoute(routes.ForumList))
})
r.Route("/forum", func(r chi.Router) {
r.Get("/{extra}", ConvertHeaderExtraRoute(routes.ViewForum))
})
r.Route("/theme", func(r chi.Router) {
r.Use(ParseFormMiddleware)
r.Get("/", ConvertUserRoute(routes.ChangeTheme))
})
r.Route("/attachs", func(r chi.Router) {
r.Use(ParseFormMiddleware)
r.Get("/{extra}", ConvertExtraRoute(routes.ShowAttachment))
})
r.Route("/ws", func(r chi.Router) {
r.Get("/{extra}", ConvertUserRoute(common.RouteWebsockets))
})
r.Route("/api", func(r chi.Router) {
r.Get("/phrases*", ConvertUserRoute(routeAPIPhrases))
r.Get("/me*", ConvertUserRoute(routes.APIMe))
r.Get("/watches*", ConvertUserRoute(routeJSAntispam))
r.Get("/*", ConvertUserRoute(routeAPI))
})
r.Route("/report", func(r chi.Router) {
r.Use(NoBannedMiddleware)
r.Use(NoSessionMismatchMiddleware)
r.Use(MemberOnlyMiddleware)
r.Get("/submit/{extra}", ConvertExtraRoute(routes.ReportSubmit))
})
r.Route("/topics", func(r chi.Router) {
r.Get("/most-viewed", ConvertHeaderRoute(routes.TopicListMostViewed))
r.Get("/week-views", ConvertHeaderRoute(routes.TopicListWeekViews))
r.Get("/create", ConvertHeaderExtraRoute(routes.CreateTopic))
r.Get("/", ConvertHeaderRoute(routes.TopicList))
})
r.Route("/panel", func(r chi.Router) {
r.Use(SuperModOnlyMiddleware)
r.Use(NoSessionMismatchMiddleware)
r.Route("/forums", func(r chi.Router) {
r.Get("/", ConvertUserRoute(panel.Forums))
r.Get("/create", ConvertUserRoute(panel.ForumsCreateSubmit))
r.Get("/delete/{extra}", ConvertExtraRoute(panel.ForumsDelete))
r.Get("/delete/submit/{extra}", ConvertExtraRoute(panel.ForumsDeleteSubmit))
r.Get("/order/edit/submit", ConvertUserRoute(panel.ForumsOrderSubmit))
r.Get("/edit/{extra}", ConvertExtraRoute(panel.ForumsEdit))
r.Get("/edit/submit/{extra}", ConvertExtraRoute(panel.ForumsEditSubmit))
r.Get("/edit/perms/submit/{extra}", ConvertExtraRoute(panel.ForumsEditPermsSubmit))
r.Get("/edit/perms/{extra}", ConvertExtraRoute(panel.ForumsEditPermsAdvance))
r.Get("/edit/perms/adv/submit/{extra}", ConvertExtraRoute(panel.ForumsEditPermsAdvanceSubmit))
r.Get("/action/create/submit/{extra}", ConvertExtraRoute(panel.ForumsEditActionCreateSubmit))
r.Get("/action/delete/submit/{extra}", ConvertExtraRoute(panel.ForumsEditActionDeleteSubmit))
})
r.Route("/settings", func(r chi.Router) {
r.Get("/", ConvertUserRoute(panel.Settings))
r.Get("/edit/{extra}", ConvertExtraRoute(panel.SettingEdit))
r.Get("/edit/submit/{extra}", ConvertExtraRoute(panel.SettingEditSubmit))
r.Get("/word-filters", ConvertUserRoute(panel.WordFilters))
r.Get("/word-filters/create", ConvertUserRoute(panel.WordFiltersCreateSubmit))
r.Get("/word-filters/edit/{extra}", ConvertExtraRoute(panel.WordFiltersEdit))
r.Get("/word-filters/edit/submit/{extra}", ConvertExtraRoute(panel.WordFiltersEdit))
r.Get("/word-filters/delete/submit/{extra}", ConvertExtraRoute(panel.WordFiltersDeleteSubmit))
})
r.Route("/pages", func(r chi.Router) {
r.Get("/create/submit", ConvertUserRoute(panel.PagesCreateSubmit))
r.Get("/edit/{extra}", ConvertExtraRoute(panel.PagesEdit))
r.Get("/edit/submit/{extra}", ConvertExtraRoute(panel.PagesEditSubmit))
r.Get("/delete/submit/{extra}", ConvertExtraRoute(panel.PagesDeleteSubmit))
})
r.Route("/themes", func(r chi.Router) {
r.Get("/", ConvertUserRoute(panel.Themes))
r.Get("/default/{extra}", ConvertExtraRoute(panel.ThemesSetDefault))
r.Get("/menus", ConvertUserRoute(panel.ThemesMenus))
r.Get("/menus/edit/{extra}", ConvertExtraRoute(panel.ThemesMenusEdit))
r.Get("/menus/item/edit/{extra}", ConvertExtraRoute(panel.ThemesMenuItemEdit))
r.Get("/menus/item/edit/submit/{extra}", ConvertExtraRoute(panel.ThemesMenuItemEditSubmit))
r.Get("/menus/item/create/submit", ConvertUserRoute(panel.ThemesMenuItemCreateSubmit))
r.Get("/menus/item/delete/submit/{extra}", ConvertExtraRoute(panel.ThemesMenuItemDeleteSubmit))
r.Get("/menus/item/order/edit/submit/{extra}", ConvertExtraRoute(panel.ThemesMenuItemOrderSubmit))
r.Get("/widgets/edit/submit/{extra}", ConvertExtraRoute(panel.ThemesWidgetsEditSubmit))
r.Get("/widgets/create/submit", ConvertUserRoute(panel.ThemesWidgetsCreateSubmit))
r.Get("/widgets/delete/submit/{extra}", ConvertExtraRoute(panel.ThemesWidgetsDeleteSubmit))
})
r.Route("/plugins", func(r chi.Router) {
r.Get("/{extra}", ConvertExtraRoute(panel.PluginsInstall))
r.Get("/activate/{extra}", ConvertExtraRoute(panel.PluginsActivate))
r.Get("/deactivate/{extra}", ConvertExtraRoute(panel.PluginsDeactivate))
r.Get("/install/{extra}", ConvertExtraRoute(panel.PluginsInstall))
})
})
r.Route("/user", func(r chi.Router) {
r.Use(MemberOnlyMiddleware)
r.Route("/edit", func(r chi.Router) {
r.Get("/", ConvertHeaderRoute(routes.AccountEdit))
r.Get("/password", ConvertHeaderRoute(routes.AccountEditPassword))
r.Get("/password/submit", ConvertUserRoute(routes.AccountEditPasswordSubmit))
r.Get("/avatar/submit", ConvertUserRoute(routes.AccountEditAvatarSubmit))
r.Get("/avatar/revoke/submit", ConvertUserRoute(routes.AccountEditRevokeAvatarSubmit))
r.Get("/username/submit", ConvertUserRoute(routes.AccountEditUsernameSubmit))
r.Get("/privacy", ConvertHeaderRoute(routes.AccountEditPrivacy))
r.Get("/privacy/submit", ConvertUserRoute(routes.AccountEditPrivacySubmit))
r.Get("/mfa", ConvertHeaderRoute(routes.AccountEditMFA))
r.Get("/mfa/setup", ConvertHeaderRoute(routes.AccountEditMFASetup))
r.Get("/mfa/setup/submit", ConvertUserRoute(routes.AccountEditMFASetupSubmit))
r.Get("/mfa/disable/submit", ConvertUserRoute(routes.AccountEditMFADisableSubmit))
r.Get("/email", ConvertHeaderRoute(routes.AccountEditEmail))
r.Get("/token", ConvertExtraRoute(routes.AccountEditEmailTokenSubmit))
r.Get("/logins", ConvertHeaderRoute(routes.AccountLogins))
r.Get("/blocked", ConvertHeaderRoute(routes.AccountBlocked))
})
r.Get("/levels", ConvertHeaderRoute(routes.LevelList))
r.Get("/convos", ConvertHeaderRoute(routes.Convos))
r.Get("/convos/create", ConvertHeaderRoute(routes.ConvosCreate))
r.Get("/convo", ConvertHeaderExtraRoute(routes.Convo))
r.Get("/convos/create/submit", ConvertUserRoute(routes.ConvosCreateSubmit))
r.Get("/convo/create/submit", ConvertUserRoute(routes.ConvosCreateSubmit))
r.Get("/convo/delete/submit", ConvertExtraRoute(routes.ConvosDeleteReplySubmit))
r.Get("/convo/edit/submit", ConvertExtraRoute(routes.ConvosEditReplySubmit))
r.Get("/block/create", ConvertHeaderExtraRoute(routes.RelationsBlockCreate))
r.Get("/block/create/submit", ConvertExtraRoute(routes.RelationsBlockCreateSubmit))
r.Get("/block/remove", ConvertHeaderExtraRoute(routes.RelationsBlockRemove))
r.Get("/block/remove/submit", ConvertExtraRoute(routes.RelationsBlockRemoveSubmit))
r.Get("/{user}", ConvertExtraRoute(routes))
})
r.Route("/users", func(r chi.Router) {
r.Get("/ban/submit", ConvertExtraRoute(routes))
r.Get("/unban", ConvertExtraRoute(routes))
r.Get("/activate", ConvertExtraRoute(routes))
r.Get("/ips", ConvertExtraRoute(routes))
r.Get("/delete-posts/submit", ConvertExtraRoute(routes))
})
r.Route("/topic", func(r chi.Router) {
r.Get("/create/submit", ConvertExtraRoute(routes))
r.Get("/edit/submit", ConvertExtraRoute(routes))
r.Get("/delete/submit", ConvertExtraRoute(routes))
r.Get("/stick/submit", ConvertExtraRoute(routes))
r.Get("/unstick/submit", ConvertExtraRoute(routes))
r.Get("/lock/submit", ConvertExtraRoute(routes))
r.Get("/unlock/submit", ConvertExtraRoute(routes))
r.Get("/move/submit", ConvertExtraRoute(routes))
r.Get("/like/submit", ConvertExtraRoute(routes))
r.Get("/unlike/submit", ConvertExtraRoute(routes))
r.Get("/attach/add/submit", ConvertExtraRoute(routes))
r.Get("/attach/remove/submit", ConvertExtraRoute(routes))
})
r.Route("/reply", func(r chi.Router) {
r.Get("/create", ConvertExtraRoute(routes))
r.Get("/edit/submit", ConvertExtraRoute(routes))
r.Get("/delete/submit", ConvertExtraRoute(routes))
r.Get("/like/submit", ConvertExtraRoute(routes))
r.Get("/unlike/submit", ConvertExtraRoute(routes))
r.Get("/attach/add/submit", ConvertExtraRoute(routes))
r.Get("/attach/remove/submit", ConvertExtraRoute(routes))
})
r.Route("/profile", func(r chi.Router) {
r.Get("/reply/create", ConvertExtraRoute(routes))
r.Get("/reply/edit/submit", ConvertExtraRoute(routes))
r.Get("/reply/edit/delete/submit", ConvertExtraRoute(routes))
})
r.Route("/poll", func(r chi.Router) {
r.Get("/poll/vote", ConvertExtraRoute(routes))
r.Get("/poll/results", ConvertExtraRoute(routes))
})
r.Route("/accounts", func(r chi.Router) {
r.Get("/login", ConvertExtraRoute(routes))
r.Get("/create", ConvertExtraRoute(routes))
r.Get("/logout", ConvertExtraRoute(routes))
r.Get("/login/submit", ConvertExtraRoute(routes))
r.Get("/mfa_verify", ConvertExtraRoute(routes))
r.Get("/mfa_verify/submit", ConvertExtraRoute(routes))
r.Get("/create/submit", ConvertExtraRoute(routes))
r.Get("/password-reset", ConvertExtraRoute(routes))
r.Get("/password-reset/submit", ConvertExtraRoute(routes))
r.Get("/password-reset/token", ConvertExtraRoute(routes))
r.Get("/password-reset/token/submit", ConvertExtraRoute(routes))
})
r.Route("/static", func(r chi.Router) {})
r.Route("/uploads", func(r chi.Router) {})
http.ListenAndServe(":3333", r)
}

View File

@ -8,8 +8,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
var stmts *Stmts
var db *sql.DB var db *sql.DB
var dbAdapter string var dbAdapter string
@ -19,89 +17,88 @@ var ErrNoRows = sql.ErrNoRows
var _initDatabase func() error var _initDatabase func() error
func InitDatabase() (err error) { func InitDatabase() (err error) {
stmts = &Stmts{Mocks: false}
// Engine specific code // Engine specific code
err = _initDatabase() err = _initDatabase()
if err != nil { if err != nil {
return err return err
} }
globs = &Globs{stmts} globs = &Globs{}
ws := errors.WithStack ws := errors.WithStack
log.Print("Running the db handlers.") log.Print("Running the db handlers.")
err = c.DbInits.Run() err = c.DbInits.Run()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
log.Print("Loading the usergroups.") log.Print("Loading the usergroups.")
c.Groups, err = c.NewMemoryGroupStore() c.Groups, err = c.NewMemoryGroupStore()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
err2 := c.Groups.LoadGroups() err2 := c.Groups.LoadGroups()
if err2 != nil { if err2 != nil {
return ws(err2) return ws(err2)
} }
// We have to put this here, otherwise LoadForums() won't be able to get the last poster data when building it's forums // We have to put this here, otherwise LoadForums() won't be able to get the last poster data when building it's forums
log.Print("Initialising the user and topic stores") log.Print("Initialising the user and topic stores")
var ucache c.UserCache var ucache c.UserCache
if c.Config.UserCache == "static" { if c.Config.UserCache == "static" {
ucache = c.NewMemoryUserCache(c.Config.UserCacheCapacity) ucache = c.NewMemoryUserCache(c.Config.UserCacheCapacity)
} }
var tcache c.TopicCache var tcache c.TopicCache
if c.Config.TopicCache == "static" { if c.Config.TopicCache == "static" {
tcache = c.NewMemoryTopicCache(c.Config.TopicCacheCapacity) tcache = c.NewMemoryTopicCache(c.Config.TopicCacheCapacity)
} }
c.Users, err = c.NewDefaultUserStore(ucache) c.Users, err = c.NewDefaultUserStore(ucache)
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
c.Topics, err = c.NewDefaultTopicStore(tcache) c.Topics, err = c.NewDefaultTopicStore(tcache)
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
log.Print("Loading the forums.") log.Print("Loading the forums.")
c.Forums, err = c.NewMemoryForumStore() c.Forums, err = c.NewMemoryForumStore()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
err = c.Forums.LoadForums() err = c.Forums.LoadForums()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
log.Print("Loading the forum permissions.") log.Print("Loading the forum permissions.")
c.FPStore, err = c.NewMemoryForumPermsStore() c.FPStore, err = c.NewMemoryForumPermsStore()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
err = c.FPStore.Init() err = c.FPStore.Init()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
log.Print("Loading the settings.") log.Print("Loading the settings.")
err = c.LoadSettings() err = c.LoadSettings()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
log.Print("Loading the plugins.") log.Print("Loading the plugins.")
err = c.InitExtend() err = c.InitExtend()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
log.Print("Loading the themes.") log.Print("Loading the themes.")
err = c.Themes.LoadActiveStatus() err = c.Themes.LoadActiveStatus()
if err != nil { if err != nil {
return ws(err) return ws(err)
} }
return nil return nil
} }

View File

@ -1,97 +0,0 @@
//go:build mssql
// +build mssql
// This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time.
package main
import "log"
import "database/sql"
import "git.tuxpa.in/a/gosora/common"
// nolint
type Stmts struct {
forumEntryExists *sql.Stmt
groupEntryExists *sql.Stmt
getForumTopics *sql.Stmt
addForumPermsToForum *sql.Stmt
updateEmail *sql.Stmt
setTempGroup *sql.Stmt
bumpSync *sql.Stmt
deleteActivityStreamMatch *sql.Stmt
getActivityFeedByWatcher *sql.Stmt
getActivityCountByWatcher *sql.Stmt
Mocks bool
}
// nolint
func _gen_mssql() (err error) {
common.DebugLog("Building the generated statements")
common.DebugLog("Preparing forumEntryExists statement.")
stmts.forumEntryExists, err = db.Prepare("SELECT [fid] FROM [forums] WHERE [name] = '' ORDER BY fid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")
if err != nil {
log.Print("Error in forumEntryExists statement.")
log.Print("Bad Query: ", "SELECT [fid] FROM [forums] WHERE [name] = '' ORDER BY fid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")
return err
}
common.DebugLog("Preparing groupEntryExists statement.")
stmts.groupEntryExists, err = db.Prepare("SELECT [gid] FROM [users_groups] WHERE [name] = '' ORDER BY gid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")
if err != nil {
log.Print("Error in groupEntryExists statement.")
log.Print("Bad Query: ", "SELECT [gid] FROM [users_groups] WHERE [name] = '' ORDER BY gid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")
return err
}
common.DebugLog("Preparing getForumTopics statement.")
stmts.getForumTopics, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[lastReplyAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy]=[users].[uid] WHERE [topics].[parentID] = ?1 ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC")
if err != nil {
log.Print("Error in getForumTopics statement.")
log.Print("Bad Query: ", "SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[lastReplyAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy]=[users].[uid] WHERE [topics].[parentID] = ?1 ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC")
return err
}
common.DebugLog("Preparing addForumPermsToForum statement.")
stmts.addForumPermsToForum, err = db.Prepare("INSERT INTO [forums_permissions] ([gid],[fid],[preset],[permissions]) VALUES (?,?,?,?)")
if err != nil {
log.Print("Error in addForumPermsToForum statement.")
log.Print("Bad Query: ", "INSERT INTO [forums_permissions] ([gid],[fid],[preset],[permissions]) VALUES (?,?,?,?)")
return err
}
common.DebugLog("Preparing updateEmail statement.")
stmts.updateEmail, err = db.Prepare("UPDATE [emails] SET [email]= ?,[uid]= ?,[validated]= ?,[token]= ? WHERE [email] = ?")
if err != nil {
log.Print("Error in updateEmail statement.")
log.Print("Bad Query: ", "UPDATE [emails] SET [email]= ?,[uid]= ?,[validated]= ?,[token]= ? WHERE [email] = ?")
return err
}
common.DebugLog("Preparing setTempGroup statement.")
stmts.setTempGroup, err = db.Prepare("UPDATE [users] SET [temp_group]= ? WHERE [uid] = ?")
if err != nil {
log.Print("Error in setTempGroup statement.")
log.Print("Bad Query: ", "UPDATE [users] SET [temp_group]= ? WHERE [uid] = ?")
return err
}
common.DebugLog("Preparing bumpSync statement.")
stmts.bumpSync, err = db.Prepare("UPDATE [sync] SET [last_update]= GETUTCDATE()")
if err != nil {
log.Print("Error in bumpSync statement.")
log.Print("Bad Query: ", "UPDATE [sync] SET [last_update]= GETUTCDATE()")
return err
}
common.DebugLog("Preparing deleteActivityStreamMatch statement.")
stmts.deleteActivityStreamMatch, err = db.Prepare("DELETE FROM [activity_stream_matches] WHERE [watcher] = ? AND [asid] = ?")
if err != nil {
log.Print("Error in deleteActivityStreamMatch statement.")
log.Print("Bad Query: ", "DELETE FROM [activity_stream_matches] WHERE [watcher] = ? AND [asid] = ?")
return err
}
return nil
}

View File

@ -1,95 +0,0 @@
//go:build !pgsql && !mssql
// +build !pgsql,!mssql
/* This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. */
package main
import (
"database/sql"
"log"
"git.tuxpa.in/a/gosora/common"
)
//import "git.tuxpa.in/a/gosora/query_gen"
// nolint
type Stmts struct {
forumEntryExists *sql.Stmt
groupEntryExists *sql.Stmt
getForumTopics *sql.Stmt
addForumPermsToForum *sql.Stmt
updateEmail *sql.Stmt
setTempGroup *sql.Stmt
bumpSync *sql.Stmt
deleteActivityStreamMatch *sql.Stmt
getActivityFeedByWatcher *sql.Stmt
getActivityCountByWatcher *sql.Stmt
Mocks bool
}
// nolint
func _gen_mysql() (err error) {
common.DebugLog("Building the generated statements")
common.DebugLog("Preparing forumEntryExists statement.")
stmts.forumEntryExists, err = db.Prepare("SELECT `fid` FROM `forums` WHERE `name` = '' ORDER BY `fid` ASC LIMIT 0,1")
if err != nil {
log.Print("Error in forumEntryExists statement.")
return err
}
common.DebugLog("Preparing groupEntryExists statement.")
stmts.groupEntryExists, err = db.Prepare("SELECT `gid` FROM `users_groups` WHERE `name` = '' ORDER BY `gid` ASC LIMIT 0,1")
if err != nil {
log.Print("Error in groupEntryExists statement.")
return err
}
common.DebugLog("Preparing getForumTopics statement.")
stmts.getForumTopics, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`createdAt`, `topics`.`lastReplyAt`, `topics`.`parentID`, `users`.`name`, `users`.`avatar` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` WHERE `topics`.`parentID` = ? ORDER BY `topics`.`sticky` DESC,`topics`.`lastReplyAt` DESC,`topics`.`createdBy` DESC")
if err != nil {
log.Print("Error in getForumTopics statement.")
return err
}
common.DebugLog("Preparing addForumPermsToForum statement.")
stmts.addForumPermsToForum, err = db.Prepare("INSERT INTO `forums_permissions`(`gid`,`fid`,`preset`,`permissions`) VALUES (?,?,?,?)")
if err != nil {
log.Print("Error in addForumPermsToForum statement.")
return err
}
common.DebugLog("Preparing updateEmail statement.")
stmts.updateEmail, err = db.Prepare("UPDATE `emails` SET `email`= ?,`uid`= ?,`validated`= ?,`token`= ? WHERE `email` = ?")
if err != nil {
log.Print("Error in updateEmail statement.")
return err
}
common.DebugLog("Preparing setTempGroup statement.")
stmts.setTempGroup, err = db.Prepare("UPDATE `users` SET `temp_group`= ? WHERE `uid` = ?")
if err != nil {
log.Print("Error in setTempGroup statement.")
return err
}
common.DebugLog("Preparing bumpSync statement.")
stmts.bumpSync, err = db.Prepare("UPDATE `sync` SET `last_update`= UTC_TIMESTAMP()")
if err != nil {
log.Print("Error in bumpSync statement.")
return err
}
common.DebugLog("Preparing deleteActivityStreamMatch statement.")
stmts.deleteActivityStreamMatch, err = db.Prepare("DELETE FROM `activity_stream_matches` WHERE `watcher` = ? AND `asid` = ?")
if err != nil {
log.Print("Error in deleteActivityStreamMatch statement.")
return err
}
return nil
}

View File

@ -16,8 +16,6 @@ import (
"git.tuxpa.in/a/gosora/uutils" "git.tuxpa.in/a/gosora/uutils"
"git.tuxpa.in/a/gosora/routes" "git.tuxpa.in/a/gosora/routes"
"git.tuxpa.in/a/gosora/routes/panel" "git.tuxpa.in/a/gosora/routes/panel"
//"github.com/andybalholm/brotli"
) )
var ErrNoRoute = errors.New("That route doesn't exist.") var ErrNoRoute = errors.New("That route doesn't exist.")
@ -920,9 +918,6 @@ func (r *GenRouter) SuspiciousRequest(req *http.Request, pre string) {
co.AgentViewCounter.Bump(43) co.AgentViewCounter.Bump(43)
} }
// TODO: Pass the default path or config struct to the router rather than accessing it via a package global
// TODO: SetDefaultPath
// TODO: GetDefaultPath
func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
malformedRequest := func(typ int) { malformedRequest := func(typ int) {
w.WriteHeader(200) // 400 w.WriteHeader(200) // 400

1
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc
github.com/fortytw2/leaktest v1.3.0 // indirect github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/go-chi/chi/v5 v5.0.7 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2

2
go.sum
View File

@ -22,6 +22,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw= github.com/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw=
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=

View File

@ -1 +0,0 @@
This file is here so that Git will include this folder in the repository.

View File

@ -1,30 +0,0 @@
package tmpl
import (
//"reflect"
//"runtime"
//"unsafe"
"git.tuxpa.in/a/gosora/uutils"
)
var GetFrag = func(name string) [][]byte {
return nil
}
type WriteString interface {
WriteString(s string) (n int, err error)
}
var StringToBytes = uutils.StringToBytes
/*
func StringToBytes(s string) (bytes []byte) {
str := (*reflect.StringHeader)(unsafe.Pointer(&s))
slice := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
slice.Data = str.Data
slice.Len = str.Len
slice.Cap = str.Len
runtime.KeepAlive(&s)
return bytes
}
*/