mirror of
https://github.com/tenox7/wrp.git
synced 2026-07-09 02:16:47 +00:00
Compare commits
178 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42bba02a73 | ||
|
|
892758140d | ||
|
|
bd0c2d974c | ||
|
|
7b9ffea57f | ||
|
|
ef1c4c0760 | ||
|
|
78efc3210d | ||
|
|
6b372aca23 | ||
|
|
9d21aa5ce1 | ||
|
|
365a786a42 | ||
|
|
007ea7b655 | ||
|
|
007f7f87d6 | ||
|
|
fb712136b5 | ||
|
|
89426c969d | ||
|
|
e9e97e8146 | ||
|
|
ef43ef5ce6 | ||
|
|
61af9046ae | ||
|
|
90dc64a625 | ||
|
|
534c26698e | ||
|
|
2850d7f3f2 | ||
|
|
7a63e0444f | ||
|
|
6085aaf824 | ||
|
|
a70f1a9ebf | ||
|
|
64c2a16085 | ||
|
|
916b5ee1b7 | ||
|
|
4db89e6a3a | ||
|
|
fc15e4ea44 | ||
|
|
619bd74891 | ||
|
|
fd9e6f3762 | ||
|
|
9c5c495811 | ||
|
|
2457473706 | ||
|
|
79f56a920c | ||
|
|
2042d1bb9d | ||
|
|
ff293f2b7a | ||
|
|
e808b494ab | ||
|
|
88fbe63fb7 | ||
|
|
25b10409db | ||
|
|
5bea0ae9ff | ||
|
|
0d805d82de | ||
|
|
9ccd770e85 | ||
|
|
48ecf6fbe9 | ||
|
|
d4f00119cb | ||
|
|
a87a37f673 | ||
|
|
0fd6967393 | ||
|
|
3ad8f78c45 | ||
|
|
e3dbe85c51 | ||
|
|
30c42bd9b8 | ||
|
|
12724a262e | ||
|
|
25a382e809 | ||
|
|
b03b8a8031 | ||
|
|
a0eb33fe51 | ||
|
|
f56c958aba | ||
|
|
3004962beb | ||
|
|
4d9319eef2 | ||
|
|
7916fa1260 | ||
|
|
9f9014dc15 | ||
|
|
3231a0a61c | ||
|
|
94fb4f437b | ||
|
|
9110ad0853 | ||
|
|
51c4c35651 | ||
|
|
b6e402029a | ||
|
|
9f7107c00b | ||
|
|
500ad0d19a | ||
|
|
b5747f52e7 | ||
|
|
0d998af68c | ||
|
|
eb38499280 | ||
|
|
56fa314d61 | ||
|
|
335a84f52e | ||
|
|
bb29ce38de | ||
|
|
db4ed0d811 | ||
|
|
2f667e447c | ||
|
|
00304b5d05 | ||
|
|
9f21d8d06e | ||
|
|
b0f4170c6c | ||
|
|
8d165df36d | ||
|
|
407907bece | ||
|
|
f838caa328 | ||
|
|
a8b8a557f7 | ||
|
|
d036914fcb | ||
|
|
701240eb7c | ||
|
|
1d9af26604 | ||
|
|
5ed55c387c | ||
|
|
0e3192b69f | ||
|
|
91870f5724 | ||
|
|
c1ffd71e25 | ||
|
|
26b3c21aa7 | ||
|
|
8cec22eb90 | ||
|
|
e64f413c76 | ||
|
|
94d0e0d128 | ||
|
|
b546b5cbae | ||
|
|
a2a4152b86 | ||
|
|
db77479bad | ||
|
|
33436333cf | ||
|
|
866750700b | ||
|
|
3f445abd14 | ||
|
|
d7eb89e135 | ||
|
|
bf946f0f63 | ||
|
|
7673e15b9e | ||
|
|
d00b1d5d7f | ||
|
|
3e8f109edd | ||
|
|
9a0e5809c1 | ||
|
|
96acf94521 | ||
|
|
807373d668 | ||
|
|
703e9d0452 | ||
|
|
f7799ecba5 | ||
|
|
37562cce23 | ||
|
|
631971b0bb | ||
|
|
23a7ba5cbf | ||
|
|
2733a84d2d | ||
|
|
abea41f498 | ||
|
|
da524ff275 | ||
|
|
b92478fd6a | ||
|
|
ee0e72f246 | ||
|
|
a3c06d346c | ||
|
|
0065fdc2c7 | ||
|
|
22efadf9cf | ||
|
|
4070fa7a53 | ||
|
|
41a14ad590 | ||
|
|
a212a14bd8 | ||
|
|
5a86c32d9a | ||
|
|
55f3c852f9 | ||
|
|
79c86a7056 | ||
|
|
19f4be3ac1 | ||
|
|
6ffdf1fd7f | ||
|
|
0796c86e73 | ||
|
|
d8b4f160ac | ||
|
|
93e9fddca7 | ||
|
|
e13a06610b | ||
|
|
5b28f1d913 | ||
|
|
da5246b9df | ||
|
|
8a484813c3 | ||
|
|
75233ccb97 | ||
|
|
04954f8be6 | ||
|
|
884374edcd | ||
|
|
ba522e3a86 | ||
|
|
e05135e433 | ||
|
|
67d550672b | ||
|
|
71889effe7 | ||
|
|
6a7ffbb67b | ||
|
|
f93058fed3 | ||
|
|
67ed26b8f4 | ||
|
|
6aefcdacc5 | ||
|
|
de315fb95f | ||
|
|
b098b3632a | ||
|
|
5ec0266f75 | ||
|
|
7d9cec6297 | ||
|
|
43df501d97 | ||
|
|
85d64a3577 | ||
|
|
993e5723ed | ||
|
|
9056c798d6 | ||
|
|
b937bea370 | ||
|
|
8fd65b3e47 | ||
|
|
8716a983ce | ||
|
|
4757cfd32b | ||
|
|
79e6f3a17e | ||
|
|
d8f5c6fb28 | ||
|
|
c816ef712a | ||
|
|
d28924583c | ||
|
|
1c17b39ea5 | ||
|
|
ecb2cc0c06 | ||
|
|
b571df7a37 | ||
|
|
78c568ac09 | ||
|
|
04a755749e | ||
|
|
e983f244f8 | ||
|
|
9b76c045d6 | ||
|
|
c8e391274a | ||
|
|
7b1274b9d4 | ||
|
|
0128b3ff8e | ||
|
|
6de3fad580 | ||
|
|
d7dcb58adc | ||
|
|
e5f83225f7 | ||
|
|
36803c4312 | ||
|
|
40e081be77 | ||
|
|
1c18fb9b81 | ||
|
|
363fbcd225 | ||
|
|
bf7e7bfb2c | ||
|
|
fec812bc32 | ||
|
|
a238a0ea6f | ||
|
|
444b7b31d7 |
97
.goreleaser.yml
Normal file
97
.goreleaser.yml
Normal file
@@ -0,0 +1,97 @@
|
||||
version: 2
|
||||
|
||||
project_name: wrp
|
||||
|
||||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
|
||||
builds:
|
||||
- main: .
|
||||
binary: wrp
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
- freebsd
|
||||
- openbsd
|
||||
- windows
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
ignore:
|
||||
- goos: darwin
|
||||
goarch: arm
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
ldflags:
|
||||
- -s -w
|
||||
|
||||
archives:
|
||||
- formats:
|
||||
- tar.gz
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
formats:
|
||||
- zip
|
||||
|
||||
dockers:
|
||||
- image_templates:
|
||||
- "tenox7/wrp:{{ .Tag }}-amd64"
|
||||
- "tenox7/wrp:latest-amd64"
|
||||
use: buildx
|
||||
goarch: amd64
|
||||
dockerfile: Dockerfile.goreleaser
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64"
|
||||
|
||||
- image_templates:
|
||||
- "tenox7/wrp:{{ .Tag }}-arm64"
|
||||
- "tenox7/wrp:latest-arm64"
|
||||
use: buildx
|
||||
goarch: arm64
|
||||
dockerfile: Dockerfile.goreleaser
|
||||
build_flag_templates:
|
||||
- "--platform=linux/arm64"
|
||||
|
||||
docker_manifests:
|
||||
- name_template: "tenox7/wrp:{{ .Tag }}"
|
||||
image_templates:
|
||||
- "tenox7/wrp:{{ .Tag }}-amd64"
|
||||
- "tenox7/wrp:{{ .Tag }}-arm64"
|
||||
|
||||
- name_template: "tenox7/wrp:latest"
|
||||
image_templates:
|
||||
- "tenox7/wrp:latest-amd64"
|
||||
- "tenox7/wrp:latest-arm64"
|
||||
|
||||
nfpms:
|
||||
- package_name: wrp
|
||||
vendor: Antoni Sawicki
|
||||
homepage: https://github.com/tenox7/wrp
|
||||
maintainer: Antoni Sawicki <as@tenoware.com>
|
||||
description: Web Rendering Proxy
|
||||
license: Apache-2.0
|
||||
formats:
|
||||
- deb
|
||||
- rpm
|
||||
- apk
|
||||
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
|
||||
release:
|
||||
github:
|
||||
owner: tenox7
|
||||
name: wrp
|
||||
11
Dockerfile
11
Dockerfile
@@ -1,5 +1,14 @@
|
||||
FROM golang AS builder
|
||||
WORKDIR /src
|
||||
RUN git clone https://github.com/tenox7/wrp.git
|
||||
WORKDIR /src/wrp
|
||||
RUN go mod download
|
||||
ARG TARGETARCH
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o /wrp-${TARGETARCH}
|
||||
|
||||
FROM chromedp/headless-shell
|
||||
ADD wrp /wrp
|
||||
ARG TARGETARCH
|
||||
COPY --from=builder /wrp-${TARGETARCH} /wrp
|
||||
ENTRYPOINT ["/wrp"]
|
||||
ENV PATH="/headless-shell:${PATH}"
|
||||
LABEL maintainer="as@tenoware.com"
|
||||
|
||||
5
Dockerfile.goreleaser
Normal file
5
Dockerfile.goreleaser
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM chromedp/headless-shell
|
||||
COPY wrp /wrp
|
||||
ENTRYPOINT ["/wrp"]
|
||||
ENV PATH="/headless-shell:${PATH}"
|
||||
LABEL maintainer="as@tenoware.com"
|
||||
6
Dockerfile.local
Normal file
6
Dockerfile.local
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM chromedp/headless-shell
|
||||
ARG TARGETARCH
|
||||
ADD wrp-${TARGETARCH}-linux /wrp
|
||||
ENTRYPOINT ["/wrp"]
|
||||
ENV PATH="/headless-shell:${PATH}"
|
||||
LABEL maintainer="as@tenoware.com"
|
||||
37
Makefile
Normal file → Executable file
37
Makefile
Normal file → Executable file
@@ -1,28 +1,31 @@
|
||||
all: wrp
|
||||
|
||||
wrp: wrp.go
|
||||
go build wrp.go
|
||||
go build -a
|
||||
|
||||
cross:
|
||||
GOOS=linux GOARCH=amd64 go build -a -o wrp-amd64-linux wrp.go
|
||||
GOOS=freebsd GOARCH=amd64 go build -a -o wrp-amd64-freebsd wrp.go
|
||||
GOOS=openbsd GOARCH=amd64 go build -a -o wrp-amd64-openbsd wrp.go
|
||||
GOOS=darwin GOARCH=amd64 go build -a -o wrp-amd64-macos wrp.go
|
||||
GOOS=darwin GOARCH=arm64 go build -a -o wrp-arm64-macos wrp.go
|
||||
GOOS=windows GOARCH=amd64 go build -a -o wrp-amd64-windows.exe wrp.go
|
||||
GOOS=windows GOARCH=386 go build -a -o wrp-386-windows.exe wrp.go
|
||||
GOOS=linux GOARCH=arm go build -a -o wrp-arm-linux wrp.go
|
||||
GOOS=linux GOARCH=arm64 go build -a -o wrp-arm64-linux wrp.go
|
||||
GOOS=linux GOARCH=amd64 go build -a -o wrp-amd64-linux
|
||||
GOOS=freebsd GOARCH=amd64 go build -a -o wrp-amd64-freebsd
|
||||
GOOS=openbsd GOARCH=amd64 go build -a -o wrp-amd64-openbsd
|
||||
GOOS=darwin GOARCH=amd64 go build -a -o wrp-amd64-macos
|
||||
GOOS=darwin GOARCH=arm64 go build -a -o wrp-arm64-macos
|
||||
GOOS=windows GOARCH=amd64 go build -a -o wrp-amd64-windows.exe
|
||||
GOOS=linux GOARCH=arm go build -a -o wrp-arm-linux
|
||||
GOOS=linux GOARCH=arm64 go build -a -o wrp-arm64-linux
|
||||
|
||||
docker: wrp
|
||||
docker build -t tenox7/wrp:latest .
|
||||
docker-local:
|
||||
GOOS=linux GOARCH=amd64 go build -a -o wrp-amd64-linux
|
||||
GOOS=linux GOARCH=arm64 go build -a -o wrp-arm64-linux
|
||||
docker buildx build --platform linux/amd64,linux/arm64 -t tenox7/wrp:latest -f Dockerfile.local --load .
|
||||
|
||||
dockerhub:
|
||||
docker push tenox7/wrp:latest
|
||||
docker-push:
|
||||
docker buildx build --platform linux/amd64,linux/arm64 -t tenox7/wrp:latest --push .
|
||||
|
||||
gcrio:
|
||||
docker tag tenox7/wrp:latest gcr.io/tenox7/wrp
|
||||
docker push gcr.io/tenox7/wrp
|
||||
docker-clean:
|
||||
docker buildx prune -a -f
|
||||
|
||||
release:
|
||||
export GITHUB_TOKEN=$$(gh auth token) && goreleaser release --clean
|
||||
|
||||
clean:
|
||||
rm -rf wrp-* wrp
|
||||
|
||||
255
README.md
255
README.md
@@ -1,124 +1,219 @@
|
||||
# WRP - Web Rendering Proxy
|
||||
|
||||
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.
|
||||
A browser-in-browser proxy server that allows to use historical / vintage web browsers on the modern web.
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
## Modes of operation
|
||||
|
||||
### Access Types
|
||||
|
||||
- Browser-in-browser, navigate to the address of WRP and use the built-in web form to browse web.
|
||||
- HTTP proxy mode which offers more seamless, but also limited use. Semi compatible with https://.
|
||||
|
||||
### Rende modes
|
||||
|
||||
- ISMAP "graphical" mode, renders web page in to a GIF/PNG/JPG image with clickable imagemap.
|
||||
- Simple HTML mode converts pages into simplified HTML for old browsers.
|
||||
|
||||
Different modes have different uses. ISMAP mode will be better for flashy modern web. Simple HTML mode will be better for reading articles or documentation.
|
||||
|
||||
## Usage Instructions
|
||||
|
||||
* [Download a WRP binary](https://github.com/tenox7/wrp/releases/) run it on a machine that will become your WRP gateway/server. This should be modern hardware and OS. Google Chrome / Chromium / Brave Browser is required to be preinstalled. Do not run WRP on an old machine like Windows XP or 98.
|
||||
* Make sure you have disabled firewall or open port WRP is listening on (by default 8080).
|
||||
* Point your legacy browser to `http://address:port` of the WRP server or set your proxy address there.
|
||||
* Type a search string or a full http/https URL and click **Go**.
|
||||
* Select whether you want to use graphical (ISMAP) or simple HTML mode.
|
||||
|
||||
### Proxy mode
|
||||
|
||||
- You can use `/proxy.pac` automatic configuration mode.
|
||||
- Stick to `http://` addresses only, the proxy will automatically rewrite them to `https://` as needed.
|
||||
- `https://` addresses are limited in functionality (no /suffix or paths).
|
||||
- Proxy mode doesn't have a customizable web interface with html forms. All configuration is done via flags.
|
||||
|
||||
### Image Map Mode
|
||||
|
||||
* [Download a WRP binary](https://github.com/tenox7/wrp/releases/) and run it on a machine that will become your WRP gateway/server.
|
||||
This machine should be pretty modern, high spec and Google Chrome / Chromium Browser is required to be preinstalled.
|
||||
* Point your legacy browser to `http://address:port` of WRP server. Do not set or use it as a "proxy server".
|
||||
* Type a search string or a http/https URL and click **Go**.
|
||||
* Adjust your screen **W**idth/**H**eight/**S**cale/**C**olors to fit in your old browser.
|
||||
* Scroll web page by clicking on the in-image scroll bar.
|
||||
* Scroll web page by clicking on the in-image scroll bar on the right.
|
||||
* WRP also allows **a single tall image without the vertical scrollbar** and use client scrolling. To enable this, simply height **H** to `0` (or flag `-g 1152x0x216`. However this should not be used with old and low spec clients. Such tall images will be very large, take a lot of memory and long time to process, especially for GIFs.
|
||||
* Do not use client browser history-back, instead use **Bk** button in the app.
|
||||
* You can re-capture screenshot without reloading page by using **St** (Stop). This is useful if page didn't render fully before screenshot is taken.
|
||||
* You can also reload page and re-capture screenshot with **Re** (Reload).
|
||||
* To send keystrokes, fill **K** input box and press **Go**. There also are buttons for backspace, enter and arrow keys.
|
||||
* You can set height **H** to `0` to render pages in to **a single tall image without the vertical scrollbar** and use client scrolling. However this should not be used with old and low spec clients. Such tall images will be very large and take long time to process, especially for GIFs.
|
||||
* Prefer PNG over GIF if your browser supports it. PNG is much faster, whereas GIF requires a lot of additional processing on both client and server.
|
||||
* You can re-capture page screenshot without reloading by using **St** (Stop).
|
||||
* You can also reload and re-capture current page with **Re** (Reload).
|
||||
* The default image type is `GIP` - an ultra fast, optimized, parallel encoded GIF type.
|
||||
* If your browser supports it, prefer PNG over GIF/JPG. PNG is much faster, whereas GIF/JPG requires a lot of additional processing on both client and server to compress/uncompress.
|
||||
* GIF images are by default encoded with 216 colors, "web safe" palette. This uses an ultra fast encoding algorithm optimized mostly for text. Images have rather wonky color colors. If you want better color representation switch to 256 color mode.
|
||||
|
||||
## Customization
|
||||
### Simple HTML mode
|
||||
|
||||
Since 4.5.1 WRP supports customizing it's own UI using HTML Template file. Download [wrp.html](wrp.html) place in the same directory with wrp binary customize it to your liking.
|
||||
|
||||
## Docker
|
||||
|
||||
```shell
|
||||
$ docker run -d -p 80:8080 tenox7/wrp
|
||||
```
|
||||
|
||||
## Google Cloud Run
|
||||
|
||||
```shell
|
||||
$ gcloud run deploy --platform managed --image=gcr.io/tenox7/wrp:latest --memory=2Gi --args='-t=png','-g=1280x0x256'
|
||||
```
|
||||
|
||||
Or from [Gcloud Console](https://console.cloud.google.com/run). Use `gcr.io/tenox7/wrp:latest` as container image URL.
|
||||
|
||||
Note that unfortunately GCR forces https. Your browser support of encryption protocols and certification authorities will vary.
|
||||
|
||||
## Azure Container Instances
|
||||
|
||||
```shell
|
||||
$ az container create --resource-group wrp --name wrp --image gcr.io/tenox7/wrp:latest --cpu 1 --memory 2 --ports 80 --protocol tcp --os-type Linux --ip-address Public --command-line '/wrp -l :80 -t png -g 1280x0x256'
|
||||
```
|
||||
|
||||
Or from the [Azure Console](https://portal.azure.com/#create/Microsoft.ContainerInstances). Use `gcr.io/tenox7/wrp:latest` or `tenox7/wrp:latest` for image name.
|
||||
|
||||
Fortunately ACI allows port 80 without encryption.
|
||||
|
||||
|
||||
## Flags
|
||||
|
||||
```
|
||||
-l listen address:port (default :8080)
|
||||
-t image type gif or png (default gif)
|
||||
-g image geometry, WxHxC, height can be 0 for unlimited (default 1152x600x256)
|
||||
-h headless mode, hide browser window on the server (default true)
|
||||
-d chromedp debug logging (default false)
|
||||
-n do not free maps and gif images after use (default false)
|
||||
```
|
||||
* Select image type PNG/GIF/JPG. Each individual image from the original web site will be converted to the selected format.
|
||||
* Type maximum image size in pixels.
|
||||
|
||||
## UI explanation
|
||||
|
||||
The first unnamed input box is either search (google) or URL starting with http/https
|
||||
|
||||
**Go** instructs browser to navigate to the url or perform search
|
||||
`Go` Navigate to the url or perform search
|
||||
|
||||
**Bk** is History Back
|
||||
`Bk` History Back
|
||||
|
||||
**St** is Stop, also re-capture screenshot without refreshing page, for example if page
|
||||
render takes a long time or it changes periodically
|
||||
`St` Stop, also re-capture screenshot without refreshing page, for example if page
|
||||
render takes a long time or it updates / changes periodically
|
||||
|
||||
**Re** is Reload
|
||||
`Re` Remote Reload / Refresh
|
||||
|
||||
**W** is width in pixels, adjust it to get rid of horizontal scroll bar
|
||||
`Up` Page Up
|
||||
|
||||
**H** is height in pixels, adjust it to get rid of vertical scroll bar.
|
||||
`Dn` Page Down
|
||||
|
||||
`W` is width in pixels, adjust it to get rid of horizontal scroll bar
|
||||
|
||||
`H` is height in pixels, adjust it to get rid of vertical scroll bar.
|
||||
It can also be set to 0 to produce one very tall image and use
|
||||
client scroll. This 0 size is experimental, buggy and should be
|
||||
used with PNG and lots of memory on a client side.
|
||||
|
||||
**Z** is zoom or scale
|
||||
`Z` Zoom or scale
|
||||
|
||||
**C** is colors, for GIF images only (unused in PNG)
|
||||
`M` Mode - ISMAP (clickable imagemap) or simple HTML mode
|
||||
|
||||
**K** is keystroke input, you can type some letters in it and when you click Go it will be typed in the remote browser.
|
||||
`T` Image type PNG / GIF / JPEG
|
||||
|
||||
**Bs** is backspace
|
||||
`C` Colors, for GIF images only
|
||||
|
||||
**Rt** is return / enter
|
||||
`K` Keystroke input, you can type some letters in it and when you click Go it will be typed in the remote browser.
|
||||
|
||||
**< ^ v >** are arrow keys, typically for navigating a map, buggy.
|
||||
`Bs` Backspace
|
||||
|
||||
`Rt` Return / enter
|
||||
|
||||
### UI Customization
|
||||
|
||||
WRP supports customizing it's own UI using HTML Template file. Download [wrp.html](wrp.html) place in the same directory with wrp binary customize it to your liking.
|
||||
|
||||
## Docker
|
||||
|
||||
https://hub.docker.com/r/tenox7/wrp
|
||||
|
||||
```shell
|
||||
$ docker run -d --rm -p 8080:8080 tenox7/wrp:latest
|
||||
```
|
||||
|
||||
## AWS
|
||||
|
||||
It's possible to run WRP on AWS App Runner.
|
||||
|
||||
First you need to upload the Docker image to ECR - [Instructions](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html).
|
||||
|
||||
Create App Runner service using the uploaded image using the AWS Console or CLI.
|
||||
|
||||
[AWS Console](https://console.aws.amazon.com/apprunner/home#/create)
|
||||
|
||||
```shell
|
||||
aws apprunner create-service --service-name my-app-runner-service --source-configuration '{
|
||||
"ImageRepository": {
|
||||
"ImageIdentifier": "<account_id>.dkr.ecr.<region>.amazonaws.com/wrp:latest",
|
||||
"ImageRepositoryType": "ECR",
|
||||
"ImageConfiguration": {"Port": "8000"},
|
||||
"AutoDeploymentsEnabled": true
|
||||
}
|
||||
}' --instance-configuration '{
|
||||
"Cpu": "1024",
|
||||
"Memory": "2048",
|
||||
"InstanceRoleArn": "arn:aws:iam::<account_id>:role/AppRunnerECRAccessRole"
|
||||
}'
|
||||
```
|
||||
|
||||
## Azure Container Instances
|
||||
|
||||
[Azure Console](https://portal.azure.com/#create/Microsoft.ContainerInstances)
|
||||
|
||||
CLI:
|
||||
|
||||
```shell
|
||||
$ az container create --resource-group wrp --name wrp --image tenox7/wrp:latest --cpu 1 --memory 2 --ports 80 --protocol tcp --os-type Linux --ip-address Public --command-line '/wrp -l :80 -t png -g 1280x0x256'
|
||||
```
|
||||
|
||||
## Google Cloud Run
|
||||
|
||||
```shell
|
||||
$ gcloud run deploy --platform managed --image=tenox7/wrp:latest --memory=2Gi --args='-t=png','-g=1280x0x256'
|
||||
```
|
||||
|
||||
Unfortunately Google Cloud Run forces you to use HTTPS, which likely won't work with old browsers.
|
||||
|
||||
|
||||
## Flags
|
||||
|
||||
```text
|
||||
-l listen address:port (default :8080)
|
||||
-m mode, either ismap (graphical) or html
|
||||
-t image type gif, png or jpg (default gif)
|
||||
-g image geometry, WxHxC, height can be 0 for unlimited (default 1152x600x216)
|
||||
C (number of colors) is only used for GIF
|
||||
-q Jpeg image quality, default 75%
|
||||
-h headless mode, hide browser window on the server (default true)
|
||||
-n do not free maps and images after use (default false)
|
||||
-ui html template file (default "wrp.html")
|
||||
-ua user agent, override the default "headless" agent (only for ismap mode)
|
||||
-s delay/sleep after page is rendered before screenshot is taken (default 2s)
|
||||
-b browser executable path (e.g., for Brave Browser)
|
||||
```
|
||||
|
||||
## Minimal Requirements
|
||||
|
||||
* Server/Gateway requires modern hardware and operating system that is supported by [Go language](https://github.com/golang/go/wiki/MinimumRequirements) and Chrome/Chromium Browser, which must be installed.
|
||||
* Client Browser needs to support `HTML FORMs` and `ISMAP`. Typically [Mosaic 2.0](http://www.ncsa.illinois.edu/enabling/mosaic/versions) would be minimum version for forms. However ISMAP was supported since 0.6B, so if you manually enter url using `?url=...`, you can use the earlier version.
|
||||
|
||||
## Troubleshooting
|
||||
## FAQ
|
||||
|
||||
### I can't get it to run
|
||||
|
||||
This program does not have a GUI and is run from the command line. You may need to enable executable bit on Unix systems, for example:
|
||||
This program does not have a GUI and is run from the command line. After downloading, you may need to enable executable bit on Unix systems, for example:
|
||||
|
||||
```bash
|
||||
```shell
|
||||
$ cd ~/Downloads
|
||||
$ chmod +x wrp-amd64-macos
|
||||
$ ./wrp-amd64-macos -t png
|
||||
$ ./wrp-amd64-macos
|
||||
```
|
||||
|
||||
### Pages are chopped off
|
||||
|
||||
Click `st` to re-capture screenshot. You may want to increase the page delay using `-s` flag.
|
||||
|
||||
### Websites are blocking headless browsers
|
||||
|
||||
This is a well known issue. WRP has some provisions to work around it, but it's a cat and mouse game. By default WRP tries to obtain some current valid User Agent from https://github.com/jnrbsn/user-agents rather than using the internal "HeadlessChrome". You can override this to your own, for example:
|
||||
|
||||
```shell
|
||||
$ wrp -ua="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
|
||||
```
|
||||
|
||||
### Why isn't there a Docker image for armv6
|
||||
|
||||
Because https://hub.docker.com/r/chromedp/headless-shell/ doesn't have one. WRP uses that image. If you have a fork that builds for armv6 let me know.
|
||||
|
||||
### WTF is GIP image format
|
||||
|
||||
It's just GIF but optimized. Avoids dithering, uses fast color palette and parallel encoding. https://github.com/tenox7/gip
|
||||
|
||||
## History
|
||||
|
||||
* Version 1.0 (2014) started as a *cgi-bin* script, adaptation of `webkit2png.py` and `pcidade.py`, [blog post](https://virtuallyfun.com/2014/03/03/surfing-modern-web-with-ancient-browsers/).
|
||||
* Version 2.0 became a stand alone http-proxy server, supporting both Linux and MacOS, [another post](https://virtuallyfun.com/wordpress/2014/03/11/web-rendering-proxy-update//).
|
||||
* In 2016 thanks to EFF/Certbot the whole internet migrated to HTTPS/SSL/TLS and WRP largely stopped working. Python code became unmaintainable and there was no easy way to make it work on Windows, even under WSL.
|
||||
* In 2016 thanks to [Let's Encrypt](https://en.wikipedia.org/wiki/Let%27s_Encrypt) the whole internet migrated to HTTPS/SSL/TLS and WRP largely stopped working. Python code became unmaintainable and there was no easy way to make it work on Windows, even under WSL.
|
||||
* Version 3.0 (2019) has been rewritten in [Go](https://golang.org/) using [Chromedp](https://github.com/chromedp) as browser-in-browser instead of http-proxy. The initial version was [less than 100 lines of code](https://gist.github.com/tenox7/b0f03c039b0a8b67f6c1bf47e2dd0df0).
|
||||
* Version 4.0 has been completely refactored to use mouse clicks via imagemap instead parsing a href nodes.
|
||||
* Version 4.1 added sending keystrokes in to input boxes. You can now login to Gmail. Also now runs as a Docker container and on Cloud Run/Azure Containers.
|
||||
* Version 4.0 has been completely refactored to use mouse clicks via imagemap instead parsing a href nodes.
|
||||
* Version 4.1 added sending keystrokes in to input boxes. You can now login to Gmail. Also now runs as a Docker container and on Cloud Run/Azure Containers.
|
||||
* Version 4.5 introduces rendering whole pages in to a single tall image with client scrolling.
|
||||
* Version 4.6 adds blazing fast gif encoding by [Hill Ma](https://github.com/mahiuchun).
|
||||
* Version 4.6.3 adds arm64 / aarch64 Docker container support - you can run it on Raspberry PI!
|
||||
* Version 4.7 add simple html aka reader aka text mode.
|
||||
* Version 4.8 add image support to simple html mode.
|
||||
* Version 4.9 adds support for ultra fast, parallel encoded gif image (GIP)
|
||||
* Version 4.10 re-adds support for http proxy mode
|
||||
|
||||
## Credits
|
||||
|
||||
@@ -126,10 +221,22 @@ $ ./wrp-amd64-macos -t png
|
||||
* Uses [go-quantize](https://github.com/ericpauley/go-quantize), thanks to [ericpauley](https://github.com/ericpauley) for developing the missing go quantizer
|
||||
* Thanks to Jason Stevens of [Fun With Virtualization](https://virtuallyfun.com/) for graciously hosting my rumblings
|
||||
* Thanks to [claunia](https://github.com/claunia/) for help with the Python/Webkit version in the past
|
||||
* Thanks to [Hill Ma](https://github.com/mahiuchun) for ultra fast gif encoding algorithm
|
||||
* Historical Python/Webkit versions and prior art can be seen in [wrp-old](https://github.com/tenox7/wrp-old) repo
|
||||
|
||||
## Related
|
||||
|
||||
You may also be interested in:
|
||||
|
||||
* [VncFox](https://github.com/tenox7/vncfox)
|
||||
* [webone](https://github.com/atauenis/webone)
|
||||
* [Pici Server](https://github.com/picidae-project/pici-server)
|
||||
* [Browservice](https://github.com/ttalvitie/browservice)
|
||||
* [Browsh](https://github.com/browsh-org/browsh)
|
||||
|
||||
## Legal Stuff
|
||||
|
||||
License: Apache 2.0
|
||||
Copyright (c) 2013-2018 Antoni Sawicki
|
||||
Copyright (c) 2019-2020 Google LLC
|
||||
```text
|
||||
License: Apache 2.0
|
||||
Copyright (c) 2013-2026 Antoni Sawicki
|
||||
```
|
||||
|
||||
167
download.go
Normal file
167
download.go
Normal file
@@ -0,0 +1,167 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/cdproto/browser"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/lithammer/shortuuid/v4"
|
||||
)
|
||||
|
||||
var (
|
||||
dlDir string
|
||||
dlNotify = make(chan struct{}, 1)
|
||||
)
|
||||
|
||||
type dlEvent struct {
|
||||
guid string
|
||||
filename string
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
var dlTrack struct {
|
||||
sync.Mutex
|
||||
ev *dlEvent
|
||||
}
|
||||
|
||||
type dlFile struct {
|
||||
name string
|
||||
data []byte
|
||||
}
|
||||
|
||||
var dlCache struct {
|
||||
sync.Mutex
|
||||
files map[string]dlFile
|
||||
}
|
||||
|
||||
func setupDownloads() {
|
||||
if dlDir == "" {
|
||||
var err error
|
||||
dlDir, err = os.MkdirTemp("", "wrp-dl-")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create download dir: %v", err)
|
||||
}
|
||||
dlCache.files = make(map[string]dlFile)
|
||||
}
|
||||
chromedp.ListenTarget(ctx, func(ev interface{}) {
|
||||
switch e := ev.(type) {
|
||||
case *browser.EventDownloadWillBegin:
|
||||
log.Printf("Download started: %s (%s)", e.SuggestedFilename, e.GUID)
|
||||
dlTrack.Lock()
|
||||
dlTrack.ev = &dlEvent{
|
||||
guid: e.GUID,
|
||||
filename: e.SuggestedFilename,
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
dlTrack.Unlock()
|
||||
select {
|
||||
case dlNotify <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
case *browser.EventDownloadProgress:
|
||||
dlTrack.Lock()
|
||||
ev := dlTrack.ev
|
||||
dlTrack.Unlock()
|
||||
if ev == nil || ev.guid != e.GUID {
|
||||
return
|
||||
}
|
||||
if e.State == browser.DownloadProgressStateCompleted || e.State == browser.DownloadProgressStateCanceled {
|
||||
log.Printf("Download %s: %s", e.State, e.GUID)
|
||||
close(ev.done)
|
||||
}
|
||||
}
|
||||
})
|
||||
err := chromedp.Run(ctx,
|
||||
browser.SetDownloadBehavior(browser.SetDownloadBehaviorBehaviorAllowAndName).
|
||||
WithDownloadPath(dlDir).
|
||||
WithEventsEnabled(true),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("Warning: failed to set download behavior: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func resetDownloadState() {
|
||||
dlTrack.Lock()
|
||||
dlTrack.ev = nil
|
||||
dlTrack.Unlock()
|
||||
select {
|
||||
case <-dlNotify:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func waitForDownload() *dlFile {
|
||||
select {
|
||||
case <-dlNotify:
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
return nil
|
||||
}
|
||||
dlTrack.Lock()
|
||||
ev := dlTrack.ev
|
||||
dlTrack.Unlock()
|
||||
if ev == nil {
|
||||
return nil
|
||||
}
|
||||
log.Printf("Waiting for download: %s", ev.filename)
|
||||
select {
|
||||
case <-ev.done:
|
||||
case <-time.After(60 * time.Second):
|
||||
log.Printf("Download timed out: %s", ev.guid)
|
||||
dlTrack.Lock()
|
||||
dlTrack.ev = nil
|
||||
dlTrack.Unlock()
|
||||
return nil
|
||||
}
|
||||
fpath := filepath.Join(dlDir, ev.guid)
|
||||
data, err := os.ReadFile(fpath)
|
||||
dlTrack.Lock()
|
||||
dlTrack.ev = nil
|
||||
dlTrack.Unlock()
|
||||
if err != nil {
|
||||
log.Printf("Failed to read download %s: %v", fpath, err)
|
||||
return nil
|
||||
}
|
||||
os.Remove(fpath)
|
||||
return &dlFile{name: ev.filename, data: data}
|
||||
}
|
||||
|
||||
func cacheDownload(f *dlFile) string {
|
||||
id := shortuuid.New()
|
||||
dlCache.Lock()
|
||||
dlCache.files[id] = *f
|
||||
dlCache.Unlock()
|
||||
log.Printf("Download cached: /dl/%s (%s, %d bytes)", id, f.name, len(f.data))
|
||||
return "/dl/" + id
|
||||
}
|
||||
|
||||
func writeDownload(w http.ResponseWriter, f *dlFile) {
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, f.name))
|
||||
w.Header().Set("Content-Type", http.DetectContentType(f.data))
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(f.data)))
|
||||
w.Write(f.data)
|
||||
w.(http.Flusher).Flush()
|
||||
log.Printf("Download served inline: %s (%d bytes)", f.name, len(f.data))
|
||||
}
|
||||
|
||||
func dlServer(w http.ResponseWriter, r *http.Request) {
|
||||
id := strings.TrimPrefix(r.URL.Path, "/dl/")
|
||||
log.Printf("%s Download request for %s", r.RemoteAddr, id)
|
||||
dlCache.Lock()
|
||||
f, ok := dlCache.files[id]
|
||||
delete(dlCache.files, id)
|
||||
dlCache.Unlock()
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
writeDownload(w, &f)
|
||||
}
|
||||
28
go.mod
28
go.mod
@@ -1,11 +1,31 @@
|
||||
module github.com/tenox7/wrp
|
||||
|
||||
go 1.16
|
||||
go 1.26
|
||||
|
||||
require (
|
||||
github.com/MaxHalford/halfgone v0.0.0-20171017091812-482157b86ccb
|
||||
github.com/chromedp/cdproto v0.0.0-20221029224954-108014bf7279
|
||||
github.com/chromedp/chromedp v0.8.6
|
||||
github.com/PuerkitoBio/goquery v1.12.0
|
||||
github.com/breml/rootcerts v0.3.5
|
||||
github.com/chromedp/cdproto v0.0.0-20260405000525-47a8ff65b46a
|
||||
github.com/chromedp/chromedp v0.15.1
|
||||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4
|
||||
golang.org/x/sys v0.1.0 // indirect
|
||||
github.com/lithammer/shortuuid/v4 v4.2.0
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef
|
||||
github.com/tenox7/gip v1.0.2
|
||||
golang.org/x/image v0.39.0
|
||||
golang.org/x/net v0.53.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||
github.com/chromedp/sysutil v1.1.0 // indirect
|
||||
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 // indirect
|
||||
github.com/gobwas/httphead v0.1.0 // indirect
|
||||
github.com/gobwas/pool v0.2.1 // indirect
|
||||
github.com/gobwas/ws v1.4.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
golang.org/x/sys v0.43.0 // indirect
|
||||
golang.org/x/text v0.36.0 // indirect
|
||||
)
|
||||
|
||||
119
go.sum
119
go.sum
@@ -1,29 +1,114 @@
|
||||
github.com/MaxHalford/halfgone v0.0.0-20171017091812-482157b86ccb h1:YQ+d0g0P0F/06oDoeEgDHeZCIrnKgLxXcqYOpe8sTuU=
|
||||
github.com/MaxHalford/halfgone v0.0.0-20171017091812-482157b86ccb/go.mod h1:J86XzS1wgzJPjpQmpriJ+SetP17JSQUd9l+HWQK86jA=
|
||||
github.com/chromedp/cdproto v0.0.0-20220924210414-0e3390be1777/go.mod h1:5Y4sD/eXpwrChIuxhSr/G20n9CdbCmoerOHnuAf0Zr0=
|
||||
github.com/chromedp/cdproto v0.0.0-20221029224954-108014bf7279 h1:7+D/pA8BoNzTpcM0Yw8issS95U/ipn0im5vzhfPzDZc=
|
||||
github.com/chromedp/cdproto v0.0.0-20221029224954-108014bf7279/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
|
||||
github.com/chromedp/chromedp v0.8.6 h1:KobeeqR2dpfKSG1prS3Y6+FbffMmGC6xmAobRXA9QEQ=
|
||||
github.com/chromedp/chromedp v0.8.6/go.mod h1:nBYHoD6YSNzrr82cIeuOzhw1Jo/s2o0QQ+ifTeoCZ+c=
|
||||
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
|
||||
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
|
||||
github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO8RIBo=
|
||||
github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ=
|
||||
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
||||
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
||||
github.com/breml/rootcerts v0.3.5 h1:oi7YiZ25HH52+mrKyjrMkcAFfnRDUf6HO8aUDr7RlJI=
|
||||
github.com/breml/rootcerts v0.3.5/go.mod h1:S/PKh+4d1HUn4HQovEB8hPJZO6pUZYrIhmXBhsegfXw=
|
||||
github.com/chromedp/cdproto v0.0.0-20260405000525-47a8ff65b46a h1:Kk4P1W58eAf+OUGtx51cM7CcJokJuBEmOxxwPdHFH4Q=
|
||||
github.com/chromedp/cdproto v0.0.0-20260405000525-47a8ff65b46a/go.mod h1:cbyjALe67vDvlvdiG9369P8w5U2w6IshwtyD2f2Tvag=
|
||||
github.com/chromedp/chromedp v0.15.1 h1:EJWiPm7BNqDqjYy6U0lTSL5wNH+iNt9GjC3a4gfjNyQ=
|
||||
github.com/chromedp/chromedp v0.15.1/go.mod h1:CdTHtUqD/dqaFw/cvFWtTydoEQS44wLBuwbMR9EkOY4=
|
||||
github.com/chromedp/sysutil v1.1.0 h1:PUFNv5EcprjqXZD9nJb9b/c9ibAbxiYo4exNWZyipwM=
|
||||
github.com/chromedp/sysutil v1.1.0/go.mod h1:WiThHUdltqCNKGc4gaU50XgYjwjYIhKWoHGPTUfWTJ8=
|
||||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 h1:BBade+JlV/f7JstZ4pitd4tHhpN+w+6I+LyOS7B4fyU=
|
||||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM=
|
||||
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao=
|
||||
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
||||
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||
github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA=
|
||||
github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
||||
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
|
||||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/lithammer/shortuuid/v4 v4.2.0 h1:LMFOzVB3996a7b8aBuEXxqOBflbfPQAiVzkIcHO0h8c=
|
||||
github.com/lithammer/shortuuid/v4 v4.2.0/go.mod h1:D5noHZ2oFw/YaKCfGy0YxyE7M0wMbezmMjPdhyEFe6Y=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
|
||||
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
|
||||
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE=
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ=
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
|
||||
github.com/tenox7/gip v1.0.2 h1:VQcaQub/bKu87pQZ1PxeSJPcRWpPRcpIGwP70w6ovQ8=
|
||||
github.com/tenox7/gip v1.0.2/go.mod h1:MR/eaUKjLGkYIguDcAUrWyxG58ipjjCrzM92jwGqDno=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/image v0.39.0 h1:skVYidAEVKgn8lZ602XO75asgXBgLj9G/FE3RbuPFww=
|
||||
golang.org/x/image v0.39.0/go.mod h1:sIbmppfU+xFLPIG0FoVUTvyBMmgng1/XAMhQ2ft0hpA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
|
||||
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
|
||||
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
|
||||
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
436
ismap.go
Normal file
436
ismap.go
Normal file
@@ -0,0 +1,436 @@
|
||||
// WRP ISMAP / ChromeDP routines
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/cdproto/emulation"
|
||||
"github.com/chromedp/cdproto/input"
|
||||
"github.com/chromedp/cdproto/page"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/lithammer/shortuuid/v4"
|
||||
"github.com/tenox7/gip"
|
||||
)
|
||||
|
||||
type cachedImg struct {
|
||||
buf bytes.Buffer
|
||||
}
|
||||
|
||||
type cachedMap struct {
|
||||
req wrpReq
|
||||
}
|
||||
|
||||
type wrpCache struct {
|
||||
sync.Mutex
|
||||
imgs map[string]cachedImg
|
||||
maps map[string]cachedMap
|
||||
}
|
||||
|
||||
func (c *wrpCache) addImg(path string, buf bytes.Buffer) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.imgs[path] = cachedImg{buf: buf}
|
||||
}
|
||||
|
||||
func (c *wrpCache) getImg(path string) (bytes.Buffer, bool) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
e, ok := c.imgs[path]
|
||||
if !ok {
|
||||
return bytes.Buffer{}, false
|
||||
}
|
||||
return e.buf, true
|
||||
}
|
||||
|
||||
func (c *wrpCache) addMap(path string, req wrpReq) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.maps[path] = cachedMap{req: req}
|
||||
}
|
||||
|
||||
func (c *wrpCache) getMap(path string) (wrpReq, bool) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
e, ok := c.maps[path]
|
||||
if !ok {
|
||||
return wrpReq{}, false
|
||||
}
|
||||
return e.req, true
|
||||
}
|
||||
|
||||
func (c *wrpCache) clear() {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.imgs = make(map[string]cachedImg)
|
||||
c.maps = make(map[string]cachedMap)
|
||||
}
|
||||
|
||||
func chromedpStart() (context.CancelFunc, context.CancelFunc) {
|
||||
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||
chromedp.Flag("headless", *headless),
|
||||
chromedp.Flag("hide-scrollbars", false),
|
||||
chromedp.Flag("enable-automation", false),
|
||||
chromedp.Flag("disable-blink-features", "AutomationControlled"),
|
||||
)
|
||||
if *userAgent == "jnrbsn" {
|
||||
if ua := fetchJnrbsnUserAgent(); ua != "" {
|
||||
*userAgent = ua
|
||||
}
|
||||
}
|
||||
if *userAgent != "" {
|
||||
opts = append(opts, chromedp.UserAgent(*userAgent))
|
||||
}
|
||||
if *browserPath == "" {
|
||||
*browserPath = findBrowser()
|
||||
}
|
||||
if *browserPath != "" {
|
||||
log.Printf("Using browser: %s", *browserPath)
|
||||
opts = append(opts, chromedp.ExecPath(*browserPath))
|
||||
} else {
|
||||
log.Printf("No browser detected, falling back to chromedp default lookup")
|
||||
}
|
||||
if *userDataDir != "" {
|
||||
opts = append(opts, chromedp.UserDataDir(*userDataDir))
|
||||
}
|
||||
actx, acncl = chromedp.NewExecAllocator(context.Background(), opts...)
|
||||
ctx, cncl = chromedp.NewContext(actx)
|
||||
return cncl, acncl
|
||||
}
|
||||
|
||||
// Determine what action to take
|
||||
func (rq *wrpReq) action() chromedp.Action {
|
||||
// Mouse Click
|
||||
if rq.mouseX > 0 && rq.mouseY > 0 {
|
||||
log.Printf("%s Mouse Click %d,%d\n", rq.r.RemoteAddr, rq.mouseX, rq.mouseY)
|
||||
return chromedp.MouseClickXY(float64(rq.mouseX)/float64(rq.zoom), float64(rq.mouseY)/float64(rq.zoom))
|
||||
}
|
||||
// Buttons
|
||||
if len(rq.buttons) > 0 {
|
||||
log.Printf("%s Button %v\n", rq.r.RemoteAddr, rq.buttons)
|
||||
switch rq.buttons {
|
||||
case "Bk":
|
||||
return chromedp.NavigateBack()
|
||||
case "St":
|
||||
return chromedp.Stop()
|
||||
case "Re":
|
||||
return chromedp.Reload()
|
||||
case "Bs":
|
||||
return chromedp.KeyEvent("\b")
|
||||
case "Rt":
|
||||
return chromedp.KeyEvent("\r")
|
||||
case "<":
|
||||
return chromedp.KeyEvent("\u0302")
|
||||
case "^":
|
||||
return chromedp.KeyEvent("\u0304")
|
||||
case "v":
|
||||
return chromedp.KeyEvent("\u0301")
|
||||
case ">":
|
||||
return chromedp.KeyEvent("\u0303")
|
||||
case "Up":
|
||||
return chromedp.KeyEvent("\u0308")
|
||||
case "Dn":
|
||||
return chromedp.KeyEvent("\u0307")
|
||||
case "All": // Select all
|
||||
return chromedp.KeyEvent("a", chromedp.KeyModifiers(input.ModifierCtrl))
|
||||
}
|
||||
}
|
||||
// Keys
|
||||
if len(rq.keys) > 0 {
|
||||
log.Printf("%s Sending Keys: %#v\n", rq.r.RemoteAddr, rq.keys)
|
||||
return chromedp.KeyEvent(rq.keys)
|
||||
}
|
||||
// Navigate to URL
|
||||
log.Printf("%s Processing Navigate Request for %s\n", rq.r.RemoteAddr, rq.url)
|
||||
return chromedp.Navigate(rq.url)
|
||||
}
|
||||
|
||||
// Navigate to the desired URL, returns the downloaded file if one was triggered.
|
||||
func (rq *wrpReq) navigate() *dlFile {
|
||||
resetDownloadState()
|
||||
ctxErr(chromedp.Run(ctx, rq.action()), rq.w)
|
||||
return waitForDownload()
|
||||
}
|
||||
|
||||
// Handle context errors
|
||||
func ctxErr(err error, w io.Writer) {
|
||||
// TODO: callers should have retry logic, perhaps create another function
|
||||
// that takes ...chromedp.Action and retries with give up
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
log.Printf("Context error: %s", err)
|
||||
fmt.Fprintf(w, "Context error: %s<BR>\n", err)
|
||||
if err.Error() != "context canceled" {
|
||||
return
|
||||
}
|
||||
ctx, cncl = chromedp.NewContext(actx)
|
||||
setupDownloads()
|
||||
log.Printf("Created new context, try again")
|
||||
fmt.Fprintln(w, "Created new context, try again")
|
||||
}
|
||||
|
||||
func waitForRender() chromedp.ActionFunc {
|
||||
return func(ctx context.Context) error {
|
||||
timeout := *delay
|
||||
if timeout > 5*time.Second {
|
||||
timeout = 5 * time.Second
|
||||
}
|
||||
ch := make(chan struct{}, 1)
|
||||
lctx, lcancel := context.WithCancel(ctx)
|
||||
defer lcancel()
|
||||
chromedp.ListenTarget(lctx, func(ev interface{}) {
|
||||
if e, ok := ev.(*page.EventLifecycleEvent); ok && e.Name == "networkAlmostIdle" {
|
||||
select {
|
||||
case ch <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
})
|
||||
deadline := time.Now().Add(timeout)
|
||||
for time.Now().Before(deadline) {
|
||||
select {
|
||||
case <-ch:
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
var ready bool
|
||||
if err := chromedp.Evaluate(
|
||||
`document.readyState === "complete" && Array.from(document.images).every(i => i.complete)`,
|
||||
&ready,
|
||||
).Do(ctx); err != nil {
|
||||
return nil
|
||||
}
|
||||
if ready {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/chromedp/chromedp/issues/979
|
||||
func chromedpCaptureScreenshot(res *[]byte, h int64) chromedp.Action {
|
||||
if res == nil {
|
||||
panic("res cannot be nil") // TODO: do not panic here, return error
|
||||
}
|
||||
if h == 0 {
|
||||
return chromedp.CaptureScreenshot(res)
|
||||
}
|
||||
|
||||
return chromedp.ActionFunc(func(ctx context.Context) error {
|
||||
var err error
|
||||
*res, err = page.CaptureScreenshot().Do(ctx)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
// Capture Screenshot using CDP
|
||||
func (rq *wrpReq) captureScreenshot() {
|
||||
wrpCach.clear()
|
||||
var h int64
|
||||
var pngCap []byte
|
||||
chromedp.Run(ctx,
|
||||
emulation.SetDeviceMetricsOverride(int64(float64(rq.width)/rq.zoom), 10, rq.zoom, false),
|
||||
chromedp.Location(&rq.url),
|
||||
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||
_, _, _, _, _, s, err := page.GetLayoutMetrics().Do(ctx)
|
||||
if err == nil {
|
||||
h = int64(math.Ceil(s.Height))
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if rq.proxy {
|
||||
rq.url = strings.Replace(rq.url, "https://", "http://", 1)
|
||||
}
|
||||
log.Printf("%s Landed on: %s, Height: %v\n", rq.r.RemoteAddr, rq.url, h)
|
||||
height := int64(float64(rq.height) / rq.zoom)
|
||||
if rq.height == 0 && h > 0 {
|
||||
height = h + 30
|
||||
}
|
||||
chromedp.Run(
|
||||
ctx, emulation.SetDeviceMetricsOverride(int64(float64(rq.width)/rq.zoom), height, rq.zoom, false),
|
||||
waitForRender(),
|
||||
)
|
||||
// Capture screenshot...
|
||||
ctxErr(chromedp.Run(ctx, chromedpCaptureScreenshot(&pngCap, rq.height)), rq.w)
|
||||
seq := shortuuid.New()
|
||||
var imgExt string
|
||||
if rq.imgType == "gip" {
|
||||
imgExt = "gif"
|
||||
} else {
|
||||
imgExt = rq.imgType
|
||||
}
|
||||
imgPath := fmt.Sprintf("/img/%s.%s", seq, imgExt)
|
||||
mapPath := fmt.Sprintf("/map/%s.map", seq)
|
||||
wrpCach.addMap(mapPath, *rq)
|
||||
var sSize string
|
||||
var iW, iH int
|
||||
switch rq.imgType {
|
||||
case "gip":
|
||||
i, err := png.Decode(bytes.NewReader(pngCap))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode PNG screenshot: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to decode page PNG screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
st := time.Now()
|
||||
var gipBuf bytes.Buffer
|
||||
err = gip.Encode(&gipBuf, i, nil)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode GIP: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to encode GIP:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
wrpCach.addImg(imgPath, gipBuf)
|
||||
sSize = fmt.Sprintf("%.0f KB", float32(len(gipBuf.Bytes()))/1024.0)
|
||||
iW = i.Bounds().Max.X
|
||||
iH = i.Bounds().Max.Y
|
||||
log.Printf("%s Encoded GIP image: %s, Size: %s, Res: %dx%d, Time: %vms\n", rq.r.RemoteAddr, imgPath, sSize, iW, iH, time.Since(st).Milliseconds())
|
||||
case "png":
|
||||
pngBuf := bytes.NewBuffer(pngCap)
|
||||
wrpCach.addImg(imgPath, *pngBuf)
|
||||
cfg, _, _ := image.DecodeConfig(pngBuf)
|
||||
sSize = fmt.Sprintf("%.0f KB", float32(len(pngBuf.Bytes()))/1024.0)
|
||||
iW = cfg.Width
|
||||
iH = cfg.Height
|
||||
log.Printf("%s Got PNG image: %s, Size: %s, Res: %dx%d\n", rq.r.RemoteAddr, imgPath, sSize, iW, iH)
|
||||
case "gif":
|
||||
i, err := png.Decode(bytes.NewReader(pngCap))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode PNG screenshot: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to decode page PNG screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
st := time.Now()
|
||||
var gifBuf bytes.Buffer
|
||||
err = gif.Encode(&gifBuf, gifPalette(i, rq.nColors), &gif.Options{})
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode GIF: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to encode GIF:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
wrpCach.addImg(imgPath, gifBuf)
|
||||
sSize = fmt.Sprintf("%.0f KB", float32(len(gifBuf.Bytes()))/1024.0)
|
||||
iW = i.Bounds().Max.X
|
||||
iH = i.Bounds().Max.Y
|
||||
log.Printf("%s Encoded GIF image: %s, Size: %s, Colors: %d, Res: %dx%d, Time: %vms\n", rq.r.RemoteAddr, imgPath, sSize, rq.nColors, iW, iH, time.Since(st).Milliseconds())
|
||||
case "jpg":
|
||||
i, err := png.Decode(bytes.NewReader(pngCap))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode PNG screenshot: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to decode page PNG screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
st := time.Now()
|
||||
var jpgBuf bytes.Buffer
|
||||
err = jpeg.Encode(&jpgBuf, i, &jpeg.Options{Quality: int(rq.jQual)})
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode JPG: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to encode JPG:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
wrpCach.addImg(imgPath, jpgBuf)
|
||||
sSize = fmt.Sprintf("%.0f KB", float32(len(jpgBuf.Bytes()))/1024.0)
|
||||
iW = i.Bounds().Max.X
|
||||
iH = i.Bounds().Max.Y
|
||||
log.Printf("%s Encoded JPG image: %s, Size: %s, Quality: %d, Res: %dx%d, Time: %vms\n", rq.r.RemoteAddr, imgPath, sSize, *defJpgQual, iW, iH, time.Since(st).Milliseconds())
|
||||
}
|
||||
if rq.proxy {
|
||||
rq.w.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(rq.w, "<HTML><HEAD>%s<TITLE>%s</TITLE></HEAD><BODY BGCOLOR=\"%s\">"+
|
||||
"<A HREF=\"%s\"><IMG SRC=\"%s\" BORDER=\"0\" WIDTH=\"%d\" HEIGHT=\"%d\" ISMAP></A>"+
|
||||
"</BODY></HTML>", rq.baseTag(), rq.url, *bgColor, mapPath, imgPath, iW, iH)
|
||||
} else {
|
||||
rq.printUI(uiParams{
|
||||
bgColor: *bgColor,
|
||||
pageHeight: fmt.Sprintf("%d PX", h),
|
||||
imgSize: sSize,
|
||||
imgURL: imgPath,
|
||||
mapURL: mapPath,
|
||||
imgWidth: iW,
|
||||
imgHeight: iH,
|
||||
})
|
||||
}
|
||||
log.Printf("%s Done with capture for %s\n", rq.r.RemoteAddr, rq.url)
|
||||
}
|
||||
|
||||
func mapServer(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s ISMAP Request for %s [%+v]\n", r.RemoteAddr, r.URL.Path, r.URL.RawQuery)
|
||||
rq, ok := wrpCach.getMap(r.URL.Path)
|
||||
rq.r = r
|
||||
rq.w = w
|
||||
if !ok {
|
||||
fmt.Fprintf(w, "Unable to find map %s\n", r.URL.Path)
|
||||
log.Printf("Unable to find map %s\n", r.URL.Path)
|
||||
return
|
||||
}
|
||||
n, err := fmt.Sscanf(r.URL.RawQuery, "%d,%d", &rq.mouseX, &rq.mouseY)
|
||||
if err != nil || n != 2 {
|
||||
fmt.Fprintf(w, "n=%d, err=%s\n", n, err)
|
||||
log.Printf("%s ISMAP n=%d, err=%s\n", r.RemoteAddr, n, err)
|
||||
return
|
||||
}
|
||||
log.Printf("%s WrpReq from ISMAP: %+v\n", r.RemoteAddr, rq)
|
||||
if len(rq.url) < 4 {
|
||||
rq.printUI(uiParams{})
|
||||
return
|
||||
}
|
||||
if dl := rq.navigate(); dl != nil {
|
||||
if rq.proxy {
|
||||
writeDownload(w, dl)
|
||||
} else {
|
||||
http.Redirect(w, r, cacheDownload(dl), http.StatusFound)
|
||||
}
|
||||
return
|
||||
}
|
||||
if rq.proxy {
|
||||
chromedp.Run(ctx, waitForRender())
|
||||
var loc string
|
||||
chromedp.Run(ctx, chromedp.Location(&loc))
|
||||
loc = strings.Replace(loc, "https://", "http://", 1)
|
||||
http.Redirect(w, r, loc, http.StatusFound)
|
||||
return
|
||||
}
|
||||
rq.captureScreenshot()
|
||||
}
|
||||
|
||||
// TODO: merge this with html mode IMGZ
|
||||
func imgServerMap(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s IMG Request for %s\n", r.RemoteAddr, r.URL.Path)
|
||||
imgBuf, ok := wrpCach.getImg(r.URL.Path)
|
||||
if !ok || imgBuf.Bytes() == nil {
|
||||
fmt.Fprintf(w, "Unable to find image %s\n", r.URL.Path)
|
||||
log.Printf("%s Unable to find image %s\n", r.RemoteAddr, r.URL.Path)
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(r.URL.Path, ".gif"):
|
||||
w.Header().Set("Content-Type", "image/gif")
|
||||
case strings.HasSuffix(r.URL.Path, ".png"):
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
case strings.HasSuffix(r.URL.Path, ".jpg"):
|
||||
w.Header().Set("Content-Type", "image/jpeg")
|
||||
}
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(imgBuf.Bytes())))
|
||||
w.Header().Set("Cache-Control", "max-age=0")
|
||||
w.Header().Set("Expires", "-1")
|
||||
w.Header().Set("Pragma", "no-cache")
|
||||
w.Write(imgBuf.Bytes())
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
398
shtml.go
Normal file
398
shtml.go
Normal file
@@ -0,0 +1,398 @@
|
||||
// WRP Simple HTML Mode Routines
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/chromedp/cdproto/emulation"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/lithammer/shortuuid/v4"
|
||||
"github.com/nfnt/resize"
|
||||
"github.com/srwiley/oksvg"
|
||||
"github.com/srwiley/rasterx"
|
||||
"github.com/tenox7/gip"
|
||||
"golang.org/x/image/webp"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
var imgStor imageStore
|
||||
|
||||
const imgZpfx = "/imgz/"
|
||||
|
||||
func init() {
|
||||
imgStor.img = make(map[string]imageContainer)
|
||||
}
|
||||
|
||||
type imageContainer struct {
|
||||
data []byte
|
||||
url string
|
||||
added time.Time
|
||||
}
|
||||
|
||||
type imageStore struct {
|
||||
img map[string]imageContainer
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (i *imageStore) add(id, url string, img []byte) {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
i.img[id] = imageContainer{data: img, url: url, added: time.Now()}
|
||||
}
|
||||
|
||||
func (i *imageStore) get(id string) ([]byte, error) {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
img, ok := i.img[id]
|
||||
if !ok {
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
return img.data, nil
|
||||
}
|
||||
|
||||
func (i *imageStore) del(id string) {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
delete(i.img, id)
|
||||
}
|
||||
|
||||
func (i *imageStore) clear() {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
i.img = make(map[string]imageContainer)
|
||||
}
|
||||
|
||||
func fetchImage(id, imgURL, imgType string, maxSize, imgOpt int) (int, int, int, error) {
|
||||
log.Printf("Downloading IMGZ URL=%q for ID=%q", imgURL, id)
|
||||
var in []byte
|
||||
var err error
|
||||
if len(imgURL) < 4 {
|
||||
return 0, 0, 0, fmt.Errorf("image URL too short: %q", imgURL)
|
||||
}
|
||||
switch imgURL[:4] {
|
||||
case "http":
|
||||
req, err := http.NewRequest("GET", imgURL, nil)
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("Error creating request for %q: %v", imgURL, err)
|
||||
}
|
||||
if *userAgent != "" {
|
||||
req.Header.Set("User-Agent", *userAgent)
|
||||
}
|
||||
r, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("Error downloading %q: %v", imgURL, err)
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return 0, 0, 0, fmt.Errorf("Error %q HTTP Status Code: %v", imgURL, r.StatusCode)
|
||||
}
|
||||
defer r.Body.Close()
|
||||
in, err = io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("Error reading %q: %v", imgURL, err)
|
||||
}
|
||||
case "data":
|
||||
idx := strings.Index(imgURL, ",")
|
||||
if idx < 1 {
|
||||
return 0, 0, 0, fmt.Errorf("image is embeded but unable to find coma: %q", imgURL)
|
||||
}
|
||||
in, err = base64.StdEncoding.DecodeString(imgURL[idx+1:])
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("error decoding image from url embed: %q: %v", imgURL, err)
|
||||
}
|
||||
default:
|
||||
return 0, 0, 0, fmt.Errorf("unsupported image URL scheme: %q", imgURL)
|
||||
}
|
||||
out, w, h, err := smallImg(in, imgType, maxSize, imgOpt)
|
||||
if err != nil {
|
||||
return 0, 0, 0, fmt.Errorf("Error scaling down %q: %v", imgURL, err)
|
||||
}
|
||||
imgStor.add(id, imgURL, out)
|
||||
return len(out), w, h, nil
|
||||
}
|
||||
|
||||
func decodeSVG(src []byte, maxSize int) (image.Image, error) {
|
||||
icon, err := oksvg.ReadIconStream(bytes.NewReader(src))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w, h := int(icon.ViewBox.W), int(icon.ViewBox.H)
|
||||
if w <= 0 || h <= 0 {
|
||||
w, h = maxSize, maxSize
|
||||
}
|
||||
if w > maxSize || h > maxSize {
|
||||
ratio := float64(maxSize) / float64(max(w, h))
|
||||
w = int(float64(w) * ratio)
|
||||
h = int(float64(h) * ratio)
|
||||
}
|
||||
if w <= 0 {
|
||||
w = 1
|
||||
}
|
||||
if h <= 0 {
|
||||
h = 1
|
||||
}
|
||||
icon.SetTarget(0, 0, float64(w), float64(h))
|
||||
rgba := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
icon.Draw(rasterx.NewDasher(w, h, rasterx.NewScannerGV(w, h, rgba, rgba.Bounds())), 1)
|
||||
return rgba, nil
|
||||
}
|
||||
|
||||
func isSVG(src []byte) bool {
|
||||
s := strings.TrimSpace(string(src[:min(len(src), 256)]))
|
||||
return strings.HasPrefix(s, "<svg") || strings.HasPrefix(s, "<?xml")
|
||||
}
|
||||
|
||||
func smallImg(src []byte, imgType string, maxSize, imgOpt int) ([]byte, int, int, error) {
|
||||
t := http.DetectContentType(src)
|
||||
var err error
|
||||
var img image.Image
|
||||
switch {
|
||||
case t == "image/png":
|
||||
img, err = png.Decode(bytes.NewReader(src))
|
||||
case t == "image/gif":
|
||||
img, err = gif.Decode(bytes.NewReader(src))
|
||||
case t == "image/jpeg":
|
||||
img, err = jpeg.Decode(bytes.NewReader(src))
|
||||
case t == "image/webp":
|
||||
img, err = webp.Decode(bytes.NewReader(src))
|
||||
case t == "image/svg+xml", isSVG(src):
|
||||
img, err = decodeSVG(src, maxSize)
|
||||
default:
|
||||
err = errors.New("unknown content type: " + t)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, 0, 0, fmt.Errorf("image decode problem: %v", err)
|
||||
}
|
||||
img = resize.Thumbnail(uint(maxSize), uint(maxSize), img, resize.NearestNeighbor)
|
||||
b := img.Bounds()
|
||||
var outBuf bytes.Buffer
|
||||
switch imgType {
|
||||
case "gip":
|
||||
err = gip.Encode(&outBuf, img, nil)
|
||||
case "png":
|
||||
err = png.Encode(&outBuf, img)
|
||||
case "gif":
|
||||
err = gif.Encode(&outBuf, gifPalette(img, int64(imgOpt)), &gif.Options{})
|
||||
case "jpg":
|
||||
err = jpeg.Encode(&outBuf, img, &jpeg.Options{Quality: imgOpt})
|
||||
}
|
||||
if err != nil {
|
||||
return nil, 0, 0, fmt.Errorf("image encode problem: %v", err)
|
||||
}
|
||||
return outBuf.Bytes(), b.Dx(), b.Dy(), nil
|
||||
}
|
||||
|
||||
var removeElements = []string{
|
||||
"script", "style", "link", "meta", "noscript", "iframe",
|
||||
"svg", "canvas", "video", "audio", "source", "picture",
|
||||
"template", "slot", "dialog", "portal",
|
||||
}
|
||||
|
||||
var renameToDiv = map[string]bool{
|
||||
"section": true, "article": true, "nav": true,
|
||||
"header": true, "footer": true, "aside": true,
|
||||
"main": true, "figure": true, "figcaption": true,
|
||||
"details": true, "summary": true, "hgroup": true,
|
||||
"mark": true, "time": true, "search": true,
|
||||
}
|
||||
|
||||
var keepAttrs = map[string]bool{
|
||||
"href": true, "src": true, "alt": true, "title": true,
|
||||
"width": true, "height": true, "border": true,
|
||||
"cellpadding": true, "cellspacing": true,
|
||||
"bgcolor": true, "background": true,
|
||||
"align": true, "valign": true,
|
||||
"colspan": true, "rowspan": true, "nowrap": true,
|
||||
"name": true, "value": true, "type": true,
|
||||
"action": true, "method": true, "enctype": true,
|
||||
"size": true, "maxlength": true,
|
||||
"checked": true, "selected": true, "multiple": true,
|
||||
"disabled": true, "readonly": true,
|
||||
"placeholder": true, "for": true,
|
||||
"rows": true, "cols": true,
|
||||
"color": true, "face": true,
|
||||
}
|
||||
|
||||
func resolveURL(raw string, base *url.URL) string {
|
||||
if raw == "" {
|
||||
return ""
|
||||
}
|
||||
ref, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return raw
|
||||
}
|
||||
return base.ResolveReference(ref).String()
|
||||
}
|
||||
|
||||
func simplifyDOM(doc *goquery.Document, rq *wrpReq) int {
|
||||
doc.Find(strings.Join(removeElements, ", ")).Remove()
|
||||
|
||||
doc.Find("*").Each(func(i int, s *goquery.Selection) {
|
||||
for _, n := range s.Nodes {
|
||||
if n.Type != html.ElementNode {
|
||||
return
|
||||
}
|
||||
if renameToDiv[n.Data] {
|
||||
n.Data = "div"
|
||||
}
|
||||
var keep []html.Attribute
|
||||
for _, a := range n.Attr {
|
||||
if keepAttrs[a.Key] {
|
||||
keep = append(keep, a)
|
||||
}
|
||||
}
|
||||
n.Attr = keep
|
||||
}
|
||||
})
|
||||
|
||||
imgExt := rq.imgType
|
||||
if imgExt == "gip" {
|
||||
imgExt = "gif"
|
||||
}
|
||||
var imgOpt int
|
||||
switch rq.imgType {
|
||||
case "jpg":
|
||||
imgOpt = int(rq.jQual)
|
||||
case "gif":
|
||||
imgOpt = int(rq.nColors)
|
||||
}
|
||||
baseURL, _ := url.Parse(rq.url)
|
||||
wrpParams := fmt.Sprintf("m=html&t=%s&s=%d", rq.imgType, rq.maxSize)
|
||||
|
||||
doc.Find("a[href]").Each(func(i int, s *goquery.Selection) {
|
||||
href, exists := s.Attr("href")
|
||||
if !exists || href == "" {
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(href, "#") || strings.HasPrefix(href, "javascript:") {
|
||||
return
|
||||
}
|
||||
abs := resolveURL(href, baseURL)
|
||||
if rq.proxy {
|
||||
abs = strings.Replace(abs, "https://", "http://", 1)
|
||||
s.SetAttr("href", abs)
|
||||
} else {
|
||||
s.SetAttr("href", "/?"+wrpParams+"&url="+url.QueryEscape(abs))
|
||||
}
|
||||
})
|
||||
|
||||
type imgJob struct {
|
||||
sel *goquery.Selection
|
||||
seq string
|
||||
abs string
|
||||
}
|
||||
var jobs []imgJob
|
||||
doc.Find("img[src]").Each(func(i int, s *goquery.Selection) {
|
||||
src, exists := s.Attr("src")
|
||||
if !exists || src == "" {
|
||||
s.Remove()
|
||||
return
|
||||
}
|
||||
abs := resolveURL(src, baseURL)
|
||||
seq := shortuuid.New() + "." + imgExt
|
||||
jobs = append(jobs, imgJob{sel: s, seq: seq, abs: abs})
|
||||
})
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
var totSize int
|
||||
for i := range jobs {
|
||||
wg.Add(1)
|
||||
go func(j imgJob) {
|
||||
defer wg.Done()
|
||||
size, w, h, err := fetchImage(j.seq, j.abs, rq.imgType, int(rq.maxSize), imgOpt)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
j.sel.Remove()
|
||||
return
|
||||
}
|
||||
j.sel.SetAttr("src", imgZpfx+j.seq)
|
||||
j.sel.SetAttr("width", strconv.Itoa(w))
|
||||
j.sel.SetAttr("height", strconv.Itoa(h))
|
||||
totSize += size
|
||||
}(jobs[i])
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
return totSize
|
||||
}
|
||||
|
||||
func (rq *wrpReq) captureMarkdown() {
|
||||
imgStor.clear()
|
||||
log.Printf("Processing simple HTML conversion for %v", rq.url)
|
||||
var outerHTML string
|
||||
err := chromedp.Run(ctx,
|
||||
waitForRender(),
|
||||
emulation.SetEmulatedMedia().WithMedia("print"),
|
||||
chromedp.Evaluate(`(function(){document.querySelectorAll('*').forEach(function(e){if(getComputedStyle(e).display==='none')e.remove()})})()`, nil),
|
||||
chromedp.OuterHTML("html", &outerHTML, chromedp.ByQuery),
|
||||
emulation.SetEmulatedMedia().WithMedia(""),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("Failed to get OuterHTML via CDP: %v", err)
|
||||
http.Error(rq.w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Printf("Got %v bytes HTML from CDP for %v", len(outerHTML), rq.url)
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(outerHTML))
|
||||
if err != nil {
|
||||
log.Printf("Failed to parse HTML: %v", err)
|
||||
http.Error(rq.w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
totSize := simplifyDOM(doc, rq)
|
||||
|
||||
body := doc.Find("body")
|
||||
simplified, err := body.Html()
|
||||
if err != nil {
|
||||
http.Error(rq.w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Printf("Simplified to %v bytes html for %v", len(simplified), rq.url)
|
||||
|
||||
if rq.proxy {
|
||||
rq.w.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(rq.w, "<HTML><HEAD>%s<TITLE>%s</TITLE></HEAD><BODY BGCOLOR=\"%s\">%s</BODY></HTML>",
|
||||
rq.baseTag(), rq.url, *bgColor, string(asciify([]byte(simplified))))
|
||||
return
|
||||
}
|
||||
rq.printUI(uiParams{
|
||||
text: string(asciify([]byte(simplified))),
|
||||
bgColor: *bgColor,
|
||||
imgSize: fmt.Sprintf("%.0f KB", float32(totSize)/1024.0),
|
||||
})
|
||||
}
|
||||
|
||||
func imgServerTxt(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s IMGZ Request for %s", r.RemoteAddr, r.URL.Path)
|
||||
id := strings.Replace(r.URL.Path, imgZpfx, "", 1)
|
||||
img, err := imgStor.get(id)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
log.Printf("%s IMGZ error for %s: %v", r.RemoteAddr, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", http.DetectContentType(img))
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(img)))
|
||||
w.Write(img)
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
172
util.go
Normal file
172
util.go
Normal file
@@ -0,0 +1,172 @@
|
||||
// wrp utility functions
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/MaxHalford/halfgone"
|
||||
"github.com/ericpauley/go-quantize/quantize"
|
||||
)
|
||||
|
||||
func printMyIPs(b string) {
|
||||
ap := strings.Split(b, ":")
|
||||
if len(ap) < 2 {
|
||||
log.Fatal("Wrong format of ipaddress:port")
|
||||
}
|
||||
port := ap[len(ap)-1]
|
||||
if ap[0] != "" && ap[0] != "0.0.0.0" {
|
||||
log.Printf("Listen address: %v", b)
|
||||
return
|
||||
}
|
||||
a, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
log.Printf("Listen address: %v", b)
|
||||
return
|
||||
}
|
||||
var m string
|
||||
for _, i := range a {
|
||||
n, ok := i.(*net.IPNet)
|
||||
if !ok || n.IP.IsLoopback() || strings.Contains(n.IP.String(), ":") {
|
||||
continue
|
||||
}
|
||||
m += n.IP.String() + ":" + port + " "
|
||||
}
|
||||
log.Printf("Listen address: %v", m)
|
||||
}
|
||||
|
||||
func gifPalette(i image.Image, n int64) image.Image {
|
||||
switch n {
|
||||
case 2:
|
||||
i = halfgone.FloydSteinbergDitherer{}.Apply(halfgone.ImageToGray(i))
|
||||
default:
|
||||
q := quantize.MedianCutQuantizer{}
|
||||
p := q.Quantize(make([]color.Color, 0, int(n)), i)
|
||||
bounds := i.Bounds()
|
||||
quantized := image.NewPaletted(bounds, p)
|
||||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||
quantized.Set(x, y, i.At(x, y))
|
||||
}
|
||||
}
|
||||
i = quantized
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func asciify(s []byte) []byte {
|
||||
a := make([]byte, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] > 127 {
|
||||
a[i] = '.'
|
||||
continue
|
||||
}
|
||||
a[i] = s[i]
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func findBrowser() string {
|
||||
var paths []string
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
paths = []string{
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
|
||||
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
||||
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
||||
"/Applications/Brave Browser Beta.app/Contents/MacOS/Brave Browser Beta",
|
||||
"/Applications/Brave Browser Nightly.app/Contents/MacOS/Brave Browser Nightly",
|
||||
"/Applications/Vivaldi.app/Contents/MacOS/Vivaldi",
|
||||
"/Applications/Arc.app/Contents/MacOS/Arc",
|
||||
}
|
||||
case "windows":
|
||||
pf := os.Getenv("ProgramFiles")
|
||||
pfx86 := os.Getenv("ProgramFiles(x86)")
|
||||
lad := os.Getenv("LOCALAPPDATA")
|
||||
paths = []string{
|
||||
filepath.Join(pf, `Google\Chrome\Application\chrome.exe`),
|
||||
filepath.Join(pfx86, `Google\Chrome\Application\chrome.exe`),
|
||||
filepath.Join(lad, `Google\Chrome\Application\chrome.exe`),
|
||||
filepath.Join(pf, `BraveSoftware\Brave-Browser\Application\brave.exe`),
|
||||
filepath.Join(pfx86, `BraveSoftware\Brave-Browser\Application\brave.exe`),
|
||||
filepath.Join(lad, `BraveSoftware\Brave-Browser\Application\brave.exe`),
|
||||
filepath.Join(pf, `Chromium\Application\chrome.exe`),
|
||||
filepath.Join(lad, `Chromium\Application\chrome.exe`),
|
||||
filepath.Join(pf, `Microsoft\Edge\Application\msedge.exe`),
|
||||
filepath.Join(pfx86, `Microsoft\Edge\Application\msedge.exe`),
|
||||
filepath.Join(pf, `Vivaldi\Application\vivaldi.exe`),
|
||||
}
|
||||
default:
|
||||
paths = []string{
|
||||
"/usr/bin/google-chrome",
|
||||
"/usr/bin/google-chrome-stable",
|
||||
"/usr/bin/chromium",
|
||||
"/usr/bin/chromium-browser",
|
||||
"/usr/bin/brave-browser",
|
||||
"/usr/bin/brave-browser-stable",
|
||||
"/usr/bin/brave",
|
||||
"/usr/bin/microsoft-edge",
|
||||
"/usr/bin/vivaldi",
|
||||
"/snap/bin/chromium",
|
||||
"/snap/bin/brave",
|
||||
"/opt/brave.com/brave/brave",
|
||||
"/opt/google/chrome/chrome",
|
||||
"/opt/vivaldi/vivaldi",
|
||||
"/usr/local/bin/chrome",
|
||||
"/usr/local/bin/chromium",
|
||||
"/usr/local/bin/brave",
|
||||
}
|
||||
}
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
for _, n := range []string{"google-chrome", "google-chrome-stable", "chromium", "chromium-browser", "brave-browser", "brave", "microsoft-edge", "vivaldi", "chrome"} {
|
||||
if p, err := exec.LookPath(n); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func fetchJnrbsnUserAgent() string {
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Get("https://jnrbsn.github.io/user-agents/user-agents.json")
|
||||
if err != nil {
|
||||
log.Printf("Failed to fetch user agents from jnrbsn: %v", err)
|
||||
return ""
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
log.Printf("jnrbsn API returned status: %d", resp.StatusCode)
|
||||
return ""
|
||||
}
|
||||
|
||||
var userAgents []string
|
||||
if err := json.NewDecoder(resp.Body).Decode(&userAgents); err != nil {
|
||||
log.Printf("Failed to decode jnrbsn user agents JSON: %v", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(userAgents) == 0 {
|
||||
log.Printf("jnrbsn API returned no user agents")
|
||||
return ""
|
||||
}
|
||||
|
||||
log.Printf("Fetched user agent from jnrbsn: %s", userAgents[0])
|
||||
return userAgents[0]
|
||||
}
|
||||
525
wrp.go
525
wrp.go
@@ -1,57 +1,62 @@
|
||||
//
|
||||
// WRP - Web Rendering Proxy
|
||||
//
|
||||
// Copyright (c) 2013-2018 Antoni Sawicki
|
||||
// Copyright (c) 2019-2021 Google LLC
|
||||
// Copyright (c) 2013-2025 Antoni Sawicki
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/MaxHalford/halfgone"
|
||||
"github.com/chromedp/cdproto/css"
|
||||
"github.com/chromedp/cdproto/emulation"
|
||||
"github.com/chromedp/cdproto/page"
|
||||
_ "github.com/breml/rootcerts"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/ericpauley/go-quantize/quantize"
|
||||
)
|
||||
|
||||
const version = "4.9.3"
|
||||
|
||||
var (
|
||||
addr = flag.String("l", ":8080", "Listen address:port, default :8080")
|
||||
headless = flag.Bool("h", true, "Headless mode / hide browser window (default true)")
|
||||
defType = flag.String("t", "gip", "Image type: gip|png|gif|jpg")
|
||||
wrpMode = flag.String("m", "ismap", "WRP Mode: ismap|html")
|
||||
defImgSize = flag.Int64("is", 200, "html mode default image size")
|
||||
defJpgQual = flag.Int64("q", 75, "Jpeg image quality, default 75%") // TODO: this should be form dropdown when jpeg is selected as image type
|
||||
fgeom = flag.String("g", "1152x600x216", "Geometry: width x height x colors, height can be 0 for unlimited")
|
||||
htmFnam = flag.String("ui", "wrp.html", "HTML template file for the UI")
|
||||
delay = flag.Duration("s", 5*time.Second, "Timeout for waiting for the page to render before screenshot")
|
||||
userAgent = flag.String("ua", "jnrbsn", "override chrome user agent (jnrbsn=fetch from API, empty=default)")
|
||||
browserPath = flag.String("b", "", "browser executable path (e.g., /Applications/Brave Browser.app/Contents/MacOS/Brave Browser)")
|
||||
searchEng = flag.String("se", "https://duckduckgo.com/search?q=", "Search engine string")
|
||||
userDataDir = flag.String("profile", "", "Chrome user data dir for persistent cookies/sessions")
|
||||
bgColor = flag.String("bgcolor", "#F0F0F0", "Background color for WRP UI")
|
||||
)
|
||||
|
||||
var (
|
||||
version = "4.5.3"
|
||||
srv http.Server
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
img = make(map[string]bytes.Buffer)
|
||||
ismap = make(map[string]wrpReq)
|
||||
noDel bool
|
||||
defType string
|
||||
defGeom geom
|
||||
htmlTmpl *template.Template
|
||||
srv http.Server
|
||||
actx, ctx context.Context
|
||||
acncl, cncl context.CancelFunc
|
||||
wrpCach wrpCache
|
||||
defGeom geom
|
||||
htmlTmpl *template.Template
|
||||
)
|
||||
|
||||
// go:embed *.html
|
||||
//go:embed *.html
|
||||
var fs embed.FS
|
||||
|
||||
type geom struct {
|
||||
@@ -60,12 +65,17 @@ type geom struct {
|
||||
c int64
|
||||
}
|
||||
|
||||
// TODO: there is a major overlap/duplication/triplication
|
||||
// between the 3 data structs, perhps we could reduce to just one?
|
||||
|
||||
// Data for html template
|
||||
type uiData struct {
|
||||
Version string
|
||||
WrpMode string
|
||||
URL string
|
||||
BgColor string
|
||||
NColors int64
|
||||
JQual int64
|
||||
Width int64
|
||||
Height int64
|
||||
Zoom float64
|
||||
@@ -74,12 +84,14 @@ type uiData struct {
|
||||
ImgSize string
|
||||
ImgWidth int
|
||||
ImgHeight int
|
||||
MaxSize int64
|
||||
MapURL string
|
||||
PageHeight string
|
||||
TeXT string
|
||||
}
|
||||
|
||||
// Parameters for HTML print function
|
||||
type printParams struct {
|
||||
type uiParams struct {
|
||||
bgColor string
|
||||
pageHeight string
|
||||
imgSize string
|
||||
@@ -87,31 +99,50 @@ type printParams struct {
|
||||
mapURL string
|
||||
imgWidth int
|
||||
imgHeight int
|
||||
text string
|
||||
}
|
||||
|
||||
// WRP Request
|
||||
type wrpReq struct {
|
||||
url string // url
|
||||
width int64 // width
|
||||
height int64 // height
|
||||
zoom float64 // zoom/scale
|
||||
colors int64 // #colors
|
||||
mouseX int64 // mouseX
|
||||
mouseY int64 // mouseY
|
||||
keys string // keys to send
|
||||
buttons string // Fn buttons
|
||||
imgType string // imgtype
|
||||
url string
|
||||
width int64
|
||||
height int64
|
||||
zoom float64
|
||||
nColors int64
|
||||
jQual int64
|
||||
mouseX int64
|
||||
mouseY int64
|
||||
keys string
|
||||
buttons string
|
||||
imgType string
|
||||
wrpMode string
|
||||
maxSize int64
|
||||
proxy bool
|
||||
w http.ResponseWriter
|
||||
r *http.Request
|
||||
}
|
||||
|
||||
// Parse HTML Form, Process Input Boxes, Etc.
|
||||
func (rq *wrpReq) baseTag() string {
|
||||
if rq.r.Method != "CONNECT" {
|
||||
return ""
|
||||
}
|
||||
if addr := rq.r.Context().Value(http.LocalAddrContextKey); addr != nil {
|
||||
return fmt.Sprintf(`<BASE HREF="http://%v/">`, addr)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (rq *wrpReq) parseForm() {
|
||||
rq.r.ParseForm()
|
||||
rq.wrpMode = rq.r.FormValue("m")
|
||||
if rq.wrpMode == "" {
|
||||
rq.wrpMode = *wrpMode
|
||||
}
|
||||
rq.url = rq.r.FormValue("url")
|
||||
if len(rq.url) > 1 && !strings.HasPrefix(rq.url, "http") {
|
||||
rq.url = fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(rq.url))
|
||||
rq.url = *searchEng + url.QueryEscape(rq.url)
|
||||
}
|
||||
// TODO: implement atoiOrZero
|
||||
rq.width, _ = strconv.ParseInt(rq.r.FormValue("w"), 10, 64)
|
||||
rq.height, _ = strconv.ParseInt(rq.r.FormValue("h"), 10, 64)
|
||||
if rq.width < 10 && rq.height < 10 {
|
||||
@@ -122,33 +153,48 @@ func (rq *wrpReq) parseForm() {
|
||||
if rq.zoom < 0.1 {
|
||||
rq.zoom = 1.0
|
||||
}
|
||||
rq.colors, _ = strconv.ParseInt(rq.r.FormValue("c"), 10, 64)
|
||||
if rq.colors < 2 || rq.colors > 256 {
|
||||
rq.colors = defGeom.c
|
||||
rq.imgType = rq.r.FormValue("t")
|
||||
switch rq.imgType {
|
||||
case "gip", "png", "gif", "jpg":
|
||||
default:
|
||||
rq.imgType = *defType
|
||||
}
|
||||
rq.nColors, _ = strconv.ParseInt(rq.r.FormValue("c"), 10, 64)
|
||||
if rq.nColors < 2 || rq.nColors > 256 {
|
||||
rq.nColors = defGeom.c
|
||||
}
|
||||
rq.jQual, _ = strconv.ParseInt(rq.r.FormValue("q"), 10, 64)
|
||||
if rq.jQual < 1 || rq.jQual > 100 {
|
||||
rq.jQual = *defJpgQual
|
||||
}
|
||||
rq.keys = rq.r.FormValue("k")
|
||||
rq.buttons = rq.r.FormValue("Fn")
|
||||
rq.imgType = rq.r.FormValue("t")
|
||||
if rq.imgType != "gif" && rq.imgType != "png" {
|
||||
rq.imgType = defType
|
||||
rq.maxSize, _ = strconv.ParseInt(rq.r.FormValue("s"), 10, 64)
|
||||
if rq.maxSize == 0 {
|
||||
rq.maxSize = *defImgSize
|
||||
}
|
||||
log.Printf("%s WrpReq from UI Form: %+v\n", rq.r.RemoteAddr, rq)
|
||||
}
|
||||
|
||||
// Display WP UI
|
||||
func (rq *wrpReq) printHTML(p printParams) {
|
||||
func (rq *wrpReq) printUI(p uiParams) {
|
||||
rq.w.Header().Set("Cache-Control", "max-age=0")
|
||||
rq.w.Header().Set("Expires", "-1")
|
||||
rq.w.Header().Set("Pragma", "no-cache")
|
||||
rq.w.Header().Set("Content-Type", "text/html")
|
||||
if p.bgColor == "" {
|
||||
p.bgColor = *bgColor
|
||||
}
|
||||
data := uiData{
|
||||
Version: version,
|
||||
WrpMode: rq.wrpMode,
|
||||
URL: rq.url,
|
||||
BgColor: p.bgColor,
|
||||
Width: rq.width,
|
||||
Height: rq.height,
|
||||
NColors: rq.colors,
|
||||
NColors: rq.nColors,
|
||||
JQual: rq.jQual,
|
||||
Zoom: rq.zoom,
|
||||
MaxSize: rq.maxSize,
|
||||
ImgType: rq.imgType,
|
||||
ImgSize: p.imgSize,
|
||||
ImgWidth: p.imgWidth,
|
||||
@@ -156,185 +202,70 @@ func (rq *wrpReq) printHTML(p printParams) {
|
||||
ImgURL: p.imgURL,
|
||||
MapURL: p.mapURL,
|
||||
PageHeight: p.pageHeight,
|
||||
TeXT: p.text,
|
||||
}
|
||||
err := htmlTmpl.Execute(rq.w, data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Fprintf(rq.w, "Error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Determine what action to take
|
||||
func (rq *wrpReq) action() chromedp.Action {
|
||||
// Mouse Click
|
||||
if rq.mouseX > 0 && rq.mouseY > 0 {
|
||||
log.Printf("%s Mouse Click %d,%d\n", rq.r.RemoteAddr, rq.mouseX, rq.mouseY)
|
||||
return chromedp.MouseClickXY(float64(rq.mouseX)/float64(rq.zoom), float64(rq.mouseY)/float64(rq.zoom))
|
||||
func proxyServer(w http.ResponseWriter, r *http.Request) {
|
||||
var purl string
|
||||
switch {
|
||||
case r.Method == "CONNECT":
|
||||
purl = "https://" + r.Host
|
||||
case r.URL.Scheme == "":
|
||||
purl = "http://" + r.Host + r.URL.RequestURI()
|
||||
default:
|
||||
purl = r.URL.String()
|
||||
}
|
||||
// Buttons
|
||||
if len(rq.buttons) > 0 {
|
||||
log.Printf("%s Button %v\n", rq.r.RemoteAddr, rq.buttons)
|
||||
switch rq.buttons {
|
||||
case "Bk":
|
||||
return chromedp.NavigateBack()
|
||||
case "St":
|
||||
return chromedp.Stop()
|
||||
case "Re":
|
||||
return chromedp.Reload()
|
||||
case "Bs":
|
||||
return chromedp.KeyEvent("\b")
|
||||
case "Rt":
|
||||
return chromedp.KeyEvent("\r")
|
||||
case "<":
|
||||
return chromedp.KeyEvent("\u0302")
|
||||
case "^":
|
||||
return chromedp.KeyEvent("\u0304")
|
||||
case "v":
|
||||
return chromedp.KeyEvent("\u0301")
|
||||
case ">":
|
||||
return chromedp.KeyEvent("\u0303")
|
||||
}
|
||||
log.Printf("%s Proxy Request for %s\n", r.RemoteAddr, purl)
|
||||
rq := wrpReq{
|
||||
r: r,
|
||||
w: w,
|
||||
url: purl,
|
||||
width: defGeom.w,
|
||||
height: defGeom.h,
|
||||
nColors: defGeom.c,
|
||||
zoom: 1.0,
|
||||
imgType: *defType,
|
||||
wrpMode: *wrpMode,
|
||||
maxSize: *defImgSize,
|
||||
jQual: *defJpgQual,
|
||||
proxy: true,
|
||||
}
|
||||
// Keys
|
||||
if len(rq.keys) > 0 {
|
||||
log.Printf("%s Sending Keys: %#v\n", rq.r.RemoteAddr, rq.keys)
|
||||
return chromedp.KeyEvent(rq.keys)
|
||||
}
|
||||
// Navigate to URL
|
||||
log.Printf("%s Processing Capture Request for %s\n", rq.r.RemoteAddr, rq.url)
|
||||
return chromedp.Navigate(rq.url)
|
||||
}
|
||||
|
||||
// Process Keyboard and Mouse events or Navigate to the desired URL.
|
||||
func (rq *wrpReq) navigate() {
|
||||
err := chromedp.Run(ctx, rq.action())
|
||||
if err != nil {
|
||||
if err.Error() == "context canceled" {
|
||||
log.Printf("%s Contex cancelled, try again", rq.r.RemoteAddr)
|
||||
fmt.Fprintf(rq.w, "<BR>%s<BR> -- restarting, try again", err)
|
||||
ctx, cancel = chromedp.NewContext(context.Background())
|
||||
var currentURL string
|
||||
chromedp.Run(ctx, chromedp.Location(¤tURL))
|
||||
currentURL = strings.Replace(currentURL, "https://", "http://", 1)
|
||||
if currentURL != strings.Replace(rq.url, "https://", "http://", 1) {
|
||||
if dl := rq.navigate(); dl != nil {
|
||||
writeDownload(w, dl)
|
||||
return
|
||||
}
|
||||
log.Printf("%s %s", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>%s<BR>", err)
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/chromedp/chromedp/issues/979
|
||||
func chromedpCaptureScreenshot(res *[]byte, h int64) chromedp.Action {
|
||||
if res == nil {
|
||||
panic("res cannot be nil")
|
||||
rq.url = strings.Replace(rq.url, "https://", "http://", 1)
|
||||
if r.Method == "CONNECT" {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
}
|
||||
if h == 0 {
|
||||
return chromedp.CaptureScreenshot(res)
|
||||
}
|
||||
|
||||
return chromedp.ActionFunc(func(ctx context.Context) error {
|
||||
var err error
|
||||
*res, err = page.CaptureScreenshot().Do(ctx)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
// Capture currently rendered web page to an image and fake ISMAP
|
||||
func (rq *wrpReq) capture() {
|
||||
var err error
|
||||
var styles []*css.ComputedStyleProperty
|
||||
var r, g, b int
|
||||
var h int64
|
||||
var pngcap []byte
|
||||
chromedp.Run(ctx,
|
||||
emulation.SetDeviceMetricsOverride(int64(float64(rq.width)/rq.zoom), 10, rq.zoom, false),
|
||||
chromedp.Location(&rq.url),
|
||||
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
|
||||
}),
|
||||
)
|
||||
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", rq.r.RemoteAddr, rq.url, h)
|
||||
height := int64(float64(rq.height) / rq.zoom)
|
||||
if rq.height == 0 && h > 0 {
|
||||
height = h + 30
|
||||
}
|
||||
chromedp.Run(
|
||||
ctx, emulation.SetDeviceMetricsOverride(int64(float64(rq.width)/rq.zoom), height, rq.zoom, false),
|
||||
chromedp.Sleep(time.Second*2), // TODO(tenox): totally lame, find a better way to determine if page is rendered
|
||||
)
|
||||
// Capture screenshot...
|
||||
err = chromedp.Run(ctx, chromedpCaptureScreenshot(&pngcap, rq.height))
|
||||
if err != nil {
|
||||
if err.Error() == "context canceled" {
|
||||
log.Printf("%s Contex cancelled, try again", rq.r.RemoteAddr)
|
||||
fmt.Fprintf(rq.w, "<BR>%s<BR> -- restarting, try again", err)
|
||||
ctx, cancel = chromedp.NewContext(context.Background())
|
||||
return
|
||||
}
|
||||
log.Printf("%s Failed to capture screenshot: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to capture screenshot:<BR>%s<BR>\n", err)
|
||||
if rq.wrpMode == "html" {
|
||||
rq.captureMarkdown()
|
||||
return
|
||||
}
|
||||
seq := rand.Intn(9999)
|
||||
imgpath := fmt.Sprintf("/img/%04d.%s", seq, rq.imgType)
|
||||
mappath := fmt.Sprintf("/map/%04d.map", seq)
|
||||
ismap[mappath] = *rq
|
||||
var ssize string
|
||||
var iw, ih int
|
||||
switch rq.imgType {
|
||||
case "gif":
|
||||
i, err := png.Decode(bytes.NewReader(pngcap))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode screenshot: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to decode page screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
if rq.colors == 2 {
|
||||
gray := halfgone.ImageToGray(i)
|
||||
i = halfgone.FloydSteinbergDitherer{}.Apply(gray)
|
||||
}
|
||||
var gifbuf bytes.Buffer
|
||||
st := time.Now()
|
||||
err = gif.Encode(&gifbuf, i, &gif.Options{NumColors: int(rq.colors), Quantizer: quantize.MedianCutQuantizer{}})
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode GIF: %s\n", rq.r.RemoteAddr, err)
|
||||
fmt.Fprintf(rq.w, "<BR>Unable to encode GIF:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
img[imgpath] = gifbuf
|
||||
ssize = fmt.Sprintf("%.0f KB", float32(len(gifbuf.Bytes()))/1024.0)
|
||||
iw = i.Bounds().Max.X
|
||||
ih = i.Bounds().Max.Y
|
||||
log.Printf("%s Encoded GIF image: %s, Size: %s, Colors: %d, %dx%d, Time: %vms\n", rq.r.RemoteAddr, imgpath, ssize, rq.colors, iw, ih, time.Since(st).Milliseconds())
|
||||
case "png":
|
||||
pngbuf := bytes.NewBuffer(pngcap)
|
||||
img[imgpath] = *pngbuf
|
||||
cfg, _, _ := image.DecodeConfig(pngbuf)
|
||||
ssize = fmt.Sprintf("%.0f KB", float32(len(pngbuf.Bytes()))/1024.0)
|
||||
iw = cfg.Width
|
||||
ih = cfg.Height
|
||||
log.Printf("%s Got PNG image: %s, Size: %s, %dx%d\n", rq.r.RemoteAddr, imgpath, ssize, iw, ih)
|
||||
}
|
||||
rq.printHTML(printParams{
|
||||
bgColor: fmt.Sprintf("#%02X%02X%02X", r, g, b),
|
||||
pageHeight: fmt.Sprintf("%d PX", h),
|
||||
imgSize: ssize,
|
||||
imgURL: imgpath,
|
||||
mapURL: mappath,
|
||||
imgWidth: iw,
|
||||
imgHeight: ih,
|
||||
})
|
||||
log.Printf("%s Done with capture for %s\n", rq.r.RemoteAddr, rq.url)
|
||||
rq.captureScreenshot()
|
||||
}
|
||||
|
||||
func isProxyRequest(r *http.Request) bool {
|
||||
return r.URL.IsAbs() || r.Method == "CONNECT"
|
||||
}
|
||||
|
||||
// Process HTTP requests to WRP '/' url
|
||||
func pageServer(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s [%+v]\n", r.RemoteAddr, r.Method, r.URL, r.Host)
|
||||
if isProxyRequest(r) {
|
||||
proxyServer(w, r)
|
||||
return
|
||||
}
|
||||
log.Printf("%s Page Request for %s [%+v]\n", r.RemoteAddr, r.URL.Path, r.URL.RawQuery)
|
||||
rq := wrpReq{
|
||||
r: r,
|
||||
@@ -342,176 +273,140 @@ func pageServer(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
rq.parseForm()
|
||||
if len(rq.url) < 4 {
|
||||
rq.printHTML(printParams{bgColor: "#FFFFFF"})
|
||||
rq.printUI(uiParams{})
|
||||
return
|
||||
}
|
||||
rq.navigate()
|
||||
rq.capture()
|
||||
if dl := rq.navigate(); dl != nil {
|
||||
http.Redirect(w, r, cacheDownload(dl), http.StatusFound)
|
||||
return
|
||||
}
|
||||
if rq.wrpMode == "html" {
|
||||
rq.captureMarkdown()
|
||||
return
|
||||
}
|
||||
rq.captureScreenshot()
|
||||
}
|
||||
|
||||
// Process HTTP requests to ISMAP '/map/' url
|
||||
func mapServer(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s ISMAP Request for %s [%+v]\n", r.RemoteAddr, r.URL.Path, r.URL.RawQuery)
|
||||
rq, ok := ismap[r.URL.Path]
|
||||
rq.r = r
|
||||
rq.w = w
|
||||
if !ok {
|
||||
fmt.Fprintf(w, "Unable to find map %s\n", r.URL.Path)
|
||||
log.Printf("Unable to find map %s\n", r.URL.Path)
|
||||
return
|
||||
}
|
||||
if !noDel {
|
||||
defer delete(ismap, r.URL.Path)
|
||||
}
|
||||
n, err := fmt.Sscanf(r.URL.RawQuery, "%d,%d", &rq.mouseX, &rq.mouseY)
|
||||
if err != nil || n != 2 {
|
||||
fmt.Fprintf(w, "n=%d, err=%s\n", n, err)
|
||||
log.Printf("%s ISMAP n=%d, err=%s\n", r.RemoteAddr, n, err)
|
||||
return
|
||||
}
|
||||
log.Printf("%s WrpReq from ISMAP: %+v\n", r.RemoteAddr, rq)
|
||||
if len(rq.url) < 4 {
|
||||
rq.printHTML(printParams{bgColor: "#FFFFFF"})
|
||||
return
|
||||
}
|
||||
rq.navigate()
|
||||
rq.capture()
|
||||
func pacServer(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
|
||||
fmt.Fprintf(w, `function FindProxyForURL(url, host) {
|
||||
if (isPlainHostName(host) ||
|
||||
host == "localhost" ||
|
||||
isInNet(host, "127.0.0.0", "255.0.0.0") ||
|
||||
isInNet(host, "10.0.0.0", "255.0.0.0") ||
|
||||
isInNet(host, "172.16.0.0", "255.240.0.0") ||
|
||||
isInNet(host, "192.168.0.0", "255.255.0.0") ||
|
||||
isInNet(host, "169.254.0.0", "255.255.0.0"))
|
||||
return "DIRECT";
|
||||
return "PROXY %s";
|
||||
}
|
||||
`, r.Host)
|
||||
}
|
||||
|
||||
// Process HTTP requests for images '/img/' url
|
||||
func imgServer(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s IMG Request for %s\n", r.RemoteAddr, r.URL.Path)
|
||||
imgbuf, ok := img[r.URL.Path]
|
||||
if !ok || imgbuf.Bytes() == nil {
|
||||
fmt.Fprintf(w, "Unable to find image %s\n", r.URL.Path)
|
||||
log.Printf("%s Unable to find image %s\n", r.RemoteAddr, r.URL.Path)
|
||||
return
|
||||
}
|
||||
if !noDel {
|
||||
defer delete(img, r.URL.Path)
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(r.URL.Path, ".gif"):
|
||||
w.Header().Set("Content-Type", "image/gif")
|
||||
case strings.HasPrefix(r.URL.Path, ".png"):
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
}
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(imgbuf.Bytes())))
|
||||
w.Header().Set("Cache-Control", "max-age=0")
|
||||
w.Header().Set("Expires", "-1")
|
||||
w.Header().Set("Pragma", "no-cache")
|
||||
w.Write(imgbuf.Bytes())
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
// Process HTTP requests for Shutdown via '/shutdown/' url
|
||||
func haltServer(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s Shutdown Request for %s\n", r.RemoteAddr, r.URL.Path)
|
||||
w.Header().Set("Cache-Control", "max-age=0")
|
||||
w.Header().Set("Expires", "-1")
|
||||
w.Header().Set("Pragma", "no-cache")
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintf(w, "Shutting down WRP...\n")
|
||||
w.(http.Flusher).Flush()
|
||||
time.Sleep(time.Second * 2)
|
||||
cancel()
|
||||
cncl()
|
||||
acncl()
|
||||
srv.Shutdown(context.Background())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// returns html template, either from html file or built-in
|
||||
func tmpl(t string) string {
|
||||
func wrpTemplate(t string) string {
|
||||
var tmpl []byte
|
||||
fh, err := os.Open(t)
|
||||
if err != nil {
|
||||
goto builtin
|
||||
}
|
||||
tmpl, err = ioutil.ReadAll(fh)
|
||||
defer fh.Close()
|
||||
|
||||
tmpl, err = io.ReadAll(fh)
|
||||
if err != nil {
|
||||
goto builtin
|
||||
}
|
||||
log.Printf("Got UI template from %v file\n", t)
|
||||
log.Printf("Got HTML UI template from %v file, size %v \n", t, len(tmpl))
|
||||
return string(tmpl)
|
||||
|
||||
builtin:
|
||||
fhs, err := fs.Open("/wrp.html")
|
||||
fhs, err := fs.Open("wrp.html")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer fhs.Close()
|
||||
|
||||
tmpl, err = ioutil.ReadAll(fhs)
|
||||
tmpl, err = io.ReadAll(fhs)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Got UI template from built-in\n")
|
||||
log.Printf("Got HTML UI template from embed\n")
|
||||
return string(tmpl)
|
||||
}
|
||||
|
||||
// Main...
|
||||
func main() {
|
||||
var addr, fgeom, tHTML string
|
||||
var headless bool
|
||||
var debug bool
|
||||
var err error
|
||||
flag.StringVar(&addr, "l", ":8080", "Listen address:port, default :8080")
|
||||
flag.BoolVar(&headless, "h", true, "Headless mode - hide 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.StringVar(&tHTML, "ui", "wrp.html", "HTML template file for the UI")
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
flag.Parse()
|
||||
log.Printf("Web Rendering Proxy Version %s (%v)\n", version, runtime.GOARCH)
|
||||
log.Printf("Using embedded ca-certs from github.com/breml/rootcerts")
|
||||
log.Printf("Args: %q", os.Args)
|
||||
if len(os.Getenv("PORT")) > 0 {
|
||||
addr = ":" + os.Getenv(("PORT"))
|
||||
*addr = ":" + os.Getenv(("PORT"))
|
||||
}
|
||||
n, err := fmt.Sscanf(fgeom, "%dx%dx%d", &defGeom.w, &defGeom.h, &defGeom.c)
|
||||
printMyIPs(*addr)
|
||||
log.Printf("Default mode: %v", *wrpMode)
|
||||
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),
|
||||
)
|
||||
actx, acancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
||||
defer acancel()
|
||||
switch debug {
|
||||
case true:
|
||||
ctx, cancel = chromedp.NewContext(actx, chromedp.WithDebugf(log.Printf))
|
||||
default:
|
||||
ctx, cancel = chromedp.NewContext(actx)
|
||||
}
|
||||
defer cancel()
|
||||
cncl, acncl = chromedpStart()
|
||||
defer cncl()
|
||||
defer acncl()
|
||||
setupDownloads()
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
c := make(chan os.Signal)
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
log.Printf("Interrupt - shutting down.")
|
||||
cancel()
|
||||
os.RemoveAll(dlDir)
|
||||
cncl()
|
||||
acncl()
|
||||
srv.Shutdown(context.Background())
|
||||
os.Exit(1)
|
||||
}()
|
||||
|
||||
wrpCach.imgs = make(map[string]cachedImg)
|
||||
wrpCach.maps = make(map[string]cachedMap)
|
||||
|
||||
http.HandleFunc("/", pageServer)
|
||||
http.HandleFunc("/map/", mapServer)
|
||||
http.HandleFunc("/img/", imgServer)
|
||||
http.HandleFunc("/img/", imgServerMap)
|
||||
http.HandleFunc(imgZpfx, imgServerTxt)
|
||||
http.HandleFunc("/proxy.pac", pacServer)
|
||||
http.HandleFunc("/shutdown/", haltServer)
|
||||
http.HandleFunc("/dl/", dlServer)
|
||||
http.HandleFunc("/favicon.ico", http.NotFound)
|
||||
|
||||
log.Printf("Web Rendering Proxy Version %s\n", version)
|
||||
log.Printf("Args: %q", os.Args)
|
||||
log.Printf("Default Img Type: %v, Geometry: %+v", defType, defGeom)
|
||||
log.Printf("Default Img Type: %v, Geometry: %+v", *defType, defGeom)
|
||||
|
||||
htmlTmpl, err = template.New("wrp.html").Parse(tmpl(tHTML))
|
||||
htmlTmpl, err = template.New("wrp.html").Parse(wrpTemplate(*htmFnam))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Printf("Starting WRP http server on %s\n", addr)
|
||||
srv.Addr = addr
|
||||
log.Print("Starting WRP http server")
|
||||
srv.Addr = *addr
|
||||
srv.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "CONNECT" {
|
||||
pageServer(w, r)
|
||||
return
|
||||
}
|
||||
http.DefaultServeMux.ServeHTTP(w, r)
|
||||
})
|
||||
err = srv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
41
wrp.html
41
wrp.html
@@ -6,12 +6,21 @@
|
||||
<FORM ACTION="/" METHOD="POST">
|
||||
<INPUT TYPE="TEXT" NAME="url" VALUE="{{.URL}}" SIZE="20">
|
||||
<INPUT TYPE="SUBMIT" VALUE="Go">
|
||||
{{ if eq .WrpMode "ismap" }}
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="Bk">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="St">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="Re">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="Up">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="Dn">
|
||||
W <INPUT TYPE="TEXT" NAME="w" VALUE="{{.Width}}" SIZE="4">
|
||||
H <INPUT TYPE="TEXT" NAME="h" VALUE="{{.Height}}" SIZE="4">
|
||||
{{ end }}
|
||||
{{ if eq .WrpMode "html" }}
|
||||
S <INPUT TYPE="TEXT" NAME="s" VALUE="{{.MaxSize}}" SIZE="4">
|
||||
{{ end }}
|
||||
{{ if eq .WrpMode "ismap" }}
|
||||
Z <SELECT NAME="z">
|
||||
<OPTION DISABLED>Zoom</OPTION>
|
||||
<OPTION VALUE="0.7" {{ if eq .Zoom 0.7}}SELECTED{{end}}>0.7 x</OPTION>
|
||||
<OPTION VALUE="0.8" {{ if eq .Zoom 0.8}}SELECTED{{end}}>0.8 x</OPTION>
|
||||
<OPTION VALUE="0.9" {{ if eq .Zoom 0.9}}SELECTED{{end}}>0.9 x</OPTION>
|
||||
@@ -20,24 +29,43 @@
|
||||
<OPTION VALUE="1.2" {{ if eq .Zoom 1.2}}SELECTED{{end}}>1.2 x</OPTION>
|
||||
<OPTION VALUE="1.3" {{ if eq .Zoom 1.3}}SELECTED{{end}}>1.3 x</OPTION>
|
||||
</SELECT>
|
||||
T <SELECT NAME="t">
|
||||
<OPTION VALUE="gif" {{ if eq .ImgType "gif"}}SELECTED{{end}}>GIF</OPTION>
|
||||
<OPTION VALUE="png" {{ if eq .ImgType "png"}}SELECTED{{end}}>PNG</OPTION>
|
||||
{{ end }}
|
||||
M <SELECT NAME="m">
|
||||
<OPTION DISABLED>Mode</OPTION>
|
||||
<OPTION VALUE="ismap" {{ if eq .WrpMode "ismap"}}SELECTED{{end}}>ISMAP</OPTION>
|
||||
<OPTION VALUE="html" {{ if eq .WrpMode "html"}}SELECTED{{end}}>HTML</OPTION>
|
||||
</SELECT>
|
||||
T <SELECT NAME="t">
|
||||
<OPTION DISABLED>Type</OPTION>
|
||||
<OPTION VALUE="gip" {{ if eq .ImgType "gip"}}SELECTED{{end}}>GIP</OPTION>
|
||||
<OPTION VALUE="png" {{ if eq .ImgType "png"}}SELECTED{{end}}>PNG</OPTION>
|
||||
<OPTION VALUE="gif" {{ if eq .ImgType "gif"}}SELECTED{{end}}>GIF</OPTION>
|
||||
<OPTION VALUE="jpg" {{ if eq .ImgType "jpg"}}SELECTED{{end}}>JPG</OPTION>
|
||||
</SELECT>
|
||||
{{ if eq .ImgType "gif" }}
|
||||
C <SELECT NAME="c">
|
||||
<OPTION DISABLED>Ncol</OPTION>
|
||||
<OPTION VALUE="256" {{ if eq .NColors 256}}SELECTED{{end}}>256</OPTION>
|
||||
<OPTION VALUE="216" {{ if eq .NColors 216}}SELECTED{{end}}>216</OPTION>
|
||||
<OPTION VALUE="128" {{ if eq .NColors 128}}SELECTED{{end}}>128</OPTION>
|
||||
<OPTION VALUE="64" {{ if eq .NColors 64}}SELECTED{{end}}>64</OPTION>
|
||||
<OPTION VALUE="16" {{ if eq .NColors 16}}SELECTED{{end}}>16</OPTION>
|
||||
<OPTION VALUE="2" {{ if eq .NColors 2}}SELECTED{{end}}>2</OPTION>
|
||||
</SELECT>
|
||||
{{ end }}
|
||||
{{ if eq .ImgType "jpg" }}
|
||||
Q <INPUT TYPE="TEXT" NAME="q" VALUE="{{.JQual}}" SIZE="2">%
|
||||
{{ end }}
|
||||
{{ if eq .WrpMode "ismap" }}
|
||||
K <INPUT TYPE="TEXT" NAME="k" VALUE="" SIZE="4">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="Bs">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="Rt"><!--
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="All">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="<">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="^">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE="v">
|
||||
<INPUT TYPE="SUBMIT" NAME="Fn" VALUE=">" SIZE="1">-->
|
||||
{{ end }}
|
||||
</FORM>
|
||||
<BR>
|
||||
{{if .ImgURL}}
|
||||
@@ -46,11 +74,14 @@
|
||||
</A>
|
||||
<P>
|
||||
{{end}}
|
||||
{{.TeXT}}
|
||||
<FONT SIZE="-2">
|
||||
<A HREF="/?url=https://github.com/tenox7/wrp/&w={{.Width}}&h={{.Height}}&s={{printf "%.1f" .Zoom}}&c={{.NColors}}&t={{.ImgType}}">Web Rendering Proxy {{.Version}}</A> |
|
||||
<A HREF="/shutdown/">Shutdown WRP</A> |
|
||||
{{ if eq .WrpMode "ismap" }}
|
||||
<A HREF="/">Page Height: {{.PageHeight}}</A> |
|
||||
<A HREF="/">Img Size: {{.ImgSize}}</A>
|
||||
</FONT>
|
||||
{{end}}
|
||||
</FONT>
|
||||
</BODY>
|
||||
</HTML>
|
||||
</HTML>
|
||||
|
||||
Reference in New Issue
Block a user