]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/status.cgi
Einige (hoffentlich die letzten) Rootfiles hinzugefuegt...
[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 &Header::openbox('100%', 'left', $Lang::tr{'services'});
72
73 print <<END
74 <div align='center'>
75 <table width='60%' cellspacing='0' border='0'>
76 END
77 ;
78
79 my $lines = 0;
80 my $key = '';
81 foreach $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
96 print "</table></div>\n";
97
98 &Header::closebox();
99
100 &Header::openbox('100%', 'left', $Lang::tr{'memory'});
101 print "<table><tr><td><table>";
102 my $ram=0;
103 my $size=0;
104 my $used=0;
105 my $free=0;
106 my $percent=0;
107 my $shared=0;
108 my $buffers=0;
109 my $cached=0;
110 open(FREE,'/usr/bin/free |');
111 while(<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>
123 END
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>
133 END
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>
147 END
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>
158 END
159 ;
160 &percentbar($percent);
161 print <<END
162 </td>
163 <td align='right'>$percent</td>
164 </tr>
165 END
166 ;
167 }
168 }
169 close FREE;
170 print <<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>
178 END
179 ;
180 &Header::closebox();
181
182 &Header::openbox('100%', 'left', $Lang::tr{'disk usage'});
183 print "<table>\n";
184 open(DF,'/bin/df -B M -x rootfs|');
185 while(<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>
198 END
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>
212 END
213 ;
214 &percentbar($percent);
215 print <<END
216 </td>
217 <td align='right'>$percent</td>
218 </tr>
219 END
220 ;
221 }
222 }
223 close DF;
224 print "</table>\n";
225 &Header::closebox();
226
227 &Header::openbox('100%', 'left', $Lang::tr{'uptime and users'});
228 my $output = `/usr/bin/who`;
229 $output = &Header::cleanhtml($output,"y");
230 print "<pre>$output</pre>\n";
231 &Header::closebox();
232
233 &Header::openbox('100%', 'left', $Lang::tr{'loaded modules'});
234 $output = qx+/bin/lsmod+;
235 ($output = &Header::cleanhtml($output,"y")) =~ s/\[.*\]//g;
236 print "<pre>\n$output\n</pre>\n";
237 &Header::closebox();
238
239 &Header::openbox('100%', 'left', $Lang::tr{'kernel version'});
240 print "<pre>\n";
241 print `/bin/uname -a`;
242 print "</pre>\n";
243 &Header::closebox();
244
245 &Header::closebigbox();
246
247 &Header::closepage();
248
249 sub 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
282 sub 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>
293 END
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>
304 END
305 ;
306 }
307 }