hosts now pulls the config itself

testing
Justin Reichardt 2022-08-19 15:03:20 -05:00
parent 83679a1033
commit 15ee33eb01
2 changed files with 11 additions and 13 deletions

View File

@ -21,33 +21,35 @@ type siteEntry struct {
site string 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 var siteBuff []siteList
err = error(nil) err = error(nil)
err = copystatichosts(tmpdir, hostsloc) err = copystatichosts(config.System.TmpDir, config.System.HostsLoc)
if err != nil { if err != nil {
log.Print("Failed to copy static entries") log.Print("Failed to copy static entries")
return return
} }
defer os.Remove(tmpdir + "rhosts") defer os.Remove(config.System.TmpDir + "rhosts")
err, siteBuff = downloadcontent(config.Downloads, tmpdir, hostsloc) err, siteBuff = downloadcontent(config.Downloads, config.System.TmpDir, config.System.HostsLoc)
if err != nil { if err != nil {
log.Print("Failed to download entries") log.Print("Failed to download entries")
return return
} }
err = writesites(config.Sites, tmpdir, &siteBuff) err = writesites(config.Sites, config.System.TmpDir, &siteBuff)
if err != nil { if err != nil {
log.Print("Failed to failed to copy rhosts static entries") log.Print("Failed to failed to copy rhosts static entries")
return return
} }
removeduplicates(&siteBuff, &config.Whitelist) removeduplicates(&siteBuff, &config.Whitelist)
err = write2tmp(tmpdir, &siteBuff) err = write2tmp(config.System.TmpDir, &siteBuff)
if err != nil { if err != nil {
log.Print("Failed to write sites to tmpfile") log.Print("Failed to write sites to tmpfile")
return return
} }
err = writetmp2hosts(hostsloc, tmpdir) err = writetmp2hosts(config.System.HostsLoc, config.System.TmpDir)
if err != nil { if err != nil {
log.Print("Failed to copy to hosts file") log.Print("Failed to copy to hosts file")
return return

View File

@ -23,7 +23,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"jbreich/rhosts/cfg"
"jbreich/rhosts/hosts" "jbreich/rhosts/hosts"
"jbreich/rhosts/serve" "jbreich/rhosts/serve"
"log" "log"
@ -83,22 +82,19 @@ func main() {
log.Print("interval:", interval) log.Print("interval:", interval)
} }
_, config := cfg.Create()
// Starting web server // Starting web server
serve.Start("blank") serve.Start("blank")
// Update the hosts file // Update the hosts file
if daemon == false { if daemon == false {
err := hosts.Update(config, config.System.TmpDir, config.System.HostsLoc) err := hosts.Update()
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
} else { } else {
for true { for true {
err := hosts.Update(config, config.System.TmpDir, config.System.HostsLoc) err := hosts.Update()
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }