Skip to content

Instantly share code, notes, and snippets.

@greylurk
Created May 29, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greylurk/f6c4c0c65f3d229ba526 to your computer and use it in GitHub Desktop.
Save greylurk/f6c4c0c65f3d229ba526 to your computer and use it in GitHub Desktop.
Key verification failure! at /var/local/cur8/lib/perl5/Cur8/SpamFilter.pm line 15.
Compilation failed in require at /var/local/cur8/lib/perl5/Cur8/MasonPackages.pm line 125.
BEGIN failed--compilation aborted at /var/local/cur8/lib/perl5/Cur8/MasonPackages.pm line 125.
Compilation failed in require at /var/local/cur8/lib/perl5/Cur8/Mason.pm line 18.
BEGIN failed--compilation aborted at /var/local/cur8/lib/perl5/Cur8/Mason.pm line 18.
Compilation failed in require at (eval 3) line 3.
package Cur8::SpamFilter;
use strict;
use warnings;
#
# Copyright 2005-2008 ThisNext. All rights reserved.
#
use Cur8::DescribedItem;
use Cur8::Note;
use Cur8::NipsaService;
use Net::Akismet;
use Socket;
use MIME::Lite;
my $akismet = Net::Akismet->new(
KEY=>Cur8::Config::akismet_key,
URL=>'http://www.thisnext.com',
) or die('Key verification failure!');
=head1 METHODS
=head2 _resolve_remote_ip
Resolve the hostname or ip to an IP to be sent to the spam filter
Just use the socket atoi stuff.
=cut
sub _resolve_remote_ip {
my $self = shift @_;
my $host = shift @_;
if( $host =~ m/^\s*$/ ) {
return "";
}
my $address = inet_ntoa(inet_aton($host));
return $address;
}
sub _attempt_delete_item_to_vendor {
my $self = shift @_;
my $item = shift @_;
my $user = shift @_;
my $item_visibility = $item->visibility;
my ($picks, $count) = $item->described_items(
start => 0,
count => 10000,
);
my $item_to_vendor = $item->item_to_vendor_for_user($user);
my $url = $item_to_vendor->from_url();
my $is_single_pick = ($count > 1) ? 0 : 1;
my $item_name = ($is_single_pick) ? $item->canonical_name : '';
if (!$is_single_pick && $item_to_vendor && !$item_to_vendor->delete_time) {
$item_to_vendor->delete_time(Cur8::DateTime::database_timestamp('now'));
$item_to_vendor->update;
Cur8::Note->create({
entity_type => Cur8::TypeDomain->entity_type_name2value('item'),
entity_id => $item->item_id,
type => 'update',
user_id => 1,
description => "Cur8::SpamFilter - deleted URL: $url",
comment => "Flagged as spam by the SpamFilter",
});
return 1;
}
return 0;
}
sub _generate_action_text{
my $self = shift @_;
my $actions = shift @_;
my $email_body = qq(PERFORMED ACTIONS:\n);
if (exists $actions->{user_nipsa}) {
my $user = $actions->{user_nipsa};
$email_body .= " NIPSAed USER: ". Cur8::Config::open_prefix() . $user->url . "\n";
}
if (exists $actions->{item_to_vendor_deleted}) {
my $itv = $actions->{item_to_vendor_deleted};
$email_body .= " DELETED VENDOR URL: " . $itv->from_url . "\n";
}
}
=head2 _check_spam
=cut
sub _check_described_item_spam {
my $self = shift @_;
my $remote_ip = shift @_;
my $user_agent = shift @_;
my $content = shift @_;
my $author = shift @_;
my $author_email = shift @_;
return $akismet->check(
'USER_IP' => $remote_ip,
'COMMENT_USER_AGENT' => $user_agent,
'COMMENT_CONTENT' => $content,
'COMMENT_AUTHOR' => $author,
'COMMENT_AUTHOR_EMAIL' => $author_email
);
}
sub report_ham {
my $self = shift @_;
my %args = @_;
my $pick = $args{'pick'};
my $user = $pick->user;
my $item = $pick->item;
my $hostname = $pick->browser;
my $user_agent = $pick->user_agent;
my $author = $user->display_name();
my $author_email = $user->email_address();
$hostname =~ s/\.\d+$//;
if( defined $hostname && defined $user_agent && !($hostname eq "") && !($user_agent eq "") ) {
$akismet->ham(
'USER_IP' => $hostname,
'COMMENT_USER_AGENT' => $user_agent,
'COMMENT_CONTENT' => $pick->description || '',
'COMMENT_AUTHOR' => $author,
'COMMENT_AUTHOR_EMAIL' => $author_email
);
}
}
sub report_spam {
my $self = shift @_;
my %args = @_;
my $pick = $args{'pick'};
my $user = $pick->user;
my $item = $pick->item;
my $hostname = $pick->browser;
my $user_agent = $pick->user_agent;
my $author = $user->display_name();
my $author_email = $user->email_address();
$hostname =~ s/\.\d+$//;
if( defined $hostname && defined $user_agent && !($hostname eq "") && !($user_agent eq "") ) {
$akismet->spam(
'USER_IP' => $hostname,
'COMMENT_USER_AGENT' => $user_agent,
'COMMENT_CONTENT' => $pick->description || '',
'COMMENT_AUTHOR' => $author,
'COMMENT_AUTHOR_EMAIL' => $author_email
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment