From 2c09bd7de700e1f4b17a55e972690e6030f06d44 Mon Sep 17 00:00:00 2001 From: Phil! Gold Date: Mon, 17 Oct 2016 10:30:26 -0400 Subject: [PATCH] Check SenderBase with either dig or host, depending on what's available. --- plugins/senderbase/senderbase | 42 ++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/plugins/senderbase/senderbase b/plugins/senderbase/senderbase index 921c056f..88da9590 100755 --- a/plugins/senderbase/senderbase +++ b/plugins/senderbase/senderbase @@ -42,20 +42,36 @@ This plugin is made available under a CC0 waiver: =cut -real_ip_address=${ip_address:-$(hostname -I | awk '{print $1}')} -ip_reversed=$(echo $real_ip_address | sed -re 's/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/\4.\3.\2.\1/') -query_host=${ip_reversed}.rf.senderbase.org +if which dig >/dev/null; then + query_program=dig + do_query () { + hostname=$1 + dig +short $hostname TXT | sed 's/"//g' | head -1 + } +elif which host >/dev/null; then + query_program=host + do_query () { + hostname=$1 + host -t TXT $hostname | grep -m 1 'descriptive text' | cut -d\" -f2 + } +else + query_program= + do_query () { + true + } +fi + +real_ip_address="${ip_address:-$(hostname -I | awk '{print $1}')}" +ip_reversed="$(echo $real_ip_address | sed -re 's/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/\4.\3.\2.\1/')" +query_host="${ip_reversed}.rf.senderbase.org" if [ "$1" = "autoconf" ]; then - if which dig >/dev/null; then - value=$(dig +short $query_host TXT | sed 's/"//g' | head -1) - if [ -n "$value" ]; then - echo 'yes' - else - echo "no (No SenderBase reputation for IP address ${ip_address}.)" - fi + if [ -z "$query_program" ]; then + echo 'no (No "dig" or "host" executable found.)' + elif [ -z "$(do_query "$query_host")" ]; then + echo "no (No SenderBase reputation for IP address ${ip_address}.)" else - echo 'no (No "dig" executable found.)' + echo 'yes' fi exit 0 fi @@ -73,5 +89,5 @@ EOF exit 0 fi -value=$(dig +short $query_host TXT | sed 's/"//g' | head -1) -echo reputation.value ${value:-U} +value="$(do_query "$query_host")" +echo reputation.value "${value:-U}"