|
@@ -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.")
|
|
|
|
|
|
}
|