diff --git a/src/cfg/cfg.go b/src/cfg/cfg.go index d2f623c..1fdcc8e 100644 --- a/src/cfg/cfg.go +++ b/src/cfg/cfg.go @@ -4,7 +4,6 @@ import ( "bufio" "log" "os" - "errors" ) const CFG = ` @@ -34,6 +33,7 @@ type Config struct { TmpDir string HostsLoc string CfgLoc string + Var string } } @@ -41,12 +41,14 @@ type Config struct { var configFuncs []func(*Config) // Create initialized a config to be used the entire session -func Create() (err error,cfg Config) { +func Create() (cfg Config) { for _,fp := range(configFuncs){ fp(&cfg) } - if (cfg.System.OS == ""){return errors.New("Failed to detect the OS"), cfg} - err, cfg = cfg.Update() + if (cfg.System.OS == ""){log.Panic("Failed to detect the OS")} + err, cfg := cfg.Update() + + if (err != nil){log.Panic("Failed to handle the config file: " + err.Error())} return } diff --git a/src/cfg/linux.go b/src/cfg/linux.go index 1859124..c1e57e4 100644 --- a/src/cfg/linux.go +++ b/src/cfg/linux.go @@ -1,16 +1,16 @@ +//go:build linux // +build linux package cfg - -func init(){ - fp := func(c *Config){ - c.System.OS = "linux" - c.System.TmpDir = "/tmp/" - c.System.HostsLoc = "/etc/hosts" - c.System.CfgLoc = "/etc/rhosts/" +func init() { + fp := func(c *Config) { + c.System.OS = "linux" + c.System.TmpDir = "/tmp/" + c.System.HostsLoc = "/etc/hosts" + c.System.CfgLoc = "/etc/rhosts/" + c.System.Var = "/var/lib/rhosts/" } - configFuncs = append(configFuncs,fp) + configFuncs = append(configFuncs, fp) } - diff --git a/src/cfg/windows.go b/src/cfg/windows.go index 1829598..4341646 100644 --- a/src/cfg/windows.go +++ b/src/cfg/windows.go @@ -1,19 +1,20 @@ +//go:build windows // +build windows package sys - -func init(){ +func init() { } -func init(){ - fp := func(c *Config){ - c.System.os = "windows" +func init() { + fp := func(c *Config) { + c.System.os = "windows" c.System.tmpdir = "/tmp/" c.System.hostsloc = "/Windows/System32/drivers/etc/hosts" c.System.cfgloc = "/ProgramData/rhosts/" + c.System.Var = "/ProgramData/rhosts/" } - configFuncs = append(configFuncs,fp) + configFuncs = append(configFuncs, fp) } diff --git a/src/hosts/hosts.go b/src/hosts/hosts.go index 7b06f44..b0eae90 100644 --- a/src/hosts/hosts.go +++ b/src/hosts/hosts.go @@ -22,8 +22,7 @@ type siteEntry struct { } func Update() (err error) { - err, config := cfg.Create() - if (err != nil){return} + config := cfg.Create() var siteBuff []siteList err = error(nil) diff --git a/src/rhosts.go b/src/rhosts.go index 6671348..d699d65 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -83,7 +83,7 @@ func main() { } // Starting web server - serve.Start("blank") + serve.Start() // Update the hosts file if daemon == false { diff --git a/src/serve/serve.go b/src/serve/serve.go index b3b1544..7fe0951 100644 --- a/src/serve/serve.go +++ b/src/serve/serve.go @@ -3,11 +3,13 @@ package serve import ( "net/http" + "jbreich/rhosts/cfg" ) -func Start(certLoc string) { +func Start() { + config := cfg.Create() go httpServer() - //go httpsServer(&certLoc) + go httpsServer(config.System.Var + "/certs/") } @@ -15,8 +17,8 @@ func httpServer() (err error) { err = http.ListenAndServe("127.0.0.1:80", http.HandlerFunc(httpHandler)) return } -func httpsServer(certLoc *string) (err error) { - err = http.ListenAndServeTLS("127.0.0.1:80", *certLoc+"ca.crt", *certLoc+"ca.key", http.HandlerFunc(httpHandler)) +func httpsServer(certLoc string) (err error) { + err = http.ListenAndServeTLS("127.0.0.1:80", certLoc+"ca.crt", certLoc+"ca.key", http.HandlerFunc(httpHandler)) return }