server.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. GNU GENERAL PUBLIC LICENSE
  3. Version 3, 29 June 2007
  4. Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  5. Everyone is permitted to copy and distribute verbatim copies
  6. of this license document, but changing it is not allowed.
  7. http-wokou, An HTTP Proxying framework for bypassing DNS Security
  8. Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. package httpserver
  21. import (
  22. "bufio"
  23. "fmt"
  24. "io"
  25. "log"
  26. "os"
  27. "strings"
  28. )
  29. var prompts = [...]string{
  30. "Name of the cookie: ",
  31. "Value to supply it: ",
  32. "Max age of the cookie (default=0, for no expiry): ",
  33. "URI path to include it for (default=/): ",
  34. "Domain that the cookie belongs to: ",
  35. "HTTPS only? (default yes) y/n: ",
  36. "Include it in subdomains? (default=y) y/n: ",
  37. }
  38. type CookiePrompt struct {
  39. Name map[string]string
  40. Value map[string]string
  41. Age map[string]string
  42. Uri map[string]string
  43. Domain map[string]string
  44. Https map[string]bool
  45. Subd map[string]bool
  46. }
  47. func NewCookiePrompt() *CookiePrompt {
  48. return &CookiePrompt{
  49. Name: map[string]string{
  50. "Name of the cookie: ": "",
  51. },
  52. Value: map[string]string{
  53. "Cookie value: ": "",
  54. },
  55. Age: map[string]string{
  56. "Max age of the cookie (default=0, for no expiry): ": "0",
  57. },
  58. Uri: map[string]string{
  59. "URI path to include it for (default=/): ": "/",
  60. },
  61. Domain: map[string]string{
  62. "Domain that the cookie belongs to: ": "",
  63. },
  64. Https: map[string]bool{
  65. "HTTPS only? (default yes) y/n: ": true,
  66. },
  67. Subd: map[string]bool{
  68. "Include it in subdomains? (default=y) y/n: ": true,
  69. },
  70. }
  71. }
  72. func (c *CookiePrompt) SetName(reader *io.Reader) {
  73. fmt.Print(c.Name[0])
  74. ans, err := reader.ReadString('\n')
  75. if err != nil {
  76. log.Fatal("couldnt read input: ", err)
  77. }
  78. }
  79. /*
  80. Open an interactive prompt for a user to save cookies to
  81. */
  82. func AddCookiePrompt() {
  83. answers := NewCookiePrompt()
  84. reader := bufio.NewReader(os.Stdin)
  85. for idx := range prompts {
  86. fmt.Print()
  87. ans, err := reader.ReadString('\n')
  88. if err != nil {
  89. log.Fatal("Fatal error when reading cookie creation input: ", err)
  90. }
  91. ans = strings.TrimSuffix(ans, "\n")
  92. if prompts[idx] == "HTTPS only? (default yes) y/n: " {
  93. if ans == "y" {
  94. }
  95. }
  96. }
  97. for i := range answers {
  98. fmt.Println(answers[i])
  99. }
  100. }