Subject: The mailing list for listmasters using Sympa
List archive
- From: Steve Shipway <address@concealed>
- To: "Ed C." <address@concealed>, "address@concealed" <address@concealed>
- Subject: RE: [sympa-users] limit number of user posts
- Date: Fri, 11 Jan 2013 06:28:26 +0000
Here's a first hack attempt at a CustomConditions plugin for Sympa to allow
rate limiting. Not anywhere near properly tested. I doubt I'll have enough
opportunity to take this through to the end but anyone is welcome to pick it
up from here and run with it.
This needs you to create a table `postlimit` in the Sympa database in advance
-
robot VARCHAR(64)
listname VARCHAR(128)
sender VARCHAR(128)
lastdate VARCHAR(8)
pcount INT(8)
Primary key: robot/listname/sender
Note that this does not yet handle multiple robots - you could pass the robot
name via the parameters, or grab it from somewhere else? Also, it's a bit
naughty to use `count` as a column name, probably should be something else.
Place it in custom_conditions/postlimit.pm or in
<robotname>/custom_conditions/postlimit.pm and restart Sympa.
Use it like this:
CustomCondition::postlimit([listname],[sender],8,60) smtp,smime,md5 -> do_it
true() smtp,smime,md5 ->
reject(reason="Too many posts today")
If this were to be implemented properly, it should probably store per-list
limits in the list custom parameters; then create a plugin page for wwsympa
to maintain these, and a include.send.header file to add the limit to all
send scenari. If no custom parameter is set then disable the limit. As well
as a per-sender limit, there should be a per-list limit and maybe even a
per-robot limit (could implement these by summing the various pcount fields
of all records).
Feedback welcome.
Steve
Steve Shipway
ITS Unix Services Design Lead
University of Auckland, New Zealand
Floor 1, 58 Symonds Street, Auckland
Phone: +64 (0)9 3737599 ext 86487
DDI: +64 (0)9 924 6487
Mobile: +64 (0)21 753 189
Email: address@concealed
Please consider the environment before printing this e-mail :
打印本邮件,将减少一棵树存活的机会
---- cut here
#!/usr/bin/perl
#vim:ts=4
package CustomCondition::postlimit;
use strict;
use Log;
use POSIX qw(strftime);
use List;
sub verify {
my($listname,$sender,$limit)=@_;
my($lastdate,$count,$today);
my($robot);
my($rv,$sth);
my( $dbh ) = &List::db_get_handler();
unless ($dbh and $dbh->ping) {
unless( &List::db_connect() ) { # default to allow
do_log('err',"Unable to connect to database to check
post limit" );
return 1;
}
$dbh = &List::db_get_handler();
}
# get todays date
$today = strftime('%y%m%d',localtime());
# retrieve record from table or create new
$sth = $dbh->prepare("SELECT `lastdate`,`pcount` from `postlimit`
where `sender` = '$sender' and `listname` = '$listname' and `robot` =
'$robot'");
unless($sth) { # default to pass
do_log('err',"Unable to prepare statement to check post
limit" );
return 1;
}
$rv = $sth->execute();
$rv = $sth->fetchrow_array();
if($rv) {
($lastdate, $count) = @$rv;
} else {
($lastdate, $count) = ('',0);
}
# reset count if lastdate!=today
if( $lastdate != $today ) { $lastdate = $today, $count = 0; }
# increment count
$count += 1;
# update table
if($rv) {
$dbh->do("UPDATE `postlimit` set `lastdate` = '$lastdate',
`pcount` = $count WHERE `sender` = '$sender' and `listname` = '$listname' and
`robot` = '$robot'");
} else {
$dbh->do("INSERT into `postlimit` (
`robot`,`listname`,`sender`,`lastdate`,`pcount` ) VALUES (
'$robot','$listname','$sender','$lastdate',$count )");
}
# test value
return 1 if($count <= $limit);
do_log('warning',"Too many posts for $sender to $listname\@$robot (
$count > $limit )" );
return 0;
}
1;
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
-
[sympa-users] limit number of user posts,
Ed C., 01/10/2013
-
RE: [sympa-users] limit number of user posts,
Steve Shipway, 01/11/2013
-
RE: [sympa-users] limit number of user posts,
Steve Shipway, 01/11/2013
- Re: [sympa-users] limit number of user posts, Ed C., 01/11/2013
-
RE: [sympa-users] limit number of user posts,
Steve Shipway, 01/11/2013
-
RE: [sympa-users] limit number of user posts,
Steve Shipway, 01/11/2013
Archive powered by MHonArc 2.6.19+.