[Rt-commit] rtir branch, 4.0/parse-attachments-for-ip, created. 4.0.1rc1-87-gd86bcde9
Craig Kaiser
craig at bestpractical.com
Mon Nov 19 17:29:25 EST 2018
The branch, 4.0/parse-attachments-for-ip has been created
at d86bcde9002230bb02589c935f597174d57e3fee (commit)
- Log -----------------------------------------------------------------
commit d86bcde9002230bb02589c935f597174d57e3fee
Author: Craig Kaiser <craig at bestpractical.com>
Date: Mon Nov 19 17:11:42 2018 -0500
Use attachments instead of transactions for IP parse
Cannot grab the attached files IPs and the content of the email's
IPs unless you check attachments in place of the transations content.
If both an attachment and email content are present with IP values then
only the email content's IP addresses will be parsed.
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 6d2be824..554c4b79 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -99,8 +99,8 @@ sub Commit {
my $how_many_can = $cf->MaxValues;
- my $attach = $self->TransactionObj->ContentObj;
- return 1 unless $attach && $attach->id;
+ my $attachments = $ticket->Attachments;
+ return 1 unless $attachments && $attachments->Count;
my %existing;
for( @{$cf->ValuesForObject( $ticket )->ItemsArrayRef} ) {
@@ -114,33 +114,35 @@ sub Commit {
my $spots_left = $how_many_can - keys %existing;
- my $content = $attach->Content || '';
- while ( $content =~ m/$IP_re/go ) {
- if ( $1 && defined $2 ) { # IPv6/mask
- my $range = $2 == 128 ? $1 : (Net::CIDR::cidr2range( "$1/$2" ))[0]
- or next;
- $spots_left -= $self->AddIP(
- IP => $range, CustomField => $cf, Skip => \%existing
- );
+ while ( my $attach = $attachments->Next ) {
+ my $content = $attach->Content || '';
+ while ( $content =~ m/$IP_re/go ) {
+ if ( $1 && defined $2 ) { # IPv6/mask
+ my $range = $2 == 128 ? $1 : (Net::CIDR::cidr2range( "$1/$2" ))[0]
+ or next;
+ $spots_left -= $self->AddIP(
+ IP => $range, CustomField => $cf, Skip => \%existing
+ );
+ }
+ elsif ( $1 ) { # IPv6
+ $spots_left -= $self->AddIP(
+ IP => $1, CustomField => $cf, Skip => \%existing
+ );
+ }
+ elsif ( $3 ) { # IPv4
+ $spots_left -= $self->AddIP(
+ IP => $3, CustomField => $cf, Skip => \%existing
+ );
+ }
+ elsif ( $4 && defined $5 ) { # IPv4/mask
+ my $cidr = join( '.', map { $_||0 } (split /\./, $4)[0..3] ) ."/$5";
+ my $range = (Net::CIDR::cidr2range( $cidr ))[0] or next;
+ $spots_left -= $self->AddIP(
+ IP => $range, CustomField => $cf, Skip => \%existing
+ );
+ }
+ return 1 unless $spots_left;
}
- elsif ( $1 ) { # IPv6
- $spots_left -= $self->AddIP(
- IP => $1, CustomField => $cf, Skip => \%existing
- );
- }
- elsif ( $3 ) { # IPv4
- $spots_left -= $self->AddIP(
- IP => $3, CustomField => $cf, Skip => \%existing
- );
- }
- elsif ( $4 && defined $5 ) { # IPv4/mask
- my $cidr = join( '.', map { $_||0 } (split /\./, $4)[0..3] ) ."/$5";
- my $range = (Net::CIDR::cidr2range( $cidr ))[0] or next;
- $spots_left -= $self->AddIP(
- IP => $range, CustomField => $cf, Skip => \%existing
- );
- }
- return 1 unless $spots_left;
}
return 1;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list