mirror of
https://github.com/tenox7/wrp.git
synced 2026-02-13 05:35:46 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af5174456a | ||
|
|
d49ef9c1c2 | ||
|
|
23b4fbaf63 | ||
|
|
a91cc60a51 | ||
|
|
51cd108bad | ||
|
|
cd2cf0baae | ||
|
|
a344d177d6 | ||
|
|
02766d8844 | ||
|
|
91091cf94b | ||
|
|
95d9de7348 | ||
|
|
6449c64e36 | ||
|
|
b058831ec6 | ||
|
|
7c50c6e841 | ||
|
|
2f2e99eb85 | ||
|
|
4dee5ea8d9 | ||
|
|
333666d3b0 | ||
|
|
780143b766 | ||
|
|
6b89e463f3 | ||
|
|
ea1ae10f97 | ||
|
|
eb4201c56b | ||
|
|
4cd55b31b0 | ||
|
|
f0ba852785 | ||
|
|
66412fa95e | ||
|
|
cd5bb94def |
9
Makefile
9
Makefile
@@ -14,5 +14,12 @@ cross:
|
||||
docker: wrp
|
||||
docker build -t tenox7/wrp:latest .
|
||||
|
||||
dockerhub:
|
||||
docker push tenox7/wrp:latest
|
||||
|
||||
gcrio:
|
||||
docker tag tenox7/wrp:latest gcr.io/tenox7/wrp
|
||||
docker push gcr.io/tenox7/wrp
|
||||
|
||||
clean:
|
||||
rm -rf wrp-* wrp
|
||||
rm -rf wrp-* wrp
|
||||
|
||||
20
README.md
20
README.md
@@ -1,6 +1,6 @@
|
||||
# WRP - Web Rendering Proxy
|
||||
|
||||
A HTTP proxy server that allows to use historical / vintage web browsers on the modern web. It works by rendering a web page in to GIF image with ISMAP.
|
||||
A browser-in-browser "proxy" server that allows to use historical / vintage web browsers on the modern web. It works by rendering a web page in to a GIF or PNG image with clickable imagemap.
|
||||
|
||||

