func restoreHostsFile(tun string, qualify bool) { becomeRoot() var err error if qualify { err = hosts.ReplaceTagged("mole."+tun, nil) } else { err = hosts.ReplaceTagged("mole", nil) } if err != nil { warnln(err) } dropRoot() }
func addToHostsFile(tag string, domain string, cfg *conf.Config) { var entries []hosts.Entry for _, fwd := range cfg.Forwards { ps := strings.SplitN(fwd.Name, " ", 2) name := strings.ToLower(ps[0]) if domain != "" { name = name + "." + domain } ip := fwd.Lines[0].SrcIP entries = append(entries, hosts.Entry{IP: ip, Names: []string{name}}) } requireRoot("update /etc/hosts") becomeRoot() err := hosts.ReplaceTagged(tag, entries) dropRoot() fatalErr(err) }