Updated for cron
authorZachary Seguin <ztseguin@csclub.uwaterloo.ca>
Tue, 2 Feb 2016 04:33:23 +0000 (23:33 -0500)
committerZachary Seguin <ztseguin@csclub.uwaterloo.ca>
Tue, 2 Feb 2016 04:33:23 +0000 (23:33 -0500)
disable-webspace [deleted file]
generate-expire-config [new file with mode: 0755]

diff --git a/disable-webspace b/disable-webspace
deleted file mode 100755 (executable)
index c590be2..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/bash
-
-#
-# CONFIGURATION
-#
-DISABLED_PAGE=/~sysadmin/expired/index.php
-
-#
-# Temporary files
-#
-EXPIRED_USERS=$(mktemp "/tmp/expired_users.XXXX")
-
-#
-# Identify expired accounts
-#
-
-# Get the current term
-YEAR=$(date '+%Y')
-MONTH=$(date '+%m')
-TERM_START_MONTH=$(($MONTH - (($MONTH - 1) % 4)))
-
-# NOTE: This is configured to give 1 months grace period
-if [ ${TERM_START_MONTH} -eq 1 ]; then
-   if [ ${MONTH} -eq 1 ]; then
-      TERM_FILTER="(!(term=F$((${YEAR} - 1))))(!(term=W${YEAR}))"
-   else
-      TERM_FILTER="(!(term=W${YEAR}))"
-   fi
-elif [ ${TERM_START_MONTH} -eq 5 ]; then
-   if [ ${MONTH} -eq 5 ]; then
-      TERM_FILTER="(!(term=W${YEAR}))(!(term=W${YEAR}))"
-   else
-      TERM_FILTER="(!(term=S${YEAR}))"
-   fi
-elif [ ${TERM_START_MONTH} -eq 9 ]; then
-   if [ ${MONTH} -eq 9 ]; then
-      TERM_FILTER="(!(term=S${YEAR}))(!(term=F${YEAR}))"
-   else
-      TERM_FILTER="(!(term=F${YEAR}))"
-   fi
-else
-   echo "Invalid term start month: ${TERM_START_MONTH}" >&2
-   exit 1
-fi
-
-# Find expired accounts
-ldapsearch -xb "ou=People,dc=csclub,dc=uwaterloo,dc=ca" "(&${TERM_FILTER}(objectClass=member))" | grep 'uid:' | awk '{print $2}' | sort -u > ${EXPIRED_USERS}
-
-#
-# Generate Apache config
-#
-for uid in $(cat ${EXPIRED_USERS}); do
-   if [ -d /users/${uid}/www ]; then
-      echo "<Directory /users/${uid}>"
-      echo "    AllowOverride None"
-      echo "    RewriteEngine On"
-      echo "    RewriteRule . ${DISABLED_PAGE} [L]"
-      echo "</Directory>"
-      echo ""
-   fi
-done
-
-rm -f ${EXPIRED_USERS}
diff --git a/generate-expire-config b/generate-expire-config
new file mode 100755 (executable)
index 0000000..c590be2
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+#
+# CONFIGURATION
+#
+DISABLED_PAGE=/~sysadmin/expired/index.php
+
+#
+# Temporary files
+#
+EXPIRED_USERS=$(mktemp "/tmp/expired_users.XXXX")
+
+#
+# Identify expired accounts
+#
+
+# Get the current term
+YEAR=$(date '+%Y')
+MONTH=$(date '+%m')
+TERM_START_MONTH=$(($MONTH - (($MONTH - 1) % 4)))
+
+# NOTE: This is configured to give 1 months grace period
+if [ ${TERM_START_MONTH} -eq 1 ]; then
+   if [ ${MONTH} -eq 1 ]; then
+      TERM_FILTER="(!(term=F$((${YEAR} - 1))))(!(term=W${YEAR}))"
+   else
+      TERM_FILTER="(!(term=W${YEAR}))"
+   fi
+elif [ ${TERM_START_MONTH} -eq 5 ]; then
+   if [ ${MONTH} -eq 5 ]; then
+      TERM_FILTER="(!(term=W${YEAR}))(!(term=W${YEAR}))"
+   else
+      TERM_FILTER="(!(term=S${YEAR}))"
+   fi
+elif [ ${TERM_START_MONTH} -eq 9 ]; then
+   if [ ${MONTH} -eq 9 ]; then
+      TERM_FILTER="(!(term=S${YEAR}))(!(term=F${YEAR}))"
+   else
+      TERM_FILTER="(!(term=F${YEAR}))"
+   fi
+else
+   echo "Invalid term start month: ${TERM_START_MONTH}" >&2
+   exit 1
+fi
+
+# Find expired accounts
+ldapsearch -xb "ou=People,dc=csclub,dc=uwaterloo,dc=ca" "(&${TERM_FILTER}(objectClass=member))" | grep 'uid:' | awk '{print $2}' | sort -u > ${EXPIRED_USERS}
+
+#
+# Generate Apache config
+#
+for uid in $(cat ${EXPIRED_USERS}); do
+   if [ -d /users/${uid}/www ]; then
+      echo "<Directory /users/${uid}>"
+      echo "    AllowOverride None"
+      echo "    RewriteEngine On"
+      echo "    RewriteRule . ${DISABLED_PAGE} [L]"
+      echo "</Directory>"
+      echo ""
+   fi
+done
+
+rm -f ${EXPIRED_USERS}