From 2baff0f4699d3de92176b1afccfd5d5b11e9d04c Mon Sep 17 00:00:00 2001 From: Jeremy Roman Date: Fri, 22 Jul 2011 21:26:08 -0400 Subject: [PATCH] csc-industry --- Makefile | 2 +- industry/.htaccess | 4 ++++ industry/Makefile | 3 +++ industry/archives.cgi | 42 ++++++++++++++++++++++++++++++++++++++++++ services/directory.xml | 3 ++- 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 industry/.htaccess create mode 100644 industry/Makefile create mode 100755 industry/archives.cgi diff --git a/Makefile b/Makefile index 53391b0..0e63001 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SHELL = umask 002; exec /bin/sh FILES = events.ics events.atom news.atom index.html stats.html \ favicon.ico default.css csclub.der csclub.pem robots.txt -SUBDIRS = about events office news services media buttons logos flash library +SUBDIRS = about events office news services media buttons logos flash library industry include common.mk diff --git a/industry/.htaccess b/industry/.htaccess new file mode 100644 index 0000000..1a59070 --- /dev/null +++ b/industry/.htaccess @@ -0,0 +1,4 @@ +AddHandler cgi-script .cgi +Options +Indexes +ExecCGI +RewriteEngine On +RewriteRule ^$ /mailman/listinfo/csc-industry [R] diff --git a/industry/Makefile b/industry/Makefile new file mode 100644 index 0000000..2671cc3 --- /dev/null +++ b/industry/Makefile @@ -0,0 +1,3 @@ +FILES = .htaccess archives.cgi +RELDIR = industry/ +include ../common.mk diff --git a/industry/archives.cgi b/industry/archives.cgi new file mode 100755 index 0000000..302c776 --- /dev/null +++ b/industry/archives.cgi @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import os +from md5 import md5 +os.umask(0027) + +ARCHIVE_LIST = 'csc-industry' +ARCHIVE_MBOX = '/var/lib/mailman/archives/private/%s.mbox/%s.mbox' % (ARCHIVE_LIST, ARCHIVE_LIST) +ARCHIVE_PCK = '/tmp/%s-%s.pck' % (ARCHIVE_LIST, md5(os.path.abspath(__file__)).hexdigest()) + +try: + mbox_mtime = os.stat(ARCHIVE_MBOX).st_mtime +except: + print 'Content-Type: text/plain\r\n\r\nUnable to stat archive.' + exit() + +try: + stat = os.stat(ARCHIVE_PCK) + pickle_mtime = stat.st_mtime + if stat.st_uid != os.getuid(): + pickle_mtime = 0 +except: + pickle_mtime = 0 + +import pickle, json + +if pickle_mtime < mbox_mtime: + import mailbox + mbox = mailbox.UnixMailbox(open(ARCHIVE_MBOX, 'r')) + messages = [] + for msg in mbox: + messages.append({ + 'subject': msg['subject'], + 'date': msg['date'], + 'from': msg['from'] + }) + pck = open(ARCHIVE_PCK, 'w') + pickle.dump(messages, pck) +else: + pck = open(ARCHIVE_PCK, 'r') + messages = pickle.load(pck) + +print 'Content-Type: application/json\r\n\r\n' + json.dumps(messages[-3:]) diff --git a/services/directory.xml b/services/directory.xml index 6a30315..9c94e76 100644 --- a/services/directory.xml +++ b/services/directory.xml @@ -5,5 +5,6 @@ - + +