Tags:
create new tag
, view all tags
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:

  1. Don't use goto
  2. Don't assume the value of $/
  3. Use indentation
  4. Don't "use lib"
  5. Don't assume apache
  6. Don't assume what login manager is used
  7. Don't assume Linux
  8. Don't use 60 obscure lines to achieve something that can be done in 10 clear ones.
  9. Please don't bug community members on private IRC channels. Use #twiki.
-- CrawfordCurrie - 25 Sep 2008

This design has two not-so-little flaws:

  1. 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
  2. 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

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2008-09-26 - SopanShewale
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.