From 2a7cec00089618524e55a193426c30a686b835b6 Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Fri, 19 Aug 2022 18:56:04 -0500 Subject: [PATCH] Added the webserver option to the config This allows turning the web server on or off --- src/cfg/cfg.go | 17 ++++++++++++++++- src/rhosts.go | 6 +++--- src/serve/serve.go | 8 +++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/cfg/cfg.go b/src/cfg/cfg.go index 48716a2..50098fa 100644 --- a/src/cfg/cfg.go +++ b/src/cfg/cfg.go @@ -22,7 +22,13 @@ const CFG = ` #whitelist=www.site.xyz # A suggested download is: https://github.com/StevenBlack/hosts -#download=https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts` +#download=https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts + +# Webserver +# This will allow you to intercept and alter messages + +# It is disabled by default +#Webserver=true` type Config struct { CfgLoc string @@ -36,6 +42,9 @@ type Config struct { CfgLoc string Var string } + WebServer struct { + Enabled bool + } } // Used to hold a list of functions to be run when building @@ -125,6 +134,12 @@ func cfgparseline(buf string, cfg *Config) (fail bool) { case 'w': if (len(buf) > 10 && buf[0:10] == "whitelist=") { cfg.Whitelist = append(cfg.Whitelist, buf[9:]) + } else if (len(buf) > 10 && buf[0:10] == "webserver=") { + if (len(buf[10:]) >= 4 && buf[10:] == "true"){ + cfg.WebServer.Enabled = true + }else if (len(buf[10:]) >= 5 && buf[10:] == "false"){ + cfg.WebServer.Enabled = false + }else {fail = true} } else { fail = true } diff --git a/src/rhosts.go b/src/rhosts.go index d699d65..aadc842 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -29,7 +29,6 @@ import ( "time" ) -var Exit chan bool const GPL = ` rhosts maintains a blocklist and appends it to the system hosts file @@ -51,6 +50,7 @@ const GPL = ` ` func main() { + exit := make(chan bool) var daemon bool = false var interval int = 1440 var versionflag bool = false @@ -83,7 +83,7 @@ func main() { } // Starting web server - serve.Start() + go serve.Start(exit) // Update the hosts file if daemon == false { @@ -112,5 +112,5 @@ func main() { } } } - <-Exit + <-exit } diff --git a/src/serve/serve.go b/src/serve/serve.go index 7fe0951..d20c9a7 100644 --- a/src/serve/serve.go +++ b/src/serve/serve.go @@ -4,10 +4,16 @@ package serve import ( "net/http" "jbreich/rhosts/cfg" + "log" ) -func Start() { +func Start(exit chan bool) { config := cfg.Create() + if config.WebServer.Enabled == false { + log.Print("Made it this far") + exit <- true + return + } go httpServer() go httpsServer(config.System.Var + "/certs/")