/* * Copyright 2021 Justin Reichardt * * This file is part of rhosts. * * rhosts is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * rhosts is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with rhosts. If not, see . */ // rhosts - Program used to maintain a blocklist within a hostfile package main import ( "runtime" "os" "bufio" "log" ) func main() { tmpdir := "" hostsloc := "" cfgloc := "" sysdetect (&tmpdir, &hostsloc, &cfgloc) cfgparse(cfgloc) } func sysdetect (tmpdir, hostsloc, cfgloc *string) { // Detect OS and set params switch runtime.GOOS { case "windows": log.Fatal("Windows is not supported") *tmpdir = "C:\\tmp" *hostsloc = "C:\\Windows\\System32\\drivers\\etc\\hosts" case "linux": *tmpdir = "/tmp/" *hostsloc = "/etc/hosts" *cfgloc ="/etc/rhosts/rhosts.cfg" case "ios": log.Fatal("IOS is not supported") default: log.Fatal(runtime.GOOS," is not supported") } } func cfgparse (cfgloc string){ log.Print("Opening: ", cfgloc) file, err := os.Open(cfgloc) defer file.Close() if err != nil { log.Fatal(err) } filebuf := bufio.NewScanner(file) filebuf.Split(bufio.ScanLines) for res := filebuf.Scan();res;res = filebuf.Scan() { state, body := cfgparseline(filebuf.Text()) log.Print(state, body) } err = filebuf.Err() if err != nil { log.Fatal(err) } } func cfgparseline(buf string) (uint8, string){ // State options // 0 - Init // 1 - Error // 2 - Comment // 3 - Site // 4 - Download var state uint8= 0 body :=buf[:] for i:=0; i