%# BEGIN LICENSE BLOCK %# %# Copyright (c) 1996-2002 Jesse Vincent %# %# (Except where explictly superceded by other copyright notices) %# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have %# been provided with this software, but in any event can be snarfed %# from www.gnu.org %# %# This work 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. %# %# %# Unless otherwise specified, all modifications, corrections or %# extensions to this work which alter its source code become the %# property of Best Practical Solutions, LLC when submitted for %# inclusion in the work. %# %# %# END LICENSE BLOCK <& /RTIR/Elements/Header, Title => $Title &> <& /RTIR/Tools/Elements/Tabs, current_tab => $current_tab, current_subtab => $current_subtab, Title => $Title &> <& /Elements/ListActions, actions => \@finalresults &>
> Id%>> % if (exists $ARGS{'TestAddresses'}) { <& /Elements/TitleBoxStart, contentbg => "#cccccc", title => 'Address test results' &>
    % foreach my $key (keys %$addrhash) {
  • <%$addrhash->{$key}->{'IP'}%>: <%$addrhash->{$key}->{'Address'}%> % }
<& /Elements/TitleBoxEnd &>
% } <& /Elements/TitleBoxStart, contentbg => "#cccccc", title => loc("Identify Recipients") &> % if ($loop eq 'IP') { % } else { % }
WHOIS:
<&|/l&>Contact Field:
<&|/l&>IP Addresses:
arg: _IP_
% if (exists $ARGS{IPs}) { <& /Elements/MessageBox, Name=>"IPs", Width => 30, Default=>$ARGS{IPs}, %ARGS&> % } else { <& /Elements/MessageBox, Name=> 'IPs', Width => 30 &> % }
<&|/l&>Addresses:
arg: _ADDR_
% if (exists $ARGS{Addresses}) { <& /Elements/MessageBox, Name=>"Addresses", Width => 30, Default=>$ARGS{Addresses}, %ARGS&> % } else { <& /Elements/MessageBox, Name=> 'Addresses', Width => 30 &> % }
<&|/l&>Template: <& /Admin/Elements/SelectTemplate, Name => "Template", Default => $ARGS{'Template'}, Queue => $investigationq->Id &>
<&|/l&>Argument:
% if ($loop eq "IP") { <& /Elements/Submit, Name => "TestAddresses", Caption => loc("Test email addresses"), Label => loc("Test")&> % } <& /Elements/TitleBoxEnd &>
<& /Elements/TitleBoxStart, contentbg => "#cccccc", title => loc("Message information") &> % if (!$incidentid) { <& /RTIR/Incident/Elements/Create, Title => $Title, QueueObj => $incidentq, %ARGS &> % } else { % }
<&|/l&>Owner: <%$session{'CurrentUser'}->Name%>
<&|/l&>Subject:
<&|/l&>Message: % if (exists $ARGS{Content}) { <& /Elements/MessageBox, Name=>"Content", Default=>$ARGS{Content}, %ARGS&> % } else { <& /Elements/MessageBox, Name=>"Content", %ARGS &> % }
<& /Elements/TitleBoxEnd &> <& /Elements/Submit, Name => "SubmitAction", Caption => loc("Create the Incidents and Investigations"), Label => loc("Create")&> <%INIT> my ($Incident, $Ticket); my (@IncidentActions, @ChildActions); my (@watchresults, @updateresults, @finalresults); $Title = loc("Scripted Action: Create Investigations for Incident #[_1]", $incidentid); my $template = new RT::Template($session{'CurrentUser'}); $template->LoadGlobalTemplate($TemplateName); $ARGS{'Template'} = $template->Id; foreach my $arg (keys %ARGS) { if ($arg =~ /^Requestorbox-(.+)/) { $ARGS{'Addresses'} .= $1 . "\r"; } } if ($incidentid) { $Incident = new RT::Ticket($session{'CurrentUser'}); $Incident->Load($incidentid); if (!exists $ARGS{Content}) { my $Transactions = $Incident->Transactions; if ($Transactions) { $ARGS{Content} = $m->scomp("/RTIR/Elements/TransactionData", Transactions => $Transactions, Type => 'messages', Include => {'Create', 'Correspond'}, QuoteText => 1); $ARGS{Content} =~ s/\>/>/g; } } } $ARGS{'loop'} = $loop if !defined $ARGS{'loop'}; if ($loop eq 'address') { $current_subtab = "RTIR/Tools/ScriptedAction.html", } else { $current_subtab = 'RTIR/Tools/ScriptedAction.html?loop=IP'; } # get the list of WHOIS servers foreach my $s (sort keys %$servers) { # just pick the first one $server = $servers->{$s} unless ($server); last; } # Load the Incidents Queue my $incidentq = new RT::Queue($session{'CurrentUser'}); unless ($incidentq->Load('Incidents')) { Abort('Queue not found'); } # Load the Investigations Queue my $investigationq = new RT::Queue($session{'CurrentUser'}); unless ($investigationq->Load('Investigations')) { Abort('Queue not found'); } # Load the Incident Reports Queue my $reportq = new RT::Queue($session{'CurrentUser'}); unless ($reportq->Load('Incident Reports')) { Abort('Queue not found'); } my $addrhash = {}; if ( exists $ARGS{SubmitAction} || exists $ARGS{'TestAddresses'} ) { if ($loop eq 'address') { my ($addresses, @addrs); $addresses = $ARGS{'Addresses'}; # replace \r\n with \n $addresses =~ s/\r\n/\n/g; # trim blanks from ends $addresses =~ s/^\s+//; $addresses =~ s/\s+$//; # replace newlines with commas (for use with parse_csv) $addresses =~ s/\n/,/g; @addrs = parse_csv($addresses); my $i = 0; foreach my $addr (@addrs) { $addrhash->{$i} = {Address => $addr, IP => loc("IP_UNKNOWN")}; $i++; } } elsif ($loop eq 'IP') { my ($ipnums, @ips); $ipnums = $ARGS{'IPs'}; # replace \r\n with \n $ipnums =~ s/\r\n/\n/g; # trim blanks from ends $ipnums =~ s/^\s+//; $ipnums =~ s/\s+$//; # replace newlines with commas (for use with parse_csv) $ipnums =~ s/\n/,/g; @ips = parse_csv($ipnums); my $i = 0; foreach my $ip (@ips) { my ($a, $err); $m->comp('Elements/GetEmailFromIP', server => $ARGS{'server'}, q => $ip, field => $ARGS{'field'}, address => \$a, error => \$err); if ($err) { # no addresses push(@finalresults, loc("Could not connect to whois server [_1] while getting address for [_2]", $server, $ip)); next; } $addrhash->{$i} = {Address => $a, IP => $ip}; $i++; } } } if ( exists $ARGS{SubmitAction} ) { if (!$Incident && (!$ARGS{'Function'} || !$ARGS{$ARGS{'Function'}})) { push @finalresults, "Incident creation failed: Function must be set."; } else { foreach my $key (keys %$addrhash) { my $addr = $addrhash->{$key}->{'Address'}; my $ip = $addrhash->{$key}->{'IP'}; if ((!exists $ARGS{'AddMoreAttach'}) && ($ARGS{'id'} eq 'new')) { # new ticket? # {{{ Create a new ticket # {{{ deal with deleting uploaded attachments foreach my $key (keys %ARGS) { if ($key =~ m/^DeleteAttach-(.+)$/) { delete $session{'Attachments'}{$1}; } $session{'Attachments'} = { %{$session{'Attachments'} || {}} }; } # {{{ store the uploaded attachment in session if ($ARGS{'Attach'}) { # attachment? $session{'Attachments'} = {} unless defined $session{'Attachments'}; # strip leading directories $ARGS{'Attach'} =~ s#^.*[\\/]##; my $attachment = MakeMIMEEntity( Subject => "$ARGS{'Attach'}", Body => "", AttachmentFieldName => 'Attach' ); $session{'Attachments'} = { %{$session{'Attachments'} || {}}, $ARGS{'Attach'} => $attachment }; } # }}} # delete temporary storage entry to make WebUI clean unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') { delete $session{'Attachments'}; } # }}} # if the subject contains _ADDR_ or _IP_ # substitute appropriately my $orig_subject = $ARGS{'Subject'}; $ARGS{'Subject'} =~ s/_ADDR_/$addr/g; $ARGS{'Subject'} =~ s/_IP_/$ip/g; if ($addr ne loc("ADDRESS_UNKNOWN")) { # create the Incident unless ($incidentq->CurrentUserHasRight('CreateTicket')) { Abort('You have no permission to create tickets in that queue.'); } $ARGS{'Queue'} = $incidentq->Id; if (!$Incident) { ($Incident, @IncidentActions) = CreateTicket(Attachments => $session{'Attachments'}, %ARGS); unless ($Incident->CurrentUserHasRight('ShowTicket')) { Abort("No permission to view newly created ticket #".$Incident->id."."); } } # }}} # create the linked investigation unless ($investigationq->CurrentUserHasRight('CreateTicket')) { Abort('You have no permission to create tickets in that queue.'); } $ARGS{'new-MemberOf'} = $Incident->Id; $ARGS{'Queue'} = $investigationq->Id; # Create the investigation without attachments, and send them later ($Ticket, @ChildActions) = CreateTicket(%ARGS); unless ($Ticket->CurrentUserHasRight('ShowTicket')) { Abort("No permission to view newly created ticket #".$Ticket->id."."); } $ARGS{'new-MemberOf'} = undef; $ARGS{'Queue'} = undef; # add the address as a Requestor and update the watchers $ARGS{"WatcherAddressEmail1"} = $addr; push @watchresults, ProcessTicketWatchers(TicketObj => $Ticket, ARGSRef => \%ARGS); $ARGS{"WatcherAddressEmail1"} = undef; # find the Create transaction, so we can pass it to the template my $transaction; while ($transaction = $Ticket->Transactions->Next) { last if ($transaction->Type eq 'Create'); } # if the template's argument contains _ADDR_ or _IP_ # substitute appropriately my $arg = $ARGS{'TemplateArg'}; $arg =~ s/_ADDR_/$addr/g; $arg =~ s/_IP_/$ip/g; # load the selected template my $TemplateObj = new RT::Template($session{'CurrentUser'}); $TemplateObj->Load($ARGS{'Template'}); my ( $result, $message ) = $TemplateObj->Parse( Argument => $arg, TicketObj => $Ticket, TransactionObj => $transaction, ); # add the template's MIMEObj to the Attachments list $session{'Attachments'} = { _Body => $TemplateObj->MIMEObj, %{$session{'Attachments'} || {}} }; # the content will be part of the template, if desired $ARGS{'UpdateContent'} = " "; $ARGS{UpdateAttachments} = $session{'Attachments'}; ProcessUpdateMessage(ARGSRef=>\%ARGS, Actions=>\@updateresults, TicketObj=>$Ticket); # restore original subject $ARGS{'Subject'} = $orig_subject; } else { # create an unlinked incident report unless ($reportq->CurrentUserHasRight('CreateTicket')) { Abort('You have no permission to create tickets in that queue.'); } $ARGS{'Queue'} = $reportq->Id; # Create the investigation without attachments, and send them later ($Ticket, @ChildActions) = CreateTicket(%ARGS); unless ($Ticket->CurrentUserHasRight('ShowTicket')) { Abort("No permission to view newly created ticket #".$Ticket->id."."); } $ARGS{'Queue'} = undef; } # say what ticket these refer to my @tempresults = (@watchresults, @updateresults); @tempresults = map { loc("Ticket [_1]: [_2]",$Ticket->Id,$_) } @tempresults; # put all the results together push (@finalresults, @IncidentActions, @ChildActions,, @tempresults); # delete attachments only after they've been sent to everyone delete $session{'Attachments'}; } } } } sub parse_csv { my $text = shift; # record containing comma-separated values my @new = (); push(@new, $+) while $text =~ m{ # the first part groups the phrase inside the quotes. # see explanation of this pattern in MRE "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx; push(@new, undef) if substr($text, -1,1) eq ','; return @new; # list of values that were comma-separated } <%ARGS> $incidentid => undef $TemplateName => 'Correspondence' $Requestors => undef $servers => $RT::whois $server => undef $Title => loc("Scripted Action: Create Incidents and Investigations") $current_tab => "RTIR/Tools/ScriptedAction.html"; $current_subtab => undef $loop => 'address'