Pārlūkot izejas kodu

added some license stuff to the binaries

svcs 1 gadu atpakaļ
vecāks
revīzija
56c165034b
5 mainītis faili ar 57 papildinājumiem un 8 dzēšanām
  1. 20 2
      cmd/http-wokou/http-wokou.go
  2. 22 0
      cmd/wokou-cmd/wokou-cmd.go
  3. 1 2
      pkg/cache.go
  4. 3 2
      pkg/configuration.go
  5. 11 2
      pkg/controller.go

+ 20 - 2
cmd/http-wokou/http-wokou.go

@@ -30,31 +30,49 @@ import (
 	"flag"
 	"fmt"
 	"log"
+	"os"
 
 	httpserver "git.aetherial.dev/aeth/http-proxy/pkg"
 	"github.com/gin-contrib/cors"
 	"github.com/gin-gonic/gin"
 )
 
+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"
+
+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"
+
+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"
+
 func main() {
 	caching := flag.Bool("cache", false, "Supply this argument to turn on caching")
+	licenseInfo := flag.Bool("license", false, "Pass this flag to display license and warantee information.")
+	redistInfo := flag.Bool("redist", false, "Pass this flag to display redistribution information.")
 	configFile := flag.String("config", ".config", "supply the path to a configuration file for the proxy to use")
 	flag.Parse()
 
+	if *licenseInfo {
+		fmt.Println(licenseMsgLong)
+		os.Exit(0)
+	}
+	if *redistInfo {
+		fmt.Println(redistMsg)
+		os.Exit(0)
+	}
+	fmt.Println(licenseMsg)
 	cfg, err := httpserver.ReadConfig(*configFile)
 	if err != nil {
 		log.Fatal("Couldnt read config: ", err)
 	}
 	cfg.Caching = *caching
-	fmt.Print(cfg.Caching)
 
 	e := gin.Default()
+	e.SetTrustedProxies(nil)
 	config := cors.DefaultConfig()
 	config.AllowOrigins = cfg.CorsHosts
 	e.Use(cors.New(config))
 	rmaps := httpserver.ReadRouteMap(cfg.RouteMapPath)
 	httpserver.RegisterRoutes(e, cfg, rmaps)
 
-	e.RunTLS(fmt.Sprintf("%s:%v", "0.0.0.0", cfg.HttpsPort), "/etc/letsencrypt/live/void-society.online/fullchain.pem", "/etc/letsencrypt/live/void-society.online/privkey.pem")
+	e.RunTLS(fmt.Sprintf("%s:%v", cfg.ListeningIp, cfg.HttpsPort), cfg.SslPemFile, cfg.SslKeyFile)
 
 }

+ 22 - 0
cmd/wokou-cmd/wokou-cmd.go

@@ -28,13 +28,35 @@ package main
 
 import (
 	"flag"
+	"fmt"
 	"log"
+	"os"
 
 	httpserver "git.aetherial.dev/aeth/http-proxy/pkg"
 )
 
+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"
+
+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"
+
+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"
+
 func main() {
 	configFile := flag.String("config", ".config", "Pass the location of the config file.")
+	licenseInfo := flag.Bool("license", false, "Pass this flag to display license and warantee information.")
+	redistInfo := flag.Bool("redist", false, "Pass this flag to display redistribution information.")
+	flag.Parse()
+
+	if *licenseInfo {
+		fmt.Println(licenseMsgLong)
+		os.Exit(0)
+	}
+	if *redistInfo {
+		fmt.Println(redistMsg)
+		os.Exit(0)
+	}
+	fmt.Println(licenseMsg)
+
 	flag.Parse()
 	cfg, err := httpserver.ReadConfig(*configFile)
 	if err != nil {

+ 1 - 2
pkg/cache.go

@@ -53,14 +53,13 @@ func NewCachedResource(data []byte, headers *http.Header, rcode int) *CachedReso
 }
 
 func (c *Controller) CacheResource(key string, resource *CachedResource) {
-	fmt.Printf("Cached resource for: %s\n", key)
 	c.cache.Set(key, resource, cache.DefaultExpiration)
 }
 
 func (c *Controller) GetResource(key string) *CachedResource {
 	resource, found := c.cache.Get(key)
 	if found {
-		fmt.Printf("Cache Hit! Found resource for URI: %s\n", key)
+		fmt.Printf("200 :::: Cache HIT! Found resource for URI: %s\n", key)
 		return resource.(*CachedResource)
 	}
 	return nil

+ 3 - 2
pkg/configuration.go

@@ -46,7 +46,9 @@ type HttpServerConfig struct {
 	FullAltAllowedDomain string          // the alt domain with the protocol
 	Proto                string          `json:"proto"` // http/https
 	UserAgent            string          `json:"user_agent"`
-	UseSsl               bool            `json:"use_ssl"`
+	SslPemFile           string          `json:"ssl_pem_file"`
+	SslKeyFile           string          `json:"ssl_key_file"`
+	ListeningIp          string          `json:"listening_ip"`
 	ProxyAddr            string          `json:"proxy_addr"`
 	RouteMapPath         string          `json:"route_map_path"`
 	PageModPath          string          `json:"page_mod_path"`
@@ -176,6 +178,5 @@ func ReadCustomFiles(loc string) *CustomFileServer {
 		}
 		fserveCfg.Config[idx].FileData = b
 	}
-	fmt.Printf("%+v\n", fserveCfg)
 	return &fserveCfg
 }

+ 11 - 2
pkg/controller.go

@@ -83,10 +83,17 @@ func NewController(cfg *HttpServerConfig, routeMap *RouteMap) *Controller {
 	}
 	pgMod := LoadPageMods(cfg.PageModPath)
 	jar.SetCookies(domain, sessCookies)
-	cache := cache.New(24*time.Hour, 10*time.Minute)
 
+	var resCache *cache.Cache
+	if cfg.Caching {
+		fmt.Printf("Starting server with resource caching ENABLED.\n")
+		resCache = cache.New(24*time.Hour, 10*time.Minute)
+	} else {
+		fmt.Printf("Starting server with resource caching DISABLED.\n")
+		resCache = nil
+	}
 	return &Controller{Config: cfg, Client: &http.Client{Jar: jar, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }},
-		SiteUrl: domain, cache: cache, RouteMaps: routeMap, PageMods: pgMod}
+		SiteUrl: domain, cache: resCache, RouteMaps: routeMap, PageMods: pgMod}
 }
 
 /*
@@ -125,6 +132,8 @@ func (c *Controller) HandleAny(ctx *gin.Context) {
 			}
 			ctx.Data(cacheHit.Rcode, cacheHit.Headers.Get("content-type"), cacheHit.Data)
 			return
+		} else {
+			fmt.Printf("Cache MISS! For resource URI: %s\n", incomingPath)
 		}
 	}