#!/usr/bin/python # Simple multi-file uploader.... (change some settings below) # (Didn't really plan to release this, but what the heck...) # version 1.0 (Script by Tim Middleton) # ----------------------------some constant settings---------------------------------- dirUpload = "mtm" # directory for upload; will be created if doesn't exist maxkb = 25000 # maximum kilobytes to store before no more files accepted link = "feedback.py" # a page/url to link at the bottom of page after upload email = "maven@gnosis.cx" # where to email upload reports; sendmail = "/usr/sbin/sendmail" # sendmail will email notification of uploads # ==================================================================================== # that's all the general settings... now for the code.... # ==================================================================================== import sys,os,cgi,glob,string sys.stderr = sys.stdout print "content-type: text/html\n" def plural(s,num): "Make plural words nicely as possible." if num<>1: if s[-1] == "s" or s[-1] == "x": s = s + "e" s = s + "s" return s def mailme(msg=""): "Quick and dirty, pipe a message to sendmail, appending various environmental variables to the message." if email: try: o = os.popen("%s -t" % sendmail,"w") o.write("To: %s\n" % email) o.write("From: %s\n" % email) o.write("Subject: %s\n" % "Upload to ~/upload/") o.write('X-Happy: g2G g33 g3B g3C g3M g42 g43 g46 g4C g4E\n') o.write("\n") o.write("%s\n" % msg) o.write("---------------------------------------\n") for x in [ 'REQUEST_URI','HTTP_USER_AGENT','REMOTE_ADDR','HTTP_FROM','REMOTE_HOST','REMOTE_PORT','SERVER_SOFTWARE','HTTP_REFERER','REMOTE_IDENT','REMOTE_USER','QUERY_STRING','DATE_LOCAL','HTTP_COOKIE' ]: if os.environ.has_key(x): o.write("%s: %s\n" % (x, os.environ[x])) o.write("---------------------------------------\n") o.close() except IOError: pass ######################################################################################## def form(posturl,files,kb,maxkb,button): "Print the main form." print """
There's currently %s %s equaling %.2f kb (of a maximum of %s kb allowed) in the upload area.
""" % (files,plural("file",files),kb/1024.0,maxkb,posturl,button) ######################################################################################## if os.environ.has_key("HTTP_USER_AGENT"): browser = os.environ["HTTP_USER_AGENT"] else: browser = "No Known Browser" if os.environ.has_key("SCRIPT_NAME"): posturl = os.environ["SCRIPT_NAME"] else: posturl = "" #posturl = "test.py" kb = 0 fns = glob.glob(dirUpload+os.sep+"*") for x in fns: kb = kb + os.stat(x)[6] if kb/1024