From e869291f8e84a07c26b883283bbe149b851816da Mon Sep 17 00:00:00 2001 From: Antoni Sawicki Date: Wed, 29 May 2019 01:29:01 -0700 Subject: [PATCH] gocdp initial checkin --- README.md | 26 ++------ Changelog.md => pywebkit/Changelog.md | 0 wrp.py => pywebkit/wrp.py | 0 wrp.go | 90 +++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 22 deletions(-) rename Changelog.md => pywebkit/Changelog.md (100%) rename wrp.py => pywebkit/wrp.py (100%) mode change 100755 => 100644 create mode 100644 wrp.go diff --git a/README.md b/README.md index 2b97769..0866e2e 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,12 @@ # WRP - Web Rendering Proxy -A HTTP proxy server that allows to use historical and obsolete web browsers on the modern web. It works by rendering the web page in to a GIF/PNG/JPEG image associated with clickable imagemap of original web links. +A HTTP proxy server that allows to use historical and obsolete web browsers on the modern web. It works by rendering the web page in to a GIF image associated with clickable imagemap of original web links. -New: Version 2.1 brings support for sslstrip to allow browsing https/SSL/TSL websites. +You are looking at a GoLang / CDP branch of WRP. +This code is under active development and not fully usable yet. -# Current Status +Check master branch for "stable" Python-Webkit version. -* This is a WebKit / Python version of WRP. -* It mostly works for casual browsing but the app is not very stable and your mileage may vary. -* Secure aka https/SSL/TLS websites might work with use of [sslstrip](https://moxie.org/software/sslstrip/) cheat (enabled by default). -* Web form submission is not yet implemented. -* New version using Chrome and GoLang is actively being developed. Stay tuned for updates. - -## OS Support -WRP works on macOS (Mac OS X), Linux and FreeBSD. On macOS it uses Cocoa Webkit, on Linux/FreeBSD QT Webkit, for which needs PyQT4 or PyQT5. - -## Installation -* macOS - should just work -* Linux/FreeBSD install `python-pyqt5.qtwebkit` and `sslstrip` -* For PythonMagick (Imagemagick library) install `python-pythonmagick` - -## Configuration -Edit wrp.py, scroll past Copyright section to find config parameters - -## Usage -Configure your web browser to use HTTP proxy at IP address and port where WRP is running. If using browsers prior to HTML 3.2, ISMAP option may need to be enabled. Check configuration. ## More info and screenshots * http://virtuallyfun.superglobalmegacorp.com/2014/03/11/web-rendering-proxy-update/ diff --git a/Changelog.md b/pywebkit/Changelog.md similarity index 100% rename from Changelog.md rename to pywebkit/Changelog.md diff --git a/wrp.py b/pywebkit/wrp.py old mode 100755 new mode 100644 similarity index 100% rename from wrp.py rename to pywebkit/wrp.py diff --git a/wrp.go b/wrp.go new file mode 100644 index 0000000..a361c17 --- /dev/null +++ b/wrp.go @@ -0,0 +1,90 @@ +package main + +import ( + "context" + "fmt" + "log" + "net/http" + "strconv" + "strings" + "time" + + "github.com/chromedp/cdproto/cdp" + "github.com/chromedp/cdproto/dom" + "github.com/chromedp/chromedp" +) + +var ( + ctx context.Context + cancel context.CancelFunc + scrcap []byte +) + +func pageServer(out http.ResponseWriter, req *http.Request) { + req.ParseForm() + furl := req.Form["url"] + var url string + if len(furl) >= 1 && len(furl[0]) > 4 { + url = furl[0] + } else { + url = "https://www.google.com/" + } + log.Printf("%s Page Reqest for %s URL=%s\n", req.RemoteAddr, req.URL.Path, url) + out.Header().Set("Content-Type", "text/html") + fmt.Fprintf(out, "\nWRP %s\n", url) + fmt.Fprintf(out, "
URL: ", url) + fmt.Fprintf(out, "

\n") + if len(url) > 4 { + capture(url, out) + } + fmt.Fprintf(out, "\n\n") +} + +func imgServer(out http.ResponseWriter, req *http.Request) { + log.Printf("%s Img Reqest for %s\n", req.RemoteAddr, req.URL.Path) + out.Header().Set("Content-Type", "image/png") + out.Header().Set("Content-Length", strconv.Itoa(len(scrcap))) + out.Write(scrcap) +} + +func capture(url string, out http.ResponseWriter) { + var nodes []*cdp.Node + ctxx := chromedp.FromContext(ctx) + var target string + + log.Printf("Caputure Request for %s\n", url) + chromedp.Run(ctx, + chromedp.Navigate(url), + chromedp.Sleep(time.Second*2), + chromedp.CaptureScreenshot(&scrcap), + chromedp.Nodes("a", &nodes, chromedp.ByQueryAll)) + + fmt.Fprintf(out, "\"wrp\"\n\n") + + for _, n := range nodes { + b, err := dom.GetBoxModel().WithNodeID(n.NodeID).Do(cdp.WithExecutor(ctx, ctxx.Target)) + if strings.HasPrefix(n.AttributeValue("href"), "/") { + target = fmt.Sprintf("/?url=%s%s", url, n.AttributeValue("href")) + } else { + target = fmt.Sprintf("/?url=%s", n.AttributeValue("href")) + } + + if err == nil && len(b.Content) > 6 { + fmt.Fprintf(out, "\"%s\"\n", + b.Content[0], b.Content[1], b.Content[4], b.Content[5], n.AttributeValue("href"), n.AttributeValue("href"), target) + } + } + + fmt.Fprintf(out, "\n") + log.Printf("Done with caputure for %s\n", url) +} + +func main() { + ctx, cancel = chromedp.NewContext(context.Background()) + defer cancel() + + http.HandleFunc("/", pageServer) + http.HandleFunc("/wrp.png", imgServer) + log.Printf("Starting http server on :8080\n") + http.ListenAndServe(":8080", nil) +}