-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimqclean
More file actions
executable file
·91 lines (78 loc) · 2.23 KB
/
simqclean
File metadata and controls
executable file
·91 lines (78 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# simqclean
#
# Given a uniqname, remove all pending messages sent by that
# uniqname from the simta queues on the localhost. Removed
# messages are archived under /var/tmp for later analysis.
timestamp=$(date +%F-%T)
pre=/var/tmp/simqclean
simtadir=/var/spool/simta
unsafe=false
efile=false
usage() {
echo "Usage: $0 <uniqname> [ <uniqname> ... ]"
echo " $0 [ -e ] -s <string> "
exit 1
}
while getopts es opt; do
case $opt in
e) efile=true
;;
s) unsafe=true
;;
*)
usage
;;
esac
done
shift $(( OPTIND - 1 ))
if [[ $# -eq 0 ]]; then
usage
fi
type rndc &>/dev/null && rndc flush
type unbound-control &>/dev/null && unbound-control reload
state=started
for p in "$@" ; do
if $unsafe; then
echo "Removing messages containing $p"
pattern=$p
else
echo "Removing messages from $p"
pattern="^((X-Originating-User:)|([[:space:]]Authuser)|([[:space:]]auth=pass smtp.auth=)) $p;?$"
fi
savedir="${pre}/${p//[^a-zA-Z0-9@+_.-]/_}/${timestamp}"
if ! [[ -d "$savedir" ]]; then
mkdir -p "$savedir" || exit 1
fi
for q in slow fast; do
if $efile; then
find ${simtadir}/$q -ignore_readdir_race -maxdepth 1 -name E\* -type f | xargs -r egrep -l "$pattern" | sed -e 'p; s/E/D/;' > "${savedir}/files"
else
find ${simtadir}/$q -ignore_readdir_race -maxdepth 1 -name D\* -type f | xargs -r egrep -l "$pattern" | sed -e 'p; s/D/E/;' > "${savedir}/files"
fi
if [[ -s "${savedir}/files" ]]; then
if [[ $state != 'stopped' ]]; then
echo 'Stopping simta...'
if type systemctl &>/dev/null ; then
systemctl stop simta
else
/etc/init.d/simta stop
fi
state=stopped
fi
echo "Cleaning $q"
xargs -r -I spam mv spam "$savedir" < "${savedir}/files"
else
echo "No cleaning needed in $q"
fi
done
done
if [[ $state = 'stopped' ]]; then
sleep 4
echo 'Starting simta...'
if which systemctl &>/dev/null ; then
systemctl start simta
else
/etc/init.d/simta start
fi
fi