Following code extracts last five entries from the log file and displays it in the twiki topic.I am trying to write a script to display the list of currently logged users on twiki.Would seem like really a stupid script but I am new to twiki and this is my first script.I want some modifications some suggestions for my script.
--
Contributors: ManasiBopardikar - 24 Sep 2008
Discussion
#!/usr/bin/perl
use strict;
use lib "/pkgs/twiki/lib";
use lib "/pkgs/twiki/lib/CPAN/lib";
use TWiki::Func;
use CGI;
$TWiki::Plugins::SESSION = new TWiki('ManasiBopardikar');
my $session = $TWiki::Plugins::SESSION;
my $web="Sandbox";
#open(FP,"/pkgs/twiki/data/log200809.txt") || die("cant open the file");
#my @array;
#foreach(<FP>)
#{
#push(@array,$_);
#}
#my $log=pop(@array);
my $topic="MyLog";
l:open(FP,"/pkgs/twiki/data/log200809.txt") || die("cant open the file");
my @array;
foreach(<FP>)
{
push(@array,$_);
}
#foreach my $arr(@array)
#{
#print $arr;
#}
my $i;
my $log1;
my $log2;
my $log3;
my $log4;
my $log5;
for($i=0;$i<5;$i++)
{
$log1=pop(@array);
$log2=pop(@array);
$log3=pop(@array);
$log4=pop(@array);
$log5=pop(@array);
}
my $text="<html><meta http-equiv=\"refresh\" content=\"1\"><body>$log1\n$log2\n$log3\n$log4\n$log5</body></html>";
my $meta=new TWiki::Meta($session,$web,$topic);
my $error=TWiki::Func::saveTopic( $web, $topic, $meta,$text,{ comment => 'Hello' } );
print "twiki topic created";
system("chown apache:apache /pkgs/twiki/data/Sandbox/MyLog.txt");
sleep(1);
goto l;
I am trying to display the information of the users who are currently logged to twiki on the twiki topic page.Is there a better way to achieve this?
--
ManasiBopardikar - 25 Sep 2008
The script doesn't appear to do much except print the most recent 5 lines of the TWiki log. It's not clear what you are hoping people will suggest. Some tips regarding your perl:
- Don't use goto
- Don't assume the value of $/
- Use indentation
- Don't "use lib"
- Don't assume apache
- Don't assume what login manager is used
- Don't assume Linux
- Don't use 60 obscure lines to achieve something that can be done in 10 clear ones.
- Please don't bug community members on private IRC channels. Use #twiki.
--
CrawfordCurrie - 25 Sep 2008
This design has two not-so-little flaws:
- You aren't detecting a "logon" event. The last five log entries could all be from the same user. You could filter the log for that
- You aren't detecting a "logoff" either (or more likely navigation away from the site), so you can't tell if they are still logged in. That's a bit harder, you would need some javascript in each page to send that event back to the server.
TWiki session info might tell you the recent logons, but the session data probably times out rather than detecting log offs.
--
SeanCMorgan - 25 Sep 2008
Hi,
A few Perl and TWiki experts are available into your enterprise/company - i suggest you to talk to them before posting such stuff in the community or ask such questions at #twiki (irc)
--
SopanShewale - 26 Sep 2008