3 set -e$MODRELAYS_PROBE_SET_X
5 MODRELAYS=moderators.isc.org
6 PROBE_TIMEOUT=$(( 20 * 60 ))
7 PROBE_EXPIRE=$(( 32 * 86400 ))
13 shift; shift; set "$mode" "$@"
21 statedir=probes/probes
22 lockfile=$statedir/.lock
25 printf >&2 "%s\n" "modrelays-probe: error: $1"
30 # implicitly uses GROUP, id, domain
31 # caller must "local td", which will be set
34 probeid="$domain,${probeid//[^-=:.,_0-9A-Za-z]/%},$id"
36 .*|*/*) fail "yikes, sanitisation bug ($probeid) !" ;;
39 td="$statedir/$probeid"
47 record-probing-start () {
49 if ! [ -e "$td/started" ]; then
50 date -R >"$td/started"
59 record-probing "$probeid"
60 printf "%s\n" >"$td"/"$outcome" "$message"
63 record-success () { record-outcome "$1" ok ''; }
64 record-tempfail () { record-outcome "$1" tempfail "$2"; }
65 record-permfail () { record-outcome "$1" permfail "$2"; }
72 record-probing-start "mx=$mx,addr=$addr"
75 swaks --to "${GROUP//./-}@$domain" \
77 --tls-optional-strict \
78 --header 'Subject: test modrelays probe test' \
80 "X-WebSTUMP-Relay-Probe: $GROUP $id $domain $mx $addr" \
81 -n >$td/swaks.log 2>$td/swaks.err
86 0) return ;; # record-success done by receiver
92 local expect_no_5xx='initial connection'
94 while read <&4 prefix rhs; do
99 if [ "x$expect_no_5xx" != x ] && \
100 [ "x$permfail" = x ]; then
101 permfail="$rhs ($expect_no_5xx)"
108 EHLO*|STARTTLS*) expect_no_5xx='' ;;
109 *) expect_no_5xx="after $rhs" ;;
116 if [ "x$permfail" = x ]; then
117 record-tempfail "mx=$mx,addr=$addr" "see swaks.log / swaks.err"
119 record-permfail "mx=$mx,addr=$addr" "$permfail"
126 record-probing-start dns
129 adnshost -Fi -Tn +Do +Dt -t mx $domain >$td/dns
135 # have a list of MX's
141 while read <&3 pref mx statustype statustypenum rhs; do
142 case $statustypenum in
144 # have a list of relays
148 record-permfail "mx=$mx" \
158 INET|INET6) continue ;;
165 record-tempfail "mx=$mx" \
166 "dns $rc $statustype $rhs"
170 record-permfail "mx=$mx" \
171 "dns $rc $statustype $rhs"
181 adnshost -Fi -Tn +Do +Dt -t a $domain >$td/dns
189 # have a list of A's (dealt with MXs above)
192 while read <&3 addr; do
193 probe-addr 'NONE' $addr
201 record-tempfail dns "dns <no-mx> $emsg"
206 record-permfail dns "dns <no-mx> $emsg"
214 *) fail "no arguments to $mode allowed" ;;
220 if [ x"$WEBSTUMP_PROBE_LOCK" = x"$lockfile" ]; then return; fi
221 WEBSTUMP_PROBE_LOCK=$lockfile \
222 exec with-lock-ex $lock_mode "$lockfile" "$0" "$mode" "$@"
228 if $found_to_report; then return; fi
229 if ! [ -e "$attempt/$outcome" ]; then return; fi
232 read <"$attempt/$outcome" message
235 if [ -e "$attempt/reported" ]; then
236 read <"$attempt/reported" reported
238 if [ "x$outcome" = "x$reported" ]; then return; fi
240 if [ x"$outcome" = x"ok" ] && [ x"$reported" = x ]; then
241 echo ok >"$attempt/reported"
245 local info=${attempt##*/}
248 delim=`od -N 50 -An -x -w50 </dev/urandom`
251 local email="$attempt/.report.$outcome"
254 Subject: mod relay probe $outcome $info
255 Content-Type: multipart/mixed; boundary="$delim"
259 Content-Type: text/plain; charset="utf-8"
260 Content-Transfer-Encoding: 7bit
262 The moderation relay probe
266 if [ -e "$attempt/started" ]; then
268 read started <"$attempt/started"
276 resulted in the outcome
279 if [ "x$message" != x ]; then
286 if [ "x$reported" != x ]; then
288 This is even though previously the outcome seemed to be
290 and this was reported previously.
298 and concatenated to this email.
303 for log in "$attempt"/*; do
306 Content-Type: text/plain; charset="utf-8"
307 Content-Disposition: inline; filename="${log##*/}"
308 Content-Description: "${log##*/}"
309 Content-Transfer-Encoding: 8bit
312 cat >>"$email" <"$log"
320 /usr/sbin/sendmail -odb -oem -oee -t <"$email"
321 echo "$outcome" >"$attempt"/reported
328 for attempt in $statedir/*; do
330 local now=$(date +%s)
331 local age=$(stat -c %Y "$attempt")
332 age=$(( $now - $age ))
334 local found_to_report=false
336 maybe-report permfail
337 maybe-report tempfail
339 if ! [ -e $attempt/reported ] && \
340 [ $age -gt $PROBE_TIMEOUT ]; then
341 echo >"$attempt"/timeout \
342 "Message did not arrive after ${PROBE_TIMEOUT}s"
347 if [ -e $attempt/reported ] && \
348 [ $age -gt $PROBE_EXPIRE ]; then
357 local hn group id domain mx addr
358 while read hn group id domain mx addr; do
359 if [ x"$hn" != x"X-WebSTUMP-Relay-Probe:" ]; then continue; fi
360 if [ x"$group" != x"$GROUP" ]; then continue; fi
361 case " $id $domain $mx $addr" in
362 */*|' '.*) fail "bad syntax" ;;
365 compute-td "mx=$mx,addr=$addr"
373 for domain in $MODRELAYS; do
379 for domain in "$@"; do