Hello,

As part of the module I am writing for tomcat management, I wrote a module for accessing tomcat logs.

The problem I have is, when I open the page, the default selected fields should cause the logs to display in the textarea box but this is not so. I have to click on the "Display" button before the logs get displayed. The second problem is that, when I select new fields and click on displays, the logs displays alright but the fields changed back to the default fields which in normal sense shouldn't be so. 

Here is the code below:

 #!/usr/bin/perl

require 'tomcat-lib.pl';
#&ReadParse();
&ui_print_header(undef, $text{'logaccess_title'}, "", "tomcatlog");

#Get all instances
@insts = File::Slurp::read_file( $config{'tomcat_instance'} ) or die "Failed to read $config{'tomcat_instance'} - $!";


#Log type: access or catalina.out
@log_types = ( "catalina.out", "access_log" );

$in{'inst'} =~ s/\s+//;

$in{'inst'} ||= $insts[0];
&indexof($in{'inst'}, @insts) >= 0 || &error( $text{'no_log'} );

$in{'log_type'} ||= $log_types[0];
&indexof($in{'log_type'}, @log_types) >= 0 || &error( $text{'clog'} );


print &ui_form_start("tomcatlogs.cgi");
print "<b>$text{'inst_select'}</b>\n";
print &ui_select("inst", $in{'inst'},
[ map { [ $_ ] } @insts ]),"\n";

print "<b>$text{'log_type'}</b>\n";
print &ui_select("log_type", $in{'log_type'},
                [ map { [ $_ ] } @log_types ]),"\n";


$d =`date '+\%d'`;
$m = `date '+\%m'`;
$y = `date '+\%Y'`;


print "Day:" . &ui_textbox("ld", $d, "2") . "Month:" . &ui_textbox("lm", $m, "2") . 
                "Year:".  &ui_textbox("ly", $y,"4") . &date_chooser_button("ld", "lm", "ly" ), "\n";
                                                   

print &ui_submit($text{'log_display'});

print &ui_form_end();



$q = CGI->new;
$instance = $q->param('inst');
$log_type = $q->param('log_type');
$lday = sprintf("%02d", $q->param('ld')); #Force 2 digit number
$lmonth = sprintf("%02d", $q->param('lm')); 
$lyear = sprintf("%04d", $q->param('ly')); #Force 4 digit number


$current = `date '+\%Y\%m\%d' `;
$cdate = $lyear . $lmonth . $lday;
$aldate = $lyear . "-" . $lmonth . "-". $lday;

$instance =~ s/\s+//;


if ( $instance eq "tomcat5" ){
if ( $log_type eq "catalina.out") { 
if ( $cdate == $current ) {
$tomcat_log = "/var/log/tomcat5/catalina.out";
}
else {
$tomcat_log = "/var/log/tomcat5/catalina.out-$cdate.gz";
}
}
elsif ( $log_type eq "access_log" ) {
if ( $cdate == $current ) {
$tomcat_log = "/var/log/tomcat5/access-logs/tomcat_access.log-$aldate";
}
else {
$tomcat_log = "/var/log/tomcat5/access-logs/tomcat_access.log-$aldate.gz";
}
}
}
else {
if ( $log_type eq "catalina.out" ) {
if ( $cdate == $current ) {
$tomcat_log = "/var/lib/$instance/logs/catalina.out";
}
else {
$tomcat_log = "/var/lib/$instance/logs/catalina.out-$cdate.gz";
}
}
elsif ($log_type eq "access_log" ) {  
if ( $cdate == $current) {
          $tomcat_log = "/var/lib/$instance/access-logs/tomcat_access.log-$aldate";
}
else {
$tomcat_log = "/var/lib/$instance/access-logs/tomcat_access.log
$aldate.gz";
}
}
}
print "<br>";
print "Log: $tomcat_log \n";
print "<br>";

#print &ui_form_start( "index.cgi", "form-data");
#print &ui_hidden("log", $tomcat_log),"<br>";
if ( -e $tomcat_log ) {
    if ( $cdate == $current ) {
        $data = &read_file_contents("$tomcat_log");
    }
    else {
        $data = `zcat $tomcat_log`;       

    }
}
#else {
 #   print "$tomcat_log does not exist on the server, kindly check your chosen date <br>";
#}

print &ui_form_start( "index.cgi", "form-data");
print &ui_hidden("log", $tomcat_log),"<br>";
print &ui_textarea("data", $data, 20, 80),"\n";
print "<br>";
print &ui_submit($text{'exit'});
print &ui_form_end();


&ui_print_footer("/", $text{'index'});