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