ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/misc/scripts/cgi/taillog.cgi
Revision: 1.2
Committed: Mon Mar 26 21:15:18 2001 UTC (23 years, 7 months ago) by tdb
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.1: +2 -2 lines
Log Message:
Uses larger values.

File Contents

# User Rev Content
1 tdb 1.1 #!/usr/bin/perl
2    
3     require CGI;
4    
5     my $query = new CGI;
6    
7     my ($n) = $query->param('n');
8     my ($grep) = $query->param('grep');
9    
10     if (defined $grep) {
11     if ($grep eq "") {
12     $grepStr = "";
13     }
14     else {
15     $grepStr = " | grep $grep";
16     }
17     }
18     else {
19     $grep = "";
20     }
21    
22     if (!defined $n) {
23     $n = 50;
24     }
25    
26 tdb 1.2 unless ($n =~ /^[0-9]{1,6}$/) {
27 tdb 1.1 $n = 50;
28     }
29    
30     print "Content-type: text/html\n\n";
31    
32     my(@lines) = `tail -n$n ../www/server.log$grepStr`;
33    
34     print <<"END";
35     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
36    
37     <html>
38    
39     <head>
40     <title>The i-scream Project Logfile Tailer</title>
41     <meta name="description" content="The i-scream Project is a central
42     monitoring system for Unix, Linux and NT servers.">
43     <meta name="keywords" content="i-scream, project, central monitoring
44     system, unix, linux, nt, server, alert">
45     <meta name="generator" content="notepad on acid, aye.">
46     </head>
47    
48     <body bgcolor="#ffffff" link="#0000ff" alink="#3333cc" vlink="#3333cc"
49     text="#000066">
50    
51     <a href="http://www.i-scream.org.uk"><img border="0" src="/i-scream.gif"></a>
52    
53     <form method="GET" action="taillog.cgi">
54     <font size="+1"><b>
55 tdb 1.2 Last <input type="text" name="n" value="$n" size="5" maxlength="5"> lines
56 tdb 1.1 of the server logfile.
57     | grep </b><input type="text" name="grep" value="$grep" size="20" maxlength="40">
58     <input type="submit" value="Enter">
59     </font>
60     </form>
61     <hr>
62     <pre>
63     END
64    
65     foreach my $line (@lines) {
66     print HTML_encode($line);
67     }
68    
69     print <<"END";
70     </pre>
71     </body>
72    
73     </html>
74     END
75    
76     exit 0;
77    
78     #------------------------------------------------------
79     # sub HTML_encode
80     #
81     # escape HTML characters that may cause problems when
82     # shown either in the <body> or within text fields.
83     #------------------------------------------------------
84     sub HTML_encode ($){
85     my ($encoded) = @_;
86     $encoded =~ s/&/&amp;/g;
87     $encoded =~ s/"/&quot;/g;
88     $encoded =~ s/</&lt;/g;
89     $encoded =~ s/>/&gt;/g;
90     $encoded =~ s/^(.{0})(.*core\.loggers\..*: started)$/<hr size=10 color=blue>$2/;
91     $encoded =~ s/(.*)] (.*)}:(.*)/$1] <i>$2<\/i>:<b>$3<\/b>/;
92     return $encoded;
93     }
94