1
|
#!/usr/bin/env python
|
2
|
|
3
|
|
4
|
"""This is a blind proxy that we use to get around browser
|
5
|
restrictions that prevent the Javascript from loading pages not on the
|
6
|
same server as the Javascript. This has several problems: it's less
|
7
|
efficient, it might break some sites, and it's a security risk because
|
8
|
people can use this proxy to browse the web and possibly do bad stuff
|
9
|
with it. If you can get your code signed (see:
|
10
|
http://trac.openlayers.org/wiki/HowToSignJavascript), then you should
|
11
|
modify Parameters.js so that this isn't used. Otherwise, you're stuck
|
12
|
with it. It only loads pages via http and https, but it can load any
|
13
|
content type. XML and HTML are both currently used by Openlayers."""
|
14
|
|
15
|
import urllib
|
16
|
import cgi
|
17
|
|
18
|
fs = cgi.FieldStorage()
|
19
|
url = fs.getvalue('url', "http://openlayers.org")
|
20
|
|
21
|
# Designed to prevent Open Proxy type stuff.
|
22
|
|
23
|
allowedHosts = ['www.openlayers.org', 'openlayers.org', 'octo.metacarta.com', 'merrimack.metacarta.com', 'labs.metacarta.com']
|
24
|
|
25
|
try:
|
26
|
host = url.split("/")[2]
|
27
|
if allowedHosts and not host in allowedHosts:
|
28
|
print "Status: 502 Bad Gateway"
|
29
|
print "Content-Type: text/plain"
|
30
|
print
|
31
|
print "This proxy does not allow you to access that location."
|
32
|
|
33
|
elif url.startswith("http://") or url.startswith("https://"):
|
34
|
|
35
|
y = urllib.urlopen(url)
|
36
|
|
37
|
headers = str(y.info()).split('\n')
|
38
|
for h in headers:
|
39
|
if h.startswith("Content-Type:"):
|
40
|
print h
|
41
|
print
|
42
|
|
43
|
print y.read()
|
44
|
|
45
|
y.close()
|
46
|
else:
|
47
|
print """Content-Type: text/plain
|
48
|
|
49
|
Illegal request."""
|
50
|
except Exception, E:
|
51
|
print "Status: 500 Unexpected Error"
|
52
|
print "Content-Type: text/plain"
|
53
|
print
|
54
|
print "Some unexpected error occurred. Error text was:", E
|