|
@@ -28,10 +28,12 @@ package httpserver
|
|
|
|
|
|
import (
|
|
|
"bufio"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
- "io"
|
|
|
"log"
|
|
|
+ "net/http"
|
|
|
"os"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
@@ -45,58 +47,21 @@ var prompts = [...]string{
|
|
|
"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()
|
|
|
+func AddCookiePrompt(path string, cookies []*http.Cookie) {
|
|
|
+ var answers []string
|
|
|
+ var https bool
|
|
|
+ var subd bool
|
|
|
+ var name string
|
|
|
+ var value string
|
|
|
+ var domain string
|
|
|
+ maxAge := 0
|
|
|
+ path := "/"
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
for idx := range prompts {
|
|
|
- fmt.Print()
|
|
|
+ fmt.Print(prompts[idx])
|
|
|
ans, err := reader.ReadString('\n')
|
|
|
if err != nil {
|
|
|
log.Fatal("Fatal error when reading cookie creation input: ", err)
|
|
@@ -104,11 +69,58 @@ func AddCookiePrompt() {
|
|
|
ans = strings.TrimSuffix(ans, "\n")
|
|
|
if prompts[idx] == "HTTPS only? (default yes) y/n: " {
|
|
|
if ans == "y" {
|
|
|
-
|
|
|
+ https = true
|
|
|
+ }
|
|
|
+ if ans == "n" {
|
|
|
+ https = false
|
|
|
}
|
|
|
}
|
|
|
+ if prompts[idx] == "Max age of the cookie (default=0, for no expiry): " {
|
|
|
+ if ans != "" {
|
|
|
+ maxAge, err = strconv.Atoi(answers[idx])
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal("Not an integer!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if prompts[idx] == "Include it in subdomains? (default=y) y/n: " {
|
|
|
+ if ans == "y" {
|
|
|
+ subd = true
|
|
|
+ }
|
|
|
+ if ans == "n" {
|
|
|
+ subd = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if prompts[idx] == "URI path to include it for (default=/): " {
|
|
|
+ if ans != "" {
|
|
|
+ path = prompts[idx]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if prompts[idx] == "Name of the cookie: " {
|
|
|
+ name = ans
|
|
|
+ }
|
|
|
+ if prompts[idx] == "Value to supply it: " {
|
|
|
+ value = ans
|
|
|
+ }
|
|
|
+ if prompts[idx] == "Domain that the cookie belongs to: " {
|
|
|
+ domain = ans
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ ck := &http.Cookie{
|
|
|
+ Name: name,
|
|
|
+ Value: value,
|
|
|
+ MaxAge: maxAge,
|
|
|
+ Path: path,
|
|
|
+ Domain: domain,
|
|
|
+ Secure: https,
|
|
|
}
|
|
|
- for i := range answers {
|
|
|
- fmt.Println(answers[i])
|
|
|
+ cookies = append(cookies, ck)
|
|
|
+ b, err := json.Marshal(cookies)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal("couldnt marshal the cookie: ", err)
|
|
|
}
|
|
|
+
|
|
|
+ os.WriteFile(path, b, os.ModePerm)
|
|
|
+
|
|
|
}
|