Changeset 30

Show
Ignore:
Timestamp:
02/16/05 08:59:16
Author:
tobias
Message:

Added link count moderation/blocking

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plugins/dnsbl/dnsbl.pl

    r28 r30  
    4444        caching_enabled cache_limit 
    4545        headers_enabled headers_moderate headers_ignore 
     46        urlcount_enabled urlcount_moderate_limit urlcount_block_limit 
    4647    ); 
    4748} 
     
    103104        unless exists $data->{headers_ignore}; 
    104105 
     106    $data->{urlcount_enabled} = 0 unless exists $data->{urlcount_enabled}; 
     107    $data->{urlcount_moderate_limit} = 5 unless exists $data->{urlcount_moderate_limit}; 
     108    $data->{urlcount_block_limit} = 10 unless exists $data->{urlcount_block_limit}; 
     109 
    105110    $data->{proxycheck_enabled} = 0 unless exists $data->{proxycheck_enabled}; 
    106111    $data->{proxycheck_moderate} = 1 unless exists $data->{proxycheck_moderate}; 
     
    114119sub filter { 
    115120    my ($eh, $app, $obj) = @_; 
    116      
     121 
    117122    # pull these from user configuration settings... 
    118123    my $data = $plugin->get_config_hash(); 
    119124 
    120     my (@urls, $blog); 
     125    my (@urls, $blog, $nurls); 
    121126    if (ref $obj eq 'MT::Comment') { 
    122127        return 1 unless $data->{comment_filter}; 
     
    125130 
    126131        # comment 
    127         @urls = extract_urls($obj->text); 
     132        @urls = extract_urls($obj->text, 0, \$nurls); 
    128133        push @urls, extract_urls($obj->url) if $obj->url; 
    129134        $data->{source_url} = $obj->url; 
     
    147152        $data->{__type} = 'Trackback ping'; 
    148153 
    149         if ($data->{domainbl_enabled}) { 
    150             @urls = extract_urls($obj->excerpt); 
     154        if ($data->{domainbl_enabled} || $data->{urlcount_enabled}) { 
     155            @urls = extract_urls($obj->excerpt, 0, \$nurls); 
    151156            push @urls, extract_urls($obj->source_url) if $obj->source_url; 
    152157        } 
     
    154159    } 
    155160    $data->{__urls} = \@urls; 
     161    $data->{__nurls} = $nurls; 
    156162 
    157163    require MT::Blog; 
     
    177183    push @tests, \&ipbl_check if $data->{ipbl_enabled}; 
    178184    push @tests, \&domainbl_check if $data->{domainbl_enabled}; 
     185    push @tests, \&urlcount_check if $data->{urlcount_enabled}; 
    179186    push @tests, \&proxy_check if $data->{proxycheck_enabled}; 
    180187 
     
    400407} 
    401408 
     409sub urlcount_check { 
     410    my ($eh, $app, $obj, $data) = @_; 
     411 
     412    my $type = $data->{__type}; 
     413    my $nurls = $data->{__nurls}; 
     414    if($nurls >= $data->{urlcount_block_limit}) { 
     415        $eh->error("Blocking $type on blog "  . $obj->blog_id . 
     416                   " because of too many (" . $nurls . 
     417                   ") links"); 
     418        return BLOCK; 
     419 
     420    }elsif($nurls >= $data->{urlcount_moderate_limit}) { 
     421        # what should we do for trackbacks? 
     422        if($type eq 'comment') { 
     423            $eh->error("Moderating $type on blog "  . $obj->blog_id . 
     424                       " because of many (" . $nurls . 
     425                       ") links"); 
     426            return MODERATE; 
     427        } 
     428    } 
     429    return IGNORE; 
     430} 
     431 
    402432sub cache_check { 
    403433    my ($eh, $app, $obj, $data) = @_; 
     
    477507 
    478508sub extract_urls { 
    479     my ($str, $single) = @_; 
     509    my ($str, $single, $total) = @_; 
    480510 
    481511    # unmunge so we can see encoded urls as well 
     
    492522        next unless @parts; 
    493523        if (($domain =~ m/^\d+\.\d+\.\d+\.\d+$/) || ($domain =~ m/^\d+$/)) { 
     524            $$total++ if(defined($total)); 
    494525            next if $seen{$domain}; 
    495526            $seen{$domain} = 1; 
     
    498529        } 
    499530        return $domain if $single; 
     531        $$total++ if(defined($total)); 
    500532        my $last = $#parts; 
    501533        my $start = length($parts[$last]) < 3 ? 2 : 1; 
  • trunk/plugins/dnsbl/tmpl/dnsbl.tmpl

    r26 r30  
    7171    <hr /> 
    7272 
     73    <input onclick="toggle(this, 'urlcount_prefs')" value="1" type="checkbox" name="urlcount_enabled" id="urlcount_enabled" <TMPL_IF NAME=URLCOUNT_ENABLED>checked="checked"</TMPL_IF> /><label for="urlcount_enabled">Enable link count limits. Moderation/Blocking of comments/trackbacks based on the number of links. </label><br /> 
     74    <div id="urlcount_prefs" class="sub-field" <TMPL_IF NAME=URLCOUNT_ENABLED>style="display: block"</TMPL_IF>> 
     75        <p>Moderation Limit. Comments with more links will be moderated automatically:<br /> 
     76        <input type="text" name="urlcount_moderate_limit" value="<TMPL_VAR NAME=URLCOUNT_MODERATE_LIMIT ESCAPE=HTML>" /> 
     77        </p> 
     78        <p>Block Limit. Comments/Trackbacks with more links will be blocked automatically:<br /> 
     79        <input type="text" name="urlcount_block_limit" value="<TMPL_VAR NAME=URLCOUNT_BLOCK_LIMIT ESCAPE=HTML>" /> 
     80        </p> 
     81 
     82    </div> 
     83 
     84    <hr />       
     85 
    7386    <input onclick="toggle(this, 'proxycheck_prefs')" value="1" type="checkbox" name="proxycheck_enabled" id="proxycheck_enabled" <TMPL_IF NAME=PROXYCHECK_ENABLED>checked="checked"</TMPL_IF> /><label for="proxycheck_enabled">Enable dynamic proxy checking. This involves a limited port scan for IPs that are not blacklisted. Not recommended if your web server cannot make outbound TCP/IP connections.</label><br /> 
    7487    <div id="proxycheck_prefs" class="sub-field" <TMPL_IF NAME=PROXYCHECK_ENABLED>style="display: block"</TMPL_IF>> 
  • trunk/readme.txt

    r29 r30  
    8181      legitimate cases. 
    8282 
     83    * Link count limitation. Moderate/Block comments and trackbacks 
     84      based on the number of links that appear in the message.  
    8385 
    8486CREDITS