Merge remote branch 'origin/master'
authorAlex Dehnert <adehnert@mit.edu>
Sat, 15 Dec 2012 10:10:38 +0000 (05:10 -0500)
committerAlex Dehnert <adehnert@mit.edu>
Sat, 15 Dec 2012 10:10:38 +0000 (05:10 -0500)
* origin/master:
  mail-merge: remind people to cd to the examples
  ldapfinger: show how to use ldaps and ldap-too
  Instructions for using mail-merge
  Install scripts read-only
  Update Makefile and README to reflect removed scripts
  Remove list-members
  Remove check-host script
  Remove card-access script
  Optionally show queries used in list-of-lists-updater
  Remove pag-screen, since it's maintained elsewhere
  Add sendmail-based mail merger
  Refactor out the actual mail-sending

Makefile
README
card-access [deleted file]
check-host [deleted file]
ldapfinger
list-members [deleted file]
list-of-lists-updater
mail-merge-help/README [new file with mode: 0644]
mail-merge-help/missing-whatever.test.csv [new file with mode: 0644]
mail-merge-help/missing-whatever.txt [new file with mode: 0644]
pag-screen [deleted file]

index 73a240e6855342647abbe6a3d1e81154650c8088..fbe3e67c6e49ec919ae5da1802365b083f067998 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,17 +3,14 @@ common=$(archdir)/common/
 
 scripts=\
     bores-me\
-    card-access\
     get-emails\
     grep-owners\
     ldapfinger\
-    list-members\
     list-of-lists-updater\
     lists-lint\
     mail-merge\
     make-zcrypt-key\
-    pag-screen\
-    rt-resolve check-host\
+    rt-resolve\
     rt-set\
     sshroot\
     update-officers\
@@ -27,7 +24,7 @@ arches=\
 all : install
 
 $(common)/% : %
-       cp $< $@
+       install -c -m 555 $< $@
 
 $(foreach script,$(scripts),$(foreach arch,$(arches),$(archdir)/$(arch)/bin/$(script))) : 
 #$(archdir)/*/bin/* :
diff --git a/README b/README
index e536f5b30459923b989adf2e7ca460d20ab4c3f0..0f0287f516d3d211184eae2dd0163a046e993948 100644 (file)
--- a/README
+++ b/README
@@ -1,20 +1,16 @@
-All scripts in this directory are Copyright (C) 2008--2010 Alex Dehnert
+All scripts in this directory are Copyright (C) 2008--2012 Alex Dehnert
 (and sometimes others)
 
 bores-me    - original
-card-access - original
-check-host  - original
 get-emails  - original
 grep-owners - original
 krbroot     - based on work by... nelhage?
 ldapfinger  - original
-list-members    - original (... and equivalent to blanche -l...)
 list-of-lists-updater   - original
 lists-lint  - original
 mail-merge  - original
 Makefile    - original
 make-zcrypt-key - original, with additions by Anders
-pag-screen  - based on work by... broder?
 rt-merge    - original
 rt-resolve  - original
 rt-set      - original
diff --git a/card-access b/card-access
deleted file mode 100755 (executable)
index 2362720..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/python
-
-import sys
-import os
-import csv
-import subprocess
-import ldap
-
-#columns = [ 'timestamp', 'first', 'last', 'email', 'constituency', 'year', 'major', 'cell', 'mitid', 'retreat', 'whynot', 'project', 'othermit', ]
-format = "%(first_with_initial)s;%(last_canonical)s;%(mitid)s"
-
-def dictize_line(header, line,):
-    line_dict = {}
-    for key, elem in zip(header, line, ):
-        line_dict[key]=elem
-    return line_dict
-
-
-
-def get_ldap_data(username, fields):
-    con = ldap.open('ldap.mit.edu')
-    con.simple_bind_s("", "")
-    dn = "dc=mit,dc=edu"
-    result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, 'uid=%s'%username, fields)
-    if len(result) > 1: print "WARNING: More than one result returned for %s" % username
-    if len(result) < 1: print "WARNING: Only one result returned for %s" % username
-    ret = {}
-    for key in result[0][1]:
-        ret[key] = result[0][1][key][0]
-    return ret
-
-def get_data_dict(line_dict):
-    email = line_dict['email']
-    username = email.lower().replace('@mit.edu', '')
-    ldap = get_ldap_data(username, [ 'cn' , 'sn' , 'givenName' ])
-    first = ldap['givenName'].replace(' ', '_').upper()
-    last = ldap['sn'].replace(' ', '_').upper()
-    mitid = line_dict['mitid']
-    data_dict = { 'first_with_initial': first, 'last_canonical': last, 'mitid': mitid }
-    return data_dict
-    
-def format_line(data_dict):
-    return format % data_dict
-    
-
-def do_produce_card_info(db = sys.stdin):
-    reader = csv.reader(db, )
-    lines = []
-
-    header = reader.next()
-    line_dict = dictize_line(header, header, )
-    data_dict = { 'first_with_initial': 'FIRST_M', 'last_canonical': 'LASTNAME', 'mitid': 'MIT ID' }
-    lines.append(format_line(data_dict))
-
-    for line in reader:
-        line_dict = dictize_line(header, line)
-        print line_dict
-        lines.append(format_line(get_data_dict(line_dict)))
-    print '\n'.join(lines)
-
-if __name__== '__main__':
-    do_produce_card_info()
diff --git a/check-host b/check-host
deleted file mode 100755 (executable)
index 51a137c..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-# Alex Dehnert
-
-for hostname in "$@"; do
-    echo
-    echo Now checking $hostname
-    echo Stella:
-    stella $hostname.mit.edu
-    echo Aliases
-    athrun ops qy ghal $hostname.mit.edu \*
-done
-
-echo
-echo For your copy/pasting convenience
-echo Please be careful that this makes sense with the output above
-echo
-echo At your convenience, please make $@.mit.edu an alias of scripts-vhosts.mit.edu.
-echo
-for hostname in "$@"; do
-    echo stella scripts-vhosts -a $hostname
-done
index 8eb1185b1311e8b02985d249f1c41d1197335070..759122621564048ead4d497b9544d7eeb2600dbf 100755 (executable)
@@ -5,3 +5,6 @@ for user in $@; do
     echo ldapsearch -h ldap.mit.edu -b dc=mit,dc=edu uid=$user
     ldapsearch -h ldap.mit.edu -b dc=mit,dc=edu uid=$user
 done
