3 set -e$MODRELAYS_PROBE_SET_X
5 MODRELAYS=moderators.isc.org
6 PROBE_TIMEOUT=$(( 20 * 60 ))
7 PROBE_EXPIRE=$(( 32 * 86400 ))
13 statedir=probes/probes
14 lockfile=$statedir/.lock
17 printf >&2 "%s\n" "modrelays-probe: error: $1"
22 # implicitly uses newsgroup, id, domain
23 # caller must "local td", which will be set
26 probeid="$domain,${probeid//[^-=.,_0-9A-Za-z]/%/},$id"
28 .*|*/*) fail "yikes, sanitisation bug!" ;;
31 td="$statedir/$probeid"
35 record-probing-start () {
37 if ! [ -e "$td/started" ]; then
38 date -R >"$td/started"
47 record-probing "$probeid"
48 printf "%s\n" >"$td"/"$outcome" "$message"
51 record-success () { record-outcome "$1" ok ''; }
52 record-tempfail () { record-outcome "$1" tempfail "$2"; }
53 record-permfail () { record-outcome "$1" permfail "$2"; }
60 record-probing-start "mx=$mx,addr=$addr"
63 swaks --to "${GROUP//./-}@$domain" \
65 --tls-optional-strict \
66 --header 'Subject: test modrelays probe test' \
68 "X-WebSTUMP-Relay-Probe: $GROUP $id $domain $mx $addr" \
69 -n >$td/swaks.log 2>$td/swaks.err
74 0) return ;; # record-success done by receiver
80 local expect_no_5xx='initial connection'
82 while read <&4 prefix rhs; do
87 if [ "x$expect_no_5xx" != x ] && \
88 [ "x$permfail" = x ]; then
89 permfail="$rhs ($expect_no_5xx)"
96 EHLO*|STARTTLS*) expect_no_5xx='' ;;
97 *) expect_no_5xx="after $rhs" ;;
104 if [ "x$permfail" = x ]; then
105 record-tempfail "mx=$mx,addr=$addr" "see swaks.log / swaks.err"
107 record-permfail "mx=$mx,addr=$addr" "$permfail"
114 record-probing-start dns
117 adnshost -Fi -Tn +Do +Dt -t mx $domain >$td/dns
123 # have a list of MX's
129 while read <&3 pref mx statustype statustypenum rhs; do
130 case $statustypenum in
132 # have a list of relays
136 record-permfail "mx=$mx" \
146 INET|INET6) continue ;;
153 record-tempfail "mx=$mx" \
154 "dns $rc $statustype $rhs"
158 record-permfail "mx=$mx" \
159 "dns $rc $statustype $rhs"
169 adnshost -Fi -Tn +Do +Dt -t a $domain >$td/dns
177 # have a list of A's (dealt with MXs above)
180 while read <&3 addr; do
181 probe-addr 'NONE' $addr
189 record-tempfail dns "dns <no-mx> $emsg"
194 record-permfail dns "dns <no-mx> $emsg"
202 *) fail "no arguments to $mode allowed" ;;
208 if [ x"$WEBSTUMP_PROBE_LOCK" = x"$lockfile" ]; then return; fi
209 WEBSTUMP_PROBE_LOCK=$lockfile \
210 exec with-lock-ex $lock_mode "$lockfile" "$0" "$mode" "$@"
216 if $found_to_report; then return; fi
217 if ! [ -e "$attempt/$outcome" ]; then return; fi
220 read <"$attempt/$outcome" message
223 if [ -e "$attempt/reported" ]; then
224 read <"$attempt/reported" reported
226 if [ "x$outcome" = "x$reported" ]; then return; fi
228 if [ x"$outcome" = x"ok" ] && [ x"$reported" = x ]; then
229 echo ok >"$attempt/reported"
233 local info=${attempt##*/}
236 delim=`od -N 50 -An -x -w50 </dev/urandom`
239 local email="$attempt/.report.$outcome"
242 Subject: mod relay probe $outcome $info
243 Content-Type: multipart/mixed; boundary="$delim"
247 Content-Type: text/plain; charset="utf-8"
248 Content-Transfer-Encoding: 7bit
250 The moderation relay probe
254 if [ -e "$attempt/started" ]; then
256 read started <"$attempt/started"
264 resulted in the outcome
267 if [ "x$message" != x ]; then
274 if [ "x$reported" != x ]; then
276 This is even though previously the outcome seemed to be
278 and this was reported previously.
286 and concatenated to this email.
291 for log in "$attempt"/*; do
294 Content-Type: text/plain; charset="utf-8"
295 Content-Disposition: inline; filename="${log##*/}"
296 Content-Description: "${log##*/}"
297 Content-Transfer-Encoding: 8bit
300 cat >>"$email" <"$log"
308 /usr/sbin/sendmail -odb -oem -oee -t <"$email"
309 echo "$outcome" >"$attempt"/reported
316 for attempt in $statedir/*; do
318 local now=$(date +%s)
319 local age=$(stat -c %Y "$attempt")
320 age=$(( $now - $age ))
322 local found_to_report=false
324 maybe-report permfail
325 maybe-report tempfail
327 if ! [ -e $attempt/reported ] && \
328 [ $age -gt $PROBE_TIMEOUT ]; then
329 echo >"$attempt"/timeout \
330 "Message did not arrive after ${PROBE_TIMEOUT}s"
335 if [ -e $attempt/reported ] && \
336 [ $age -gt $PROBE_EXPIRE ]; then
344 for domain in $MODRELAYS; do
351 xxx do something to cause sleeping
356 for domain in "$@"; do