Changeset 5634
- Timestamp:
- 01/03/08 00:59:38 (1 year ago)
- Files:
-
- sandbox/rdewit/kml/examples/proxy.cgi (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/rdewit/kml/examples/proxy.cgi
r5550 r5634 13 13 import cgi 14 14 import sys, os 15 import zipfile, re, StringIO #for KMZ support 16 15 17 16 18 # Designed to prevent Open Proxy type stuff. 19 17 20 18 21 allowedHosts = ['www.openlayers.org', 'openlayers.org', … … 37 40 try: 38 41 host = url.split("/")[2] 39 if allowedHosts and not host in allowedHosts: 42 #isLocalHost = (os.environ["SERVER_NAME"] == "localhost") or (os.environ["HTTP_HOST"] == "localhost") 43 isLocalHost = False 44 if not isLocalHost and allowedHosts and not host in allowedHosts: 40 45 print "Status: 502 Bad Gateway" 41 46 print "Content-Type: text/plain" … … 63 68 print "Content-Type: text/plain" 64 69 print 70 71 # Handle KMZ files 72 # First put content in StringIO object, so ZipFile can handle it 73 fileObject = StringIO.StringIO() 74 fileObject.write(y.read()) 75 76 # Now try to handle it as a ZIP file 77 try: 78 zipObject = zipfile.ZipFile(fileObject, "r") 79 80 # if not, print the contents (most cases) 81 except zipfile.BadZipfile: 82 fileObject.seek(0) # reset pointer to start of file 83 print fileObject.read() 84 85 # It *is* a ZIP! Now loop through all files in ZIP 86 # and only print the ones ending in .kml 87 else: 88 for info in zipObject.infolist(): 89 if re.search(r'''\.kml$''', info.filename): 90 print zipObject.read(info.filename) 91 zipObject.close() 65 92 66 print y.read() 67 93 fileObject.close() 68 94 y.close() 69 95 else:
