Commit 74ea0e89 authored by Michael Murtaugh's avatar Michael Murtaugh

rename spaces, use javascript marker for serving script, not referer

parent c801effa
#!/usr/bin/env python
from __future__ import print_function
import cgitb; cgitb.enable()
import cgi, os, sys, json
env = os.environ
method = os.environ.get("REQUEST_METHOD", "GET").upper()
UPLOADS = os.environ.get("DOCUMENT_ROOT", "/var/www/html")
fs = cgi.FieldStorage()
referer = env.get("HTTP_REFERER")
request_uri = env.get("REQUEST_URI", "").lower()
serve_script = "javascript" in request_uri
# with open ("/usr/lib/cgi-bin/droptoupload.log", "a") as f:
# print ("="*40, file=f)
# print ("ACCESS", file=f)
# print ("="*40, file=f)
# for x in env:
# print ("{0} = {1}".format(x, env.get(x)), file=f)
# print (file=f)
# print (file=f)
def upload (form, inputname, base_upload_dir, pathname=None):
path = None
if (pathname != None) and form.getvalue(pathname):
......@@ -19,7 +34,7 @@ def upload (form, inputname, base_upload_dir, pathname=None):
upload_dir = base_upload_dir
if path:
upload_dir = os.path.join(upload_dir, path.strip("/"))
fp = os.path.join(upload_dir, fileitem.filename)
fp = os.path.join(upload_dir, fileitem.filename.replace(" ", "_"))
# log.write("uploading to path:{0} fp:{1}\n".format(upload_dir, fp))
fout = file (fp, 'wb')
bytes = 0
......@@ -41,21 +56,21 @@ if method == "POST":
resp = {}
resp["code"] = 0
resp["bytes"] = bytes
print "Content-type: application/json"
print
print json.dumps(resp)
print ("Content-type: application/json")
print ()
print (json.dumps(resp))
else:
print "Content-type: text/html;charset=utf8"
print
print "{0} bytes written to {1}<br />".format(bytes, filename)
print ""
print ("Content-type: text/html;charset=utf8")
print ()
print ("{0} bytes written to {1}<br />".format(bytes, filename))
print ("")
else:
# form = fs.getvalue("form")
this_url = os.environ.get("SCRIPT_NAME", "")
if referer:
print "Content-type: application/javascript;charset=utf8"
print
print """
if serve_script:
print ("Content-type: application/javascript;charset=utf8")
print ()
print ("""
(function () {
// http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
function componentToHex(c) {
......@@ -181,12 +196,12 @@ else:
});
})();
""".replace("THISURL", this_url)
""".replace("THISURL", this_url))
else:
print "Content-type: text/html; charset=utf8"
print
print """<!DOCTYPE html>
print ("Content-type: text/html; charset=utf8")
print ()
print ("""<!DOCTYPE html>
<html>
<head>
</head>
......@@ -197,4 +212,4 @@ else:
</form>
</body>
</html>
"""
\ No newline at end of file
""")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment