]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/status.cgi
RRDTool Fix
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / status.cgi
1 #!/usr/bin/perl
2 #
3 # SmoothWall CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The SmoothWall Team
8 #
9 # $Id: status.cgi,v 1.6.2.7 2005/02/24 07:44:35 gespinasse Exp $
10 #
11
12 use strict;
13
14 # enable only the following on debugging purpose
15 #use warnings;
16 #use CGI::Carp 'fatalsToBrowser';
17
18 require '/var/ipfire/general-functions.pl';
19 require "${General::swroot}/lang.pl";
20 require "${General::swroot}/header.pl";
21
22 #workaround to suppress a warning when a variable is used only once
23 my @dummy = ( ${Header::colourred} );
24 undef (@dummy);
25
26 my %netsettings=();
27 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
28
29 my %cgiparams=();
30 # Maps a nice printable name to the changing part of the pid file, which
31 # is also the name of the program
32 my %servicenames =
33 (
34 $Lang::tr{'dhcp server'} => 'dhcpd',
35 $Lang::tr{'web server'} => 'httpd',
36 $Lang::tr{'cron server'} => 'fcron',
37 $Lang::tr{'dns proxy server'} => 'dnsmasq',
38 $Lang::tr{'logging server'} => 'syslogd',
39 $Lang::tr{'kernel logging server'} => 'klogd',
40 $Lang::tr{'ntp server'} => 'ntpd',
41 $Lang::tr{'secure shell server'} => 'sshd',
42 $Lang::tr{'vpn'} => 'pluto',
43 $Lang::tr{'web proxy'} => 'squid',
44 'OpenVPN' => 'openvpn'
45 );
46
47 my $iface = '';
48 if (open(FILE, "${General::swroot}/red/iface"))
49 {
50 $iface = <FILE>;
51 close FILE;
52 chomp $iface;
53 }
54 $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
55 $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
56 if ($netsettings{'ORANGE_DEV'} ne '') {
57 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
58 }
59 if ($netsettings{'BLUE_DEV'} ne '') {
60 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
61 }
62
63 &Header::showhttpheaders();
64
65 &Header::getcgihash(\%cgiparams);
66
67 &Header::openpage($Lang::tr{'status information'}, 1, '');
68
69 &Header::openbigbox('100%', 'left');
70
71 print <<END
72 <table width='100%' cellspacing='0' cellpadding='5'border='0'>
73 <tr><td style="background-color: #EAE9EE;" align='left'>
74 <a href='#services'>$Lang::tr{'services'}</a> |
75 <a href='#memory'>$Lang::tr{'memory'}</a> |
76 <a href='#disk'>$Lang::tr{'disk usage'}</a> |
77 <a href='#uptime'>$Lang::tr{'uptime and users'}</a> |
78 <a href='#modules'>$Lang::tr{'loaded modules'}</a> |
79 <a href='#kernel'>$Lang::tr{'kernel version'}</a>
80 </td></tr></table>
81 END
82 ;
83
84 print "<a name='services'/>\n";
85 &Header::openbox('100%', 'left', $Lang::tr{'services'});
86
87 print <<END
88 <div align='center'>
89 <table width='60%' cellspacing='0' border='0'>
90 END
91 ;
92
93 my $lines = 0;
94 my $key = '';
95 foreach $key (sort keys %servicenames)
96 {
97 if ($lines % 2) {
98 print "<tr bgcolor='${Header::table1colour}'>\n"; }
99 else {
100 print "<tr bgcolor='${Header::table2colour}'>\n"; }
101 print "<td align='left'>$key</td>\n";
102 my $shortname = $servicenames{$key};
103 my $status = &isrunning($shortname);
104 print "$status\n";
105 print "</tr>\n";
106 $lines++;
107 }
108
109
110 print "</table></div>\n";
111
112 &Header::closebox();
113
114 print "<a name='memory'/>\n";
115 &Header::openbox('100%', 'left', $Lang::tr{'memory'});
116 print "<table><tr><td><table>";
117 my $ram=0;
118 my $size=0;
119 my $used=0;
120 my $free=0;
121 my $percent=0;
122 my $shared=0;
123 my $buffers=0;
124 my $cached=0;
125 open(FREE,'/usr/bin/free |');
126 while(<FREE>)
127 {
128 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
129 {
130 print <<END
131 <tr>
132 <td>&nbsp;</td>
133 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
134 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
135 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
136 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
137 </tr>
138 END
139 ;
140 } else {
141 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
142 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
143 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
144 print <<END
145 <tr>
146 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
147 <td align='right'>$size</td>
148 END
149 ;
150 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
151 ($size,$used,$free) = ($1,$2,$3);
152 if ($size != 0)
153 {
154 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
155 } else {
156 ($percent = '');
157 }
158 print <<END
159 <tr>
160 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
161 <td align='right'>$size</td>
162 END
163 ;
164 } elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) {
165 ($used,$free) = ($1,$2);
166 ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
167 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
168 }
169 print <<END
170 <td align='right'>$used</td>
171 <td align='right'>$free</td>
172 <td>
173 END
174 ;
175 &percentbar($percent);
176 print <<END
177 </td>
178 <td align='right'>$percent</td>
179 </tr>
180 END
181 ;
182 }
183 }
184 close FREE;
185 print <<END
186 </table></td><td>
187 <table>
188 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='right'>$shared</td></tr>
189 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='right'>$buffers</td></tr>
190 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='right'>$cached</td></tr>
191 </table>
192 </td></tr></table>
193 END
194 ;
195 &Header::closebox();
196
197 print "<a name='disk'/>\n";
198 &Header::openbox('100%', 'left', $Lang::tr{'disk usage'});
199 print "<table>\n";
200 open(DF,'/bin/df -B M -x rootfs|');
201 while(<DF>)
202 {
203 if ($_ =~ m/^Filesystem/ )
204 {
205 print <<END
206 <tr>
207 <td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
208 <td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
209 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
210 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
211 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
212 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
213 </tr>
214 END
215 ;
216 }
217 else
218 {
219 my ($device,$size,$used,$free,$percent,$mount) = split;
220 print <<END
221 <tr>
222 <td>$device</td>
223 <td>$mount</td>
224 <td align='right'>$size</td>
225 <td align='right'>$used</td>
226 <td align='right'>$free</td>
227 <td>
228 END
229 ;
230 &percentbar($percent);
231 print <<END
232 </td>
233 <td align='right'>$percent</td>
234 </tr>
235 END
236 ;
237 }
238 }
239 close DF;
240 print "</table>\n";
241 &Header::closebox();
242
243 print "<a name='uptime'/>\n";
244 &Header::openbox('100%', 'left', $Lang::tr{'uptime and users'});
245 my $output = `/usr/bin/w`;
246 $output = &Header::cleanhtml($output,"y");
247 print "<pre>$output</pre>\n";
248 &Header::closebox();
249
250 print "<a name='modules'/>\n";
251 &Header::openbox('100%', 'left', $Lang::tr{'loaded modules'});
252 $output = qx+/bin/lsmod+;
253 ($output = &Header::cleanhtml($output,"y")) =~ s/\[.*\]//g;
254 print "<pre>\n$output\n</pre>\n";
255 &Header::closebox();
256
257 print "<a name='kernel'/>\n";
258 &Header::openbox('100%', 'left', $Lang::tr{'kernel version'});
259 print "<pre>\n";
260 print `/bin/uname -a`;
261 print "</pre>\n";
262 &Header::closebox();
263
264 &Header::closebigbox();
265
266 &Header::closepage();
267
268 sub isrunning
269 {
270 my $cmd = $_[0];
271 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
272 my $pid = '';
273 my $testcmd = '';
274 my $exename;
275
276 $cmd =~ /(^[a-z]+)/;
277 $exename = $1;
278
279 if (open(FILE, "/var/run/${cmd}.pid"))
280 {
281 $pid = <FILE>; chomp $pid;
282 close FILE;
283 if (open(FILE, "/proc/${pid}/status"))
284 {
285 while (<FILE>)
286 {
287 if (/^Name:\W+(.*)/) {
288 $testcmd = $1; }
289 }
290 close FILE;
291 if ($testcmd =~ /$exename/)
292 {
293 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
294 }
295 }
296 }
297
298 return $status;
299 }
300
301 sub percentbar
302 {
303 my $percent = $_[0];
304 my $fg = '#a0a0a0';
305 my $bg = '#e2e2e2';
306
307 if ($percent =~ m/^(\d+)%$/ )
308 {
309 print <<END
310 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
311 <tr>
312 END
313 ;
314 if ($percent eq "100%") {
315 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
316 } elsif ($percent eq "0%") {
317 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
318 } else {
319 print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
320 }
321 print <<END
322 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
323 END
324 ;
325 }
326 }