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 | |
parent | 8c4fde5b8f3ea7148cd3ad85c87f2c99a94e77da (diff) |
initial commit
git-svn-id: file:///home/lennart/svn/public/syrep-chub/trunk@2 4c8cc7d0-f3cb-0310-ad32-ddc431b48844
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | diff.cgi | 21 | ||||
-rwxr-xr-x | info.cgi | 18 | ||||
-rwxr-xr-x | list.cgi | 30 | ||||
-rw-r--r-- | sch.py | 49 | ||||
-rw-r--r-- | style.css | 11 | ||||
-rwxr-xr-x | upload.cgi | 58 |
7 files changed, 191 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7adc396 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: + chmod 755 *.cgi + chmod 775 rep + chgrp www-data rep diff --git a/diff.cgi b/diff.cgi new file mode 100755 index 0000000..c6176b3 --- /dev/null +++ b/diff.cgi @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import cgi, cgitb, os, time, urllib, sch +cgitb.enable() + +form = cgi.FieldStorage() + +if not form.has_key("fname"): + sch.error("No file name passed to script file") + +if not isinstance(form["fname"], list) or len(form["fname"]) != 2: + sch.error("You are required to pass exactly two file names.") + +fname = [form["fname"][0].value, form["fname"][1].value] + +if not sch.valid_fname(fname[0]) or not sch.valid_fname(fname[1]): + sch.error("Fuck off!") + +sch.print_header("Differences between '%s' and '%s'" % (fname[0], fname[1])) +sch.run_proc('/usr/local/bin/syrep --diff "%s/%s" "%s/%s"' % (sch.repository_directory, fname[0], sch.repository_directory, fname[1])) +sch.print_footer() diff --git a/info.cgi b/info.cgi new file mode 100755 index 0000000..6b65301 --- /dev/null +++ b/info.cgi @@ -0,0 +1,18 @@ +#!/usr/bin/python + +import cgi, cgitb, os, time, urllib, sch +cgitb.enable() + +form = cgi.FieldStorage() + +if not form.has_key("fname"): + sch.error("No file name passed to script file") + +fname = form["fname"].value + +if not sch.valid_fname(fname): + sch.error("Fuck off!") + +sch.print_header("File Info for '%s'" % fname) +sch.run_proc('/usr/local/bin/syrep --info "%s/%s" ' % (sch.repository_directory, fname)) +sch.print_footer() diff --git a/list.cgi b/list.cgi new file mode 100755 index 0000000..097c857 --- /dev/null +++ b/list.cgi @@ -0,0 +1,30 @@ +#!/usr/bin/python + +import cgi, cgitb, os, time, urllib, sch +cgitb.enable() + +def list_files(): + d = os.listdir(sch.repository_directory) + + for f in d: + st = os.stat(sch.repository_directory + "/" + f) + + print '<tr><td class="checkbox"><input type="checkbox" name="fname" value="%s"></td>' % cgi.escape(f) + print '<td class="filename"><a href="info.cgi?fname=%s">%s</a></td>' % (urllib.quote_plus(f), cgi.escape(f)) + print '<td class="filedate">%s</td></tr>' % time.strftime("%c", time.localtime(st.st_mtime)) + + +sch.print_header("File Listing") + +print '<form action="diff.cgi" method="get"><table><tr><th></th><th>File name</th><th>Modification date</th></tr>' + +list_files() + +print '<tr><td colspan="3" class="buttons">' + +print '<input name="diff" type="submit" value="SYREP Diff"/>' + +print '</td></tr></table></form>' + +sch.print_footer() + @@ -0,0 +1,49 @@ + +import cgi, sys, os + +repository_directory = "./rep" + +header_done = 0 + +def print_header(s): + global header_done + print "Content-Type: text/html" + print + + t = cgi.escape(s) + print '<html><head><title>syrep-chub: %s</title><link rel="stylesheet" type="text/css" href="style.css"></head><body><h1>%s</h1>' % (t, t) + header_done = 1 + +def print_footer(): + print '<div class="copyright">© Lennart Poettering 2003</div>' + print '</body></html>' + +def error(s): + global header_done + + if not header_done: + print_header("Error"); + + print '<div class="error">%s</div>' % cgi.escape(s) + print_footer(); + sys.exit(0); + +def run_proc(p): + print '<pre>' + fds = os.popen4(p, "r") + + for ln in fds[1]: + print cgi.escape(ln), + + fds[0].close() + fds[1].close() + + print '</pre>' + + +def valid_fname(fn): + + if fn.find("/") >= 0: + return 0 + + return 1 diff --git a/style.css b/style.css new file mode 100644 index 0000000..a723911 --- /dev/null +++ b/style.css @@ -0,0 +1,11 @@ +/* $Id$ */ + +td { padding: 5px; } +td.filename { width: 50ex; } +td.filedate { color: darkgray; font-size: small; text-align: right; } +th { text-align: left; background: #f0f0f0; border-bottom-width: 1px; border-bottom-style:solid; border-bottom-color: darkblue; padding: 5px;} +table { border-width: 1px; border-style:solid; border-color: darkblue; border-spacing: 0; empty-cells:show; } +td.buttons { border-top-width: 1px; border-top-style:solid; border-top-color: darkblue; background: #f0f0f0; padding: 5px; text-align: center; } +.error { color: red; background: #f0f0f0; padding: 10px; } +h1 { color: #00009F; } +div.copyright { color: lightgray; margin-top: 5px; margin-bottom: 5px; } 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() |