/* GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. 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 . */ package httpserver import ( "bufio" "encoding/json" "fmt" "log" "net/http" "os" "strconv" "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: ", } /* Open an interactive prompt for a user to save cookies to */ func AddCookiePrompt(loc string, cookies []*http.Cookie) { var answers []string var https bool var name string var value string var domain string maxAge := 0 path := "/" reader := bufio.NewReader(os.Stdin) for idx := range prompts { fmt.Print(prompts[idx]) 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" { 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] == "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, } cookies = append(cookies, ck) b, err := json.Marshal(cookies) if err != nil { log.Fatal("couldnt marshal the cookie: ", err) } os.WriteFile(loc, b, os.ModePerm) }