+#
+# enforces very strict permissions on configuration file $file.
+#
+
+function check_perms() {
+ local file=$1
+ local perms=`ls -ld $file`
+ perms=${perms:4:6}
+ if [ "$perms" != "------" ]; then
+ fatal "Configuration files must not be group or world readable! Dying on file $file"
+ fi
+ if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
+ fatal "Configuration files must be owned by root! Dying on file $file"
+ fi
+}
+
+# simple lowercase function
+function tolower() {
+ echo "$1" | tr [:upper:] [:lower:]
+}
+
+# simple to integer function
+function toint() {
+ echo "$1" | tr [:alpha:] -d
+}
+
+#
+# function isnow(): returns 1 if the time/day passed as $1 matches
+# the current time/day.
+#
+# format is <day> at <time>:
+# sunday at 16
+# 8th at 01
+# everyday at 22
+#
+
+# we grab the current time once, since processing
+# all the configs might take more than an hour.
+nowtime=`date +%H`
+nowday=`date +%d`
+nowdayofweek=`date +%A`
+nowdayofweek=`tolower "$nowdayofweek"`
+
+function isnow() {
+ local when="$1"
+ set -- $when
+ whendayofweek=$1; at=$2; whentime=$3;
+ whenday=`toint "$whendayofweek"`
+ whendayofweek=`tolower "$whendayofweek"`
+ whentime=`echo "$whentime" | sed 's/:[0-9][0-9]$//'`
+
+ if [ "$whendayofweek" == "everyday" ]; then
+ whendayofweek=$nowdayofweek
+ fi
+
+ if [ "$whenday" == "" ]; then
+ if [ "$whendayofweek" != "$nowdayofweek" ]; then
+ whendayofweek=${whendayofweek%s}
+ if [ "$whendayofweek" != "$nowdayofweek" ]; then
+ return 0
+ fi
+ fi
+ elif [ "$whenday" != "$nowday" ]; then
+ return 0
+ fi
+
+ [ "$at" == "at" ] || return 0
+ [ "$whentime" == "$nowtime" ] || return 0
+
+ return 1
+}