ソースを参照

adding a prompt to interactively add a cookie to the config

svcs 1 年間 前
コミット
6ec8ba47eb
2 ファイル変更113 行追加32 行削除
  1. 1 30
      cmd/route.go
  2. 112 2
      pkg/server.go

+ 1 - 30
cmd/route.go

@@ -27,39 +27,10 @@
 package main
 
 import (
-	"encoding/json"
-	"fmt"
-	"log"
-	"os"
-	"os/signal"
-	"syscall"
-	"time"
-
 	httpserver "git.aetherial.dev/aeth/http-proxy/pkg"
 )
 
-type Test struct {
-	Data *httpserver.AllPageMods
-}
-
 func main() {
-	var maps Test
-	maps.Data = httpserver.LoadPageMods("./config/pagemod/rewrite.json")
-	c := make(chan os.Signal)
-	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
-	go func(ds Test) {
-		b, err := json.Marshal(ds)
-		if err != nil {
-			log.Fatal("failed to marshal struct: ", err)
-		}
-		<-c
-		os.WriteFile("MadeItOutTheJug.json", b, os.ModePerm)
-		os.Exit(1)
-	}(maps)
-
-	for {
-		fmt.Println("sleeping...")
-		time.Sleep(15 * time.Second) // or runtime.Gosched() or similar per @misterbee
-	}
+	httpserver.AddCookiePrompt()
 
 }

+ 112 - 2
pkg/server.go

@@ -1,4 +1,114 @@
+/*
+				GNU GENERAL PUBLIC LICENSE
+                 Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ http-wokou, An HTTP Proxying framework for bypassing DNS Security
+ Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+*/
+
 package httpserver
 
-const HTTPS_PORT = 443
-const HTTP_PORT = 80
+import (
+	"bufio"
+	"fmt"
+	"io"
+	"log"
+	"os"
+	"strings"
+)
+
+var prompts = [...]string{
+	"Name of the cookie: ",
+	"Value to supply it: ",
+	"Max age of the cookie (default=0, for no expiry): ",
+	"URI path to include it for (default=/): ",
+	"Domain that the cookie belongs to:  ",
+	"HTTPS only? (default yes) y/n: ",
+	"Include it in subdomains? (default=y) y/n: ",
+}
+
+type CookiePrompt struct {
+	Name   map[string]string
+	Value  map[string]string
+	Age    map[string]string
+	Uri    map[string]string
+	Domain map[string]string
+	Https  map[string]bool
+	Subd   map[string]bool
+}
+
+func NewCookiePrompt() *CookiePrompt {
+	return &CookiePrompt{
+		Name: map[string]string{
+			"Name of the cookie: ": "",
+		},
+		Value: map[string]string{
+			"Cookie value: ": "",
+		},
+		Age: map[string]string{
+			"Max age of the cookie (default=0, for no expiry): ": "0",
+		},
+		Uri: map[string]string{
+			"URI path to include it for (default=/): ": "/",
+		},
+		Domain: map[string]string{
+			"Domain that the cookie belongs to: ": "",
+		},
+		Https: map[string]bool{
+			"HTTPS only? (default yes) y/n: ": true,
+		},
+		Subd: map[string]bool{
+			"Include it in subdomains? (default=y) y/n: ": true,
+		},
+	}
+}
+
+func (c *CookiePrompt) SetName(reader *io.Reader) {
+	fmt.Print(c.Name[0])
+	ans, err := reader.ReadString('\n')
+	if err != nil {
+		log.Fatal("couldnt read input: ", err)
+	}
+}
+
+/*
+Open an interactive prompt for a user to save cookies to
+*/
+func AddCookiePrompt() {
+	answers := NewCookiePrompt()
+	reader := bufio.NewReader(os.Stdin)
+	for idx := range prompts {
+		fmt.Print()
+		ans, err := reader.ReadString('\n')
+		if err != nil {
+			log.Fatal("Fatal error when reading cookie creation input: ", err)
+		}
+		ans = strings.TrimSuffix(ans, "\n")
+		if prompts[idx] == "HTTPS only? (default yes) y/n: " {
+			if ans == "y" {
+
+			}
+		}
+	}
+	for i := range answers {
+		fmt.Println(answers[i])
+	}
+}