3 set -e$MODRELAYS_PROBE_SET_X
5 MODRELAYS=moderators.isc.org
6 PROBE_TIMEOUT=$(( 20 * 60 ))
7 PROBE_EXPIRE=$(( 32 * 86400 ))
15 shift; shift; set "$mode" "$@"
23 statedir=probes/probes
24 lockfile=$statedir/.lock
27 printf >&2 "%s\n" "modrelays-probe: error: $1"
32 # implicitly uses GROUP, id, domain
33 # caller must "local td", which will be set
36 probeid="$domain,${probeid//[^-=:.,_0-9A-Za-z]/%},$id"
38 .*|*/*) fail "yikes, sanitisation bug ($probeid) !" ;;
41 td="$statedir/$probeid"
49 record-probing-start () {
51 if ! [ -e "$td/started" ]; then
52 date -R >"$td/started"
61 record-probing "$probeid"
62 printf "%s\n" >"$td"/"$outcome" "$message"
65 record-success () { record-outcome "$1" ok ''; }
66 record-tempfail () { record-outcome "$1" tempfail "$2"; }
67 record-permfail () { record-outcome "$1" permfail "$2"; }
74 record-probing-start "mx=$mx,addr=$addr"
77 swaks --to "${GROUP//./-}@$domain" \
79 --tls-optional-strict \
80 --header 'Subject: test modrelays probe test' \
82 "X-WebSTUMP-Relay-Probe: $GROUP $id $domain $mx $addr" \
83 -n >$td/swaks.log 2>$td/swaks.err
88 0) return ;; # record-success done by receiver
94 local expect_no_5xx='initial connection'
96 while read <&4 prefix rhs; do
101 if [ "x$expect_no_5xx" != x ] && \
102 [ "x$permfail" = x ]; then
103 permfail="$rhs ($expect_no_5xx)"
110 EHLO*|STARTTLS*) expect_no_5xx='' ;;
111 *) expect_no_5xx="after $rhs" ;;
118 if [ "x$permfail" = x ]; then
119 record-tempfail "mx=$mx,addr=$addr" "see swaks.log / swaks.err"
121 record-permfail "mx=$mx,addr=$addr" "$permfail"
128 record-probing-start dns
131 adnshost -Fi -Tn +Do +Dt -t mx $domain >$td/dns
137 # have a list of MX's
143 while read <&3 pref mx statustype statustypenum rhs; do
144 case $statustypenum in
146 # have a list of relays
150 record-permfail "mx=$mx" \
160 INET|INET6) continue ;;
167 record-tempfail "mx=$mx" \
168 "dns $rc $statustype $rhs"
172 record-permfail "mx=$mx" \
173 "dns $rc $statustype $rhs"
183 adnshost -Fi -Tn +Do +Dt -t a $domain >$td/dns
191 # have a list of A's (dealt with MXs above)
194 while read <&3 addr; do
195 probe-addr 'NONE' $addr
203 record-tempfail dns "dns <no-mx> $emsg"
208 record-permfail dns "dns <no-mx> $emsg"
216 *) fail "no arguments to $mode allowed" ;;
222 if [ x"$WEBSTUMP_PROBE_LOCK" = x"$lockfile" ]; then return; fi
223 WEBSTUMP_PROBE_LOCK=$lockfile \
224 exec with-lock-ex $lock_mode "$lockfile" "$0" "$mode" "$@"
230 if $found_to_report; then return; fi
231 if ! [ -e "$attempt/$outcome" ]; then return; fi
234 message=$(cat "$attempt/$outcome")
237 if [ -e "$attempt/reported" ]; then
238 read <"$attempt/reported" reported
240 if [ "x$outcome" = "x$reported" ]; then return; fi
242 if [ x"$outcome" = x"ok" ] && [ x"$reported" = x ]; then
243 echo ok >"$attempt/reported"
247 local info=${attempt##*/}
250 delim=`od -N 50 -An -x -w50 </dev/urandom`
253 local email="$attempt/.report.$outcome"
256 Subject: mod relay probe $outcome $info
257 Content-Type: multipart/mixed; boundary="$delim"
261 Content-Type: text/plain; charset="utf-8"
262 Content-Transfer-Encoding: 7bit
264 The moderation relay probe
268 if [ -e "$attempt/started" ]; then
270 read started <"$attempt/started"
278 resulted in the outcome
281 if [ "x$message" != x ]; then
288 if [ "x$reported" != x ]; then
290 This is even though previously the outcome seemed to be
292 and this was reported previously.
300 and concatenated to this email.
305 for log in "$attempt"/*; do
308 Content-Type: text/plain; charset="utf-8"
309 Content-Disposition: inline; filename="${log##*/}"
310 Content-Description: "${log##*/}"
311 Content-Transfer-Encoding: 8bit
314 cat >>"$email" <"$log"
322 /usr/sbin/sendmail -odb -oem -oee -t <"$email"
323 echo "$outcome" >"$attempt"/reported
330 for attempt in $statedir/*; do
332 local now=$(date +%s)
333 local age=$(stat -c %Y "$attempt")
334 age=$(( $now - $age ))
336 local found_to_report=false
338 maybe-report permfail
339 maybe-report tempfail
341 if ! [ -e $attempt/reported ] && \
342 [ $age -gt $PROBE_TIMEOUT ]; then
343 echo >"$attempt"/timeout \
344 "Message did not arrive after ${PROBE_TIMEOUT}s"
349 if [ -e $attempt/reported ] && \
350 [ $age -gt $PROBE_EXPIRE ]; then
359 local hn group id domain mx addr
360 while read hn group id domain mx addr; do
361 if [ x"$hn" != x"X-WebSTUMP-Relay-Probe:" ]; then continue; fi
362 if [ x"$group" != x"$GROUP" ]; then continue; fi
363 case " $id $domain $mx $addr" in
364 */*|' '.*) fail "bad syntax" ;;
367 compute-td "mx=$mx,addr=$addr"
375 for domain in $MODRELAYS; do
381 for domain in "$@"; do