diff options
Diffstat (limited to 'cgi-bin/proxy')
| -rwxr-xr-x | cgi-bin/proxy | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/cgi-bin/proxy b/cgi-bin/proxy index 801e0f2..df208a0 100755 --- a/cgi-bin/proxy +++ b/cgi-bin/proxy @@ -2,6 +2,7 @@ from os import environ as env import urllib.request +import base64 import json import sys @@ -12,19 +13,24 @@ def error(): def proxy(url,ext,callback): req = urllib.request.urlopen(url) - print("Content-type: image/" + ext) - print() - sys.stdout.flush() - if callback: - sys.stdout.buffer.write( callback + "('" ) - sys.stdout.buffer.write( json.dump({ data: req.read() }) - sys.stdout.buffer.write( callback + "')" ) + if callback != "": + print("Content-type: text/plain") + print() + sys.stdout.flush() + sys.stdout.buffer.write( bytes( callback + "(btoa(" + json.dumps( "".join(map(chr, base64.b64encode( req.read() )))) + "))" , 'utf-8')) else: - sys.stdout.buffer.write( req.read() ) + print("Content-type: image/" + ext) + print() + sys.stdout.flush() + sys.stdout.buffer.write( req.read() ) qs = env['QUERY_STRING'].split('&callback=') +if len(qs) == 2: + callback = qs[1] +else: + callback = '' path = qs[0] -callback = qs[1] + ext = path[-3:].lower() if path[0:4] == "http" and ext in ("gif","jpg","png","peg"): |
