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" "$@"
228 # implicitly uses $outcome, $reported etc. - see maybe-report
229 echo "$outcome" >"$attempt"/reported
235 if $found_to_report; then return; fi
236 if ! [ -e "$attempt/$outcome" ]; then return; fi
239 message=$(cat "$attempt/$outcome")
242 if [ -e "$attempt/reported" ]; then
243 read <"$attempt/reported" reported
245 if [ "x$outcome" = "x$reported" ]; then return; fi
247 if [ x"$outcome" = x"ok" ] && [ x"$reported" = x ]; then
252 local info=${attempt##*/}
255 delim=`od -N 50 -An -x -w50 </dev/urandom`
258 local email="$attempt/.report.$outcome"
261 Subject: mod relay probe $outcome $info
262 Content-Type: multipart/mixed; boundary="$delim"
266 Content-Type: text/plain; charset="utf-8"
267 Content-Transfer-Encoding: 7bit
269 The moderation relay probe
273 if [ -e "$attempt/started" ]; then
275 read started <"$attempt/started"
283 resulted in the outcome
286 if [ "x$message" != x ]; then
293 if [ "x$reported" != x ]; then
295 This is even though previously the outcome seemed to be
297 and this was reported previously.
305 and concatenated to this email.
310 for log in "$attempt"/*; do
313 Content-Type: text/plain; charset="utf-8"
314 Content-Disposition: inline; filename="${log##*/}"
315 Content-Description: "${log##*/}"
316 Content-Transfer-Encoding: 8bit
319 cat >>"$email" <"$log"
327 /usr/sbin/sendmail -odb -oem -oee -t <"$email"
335 for attempt in $statedir/*; do
337 local now=$(date +%s)
338 local age=$(stat -c %Y "$attempt")
339 age=$(( $now - $age ))
341 local found_to_report=false
343 maybe-report permfail
344 maybe-report tempfail
346 if ! [ -e $attempt/reported ] && \
347 [ $age -gt $PROBE_TIMEOUT ]; then
348 echo >"$attempt"/timeout \
349 "Message did not arrive after ${PROBE_TIMEOUT}s"
354 if [ -e $attempt/reported ] && \
355 [ $age -gt $PROBE_EXPIRE ]; then
364 local hn group id domain mx addr
365 while read hn group id domain mx addr; do
366 if [ x"$hn" != x"X-WebSTUMP-Relay-Probe:" ]; then continue; fi
367 if [ x"$group" != x"$GROUP" ]; then continue; fi
368 case " $id $domain $mx $addr" in
369 */*|' '.*) fail "bad syntax" ;;
372 compute-td "mx=$mx,addr=$addr"
380 for domain in $MODRELAYS; do
386 for domain in "$@"; do