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
|
#whitelist=www.site.xyz
|
||||||
|
|
||||||
# A suggested download is: https://github.com/StevenBlack/hosts
|
# 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 {
|
type Config struct {
|
||||||
CfgLoc string
|
CfgLoc string
|
||||||
|
|
@ -36,6 +42,9 @@ type Config struct {
|
||||||
CfgLoc string
|
CfgLoc string
|
||||||
Var string
|
Var string
|
||||||
}
|
}
|
||||||
|
WebServer struct {
|
||||||
|
Enabled bool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to hold a list of functions to be run when building
|
// 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':
|
case 'w':
|
||||||
if (len(buf) > 10 && buf[0:10] == "whitelist=") {
|
if (len(buf) > 10 && buf[0:10] == "whitelist=") {
|
||||||
cfg.Whitelist = append(cfg.Whitelist, buf[9:])
|
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 {
|
} else {
|
||||||
fail = true
|
fail = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Exit chan bool
|
|
||||||
|
|
||||||
const GPL = `
|
const GPL = `
|
||||||
rhosts maintains a blocklist and appends it to the system hosts file
|
rhosts maintains a blocklist and appends it to the system hosts file
|
||||||
|
|
@ -51,6 +50,7 @@ const GPL = `
|
||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
exit := make(chan bool)
|
||||||
var daemon bool = false
|
var daemon bool = false
|
||||||
var interval int = 1440
|
var interval int = 1440
|
||||||
var versionflag bool = false
|
var versionflag bool = false
|
||||||
|
|
@ -83,7 +83,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starting web server
|
// Starting web server
|
||||||
serve.Start()
|
go serve.Start(exit)
|
||||||
|
|
||||||
// Update the hosts file
|
// Update the hosts file
|
||||||
if daemon == false {
|
if daemon == false {
|
||||||
|
|
@ -112,5 +112,5 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<-Exit
|
<-exit
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@ package serve
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"jbreich/rhosts/cfg"
|
"jbreich/rhosts/cfg"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start() {
|
func Start(exit chan bool) {
|
||||||
config := cfg.Create()
|
config := cfg.Create()
|
||||||
|
if config.WebServer.Enabled == false {
|
||||||
|
log.Print("Made it this far")
|
||||||
|
exit <- true
|
||||||
|
return
|
||||||
|
}
|
||||||
go httpServer()
|
go httpServer()
|
||||||
go httpsServer(config.System.Var + "/certs/")
|
go httpsServer(config.System.Var + "/certs/")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue