Added the webserver option to the config
This allows turning the web server on or offtesting
parent
c3ff05c989
commit
2a7cec0008
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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/")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue