chiark / gitweb /
probes: Fix "read message" for if the message is empty
[modbot-ulm.git] / probes / modrelays-probe
index 27c5545d6f78a661ce656c97d099ca900ad0d896..22f00a718413f96eef809b89a6a0ef35981cb6b5 100755 (executable)
@@ -6,6 +6,16 @@ MODRELAYS=moderators.isc.org
 PROBE_TIMEOUT=$(( 20 * 60 ))
 PROBE_EXPIRE=$(( 32 * 86400 ))
 
+shopt -s nullglob
+
+case "$1" in
+received)
+       mode="$1"
+       cd "$2"
+       shift; shift; set "$mode" "$@"
+       ;;
+esac
+
 . ../global-settings
 . ./settings
 
@@ -18,20 +28,31 @@ fail () {
        exit 16
 }
 
-record-probing () {
-       # implicitly uses newsgroup, id, domain
+compute-td () {
+       # implicitly uses GROUP, id, domain
        # caller must "local td", which will be set
        local probeid=$1
 
-       probeid="$domain,${probeid//[^-=.,_0-9A-Za-z]/%/},$id"
+       probeid="$domain,${probeid//[^-=:.,_0-9A-Za-z]/%},$id"
        case $probeid in
-       .*|*/*) fail "yikes, sanitisation bug!" ;;
+       .*|*/*) fail "yikes, sanitisation bug ($probeid) !" ;;
        esac
 
        td="$statedir/$probeid"
+}
+
+record-probing () {
+       compute-td "$@"
        mkdir -p $td
 }
 
+record-probing-start () {
+       record-probing "$@"
+       if ! [ -e "$td/started" ]; then
+               date -R >"$td/started"
+       fi
+}
+
 record-outcome () {
        local probeid=$1
        local outcome=$2
@@ -50,7 +71,7 @@ probe-addr () {
        local addr=$2
 
        local td
-       record-probing "mx=$mx,addr=$addr"
+       record-probing-start "mx=$mx,addr=$addr"
 
        set +e
        swaks   --to "${GROUP//./-}@$domain" \
@@ -104,7 +125,7 @@ probe-addr () {
 probe-domain () {
        local domain=$1
        local td
-       record-probing dns
+       record-probing-start dns
        
        set +e
        adnshost -Fi -Tn +Do +Dt -t mx $domain >$td/dns
@@ -210,7 +231,7 @@ maybe-report () {
        if ! [ -e "$attempt/$outcome" ]; then return; fi
        found_to_report=true
 
-       read <"$attempt/$outcome" message
+       message=$(cat "$attempt/$outcome")
 
        local reported
        if [ -e "$attempt/reported" ]; then
@@ -242,6 +263,18 @@ Content-Transfer-Encoding: 7bit
 
 The moderation relay probe
   $info
+END
+
+       if [ -e "$attempt/started" ]; then
+               local started
+               read started <"$attempt/started"
+               cat >>"$email" <<END
+started at
+  $started
+END
+       fi
+
+       cat >>"$email" <<END
 resulted in the outcome
   $outcome
 END
@@ -274,6 +307,7 @@ END
 --$delim
 Content-Type: text/plain; charset="utf-8"
 Content-Disposition: inline; filename="${log##*/}"
+Content-Description: "${log##*/}"
 Content-Transfer-Encoding: 8bit
 
 END
@@ -319,17 +353,28 @@ mode_report () {
        done
 }
 
-mode_all () {
+mode_received () {
        no_args $#
-       for domain in $MODRELAYS; do
-               probe-domain $domain
+
+       local hn group id domain mx addr
+       while read hn group id domain mx addr; do
+               if [ x"$hn" != x"X-WebSTUMP-Relay-Probe:" ]; then continue; fi
+               if [ x"$group" != x"$GROUP" ]; then continue; fi
+               case " $id $domain $mx $addr" in
+               */*|' '.*)      fail "bad syntax" ;;
+               esac
+               local td
+               compute-td "mx=$mx,addr=$addr"
+               >"$td/ok" ||:
+               return
        done
 }
 
-mode_auto () {
+mode_all () {
        no_args $#
-       xxx do something to cause sleeping
-       mode_all
+       for domain in $MODRELAYS; do
+               probe-domain $domain
+       done
 }
 
 mode_domain () {