+
+echo Try also athrun consult ldaps
+echo or ldapsearch -x -h ldap-too.mit.edu -b ou=moira,dc=mit,dc=edu uid=$user
diff --git a/list-members b/list-members
deleted file mode 100755 (executable)
index f5f6213..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-# Alex Dehnert --- 2009-04-24
-# Print list members of a list
-# Takes a container mailing list on the commandline
-
-cont=$1
-cont=${cont:-ua-lists}
-
-blanche $cont | grep ^LIST | sed -e "s/^LIST://"
index 4018ac04bbef49cb551b03b17e10b645377e5733..756dae927064ec5dc7b2ed7c2a0f80df39edaa96 100755 (executable)
@@ -11,6 +11,11 @@ prev=${prev:-ua-lists}
 anti=${anti:-ua-foreign-lists}
 nativepat=${nativepat:-ua}
 
+function prefix {
+    #echo "$@"
+    "$@"
+}
+
 function add_lists
 {
     (
@@ -18,23 +23,23 @@ function add_lists
     for list in $lists; do # for each list we already know about
         # Add a list's sublists
         for newlist in $(blanche $list | grep LIST | cut -d : -f 2); do
-            blanche $prev -a $newlist;
+            prefix blanche $prev -a $newlist;
         done;
         # Add a list's owner and memacl
         owner=$(athrun ops qy -s -f ace_name glin $list)
         towner=$(athrun ops qy -s -f ace_type glin $list)
         if [[ "$towner" == "LIST" ]]; then
-            blanche $prev -a $owner
+            prefix blanche $prev -a $owner
         fi
         macl=$(athrun ops qy -s -f memace_name glin $list)
         tmacl=$(athrun ops qy -s -f memace_type glin $list)
         if [[ "$tmacl" == "LIST" ]]; then
-            blanche $prev -a $macl
+            prefix blanche $prev -a $macl
         fi
         # Add stuff this owns
         owned=$(athrun ops qy -s get_ace_use list $list | grep -v ^$prev\$ | grep LIST | cut -d " " -f 2)
         for newlist in $owned; do
-            blanche $prev -a $newlist;
+            prefix blanche $prev -a $newlist;
         done;
     done
     ) 2>&1 | grep -v "Record already exists" | grep -v "moira (query): No records in database match query"
diff --git a/mail-merge-help/README b/mail-merge-help/README
new file mode 100644 (file)
index 0000000..9890086
--- /dev/null
@@ -0,0 +1,27 @@
+Using the "mail-merge" script
+
+The mail-merge script (if this file is ./mail-merge-help/README, it should be
+./mail-merge) is a simple tool for combining a CSV file of data with a Python
+template for an email, and sending it out.
+
+The first argument is an address to receive copies of all emails sent out (generally an archive address (gmail, discuss, ...) or some list of your organization (esp@, asa-admin@, etc.). This address will be BCC'd; if you want it to be visible to the recipients, make sure to mention it in your template.
+
+Your template should contain full SMTP headers and be suitable for passing to Python's % operator. In particular, this usually means that it should start with To:, Subject:, etc. lines, and fields should be substituted using "%(fieldname)s". Note that the values of the To:, CC:, etc. fields in your template are independent from who actually recieves the email --- you can include a CC: of, say, asa-exec@mit.edu and pass asa-admin@mit.edu as the first argument of the script, and asa-admin@mit.edu will receive the emails, but to the recipients it will (mostly) appear that asa-exec@mit.edu did instead. This may be useful to encourage reply-all to go to the right place without actually spamming everybody on the list.
+
+Your CSV should contain a header line with the names of your fields, followed by several data lines. As is (definitionally) the case with any CSV file, fields on a given line should be comma-separated. The field named "email" will be used as the recipient of the email. The rest of the fields have no defined meaning, but can be substituted into your template.
+
+I recommend creating both a "test" CSV file, containing just one row with your email address, and a real CSV file. Run the mail merge script repeatedly on the test CSV file until you're happy with the template, and then run it on the real file.
+
+Sample files are also available in this directory.
+
+Putting these all together, you'll probably want a command like:
+add adehnert        # If on an Athena machine, to make the script available
+cd /mit/adehnert/Public/software/my-snippets/mail-merge-help                # change to the directory with your data files
+mail-merge asa-admin@mit.edu missing-whatever.txt missing-whatever.test.csv # repeat until the message looks good
+mail-merge asa-admin@mit.edu missing-whatever.txt missing-whatever.csv      # run just once
+
+The script will output the rows in the CSV file, as it parsed them, as it reads and processes them.
+
+The mail-merge command should work on any Athena machine (and most other machines with Python installed).
+
+Please feel free to contact me (adehnert@mit.edu) with any questions.
diff --git a/mail-merge-help/missing-whatever.test.csv b/mail-merge-help/missing-whatever.test.csv
new file mode 100644 (file)
index 0000000..27499b9
--- /dev/null
@@ -0,0 +1,2 @@
+"email","FNAME","LNAME",group_id
+"adehnert@mit.edu","Alex","Dehnert",1955
diff --git a/mail-merge-help/missing-whatever.txt b/mail-merge-help/missing-whatever.txt
new file mode 100644 (file)
index 0000000..a8bf8c5
--- /dev/null
@@ -0,0 +1,11 @@
+To: %(FNAME)s %(LNAME)s <%(email)s>
+Subject: Missing whatever for %(FNAME)s %(LNAME)s
+From: asa-exec@mit.edu
+CC: asa-exec@mit.edu
+
+Hello %(FNAME)s %(LNAME)s,
+
+You have not yet filled out the whatever form. You are required to do this before 1/1/1970. You can do so at https://asa.mit.edu/whatever/%(group_id)s.
+
+Thanks,
+ASA Exec
diff --git a/pag-screen b/pag-screen
deleted file mode 100755 (executable)
index c0c46e8..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env pagsh
-
-screen=`which screen`
-
-# Check for pre-existing screens.
-screenlist=`$screen -list | grep owl`
-if [ "x$screenlist" != "x" ]; then
-    echo "Found a pre-existing owl-screen session:"
-    echo "$screenlist"
-    echo "You probably want to reattach it instead."
-    echo
-    exit 1
-fi
-
-# Get AFS tokens for the screen session.
-# We are now in a new PAG (because of pagsh).
-# If you want to get tokens for other cells, list them in ~/.xlog
-aklog || echo "Failed to get new tokens"
-
-# Use separate kerberos tickets for screen. Even if we accidentally
-# (or intentionally) log out, screen and owl will still have tickets.
-NEWKRB5=/tmp/krb5cc_${USER}_screen
-
-# Copy the tickets we obtained on login to the screen tickets.
-KRB5CCNAME=`echo $KRB5CCNAME | sed 's/FILE://'`
-if [ "x$KRB5CCNAME" != "x" ]; then
-    cp $KRB5CCNAME $NEWKRB5
-else
-    echo "No tickets; not copying to new CC"
-fi
-
-# Now actually use the new tickets.
-KRB5CCNAME=FILE:$NEWKRB5; export KRB5CCNAME
-
-# Repeat for krb4 if appropriate.
-if [ "x$KRBTKFILE" != "x" ]; then
-   NEWKRB4=/tmp/tkt_${USER}_screen
-   KRBTKFILE=`echo $KRBTKFILE | sed 's/FILE://'`
-   cp $KRBTKFILE $NEWKRB4
-   KRBTKFILE=$NEWKRB4; export KRBTKFILE
-fi
-
-# Figure out which zephyr client to use.  Defaults to barnowl.
-if [ "x$ZEPHYR_SCREEN_CLIENT" = "x" ]; then
-    barnowl=`which barnowl`
-    if [ ! -x "$barnowl" ]; then
-       attach -n -q barnowl
-       barnowl=`athdir /mit/barnowl`/barnowl
-    fi
-    ZEPHYR_SCREEN_CLIENT="$barnowl"
-fi
-
-# Renew tickets and tokens.
-contrenew=`which cont-renew-notify`
-if [ ! -x "$contrenew" ]; then
-    zwrite $ATHENA_USER -d -m "$0: cont-renew doesn't exist on $(hostname)... Not doing renewals"
-    contrenew=/bin/true
-fi
-nohup $contrenew < /dev/null > /dev/null 2> /dev/null &
-
-# Name the screen pag so we can reattach the right screen later.
-$screen -S pag