|
||||
|
||||
@@ -8,13 +8,13 @@ A HTTP proxy server that allows to use historical / vintage web browsers on the
|
||||
|
||||
* This is a new version using GoLang/[ChromeDP](https://github.com/chromedp/chromedp) (Python/Webkit is now deprecated).
|
||||
* Fully supported an maintained.
|
||||
* Works as browser-in-browser. A real http proxy mode is being investigated. Check [issue #35](https://github.com/tenox7/wrp/issues/35) for updates.
|
||||
* Supports clicking on non-link elements (eg. cookie warnings, dropdown menus, etc.) and sending keystrokes. Yes, you can login to Gmail.
|
||||
* Works as browser-in-browser. A real http proxy mode is being investigated but very unlikely to happen. Mostly because a lot of clicable elements are not http links and there is no way to proxy them. Also there is no universal way of stripping SSL that would satisfy all browsers. Check [issue #35](https://github.com/tenox7/wrp/issues/35) for more info.
|
||||
* Supports clicking on non-link elements (eg. cookie warnings, dropdown menus, etc.) and sending keystrokes. Yes, you can login to Gmail, etc.
|
||||
|
||||
## Usage
|
||||
|
||||
1. [Download a WRP binary](https://github.com/tenox7/wrp/releases/) and run it on a machine that will become your WRP gateway server.
|
||||
2. Point your legacy browser to `http://address:port` of WRP server. Do not set or use it as a "Proxy Server" (yet).
|
||||
2. Point your legacy browser to `http://address:port` of WRP server. Do not set or use it as a "http proxy server".
|
||||
3. Type a search string or a http/https URL and click Go.
|
||||
4. Adjust your screen width/height/scale/#colors to fit in your old browser.
|
||||
5. Scroll web page by clicking on the in-image scroll bar.
|
||||
@@ -23,8 +23,16 @@ A HTTP proxy server that allows to use historical / vintage web browsers on the
|
||||
|
||||
## Docker
|
||||
|
||||
docker hub:
|
||||
|
||||
```
|
||||
docker run -d -p 8080:8080 --name wrp --restart unless-stopped tenox7/wrp
|
||||
docker run -d -p 8080:8080 tenox7/wrp
|
||||
```
|
||||
|
||||
gcr.io:
|
||||
|
||||
```
|
||||
docker run -d -p 8080:8080 gcr.io/tenox7/wrp:latest
|
||||
```
|
||||
|
||||
## Flags
|
||||
@@ -33,6 +41,8 @@ docker run -d -p 8080:8080 --name wrp --restart unless-stopped tenox7/wrp
|
||||
-l listen address:port, default :8080
|
||||
-h headed mode, display browser window
|
||||
-d chromedp debug logging
|
||||
-n do not free maps and gif images after use
|
||||
-t image type gif (default) or png, when using PNG number of colors is ignored
|
||||
```
|
||||
|
||||
## Minimal Requirements
|
||||
|
||||
17
make.ps1
17
make.ps1
@@ -1,17 +0,0 @@
|
||||
param (
|
||||
[switch]$clean = $false
|
||||
)
|
||||
$env:GOARCH="amd64"
|
||||
foreach($sys in ("amd64-linux", "arm-linux", "amd64-freebsd", "amd64-openbsd", "amd64-darwin", "amd64-windows")) {
|
||||
$cpu,$os = $sys.split('-')
|
||||
$env:GOARCH=$cpu
|
||||
$env:GOOS=$os
|
||||
$o="wrp-$cpu-$(if ($os -eq "windows") {$os="windows.exe"} elseif ($os -eq "darwin") { $os="macos" })$os"
|
||||
Remove-Item -ErrorAction Ignore $o
|
||||
if (!$clean) {
|
||||
$cmd = "& go build -a -o $o wrp.go"
|
||||
Write-Host $cmd
|
||||
Invoke-Expression $cmd
|
||||
}
|
||||
}
|
||||
|
||||
213
wrp.go
213
wrp.go
@@ -12,9 +12,11 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/png"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -25,20 +27,31 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/cdproto/css"
|
||||
"github.com/chromedp/cdproto/emulation"
|
||||
"github.com/chromedp/cdproto/page"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/ericpauley/go-quantize/quantize"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "4.4"
|
||||
version = "4.5"
|
||||
srv http.Server
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
gifmap = make(map[string]bytes.Buffer)
|
||||
img = make(map[string]bytes.Buffer)
|
||||
ismap = make(map[string]wrpReq)
|
||||
nodel bool
|
||||
deftype string
|
||||
defgeom geom
|
||||
)
|
||||
|
||||
type geom struct {
|
||||
w int64
|
||||
h int64
|
||||
c int64
|
||||
}
|
||||
|
||||
type wrpReq struct {
|
||||
U string // url
|
||||
W int64 // width
|
||||
@@ -49,6 +62,7 @@ type wrpReq struct {
|
||||
Y int64 // mouseY
|
||||
K string // keys to send
|
||||
F string // Fn buttons
|
||||
T string // imgtype
|
||||
}
|
||||
|
||||
func (w *wrpReq) parseForm(req *http.Request) {
|
||||
@@ -58,12 +72,10 @@ func (w *wrpReq) parseForm(req *http.Request) {
|
||||
w.U = fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(w.U))
|
||||
}
|
||||
w.W, _ = strconv.ParseInt(req.FormValue("w"), 10, 64)
|
||||
if w.W < 10 {
|
||||
w.W = 1152
|
||||
}
|
||||
w.H, _ = strconv.ParseInt(req.FormValue("h"), 10, 64)
|
||||
if w.H < 10 {
|
||||
w.H = 600
|
||||
if w.W < 10 && w.H < 10 {
|
||||
w.W = defgeom.w
|
||||
w.H = defgeom.h
|
||||
}
|
||||
w.S, _ = strconv.ParseFloat(req.FormValue("s"), 64)
|
||||
if w.S < 0.1 {
|
||||
@@ -71,27 +83,51 @@ func (w *wrpReq) parseForm(req *http.Request) {
|
||||
}
|
||||
w.C, _ = strconv.ParseInt(req.FormValue("c"), 10, 64)
|
||||
if w.C < 2 || w.C > 256 {
|
||||
w.C = 256
|
||||
w.C = defgeom.c
|
||||
}
|
||||
w.K = req.FormValue("k")
|
||||
w.F = req.FormValue("Fn")
|
||||
w.T = req.FormValue("t")
|
||||
if w.T != "gif" && w.T != "png" {
|
||||
w.T = deftype
|
||||
}
|
||||
log.Printf("%s WrpReq from Form: %+v\n", req.RemoteAddr, w)
|
||||
}
|
||||
|
||||
func (w wrpReq) printPage(out http.ResponseWriter) {
|
||||
func (w wrpReq) printPage(out http.ResponseWriter, bgcolor string) {
|
||||
var s string
|
||||
out.Header().Set("Cache-Control", "max-age=0")
|
||||
out.Header().Set("Expires", "-1")
|
||||
out.Header().Set("Pragma", "no-cache")
|
||||
out.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(out, "<!-- Web Rendering Proxy Version %s -->\n", version)
|
||||
fmt.Fprintf(out, "<HTML>\n<HEAD><TITLE>WRP %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#F0F0F0\">\n", w.U)
|
||||
fmt.Fprintf(out, "<HTML>\n<HEAD><TITLE>WRP %s</TITLE></HEAD>\n<BODY BGCOLOR=\"%s\">\n", w.U, bgcolor)
|
||||
fmt.Fprintf(out, "<FORM ACTION=\"/\" METHOD=\"POST\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"TEXT\" NAME=\"url\" VALUE=\"%s\" SIZE=\"10\">", w.U)
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"TEXT\" NAME=\"url\" VALUE=\"%s\" SIZE=\"20\">", w.U)
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" VALUE=\"Go\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"Bk\">\n")
|
||||
fmt.Fprintf(out, "W <INPUT TYPE=\"TEXT\" NAME=\"w\" VALUE=\"%d\" SIZE=\"4\"> \n", w.W)
|
||||
fmt.Fprintf(out, "H <INPUT TYPE=\"TEXT\" NAME=\"h\" VALUE=\"%d\" SIZE=\"4\"> \n", w.H)
|
||||
fmt.Fprintf(out, "S <INPUT TYPE=\"TEXT\" NAME=\"s\" VALUE=\"%1.2f\" SIZE=\"3\"> \n", w.S)
|
||||
fmt.Fprintf(out, "S <SELECT NAME=\"s\">\n")
|
||||
for _, v := range []float64{0.65, 0.75, 0.85, 0.95, 1.0, 1.05, 1.15, 1.25} {
|
||||
if v == w.S {
|
||||
s = "SELECTED"
|
||||
} else {
|
||||
s = ""
|
||||
}
|
||||
fmt.Fprintf(out, "<OPTION VALUE=\"%1.2f\" %s>%1.2f</OPTION>\n", v, s, v)
|
||||
}
|
||||
fmt.Fprintf(out, "</SELECT>\n")
|
||||
fmt.Fprintf(out, "T <SELECT NAME=\"t\">\n")
|
||||
for _, v := range []string{"gif", "png"} {
|
||||
if v == w.T {
|
||||
s = "SELECTED"
|
||||
} else {
|
||||
s = ""
|
||||
}
|
||||
fmt.Fprintf(out, "<OPTION VALUE=\"%s\" %s>%s</OPTION>\n", v, s, strings.ToUpper(v))
|
||||
}
|
||||
fmt.Fprintf(out, "</SELECT>\n")
|
||||
fmt.Fprintf(out, "C <INPUT TYPE=\"TEXT\" NAME=\"c\" VALUE=\"%d\" SIZE=\"3\">\n", w.C)
|
||||
fmt.Fprintf(out, "K <INPUT TYPE=\"TEXT\" NAME=\"k\" VALUE=\"\" SIZE=\"4\"> \n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"Bs\">\n")
|
||||
@@ -103,21 +139,21 @@ func (w wrpReq) printPage(out http.ResponseWriter) {
|
||||
fmt.Fprintf(out, "</FORM><BR>\n")
|
||||
}
|
||||
|
||||
func (w wrpReq) printFooter(out http.ResponseWriter) {
|
||||
fmt.Fprintf(out, "\n<P><FONT SIZE=\"-2\"><A HREF=\"/?url=https://github.com/tenox7/wrp/&w=%d&h=%d&s=%1.2f&c=%d\">"+
|
||||
"Web Rendering Proxy Version %s</A> | <A HREF=\"/shutdown/\">Shutdown WRP</A></FONT></BODY>\n</HTML>\n", w.W, w.H, w.S, w.C, version)
|
||||
func (w wrpReq) printFooter(out http.ResponseWriter, h string, s string) {
|
||||
fmt.Fprintf(out, "\n<P><FONT SIZE=\"-2\"><A HREF=\"/?url=https://github.com/tenox7/wrp/&w=%d&h=%d&s=%1.2f&c=%d&t=%s\">"+
|
||||
"Web Rendering Proxy Version %s</A> | <A HREF=\"/shutdown/\">Shutdown WRP</A> | "+
|
||||
"<A HREF=\"/\">Page Height: %s</A> | <A HREF=\"/\">Img Size: %s</A></FONT></BODY>\n</HTML>\n", w.W, w.H, w.S, w.C, w.T, version, h, s)
|
||||
}
|
||||
|
||||
func pageServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s Page Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
||||
var w wrpReq
|
||||
w.parseForm(req)
|
||||
|
||||
if len(w.U) > 4 {
|
||||
w.capture(req.RemoteAddr, out)
|
||||
} else {
|
||||
w.printPage(out)
|
||||
w.printFooter(out)
|
||||
w.printPage(out, "#FFFFFF")
|
||||
w.printFooter(out, "", "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +165,9 @@ func mapServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("Unable to find map %s\n", req.URL.Path)
|
||||
return
|
||||
}
|
||||
defer delete(ismap, req.URL.Path)
|
||||
if !nodel {
|
||||
defer delete(ismap, req.URL.Path)
|
||||
}
|
||||
n, err := fmt.Sscanf(req.URL.RawQuery, "%d,%d", &w.X, &w.Y)
|
||||
if err != nil || n != 2 {
|
||||
fmt.Fprintf(out, "n=%d, err=%s\n", n, err)
|
||||
@@ -140,37 +178,40 @@ func mapServer(out http.ResponseWriter, req *http.Request) {
|
||||
if len(w.U) > 4 {
|
||||
w.capture(req.RemoteAddr, out)
|
||||
} else {
|
||||
w.printPage(out)
|
||||
w.printFooter(out)
|
||||
w.printPage(out, "#FFFFFF")
|
||||
w.printFooter(out, "", "")
|
||||
}
|
||||
}
|
||||
|
||||
func imgServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s IMG Request for %s\n", req.RemoteAddr, req.URL.Path)
|
||||
gifbuf, ok := gifmap[req.URL.Path]
|
||||
if !ok || gifbuf.Bytes() == nil {
|
||||
imgbuf, ok := img[req.URL.Path]
|
||||
if !ok || imgbuf.Bytes() == nil {
|
||||
fmt.Fprintf(out, "Unable to find image %s\n", req.URL.Path)
|
||||
log.Printf("Unable to find image %s\n", req.URL.Path)
|
||||
log.Printf("%s Unable to find image %s\n", req.RemoteAddr, req.URL.Path)
|
||||
return
|
||||
}
|
||||
defer delete(gifmap, req.URL.Path)
|
||||
out.Header().Set("Content-Type", "image/gif")
|
||||
out.Header().Set("Content-Length", strconv.Itoa(len(gifbuf.Bytes())))
|
||||
if !nodel {
|
||||
defer delete(img, req.URL.Path)
|
||||
}
|
||||
if strings.HasPrefix(req.URL.Path, ".gif") {
|
||||
out.Header().Set("Content-Type", "image/gif")
|
||||
} else if strings.HasPrefix(req.URL.Path, ".png") {
|
||||
out.Header().Set("Content-Type", "image/png")
|
||||
}
|
||||
out.Header().Set("Content-Length", strconv.Itoa(len(imgbuf.Bytes())))
|
||||
out.Header().Set("Cache-Control", "max-age=0")
|
||||
out.Header().Set("Expires", "-1")
|
||||
out.Header().Set("Pragma", "no-cache")
|
||||
out.Write(gifbuf.Bytes())
|
||||
out.Write(imgbuf.Bytes())
|
||||
out.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
func (w wrpReq) capture(c string, out http.ResponseWriter) {
|
||||
var pngbuf []byte
|
||||
var gifbuf bytes.Buffer
|
||||
var err error
|
||||
|
||||
if w.X > 0 && w.Y > 0 {
|
||||
log.Printf("%s Mouse Click %d,%d\n", c, w.X, w.Y)
|
||||
err = chromedp.Run(ctx, chromedp.MouseClickXY(int64(float64(w.X)/w.S), int64(float64(w.Y)/w.S)))
|
||||
err = chromedp.Run(ctx, chromedp.MouseClickXY(int64(float64(w.X)/float64(w.S)), int64(float64(w.Y)/float64(w.S))))
|
||||
} else if len(w.F) > 0 {
|
||||
log.Printf("%s Button %v\n", c, w.F)
|
||||
switch w.F {
|
||||
@@ -194,12 +235,8 @@ func (w wrpReq) capture(c string, out http.ResponseWriter) {
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent(w.K))
|
||||
} else {
|
||||
log.Printf("%s Processing Capture Request for %s\n", c, w.U)
|
||||
err = chromedp.Run(ctx,
|
||||
emulation.SetDeviceMetricsOverride(int64(float64(w.W)/w.S), int64(float64(w.H)/w.S), w.S, false),
|
||||
chromedp.Navigate(w.U),
|
||||
)
|
||||
err = chromedp.Run(ctx, chromedp.Navigate(w.U))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "context canceled" {
|
||||
log.Printf("%s Contex cancelled, try again", c)
|
||||
@@ -211,45 +248,77 @@ func (w wrpReq) capture(c string, out http.ResponseWriter) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
chromedp.Run(
|
||||
ctx, chromedp.Sleep(time.Second*2),
|
||||
var styles []*css.ComputedProperty
|
||||
var r, g, b int
|
||||
var h int64
|
||||
var pngcap []byte
|
||||
chromedp.Run(ctx,
|
||||
emulation.SetDeviceMetricsOverride(int64(float64(w.W)/w.S), 10, w.S, false),
|
||||
chromedp.Sleep(time.Second*2),
|
||||
chromedp.Location(&w.U),
|
||||
chromedp.ComputedStyle("body", &styles, chromedp.ByQuery),
|
||||
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||
_, _, s, err := page.GetLayoutMetrics().Do(ctx)
|
||||
if err == nil {
|
||||
h = int64(math.Ceil(s.Height))
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
log.Printf("%s Landed on: %s\n", c, w.U)
|
||||
w.printPage(out)
|
||||
|
||||
// Process Screenshot Image
|
||||
err = chromedp.Run(ctx, chromedp.CaptureScreenshot(&pngbuf))
|
||||
for _, style := range styles {
|
||||
if style.Name == "background-color" {
|
||||
fmt.Sscanf(style.Value, "rgb(%d,%d,%d)", &r, &g, &b)
|
||||
}
|
||||
}
|
||||
log.Printf("%s Landed on: %s, Height: %v\n", c, w.U, h)
|
||||
w.printPage(out, fmt.Sprintf("#%02X%02X%02X", r, g, b))
|
||||
if w.H == 0 && h > 0 {
|
||||
chromedp.Run(ctx, emulation.SetDeviceMetricsOverride(int64(float64(w.W)/w.S), h+30, w.S, false))
|
||||
} else {
|
||||
chromedp.Run(ctx, emulation.SetDeviceMetricsOverride(int64(float64(w.W)/w.S), int64(float64(w.H)/w.S), w.S, false))
|
||||
}
|
||||
err = chromedp.Run(ctx, chromedp.CaptureScreenshot(&pngcap))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to capture screenshot: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to capture screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
bytes.NewReader(pngbuf).Seek(0, 0)
|
||||
img, err := png.Decode(bytes.NewReader(pngbuf))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode screenshot: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to decode page screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
gifbuf.Reset()
|
||||
err = gif.Encode(&gifbuf, img, &gif.Options{NumColors: int(w.C), Quantizer: quantize.MedianCutQuantizer{}})
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode GIF: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to encode GIF:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Compose map and gif
|
||||
seq := rand.Intn(9999)
|
||||
imgpath := fmt.Sprintf("/img/%04d.gif", seq)
|
||||
imgpath := fmt.Sprintf("/img/%04d.%s", seq, w.T)
|
||||
mappath := fmt.Sprintf("/map/%04d.map", seq)
|
||||
gifmap[imgpath] = gifbuf
|
||||
ismap[mappath] = w
|
||||
log.Printf("%s Encoded GIF image: %s, Size: %dKB, Colors: %d\n", c, imgpath, len(gifbuf.Bytes())/1024, w.C)
|
||||
fmt.Fprintf(out, "<A HREF=\"%s\"><IMG SRC=\"%s\" BORDER=\"0\" ISMAP></A>", mappath, imgpath)
|
||||
w.printFooter(out)
|
||||
var ssize string
|
||||
var sw, sh int
|
||||
if w.T == "gif" {
|
||||
i, err := png.Decode(bytes.NewReader(pngcap))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode screenshot: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to decode page screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
var gifbuf bytes.Buffer
|
||||
err = gif.Encode(&gifbuf, i, &gif.Options{NumColors: int(w.C), Quantizer: quantize.MedianCutQuantizer{}})
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode GIF: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to encode GIF:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
img[imgpath] = gifbuf
|
||||
ssize = fmt.Sprintf("%.1f MB", float32(len(gifbuf.Bytes()))/1024.0/1024.0)
|
||||
sw = i.Bounds().Max.X
|
||||
sh = i.Bounds().Max.Y
|
||||
log.Printf("%s Encoded GIF image: %s, Size: %s, Colors: %d, %dx%d\n", c, imgpath, ssize, w.C, sw, sh)
|
||||
} else if w.T == "png" {
|
||||
pngbuf := bytes.NewBuffer(pngcap)
|
||||
img[imgpath] = *pngbuf
|
||||
cfg, _, _ := image.DecodeConfig(pngbuf)
|
||||
ssize = fmt.Sprintf("%.1f MB", float32(len(pngbuf.Bytes()))/1024.0/1024.0)
|
||||
sw = cfg.Width
|
||||
sh = cfg.Height
|
||||
log.Printf("%s Got PNG image: %s, Size: %s, %dx%d\n", c, imgpath, ssize, sw, sh)
|
||||
}
|
||||
fmt.Fprintf(out, "<A HREF=\"%s\"><IMG SRC=\"%s\" BORDER=\"0\" ALT=\"Url: %s, Size: %s\" WIDTH=\"%d\" HEIGHT=\"%d\" ISMAP></A>", mappath, imgpath, w.U, ssize, sw, sh)
|
||||
w.printFooter(out, fmt.Sprintf("%d PX", h), ssize)
|
||||
log.Printf("%s Done with caputure for %s\n", c, w.U)
|
||||
}
|
||||
|
||||
@@ -268,18 +337,26 @@ func haltServer(out http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var addr string
|
||||
var addr, fgeom string
|
||||
var head, headless bool
|
||||
var debug bool
|
||||
var err error
|
||||
flag.StringVar(&addr, "l", ":8080", "Listen address:port, default :8080")
|
||||
flag.BoolVar(&head, "h", false, "Headed mode - display browser window")
|
||||
flag.BoolVar(&debug, "d", false, "Debug ChromeDP")
|
||||
flag.BoolVar(&nodel, "n", false, "Do not free maps and images after use")
|
||||
flag.StringVar(&deftype, "t", "gif", "Image type: gif|png")
|
||||
flag.StringVar(&fgeom, "g", "1152x600x256", "Geometry: width x height x colors, height can be 0 for unlimited")
|
||||
flag.Parse()
|
||||
if head {
|
||||
headless = false
|
||||
} else {
|
||||
headless = true
|
||||
}
|
||||
n, err := fmt.Sscanf(fgeom, "%dx%dx%d", &defgeom.w, &defgeom.h, &defgeom.c)
|
||||
if err != nil || n != 3 {
|
||||
log.Fatalf("Unable to parse -g geometry flag / %s", err)
|
||||
}
|
||||
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||
chromedp.Flag("headless", headless),
|
||||
chromedp.Flag("hide-scrollbars", false),
|
||||
@@ -310,7 +387,7 @@ func main() {
|
||||
log.Printf("Web Rendering Proxy Version %s\n", version)
|
||||
log.Printf("Starting WRP http server on %s\n", addr)
|
||||
srv.Addr = addr
|
||||
err := srv.ListenAndServe()
|
||||
err = srv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user