From f4f5053170a6bf8e45c15ea0435b86f5fa1b6d06 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 12 Nov 2003 21:41:46 +0000 Subject: initial commit git-svn-id: file:///home/lennart/svn/public/syrep-chub/trunk@2 4c8cc7d0-f3cb-0310-ad32-ddc431b48844 --- Makefile | 4 ++++ diff.cgi | 21 +++++++++++++++++++++ info.cgi | 18 ++++++++++++++++++ list.cgi | 30 ++++++++++++++++++++++++++++++ sch.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 11 +++++++++++ upload.cgi | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+) create mode 100644 Makefile create mode 100755 diff.cgi create mode 100755 info.cgi create mode 100755 list.cgi create mode 100644 sch.py create mode 100644 style.css create mode 100755 upload.cgi 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 '' % cgi.escape(f) + print '%s' % (urllib.quote_plus(f), cgi.escape(f)) + print '%s' % time.strftime("%c", time.localtime(st.st_mtime)) + + +sch.print_header("File Listing") + +print '
' + +list_files() + +print '
File nameModification date
' + +print '' + +print '
' + +sch.print_footer() + diff --git a/sch.py b/sch.py new file mode 100644 index 0000000..395cf1e --- /dev/null +++ b/sch.py @@ -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 'syrep-chub: %s

%s

' % (t, t) + header_done = 1 + +def print_footer(): + print '' + print '' + +def error(s): + global header_done + + if not header_done: + print_header("Error"); + + print '
%s
' % cgi.escape(s) + print_footer(); + sys.exit(0); + +def run_proc(p): + print '
'
+    fds = os.popen4(p, "r")
+
+    for ln in fds[1]:
+        print cgi.escape(ln),
+
+    fds[0].close()
+    fds[1].close()
+        
+    print '
' + + +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 "

Successful

" + +sch.print_footer() -- cgit