[webmin-devel] Log access

Emma wasanzy <[email protected]> Tue, 26 Mar 2013 20:11:07 +0000
Newsgroups gmane.comp.web.webmin.devel,gmane.comp.web.webmin.general
Message-ID <CALgYh1FakvYUH_uwH3+9r5KqFy7u03cDZHLTm2RHKS76GF7Eww@mail.gmail.com>
--===============5725128296109651539==
Content-Type: multipart/alternative; boundary=e89a8f921936ca484804d8d986a5

--e89a8f921936ca484804d8d986a5
Content-Type: text/plain; charset=ISO-8859-1

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'});

--e89a8f921936ca484804d8d986a5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<div><br></div><div style>As part of the module I am=
 writing for tomcat management, I wrote a module for accessing tomcat logs.=
</div><div style><br></div><div style>The problem I have is, when I open th=
e 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 &quot;Display&quot=
; 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&#39=
;t be so.=A0</div>

<div style><br></div><div style>Here is the code below:</div><div style><br=
></div><div style>=A0#!/usr/bin/perl</div><div><br></div><div>require &#39;=
<a href=3D"http://tomcat-lib.pl">tomcat-lib.pl</a>&#39;;</div><div>#&amp;Re=
adParse();</div>

<div>&amp;ui_print_header(undef, $text{&#39;logaccess_title&#39;}, &quot;&q=
uot;, &quot;tomcatlog&quot;);</div><div><br></div><div>#Get all instances</=
div><div>@insts =3D File::Slurp::read_file( $config{&#39;tomcat_instance&#3=
9;} ) or die &quot;Failed to read $config{&#39;tomcat_instance&#39;} - $!&q=
uot;;</div>

<div><br></div><div><br></div><div>#Log type: access or catalina.out</div><=
div>@log_types =3D ( &quot;catalina.out&quot;, &quot;access_log&quot; );</d=
iv><div><br></div><div>$in{&#39;inst&#39;} =3D~ s/\s+//;</div><div><br></di=
v>

<div>$in{&#39;inst&#39;} ||=3D $insts[0];</div><div>&amp;indexof($in{&#39;i=
nst&#39;}, @insts) &gt;=3D 0 || &amp;error( $text{&#39;no_log&#39;} );</div=
><div><br></div><div>$in{&#39;log_type&#39;} ||=3D $log_types[0];</div><div=
>
&amp;indexof($in{&#39;log_type&#39;}, @log_types) &gt;=3D 0 || &amp;error( =
$text{&#39;clog&#39;} );</div>
<div><br></div><div><br></div><div>print &amp;ui_form_start(&quot;tomcatlog=
s.cgi&quot;);</div><div>print &quot;&lt;b&gt;$text{&#39;inst_select&#39;}&l=
t;/b&gt;\n&quot;;</div><div>print &amp;ui_select(&quot;inst&quot;, $in{&#39=
;inst&#39;},</div>

<div><span class=3D"" style=3D"white-space:pre">		</span>[ map { [ $_ ] } @=
insts ]),&quot;\n&quot;;</div><div><br></div><div>print &quot;&lt;b&gt;$tex=
t{&#39;log_type&#39;}&lt;/b&gt;\n&quot;;</div><div>print &amp;ui_select(&qu=
ot;log_type&quot;, $in{&#39;log_type&#39;},</div>

<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 [ map { [ $_ ] } @log_types ]),&quot;\=
n&quot;;</div><div><br></div><div><br></div><div>$d =3D`date &#39;+\%d&#39;=
`;</div><div>$m =3D `date &#39;+\%m&#39;`;</div><div>$y =3D `date &#39;+\%Y=
&#39;`;</div><div>

<br></div><div><br></div><div>print &quot;Day:&quot; . &amp;ui_textbox(&quo=
t;ld&quot;, $d, &quot;2&quot;) . &quot;Month:&quot; . &amp;ui_textbox(&quot=
;lm&quot;, $m, &quot;2&quot;) .=A0</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 &quot;Year:&quot;. =A0&amp;ui_textbox(&quot;ly&quot;, $y,&quot;4&quot;)=
 . &amp;date_chooser_button(&quot;ld&quot;, &quot;lm&quot;, &quot;ly&quot; =
), &quot;\n&quot;;</div>

<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</div><div><br></div><div>print &amp;ui_=
submit($text{&#39;log_display&#39;});</div><div><br></div><div>print &amp;u=
i_form_end();</div><div><br></div><div><br></div>
<div>
<br></div><div>$q =3D CGI-&gt;new;</div><div>$instance =3D $q-&gt;param(&#3=
9;inst&#39;);</div><div>$log_type =3D $q-&gt;param(&#39;log_type&#39;);</di=
v><div>$lday =3D sprintf(&quot;%02d&quot;, $q-&gt;param(&#39;ld&#39;)); #Fo=
rce 2 digit number</div>

<div>$lmonth =3D sprintf(&quot;%02d&quot;, $q-&gt;param(&#39;lm&#39;));=A0<=
/div><div>$lyear =3D sprintf(&quot;%04d&quot;, $q-&gt;param(&#39;ly&#39;));=
 #Force 4 digit number</div><div><br></div><div><br></div><div>$current =3D=
 `date &#39;+\%Y\%m\%d&#39; `;</div>

<div>$cdate =3D $lyear . $lmonth . $lday;</div><div>$aldate =3D $lyear . &q=
uot;-&quot; . $lmonth . &quot;-&quot;. $lday;</div><div><br></div><div>$ins=
tance =3D~ s/\s+//;</div><div><br></div><div><br></div><div>if ( $instance =
eq &quot;tomcat5&quot; ){</div>

<div><span class=3D"" style=3D"white-space:pre">	</span></div><div><span cl=
ass=3D"" style=3D"white-space:pre">	</span>if ( $log_type eq &quot;catalina=
.out&quot;) {=A0</div><div><span class=3D"" style=3D"white-space:pre">		</s=
pan>if ( $cdate =3D=3D $current ) {</div>

<div><span class=3D"" style=3D"white-space:pre">			</span>$tomcat_log =3D &=
quot;/var/log/tomcat5/catalina.out&quot;;</div><div><span class=3D"" style=
=3D"white-space:pre">		</span>}</div><div><span class=3D"" style=3D"white-s=
pace:pre">		</span>else {</div>

<div><span class=3D"" style=3D"white-space:pre">			</span>$tomcat_log =3D &=
quot;/var/log/tomcat5/catalina.out-$cdate.gz&quot;;</div><div><span class=
=3D"" style=3D"white-space:pre">		</span>}</div><div><span class=3D"" style=
=3D"white-space:pre">	</span>}</div>

<div><span class=3D"" style=3D"white-space:pre">	</span>elsif ( $log_type e=
q &quot;access_log&quot; ) {</div><div><span class=3D"" style=3D"white-spac=
e:pre">		</span>if ( $cdate =3D=3D $current ) {</div><div><span class=3D"" =
style=3D"white-space:pre">			</span>$tomcat_log =3D &quot;/var/log/tomcat5/=
access-logs/tomcat_access.log-$aldate&quot;;</div>

<div><span class=3D"" style=3D"white-space:pre">		</span>}</div><div><span =
class=3D"" style=3D"white-space:pre">		</span>else {</div><div><span class=
=3D"" style=3D"white-space:pre">			</span>$tomcat_log =3D &quot;/var/log/to=
mcat5/access-logs/tomcat_access.log-$aldate.gz&quot;;</div>

<div><span class=3D"" style=3D"white-space:pre">		</span>}</div><div><span =
class=3D"" style=3D"white-space:pre">	</span>}</div><div>}<span class=3D"" =
style=3D"white-space:pre">	</span></div><div>else {</div><div><span class=
=3D"" style=3D"white-space:pre">	</span>if ( $log_type eq &quot;catalina.ou=
t&quot; ) {</div>

<div><span class=3D"" style=3D"white-space:pre">		</span>if ( $cdate =3D=3D=
 $current ) {</div><div><span class=3D"" style=3D"white-space:pre">			</spa=
n>$tomcat_log =3D &quot;/var/lib/$instance/logs/catalina.out&quot;;</div><d=
iv><span class=3D"" style=3D"white-space:pre">		</span>}</div>

<div><span class=3D"" style=3D"white-space:pre">		</span>else {</div><div><=
span class=3D"" style=3D"white-space:pre">			</span>$tomcat_log =3D &quot;/=
var/lib/$instance/logs/catalina.out-$cdate.gz&quot;;</div><div><span class=
=3D"" style=3D"white-space:pre">		</span>}</div>

<div><span class=3D"" style=3D"white-space:pre">	</span>}</div><div><span c=
lass=3D"" style=3D"white-space:pre">	</span>elsif ($log_type eq &quot;acces=
s_log&quot; ) { =A0</div><div><span class=3D"" style=3D"white-space:pre">		=
</span>if ( $cdate =3D=3D $current) {</div>

<div>=A0 =A0 =A0 =A0 =A0 $tomcat_log =3D &quot;/var/lib/$instance/access-lo=
gs/tomcat_access.log-$aldate&quot;;</div><div><span class=3D"" style=3D"whi=
te-space:pre">		</span>}<span class=3D"" style=3D"white-space:pre">	</span>=
</div><div><span class=3D"" style=3D"white-space:pre">		</span>else {</div>

<div><span class=3D"" style=3D"white-space:pre">			</span>$tomcat_log =3D &=
quot;/var/lib/$instance/access-logs/tomcat_access.log</div><div>$aldate.gz&=
quot;;</div><div><span class=3D"" style=3D"white-space:pre">		</span>}</div=
><div>

<span class=3D"" style=3D"white-space:pre">	</span>}</div><div>}</div><div>=
print &quot;&lt;br&gt;&quot;;<span class=3D"" style=3D"white-space:pre">	</=
span></div><div>print &quot;Log: $tomcat_log \n&quot;;</div><div>print &quo=
t;&lt;br&gt;&quot;;</div>

<div><br></div><div>#print &amp;ui_form_start( &quot;index.cgi&quot;, &quot=
;form-data&quot;);</div><div>#print &amp;ui_hidden(&quot;log&quot;, $tomcat=
_log),&quot;&lt;br&gt;&quot;;</div><div>if ( -e $tomcat_log ) {</div><div>

=A0 =A0 if ( $cdate =3D=3D $current ) {</div><div>=A0 =A0 =A0 =A0 $data =3D=
 &amp;read_file_contents(&quot;$tomcat_log&quot;);</div><div>=A0 =A0 }</div=
><div>=A0 =A0 else {</div><div>=A0 =A0 =A0 =A0 $data =3D `zcat $tomcat_log`=
; =A0 =A0 =A0=A0</div><div><br></div><div>

=A0 =A0 }</div><div>}</div><div>#else {</div><div>=A0# =A0 print &quot;$tom=
cat_log does not exist on the server, kindly check your chosen date &lt;br&=
gt;&quot;;</div><div>#}</div><div><br></div><div>print &amp;ui_form_start( =
&quot;index.cgi&quot;, &quot;form-data&quot;);</div>

<div>print &amp;ui_hidden(&quot;log&quot;, $tomcat_log),&quot;&lt;br&gt;&qu=
ot;;</div><div>print &amp;ui_textarea(&quot;data&quot;, $data, 20, 80),&quo=
t;\n&quot;;</div><div>print &quot;&lt;br&gt;&quot;;</div><div>print &amp;ui=
_submit($text{&#39;exit&#39;});</div>

<div>print &amp;ui_form_end();</div><div><br></div><div><br></div><div>&amp=
;ui_print_footer(&quot;/&quot;, $text{&#39;index&#39;});</div></div>

--e89a8f921936ca484804d8d986a5--


--===============5725128296109651539==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
--===============5725128296109651539==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-
Forwarded by the Webmin development list at [email protected]
To remove yourself from this list, go to
http://lists.sourceforge.net/lists/listinfo/webadmin-devel

--===============5725128296109651539==--