123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /*
- 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 (
- "encoding/json"
- "log"
- "net/http"
- "os"
- "time"
- "github.com/patrickmn/go-cache"
- )
- type HttpServerConfig struct {
- HttpPort int `json:"http_port"`
- HttpsPort int `json:"https_port"`
- TargetDomain string // This is the domain that will be used by the client
- ProxyDomain string // This will be the domain that is being proxied, i.e. the downstream domain
- SslPemFile string `json:"ssl_pem_file"`
- SslKeyFile string `json:"ssl_key_file"`
- ListeningIp string `json:"listening_ip"`
- KnownHosts []string `json:"known_hosts"`
- RouteMapPath string `json:"route_map_path"` // path to the routemaps
- Caching bool
- CookieFile string `json:"cookie_file"` // path to a cookie for the outbound client
- CookieJar []*http.Cookie
- Home string `json:"home"` // the location on the filesystem to save the output config to
- }
- type Cookie struct {
- Name string `json:"name"`
- Value string `json:"value"`
- MaxAge int `json:"max_age"`
- Path string `json:"path"`
- Domain string `json:"domain"`
- Secure bool `json:"secure"`
- IncludeSub bool `json:"include_sub"`
- }
- /*
- Reads the server configuration file, along with the cookie file so that the correlated account can be
- accessed through the proxy
- :param loc: the location of the config file
- */
- func ReadConfig(loc string, proxyDomain string, targetDomain string) (HttpServerConfig, error) {
- f, err := os.ReadFile(loc)
- if err != nil {
- return HttpServerConfig{}, err
- }
- var cfg HttpServerConfig
- cfg = HttpServerConfig{ProxyDomain: proxyDomain, TargetDomain: targetDomain}
- err = json.Unmarshal(f, &cfg)
- if err != nil {
- return HttpServerConfig{}, err
- }
- cf, err := os.ReadFile(cfg.CookieFile)
- if err != nil {
- return HttpServerConfig{}, err
- }
- var cookies []*http.Cookie
- err = json.Unmarshal(cf, &cookies)
- if err != nil {
- return HttpServerConfig{}, err
- }
- cfg.CookieJar = cookies
- return cfg, err
- }
- func ReadRouteMap(loc string) *RouteMap {
- f, err := os.ReadFile(loc)
- if err != nil {
- log.Fatal(err)
- }
- var mapfile RouteMap
- err = json.Unmarshal(f, &mapfile)
- if err != nil {
- log.Fatal(err)
- }
- mapfile.MapCache = cache.New(24*time.Hour, 10*time.Minute)
- mapfile.populateRouteMaps()
- return &mapfile
- }
|