Changeset 95
- Timestamp:
- 04/13/05 12:27:08
- Files:
-
- trunk/plugins/spamlookup/spamlookup.pl (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plugins/spamlookup/spamlookup.pl
r94 r95 212 212 $data->{__blog} = MT::Blog->load($obj->blog_id); 213 213 return 0 unless $data->{__blog}; 214 $data->{__blogname} = qq{"}.$data->{__blog}->name.qq{" (id }.$obj->blog_id.qq{)};215 214 216 215 my $pdata; … … 260 259 my ($result, @errors); 261 260 foreach (@tests) { 261 delete $data->{__reason}; 262 262 $result = $_->[0]->($eh, $app, $obj, $data); 263 if ((defined $eh->errstr) && ($eh->errstr =~ m/\w/)) { 264 push @errors, $eh->errstr . ' ('.$_->[1].')'; 265 $eh->error(undef); 263 if (exists $data->{__reason}) { 264 push @errors, log_message( Reason => $data->{__reason}, 265 Object => $obj, Test => $_->[1], Result => $result, 266 BlogID => $data->{__blog}->id, Blog => $data->{__blog}->name ); 266 267 } 267 268 if (defined $result && ($result == ACCEPT)) { … … 340 341 } 341 342 343 sub log_message { 344 # arguments to this function: 345 # Reason: textual reason for block/moderate action 346 # Object: the object being acted upon 347 # Test: the name of the test that caused the action 348 # Result: BLOCK or MODERATE constant 349 # BlogID: the blog id for this object 350 # Blog: the blog name for this object 351 352 my %args = @_; 353 354 my $obj = $args{Object}; 355 356 $args{Result} = $args{Result} == BLOCK ? "Blocking" : "Moderating"; 357 $args{Type} = ref $obj eq 'MT::Comment' ? 'Comment' : 'TrackBack Ping'; 358 if (ref $obj eq 'MT::Comment') { 359 $args{EntryID} = $obj->entry_id; 360 } elsif ($obj->tb_id) { 361 my $tb = MT::Trackback->load($obj->tb_id); 362 if ($tb->entry_id) { 363 $args{EntryID} = $tb->entry_id; 364 } else { 365 $args{CategoryID} = $tb->category_id; 366 if (my $cat = MT::Category->load($args{CategoryID})) { 367 $args{Category} = $cat->label; 368 $args{Title} = $args{Category}; 369 } 370 } 371 } 372 if ($args{EntryID}) { 373 if (my $entry = MT::Entry->load($args{EntryID})) { 374 $args{Entry} = $entry->title; 375 $args{Title} = $args{Entry}; 376 } 377 } 378 $args{ObjType} = $args{EntryID} ? "entry" : "category"; 379 $args{ObjID} = $args{EntryID} || $args{CategoryID}; 380 381 # Blocking Comment for blog "My Blog", entry "Once upon a time": URL count test reported "REASON" 382 return sprintf(qq{%s %s for blog "%s" (%d), %s "%s" (%d): %s reported %s}, 383 $args{Result}, $args{Type}, $args{Blog}, $args{BlogID}, 384 $args{ObjType}, $args{Title}, $args{ObjID}, 385 $args{Test}, $args{Reason}); 386 } 387 342 388 ## "Check" routines... one for each type of test we perform... 343 389 ## Each returns one of three states: 0 to reject, 1 to accept, undef … … 358 404 my $entry = MT::Entry->load($tb->entry_id); 359 405 if ($entry && !$entry->allow_pings) { 360 $ eh->error("Blocking ".$data->{__type}." on blog id ".$obj->blog_id." for entry id ".$tb->entry_id." since it no longer allows pings.");406 $data->{__reason} = "Entry no longer accepts TrackBack pings."; 361 407 return BLOCK; 362 408 } … … 364 410 my $cat = MT::Category->load($tb->category_id); 365 411 if ($cat && !$cat->allow_pings) { 366 $ eh->error("Blocking ".$data->{__type}." on blog id ".$obj->blog_id." for category id ".$tb->category_id." since it no longer allows pings.");412 $data->{__reason} = "Category no longer accepts TrackBack pings."; 367 413 return BLOCK; 368 414 } … … 396 442 $match ||= wordlist_match($decodedtext, $data->{wordlist_block}); 397 443 if ($match) { 398 $ eh->error("Blocking ".$data->{__type}." on blog ".$data->{__blogname}." based on wordlist match: ".$match);444 $data->{__reason} = "Wordlist match: $match"; 399 445 return BLOCK; 400 446 } … … 405 451 $match ||= wordlist_match($decodedtext, $data->{wordlist_moderate}); 406 452 if ($match) { 407 $ eh->error("Moderating ".$data->{__type}." on blog ".$data->{__blogname}." based on wordlist match: ".$match);453 $data->{__reason} = "Wordlist match: $match"; 408 454 return MODERATE; 409 455 } … … 448 494 449 495 if (!defined $inpass) { 450 $ eh->error("Blocking TrackBack ping for blog " . $obj->blog_id . " because passphrase was not supplied at all.");496 $data->{__reason} = "Passphrase was not supplied."; 451 497 return BLOCK; 452 498 } … … 460 506 return IGNORE if lc($text) eq lc($inpass); 461 507 462 $eh->error(($data->{tbpass_moderate} ? "Moderating" : "Blocking") . 463 " TrackBack ping for blog " . $obj->blog_id . " due to passphrase not matching."); 508 $data->{__reason} = sprintf("Passphrase did not match ('%s' and '%s')", lc($text), lc($inpass)); 464 509 return $data->{tbpass_moderate} ? MODERATE : BLOCK; 465 510 } … … 475 520 my $inpass = $app->{query}->param($formfield); 476 521 if (!defined $inpass) { 477 $ eh->error("Blocking comment for blog " . $obj->blog_id . " because passphrase was not supplied at all.");522 $data->{__reason} = "Passphrase was not supplied."; 478 523 return BLOCK; 479 524 } … … 487 532 return IGNORE if lc($text) eq lc($inpass); 488 533 489 $eh->error(($data->{commentpass_moderate} ? "Moderating" : "Blocking") . 490 " comment for blog " . $obj->blog_id . " due to passphrase not matching."); 534 $data->{__reason} = sprintf("Passphrase did not match ('%s' and '%s')", lc($text), lc($inpass)); 491 535 return $data->{commentpass_moderate} ? MODERATE : BLOCK; 492 536 } … … 499 543 my $domainip = checkdns($domain); 500 544 if (!$domainip) { 501 $eh->error("Blocking TrackBack ping for blog " . 502 $obj->blog_id." due to failure to resolve IP address " . 503 "for source URL ".$obj->source_url); 545 $data->{__reason} = "Failed to resolve IP address for source URL " . $obj->source_url; 504 546 return BLOCK; 505 547 } … … 525 567 526 568 my $action = ($result == MODERATE ? "Moderating" : "Blocking"); 527 $eh->error("$action TrackBack ping for blog " . $obj->blog_id . 528 " since domain IP does not match ping IP for source URL " . 529 $obj->source_url . "; domain IP: $domainip; ping IP: $pingip"); 569 $data->{__reason} = "Domain IP does not match ping IP for source URL " . 570 $obj->source_url . "; domain IP: $domainip; ping IP: $pingip"; 530 571 531 572 return $result; … … 611 652 } 612 653 # yep - this is a good proxy 613 $eh->error(($data->{proxycheck_moderate} ? "Moderating" : "Blocking") . 614 " $type on blog " . $obj->blog_id . 615 " based on dynamic proxy check of $ip:$port"); 654 $data->{__reason} = "Found proxy at $ip:$port"; 616 655 $data->{is_proxy} = 1; 617 656 return $data->{proxycheck_moderate} ? MODERATE : BLOCK; … … 650 689 # added by the system that sent the request 651 690 $data->{__proxy} = $obj->ip; 652 $eh->error(($data->{headers_moderate} ? "Moderating" : "Blocking") . 653 " $type on blog " . $obj->blog_id . 654 " based on X-Forwarded-For header $proxy"); 691 $data->{__reason} = "X-Forwarded-For header found: $proxy"; 655 692 return $data->{headers_moderate} ? MODERATE : BLOCK; 656 693 } … … 664 701 my $nurls = $data->{__nurls} || 0; 665 702 if ($nurls >= $data->{urlcount_block_limit}) { 666 $eh->error("Blocking $type on blog " . $obj->blog_id . 667 " because of too many ($nurls) links"); 703 $data->{__reason} = "Too many links: $nurls"; 668 704 return BLOCK; 669 705 } elsif ($nurls >= $data->{urlcount_moderate_limit}) { 670 706 # what should we do for trackbacks? 671 707 if($type eq 'comment') { 672 $eh->error("Moderating $type on blog " . $obj->blog_id . 673 " because of too many ($nurls) links"); 708 $data->{__reason} = "Too many links: $nurls"; 674 709 return MODERATE; 675 710 } … … 690 725 my $result = $cache->{$obj->ip}->{result}; 691 726 if ($result != ACCEPT) { 692 $eh->error(($result == MODERATE ? "Moderating" : "Blocking") . 693 " $type on blog " . $obj->blog_id . 694 " based on cached proxy information for IP " . $obj->ip . 695 "; hit count is " . $cache->{$obj->ip}->{hits}); 727 $data->{__reason} = "Cached proxy record found for IP " . $obj->ip . "; cache hitcount is " . $cache->{$obj->ip}->{hits}; 696 728 return $result; 697 729 } … … 715 747 if (checkdns("$url.$service.")) { 716 748 $data->{__service} = $service; 717 $eh->error(($data->{domainbl_moderate} ? "Moderating" : "Blocking") . 718 " $type on blog ". $obj->blog_id . 719 " based on domain $url matching on service $service"); 749 $data->{__reason} = "domain in $url found on service $service"; 720 750 return $data->{domainbl_moderate} ? MODERATE : BLOCK; 721 751 } … … 736 766 if (checkdns("$d.$c.$b.$a.$service.")) { 737 767 $data->{__service} = $service; 738 $eh->error(($data->{ipbl_moderate} ? "Moderating" : "Blocking") . 739 " $type on blog " . $obj->blog_id . 740 " based on IP $remote_ip matching on service $service"); 768 $data->{__reason} = "$remote_ip found on service $service"; 741 769 return $data->{ipbl_moderate} ? MODERATE : BLOCK; 742 770 }
