2015-07-28 22:44:53 +02:00
|
|
|
|
# Copyright (C) 2007–2015 Alex Schroeder <alex@gnu.org>
|
2007-10-27 18:49:26 +00:00
|
|
|
|
#
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
#
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
#
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
2015-03-29 16:34:41 +02:00
|
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
|
AddModuleDescription('multi-url-spam-block.pl', 'Multiple Link Ban Extension');
|
2007-10-27 18:49:26 +00:00
|
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
|
our ($BannedContent, @MyInitVariables, %AdminPages, %PlainTextPages, $FullUrlPattern, $LocalNamesPage);
|
2015-03-29 16:34:41 +02:00
|
|
|
|
|
2015-03-30 09:58:33 +03:00
|
|
|
|
*OldMultiUrlBannedContent = \&BannedContent;
|
|
|
|
|
|
*BannedContent = \&NewMultiUrlBannedContent;
|
2007-10-27 19:33:43 +00:00
|
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
|
our ($MultiUrlWhiteList, $MultiUrlLimit);
|
2007-11-02 17:34:41 +00:00
|
|
|
|
|
2007-11-06 10:23:29 +00:00
|
|
|
|
$MultiUrlLimit = 10;
|
2007-11-02 17:34:41 +00:00
|
|
|
|
$MultiUrlWhiteList = 'UrlWhitelist';
|
|
|
|
|
|
|
|
|
|
|
|
push(@MyInitVariables, sub {
|
|
|
|
|
|
$MultiUrlWhiteList = FreeToNormal($MultiUrlWhiteList);
|
|
|
|
|
|
$AdminPages{$MultiUrlWhiteList} = 1;
|
2007-11-02 17:38:47 +00:00
|
|
|
|
$PlainTextPages{$MultiUrlWhiteList} = 1;
|
2007-11-02 17:34:41 +00:00
|
|
|
|
});
|
2007-10-30 08:47:59 +00:00
|
|
|
|
|
2007-10-27 18:49:26 +00:00
|
|
|
|
sub NewMultiUrlBannedContent {
|
2008-01-12 22:55:56 +00:00
|
|
|
|
my $str = shift;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
if (not $LocalNamesPage
|
2008-01-12 22:55:56 +00:00
|
|
|
|
or GetParam('title', '') ne $LocalNamesPage) {
|
|
|
|
|
|
my $rule = MultiUrlBannedContent($str);
|
|
|
|
|
|
return $rule if $rule;
|
|
|
|
|
|
}
|
|
|
|
|
|
return OldMultiUrlBannedContent($str);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub MultiUrlBannedContent {
|
2007-10-27 18:49:26 +00:00
|
|
|
|
my $str = shift;
|
2015-08-23 21:22:12 +03:00
|
|
|
|
my @urls = $str =~ /$FullUrlPattern/g;
|
2007-10-27 18:49:26 +00:00
|
|
|
|
my %domains;
|
2007-11-02 17:34:41 +00:00
|
|
|
|
my %whitelist;
|
2007-10-27 18:49:26 +00:00
|
|
|
|
my $max = 0;
|
2007-11-02 17:34:41 +00:00
|
|
|
|
my $label = '[a-z]([a-z0-9-]*[a-z0-9])?'; # RFC 1034
|
|
|
|
|
|
foreach (split(/\n/, GetPageContent($MultiUrlWhiteList))) {
|
2015-08-23 21:22:12 +03:00
|
|
|
|
next unless m/^\s*($label\.$label)/i;
|
2007-11-02 17:34:41 +00:00
|
|
|
|
$whitelist{$1} = 1;
|
|
|
|
|
|
}
|
2007-10-27 18:49:26 +00:00
|
|
|
|
foreach my $url (@urls) {
|
|
|
|
|
|
my @urlparts = split('/', $url, 4);
|
|
|
|
|
|
my $domain = $urlparts[2];
|
|
|
|
|
|
my @domainparts = split('\.', $domain);
|
|
|
|
|
|
splice(@domainparts, 0, -2); # no subdomains
|
|
|
|
|
|
$domain = join('.', @domainparts);
|
2007-11-02 17:34:41 +00:00
|
|
|
|
next if $whitelist{$domain};
|
2007-10-27 18:49:26 +00:00
|
|
|
|
$domains{$domain}++;
|
|
|
|
|
|
$max = $domains{$domain} if $domains{$domain} > $max;
|
|
|
|
|
|
}
|
2007-10-30 08:47:59 +00:00
|
|
|
|
return Ts('You linked more than %s times to the same domain. It would seem that only a spammer would do this. Your edit is refused.', $MultiUrlLimit)
|
|
|
|
|
|
if $max > $MultiUrlLimit;
|
2007-10-27 18:49:26 +00:00
|
|
|
|
}
|