mirror of
https://github.com/tenox7/wrp.git
synced 2026-02-09 05:44:33 +00:00
Compare commits
159 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
357f3ed6bf | ||
|
|
97c0679e0b | ||
|
|
e2223af833 | ||
|
|
60989d3395 | ||
|
|
74d015a4da | ||
|
|
8628c00dd7 | ||
|
|
327baf318a | ||
|
|
0e07f422f6 | ||
|
|
f7aece10e9 | ||
|
|
a7b7164932 | ||
|
|
7a27cf7b62 | ||
|
|
749f8bea5d | ||
|
|
290bc5a977 | ||
|
|
cc98932f5a | ||
|
|
f69e213a0b | ||
|
|
66641a099b | ||
|
|
872321c699 | ||
|
|
ba4183e0b4 | ||
|
|
4212678d81 | ||
|
|
0d2ba9d4b2 | ||
|
|
a63d4ef50d | ||
|
|
127114f753 | ||
|
|
b313e703fb | ||
|
|
ee26c40eb3 | ||
|
|
6c29008eb5 | ||
|
|
bb84d43d31 | ||
|
|
7067d2cdf8 | ||
|
|
640a405622 | ||
|
|
22dd6aaab2 | ||
|
|
d102016ba9 | ||
|
|
253fef2aad | ||
|
|
fdfad6bc69 | ||
|
|
1807790629 | ||
|
|
bd7d92393d | ||
|
|
e3b28e93c5 | ||
|
|
6784d47892 | ||
|
|
c96eb9ae35 | ||
|
|
cebebfa408 | ||
|
|
9d7bb952c5 | ||
|
|
fd4b7a381e | ||
|
|
b894c3f809 | ||
|
|
733efaea56 | ||
|
|
ad668d1bca | ||
|
|
4e28a50a8d | ||
|
|
2fab53d8a3 | ||
|
|
9557f172ed | ||
|
|
a3661003b0 | ||
|
|
7baaa0bd6e | ||
|
|
e5e5e321e8 | ||
|
|
650ac026c3 | ||
|
|
579d67f7fb | ||
|
0502f7a99d
|
|||
|
|
eb1476e579 | ||
|
|
f599a51c8d | ||
|
|
dedf7479b8 | ||
|
|
877c42a388 | ||
|
|
1f5592cbde | ||
|
|
404af50aa1 | ||
|
|
bb59229438 | ||
|
|
faa0818f18 | ||
|
|
26f999f262 | ||
|
|
4d02165619 | ||
|
|
1578b14fcd | ||
|
|
ceb6a67ff3 | ||
|
|
3ee146dee7 | ||
|
|
1e58c94263 | ||
|
|
ce51eb6226 | ||
|
|
1b68593fd2 | ||
|
|
8f16abacde | ||
|
|
b1e0b417c3 | ||
|
|
fd6f8592ef | ||
|
|
210a12fe3d | ||
|
|
92f3cb7aee | ||
|
|
d9381ef71a | ||
|
|
64f86b4fd9 | ||
|
|
2d41aa1044 | ||
|
|
6e43026100 | ||
|
|
3285a60c69 | ||
|
|
c873e53df0 | ||
|
|
dc6c8eca52 | ||
|
|
849239fc8e | ||
|
|
d71a48b746 | ||
|
|
2671fc236c | ||
|
|
15b227ccf1 | ||
|
|
89f5f556f9 | ||
|
|
af3aef5c39 | ||
|
|
26ad732d99 | ||
|
|
033f2f3578 | ||
|
|
277d70f4c3 | ||
|
|
ab4122a9ba | ||
|
|
9bd1359a4d | ||
|
|
adff09c6b9 | ||
|
|
93c84fdfca | ||
|
|
de780b353d | ||
|
|
d64ae7e5d0 | ||
|
|
6f702d74e5 | ||
|
|
6a8f655953 | ||
|
|
1b8d3544ed | ||
|
|
b5f5d6c576 | ||
|
|
99f4c8cac3 | ||
|
|
6e75da10f3 | ||
|
|
fb4848d235 | ||
|
|
06317022a6 | ||
|
|
69d4b39eff | ||
|
|
5f6a1154df | ||
|
|
d6005b52fd | ||
|
|
fabcd721c3 | ||
|
|
0ee45139c3 | ||
|
|
936cb97bc0 | ||
|
|
02758bd039 | ||
|
|
dd1031a35b | ||
|
|
a05a30c26f | ||
|
|
9c96a62816 | ||
|
|
5dd4b5feab | ||
|
|
791e87d7ed | ||
|
|
a8cc1b6b4e | ||
|
|
9358691ce5 | ||
|
|
253d36e963 | ||
|
|
719a7fc560 | ||
|
|
3270bbcdd3 | ||
|
|
fec97243ba | ||
|
|
6dfe7ddafc | ||
|
|
a6df4cbec4 | ||
|
|
e48f0c9ff2 | ||
|
|
c7fcea908f | ||
|
|
b91bbed4a7 | ||
|
|
7a2f673fd0 | ||
|
|
61b84116b1 | ||
|
|
ea738f206a | ||
|
|
981055dff9 | ||
|
|
deb0cf7923 | ||
|
|
186fda4949 | ||
|
|
7610f52574 | ||
|
|
416490289d | ||
|
|
0ae49044c2 | ||
|
|
cb87a83d26 | ||
|
|
ebe19912e6 | ||
|
|
5d8f51ac66 | ||
|
|
d905704a2a | ||
|
|
d382c38547 | ||
|
|
12664e6a10 | ||
|
|
e643ec1d69 | ||
|
|
9ad651c72c | ||
|
|
a897f76e20 | ||
|
|
df400d57b3 | ||
|
|
546e686cbc | ||
|
|
57a107aa69 | ||
|
|
aabc8cf021 | ||
|
|
a3eb7cb69a | ||
|
|
d8617af9c2 | ||
|
|
c6186d6fb4 | ||
|
|
7d84d01268 | ||
|
|
5b827bffb0 | ||
|
|
0680b4a72e | ||
|
|
e869291f8e | ||
|
|
071a75dfc6 | ||
|
|
34d4e2fa2a | ||
|
|
2ac4464b98 | ||
|
|
cc3d4a674b |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
.vscode
|
||||
wrp-*
|
||||
36
Changelog.md
36
Changelog.md
@@ -1,36 +0,0 @@
|
||||
## [2.0] - 2017-05-10
|
||||
### Added
|
||||
- Support PyQt5 if available.
|
||||
- Sets title from original one.
|
||||
- Returns server errors as is.
|
||||
- Download non-HTML files as is.
|
||||
- For JavaScript capable browsers detect and automatically set view width.
|
||||
- Add support for configuring which image format to use.
|
||||
- Added support for PythonMagick. If found, allows to dither, color-reduce, or convert to grayscale or monochrome.
|
||||
- If PythonMagick is found, render as PNG and convert to user-requested format using it, for better quality.
|
||||
|
||||
### Changed
|
||||
- Support www prepented to http://wrp.stop command.
|
||||
|
||||
### Fixed
|
||||
- Prevent python crashes with non-ASCII character in URLs.
|
||||
|
||||
## [1.4] - 2017-01-22
|
||||
### Added
|
||||
- Suport for ISMAP on Linux.
|
||||
- Use queues instead of globals in Linux.
|
||||
|
||||
## [1.3] - 2017-01-21
|
||||
### Changed
|
||||
- Merged mac OS and Linux in a single executable.
|
||||
- Use queues instead of globals in Linux.
|
||||
|
||||
### Fixed
|
||||
- Call PyQt to close application on http://wrp.stop
|
||||
|
||||
## [1.2] - 2016-12-27
|
||||
### Added
|
||||
- Support for IMAP on mac OS.
|
||||
|
||||
### Changed
|
||||
- Use queues instead of globals in mac OS.
|
||||
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM chromedp/headless-shell
|
||||
ADD wrp /wrp
|
||||
ENTRYPOINT ["/wrp"]
|
||||
ENV PATH="/headless-shell:${PATH}"
|
||||
LABEL maintainer="as@tenoware.com"
|
||||
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
18
Makefile
Normal file
18
Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
all: wrp
|
||||
|
||||
wrp: wrp.go
|
||||
go build wrp.go
|
||||
|
||||
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=windows GOARCH=amd64 go build -a -o wrp-amd64-windows.exe wrp.go
|
||||
GOOS=linux GOARCH=arm go build -a -o wrp-arm-linux wrp.go
|
||||
|
||||
docker: wrp
|
||||
docker build -t tenox7/wrp:latest .
|
||||
|
||||
clean:
|
||||
rm -rf wrp-* wrp
|
||||
71
README.md
71
README.md
@@ -1,31 +1,60 @@
|
||||
# WRP - Web Rendering Proxy
|
||||
A HTTP proxy server that allows to use historical and obsolete web browsers on the modern web. It works by rendering the web page in to a GIF/PNG/JPEG image associated with clickable imagemap of original web links.
|
||||
|
||||
New: Version 2.1 brings support for sslstrip to allow browsing https/SSL/TSL websites
|
||||
A HTTP proxy server that allows to use historical / vintage web browsers on the modern web. It works by rendering a web page in to GIF image with ISMAP.
|
||||
|
||||

