From 49612063d71a995bab8010e2e4569267c0705d70 Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Thu, 9 Dec 2021 17:43:39 -0600 Subject: [PATCH] Added minimal support for daemon mode --- src/rhosts.go | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/rhosts.go b/src/rhosts.go index c462cbd..f025c8f 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -28,22 +28,41 @@ import ( "bufio" "log" "net/http" + "flag" + "time" ) func main() { tmpdir := "" hostsloc := "" cfgloc := "" + i := true + var daemon bool=false + var interval int=1440 + + // Parsing Flags + flag.BoolVar(&daemon, "d", false, "Should this be run in daemon mode") + flag.IntVar(&interval, "t", 1440, "Minutes until next run of daemon") + flag.Parse() + log.Print("daemon:" , daemon) + log.Print("interval:",interval) sysdetect (&tmpdir, &hostsloc, &cfgloc) - sites, downloads := cfgparse(cfgloc) - log.Print("Sites:\n",sites) - log.Print("Downloads:\n",downloads) - copystatichosts(tmpdir, hostsloc) - downloadcontent(downloads, tmpdir) - writesites(sites, tmpdir) - writetmp2hosts(hostsloc, tmpdir) + for ;i == true; time.Sleep(time.Duration(interval) * time.Minute){ + sites, downloads := cfgparse(cfgloc) + log.Print("Sites:\n",sites) + log.Print("Downloads:\n",downloads) + copystatichosts(tmpdir, hostsloc) + downloadcontent(downloads, tmpdir) + writesites(sites, tmpdir) + writetmp2hosts(hostsloc, tmpdir) + log.Print("Finished updating host") + i = daemon + if (i == false){ + break + } + } } func sysdetect (tmpdir, hostsloc, cfgloc *string) { @@ -183,11 +202,11 @@ func downloadcontent(downloads []string, tmpdir string) { log.Print("Downloading: ",d) file.WriteString("# rhosts download - " + d + "\n") if (err != nil) { - continue } response, err := http.Get(d) if (err !=nil) { log.Print(err) + continue }else{ _,err := io.Copy(file,response.Body) if (err != nil){