chiark / gitweb /
probes: probe script can probe
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Oct 2017 13:57:02 +0000 (14:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Oct 2017 13:57:02 +0000 (14:57 +0100)
.gitignore
probes/modrelays-probe

index d73d369..ba70808 100644 (file)
@@ -47,3 +47,4 @@
 /settings.publish-rejection-kinds
 /moderators
 /persistent-autosettings
+/probes/probes
index 1c4ead4..6c78c62 100755 (executable)
@@ -2,6 +2,8 @@
 
 set -e
 
+. settings
+
 id=$(date +%s)_$$
 
 fail () {
@@ -11,36 +13,37 @@ fail () {
 
 record-probing () {
        # implicitly uses newsgroup, id, domain
-       # prints working dir filename
+       # caller must "local td", which will be set
        local probeid=$1
 
-       probeid=${probeid//[^=-.,_0-9A-Za-z]/%/}
+       probeid="$domain,${probeid//[^-=.,_0-9A-Za-z]/%/},$id"
        case $probeid in
        .*|*/*) fail "yikes, sanitisation bug!" ;;
        esac
 
-       local newtd="monitoring/modrelays.probes/$probeid"
-       mkdir -p $newtd
-       printf "%s" $newtd
+       td="probes/probes/$probeid"
+       mkdir -p $td
 }
 
 record-outcome () {
        local probeid=$1
        local outcome=$2
        local message=$3
-       local td=`record-probing "$probeid"`
-       printf "%s\n" >"$td"/"$outcome"
+       local td
+       record-probing "$probeid"
+       printf "%s\n" >"$td"/"$outcome" "$message"
 }
 
-record-success () { record-outcome "$1" ok '' }
-record-tempfail () { record-outcome "$1" tempfail "$2" }
-record-permfail () { record-outcome "$1" permfail "$2" }
+record-success () { record-outcome "$1" ok ''; }
+record-tempfail () { record-outcome "$1" tempfail "$2"; }
+record-permfail () { record-outcome "$1" permfail "$2"; }
 
 probe-addr () {
        local mx=$1
        local addr=$2
 
-       local td=`record-probing "mx=$mx,addr=$addr"`
+       local td
+       record-probing "mx=$mx,addr=$addr"
 
        set +e
        swaks   --to "${GROUP//./-/}@$domain" \
@@ -61,14 +64,15 @@ probe-addr () {
        local rhs
        local prefix
        local expect_no_5xx='initial connection'
-       while read <$td/swaks.log prefix rhs; do
+       exec <$td/swaks.log
+       while read prefix rhs; do
                case "$prefix" in
                '<'*)
                        case "$rhs" in
                        5*)
                                if [ "x$expect_no_5xx" != x ] && \
                                   [ "x$permfail" = x ]; then
-                                       permfail="$rhs ($expect_no_5xx)" ;;
+                                       permfail="$rhs ($expect_no_5xx)"
                                fi
                                ;;
                        esac
@@ -80,6 +84,7 @@ probe-addr () {
                        esac
                        ;;
                *)
+               esac
        done
 
        if [ "x$permfail" = x ]; then
@@ -91,7 +96,8 @@ probe-addr () {
 
 probe-domain () {
        local domain=$1
-       local td=`record-probing dns`
+       local td
+       record-probing dns
        
        set +e
        adnshost -Fi -Tn +Do +Dt -t mx $domain >$td/dns
@@ -106,8 +112,8 @@ probe-domain () {
                local mx
                local statustype
                local rhs
-               while read pref mx statustype rhs; do
-                       case $statustype in
+               while read pref mx statustype statustypenum rhs; do
+                       case $statustypenum in
                        0)
                                # have a list of relays
                                case $rhs in
@@ -116,9 +122,10 @@ probe-domain () {
                                        record-permfail "mx=$mx" \
                                                "dns format $rhs"
                                        continue
-                               ;;
-                               rhs=${rhs%%* (}
-                               rhs=${rhs# )}
+                                       ;;
+                               esac
+                               rhs=${rhs##* (}
+                               rhs=${rhs% )}
                                local addr
                                for addr in $rhs; do
                                        case $addr in
@@ -129,11 +136,13 @@ probe-domain () {
                                ;;
                        [123])
                                # temporary errors
-                               record-tempfail "mx=$mx" "dns $rc $rhs"
+                               record-tempfail "mx=$mx" \
+                                       "dns $rc $statustype $rhs"
                                ;;
                        *)
                                # yikes
-                               record-permfail "mx=$mx" "dns $rc $rhs"
+                               record-permfail "mx=$mx" \
+                                       "dns $rc $statustype $rhs"
                                ;;
                        esac
                done
@@ -141,9 +150,9 @@ probe-domain () {
                return
                ;;
        6)
-               permfail, try A
+               permfail, try A
                set +e
-               adnshost -Fi -Tn +Do +Dt -t a $domain >$td
+               adnshost -Fi -Tn +Do +Dt -t a $domain >$td/dns
                rc=$?
                set -e
                ;;
@@ -155,7 +164,7 @@ probe-domain () {
                exec <$td/dns
                local addr
                while read addr; do
-                       probe-addr '<no-mx>' $addr
+                       probe-addr 'NONE' $addr
                done
                record-success dns
                return
@@ -176,12 +185,14 @@ probe-domain () {
 no_args () {
        case $1 in
        0) return ;;
-       *) fail
+       *) fail "no arguments to $mode allowed" ;;
+       esac
+}
 
 mode_all () {
        no_args $#
        for domain in $MODRELAYS; do
-               probe $domain
+               probe-domain $domain
        done
 }
 
@@ -191,9 +202,10 @@ mode_auto () {
        mode_all
 }
 
-mode_relay () {
-       relay="$1"
-       probe "$relay"
+mode_domain () {
+       for domain in "$@"; do
+               probe-domain $domain
+       done
 }
 
 mode=$1; shift||: