]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/status.cgi
SMP-Config angepasst.. CGIs usw. wurden im Windoof-Format gespeichert... muss noch...
[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 'CONFIG_ROOT/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 );
45
46 my $iface = '';
47 if (open(FILE, "${General::swroot}/red/iface"))
48 {
49 $iface = <FILE>;
50 close FILE;
51 chomp $iface;
52 }
53 $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
54 $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
55 if ($netsettings{'ORANGE_DEV'} ne '') {
56 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
57 }
58 if ($netsettings{'BLUE_DEV'} ne '') {
59 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
60 }
61
62 &Header::showhttpheaders();
63
64 &Header::getcgihash(\%cgiparams);
65
66 &Header::openpage($Lang::tr{'status information'}, 1, '');
67
68 &Header::openbigbox('100%', 'left');
69
70 print <<END
71 <table width='100%' cellspacing='0' cellpadding='5'border='0'>
72 <tr><td style="background-color: #EAE9EE;" align='left'>
73 <a href='#services'>$Lang::tr{'services'}</a> |
74 <a href='#memory'>$Lang::tr{'memory'}</a> |
75 <a href='#disk'>$Lang::tr{'disk usage'}</a> |
76 <a href='#uptime'>$Lang::tr{'uptime and users'}</a> |
77 <a href='#modules'>$Lang::tr{'loaded modules'}</a> |
78 <a href='#kernel'>$Lang::tr{'kernel version'}</a>
79 </td></tr></table>
80 END
81 ;
82
83 print "<a name='services'/>\n";
84 &Header::openbox('100%', 'left', $Lang::tr{'services'});
85
86 print <<END
87 <div align='center'>
88 <table width='60%' cellspacing='0' border='0'>
89 END
90 ;
91
92 my $lines = 0;
93 my $key = '';
94 foreach $key (sort keys %servicenames)
95 {
96 if ($lines % 2) {
97 print "<tr bgcolor='${Header::table1colour}'>\n"; }
98 else {
99 print "<tr bgcolor='${Header::table2colour}'>\n"; }
100 print "<td align='left'>$key</td>\n";
101 my $shortname = $servicenames{$key};
102 my $status = &isrunning($shortname);
103 print "$status\n";
104 print "</tr>\n";
105 $lines++;
106 }
107
108
109 print "</table></div>\n";
110
111 &Header::closebox();
112
113 print "<a name='memory'/>\n";
114 &Header::openbox('100%', 'left', $Lang::tr{'memory'});
115 print "<table><tr><td><table>";
116 my $ram=0;
117 my $size=0;
118 my $used=0;
119 my $free=0;
120 my $percent=0;
121 my $shared=0;
122 my $buffers=0;
123 my $cached=0;
124 open(FREE,'/usr/bin/free |');
125 while(<FREE>)
126 {
127 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
128 {
129 print <<END
130 <tr>
131 <td>&nbsp;</td>
132 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
133 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
134 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
135 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
136 </tr>
137 END
138 ;
139 } else {
140 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
141 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
142 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
143 print <<END
144 <tr>
145 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
146 <td align='right'>$size</td>
147 END
148 ;
149 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
150 ($size,$used,$free) = ($1,$2,$3);
151 if ($size != 0)
152 {
153 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
154 } else {
155 ($percent = '');
156 }
157 print <<END
158 <tr>
159 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
160 <td align='right'>$size</td>
161 END
162 ;
163 } elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) {
164 ($used,$free) = ($1,$2);
165 ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
166 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
167 }
168 print <<END
169 <td align='right'>$used</td>
170 <td align='right'>$free</td>
171 <td>
172 END
173 ;
174 &percentbar($percent);
175 print <<END
176 </td>
177 <td align='right'>$percent</td>
178 </tr>
179 END
180 ;
181 }
182 }
183 close FREE;
184 print <<END
185 </table></td><td>
186 <table>
187 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='right'>$shared</td></tr>
188 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='right'>$buffers</td></tr>
189 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='right'>$cached</td></tr>
190 </table>
191 </td></tr></table>
192 END
193 ;
194 &Header::closebox();
195
196 print "<a name='disk'/>\n";
197 &Header::openbox('100%', 'left', $Lang::tr{'disk usage'});
198 print "<table>\n";
199 open(DF,'/bin/df -B M -x rootfs|');
200 while(<DF>)
201 {
202 if ($_ =~ m/^Filesystem/ )
203 {
204 print <<END
205 <tr>
206 <td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
207 <td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
208 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
209 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
210 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
211 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
212 </tr>
213 END
214 ;
215 }
216 else
217 {
218 my ($device,$size,$used,$free,$percent,$mount) = split;
219 print <<END
220 <tr>
221 <td>$device</td>
222 <td>$mount</td>
223 <td align='right'>$size</td>
224 <td align='right'>$used</td>
225 <td align='right'>$free</td>
226 <td>
227 END
228 ;
229 &percentbar($percent);
230 print <<END
231 </td>
232 <td align='right'>$percent</td>
233 </tr>
234 END
235 ;
236 }
237 }
238 close DF;
239 print "</table>\n";
240 &Header::closebox();
241
242 print "<a name='uptime'/>\n";
243 &Header::openbox('100%', 'left', $Lang::tr{'uptime and users'});
244 my $output = `/usr/bin/w`;
245 $output = &Header::cleanhtml($output,"y");
246 print "<pre>$output</pre>\n";
247 &Header::closebox();
248
249 print "<a name='modules'/>\n";
250 &Header::openbox('100%', 'left', $Lang::tr{'loaded modules'});
251 $output = qx+/sbin/lsmod+;
252 ($output = &Header::cleanhtml($output,"y")) =~ s/\[.*\]//g;
253 print "<pre>\n$output\n</pre>\n";
254 &Header::closebox();
255
256 print "<a name='kernel'/>\n";
257 &Header::openbox('100%', 'left', $Lang::tr{'kernel version'});
258 print "<pre>\n";
259 print `/bin/uname -a`;
260 print "</pre>\n";
261 &Header::closebox();
262
263 &Header::closebigbox();
264
265 &Header::closepage();
266
267 sub isrunning
268 {
269 my $cmd = $_[0];
270 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
271 my $pid = '';
272 my $testcmd = '';
273 my $exename;
274
275 $cmd =~ /(^[a-z]+)/;
276 $exename = $1;
277
278 if (open(FILE, "/var/run/${cmd}.pid"))
279 {
280 $pid = <FILE>; chomp $pid;
281 close FILE;
282 if (open(FILE, "/proc/${pid}/status"))
283 {
284 while (<FILE>)
285 {
286 if (/^Name:\W+(.*)/) {
287 $testcmd = $1; }
288 }
289 close FILE;
290 if ($testcmd =~ /$exename/)
291 {
292 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
293 }
294 }
295 }
296
297 return $status;
298 }
299
300 sub percentbar
301 {
302 my $percent = $_[0];
303 my $fg = '#a0a0a0';
304 my $bg = '#e2e2e2';
305
306 if ($percent =~ m/^(\d+)%$/ )
307 {
308 print <<END
309 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
310 <tr>
311 END
312 ;
313 if ($percent eq "100%") {
314 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
315 } elsif ($percent eq "0%") {
316 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
317 } else {
318 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'>"
319 }
320 print <<END
321 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
322 END
323 ;
324 }
325 }