diff --git a/src/hosts/hosts.go b/src/hosts/hosts.go index 5eb9f6e..7b06f44 100644 --- a/src/hosts/hosts.go +++ b/src/hosts/hosts.go @@ -21,33 +21,35 @@ type siteEntry struct { site string } -func Update(config cfg.Config, tmpdir, hostsloc string) (err error) { +func Update() (err error) { + err, config := cfg.Create() + if (err != nil){return} var siteBuff []siteList err = error(nil) - err = copystatichosts(tmpdir, hostsloc) + err = copystatichosts(config.System.TmpDir, config.System.HostsLoc) if err != nil { log.Print("Failed to copy static entries") return } - defer os.Remove(tmpdir + "rhosts") - err, siteBuff = downloadcontent(config.Downloads, tmpdir, hostsloc) + defer os.Remove(config.System.TmpDir + "rhosts") + err, siteBuff = downloadcontent(config.Downloads, config.System.TmpDir, config.System.HostsLoc) if err != nil { log.Print("Failed to download entries") return } - err = writesites(config.Sites, tmpdir, &siteBuff) + err = writesites(config.Sites, config.System.TmpDir, &siteBuff) if err != nil { log.Print("Failed to failed to copy rhosts static entries") return } removeduplicates(&siteBuff, &config.Whitelist) - err = write2tmp(tmpdir, &siteBuff) + err = write2tmp(config.System.TmpDir, &siteBuff) if err != nil { log.Print("Failed to write sites to tmpfile") return } - err = writetmp2hosts(hostsloc, tmpdir) + err = writetmp2hosts(config.System.HostsLoc, config.System.TmpDir) if err != nil { log.Print("Failed to copy to hosts file") return diff --git a/src/rhosts.go b/src/rhosts.go index 86d35bf..6671348 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -23,7 +23,6 @@ package main import ( "flag" "fmt" - "jbreich/rhosts/cfg" "jbreich/rhosts/hosts" "jbreich/rhosts/serve" "log" @@ -83,22 +82,19 @@ func main() { log.Print("interval:", interval) } - _, config := cfg.Create() - - // Starting web server serve.Start("blank") // Update the hosts file if daemon == false { - err := hosts.Update(config, config.System.TmpDir, config.System.HostsLoc) + err := hosts.Update() if err != nil { log.Print(err) } } else { for true { - err := hosts.Update(config, config.System.TmpDir, config.System.HostsLoc) + err := hosts.Update() if err != nil { log.Print(err) }