Changeset 14771


Ignore:
Timestamp:
05/08/12 00:19:38 (13 months ago)
Author:
KipLubliner
Message:

Item11822: Item9581: fix security hole

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/tools/develop/plague.pl

    r13286 r14771  
    22# Analyses the Waiting for Feedback tasks, Waiting For field, extracts 
    33# wikiname, maps to email address, sends mail. 
     4 
     5# usage: plague.pl [--topics "Item123,Item456"]  [--nomail] 
     6# with no arguments, searches thru Item* 
    47use strict; 
    58use warnings; 
     9 
     10my $itemTopics = "Item*"; 
     11my $sendMail   = 1; 
     12 
     13while (@ARGV) { 
     14    my $arg = shift @ARGV; 
     15    if ( $arg eq "--topics" ) { 
     16        $itemTopics = shift @ARGV; 
     17    } 
     18    elsif ( $arg eq '--nomail' ) { 
     19        $sendMail = undef; 
     20    } 
     21} 
     22print "Searching items $itemTopics\n"; 
    623 
    724BEGIN { 
     
    1835my $session = new Foswiki( $Foswiki::cfg{AdminUserLogin}, $request ); 
    1936 
    20 # Search for Waiting for Feedback, and load a struct with the results 
    21 my $details = '[' . Foswiki::Func::expandCommonVariables(<<'SEARCH') . ']'; 
    22 %SEARCH{ 
    23  "name~'Item*' AND CurrentState='Waiting for Feedback'" 
     37my $sep  = "JENNY8675309xyzzy"; 
     38my $data = Foswiki::Func::expandCommonVariables(<<"SEARCH"); 
     39\%SEARCH{ 
     40 "CurrentState='Waiting for Feedback'" 
    2441 type="query" 
     42 topic="$itemTopics" 
     43 web="Tasks" 
    2544 nonoise="on" 
    26  format="$percntFORMAT{\"$percntENCODE{\"$formfield(WaitingFor)\"  
    27 old=\"Main.,Foswiki:,TWiki:\" new=\",,\"}$percnt\" type=\"string\"  
    28 format=\"{topic=>'$topic',who=>'$dollaritem'}\" separator=\",\"}$percnt" 
    29  separator=","}% 
     45 format="topic='\$topic' WaitingFor='\$formfield(WaitingFor)' Summary='\$formfield(Summary)'" 
     46 separator="$sep"}\% 
    3047SEARCH 
    31 my $data = eval($details); 
    3248 
    33 # Process the struct, collating items according to the recipient email 
     49# collate search results into %send, keyed by mail address to be notified. 
    3450my %send; 
    35 foreach my $entry (@$data) { 
    36     next unless $entry->{who}; 
    37     my @emails = Foswiki::Func::wikinameToEmails( $entry->{who} ); 
     51for my $itemData ( split $sep, $data ) { 
     52    my ( $topic, $waitingFor, $summary ) = 
     53      $itemData =~ m/topic='(.*?)' WaitingFor='(.*?)' Summary='(.*)'/; 
     54    next unless $waitingFor; 
     55    $waitingFor =~ s/^\s+//; 
     56    $waitingFor =~ s/\s+$//; 
     57    my @emails; 
     58    foreach my $waitname ( split( /[,\s]/, $waitingFor ) ) { 
     59        $waitname =~ s/Foswiki://; 
     60        my @waitemails = Foswiki::Func::wikinameToEmails($waitname); 
     61        push @emails, @waitemails; 
     62    } 
    3863    unless ( scalar(@emails) ) { 
    39         print STDERR 
    40           "$0: $entry->{topic}: $entry->{who} has no email address\n"; 
     64        print STDERR "$0: $topic: $waitingFor has no email address\n"; 
    4165        next; 
    4266    } 
    4367    foreach my $email (@emails) { 
    44         push( @{ $send{$email} }, $entry->{topic} ); 
     68        push( @{ $send{$email} }, { topic => $topic, summary => $summary } ); 
    4569    } 
    4670} 
     
    5074my $template = <DATA>; 
    5175while ( my ( $email, $items ) = each %send ) { 
    52     my $list = join( "\n", map { 'http://foswiki.org/Tasks/' . $_ } @$items ); 
     76    my $list = join( "\n\n", 
     77        map { $_->{summary} . "\nhttp://foswiki.org/Tasks/" . $_->{topic} } 
     78          @$items ); 
    5379    my $mail = $template; 
    5480    $mail =~ s/%EMAILTO%/$email/g; 
    5581    $mail =~ s/%TASK_LIST%/$list/g; 
    5682    $mail = Foswiki::Func::expandCommonVariables($mail); 
    57     my $e = Foswiki::Func::sendEmail($mail); 
    58     print STDERR "$0: error sending mail: $e\n" if $e; 
     83    if ($sendMail) { 
     84        my $e = Foswiki::Func::sendEmail($mail); 
     85        print STDERR "$0: error sending mail: $e\n" if $e; 
     86    } 
     87    else { 
     88        print "$mail\n"; 
     89    } 
    5990} 
    60911; 
     
    6697Content-Type: text/plain 
    6798Content-Transfer-Encoding: 8bit 
     99 
    68100 
    69101This is an automated e-mail from Foswiki.org 
Note: See TracChangeset for help on using the changeset viewer.