Archived
1
0
This commit is contained in:
Jeff Becker 2018-03-09 16:24:57 -05:00
parent 58464582bd
commit caf9378073
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
5 changed files with 24 additions and 40 deletions

View File

@ -1,11 +0,0 @@
<!doctype html>
<html>
<head>
<title> Error </title>
</head>
<body>
<pre> {{ .Error}} </pre>
</body>
</html>

View File

@ -1,11 +0,0 @@
<!doctype html>
<html>
<head>
<title> Overchan </title>
</head>
<body>
<pre>ebin</pre>
</body>
</html>

View File

@ -6,9 +6,12 @@ type MiddlewareConfig struct {
Type string `json:"type"` Type string `json:"type"`
// directory for our html templates // directory for our html templates
Templates string `json:"templates_dir"` Templates string `json:"templates_dir"`
// directory for static files
StaticDir string `json:"static_dir"`
} }
var DefaultMiddlewareConfig = MiddlewareConfig{ var DefaultMiddlewareConfig = MiddlewareConfig{
Type: "overchan", Type: "overchan",
Templates: "./files/templates/overchan/", Templates: "./files/templates/overchan/",
StaticDir: "./files/",
} }

View File

@ -18,6 +18,7 @@ type overchanMiddleware struct {
captcha *CaptchaServer captcha *CaptchaServer
store *sessions.CookieStore store *sessions.CookieStore
db database.Database db database.Database
staticDir string
} }
func (m *overchanMiddleware) SetupRoutes(mux *mux.Router) { func (m *overchanMiddleware) SetupRoutes(mux *mux.Router) {
@ -34,6 +35,8 @@ func (m *overchanMiddleware) SetupRoutes(mux *mux.Router) {
m.captcha = NewCaptchaServer(200, 400, captchaPrefix, m.store) m.captcha = NewCaptchaServer(200, 400, captchaPrefix, m.store)
// setup captcha endpoint // setup captcha endpoint
m.captcha.SetupRoutes(mux.PathPrefix(captchaPrefix).Subrouter()) m.captcha.SetupRoutes(mux.PathPrefix(captchaPrefix).Subrouter())
mux.Path("/static/").Handler(http.FileServer(http.Dir(m.staticDir)))
} }
// reload middleware // reload middleware
@ -57,9 +60,9 @@ func (m *overchanMiddleware) ServeBoardPage(w http.ResponseWriter, r *http.Reque
var obj interface{} var obj interface{}
obj, err = m.db.BoardPage(board, pageno, 10) obj, err = m.db.BoardPage(board, pageno, 10)
if err == nil { if err == nil {
m.serveTemplate(w, r, "board.html.tmpl", obj) m.serveTemplate(w, r, "board.html", obj)
} else { } else {
m.serveTemplate(w, r, "error.html.tmpl", err) m.serveTemplate(w, r, "error.html", err)
} }
} else { } else {
// 404 // 404
@ -72,15 +75,15 @@ func (m *overchanMiddleware) ServeThread(w http.ResponseWriter, r *http.Request)
param := mux.Vars(r) param := mux.Vars(r)
obj, err := m.db.ThreadByHash(param["id"]) obj, err := m.db.ThreadByHash(param["id"])
if err == nil { if err == nil {
m.serveTemplate(w, r, "thread.html.tmpl", obj) m.serveTemplate(w, r, "thread.html", obj)
} else { } else {
m.serveTemplate(w, r, "error.html.tmpl", err) m.serveTemplate(w, r, "error.html", err)
} }
} }
// serve index page // serve index page
func (m *overchanMiddleware) ServeIndex(w http.ResponseWriter, r *http.Request) { func (m *overchanMiddleware) ServeIndex(w http.ResponseWriter, r *http.Request) {
m.serveTemplate(w, r, "index.html.tmpl", nil) m.serveTemplate(w, r, "index.html", nil)
} }
// serve a template // serve a template

View File

