diff --git a/wrp.go b/wrp.go index 625e7e8..f477bac 100644 --- a/wrp.go +++ b/wrp.go @@ -72,22 +72,22 @@ func pageServer(out http.ResponseWriter, r *http.Request) { } log.Printf("%s Page Reqest for url=\"%s\" [%s]\n", r.RemoteAddr, u, r.URL.Path) out.Header().Set("Content-Type", "text/html") - fmt.Fprintf(out, "\nWRP %s\n", u) + fmt.Fprintf(out, "\nWRP %s\n", u) fmt.Fprintf(out, "
URL/Search: ", u) fmt.Fprintf(out, "

\n") - fmt.Fprintf(out, "ISMAP: [%v]\n", istr, i) + fmt.Fprintf(out, "ISMAP: \n", istr) fmt.Fprintf(out, "Width: \n", w) fmt.Fprintf(out, "Height: \n", h) fmt.Fprintf(out, "Scale: \n", s) fmt.Fprintf(out, "Page: \n", p) fmt.Fprintf(out, " %d \n", p) fmt.Fprintf(out, ">\"> \n") - fmt.Fprintf(out, "

") + fmt.Fprintf(out, "

\n") if len(u) > 4 { if strings.HasPrefix(u, "http") { - capture(u, w, h, s, p, out) + capture(u, w, h, s, p, i, out) } else { - capture(fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(u)), w, h, s, p, out) + capture(fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(u)), w, h, s, p, i, out) } } else { fmt.Fprintf(out, "No URL or search query specified") @@ -96,7 +96,7 @@ func pageServer(out http.ResponseWriter, r *http.Request) { } func imgServer(out http.ResponseWriter, req *http.Request) { - log.Printf("%s Img Request for %s\n", req.RemoteAddr, req.URL.Path) + log.Printf("%s IMG Request for %s\n", req.RemoteAddr, req.URL.Path) gifbuf := gifmap[req.URL.Path] defer delete(gifmap, req.URL.Path) out.Header().Set("Content-Type", "image/gif") @@ -105,6 +105,11 @@ func imgServer(out http.ResponseWriter, req *http.Request) { out.(http.Flusher).Flush() } +func mapServer(out http.ResponseWriter, req *http.Request) { + log.Printf("%s MAP Request for %s [%v]\n", req.RemoteAddr, req.URL.Path, req.URL.Query()) +} + + func haltServer(out http.ResponseWriter, req *http.Request) { log.Printf("%s Shutdown request received [%s]\n", req.RemoteAddr, req.URL.Path) out.Header().Set("Content-Type", "text/plain") @@ -114,7 +119,7 @@ func haltServer(out http.ResponseWriter, req *http.Request) { os.Exit(0) } -func capture(gourl string, w int64, h int64, s float64, p int64, out http.ResponseWriter) { +func capture(gourl string, w int64, h int64, s float64, p int64, ismap bool, out http.ResponseWriter) { var nodes []*cdp.Node ctxx := chromedp.FromContext(ctx) var pngbuf []byte @@ -163,7 +168,11 @@ func capture(gourl string, w int64, h int64, s float64, p int64, out http.Respon // Process Nodes base, _ := url.Parse(loc) - fmt.Fprintf(out, "\"wrp\"\n\n", imgpath) + if ismap { + fmt.Fprintf(out, "\"wrp\"", imgpath) + } else { + fmt.Fprintf(out, "\"wrp\"\n\n", imgpath) + } for _, n := range nodes { b, err := dom.GetBoxModel().WithNodeID(n.NodeID).Do(cdp.WithExecutor(ctx, ctxx.Target)) @@ -177,12 +186,18 @@ func capture(gourl string, w int64, h int64, s float64, p int64, out http.Respon target := fmt.Sprintf("/?url=%s&w=%d&h=%d&s=%1.2f&", tgt, w, h, s) // no page# here if len(b.Content) > 6 && len(target) > 7 { + if ismap { + + } else { fmt.Fprintf(out, "\"%s\"\n", b.Content[0]*s, b.Content[1]*s, b.Content[4]*s, b.Content[5]*s, n.AttributeValue("href"), n.AttributeValue("href"), target) + } } } - fmt.Fprintf(out, "\n") + if !ismap { + fmt.Fprintf(out, "\n") + } out.(http.Flusher).Flush() log.Printf("Done with caputure for %s\n", gourl) } @@ -196,6 +211,7 @@ func main() { rand.Seed(time.Now().UnixNano()) http.HandleFunc("/", pageServer) http.HandleFunc("/img/", imgServer) + http.HandleFunc("/map/", mapServer) http.HandleFunc("/favicon.ico", http.NotFound) http.HandleFunc("/halt", haltServer) log.Printf("Starting WRP http server on %s\n", addr)