package common import ( "fmt" "log/slog" "os" "strings" ) func thread(l *slog.Logger, dests <-chan string, tab chan<- interface{}) { c := MkClient() for dest := range dests { uriloop: for _, uri := range Paths { url := fmt.Sprintf("https://%s%s", dest, uri) fallback, redirect := true, true for { if doc, redir, err := Hit(c, url); err == nil { if doc != nil { if Checktitle(doc) { entries := Entries(doc) l.Info("opendir", "url", url, "entries", entries) } } else if redir != "" && redirect { url = redir if !strings.HasPrefix(url, "https") { fallback = false } redirect = false continue } break } else { if !fallback { break uriloop } url = "http://" + url[8:] fallback = false } } } } tab <- "H A C K T H E P L A N E T" } func Takeoff() { dests := make(chan string) tab := make(chan interface{}) logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) for i := 0; i < Conf.Threads; i++ { go thread(logger, dests, tab) } if Conf.List != "" { Readfile(Conf.List, dests) } else if Conf.Cidr != "" { if !ValidRange(Conf.Cidr) { Fatal("invalid cidr range") } LCG(Conf.Cidr, dests) } else { Fatal("provide either a list (-l) or cidr range (-r)") } close(dests) for x := 0; x < Conf.Threads; x++ { <-tab } close(tab) }