123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /*
- 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
- 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)
- }
|