http-wokou.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 main
  21. import (
  22. "flag"
  23. "fmt"
  24. "log"
  25. "os"
  26. httpserver "git.aetherial.dev/aeth/http-proxy/pkg"
  27. "github.com/gin-contrib/cors"
  28. "github.com/gin-gonic/gin"
  29. )
  30. var licenseMsg = "\n http-wokou Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC\n This program comes with ABSOLUTELY NO WARRANTY; for details type `http-wokou --license`\n This is free software, and you are welcome to redistribute it\n under certain conditions; type `http-wokou --redist` for details.\n\n"
  31. var redistMsg = "\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n"
  32. var licenseMsgLong = "\n GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n http-wokou, An HTTP Proxying framework for bypassing DNS Security\n Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n"
  33. func main() {
  34. caching := flag.Bool("cache", false, "Supply this argument to turn on caching")
  35. licenseInfo := flag.Bool("license", false, "Pass this flag to display license and warantee information.")
  36. redistInfo := flag.Bool("redist", false, "Pass this flag to display redistribution information.")
  37. configFile := flag.String("config", ".config", "supply the path to a configuration file for the proxy to use")
  38. flag.Parse()
  39. if *licenseInfo {
  40. fmt.Println(licenseMsgLong)
  41. os.Exit(0)
  42. }
  43. if *redistInfo {
  44. fmt.Println(redistMsg)
  45. os.Exit(0)
  46. }
  47. fmt.Println(licenseMsg)
  48. cfg, err := httpserver.ReadConfig(*configFile)
  49. if err != nil {
  50. log.Fatal("Couldnt read config: ", err)
  51. }
  52. cfg.Caching = *caching
  53. e := gin.Default()
  54. e.SetTrustedProxies(nil)
  55. config := cors.DefaultConfig()
  56. config.AllowOrigins = cfg.CorsHosts
  57. e.Use(cors.New(config))
  58. rmaps := httpserver.ReadRouteMap(cfg.RouteMapPath)
  59. httpserver.RegisterRoutes(e, cfg, rmaps)
  60. e.RunTLS(fmt.Sprintf("%s:%v", cfg.ListeningIp, cfg.HttpsPort), cfg.SslPemFile, cfg.SslKeyFile)
  61. }