mirror of
https://github.com/tenox7/wrp.git
synced 2026-02-11 05:35:36 +00:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b91bbed4a7 | ||
|
|
7a2f673fd0 | ||
|
|
61b84116b1 | ||
|
|
ea738f206a | ||
|
|
981055dff9 | ||
|
|
deb0cf7923 | ||
|
|
186fda4949 | ||
|
|
7610f52574 | ||
|
|
416490289d | ||
|
|
0ae49044c2 | ||
|
|
cb87a83d26 | ||
|
|
ebe19912e6 | ||
|
|
5d8f51ac66 | ||
|
|
d905704a2a | ||
|
|
d382c38547 | ||
|
|
12664e6a10 | ||
|
|
e643ec1d69 | ||
|
|
9ad651c72c | ||
|
|
a897f76e20 | ||
|
|
df400d57b3 | ||
|
|
546e686cbc | ||
|
|
57a107aa69 | ||
|
|
a3eb7cb69a | ||
|
|
d8617af9c2 | ||
|
|
c6186d6fb4 | ||
|
|
7d84d01268 | ||
|
|
5b827bffb0 | ||
|
|
0680b4a72e | ||
|
|
e869291f8e | ||
|
|
071a75dfc6 | ||
|
|
34d4e2fa2a | ||
|
|
2ac4464b98 | ||
|
|
cc3d4a674b | ||
|
|
6655993c07 | ||
|
|
64cf34fb85 | ||
|
|
85063cefc8 | ||
|
|
7013f521b3 | ||
|
|
b15d64351b | ||
|
|
0b617d1592 | ||
|
|
f6446c0a3e | ||
|
|
4526dfca64 | ||
|
|
40c0329d1a | ||
|
|
67ec48aa62 | ||
|
|
b89211e432 | ||
|
|
ef96884e77 | ||
| b090ea47b0 |
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.
|
||||
7
README
7
README
@@ -1,7 +0,0 @@
|
||||
WRP is a HTTP proxy service that renders the web page in to a GIF/JPEG image associated with clickable imagemap of the original web links. It allows to use historical and obsolete web browsers on the modern web. It's still a work in progress but it's quite stable and usable for casual web browsing.
|
||||
|
||||
WRP supports Mac OS X and Linux. It requires Python 2.7 and under Linux, PyQT4.
|
||||
|
||||
More info and screenshots: http://virtuallyfun.superglobalmegacorp.com/2014/03/11/web-rendering-proxy-update/
|
||||
|
||||
Even more screenshots: http://virtuallyfun.superglobalmegacorp.com/2014/03/03/surfing-modern-web-with-ancient-browsers/
|
||||
32
README.md
Normal file
32
README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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 image associated with clickable imagemap of original web links.
|
||||
|
||||
**You are looking at a GoLang / CDP branch of WRP.**
|
||||
|
||||
**This code is under active development and not fully usable yet.**
|
||||
|
||||
## Done so far
|
||||
|
||||
* basic browser-in-browser mode
|
||||
* screenshot and serve image+map via CDP
|
||||
* gif with Floyd–Steinberg dithering
|
||||
* random image addressing
|
||||
* resolve relative links
|
||||
* paginated scrolling
|
||||
* google search on input not starting with ^http
|
||||
|
||||
## Todo
|
||||
|
||||
* ISMAP - underway
|
||||
* net/url: invalid control character in URL on Windows
|
||||
* configurable color palete and quantization
|
||||
* real http proxy support
|
||||
* option to encode as png/jpeg
|
||||
* padded box model coordinates
|
||||
* better http server shutdown
|
||||
* chromedp logging, timeout, non-headless flags
|
||||
|
||||
## Python version
|
||||
|
||||
Check [master branch](https://github.com/tenox7/wrp/tree/master) for "stable" Python-Webkit version.
|
||||
65
wrp.py → pywebkit/wrp.py
Executable file → Normal file
65
wrp.py → pywebkit/wrp.py
Executable file → Normal file
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python2.7
|
||||
|
||||
# wrp.py - Web Rendering Proxy
|
||||
# wrp.py - Web Rendering Proxy - https://github.com/tenox7/wrp
|
||||
# A HTTP proxy service that renders the requested URL in to a image associated
|
||||
# with an imagemap of clickable links. This is an adaptation of previous works by
|
||||
# picidae.net and Paul Hammond.
|
||||
@@ -9,15 +9,16 @@ __version__ = "2.0"
|
||||
|
||||
#
|
||||
# This program is based on the software picidae.py from picidae.net
|
||||
# It was modified by Antoni Sawicki http://www.tenox.net/out/#wrp
|
||||
# It was modified by Antoni Sawicki and Natalia Portillo
|
||||
#
|
||||
# This program is based on the software webkit2png from Paul Hammond.
|
||||
# It was extended by picidae.net
|
||||
#
|
||||
# Copyright (c) 2013-2014 Antoni Sawicki
|
||||
# Copyright (c) 2013-2018 Antoni Sawicki
|
||||
# Copyright (c) 2012-2013 picidae.net
|
||||
# Copyright (c) 2004-2013 Paul Hammond
|
||||
# Copyright (c) 2017 Natalia Portillo
|
||||
# Copyright (c) 2017-2018 Natalia Portillo
|
||||
# Copyright (c) 2018 //gir.st/
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -39,20 +40,21 @@ __version__ = "2.0"
|
||||
#
|
||||
|
||||
# Configuration options:
|
||||
PORT = 8080
|
||||
WIDTH = 1024
|
||||
HEIGHT = 768
|
||||
ISMAP = "true"
|
||||
WAIT = 1 # sleep for 1 second to allow javascript renders
|
||||
QUALITY = 75 # For JPEG: image quality 0-100; For PNG: sets compression level (leftmost digit 0 fastest, 9 best)
|
||||
PORT = 8080
|
||||
WIDTH = 1024
|
||||
HEIGHT = 768
|
||||
ISMAP = False # ISMAP=True is Server side for Mosaic 1.1 and up. HTML 3.2 supports Client side maps (ISMAP=False)
|
||||
WAIT = 1 # sleep for 1 second to allow javascript renders
|
||||
QUALITY = 75 # For JPEG: image quality 0-100; For PNG: sets compression level (leftmost digit 0 fastest, 9 best)
|
||||
AUTOWIDTH = True # Check for browser width using javascript
|
||||
FORMAT = "AUTO" # AUTO = GIF for mac OS, JPG for rest; PNG, GIF, JPG as supported values.
|
||||
FORMAT = "AUTO" # AUTO = GIF for mac OS, JPG for rest; PNG, GIF, JPG as supported values.
|
||||
SSLSTRIP = True # enable to automatically downgrade secure requests
|
||||
|
||||
# PythonMagick configuration options
|
||||
MK_MONOCHROME = False # Convert the render to a black and white dithered image
|
||||
MK_GRAYSCALE = False # Convert the render to a grayscal dithered image
|
||||
MK_COLORS = 0 # Reduce number of colors in the image. 0 for not reducing. Less than 256 works in grayscale also.
|
||||
MK_DITHER = False # Dither the image to reduce size. GIFs will always be dithered. Ignored if MK_COLORS is not set.
|
||||
MK_GRAYSCALE = False # Convert the render to a grayscal dithered image
|
||||
MK_COLORS = 0 # Reduce number of colors in the image. 0 for not reducing. Less than 256 works in grayscale also.
|
||||
MK_DITHER = False # Dither the image to reduce size. GIFs will always be dithered. Ignored if MK_COLORS is not set.
|
||||
|
||||
import re
|
||||
import random
|
||||
@@ -68,6 +70,7 @@ import Queue
|
||||
import sys
|
||||
import logging
|
||||
import StringIO
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
import PythonMagick
|
||||
@@ -86,7 +89,7 @@ RENDERS = {}
|
||||
### Linux CODEPATH ###
|
||||
#######################
|
||||
|
||||
if sys.platform == "linux" or sys.platform == "linux2":
|
||||
if sys.platform.startswith('linux') or sys.platform.startswith('freebsd'):
|
||||
try:
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtGui import *
|
||||
@@ -265,7 +268,7 @@ if sys.platform == "linux" or sys.platform == "linux2":
|
||||
if AUTOWIDTH:
|
||||
httpout.write("<script>document.write('<span style=\"display: none;\"><img src=\"http://width-' + document.body.clientWidth + '-px.jpg\" width=\"0\" height=\"0\"></span>');</script>\n")
|
||||
|
||||
if ISMAP == "true":
|
||||
if ISMAP == True:
|
||||
httpout.write("<A HREF=\"http://%s\">"
|
||||
"<IMG SRC=\"http://%s\" ALT=\"wrp-render\" ISMAP>\n"
|
||||
"</A>\n" % (WebkitRenderer.req_map, WebkitRenderer.req_img))
|
||||
@@ -278,7 +281,7 @@ if sys.platform == "linux" or sys.platform == "linux2":
|
||||
for x in frame.findAllElements('a'):
|
||||
turl = QUrl(web_url).resolved(QUrl(x.attribute('href'))).toString()
|
||||
xmin, ymin, xmax, ymax = x.geometry().getCoords()
|
||||
if ISMAP == "true":
|
||||
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\""
|
||||
@@ -286,12 +289,12 @@ if sys.platform == "linux" or sys.platform == "linux2":
|
||||
" ALT=\"%s\" HREF=\"%s\">\n".decode('utf-8', errors='ignore')
|
||||
% (xmin, ymin, xmax, ymax, turl, turl))
|
||||
|
||||
if ISMAP != "true":
|
||||
if ISMAP != True:
|
||||
httpout.write("</MAP>\n")
|
||||
|
||||
httpout.write("</BODY>\n</HTML>\n")
|
||||
|
||||
if ISMAP == "true":
|
||||
if ISMAP == True:
|
||||
RENDERS[WebkitRenderer.req_map] = mapfile
|
||||
|
||||
return image
|
||||
@@ -665,7 +668,7 @@ elif sys.platform == "darwin":
|
||||
if AUTOWIDTH:
|
||||
httpout.write("<script>document.write('<span style=\"display: none;\"><img src=\"http://width-' + document.body.clientWidth + '-px.jpg\" width=\"0\" height=\"0\"></span>');</script>\n")
|
||||
|
||||
if ISMAP == "true":
|
||||
if ISMAP == True:
|
||||
httpout.write("<A HREF=\"http://%s\">"
|
||||
"<IMG SRC=\"http://%s\" ALT=\"wrp-render\" ISMAP>\n"
|
||||
"</A>\n" % (WebkitLoad.req_map, WebkitLoad.req_img))
|
||||
@@ -687,7 +690,7 @@ elif sys.platform == "darwin":
|
||||
xmax = Foundation.NSMaxX(myrect)
|
||||
ymax = Foundation.NSMaxY(myrect)
|
||||
|
||||
if ISMAP == "true":
|
||||
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\""
|
||||
@@ -697,12 +700,12 @@ elif sys.platform == "darwin":
|
||||
|
||||
i += 1
|
||||
|
||||
if ISMAP != "true":
|
||||
if ISMAP != True:
|
||||
httpout.write("</MAP>\n")
|
||||
|
||||
httpout.write("</BODY>\n</HTML>\n")
|
||||
|
||||
if ISMAP == "true":
|
||||
if ISMAP == True:
|
||||
RENDERS[WebkitLoad.req_map] = mapfile
|
||||
|
||||
# Return to Proxy thread and Loop...
|
||||
@@ -861,7 +864,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
req_extension = ".jpg"
|
||||
elif FORMAT == "PNG":
|
||||
req_extension = ".png"
|
||||
elif (sys.platform == "linux" or sys.platform == "linux2") and FORMAT == "AUTO":
|
||||
elif (sys.platform.startswith('linux') or sys.platform.startswitch('freebsd')) and FORMAT == "AUTO":
|
||||
req_extension = ".jpg"
|
||||
elif sys.platform == "darwin" and FORMAT == "AUTO":
|
||||
req_extension = ".gif"
|
||||
@@ -891,13 +894,23 @@ def main():
|
||||
if(FORMAT != "AUTO" and FORMAT != "GIF" and FORMAT != "JPG" and FORMAT != "PNG"):
|
||||
sys.exit("Unsupported image format \"%s\". Exiting." % FORMAT)
|
||||
|
||||
if (sys.platform == "linux" or sys.platform == "linux2") and FORMAT == "GIF" and not HasMagick:
|
||||
if (sys.platform.startswith('linux') or sys.platform.startswith('freebsd')) and FORMAT == "GIF" and not HasMagick:
|
||||
sys.exit("GIF format is not supported on this platform. Exiting.")
|
||||
|
||||
# run traffic through sslstrip as a quick workaround for getting SSL webpages to work
|
||||
# NOTE: modern browsers are doing their best to stop this kind of 'attack'. Firefox
|
||||
# supports an about:config flag test.currentTimeOffsetSeconds(int) = 12000000, which
|
||||
# you can use to circumvent those checks.
|
||||
if SSLSTRIP:
|
||||
try:
|
||||
subprocess.check_output(["pidof", "sslstrip"])
|
||||
except:
|
||||
subprocess.Popen(["sslstrip"], stdout=open(os.devnull,'w'), stderr=subprocess.STDOUT) # runs on port 10000 by default
|
||||
QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.HttpProxy, "localhost", 10000))
|
||||
# Launch Proxy Thread
|
||||
threading.Thread(target=run_proxy).start()
|
||||
|
||||
if sys.platform == "linux" or sys.platform == "linux2":
|
||||
if sys.platform.startswith('linux') or sys.platform.startswith('freebsd'):
|
||||
import signal
|
||||
try:
|
||||
import PyQt5.QtCore
|
||||
219
wrp.go
Normal file
219
wrp.go
Normal file
@@ -0,0 +1,219 @@
|
||||
//
|
||||
// WRP - Web Rendering Proxy
|
||||
//
|
||||
// Copyright (c) 2013-2018 Antoni Sawicki
|
||||
// Copyright (c) 2019 Google LLC
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "image"
|
||||
"image/gif"
|
||||
"image/png"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/cdproto/emulation"
|
||||
"github.com/chromedp/cdproto/runtime"
|
||||
|
||||
"github.com/chromedp/cdproto/cdp"
|
||||
"github.com/chromedp/cdproto/dom"
|
||||
"github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
gifmap = make(map[string]bytes.Buffer)
|
||||
)
|
||||
|
||||
func pageServer(out http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
u := r.FormValue("url")
|
||||
var istr string
|
||||
var i bool
|
||||
if r.FormValue("i") == "on" {
|
||||
istr = "CHECKED"
|
||||
i = true
|
||||
} else {
|
||||
istr = ""
|
||||
i = false
|
||||
}
|
||||
p, _ := strconv.ParseInt(r.FormValue("p"), 10, 64)
|
||||
if r.FormValue("pg") == ">>" {
|
||||
p++
|
||||
} else if r.FormValue("pg") == "<<" {
|
||||
p--
|
||||
} else {
|
||||
p = 0
|
||||
}
|
||||
w, _ := strconv.ParseInt(r.FormValue("w"), 10, 64)
|
||||
if w < 10 {
|
||||
w = 1024
|
||||
}
|
||||
h, _ := strconv.ParseInt(r.FormValue("h"), 10, 64)
|
||||
if h < 10 {
|
||||
h = 768
|
||||
}
|
||||
s, _ := strconv.ParseFloat(r.FormValue("s"), 64)
|
||||
if s < 0.1 {
|
||||
s = 1.0
|
||||
}
|
||||
log.Printf("%s Page Reqest for url=\"%s\" [%s]\n", r.RemoteAddr, u, r.URL.Path)
|
||||
out.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprintf(out, "<HTML>\n<HEAD><TITLE>WRP %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#F0F0F0\">", u)
|
||||
fmt.Fprintf(out, "<FORM ACTION=\"/\">URL/Search: <INPUT TYPE=\"TEXT\" NAME=\"url\" VALUE=\"%s\" SIZE=\"40\">", u)
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" VALUE=\"Go\"><P>\n")
|
||||
fmt.Fprintf(out, "ISMAP:<INPUT TYPE=\"CHECKBOX\" NAME=\"i\" %s> \n", istr)
|
||||
fmt.Fprintf(out, "Width:<INPUT TYPE=\"TEXT\" NAME=\"w\" VALUE=\"%d\" SIZE=\"4\"> \n", w)
|
||||
fmt.Fprintf(out, "Height:<INPUT TYPE=\"TEXT\" NAME=\"h\" VALUE=\"%d\" SIZE=\"4\"> \n", h)
|
||||
fmt.Fprintf(out, "Scale:<INPUT TYPE=\"TEXT\" NAME=\"s\" VALUE=\"%1.2f\" SIZE=\"3\"> \n", s)
|
||||
fmt.Fprintf(out, "Page:<INPUT TYPE=\"HIDDEN\" NAME=\"p\" VALUE=\"%d\"> \n", p)
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"pg\" VALUE=\"<<\"> %d \n", p)
|
||||
fmt.Fprintf(out, "<INPUT TYPE=\"SUBMIT\" NAME=\"pg\" VALUE=\">>\"> \n")
|
||||
fmt.Fprintf(out, "</FORM><P>\n")
|
||||
if len(u) > 4 {
|
||||
if strings.HasPrefix(u, "http") {
|
||||
capture(u, w, h, s, p, i, out)
|
||||
} else {
|
||||
capture(fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(u)), w, h, s, p, i, out)
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(out, "No URL or search query specified")
|
||||
}
|
||||
fmt.Fprintf(out, "</BODY>\n</HTML>\n")
|
||||
}
|
||||
|
||||
func imgServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s IMG Request for %s\n", req.RemoteAddr, req.URL.Path)
|
||||
gifbuf := gifmap[req.URL.Path]
|
||||
defer delete(gifmap, req.URL.Path)
|
||||
out.Header().Set("Content-Type", "image/gif")
|
||||
out.Header().Set("Content-Length", strconv.Itoa(len(gifbuf.Bytes())))
|
||||
out.Write(gifbuf.Bytes())
|
||||
out.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
func mapServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s MAP Request for %s [%v]\n", req.RemoteAddr, req.URL.Path, req.URL.Query())
|
||||
}
|
||||
|
||||
|
||||
func haltServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s Shutdown request received [%s]\n", req.RemoteAddr, req.URL.Path)
|
||||
out.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintf(out, "WRP Shutdown")
|
||||
out.(http.Flusher).Flush()
|
||||
cancel()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func capture(gourl string, w int64, h int64, s float64, p int64, ismap bool, out http.ResponseWriter) {
|
||||
var nodes []*cdp.Node
|
||||
ctxx := chromedp.FromContext(ctx)
|
||||
var pngbuf []byte
|
||||
var gifbuf bytes.Buffer
|
||||
var loc string
|
||||
var res *runtime.RemoteObject
|
||||
|
||||
log.Printf("Processing Caputure Request for %s\n", gourl)
|
||||
|
||||
// Run ChromeDP Magic
|
||||
err := chromedp.Run(ctx,
|
||||
emulation.SetDeviceMetricsOverride(w, h, s, false),
|
||||
chromedp.Navigate(gourl),
|
||||
chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", p*int64(float64(h)*float64(0.9))), &res),
|
||||
chromedp.Sleep(time.Second*1),
|
||||
chromedp.CaptureScreenshot(&pngbuf),
|
||||
chromedp.Location(&loc),
|
||||
chromedp.Nodes("a", &nodes, chromedp.ByQueryAll))
|
||||
|
||||
if err != nil {
|
||||
log.Printf("%s", err)
|
||||
fmt.Fprintf(out, "<BR>%s<BR>", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Landed on: %s, Nodes: %d\n", loc, len(nodes))
|
||||
|
||||
// Process Screenshot Image
|
||||
bytes.NewReader(pngbuf).Seek(0, 0)
|
||||
img, err := png.Decode(bytes.NewReader(pngbuf))
|
||||
if err != nil {
|
||||
log.Printf("Failed to decode screenshot: %s\n", err)
|
||||
fmt.Fprintf(out, "<BR>Unable to decode page screenshot:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
gifbuf.Reset()
|
||||
err = gif.Encode(&gifbuf, img, nil)
|
||||
if err != nil {
|
||||
log.Printf("Failed to encode GIF: %s\n", err)
|
||||
fmt.Fprintf(out, "<BR>Unable to encode GIF:<BR>%s<BR>\n", err)
|
||||
return
|
||||
}
|
||||
imgpath := fmt.Sprintf("/img/%04d.gif", rand.Intn(9999))
|
||||
log.Printf("Encoded GIF image: %s, Size: %dKB\n", imgpath, len(gifbuf.Bytes())/1024)
|
||||
gifmap[imgpath] = gifbuf
|
||||
|
||||
// Process Nodes
|
||||
base, _ := url.Parse(loc)
|
||||
if ismap {
|
||||
fmt.Fprintf(out, "<A HREF=\"/map/123.map\"><IMG SRC=\"%s\" ALT=\"wrp\" ISMAP></A>", imgpath)
|
||||
} else {
|
||||
fmt.Fprintf(out, "<IMG SRC=\"%s\" ALT=\"wrp\" USEMAP=\"#map\">\n<MAP NAME=\"map\">\n", imgpath)
|
||||
}
|
||||
|
||||
for _, n := range nodes {
|
||||
b, err := dom.GetBoxModel().WithNodeID(n.NodeID).Do(cdp.WithExecutor(ctx, ctxx.Target))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
tgt, err := base.Parse(n.AttributeValue("href"))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
target := fmt.Sprintf("/?url=%s&w=%d&h=%d&s=%1.2f&", tgt, w, h, s) // no page# here
|
||||
|
||||
if len(b.Content) > 6 && len(target) > 7 {
|
||||
if ismap {
|
||||
|
||||
} else {
|
||||
fmt.Fprintf(out, "<AREA SHAPE=\"RECT\" COORDS=\"%.f,%.f,%.f,%.f\" ALT=\"%s\" TITLE=\"%s\" HREF=\"%s\">\n",
|
||||
b.Content[0]*s, b.Content[1]*s, b.Content[4]*s, b.Content[5]*s, n.AttributeValue("href"), n.AttributeValue("href"), target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !ismap {
|
||||
fmt.Fprintf(out, "</MAP>\n")
|
||||
}
|
||||
out.(http.Flusher).Flush()
|
||||
log.Printf("Done with caputure for %s\n", gourl)
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx, cancel = chromedp.NewContext(context.Background())
|
||||
defer cancel()
|
||||
var addr string
|
||||
flag.StringVar(&addr, "l", ":8080", "Listen address:port, default :8080")
|
||||
flag.Parse()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
http.HandleFunc("/", pageServer)
|
||||
http.HandleFunc("/img/", imgServer)
|
||||
http.HandleFunc("/map/", mapServer)
|
||||
http.HandleFunc("/favicon.ico", http.NotFound)
|
||||
http.HandleFunc("/halt", haltServer)
|
||||
log.Printf("Starting WRP http server on %s\n", addr)
|
||||
http.ListenAndServe(addr, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user