comparison cgi-bin/webuser-notify.in @ 0:c7f6b056b673

First import of vendor version
author Peter Gervai <grin@grin.hu>
date Tue, 10 Mar 2009 13:49:58 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c7f6b056b673
1 #! /bin/sh
2
3 # send mail messages about new per-user DCC log files
4
5 # This script can be run by the daily DCC cron job after it has been
6 # 1. changed to contain the URL of the local DCC CGI scripts,
7 # 2. changed to use a locally suitable command to send mail
8 # 3. copied to the DCC libexec directory,
9 # 4. and made executable.
10 # It is remotely possible that the default values in this script are
11 # suitable and that you could use this script directly by putting
12 # the following in the libexec directory:
13 # #! /bin/sh
14 # sh /var/dcc/cgi-bin/webuser-notify -d $*
15 #
16 # This script expects to be called by the standard DCC cron job to read a
17 # series of user names on stdin, each of which has a new log file.
18 # Each user name must be prefixed with the appropriate subdirectory such
19 # as "local/". The single argument to this script must be the
20 # DCCM_USERDIRS or DCCIFD_USERDIRS_directory made into an absolute path.
21
22
23 # Copyright (c) 2008 by Rhyolite Software, LLC
24 #
25 # This agreement is not applicable to any entity which sells anti-spam
26 # solutions to others or provides an anti-spam solution as part of a
27 # security solution sold to other entities, or to a private network
28 # which employs the DCC or uses data provided by operation of the DCC
29 # but does not provide corresponding data to other users.
30 #
31 # Permission to use, copy, modify, and distribute this software without
32 # changes for any purpose with or without fee is hereby granted, provided
33 # that the above copyright notice and this permission notice appear in all
34 # copies and any distributed versions or copies are either unchanged
35 # or not called anything similar to "DCC" or "Distributed Checksum
36 # Clearinghouse".
37 #
38 # Parties not eligible to receive a license under this agreement can
39 # obtain a commercial license to use DCC by contacting Rhyolite Software
40 # at sales@rhyolite.com.
41 #
42 # A commercial license would be for Distributed Checksum and Reputation
43 # Clearinghouse software. That software includes additional features. This
44 # free license for Distributed ChecksumClearinghouse Software does not in any
45 # way grant permision to use Distributed Checksum and Reputation Clearinghouse
46 # software
47 #
48 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
49 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
50 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
51 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
52 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
53 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
54 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 # SOFTWARE.
56 # Rhyolite Software DCC 1.3.103-1.11 $Revision$
57
58
59 # http or https; prefer https.
60 HTTPS="https"
61
62 # URL of the CGI scripts
63 # you will probably need to change this
64 BASE=`hostname`
65 BASE=`expr "$BASE" : '.*\.\([^.]*\.[^.]*$\)' \| "$BASE"`
66 BASE="www.$BASE/DCC-cgi-bin"
67
68
69 SWITCH='#webuser mail-notify'
70
71 USAGE="`basename $0`: [-x] -d userdirs"
72 USERDIRS=
73 while getopts "xd:" c; do
74 case $c in
75 x) set -x;;
76 d) USERDIRS=$OPTARG;;
77 *) ;;
78 esac
79 done
80 shift `expr $OPTIND - 1 || true`
81 if test "$#" -ne 0 -o "$USERDIRS" = ""; then
82 echo "$USAGE" 1>&2
83 exit 1
84 fi
85 if test ! -d "$USERDIRS"; then
86 echo "userdir $1 is not a directory" 1>&2
87 exit 1
88 fi
89
90
91 while read NM; do
92 # ignore users that are not configured to use the machinery
93 if test ! -f "$USERDIRS/$NM/whiteclnt"; then
94 continue;
95 fi
96
97 DIR="$USERDIRS/$NM"
98
99 UNAME=`expr "$NM" : 'local/\(.*\)' \| "$NM"`
100 OK=no
101 BOX="$UNAME"
102 eval `sed -n -e '/^[^#]/q' \
103 -e "s/^$SWITCH=on mailbox=$/OK=yes;/p" \
104 -e "s/^$SWITCH=on mailbox=\(.*\)/BOX=\1;OK=yes;/p" \
105 -e "s/^$SWITCH=off.*/OK=no;/p" $USERDIRS/$NM/whiteclnt`
106 if test "$OK" != yes; then
107 # forget it if notifications are turned off for this user
108 continue
109 fi
110
111 # Don't send a notification of messages older than this file,
112 # because the user has already check them through the CGI scripts.
113 MARKER=notify.marker
114
115 # Postpone notifications until this file is current to avoid sending
116 # daily notes that the user is ignoring.
117 BLOCK=notify.block
118
119 # Send a notification when this file is current
120 PENDING=notify.pending
121
122 FND="find $DIR -follow"
123
124 if test -f $DIR/$PENDING; then
125 # Because `find -mtime -0` sometimes means `find -mtime -1`
126 # or vice versa, use this to see if $DIR/$PENDING is finally ready.
127 rm -f $DIR/$MARKER
128 touch $DIR/$MARKER
129 if test "`$FND -name $PENDING -newer $DIR/$MARKER`" != ""; then
130 continue;
131 fi
132 rm $DIR/$PENDING
133
134 else
135 if test -f $DIR/$MARKER; then
136 if test "`$FND -name 'msg.*' -newer $DIR/$MARKER \
137 | head -1`" = ""; then
138 # there are no messages the user has not seen
139 continue
140 fi
141 fi
142 # We have at least one new message. If we are blocked by having
143 # sent a notification within the past week, make a pending message.
144 rm -f $DIR/$MARKER
145 touch $DIR/$MARKER
146 if test "`$FND -name $BLOCK -newer $DIR/$MARKER`" != ""; then
147 mv $DIR/$BLOCK $DIR/$PENDING
148 continue;
149 fi
150 fi
151
152 # browsers don't tolerate '/' or '@' in usernames and passwords in URLs
153 URL_UNAME="`expr "$UNAME@" : '\([^/@]*@$\)' || true`$BASE"
154
155
156
157 ####################################################################
158 # Modify the following message to taste.
159
160 MAIL_SUBJECT="bulk mail notification for $UNAME"
161 if test "`basename @NOTIFYMAILER@`" = sendmail; then
162 HEADERS="Subject: $MAIL_SUBJECT
163 Precedence: bulk
164 "
165 CMD="@NOTIFYMAILER@ $BOX"
166 else
167 HEADERS=
168 CMD="@NOTIFYMAILER@ -s '$MAIL_SUBJECT' $BOX"
169 fi
170 eval $CMD <<EOF
171 $HEADERS
172 Recently logged bulk messages for $UNAME can be viewed at
173 $HTTPS://$URL_UNAME/list-log
174 Edit your whitelist at
175 $HTTPS://$URL_UNAME/edit-whiteclnt
176 if any of those are solicited bulk messages instead of spam
177 or to stop or redirect these messages.
178
179 The user name for both web pages is $UNAME
180 EOF
181
182 # no more of this mail for a week
183 NWEEK=`@PERL@ -e 'use POSIX;
184 print strftime("%y%m%d%H%M", localtime(time()+7*24*60*60))'`
185 rm -f $DIR/$BLOCK
186 touch -t "$NWEEK" $DIR/$BLOCK
187
188 done