csc-industry
authorJeremy Roman <jbroman@csclub.uwaterloo.ca>
Sat, 23 Jul 2011 01:26:08 +0000 (21:26 -0400)
committerJeremy Roman <jbroman@csclub.uwaterloo.ca>
Sat, 23 Jul 2011 01:26:08 +0000 (21:26 -0400)
Makefile
industry/.htaccess [new file with mode: 0644]
industry/Makefile [new file with mode: 0644]
industry/archives.cgi [new file with mode: 0755]
services/directory.xml

index 53391b0..0e63001 100644 (file)
--- 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 (file)
index 0000000..1a59070
--- /dev/null
@@ -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 (file)
index 0000000..2671cc3
--- /dev/null
@@ -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 (executable)
index 0000000..302c776
--- /dev/null
@@ -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:])
index 6a30315..9c94e76 100644 (file)
@@ -5,5 +5,6 @@
 <directory title="Services">
  <diritem title="Usage Agreement" href="machine_usage" />
  <diritem title="Usage Agreement Summary" href="machine_usage_summary" />
- <diritem title="Webmail" href="https://mail.csclub.uwaterloo.ca/" />
+ <!--diritem title="Webmail" href="https://mail.csclub.uwaterloo.ca/" /-->
+ <diritem title="csc-industry" href="/industry" />
 </directory>