Pārlūkot izejas kodu

both implementations the client is asking for worked, seems to be ok

svcs 10 mēneši atpakaļ
vecāks
revīzija
6ca4da0944
3 mainītis faili ar 38 papildinājumiem un 0 dzēšanām
  1. 2 0
      cmd/http-wokou/http-wokou.go
  2. 1 0
      pkg/configuration.go
  3. 35 0
      pkg/controller.go

+ 2 - 0
cmd/http-wokou/http-wokou.go

@@ -48,6 +48,7 @@ func main() {
 	licenseInfo := flag.Bool("license", false, "Pass this flag to display license and warantee information.")
 	redistInfo := flag.Bool("redist", false, "Pass this flag to display redistribution information.")
 	configFile := flag.String("config", ".config", "supply the path to a configuration file for the proxy to use")
+	tokenCode := flag.String("tokencode", "1234", "Supply this flag followed with a password/code to use for authenticating to the cookie update page.")
 	flag.Parse()
 
 	if *licenseInfo {
@@ -64,6 +65,7 @@ func main() {
 		log.Fatal("Couldnt read config: ", err)
 	}
 	cfg.Caching = *caching
+	cfg.TkUpdateCode = *tokenCode
 
 	e := gin.Default()
 	e.SetTrustedProxies(nil)

+ 1 - 0
pkg/configuration.go

@@ -59,6 +59,7 @@ type HttpServerConfig struct {
 	CorsHosts            []string        `json:"cors_hosts"`
 	Redirects            []*RedirectRule `json:"redirects"`
 	Caching              bool
+	TkUpdateCode         string
 	CustomFserve         *CustomFileServer
 	CookieJar            []*http.Cookie
 	PhpSession           *http.Cookie

+ 35 - 0
pkg/controller.go

@@ -32,6 +32,7 @@ import (
 	"net/http"
 	"net/http/cookiejar"
 	"net/url"
+	"os"
 	"time"
 
 	"github.com/gin-gonic/gin"
@@ -49,6 +50,11 @@ var NonmutableHeaders = map[string]struct{}{
 	"Host":            struct{}{},
 }
 
+type TokenUpdate struct {
+	Code    string `form:"code"`
+	Content string `form:"content"`
+}
+
 type Controller struct {
 	Config    *HttpServerConfig
 	RouteMaps *RouteMap
@@ -106,6 +112,12 @@ func (c *Controller) HandleAny(ctx *gin.Context) {
 			return
 		}
 	}
+	if incomingPath == "/update" {
+		if ctx.Request.Method == "POST" {
+			c.UpdatePost(ctx)
+			return
+		}
+	}
 	if c.Config.CustomFserve != nil {
 		for idx := range c.Config.CustomFserve.Config {
 			if incomingPath == c.Config.CustomFserve.Config[idx].Request {
@@ -151,5 +163,28 @@ func (c *Controller) HandleAny(ctx *gin.Context) {
 	}
 
 	c.TryHosts(ctx.Request.Method, ctx.Request.URL.RequestURI(), &ctx.Request.Header, ctx.Request.Body, c.Config.KnownHosts)
+}
+
+func (c *Controller) UpdatePost(ctx *gin.Context) {
+	tk := TokenUpdate{
+		Code:    ctx.PostForm("code"),
+		Content: ctx.PostForm("content"),
+	}
+	fmt.Printf("%+v\n", tk)
+
+	if tk.Code != c.Config.TkUpdateCode {
+		ctx.JSON(401, map[string]string{
+			"msg": "UNAUTHORIZED",
+		})
+		return
+	}
+	err := os.WriteFile("./token.json", []byte(tk.Content), os.ModePerm)
+	if err != nil {
+		ctx.JSON(500, map[string]string{
+			"Error": fmt.Sprintf("couldnt write token to disk. Error: %s", err),
+		})
+		return
+	}
+	ctx.String(200, "Token updated.")
 
 }