Re: Submission Quota?
Werner Reisberger <[email protected]>
| Newsgroups | gmane.mail.smartlist.user |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Oct 10, 2002 at 08:34:39AM -0400, Doug Mansfield wrote: > This is what I did, I just use a cron job to reset the wholog at whatever > interval I want. It limits a user to three posts (ends up 6 per day). I > put it in rc.local.s10 in both the list and digest. The first line checks > to make sure they aren't counted twice (once for the list and twice for the > digest or vise-versa). Thank you for your recipe. I wrote something which is better suited for me because I need a limit configurable for a certain member. You gave me some good hints which I incorporated. I am using a recipe and a shell script which enables me to set monthly or daily quota limits for a set of list members. It's possible to set the quota different for each user. If the quota limit is reached the subscriber gets a message indicating the current limit in the subject. A cronjob for housekeeping isn't necessary. I attached the recipe and the shell script. Werner
rc.local.s10
(text/plain, 831 B)
SENDMAIL=/usr/sbin/sendmail
# format of the quota file (quotaconf) <email address> <month|day>
# <number of postings>
# you need to create a directory named "pquota" in the list directory
# change the name/location of this directory in the sublimit.sh
# shell script
:0
* ? formail -rtzxTo: | multigram -b1 -m -l32500 quotaconf
{
SENDER=`formail -rtzxTo:`
# check if the quota limit is exceeded
QCHECK=`sublimit.sh $SENDER`
:0
* -1^0
* $$QCHECK^0
{
MAX=`grep -i $SENDER quotaconf | awk '{ print $3 }'`
RANGE=`grep -i $SENDER quotaconf | awk '{ print $2 }'`
SUBJECT="Max. Messages for this ${RANGE}: $MAX"
:0
|(formail -rkbt -I"From: List Admin <lists@$domain>" \
-I"Subject: $SUBJECT" -i "X-Loop: $list@$domain"; \
cat postlimit.txt) | $SENDMAIL -t
}
}
sublimit.sh
(application/x-sh, 1.2 KB)
#!/bin/sh
AWK=awk
SED=sed
GREP=egrep
DATE=date
EXPR=expr
CAT=cat
ECHO=echo
FIND=find
EXIT=exit
if [ $# != 1 ]; then
echo "Usage: $0 <email address>"
$EXIT -1
fi
QDIR=pquota
QFILE=quotaconf
SENDER=$1
RANGE=`$GREP -i $SENDER $QFILE | $AWK '{ print $2 }'`
MAX=`$GREP -i $SENDER $QFILE | $AWK '{ print $3 }'`
if $ECHO $RANGE | $GREP 'month|day' > /dev/null
$ECHO $MAX | $GREP '[0-9]+' > /dev/null
then
if [ "x$RANGE" = "xmonth" ]; then
TIME=`$DATE '+%m'`
fi
if [ "x$RANGE" = "xday" ]; then
TIME=`$DATE '+%d'`
fi
if [ -f $QDIR/$SENDER$TIME ]; then
COUNT=`$CAT $QDIR/$SENDER$TIME`
if [ $COUNT -lt $MAX ]; then
# increase posting count
COUNT=`$EXPR $COUNT + 1`
if [ $? -eq 0 ]; then
EX=0
$ECHO "$COUNT" > $QDIR/$SENDER${TIME}
EX=`$EXPR $EX + $?`
else
EX=-3
$ECHO "Cannot increase count for $SENDER"
fi
else
# max. no. of postings reached
EX=2
fi
else
$ECHO "1" > $QDIR/$SENDER$TIME
fi
else
EX=-1
echo "No valid parameters for member $SENDER"
fi
# do some housekeeping
$FIND $QDIR -mtime +40 -exec rm {} \;
$ECHO $EX
quotaconf
(text/plain, 62 B)
[email protected] month 7 [email protected] day 3