GIF89a;
Mass Deface
"
echo
echo "Valid modes:"
echo
echo " -register Downloads the opendkim.org public key,"
echo " generates stats reporting GPG setup, and"
echo " sends a registration request"
echo
echo " -sendregistration Sends pre-setup GPG registration to"
ecoh " opendkim.org in case initial registration"
echo " has problems sending email"
echo
echo " -sendstats Sends latest OpenDKIM stats to opendkim.org"
echo
echo " -version Displays the version and exits"
exit 0
}
#
# SET_PATHS -- set PATH and SENDMAIL variables
#
set_paths()
{
# Try to ensure proper execution by adding likely paths
PATH=$PATH:/usr/sbin:/sbin:/usr/bin:/usr/lib
for i in /usr/local/bin /usr/local/sbin /opt/local/bin \
/opt/local/sbin /usr/sfw/bin /usr/sfw/sbin
do
if [ -d "$i" ]; then
PATH=$PATH:$i
export PATH
fi
done
# Solaris
if [ -f '/usr/lib/sendmail' ]
then
SENDMAIL="/usr/lib/sendmail"
else
SENDMAIL="/usr/sbin/sendmail"
fi
}
#
# CHECK_OPENSSL -- try to find the openssl binary
#
check_openssl()
{
OPENSSL=`which openssl`
if [ -z "$OPENSSL" ]; then
echo "${PROGNAME}: cannot locate openssl binary"
exit 1
fi
}
#
# CHECK_GPG -- try to find the gpg binary
#
check_gpg()
{
GPG=`which gpg`
if [ -z "$GPG" ]; then
echo "${PROGNAME}: cannot locate gpg binary"
exit 1
fi
}
#
# CHECK_GPG_SETUP -- verify the OpenDKIM public key is in the local keyring
#
check_gpg_setup()
{
GPGVERIFY=`gpg --homedir="$GNUPGDIR" --no-permission-warning --list-keys | \
grep "$STATEMAIL" | \
awk -FO '{print "O"$2}'`
if [ "$GPGVERIFY" != "$STATEMAIL" ]
then
echo "${PROGNAME}: could not verify imported GPG key for $STATEMAIL"
echo "${PROGNAME}: run \"${PROGNAME} -register\" first"
exit 1
fi
GPGSETUP=`gpg --homedir="$GNUPGDIR" --no-permission-warning --list-keys | \
grep -v "$STATEMAIL" | \
grep "OpenDKIM"`
if [ -z "$GPGSETUP" ]
then
echo "${PROGNAME}: GPG setup incomplete"
echo "${PROGNAME}: run \"${PROGNAME}\" again"
exit 1
fi
}
#
# CHECK_WEB_APP -- figure out what web "GET" application is available
#
check_web_app()
{
WGET=`which wget`
if [ ! -z "$WGET" ]
then
WEBAPP=wget
elif [ -z "$WGET" ]
then
CURL=`which curl`
if [ -z "$CURL" ]
then
echo "${PROGNAME}: cannot locate wget or curl"
exit 1
fi
WEBAPP=curl
fi
}
#
# GET_OPENDKIM_ORG_PUB_CERT -- go get the OpenDKIM public key for signing
#
get_opendkim_org_pub_cert()
{
# safety net
if [ $? != 0 ]
then
echo "${PROGNAME}: cannot locate wget or curl"
exit 1
fi
# get the md5 sum file first
if [ x"$WEBAPP" = x"wget" ]
then
"$WEBAPP" -q -c --tries=10 -T 340 \
-O "$ODKGNUPGMD5" "$ODKGNUPGMD5URL"
elif [ "$WEBAPP" = curl ]
then
"$WEBAPP" -s -m 340 "$ODKGNUPGMD5URL" > "$ODKGNUPGMD5"
fi
if [ $? != 0 ]
then
echo "${PROGNAME}: failed to retrieve ${ODKGNUPGMD5URL}"
exit 1
fi
# get the public cert
if [ "$WEBAPP" = wget ]
then
"$WEBAPP" -q -c --tries=10 -T 340 \
-O "$ODKGNUPGCERT" "$ODKGNUPGURL"
elif [ "$WEBAPP" = curl ]
then
"$WEBAPP" -s -m 340 "$ODKGNUPGURL" > "$ODKGNUPGCERT"
fi
if [ $? != 0 ]
then
echo "${PROGNAME}: failed to retrieve ${ODKGNUPGURL}"
exit 1
fi
# verify the md5 sum of the public cert
if [ -f "$ODKGNUPGMD5" ] && [ -f "$ODKGNUPGCERT" ]
then
ODKORGSUM=`cat "$ODKGNUPGMD5"`
LOCALSUM=`"$OPENSSL" md5 "$ODKGNUPGCERT" | awk '{print $2}'`
else
echo "${PROGNAME}: $ODKGNUPGMD5 or ${ODKGNUPGCERT} absent/unreadable"
exit 1
fi
if [ "$ODKORGSUM" != "$LOCALSUM" ]
then
echo "${PROGNAME}: MD5 checksum for $ODKGNUPGCERT failed"
echo "${PROGNAME}: (expecting ${ODKORGSUM}, got ${LOCALSUM})"
exit 1
fi
}
#
# INPUT_CONTACT_INFO -- prompt for details we want to store in the key
#
input_contact_info()
{
NAMEVALID=0
INPUTNAME=""
EMAILVALID=0
INPUTEMAIL=""
NAMELENGTH=0
CONTACTEMAIL=""
until [ "$NAMEVALID" = 1 ]
do
printf "Please enter your name: "
read INPUTNAME
NAMELENGTH=`echo "$INPUTNAME" | wc -c`
if [ "$NAMELENGTH" -lt 5 ]
then
INPUTNAME=""
echo "${PROGNAME}: name must be at least five characters long"
fi
if [ ! -z "$INPUTNAME" ]
then
NAMEVALID=1
fi
done
until [ "$EMAILVALID" = 1 ]
do
printf "Please enter your contact email for OpenDKIM stats: "
read INPUTEMAIL
CONTACTEMAIL=`echo $INPUTEMAIL | egrep '[^[:space:]]+\>@[a-zA-Z0-9_\.]+\.[a-zA-Z]{2,3}'`
if [ ! -z "$CONTACTEMAIL" ]
then
EMAILVALID=1
else
echo "${PROGNAME}: invalid email address syntax"
fi
done
}
#
# OPENDKIM_GPG_IMPORT -- set up GPG and import the OpenDKIM key
#
opendkim_gpg_import()
{
echo "${PROGNAME}: retrieving opendkim.org public GPG certificate"
get_opendkim_org_pub_cert
if [ $? != 0 ]
then
echo "${PROGNAME}: failed to retrieve opendkim.org public GPG certificate"
exit 1
fi
echo "${PROGNAME}: importing opendkim.org public GPG certificate"
if [ ! -d "$GNUPGDIR" ]
then
echo "${PROGNAME}: directory ${GNUPGDIR} missing"
exit 1
fi
cat > "${GNUPGDIR}/gpg.conf" <