diff options
author | Lennart Poettering <lennart@poettering.net> | 2003-11-12 21:41:46 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2003-11-12 21:41:46 +0000 |
commit | f4f5053170a6bf8e45c15ea0435b86f5fa1b6d06 (patch) | |
tree | a7353540ccbb8550d2889e8911ff331cabe018e2 /upload.cgi | |
parent | 8c4fde5b8f3ea7148cd3ad85c87f2c99a94e77da (diff) |
initial commit
git-svn-id: file:///home/lennart/svn/public/syrep-chub/trunk@2 4c8cc7d0-f3cb-0310-ad32-ddc431b48844
Diffstat (limited to 'upload.cgi')
-rwxr-xr-x | upload.cgi | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/upload.cgi b/upload.cgi new file mode 100755 index 0000000..fd27e0e --- /dev/null +++ b/upload.cgi @@ -0,0 +1,58 @@ +#!/usr/bin/python + +import cgi, cgitb, os, time, urllib, sch, sys + +if os.getenv("REQUEST_METHOD") != "PUT": + sch.error("Method PUT required.") + +fname = os.getenv("QUERY_STRING") +if fname is None: + sch.error("Need to pass query string.") + +if os.getenv("CONTENT_LENGTH") is None: + sch.error("Header field Content-Length missing.") +length = int(os.getenv("CONTENT_LENGTH")) + +if not sch.valid_fname(fname): + sch.error("Fuck off!") + +sch.print_header("Upload for '%s'" % fname) + +fname = sch.repository_directory + "/" + fname; +tfname = fname+".tmp" + +out = file(tfname, "wb+") + +total = 0 + +try: + while 1: + buf = sys.stdin.read(1024) + + if not len(buf): + break + + out.write(buf) + total += len(buf) + + out.close() + +except IOError, e: + os.unlink(tfname) + sch.error("IOError: %s", str(e)) + +if total != length: + os.unlink(tfname) + sch.error("Incomplete upload.") + +try: + os.unlink(fname) +except OSError, e: + pass + +os.link(tfname, fname) +os.unlink(tfname) + +print "<p>Successful</p>" + +sch.print_footer() |