dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit f3567444ca28cd1069b2e417f600916317fe8132
parent c6263a7abc05918de50aa2ee4a961369386c430d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun,  7 Jan 2024 00:11:37 -0500

POC multi domain hack to avoid network.http.max-persistent-connections-per-server limitations

Diffstat:
Mpkg/web/handlers/poker/poker.go | 13+++++++++++--
Mpkg/web/middlewares/middlewares.go | 8++++++++
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -2,6 +2,7 @@ package poker import ( "bytes" + "dkforest/pkg/config" "dkforest/pkg/database" "dkforest/pkg/pubsub" "dkforest/pkg/utils" @@ -1735,6 +1736,14 @@ func buildGameDiv(g *Game, authUser *database.User) (html string) { } func BuildBaseHtml(g *Game, authUser *database.User, chatRoomSlug string) (html string) { + firstDomain := "" + secondDomain := "" + apiToken := authUser.ApiKey + if config.Development.IsFalse() && apiToken != "" { + firstDomain = "http://peddrcq5m2digvtwjf3beh7wb4pqsn3jbfxq2x4wwvey4gy42uqgtbyd.onion" + secondDomain = "http://hm4iv33o5l7gmjk6gnp75payt7ruoez754hukqksf5vatrgxs7xmx2yd.onion" + } + ongoing := g.ongoing roomID := g.roomID html += hutils.HtmlCssReset @@ -1746,9 +1755,9 @@ func BuildBaseHtml(g *Game, authUser *database.User, chatRoomSlug string) (html html += buildHelpHtml() html += `<div id="chat-div">` html += ` <iframe id="chat-top-bar" name="iframe1" src="/api/v1/chat/top-bar/` + chatRoomSlug + `" sandbox="allow-forms allow-scripts allow-same-origin allow-top-navigation-by-user-activation"></iframe>` - html += ` <iframe id="chat-content" name="iframe2" src="/api/v1/chat/messages/` + chatRoomSlug + `/stream?hrm=1&hactions=1&hide_ts=1"></iframe>` + html += ` <iframe id="chat-content" name="iframe2" src="` + firstDomain + `/api/v1/chat/messages/` + chatRoomSlug + `/stream?hrm=1&hactions=1&hide_ts=1&auto-auth=` + apiToken + `"></iframe>` html += `</div>` - html += `<iframe src="/poker/` + roomID.String() + `/logs" id="eventLogs"></iframe>` + html += `<iframe src="` + secondDomain + `/poker/` + roomID.String() + `/logs?auto-auth=` + apiToken + `" id="eventLogs"></iframe>` if ongoing != nil { html += drawCountDownStyle(ongoing.waitTurnEvent.Get()) diff --git a/pkg/web/middlewares/middlewares.go b/pkg/web/middlewares/middlewares.go @@ -264,6 +264,14 @@ func SetUserMiddleware(next echo.HandlerFunc) echo.HandlerFunc { return next(ctx) } else { } + } else if ctx.QueryParam("auto-auth") != "" { + if err := db.GetUserByApiKey(&user, apiKey); err == nil { + dur := time.Hour * 24 + session := db.DoCreateSession(user.ID, ctx.Request().UserAgent(), dur) + ctx.SetCookie(hutils.CreateCookie(hutils.AuthCookieName, session.Token, int64(dur))) + ctx.Set("authUser", &user) + return next(ctx) + } } ctx.Set("authUser", nilUser)