@ -157,10 +157,10 @@ func (self *PostgresDatabase) prepareStatements() {
NewsgroupBanned: "SELECT 1 FROM BannedGroups WHERE newsgroup = $1", NewsgroupBanned: "SELECT 1 FROM BannedGroups WHERE newsgroup = $1",
ArticleBanned: "SELECT 1 FROM BannedArticles WHERE message_id = $1", ArticleBanned: "SELECT 1 FROM BannedArticles WHERE message_id = $1",
GetAllNewsgroups: "SELECT name FROM Newsgroups WHERE name NOT IN ( SELECT newsgroup FROM BannedGroups )", GetAllNewsgroups: "SELECT name FROM Newsgroups WHERE name NOT IN ( SELECT newsgroup FROM BannedGroups )",
GetPostsInGroup: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE newsgroup = $1 ORDER BY time_posted", GetPostsInGroup: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr, frontendpubkey FROM ArticlePosts WHERE newsgroup = $1 ORDER BY time_posted",
GetPostModel: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE message_id = $1 LIMIT 1", GetPostModel: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr, frontendpubkey FROM ArticlePosts WHERE message_id = $1 LIMIT 1",
GetArticlePubkey: "SELECT pubkey FROM ArticleKeys WHERE message_id = $1", GetArticlePubkey: "SELECT pubkey FROM ArticleKeys WHERE message_id = $1",
GetThreadModel: "SELECT ArticlePosts.newsgroup, ArticlePosts.message_id, ArticlePosts.name, ArticlePosts.subject, ArticlePosts.time_posted, ArticlePosts.message, ArticlePosts.addr FROM ArticlePosts WHERE ArticlePosts.message_id = $1 OR ArticlePosts.ref_id = $1 ORDER BY ArticlePosts.time_posted", GetThreadModel: "SELECT ArticlePosts.newsgroup, ArticlePosts.message_id, ArticlePosts.name, ArticlePosts.subject, ArticlePosts.time_posted, ArticlePosts.message, ArticlePosts.addr, ArticlePosts.frontendpubkey FROM ArticlePosts WHERE ArticlePosts.message_id = $1 OR ArticlePosts.ref_id = $1 ORDER BY ArticlePosts.time_posted",
GetThreadModelPubkeys: "SELECT pubkey, message_id from ArticleKeys WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 OR message_id = $1 )", GetThreadModelPubkeys: "SELECT pubkey, message_id from ArticleKeys WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 OR message_id = $1 )",
GetThreadModelAttachments: "SELECT filename, filepath, message_id from ArticleAttachments WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 OR message_id = $1 )", GetThreadModelAttachments: "SELECT filename, filepath, message_id from ArticleAttachments WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 OR message_id = $1 )",
DeleteArticle_1: "DELETE FROM NNTPHeaders WHERE header_article_message_id = $1", DeleteArticle_1: "DELETE FROM NNTPHeaders WHERE header_article_message_id = $1",
@ -171,8 +171,8 @@ func (self *PostgresDatabase) prepareStatements() {
DeleteThread: "DELETE FROM ArticleThreads WHERE root_message_id = $1", DeleteThread: "DELETE FROM ArticleThreads WHERE root_message_id = $1",
DeleteArticleV8: "DELETE FROM ArticlePosts WHERE message_id = $1", DeleteArticleV8: "DELETE FROM ArticlePosts WHERE message_id = $1",
DeleteThreadV8: "DELETE FROM ArticlePosts WHERE ref_id = $1 OR message_id = $1", DeleteThreadV8: "DELETE FROM ArticlePosts WHERE ref_id = $1 OR message_id = $1",
GetThreadReplyPostModels_1: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ORDER BY time_posted DESC LIMIT $2 ) ORDER BY time_posted ASC", GetThreadReplyPostModels_1: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr, frontendpubkey FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ORDER BY time_posted DESC LIMIT $2 ) ORDER BY time_posted ASC",
GetThreadReplyPostModels_2: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ) ORDER BY time_posted ASC", GetThreadReplyPostModels_2: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr, frontendpubkey FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ) ORDER BY time_posted ASC",
GetThreadReplies_1: "SELECT message_id FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ORDER BY time_posted DESC LIMIT $2 ) ORDER BY time_posted ASC", GetThreadReplies_1: "SELECT message_id FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ORDER BY time_posted DESC LIMIT $2 ) ORDER BY time_posted ASC",
GetThreadReplies_2: "SELECT message_id FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ) ORDER BY time_posted ASC", GetThreadReplies_2: "SELECT message_id FROM ArticlePosts WHERE message_id IN ( SELECT message_id FROM ArticlePosts WHERE ref_id = $1 ) ORDER BY time_posted ASC",
GetGroupThreads: "SELECT message_id FROM ArticlePosts WHERE newsgroup = $1 AND ref_id = '' ", GetGroupThreads: "SELECT message_id FROM ArticlePosts WHERE newsgroup = $1 AND ref_id = '' ",
@ -1132,7 +1132,7 @@ func (self *PostgresDatabase) GetPostsInGroup(newsgroup string) (models []PostMo
if err == nil { if err == nil {
for rows.Next() { for rows.Next() {
model := new(post) model := new(post)
rows.Scan(&model.board, &model.Message_id, &model.Parent, &model.PostName, &model.PostSubject, &model.MessagePath, &model.Posted, &model.PostMessage, &model.addr) rows.Scan(&model.board, &model.Message_id, &model.Parent, &model.PostName, &model.PostSubject, &model.MessagePath, &model.Posted, &model.PostMessage, &model.addr, &model.FrontendPublicKey)
models = append(models, model) models = append(models, model)
} }
rows.Close() rows.Close()
@ -1142,7 +1142,7 @@ func (self *PostgresDatabase) GetPostsInGroup(newsgroup string) (models []PostMo
func (self *PostgresDatabase) GetPostModel(prefix, messageID string) PostModel { func (self *PostgresDatabase) GetPostModel(prefix, messageID string) PostModel {
model := new(post) model := new(post)
err := self.conn.QueryRow(self.stmt[GetPostModel], messageID).Scan(&model.board, &model.Message_id, &model.Parent, &model.PostName, &model.PostSubject, &model.MessagePath, &model.Posted, &model.PostMessage, &model.addr) err := self.conn.QueryRow(self.stmt[GetPostModel], messageID).Scan(&model.board, &model.Message_id, &model.Parent, &model.PostName, &model.PostSubject, &model.MessagePath, &model.Posted, &model.PostMessage, &model.addr, &model.FrontendPublicKey)
if err == nil { if err == nil {
model.op = len(model.Parent) == 0 model.op = len(model.Parent) == 0
if len(model.Parent) == 0 { if len(model.Parent) == 0 {
@ -1188,7 +1188,7 @@ func (self *PostgresDatabase) GetThreadModel(prefix, msgid string) (th ThreadMod
for err == nil && rows.Next() { for err == nil && rows.Next() {
p := new(post) p := new(post)
p.Parent = msgid p.Parent = msgid
err = rows.Scan(&p.board, &p.Message_id, &p.PostName, &p.PostSubject, &p.Posted, &p.PostMessage, &p.addr) err = rows.Scan(&p.board, &p.Message_id, &p.PostName, &p.PostSubject, &p.Posted, &p.PostMessage, &p.addr, &p.FrontendPublicKey)
pmap[p.Message_id] = p pmap[p.Message_id] = p
posts = append(posts, p) posts = append(posts, p)
} }
@ -1259,7 +1259,7 @@ func (self *PostgresDatabase) GetThreadReplyPostModels(prefix, rootpost string,
} }
model := new(post) model := new(post)
model.prefix = prefix model.prefix = prefix
rows.Scan(&model.board, &model.Message_id, &model.Parent, &model.PostName, &model.PostSubject, &model.MessagePath, &model.Posted, &model.PostMessage, &model.addr) rows.Scan(&model.board, &model.Message_id, &model.Parent, &model.PostName, &model.PostSubject, &model.MessagePath, &model.Posted, &model.PostMessage, &model.addr, &model.FrontendPublicKey)
model.op = len(model.Parent) == 0 model.op = len(model.Parent) == 0
if len(model.Parent) == 0 { if len(model.Parent) == 0 {
model.Parent = model.Message_id model.Parent = model.Message_id