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"
40 record-probing "$probeid"
41 printf "%s\n" >"$td"/"$outcome" "$message"
44 record-success () { record-outcome "$1" ok ''; }
45 record-tempfail () { record-outcome "$1" tempfail "$2"; }
46 record-permfail () { record-outcome "$1" permfail "$2"; }
53 record-probing "mx=$mx,addr=$addr"
56 swaks --to "${GROUP//./-}@$domain" \
58 --tls-optional-strict \
59 --header 'Subject: test modrelays probe test' \
61 "X-WebSTUMP-Relay-Probe: $GROUP $id $domain $mx $addr" \
62 -n >$td/swaks.log 2>$td/swaks.err
67 0) return ;; # record-success done by receiver
73 local expect_no_5xx='initial connection'
75 while read <&4 prefix rhs; do
80 if [ "x$expect_no_5xx" != x ] && \
81 [ "x$permfail" = x ]; then
82 permfail="$rhs ($expect_no_5xx)"
89 EHLO*|STARTTLS*) expect_no_5xx='' ;;
90 *) expect_no_5xx="after $rhs" ;;
97 if [ "x$permfail" = x ]; then
98 record-tempfail "mx=$mx,addr=$addr" "see swaks.log / swaks.err"
100 record-permfail "mx=$mx,addr=$addr" "$permfail"
110 adnshost -Fi -Tn +Do +Dt -t mx $domain >$td/dns
116 # have a list of MX's
122 while read <&3 pref mx statustype statustypenum rhs; do
123 case $statustypenum in
125 # have a list of relays
129 record-permfail "mx=$mx" \
139 INET|INET6) continue ;;
146 record-tempfail "mx=$mx" \
147 "dns $rc $statustype $rhs"
151 record-permfail "mx=$mx" \
152 "dns $rc $statustype $rhs"
162 adnshost -Fi -Tn +Do +Dt -t a $domain >$td/dns
170 # have a list of A's (dealt with MXs above)
173 while read <&3 addr; do
174 probe-addr 'NONE' $addr
182 record-tempfail dns "dns <no-mx> $emsg"
187 record-permfail dns "dns <no-mx> $emsg"
195 *) fail "no arguments to $mode allowed" ;;
201 if [ x"$WEBSTUMP_PROBE_LOCK" = x"$lockfile" ]; then return; fi
202 WEBSTUMP_PROBE_LOCK=$lockfile \
203 exec with-lock-ex $lock_mode "$lockfile" "$0" "$mode" "$@"
209 if $found_to_report; then return; fi
210 if ! [ -e "$attempt/$outcome" ]; then return; fi
213 read <"$attempt/$outcome" message
216 if [ -e "$attempt/reported" ]; then
217 read <"$attempt/reported" reported
219 if [ "x$outcome" = "x$reported" ]; then return; fi
221 if [ x"$outcome" = x"ok" ] && [ x"$reported" = x ]; then
222 echo ok >"$attempt/reported"
226 local info=${attempt##*/}
229 delim=`od -N 50 -An -x -w50 </dev/urandom`
232 local email="$attempt/.report.$outcome"
235 Subject: mod relay probe $outcome $info
236 Content-Type: multipart/mixed; boundary="$delim"
240 Content-Type: text/plain; charset="utf-8"
241 Content-Transfer-Encoding: 7bit
243 The moderation relay probe
245 resulted in the outcome
248 if [ "x$message" != x ]; then
255 if [ "x$reported" != x ]; then
257 This is even though previously the outcome seemed to be
259 and this was reported previously.
267 and concatenated to this email.
272 for log in "$attempt"/*; do
275 Content-Type: text/plain; charset="utf-8"
276 Content-Disposition: inline; filename="${log##*/}"
277 Content-Transfer-Encoding: 8bit
280 cat >>"$email" <"$log"
288 /usr/sbin/sendmail -odb -oem -oee -t <"$email"
289 echo "$outcome" >"$attempt"/reported
296 for attempt in $statedir/*; do
298 local now=$(date +%s)
299 local age=$(stat -c %Y "$attempt")
300 age=$(( $now - $age ))
302 local found_to_report=false
304 maybe-report permfail
305 maybe-report tempfail
307 if ! [ -e $attempt/reported ] && \
308 [ $age -gt $PROBE_TIMEOUT ]; then
309 echo >"$attempt"/timeout \
310 "Message did not arrive after ${PROBE_TIMEOUT}s"
315 if [ -e $attempt/reported ] && \
316 [ $age -gt $PROBE_EXPIRE ]; then
324 for domain in $MODRELAYS; do
331 xxx do something to cause sleeping
336 for domain in "$@"; do