#!/usr/bin/perl -w # ***************************************************************************** # # my edited topics in all webs # # ****************************************************************************** # # Foswiki WikiClone (see Foswiki.pm for $wikiversion and other info) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program 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, published at # http://www.gnu.org/copyleft/gpl.html # BEGIN { # Set default current working directory (needed for mod_perl) if ( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~ /^(.+)\/[^\/]+$/ ) { chdir $1; } # Set library paths in @INC, at compile time unshift @INC, '.'; require 'setlib.cfg'; } use CGI::Carp qw(fatalsToBrowser); use CGI; use File::Copy; use File::Path; use lib ('.'); use Foswiki; $Foswiki::Plugins::SESSION = new Foswiki(); #use strict; use vars qw($user ); &main(); # ****************************************************************************** # # Main rendering loop. # sub main { %monnmon = ( 'Jan', '01', 'Feb', '02', 'Mar', '03', 'Apr', '04', 'May', '05', 'Jun', '06', 'Jul', '07', 'Aug', '08', 'Sep', '09', 'Oct', '10', 'Nov', '11', 'Dec', '12' ); # Read command-line arguments and make # Now do normal CGI init. $query = new CGI; my $thePathInfo = $query->path_info(); # HTTP_COOKIE = FOSWIKISID=2d10f0bb5553bfed507de253f46c98ec; WTC_AUTHENTICATED=fischer my $theRemoteUser = ""; my $rcvd_cookies = $ENV{'HTTP_COOKIE'}; my @cookies = split /;/, $rcvd_cookies; foreach my $cookie (@cookies) { if ( $cookie =~ s/.*WTC_AUTHENTICATED=// ) { $theRemoteUser = $cookie; } } my $quser = ""; my $theTopic = $query->param('topic'); my $theUrl = $query->url; my $host = $Foswiki::cfg{DefaultUrlHost}; my $main = $Foswiki::cfg{UsersWebName}; $debug = $query->param('debug'); $quser = $query->param('user'); $theRemoteUser = $quser if $quser ne ""; $| = 0 if ($debug); my ( $topic, $web, $scriptUrlPath, $userName, $dataDir ) = &Foswiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl, $query ); # Print environment variables for debugging. if ($debug) { print "\n$topic, $web, $scriptUrlPath, $userName, $dataDir, $theRemoteUser, $host\n"; print "Content-type: text/plain\n\n"; foreach my $key ( sort keys %ENV ) { print "$key => $ENV{$key}\n"; } } my $user = ( $quser eq "" ) ? &Foswiki::Func::getWikiName() : &Foswiki::Func::getWikiName($quser); my $wikiUserName = &Foswiki::Func::wikiToUserName($user); my $date = &Foswiki::Func::formatTime( time() ); my $datadir = &Foswiki::Func::getDataDir(); if ($debug) { print "Publisher: $user,$userName,$wikiUserName,$theRemoteUser\n" if $debug; print "Date: $date\n" if $debug; print "DataDir: $datadir/log2*\n" if $debug; } if ( &Foswiki::Func::isGuest() ) { print "\n\nYou must be logged in!\n"; exit(1); } my %savedTopics; @logfiles = <$datadir/log*>; my ( $text, $textP1, $textP2, $textP3, $textP4, @rest, $dump, $wl, $tl, $dl ); # topicExists( $web, $topic ) if ( &Foswiki::Func::topicExists( "$main", "${user}LastEdited" ) ) { $text = &Foswiki::Func::readTopicText( "$main", "${user}LastEdited" ); ( $textP1, $textP2, $textP3, $textP4, @rest ) = split( /\n/, $text ); ( $dump, $tl, $dl ) = split( /\|/, $rest[0] ); $dl = del_blank($dl); print "DATE0:#$rest[0]#$dl#\n" if $debug; # print "\n@logfiles" if $debug; while (@logfiles) { my $log = shift(@logfiles); my $tlog = $log; #print "\n$tlog" if $debug; $tlog =~ s|/mnt/wiki/Foswiki/data/log||; $tlog =~ s|\.txt||; my $y1 = substr( $tlog, 0, 4 ); my $m1 = substr( $tlog, 4, 5 ); my $y2 = substr( $dl, 0, 4 ); my $m2 = substr( $dl, 5, 2 ); print "DATE:|$y1|$m1|$y2|$m2|\n" if $debug; if ( $y1 lt $y2 ) { redo; } if ( ( $y1 eq $y2 ) && ( $m1 lt $m2 ) ) { redo; } unshift( @logfiles, "$log" ); last; } print "\nTLF:@logfiles" if $debug; } $text = " * Set ALLOWTOPICCHANGE = $main.$user\n---+ Von $user bearbeitete Topics ([[$host/bin/MyEditedTopics][update]])\n| *Web.Topic* | *Date* |\n"; my $LL1 = 0; print "REST:@rest\n" if debug; while (@rest) { my $l = shift(@rest); $LL1++; my ( $wl, $tl, $dl ) = split( /\|/, $l ); print "REST0: $tl,$dl,\n" if debug; $dl = del_blank($dl); $tl = del_blank($tl); $tl =~ s/\[\[//; $tl =~ s/\]\].*$//; print "REST1: $tl,$dl,\n" if debug; $savedTopics{"$tl"} = "$dl"; print "REST: $tl,$dl, $savedTopics{\"$tl\"}\n" if debug; } my $new = 0; while (@logfiles) { my $log = shift(@logfiles); print "\n$log" if $debug; open LOG, "<$log"; while ( $line = ) { my ( $dump, $dat, $luser, $action, $webtopic, $browser, $ip ) = split( /\|/, $line ); if ( ( ( $luser =~ /$user/ ) || ( $luser =~ $wikiUserName ) ) && $action =~ /save/ ) { $dat =~ s/Z info.*$//; $dat =~ s/^[ ]*//; if ( $dat =~ /^[0-9]* [A-Za-z]*/ ) { my ( $day, $mon, $year, $dump, $time ) = split( / /, $dat ); $dat = "$year-$monnmon{\"$mon\"}-${day}T$time"; } if ( $dat le $dl ) { next; } $webtopic = del_blank($webtopic); my $web = $webtopic; $web =~ s/\..*$//; my $topic = $webtopic; $topic =~ s/^.*\.$//; if ( !( $webtopic =~ /^Trash\./ ) && !( $webtopic =~ /\.WebStatistics$/ ) && !( $webtopic =~ /\.BmsG$/ ) && !( $webtopic =~ /\.Config.*00$/ ) && !( $webtopic =~ /\.WebHomeWarn$/ ) && !( $webtopic =~ /\.WwW.*Template$/ ) && !( $webtopic =~ /\.PublishPluginHistory$/ ) && !( $webtopic =~ /\.GuentherFischerLastEdited$/ ) && &Foswiki::Func::topicExists( $web, $topic ) ) { $savedTopics{"$webtopic"} = "$dat"; $new++; } } } } print "\nNEW:$new\n" if $debug; if ( $new > 0 ) { foreach $key ( sort { $savedTopics{$b} cmp $savedTopics{$a} } keys %savedTopics ) { my $topic = $key; $topic =~ s/\//./g; $text .= "| [[$topic]] | $savedTopics{$key} |\n"; print "Text:$savedTopics{$key} $topic\n" if $debug; } &Foswiki::Func::saveTopicText( "$main", "${user}LastEdited", $text ); } $topic = "${user}LastEdited"; Foswiki::Func::redirectCgiQuery( undef, Foswiki::Func::getScriptUrl( $main, $topic, 'view' ), 1 ); exit(0); } sub del_blank { my ($var) = @_; return "" if !$var; $var =~ s/^ *//; $var =~ s/ *$//; return $var; }