|
||||
|
||||
# Current Status
|
||||
* SSL/TLS stripping is delegated to `sslstrip`[1], which you need to install into your PATH first
|
||||
* I'm also looking for moving away from WebKit, QT and Python
|
||||
* Stay tuned
|
||||
## Current Status
|
||||
|
||||
## OS Support
|
||||
WRP works on macOS (Mac OS X), Linux and FreeBSD. On macOS it uses Cocoa Webkit, on Linux/FreeBSD QT Webkit, for which needs PyQT4 or PyQT5.
|
||||
* This is a new version using GoLang/[ChromeDP](https://github.com/chromedp/chromedp) (Python/Webkit is now deprecated).
|
||||
* Fully supported an maintained.
|
||||
* Works as browser-in-browser. A real http proxy mode is being investigated. Check [issue #35](https://github.com/tenox7/wrp/issues/35) for updates.
|
||||
* Supports clicking on non-link elements (eg. cookie warnings, dropdown menus, etc.) and sending keystrokes. Yes, you can login to Gmail.
|
||||
|
||||
## Installation
|
||||
* macOS - should just work
|
||||
* Linux/FreeBSD install `python-pyqt5.qtwebkit`
|
||||
* For sslstrip install `sslstrip`
|
||||
* For PythonMagick (Imagemagick library) install `python-pythonmagick`
|
||||
## Usage
|
||||
|
||||
## Configuration
|
||||
Edit wrp.py, scroll past Copyright section to find config parameters
|
||||
1. [Download a WRP binary](https://github.com/tenox7/wrp/releases/) and run it on a machine that will become your WRP gateway server.
|
||||
2. Point your legacy browser to `http://address:port` of WRP server. Do not set or use it as a "Proxy Server" (yet).
|
||||
3. Type a search string or a http/https URL and click Go.
|
||||
4. Adjust your screen width/height/scale/#colors to fit in your old browser.
|
||||
5. Scroll web page by clicking on the in-image scroll bar.
|
||||
6. Do not use client browser history-back, instead use Bk WRP button.
|
||||
7. To send keystrokes fill K input box and press Go. There also are buttons for backspace, enter and arrow keys.
|
||||
|
||||
## Usage
|
||||
Configure your web browser to use HTTP proxy at IP address and port where WRP is running. If using browsers prior to HTML 3.2, ISMAP option may need to be enabled. Check configuration.
|
||||
## Docker
|
||||
|
||||
## More info and screenshots
|
||||
* http://virtuallyfun.superglobalmegacorp.com/2014/03/11/web-rendering-proxy-update/
|
||||
* http://virtuallyfun.superglobalmegacorp.com/2014/03/03/surfing-modern-web-with-ancient-browsers/
|
||||
```
|
||||
docker run -d -p 8080:8080 --name wrp --restart unless-stopped tenox7/wrp
|
||||
```
|
||||
|
||||
[1]: https://moxie.org/software/sslstrip/
|
||||
## Flags
|
||||
|
||||
```
|
||||
-l listen address:port, default :8080
|
||||
-h headed mode, display browser window
|
||||
-d chromedp debug logging
|
||||
```
|
||||
|
||||
## Minimal Requirements
|
||||
|
||||
- Server / Gateway should run on a modern hardware/os that supports memory hungry Chrome.
|
||||
|
||||
- Client / Browser needs to support HTML FORMs and ISMAP. Typically Mosaic 2.0 would be minimum version for forms. However ISMAP was supported since 0.6B, so if you manually enter url using `?url=...` you can use ealier version.
|
||||
|
||||
## History
|
||||
* In 2014, version 1.0 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/).
|
||||
* Later in 2014, version 2.0 became a stand alone http-proxy server, also support for both Linux/MacOS, [another post](https://virtuallyfun.com/wordpress/2014/03/11/web-rendering-proxy-update//).
|
||||
* In 2016 the whole internet migrated to HTTPS/SSL/TLS and WRP largely stopped working. Python code became unmaintainable and mostly unportable (especially to Windows, even WSL).
|
||||
* In 2019 WRP 3.0 has been rewritten in Golang/Chromedp as browser-in-browser instead of http proxy.
|
||||
* Later in 2019, WRP 4.0 has been completely refactored to use mouse clicks instead using a href nodes. Also in 4.1 added sending keystrokes in to input boxes. You can now login to Gmail. Also now runs as a Docker container.
|
||||
|
||||
## Credits
|
||||
* Uses [chromedp](https://github.com/chromedp), thanks to [mvdan](https://github.com/mvdan) for dealing with my issues
|
||||
* 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
|
||||
|
||||
## Legal Stuff
|
||||
License: Apache 2.0
|
||||
Copyright (c) 2013-2018 Antoni Sawicki
|
||||
Copyright (c) 2019 Google LLC
|
||||
|
||||
17
make.ps1
Normal file
17
make.ps1
Normal file
@@ -0,0 +1,17 @@
|
||||
param (
|
||||
[switch]$clean = $false
|
||||
)
|
||||
$env:GOARCH="amd64"
|
||||
foreach($sys in ("amd64-linux", "arm-linux", "amd64-freebsd", "amd64-openbsd", "amd64-darwin", "amd64-windows")) {
|
||||
$cpu,$os = $sys.split('-')
|
||||
$env:GOARCH=$cpu
|
||||
$env:GOOS=$os
|
||||
$o="wrp-$cpu-$(if ($os -eq "windows") {$os="windows.exe"} elseif ($os -eq "darwin") { $os="macos" })$os"
|
||||
Remove-Item -ErrorAction Ignore $o
|
||||
if (!$clean) {
|
||||
$cmd = "& go build -a -o $o wrp.go"
|
||||
Write-Host $cmd
|
||||
Invoke-Expression $cmd
|
||||
}
|
||||
}
|
||||
|
||||
9
old/README
Normal file
9
old/README
Normal file
@@ -0,0 +1,9 @@
|
||||
Historical versions of WRP and prior art
|
||||
|
||||
License: GNU
|
||||
|
||||
Copyright (c) 2013-2018 Antoni Sawicki
|
||||
Copyright (c) 2012-2013 picidae.net
|
||||
Copyright (c) 2004-2013 Paul Hammond
|
||||
Copyright (c) 2017-2018 Natalia Portillo
|
||||
Copyright (c) 2018 //gir.st/
|
||||
392
old/picidae.py
Normal file
392
old/picidae.py
Normal file
@@ -0,0 +1,392 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# picidae.py - makes screenshots of webpages
|
||||
# and analyzes the webpage structure and writes image-maps of the links
|
||||
# as well as forms that are placed on the exact position of the old form.
|
||||
# It is a part of the art project www.picidae.net
|
||||
# http://www.picidae.net
|
||||
|
||||
#
|
||||
# This script is based on webkit2png from Paul Hammond.
|
||||
# It was extended by picidae.net
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
__version__ = "1.0"
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
#print "hello ... "
|
||||
|
||||
|
||||
try:
|
||||
import Foundation
|
||||
import WebKit
|
||||
import AppKit
|
||||
import objc
|
||||
import urllib
|
||||
except ImportError:
|
||||
print "Cannot find pyobjc library files. Are you sure it is installed?"
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#try:
|
||||
# from optparse import OptionParser
|
||||
#except ImportError:
|
||||
# print "OptionParser not imported"
|
||||
# sys.exit()
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
|
||||
class AppDelegate (Foundation.NSObject):
|
||||
# what happens when the app starts up
|
||||
def applicationDidFinishLaunching_(self, aNotification):
|
||||
webview = aNotification.object().windows()[0].contentView()
|
||||
webview.frameLoadDelegate().getURL(webview)
|
||||
|
||||
|
||||
class WebkitLoad (Foundation.NSObject, WebKit.protocols.WebFrameLoadDelegate):
|
||||
# what happens if something goes wrong while loading
|
||||
def webView_didFailLoadWithError_forFrame_(self,webview,error,frame):
|
||||
print " ... something went wrong 1"
|
||||
self.getURL(webview)
|
||||
def webView_didFailProvisionalLoadWithError_forFrame_(self,webview,error,frame):
|
||||
print " ... something went wrong 2"
|
||||
self.getURL(webview)
|
||||
|
||||
def makeFilename(self,URL,options):
|
||||
# make the filename
|
||||
if options.filename:
|
||||
filename = options.filename
|
||||
elif options.md5:
|
||||
try:
|
||||
import md5
|
||||
except ImportError:
|
||||
print "--md5 requires python md5 library"
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
filename = md5.new(URL).hexdigest()
|
||||
else:
|
||||
import re
|
||||
filename = re.sub('\W','',URL);
|
||||
filename = re.sub('^http','',filename);
|
||||
if options.datestamp:
|
||||
import time
|
||||
now = time.strftime("%Y%m%d")
|
||||
filename = now + "-" + filename
|
||||
import os
|
||||
dir = os.path.abspath(os.path.expanduser(options.dir))
|
||||
return os.path.join(dir,filename)
|
||||
|
||||
def saveImages(self,bitmapdata,filename,options):
|
||||
# save the fullsize png
|
||||
if options.fullsize:
|
||||
bitmapdata.representationUsingType_properties_(AppKit.NSPNGFileType,None).writeToFile_atomically_(filename + ".png",objc.YES)
|
||||
|
||||
if options.thumb or options.clipped:
|
||||
# work out how big the thumbnail is
|
||||
width = bitmapdata.pixelsWide()
|
||||
height = bitmapdata.pixelsHigh()
|
||||
thumbWidth = (width * options.scale)
|
||||
thumbHeight = (height * options.scale)
|
||||
|
||||
# make the thumbnails in a scratch image
|
||||
scratch = AppKit.NSImage.alloc().initWithSize_(
|
||||
Foundation.NSMakeSize(thumbWidth,thumbHeight))
|
||||
scratch.lockFocus()
|
||||
AppKit.NSGraphicsContext.currentContext().setImageInterpolation_(
|
||||
AppKit.NSImageInterpolationHigh)
|
||||
thumbRect = Foundation.NSMakeRect(0.0, 0.0, thumbWidth, thumbHeight)
|
||||
clipRect = Foundation.NSMakeRect(0.0,
|
||||
thumbHeight-options.clipheight,
|
||||
options.clipwidth, options.clipheight)
|
||||
bitmapdata.drawInRect_(thumbRect)
|
||||
thumbOutput = AppKit.NSBitmapImageRep.alloc().initWithFocusedViewRect_(thumbRect)
|
||||
clipOutput = AppKit.NSBitmapImageRep.alloc().initWithFocusedViewRect_(clipRect)
|
||||
scratch.unlockFocus()
|
||||
|
||||
# save the thumbnails as pngs
|
||||
if options.thumb:
|
||||
thumbOutput.representationUsingType_properties_(
|
||||
AppKit.NSPNGFileType,None
|
||||
).writeToFile_atomically_(filename + "-thumb.png",objc.YES)
|
||||
if options.clipped:
|
||||
clipOutput.representationUsingType_properties_(
|
||||
AppKit.NSPNGFileType,None
|
||||
).writeToFile_atomically_(filename + "-clipped.png",objc.YES)
|
||||
|
||||
def getURL(self,webview):
|
||||
if self.urls:
|
||||
if self.urls[0] == '-':
|
||||
url = sys.stdin.readline().rstrip()
|
||||
if not url: AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
else:
|
||||
url = self.urls.pop(0)
|
||||
else:
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
#print "<urlcall href=\"\" />", url, "..."
|
||||
#print "<urlcall href=\"%s\" />" % (url)
|
||||
self.resetWebview(webview)
|
||||
webview.mainFrame().loadRequest_(Foundation.NSURLRequest.requestWithURL_(Foundation.NSURL.URLWithString_(url)))
|
||||
if not webview.mainFrame().provisionalDataSource():
|
||||
print "<nosuccess />"
|
||||
self.getURL(webview)
|
||||
|
||||
def resetWebview(self,webview):
|
||||
rect = Foundation.NSMakeRect(0,0,self.options.initWidth,self.options.initHeight)
|
||||
webview.window().setContentSize_((self.options.initWidth,self.options.initHeight))
|
||||
webview.setFrame_(rect)
|
||||
|
||||
def resizeWebview(self,view):
|
||||
view.window().display()
|
||||
view.window().setContentSize_(view.bounds().size)
|
||||
view.setFrame_(view.bounds())
|
||||
|
||||
def captureView(self,view):
|
||||
view.lockFocus()
|
||||
bitmapdata = AppKit.NSBitmapImageRep.alloc()
|
||||
bitmapdata.initWithFocusedViewRect_(view.bounds())
|
||||
view.unlockFocus()
|
||||
return bitmapdata
|
||||
|
||||
# what happens when the page has finished loading
|
||||
def webView_didFinishLoadForFrame_(self,webview,frame):
|
||||
# don't care about subframes
|
||||
if (frame == webview.mainFrame()):
|
||||
view = frame.frameView().documentView()
|
||||
|
||||
self.resizeWebview(view)
|
||||
|
||||
URL = frame.dataSource().initialRequest().URL().absoluteString()
|
||||
filename = self.makeFilename(URL, self.options)
|
||||
|
||||
bitmapdata = self.captureView(view)
|
||||
self.saveImages(bitmapdata,filename,self.options)
|
||||
|
||||
# ----------------------------------
|
||||
# picidae my stuff
|
||||
|
||||
|
||||
#print "url"
|
||||
print "<page>"
|
||||
print frame.dataSource().request().URL().absoluteString()
|
||||
print "</page>"
|
||||
|
||||
|
||||
# Analyse HTML and get links
|
||||
xmloutput = "<map name=\"map\">\r";
|
||||
|
||||
domdocument = frame.DOMDocument()
|
||||
domnodelist = domdocument.getElementsByTagName_('A')
|
||||
i = 0
|
||||
while i < domnodelist.length():
|
||||
# linkvalue
|
||||
value = domnodelist.item_(i).valueForKey_('href')
|
||||
|
||||
# position-rect
|
||||
myrect = domnodelist.item_(i).boundingBox()
|
||||
|
||||
xmin = Foundation.NSMinX(myrect)
|
||||
ymin = Foundation.NSMinY(myrect)
|
||||
xmax = Foundation.NSMaxX(myrect)
|
||||
ymax = Foundation.NSMaxY(myrect)
|
||||
|
||||
# print Link
|
||||
prefix = ""
|
||||
xmloutput += "<area shape=\"rect\" coords=\"%i,%i,%i,%i\" alt=\"\"><![CDATA[%s%s]]></area>\r" % (xmin, ymin, xmax, ymax, prefix, value)
|
||||
i += 1
|
||||
|
||||
#print "</map>"
|
||||
xmloutput += "</map>"
|
||||
f = open(filename +'.xml', 'w+')
|
||||
f.write(xmloutput)
|
||||
f.close()
|
||||
|
||||
# ----------------------------------
|
||||
# get forms
|
||||
xmloutput = "<forms>\r";
|
||||
xmloutput += "<page><![CDATA["
|
||||
xmloutput += frame.dataSource().request().URL().absoluteString()
|
||||
xmloutput += "]]></page>\r"
|
||||
|
||||
domdocument = frame.DOMDocument()
|
||||
domnodelist = domdocument.getElementsByTagName_('form')
|
||||
i = 0
|
||||
while i < domnodelist.length():
|
||||
# form
|
||||
action = domnodelist.item_(i).valueForKey_('action')
|
||||
method = domnodelist.item_(i).valueForKey_('method')
|
||||
xmloutput += "<form method=\"%s\" ><action><![CDATA[%s]]></action>\r" % (method, action)
|
||||
|
||||
# form fields
|
||||
fieldlist = domnodelist.item_(i).getElementsByTagName_('input')
|
||||
j=0
|
||||
while j < fieldlist.length():
|
||||
# values
|
||||
type = fieldlist.item_(j).valueForKey_('type')
|
||||
name = fieldlist.item_(j).valueForKey_('name')
|
||||
formvalue = fieldlist.item_(j).valueForKey_('value')
|
||||
size = fieldlist.item_(j).valueForKey_('size')
|
||||
checked = fieldlist.item_(j).valueForKey_('checked')
|
||||
# write output
|
||||
xmloutput += "\t<input "
|
||||
if (type):
|
||||
xmloutput += "type=\"%s\" " % (type)
|
||||
if (name):
|
||||
xmloutput += "name=\"%s\" " % (name)
|
||||
if (size):
|
||||
xmloutput += "size=\"%s\" " % (size)
|
||||
if (type and type != "hidden"):
|
||||
myrect = fieldlist.item_(j).boundingBox()
|
||||
xmin = Foundation.NSMinX(myrect)
|
||||
ymin = Foundation.NSMinY(myrect)
|
||||
xmax = Foundation.NSMaxX(myrect)
|
||||
ymax = Foundation.NSMaxY(myrect)
|
||||
height = ymax - ymin
|
||||
width = xmax - xmin
|
||||
if (type == "radio" or type == "checkbox"):
|
||||
xmin -= 3
|
||||
ymin -= 3
|
||||
xmloutput += "style=\"position:absolute;top:%i;left:%i;width:%i;height:%i;\" " % (ymin, xmin, width, height)
|
||||
if (checked):
|
||||
xmloutput += "checked=\"%s\" " % (checked)
|
||||
xmloutput += "><![CDATA["
|
||||
if (formvalue and type!="text" and type!="password"):
|
||||
#xmloutput += urllib.quote(formvalue)
|
||||
dummy=10
|
||||
xmloutput += "]]></input>\r"
|
||||
j += 1
|
||||
xmloutput += "</form>\r"
|
||||
i += 1
|
||||
|
||||
xmloutput += "</forms>"
|
||||
f = open(filename +'.form.xml', 'w+')
|
||||
f.write(xmloutput)
|
||||
f.close()
|
||||
|
||||
|
||||
# End picidae
|
||||
# ----------------------------------
|
||||
|
||||
|
||||
#print " ... done"
|
||||
self.getURL(webview)
|
||||
|
||||
#trying to give back the real url
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
# parse the command line
|
||||
usage = """%prog [options] [http://example.net/ ...]
|
||||
|
||||
examples:
|
||||
%prog http://google.com/ # screengrab google
|
||||
%prog -W 1000 -H 1000 http://google.com/ # bigger screengrab of google
|
||||
%prog -T http://google.com/ # just the thumbnail screengrab
|
||||
%prog -TF http://google.com/ # just thumbnail and fullsize grab
|
||||
%prog -o foo http://google.com/ # save images as "foo-thumb.png" etc
|
||||
%prog - # screengrab urls from stdin"""
|
||||
|
||||
cmdparser = OptionParser(usage, version=("webkit2png "+__version__))
|
||||
# TODO: add quiet/verbose options
|
||||
cmdparser.add_option("-W", "--width",type="float",default=800.0,
|
||||
help="initial (and minimum) width of browser (default: 800)")
|
||||
cmdparser.add_option("-H", "--height",type="float",default=600.0,
|
||||
help="initial (and minimum) height of browser (default: 600)")
|
||||
cmdparser.add_option("--clipwidth",type="float",default=200.0,
|
||||
help="width of clipped thumbnail (default: 200)",
|
||||
metavar="WIDTH")
|
||||
cmdparser.add_option("--clipheight",type="float",default=150.0,
|
||||
help="height of clipped thumbnail (default: 150)",
|
||||
metavar="HEIGHT")
|
||||
cmdparser.add_option("-s", "--scale",type="float",default=0.25,
|
||||
help="scale factor for thumbnails (default: 0.25)")
|
||||
cmdparser.add_option("-m", "--md5", action="store_true",
|
||||
help="use md5 hash for filename (like del.icio.us)")
|
||||
cmdparser.add_option("-o", "--filename", type="string",default="",
|
||||
metavar="NAME", help="save images as NAME.png,NAME-thumb.png etc")
|
||||
cmdparser.add_option("-F", "--fullsize", action="store_true",
|
||||
help="only create fullsize screenshot")
|
||||
cmdparser.add_option("-T", "--thumb", action="store_true",
|
||||
help="only create thumbnail sreenshot")
|
||||
cmdparser.add_option("-C", "--clipped", action="store_true",
|
||||
help="only create clipped thumbnail screenshot")
|
||||
cmdparser.add_option("-d", "--datestamp", action="store_true",
|
||||
help="include date in filename")
|
||||
cmdparser.add_option("-D", "--dir",type="string",default="./",
|
||||
help="directory to place images into")
|
||||
(options, args) = cmdparser.parse_args()
|
||||
if len(args) == 0:
|
||||
cmdparser.print_help()
|
||||
return
|
||||
if options.filename:
|
||||
if len(args) != 1 or args[0] == "-":
|
||||
print "--filename option requires exactly one url"
|
||||
return
|
||||
if options.scale == 0:
|
||||
cmdparser.error("scale cannot be zero")
|
||||
# make sure we're outputing something
|
||||
if not (options.fullsize or options.thumb or options.clipped):
|
||||
options.fullsize = True
|
||||
options.thumb = True
|
||||
options.clipped = True
|
||||
# work out the initial size of the browser window
|
||||
# (this might need to be larger so clipped image is right size)
|
||||
options.initWidth = (options.clipwidth / options.scale)
|
||||
options.initHeight = (options.clipheight / options.scale)
|
||||
if options.width>options.initWidth:
|
||||
options.initWidth = options.width
|
||||
if options.height>options.initHeight:
|
||||
options.initHeight = options.height
|
||||
|
||||
|
||||
app = AppKit.NSApplication.sharedApplication()
|
||||
|
||||
# create an app delegate
|
||||
delegate = AppDelegate.alloc().init()
|
||||
AppKit.NSApp().setDelegate_(delegate)
|
||||
|
||||
# create a window
|
||||
rect = Foundation.NSMakeRect(-16000,-16000,100,100)
|
||||
win = AppKit.NSWindow.alloc()
|
||||
win.initWithContentRect_styleMask_backing_defer_ (rect,
|
||||
AppKit.NSBorderlessWindowMask, 2, 0)
|
||||
|
||||
# create a webview object
|
||||
webview = WebKit.WebView.alloc()
|
||||
webview.initWithFrame_(rect)
|
||||
# turn off scrolling so the content is actually x wide and not x-15
|
||||
webview.mainFrame().frameView().setAllowsScrolling_(objc.NO)
|
||||
# add the webview to the window
|
||||
win.setContentView_(webview)
|
||||
|
||||
|
||||
# create a LoadDelegate
|
||||
loaddelegate = WebkitLoad.alloc().init()
|
||||
loaddelegate.options = options
|
||||
loaddelegate.urls = args
|
||||
webview.setFrameLoadDelegate_(loaddelegate)
|
||||
|
||||
app.run()
|
||||
|
||||
if __name__ == '__main__' : main()
|
||||
|
||||
506
old/webkit2png.py
Normal file
506
old/webkit2png.py
Normal file
@@ -0,0 +1,506 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# webkit2png - makes screenshots of web pages
|
||||
# http://www.paulhammond.org/webkit2png
|
||||
|
||||
__version__ = "dev"
|
||||
|
||||
# Copyright (c) 2004-2013 Paul Hammond
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
import re
|
||||
import os
|
||||
|
||||
try:
|
||||
import Foundation
|
||||
import WebKit
|
||||
import AppKit
|
||||
import Quartz
|
||||
import objc
|
||||
except ImportError:
|
||||
print "Cannot find pyobjc library files. Are you sure it is installed?"
|
||||
sys.exit()
|
||||
|
||||
|
||||
class AppDelegate(Foundation.NSObject):
|
||||
# what happens when the app starts up
|
||||
def applicationDidFinishLaunching_(self, aNotification):
|
||||
webview = aNotification.object().windows()[0].contentView()
|
||||
webview.frameLoadDelegate().getURL(webview)
|
||||
self.performSelector_withObject_afterDelay_("timeout:", None,
|
||||
self.timeout)
|
||||
|
||||
def timeout_(self, obj):
|
||||
Foundation.NSLog("timed out!")
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
|
||||
|
||||
class Webkit2PngScriptBridge(Foundation.NSObject):
|
||||
def init(self):
|
||||
self = super(Webkit2PngScriptBridge, self).init()
|
||||
self.is_stopped = False
|
||||
self.start_callback = False
|
||||
return self
|
||||
|
||||
def stop(self):
|
||||
self.is_stopped = True
|
||||
|
||||
def start(self):
|
||||
self.is_stopped = False
|
||||
self.start_callback()
|
||||
|
||||
def isSelectorExcludedFromWebScript_(self, sel):
|
||||
if sel in ['stop', 'start']:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class WebkitLoad (Foundation.NSObject, WebKit.protocols.WebFrameLoadDelegate):
|
||||
|
||||
# what happens if something goes wrong while loading
|
||||
def webView_didFailLoadWithError_forFrame_(self, webview, error, frame):
|
||||
if error.code() == Foundation.NSURLErrorCancelled:
|
||||
return
|
||||
print " ... something went wrong: "+error.localizedDescription()
|
||||
self.getURL(webview)
|
||||
|
||||
def webView_didFailProvisionalLoadWithError_forFrame_(self, webview, error,
|
||||
frame):
|
||||
if error.code() == Foundation.NSURLErrorCancelled:
|
||||
return
|
||||
print " ... something went wrong: "+error.localizedDescription()
|
||||
self.getURL(webview)
|
||||
|
||||
def makeFilename(self, URL, options):
|
||||
# make the filename
|
||||
if options.filename:
|
||||
filename = options.filename
|
||||
elif options.md5:
|
||||
try:
|
||||
import md5
|
||||
except ImportError:
|
||||
print "--md5 requires python md5 library"
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
filename = md5.new(URL).hexdigest()
|
||||
else:
|
||||
filename = re.sub('^https?', '', URL)
|
||||
filename = re.sub('\W', '', filename)
|
||||
if options.datestamp:
|
||||
import time
|
||||
now = time.strftime("%Y%m%d")
|
||||
filename = now + "-" + filename
|
||||
dir = os.path.abspath(os.path.expanduser(options.dir))
|
||||
if not os.path.exists(options.dir):
|
||||
os.makedirs(dir)
|
||||
return os.path.join(dir, filename)
|
||||
|
||||
def saveImages(self, bitmapdata, filename, options):
|
||||
# save the fullsize png
|
||||
if options.fullsize:
|
||||
bitmapdata.representationUsingType_properties_(
|
||||
AppKit.NSPNGFileType,
|
||||
None
|
||||
).writeToFile_atomically_(filename + "-full.png", objc.YES)
|
||||
|
||||
if options.thumb or options.clipped:
|
||||
# work out how big the thumbnail is
|
||||
width = bitmapdata.pixelsWide()
|
||||
height = bitmapdata.pixelsHigh()
|
||||
thumbWidth = (width * options.scale)
|
||||
thumbHeight = (height * options.scale)
|
||||
|
||||
# make the thumbnails in a scratch image
|
||||
scratch = AppKit.NSImage.alloc().initWithSize_(
|
||||
Foundation.NSMakeSize(thumbWidth, thumbHeight))
|
||||
scratch.lockFocus()
|
||||
AppKit.NSGraphicsContext.currentContext().setImageInterpolation_(
|
||||
AppKit.NSImageInterpolationHigh)
|
||||
thumbRect = Foundation.NSMakeRect(0.0, 0.0, thumbWidth,
|
||||
thumbHeight)
|
||||
clipRect = Foundation.NSMakeRect(
|
||||
0.0,
|
||||
thumbHeight-options.clipheight,
|
||||
options.clipwidth,
|
||||
options.clipheight)
|
||||
bitmapdata.drawInRect_(thumbRect)
|
||||
thumbOutput = AppKit.NSBitmapImageRep.alloc()\
|
||||
.initWithFocusedViewRect_(thumbRect)
|
||||
clipOutput = AppKit.NSBitmapImageRep.alloc()\
|
||||
.initWithFocusedViewRect_(clipRect)
|
||||
scratch.unlockFocus()
|
||||
|
||||
# save the thumbnails as pngs
|
||||
if options.thumb:
|
||||
thumbOutput.representationUsingType_properties_(
|
||||
AppKit.NSPNGFileType, None).writeToFile_atomically_(
|
||||
filename + "-thumb.png", objc.YES)
|
||||
if options.clipped:
|
||||
clipOutput.representationUsingType_properties_(
|
||||
AppKit.NSPNGFileType, None).writeToFile_atomically_(
|
||||
filename + "-clipped.png", objc.YES)
|
||||
|
||||
def getURL(self, webview):
|
||||
if self.urls:
|
||||
if self.urls[0] == '-':
|
||||
url = sys.stdin.readline().rstrip()
|
||||
if not url:
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
else:
|
||||
url = self.urls.pop(0)
|
||||
else:
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
|
||||
nsurl = Foundation.NSURL.URLWithString_(url)
|
||||
if not (nsurl and nsurl.scheme()):
|
||||
nsurl = Foundation.NSURL.alloc().initFileURLWithPath_(url)
|
||||
nsurl = nsurl.absoluteURL()
|
||||
|
||||
if self.options.ignore_ssl_check:
|
||||
Foundation.NSURLRequest.setAllowsAnyHTTPSCertificate_forHost_(objc.YES, nsurl.host())
|
||||
|
||||
print "Fetching", nsurl, "..."
|
||||
self.resetWebview(webview)
|
||||
scriptobject = webview.windowScriptObject()
|
||||
scriptobject.setValue_forKey_(Webkit2PngScriptBridge.alloc().init(),
|
||||
'webkit2png')
|
||||
|
||||
webview.mainFrame().loadRequest_(Foundation.NSURLRequest.requestWithURL_(nsurl))
|
||||
if not webview.mainFrame().provisionalDataSource():
|
||||
print " ... not a proper url?"
|
||||
self.getURL(webview)
|
||||
|
||||
def resetWebview(self, webview):
|
||||
rect = Foundation.NSMakeRect(0, 0, self.options.initWidth,
|
||||
self.options.initHeight)
|
||||
window = webview.window()
|
||||
window.setContentSize_((self.options.initWidth,
|
||||
self.options.initHeight))
|
||||
|
||||
if self.options.transparent:
|
||||
window.setOpaque_(objc.NO)
|
||||
window.setBackgroundColor_(AppKit.NSColor.clearColor())
|
||||
webview.setDrawsBackground_(objc.NO)
|
||||
|
||||
webview.setFrame_(rect)
|
||||
|
||||
def captureView(self, view):
|
||||
bounds = view.bounds()
|
||||
if bounds.size.height > self.options.UNSAFE_max_height:
|
||||
print >> sys.stderr, "Error: page height greater than %s, " \
|
||||
"clipping to avoid crashing windowserver." % \
|
||||
self.options.UNSAFE_max_height
|
||||
bounds.size.height = self.options.UNSAFE_max_height
|
||||
if bounds.size.width > self.options.UNSAFE_max_width:
|
||||
print >> sys.stderr, "Error: page width greater than %s, " \
|
||||
"clipping to avoid crashing windowserver." % \
|
||||
self.options.UNSAFE_max_width
|
||||
bounds.size.width = self.options.UNSAFE_max_width
|
||||
|
||||
view.window().display()
|
||||
view.window().setContentSize_(
|
||||
Foundation.NSSize(self.options.initWidth, self.options.initHeight))
|
||||
view.setFrame_(bounds)
|
||||
|
||||
if hasattr(view, "bitmapImageRepForCachingDisplayInRect_"):
|
||||
bitmapdata = view.bitmapImageRepForCachingDisplayInRect_(bounds)
|
||||
view.cacheDisplayInRect_toBitmapImageRep_(bounds, bitmapdata)
|
||||
else:
|
||||
view.lockFocus()
|
||||
bitmapdata = AppKit.NSBitmapImageRep.alloc()
|
||||
bitmapdata.initWithFocusedViewRect_(bounds)
|
||||
view.unlockFocus()
|
||||
return bitmapdata
|
||||
|
||||
# what happens when the page has finished loading
|
||||
def webView_didFinishLoadForFrame_(self, webview, frame):
|
||||
# don't care about subframes
|
||||
if (frame == webview.mainFrame()):
|
||||
scriptobject = webview.windowScriptObject()
|
||||
if self.options.js:
|
||||
scriptobject.evaluateWebScript_(self.options.js)
|
||||
|
||||
bridge = scriptobject.valueForKey_('webkit2png')
|
||||
|
||||
def doGrab():
|
||||
Foundation.NSTimer.\
|
||||
scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
|
||||
self.options.delay, self, self.doGrab, webview, False)
|
||||
|
||||
if bridge.is_stopped:
|
||||
bridge.start_callback = doGrab
|
||||
else:
|
||||
doGrab()
|
||||
|
||||
def doGrab(self, timer):
|
||||
webview = timer.userInfo()
|
||||
frame = webview.mainFrame()
|
||||
view = frame.frameView().documentView()
|
||||
|
||||
URL = webview.mainFrame().dataSource().initialRequest().URL()\
|
||||
.absoluteString()
|
||||
filename = self.makeFilename(URL, self.options)
|
||||
|
||||
bitmapdata = self.captureView(view)
|
||||
|
||||
if self.options.selector:
|
||||
doc = frame.DOMDocument()
|
||||
el = doc.querySelector_(self.options.selector)
|
||||
|
||||
if not el:
|
||||
print " ... no element matching %s found?" % \
|
||||
self.options.selector
|
||||
self.getURL(webview)
|
||||
return
|
||||
|
||||
left, top = 0, 0
|
||||
parent = el
|
||||
while parent:
|
||||
left += parent.offsetLeft()
|
||||
top += parent.offsetTop()
|
||||
parent = parent.offsetParent()
|
||||
|
||||
zoom = self.options.zoom
|
||||
|
||||
cropRect = view.window().convertRectToBacking_(Foundation.NSMakeRect(
|
||||
zoom * left, zoom * top,
|
||||
zoom * el.offsetWidth(), zoom * el.offsetHeight()))
|
||||
|
||||
cropped = Quartz.CGImageCreateWithImageInRect(
|
||||
bitmapdata.CGImage(), cropRect)
|
||||
bitmapdata = AppKit.NSBitmapImageRep.alloc().initWithCGImage_(
|
||||
cropped)
|
||||
Quartz.CGImageRelease(cropped)
|
||||
|
||||
self.saveImages(bitmapdata, filename, self.options)
|
||||
|
||||
print " ... done"
|
||||
self.getURL(webview)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
# parse the command line
|
||||
usage = """%prog [options] [http://example.net/ ...]
|
||||
|
||||
Examples:
|
||||
%prog http://google.com/ # screengrab google
|
||||
%prog -W 1000 -H 1000 http://google.com/ # bigger screengrab of google
|
||||
%prog -T http://google.com/ # just the thumbnail screengrab
|
||||
%prog -TF http://google.com/ # just thumbnail and fullsize grab
|
||||
%prog -o foo http://google.com/ # save images as "foo-thumb.png" etc
|
||||
%prog - # screengrab urls from stdin
|
||||
%prog /path/to/file.html # screengrab local html file
|
||||
%prog -h | less # full documentation"""
|
||||
|
||||
cmdparser = optparse.OptionParser(usage,
|
||||
version=("webkit2png " + __version__))
|
||||
# TODO: add quiet/verbose options
|
||||
cmdparser.add_option("--debug", action="store_true",
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
|
||||
# warning: setting these too high can crash your window server
|
||||
cmdparser.add_option("--UNSAFE-max-height", type="int", default=30000,
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
cmdparser.add_option("--UNSAFE-max-width", type="int", default=30000,
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
|
||||
group = optparse.OptionGroup(cmdparser, "Network Options")
|
||||
group.add_option("--timeout", type="float", default=60.0,
|
||||
help="page load timeout (default: 60)")
|
||||
group.add_option("--user-agent", type="string", default=False,
|
||||
help="set user agent header")
|
||||
group.add_option("--ignore-ssl-check", action="store_true", default=False,
|
||||
help="ignore SSL Certificate name mismatches")
|
||||
cmdparser.add_option_group(group)
|
||||
|
||||
group = optparse.OptionGroup(cmdparser, "Browser Window Options")
|
||||
group.add_option(
|
||||
"-W", "--width", type="float", default=800.0,
|
||||
help="initial (and minimum) width of browser (default: 800)")
|
||||
group.add_option(
|
||||
"-H", "--height", type="float", default=600.0,
|
||||
help="initial (and minimum) height of browser (default: 600)")
|
||||
group.add_option(
|
||||
"-z", "--zoom", type="float", default=1.0,
|
||||
help='zoom level of browser, equivalent to "Zoom In" and "Zoom Out" '
|
||||
'in "View" menu (default: 1.0)')
|
||||
group.add_option(
|
||||
"--selector", type="string",
|
||||
help="CSS selector for a single element to capture (first matching "
|
||||
"element will be used)")
|
||||
cmdparser.add_option_group(group)
|
||||
|
||||
group = optparse.OptionGroup(cmdparser, "Output size options")
|
||||
group.add_option(
|
||||
"-F", "--fullsize", action="store_true",
|
||||
help="only create fullsize screenshot")
|
||||
group.add_option(
|
||||
"-T", "--thumb", action="store_true",
|
||||
help="only create thumbnail sreenshot")
|
||||
group.add_option(
|
||||
"-C", "--clipped", action="store_true",
|
||||
help="only create clipped thumbnail screenshot")
|
||||
group.add_option(
|
||||
"--clipwidth", type="float", default=200.0,
|
||||
help="width of clipped thumbnail (default: 200)",
|
||||
metavar="WIDTH")
|
||||
group.add_option(
|
||||
"--clipheight", type="float", default=150.0,
|
||||
help="height of clipped thumbnail (default: 150)",
|
||||
metavar="HEIGHT")
|
||||
group.add_option(
|
||||
"-s", "--scale", type="float", default=0.25,
|
||||
help="scale factor for thumbnails (default: 0.25)")
|
||||
cmdparser.add_option_group(group)
|
||||
|
||||
group = optparse.OptionGroup(cmdparser, "Output filename options")
|
||||
group.add_option(
|
||||
"-D", "--dir", type="string", default="./",
|
||||
help="directory to place images into")
|
||||
group.add_option(
|
||||
"-o", "--filename", type="string", default="",
|
||||
metavar="NAME", help="save images as NAME-full.png,NAME-thumb.png etc")
|
||||
group.add_option(
|
||||
"-m", "--md5", action="store_true",
|
||||
help="use md5 hash for filename (like del.icio.us)")
|
||||
group.add_option(
|
||||
"-d", "--datestamp", action="store_true",
|
||||
help="include date in filename")
|
||||
cmdparser.add_option_group(group)
|
||||
|
||||
group = optparse.OptionGroup(cmdparser, "Web page functionality")
|
||||
group.add_option(
|
||||
"--delay", type="float", default=0,
|
||||
help="delay between page load finishing and screenshot")
|
||||
group.add_option(
|
||||
"--js", type="string", default=None,
|
||||
help="JavaScript to execute when the window finishes loading"
|
||||
"(example: --js='document.bgColor=\"red\";'). "
|
||||
"If you need to wait for asynchronous code to finish before "
|
||||
"capturing the screenshot, call webkit2png.stop() before the "
|
||||
"async code runs, then webkit2png.start() to capture the image.")
|
||||
group.add_option(
|
||||
"--noimages", action="store_true",
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
group.add_option(
|
||||
"--no-images", action="store_true",
|
||||
help="don't load images")
|
||||
group.add_option(
|
||||
"--nojs", action="store_true",
|
||||
help=optparse.SUPPRESS_HELP)
|
||||
group.add_option(
|
||||
"--no-js", action="store_true",
|
||||
help="disable JavaScript support")
|
||||
group.add_option(
|
||||
"--transparent", action="store_true",
|
||||
help="render output on a transparent background (requires a web "
|
||||
"page with a transparent background)", default=False)
|
||||
cmdparser.add_option_group(group)
|
||||
|
||||
(options, args) = cmdparser.parse_args()
|
||||
if len(args) == 0:
|
||||
cmdparser.print_usage()
|
||||
return
|
||||
if options.filename:
|
||||
if len(args) != 1 or args[0] == "-":
|
||||
print "--filename option requires exactly one url"
|
||||
return
|
||||
|
||||
# deprecated options
|
||||
if options.nojs:
|
||||
print >> sys.stderr, 'Warning: --nojs will be removed in ' \
|
||||
'webkit2png 1.0. Please use --no-js.'
|
||||
options.no_js = True
|
||||
if options.noimages:
|
||||
print >> sys.stderr, 'Warning: --noimages will be removed in ' \
|
||||
'webkit2png 1.0. Please use --no-images.'
|
||||
options.no_images = True
|
||||
|
||||
if options.scale == 0:
|
||||
cmdparser.error("scale cannot be zero")
|
||||
# make sure we're outputing something
|
||||
if not (options.fullsize or options.thumb or options.clipped):
|
||||
options.fullsize = True
|
||||
options.thumb = True
|
||||
options.clipped = True
|
||||
# work out the initial size of the browser window
|
||||
# (this might need to be larger so clipped image is right size)
|
||||
options.initWidth = (options.clipwidth / options.scale)
|
||||
options.initHeight = (options.clipheight / options.scale)
|
||||
options.width *= options.zoom
|
||||
if options.width > options.initWidth:
|
||||
options.initWidth = options.width
|
||||
if options.height > options.initHeight:
|
||||
options.initHeight = options.height
|
||||
|
||||
# Hide the dock icon (needs to run before NSApplication.sharedApplication)
|
||||
AppKit.NSBundle.mainBundle().infoDictionary()['LSBackgroundOnly'] = '1'
|
||||
|
||||
app = AppKit.NSApplication.sharedApplication()
|
||||
|
||||
# create an app delegate
|
||||
delegate = AppDelegate.alloc().init()
|
||||
delegate.timeout = options.timeout
|
||||
AppKit.NSApp().setDelegate_(delegate)
|
||||
|
||||
# create a window
|
||||
rect = Foundation.NSMakeRect(0, 0, 100, 100)
|
||||
win = AppKit.NSWindow.alloc()
|
||||
win.initWithContentRect_styleMask_backing_defer_(
|
||||
rect, AppKit.NSBorderlessWindowMask, 2, 0)
|
||||
if options.debug:
|
||||
win.orderFrontRegardless()
|
||||
# create a webview object
|
||||
webview = WebKit.WebView.alloc()
|
||||
webview.initWithFrame_(rect)
|
||||
# turn off scrolling so the content is actually x wide and not x-15
|
||||
webview.mainFrame().frameView().setAllowsScrolling_(objc.NO)
|
||||
|
||||
if options.user_agent:
|
||||
webview.setCustomUserAgent_(options.user_agent)
|
||||
else:
|
||||
webkit_version = Foundation.NSBundle.bundleForClass_(WebKit.WebView)\
|
||||
.objectForInfoDictionaryKey_(WebKit.kCFBundleVersionKey)[1:]
|
||||
webview.setApplicationNameForUserAgent_(
|
||||
"Like-Version/6.0 Safari/%s webkit2png/%s" % (webkit_version, __version__))
|
||||
webview.setPreferencesIdentifier_('webkit2png')
|
||||
webview.preferences().setLoadsImagesAutomatically_(not options.no_images)
|
||||
webview.preferences().setJavaScriptEnabled_(not options.no_js)
|
||||
|
||||
if options.zoom != 1.0:
|
||||
webview._setZoomMultiplier_isTextOnly_(options.zoom, False)
|
||||
|
||||
# add the webview to the window
|
||||
win.setContentView_(webview)
|
||||
|
||||
# create a LoadDelegate
|
||||
loaddelegate = WebkitLoad.alloc().init()
|
||||
loaddelegate.options = options
|
||||
loaddelegate.urls = args
|
||||
webview.setFrameLoadDelegate_(loaddelegate)
|
||||
|
||||
app.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
212
old/webrender.py
Normal file
212
old/webrender.py
Normal file
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# webrender.py - recursively render web pages to a gif+imagemap of clickable links
|
||||
# caveat: this script requires to be run as a regular user and cannot run as a daemon
|
||||
# from apache cgi-bin, you can use python built in http server instead
|
||||
# usage:
|
||||
# create cgi-bin directory, copy webrender.py to cgi-bin and chmod 755
|
||||
# python -m CGIHTTPServer 8000
|
||||
# navigate web browser to http://x.x.x.x:8000/cgi-bin/webrender.py
|
||||
# the webrender-xxx.gif images are created in the CWD of the http server
|
||||
|
||||
|
||||
__version__ = "1.0"
|
||||
|
||||
#
|
||||
# This program is based on the software picidae.py 1.0 from http://www.picidae.net
|
||||
# It was modified by Antoni Sawicki
|
||||
#
|
||||
# This program is based on the software webkit2png 0.4 from Paul Hammond.
|
||||
# It was extended by picidae.net
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
try:
|
||||
import sys
|
||||
import os
|
||||
import glob
|
||||
import random
|
||||
import Foundation
|
||||
import WebKit
|
||||
import AppKit
|
||||
import objc
|
||||
import string
|
||||
import urllib
|
||||
import socket
|
||||
import cgi
|
||||
import cgitb; cgitb.enable() # for trubleshooting
|
||||
except ImportError:
|
||||
print "Cannot find pyobjc library files. Are you sure it is installed?"
|
||||
sys.exit()
|
||||
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
|
||||
class AppDelegate (Foundation.NSObject):
|
||||
# what happens when the app starts up
|
||||
def applicationDidFinishLaunching_(self, aNotification):
|
||||
webview = aNotification.object().windows()[0].contentView()
|
||||
webview.frameLoadDelegate().getURL(webview)
|
||||
|
||||
|
||||
class WebkitLoad (Foundation.NSObject, WebKit.protocols.WebFrameLoadDelegate):
|
||||
# what happens if something goes wrong while loading
|
||||
def webView_didFailLoadWithError_forFrame_(self,webview,error,frame):
|
||||
print " ... something went wrong 1: " + error.localizedDescription()
|
||||
self.getURL(webview)
|
||||
def webView_didFailProvisionalLoadWithError_forFrame_(self,webview,error,frame):
|
||||
print " ... something went wrong 2: " + error.localizedDescription()
|
||||
self.getURL(webview)
|
||||
|
||||
def getURL(self,webview):
|
||||
if self.urls:
|
||||
if self.urls[0] == '-':
|
||||
url = sys.stdin.readline().rstrip()
|
||||
if not url: AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
else:
|
||||
url = self.urls.pop(0)
|
||||
else:
|
||||
AppKit.NSApplication.sharedApplication().terminate_(None)
|
||||
|
||||
self.resetWebview(webview)
|
||||
webview.mainFrame().loadRequest_(Foundation.NSURLRequest.requestWithURL_(Foundation.NSURL.URLWithString_(url)))
|
||||
if not webview.mainFrame().provisionalDataSource():
|
||||
print "<nosuccess />"
|
||||
self.getURL(webview)
|
||||
|
||||
def resetWebview(self,webview):
|
||||
rect = Foundation.NSMakeRect(0,0,1024,768)
|
||||
webview.window().setContentSize_((1024,768))
|
||||
webview.setFrame_(rect)
|
||||
|
||||
def resizeWebview(self,view):
|
||||
view.window().display()
|
||||
view.window().setContentSize_(view.bounds().size)
|
||||
view.setFrame_(view.bounds())
|
||||
|
||||
def captureView(self,view):
|
||||
view.lockFocus()
|
||||
bitmapdata = AppKit.NSBitmapImageRep.alloc()
|
||||
bitmapdata.initWithFocusedViewRect_(view.bounds())
|
||||
view.unlockFocus()
|
||||
return bitmapdata
|
||||
|
||||
# what happens when the page has finished loading
|
||||
def webView_didFinishLoadForFrame_(self,webview,frame):
|
||||
# don't care about subframes
|
||||
if (frame == webview.mainFrame()):
|
||||
view = frame.frameView().documentView()
|
||||
|
||||
self.resizeWebview(view)
|
||||
|
||||
URL = frame.dataSource().initialRequest().URL().absoluteString()
|
||||
|
||||
for fl in glob.glob("webrender-*.gif"):
|
||||
os.remove(fl)
|
||||
|
||||
GIF = "webrender-%s.gif" % (random.randrange(0,1000))
|
||||
|
||||
bitmapdata = self.captureView(view)
|
||||
bitmapdata.representationUsingType_properties_(AppKit.NSGIFFileType,None).writeToFile_atomically_(GIF,objc.YES)
|
||||
|
||||
myurl = "http://%s:%s%s" % (socket.gethostbyname(socket.gethostname()), os.getenv("SERVER_PORT"), os.getenv("SCRIPT_NAME"))
|
||||
|
||||
print "Content-type: text/html\r\n\r\n"
|
||||
print "<!-- webrender.py by Antoni Sawicki -->"
|
||||
print "<html><head><title>Webrender - %s</title></head><body><table border=\"0\"><tr>" % (URL)
|
||||
print "<td><form action=\"%s\">" % (myurl)
|
||||
print "<input type=\"text\" name=\"url\" value=\"%s\" size=\"80\">" % (URL)
|
||||
print "<input type=\"submit\" value=\"go\">"
|
||||
print "</form></td><td>"
|
||||
print "<form action=\"%s\">" % (myurl)
|
||||
print "<input type=\"text\" name=\"search\" value=\"\" size=\"20\">"
|
||||
print "<input type=\"submit\" value=\"search\">"
|
||||
print "</form></td></tr></table>"
|
||||
print "<img src=\"../%s\" alt=\"webrender\" usemap=\"#map\" border=\"0\">" % (GIF)
|
||||
|
||||
|
||||
# Analyse HTML and get links
|
||||
print "<map name=\"map\">";
|
||||
|
||||
domdocument = frame.DOMDocument()
|
||||
domnodelist = domdocument.getElementsByTagName_('A')
|
||||
i = 0
|
||||
while i < domnodelist.length():
|
||||
# linkvalue
|
||||
value = domnodelist.item_(i).valueForKey_('href')
|
||||
|
||||
# position-rect
|
||||
myrect = domnodelist.item_(i).boundingBox()
|
||||
|
||||
xmin = Foundation.NSMinX(myrect)
|
||||
ymin = Foundation.NSMinY(myrect)
|
||||
xmax = Foundation.NSMaxX(myrect)
|
||||
ymax = Foundation.NSMaxY(myrect)
|
||||
|
||||
# print Link
|
||||
escval = string.replace( string.replace(value, "?", "TNXQUE"), "&", "TNXAMP" )
|
||||
print "<area shape=\"rect\" coords=\"%i,%i,%i,%i\" alt=\"\" href=\"%s?url=%s\"></area>" % (xmin, ymin, xmax, ymax, myurl, escval)
|
||||
i += 1
|
||||
|
||||
print "</map>"
|
||||
print "</body></html>"
|
||||
self.getURL(webview)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
# obtain url from cgi input
|
||||
form = cgi.FieldStorage()
|
||||
rawurl = form.getfirst("url", "http://www.google.com")
|
||||
rawsearch = form.getfirst("search")
|
||||
if rawsearch:
|
||||
url = "http://www.google.com/search?q=%s" % (rawsearch)
|
||||
else:
|
||||
url = string.replace( string.replace(rawurl, "TNXAMP", "&"), "TNXQUE", "?")
|
||||
|
||||
|
||||
AppKit.NSApplicationLoad();
|
||||
|
||||
app = AppKit.NSApplication.sharedApplication()
|
||||
|
||||
# create an app delegate
|
||||
delegate = AppDelegate.alloc().init()
|
||||
AppKit.NSApp().setDelegate_(delegate)
|
||||
|
||||
# create a window
|
||||
rect = Foundation.NSMakeRect(-16000,-16000,100,100)
|
||||
win = AppKit.NSWindow.alloc()
|
||||
win.initWithContentRect_styleMask_backing_defer_ (rect, AppKit.NSBorderlessWindowMask, 2, 0)
|
||||
|
||||
# create a webview object
|
||||
webview = WebKit.WebView.alloc()
|
||||
webview.initWithFrame_(rect)
|
||||
# turn off scrolling so the content is actually x wide and not x-15
|
||||
webview.mainFrame().frameView().setAllowsScrolling_(objc.NO)
|
||||
# add the webview to the window
|
||||
win.setContentView_(webview)
|
||||
|
||||
|
||||
# create a LoadDelegate
|
||||
loaddelegate = WebkitLoad.alloc().init()
|
||||
loaddelegate.options = [""]
|
||||
loaddelegate.urls = [url]
|
||||
webview.setFrameLoadDelegate_(loaddelegate)
|
||||
|
||||
app.run()
|
||||
|
||||
if __name__ == '__main__' : main()
|
||||
|
||||
4
wrp.py → old/wrp.py
Executable file → Normal file
4
wrp.py → old/wrp.py
Executable file → Normal file
@@ -284,10 +284,10 @@ if sys.platform.startswith('linux') or sys.platform.startswith('freebsd'):
|
||||
if ISMAP == True:
|
||||
mapfile.write("rect %s %i,%i %i,%i\n".decode('utf-8', errors='ignore') % (turl, xmin, ymin, xmax, ymax))
|
||||
else:
|
||||
httpout.write("<AREA SHAPE=\"RECT\""
|
||||
httpout.write(("<AREA SHAPE=\"RECT\""
|
||||
" COORDS=\"%i,%i,%i,%i\""
|
||||
" ALT=\"%s\" HREF=\"%s\">\n".decode('utf-8', errors='ignore')
|
||||
% (xmin, ymin, xmax, ymax, turl, turl))
|
||||
% (xmin, ymin, xmax, ymax, turl, turl)).encode("utf-8"))
|
||||
|
||||
if ISMAP != True:
|
||||
httpout.write("</MAP>\n")
|
||||
317
wrp.go
Normal file
317
wrp.go
Normal file
@@ -0,0 +1,317 @@
|
||||
//
|
||||
// WRP - Web Rendering Proxy
|
||||
//
|
||||
// Copyright (c) 2013-2018 Antoni Sawicki
|
||||
// Copyright (c) 2019 Google LLC
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"image/gif"
|
||||
"image/png"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/cdproto/emulation"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/ericpauley/go-quantize/quantize"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "4.4"
|
||||
srv http.Server
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
gifmap = make(map[string]bytes.Buffer)
|
||||
ismap = make(map[string]wrpReq)
|
||||
)
|
||||
|
||||
type wrpReq struct {
|
||||
U string // url
|
||||
W int64 // width
|
||||
H int64 // height
|
||||
S float64 // scale
|
||||
C int64 // #colors
|
||||
X int64 // mouseX
|
||||
Y int64 // mouseY
|
||||
K string // keys to send
|
||||
F string // Fn buttons
|
||||
}
|
||||
|
||||
func (w *wrpReq) parseForm(req *http.Request) {
|
||||
req.ParseForm()
|
||||
w.U = req.FormValue("url")
|
||||
if len(w.U) > 1 && !strings.HasPrefix(w.U, "http") {
|
||||
w.U = fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(w.U))
|
||||
}
|
||||
w.W, _ = strconv.ParseInt(req.FormValue("w"), 10, 64)
|
||||
if w.W < 10 {
|
||||
w.W = 1152
|
||||
}
|
||||
w.H, _ = strconv.ParseInt(req.FormValue("h"), 10, 64)
|
||||
if w.H < 10 {
|
||||
w.H = 600
|
||||
}
|
||||
w.S, _ = strconv.ParseFloat(req.FormValue("s"), 64)
|
||||
if w.S < 0.1 {
|
||||
w.S = 1.0
|
||||
}
|
||||
w.C, _ = strconv.ParseInt(req.FormValue("c"), 10, 64)
|
||||
if w.C < 2 || w.C > 256 {
|
||||
w.C = 256
|
||||
}
|
||||
w.K = req.FormValue("k")
|
||||
w.F = req.FormValue("Fn")
|
||||
log.Printf("%s WrpReq from Form: %+v\n", req.RemoteAddr, w)
|
||||
}
|
||||
|
||||
func (w wrpReq) printPage(out http.ResponseWriter) {
|
||||
out.Header().Set("Cache-Control", "max-age=0")
|
||||
out.Header().Set("Expires", "-1")
|
||||
out.Header().Set("Pragma", "no-cache")
|
||||
out.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(out, "<!-- Web Rendering Proxy Version %s -->\n", version)
|
||||
fmt.Fprintf(out, "<HTML>\n<HEAD><TITLE>WRP %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#F0F0F0\">\n", w.U)
|
||||
fmt.Fprintf(out, "<FORM ACTION=\"/\" METHOD=\"POST\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"TEXT\" NAME=\"url\" VALUE=\"%s\" SIZE=\"10\">", w.U)
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" VALUE=\"Go\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"Bk\">\n")
|
||||
fmt.Fprintf(out, "W <INPUT TYPE=\"TEXT\" NAME=\"w\" VALUE=\"%d\" SIZE=\"4\"> \n", w.W)
|
||||
fmt.Fprintf(out, "H <INPUT TYPE=\"TEXT\" NAME=\"h\" VALUE=\"%d\" SIZE=\"4\"> \n", w.H)
|
||||
fmt.Fprintf(out, "S <INPUT TYPE=\"TEXT\" NAME=\"s\" VALUE=\"%1.2f\" SIZE=\"3\"> \n", w.S)
|
||||
fmt.Fprintf(out, "C <INPUT TYPE=\"TEXT\" NAME=\"c\" VALUE=\"%d\" SIZE=\"3\">\n", w.C)
|
||||
fmt.Fprintf(out, "K <INPUT TYPE=\"TEXT\" NAME=\"k\" VALUE=\"\" SIZE=\"4\"> \n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"Bs\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"Rt\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"<\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"^\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\"v\">\n")
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"Fn\" VALUE=\">\" SIZE=\"1\">\n")
|
||||
fmt.Fprintf(out, "</FORM><BR>\n")
|
||||
}
|
||||
|
||||
func (w wrpReq) printFooter(out http.ResponseWriter) {
|
||||
fmt.Fprintf(out, "\n<P><FONT SIZE=\"-2\"><A HREF=\"/?url=https://github.com/tenox7/wrp/&w=%d&h=%d&s=%1.2f&c=%d\">"+
|
||||
"Web Rendering Proxy Version %s</A> | <A HREF=\"/shutdown/\">Shutdown WRP</A></FONT></BODY>\n</HTML>\n", w.W, w.H, w.S, w.C, version)
|
||||
}
|
||||
|
||||
func pageServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s Page Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
||||
var w wrpReq
|
||||
w.parseForm(req)
|
||||
|
||||
if len(w.U) > 4 {
|
||||
w.capture(req.RemoteAddr, out)
|
||||
} else {
|
||||
w.printPage(out)
|
||||
w.printFooter(out)
|
||||
}
|
||||
}
|
||||
|
||||
func mapServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s ISMAP Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
||||
w, ok := ismap[req.URL.Path]
|
||||
if !ok {
|
||||
fmt.Fprintf(out, "Unable to find map %s\n", req.URL.Path)
|
||||
log.Printf("Unable to find map %s\n", req.URL.Path)
|
||||
return
|
||||
}
|
||||
defer delete(ismap, req.URL.Path)
|
||||
n, err := fmt.Sscanf(req.URL.RawQuery, "%d,%d", &w.X, &w.Y)
|
||||
if err != nil || n != 2 {
|
||||
fmt.Fprintf(out, "n=%d, err=%s\n", n, err)
|
||||
log.Printf("%s ISMAP n=%d, err=%s\n", req.RemoteAddr, n, err)
|
||||
return
|
||||
}
|
||||
log.Printf("%s WrpReq from ISMAP: %+v\n", req.RemoteAddr, w)
|
||||
if len(w.U) > 4 {
|
||||
w.capture(req.RemoteAddr, out)
|
||||
} else {
|
||||
w.printPage(out)
|
||||
w.printFooter(out)
|
||||
}
|
||||
}
|
||||
|
||||
func imgServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s IMG Request for %s\n", req.RemoteAddr, req.URL.Path)
|
||||
gifbuf, ok := gifmap[req.URL.Path]
|
||||
if !ok || gifbuf.Bytes() == nil {
|
||||
fmt.Fprintf(out, "Unable to find image %s\n", req.URL.Path)
|
||||
log.Printf("Unable to find image %s\n", req.URL.Path)
|
||||
return
|
||||
}
|
||||
defer delete(gifmap, req.URL.Path)
|
||||
out.Header().Set("Content-Type", "image/gif")
|
||||
out.Header().Set("Content-Length", strconv.Itoa(len(gifbuf.Bytes())))
|
||||
out.Header().Set("Cache-Control", "max-age=0")
|
||||
out.Header().Set("Expires", "-1")
|
||||
out.Header().Set("Pragma", "no-cache")
|
||||
out.Write(gifbuf.Bytes())
|
||||
out.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
func (w wrpReq) capture(c string, out http.ResponseWriter) {
|
||||
var pngbuf []byte
|
||||
var gifbuf bytes.Buffer
|
||||
var err error
|
||||
|
||||
if w.X > 0 && w.Y > 0 {
|
||||
log.Printf("%s Mouse Click %d,%d\n", c, w.X, w.Y)
|
||||
err = chromedp.Run(ctx, chromedp.MouseClickXY(int64(float64(w.X)/w.S), int64(float64(w.Y)/w.S)))
|
||||
} else if len(w.F) > 0 {
|
||||
log.Printf("%s Button %v\n", c, w.F)
|
||||
switch w.F {
|
||||
case "Bk":
|
||||
err = chromedp.Run(ctx, chromedp.NavigateBack())
|
||||
case "Bs":
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent("\b"))
|
||||
case "Rt":
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent("\r"))
|
||||
case "<":
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent("\u0302"))
|
||||
case "^":
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent("\u0304"))
|
||||
case "v":
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent("\u0301"))
|
||||
case ">":
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent("\u0303"))
|
||||
}
|
||||
} else if len(w.K) > 0 {
|
||||
log.Printf("%s Sending Keys: %#v\n", c, w.K)
|
||||
err = chromedp.Run(ctx, chromedp.KeyEvent(w.K))
|
||||
} else {
|
||||
log.Printf("%s Processing Capture Request for %s\n", c, w.U)
|
||||
err = chromedp.Run(ctx,
|
||||
emulation.SetDeviceMetricsOverride(int64(float64(w.W)/w.S), int64(float64(w.H)/w.S), w.S, false),
|
||||
chromedp.Navigate(w.U),
|
||||
)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "context canceled" {
|
||||
log.Printf("%s Contex cancelled, try again", c)
|
||||
fmt.Fprintf(out, "<BR>%s<BR> -- restarting, try again", err)
|
||||
ctx, cancel = chromedp.NewContext(context.Background())
|
||||
} else {
|
||||
log.Printf("%s %s", c, err)
|
||||
fmt.Fprintf(out, "<BR>%s<BR>", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
chromedp.Run(
|
||||
ctx, chromedp.Sleep(time.Second*2),
|
||||
chromedp.Location(&w.U),
|
||||
)
|
||||
log.Printf("%s Landed on: %s\n", c, w.U)
|
||||
w.printPage(out)
|
||||
|
||||
// Process Screenshot Image
|
||||
err = chromedp.Run(ctx, chromedp.CaptureScreenshot(&pngbuf))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to capture screenshot: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to capture screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
bytes.NewReader(pngbuf).Seek(0, 0)
|
||||
img, err := png.Decode(bytes.NewReader(pngbuf))
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to decode screenshot: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to decode page screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
gifbuf.Reset()
|
||||
err = gif.Encode(&gifbuf, img, &gif.Options{NumColors: int(w.C), Quantizer: quantize.MedianCutQuantizer{}})
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to encode GIF: %s\n", c, err)
|
||||
fmt.Fprintf(out, "<BR>Unable to encode GIF:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Compose map and gif
|
||||
seq := rand.Intn(9999)
|
||||
imgpath := fmt.Sprintf("/img/%04d.gif", seq)
|
||||
mappath := fmt.Sprintf("/map/%04d.map", seq)
|
||||
gifmap[imgpath] = gifbuf
|
||||
ismap[mappath] = w
|
||||
log.Printf("%s Encoded GIF image: %s, Size: %dKB, Colors: %d\n", c, imgpath, len(gifbuf.Bytes())/1024, w.C)
|
||||
fmt.Fprintf(out, "<A HREF=\"%s\"><IMG SRC=\"%s\" BORDER=\"0\" ISMAP></A>", mappath, imgpath)
|
||||
w.printFooter(out)
|
||||
log.Printf("%s Done with caputure for %s\n", c, w.U)
|
||||
}
|
||||
|
||||
func haltServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s Shutdown Request for %s\n", req.RemoteAddr, req.URL.Path)
|
||||
out.Header().Set("Cache-Control", "max-age=0")
|
||||
out.Header().Set("Expires", "-1")
|
||||
out.Header().Set("Pragma", "no-cache")
|
||||
out.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintf(out, "Shutting down WRP...\n")
|
||||
out.(http.Flusher).Flush()
|
||||
time.Sleep(time.Second * 2)
|
||||
cancel()
|
||||
srv.Shutdown(context.Background())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var addr string
|
||||
var head, headless bool
|
||||
var debug bool
|
||||
flag.StringVar(&addr, "l", ":8080", "Listen address:port, default :8080")
|
||||
flag.BoolVar(&head, "h", false, "Headed mode - display browser window")
|
||||
flag.BoolVar(&debug, "d", false, "Debug ChromeDP")
|
||||
flag.Parse()
|
||||
if head {
|
||||
headless = false
|
||||
} else {
|
||||
headless = true
|
||||
}
|
||||
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||
chromedp.Flag("headless", headless),
|
||||
chromedp.Flag("hide-scrollbars", false),
|
||||
)
|
||||
actx, acancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
||||
defer acancel()
|
||||
if debug {
|
||||
ctx, cancel = chromedp.NewContext(actx, chromedp.WithDebugf(log.Printf))
|
||||
} else {
|
||||
ctx, cancel = chromedp.NewContext(actx)
|
||||
}
|
||||
defer cancel()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
log.Printf("Interrupt - shutting down.")
|
||||
cancel()
|
||||
srv.Shutdown(context.Background())
|
||||
os.Exit(1)
|
||||
}()
|
||||
http.HandleFunc("/", pageServer)
|
||||
http.HandleFunc("/map/", mapServer)
|
||||
http.HandleFunc("/img/", imgServer)
|
||||
http.HandleFunc("/shutdown/", haltServer)
|
||||
http.HandleFunc("/favicon.ico", http.NotFound)
|
||||
log.Printf("Web Rendering Proxy Version %s\n", version)
|
||||
log.Printf("Starting WRP http server on %s\n", addr)
|
||||
srv.Addr = addr
|
||||
err := srv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user