diff options
Diffstat (limited to 'cgi-bin')
| -rwxr-xr-x | cgi-bin/proxy | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/cgi-bin/proxy b/cgi-bin/proxy index 9c2ca3d..5e3539c 100755 --- a/cgi-bin/proxy +++ b/cgi-bin/proxy @@ -2,6 +2,8 @@ from os import environ as env import urllib.request +import base64 +import json import sys def error(): @@ -9,18 +11,30 @@ def error(): print() print("HELLO!") -def proxy(url,ext): +def proxy(url,ext,callback): req = urllib.request.urlopen(url) - print("Content-type: image/" + ext) - print() - sys.stdout.flush() - sys.stdout.buffer.write( req.read() ) + if callback != "": + print("Content-type: text/plain") + print() + sys.stdout.flush() + sys.stdout.buffer.write( bytes( callback + "(" + json.dumps( "".join(map(chr, base64.b64encode( req.read() )))) + ")" , 'utf-8')) + else: + 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] -path = env['QUERY_STRING'] ext = path[-3:].lower() if path[0:4] == "http" and ext in ("gif","jpg","png","peg"): - proxy(path,ext) + proxy(path,ext,callback) else: error() |
