corrected some smaller bugs in some cgiŽs
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / system.cgi
CommitLineData
72fe12a9 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
72fe12a9
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
72fe12a9
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
350b52c5 31require "${General::swroot}/graphs.pl";
72fe12a9
MT
32
33#workaround to suppress a warning when a variable is used only once
34my @dummy = ( ${Header::colourred} );
35undef (@dummy);
36
37my %netsettings=();
38&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
39
f2fdd0c1
CS
40my %color = ();
41my %mainsettings = ();
42&General::readhash("${General::swroot}/main/settings", \%mainsettings);
43&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
44
72fe12a9
MT
45my %cgiparams=();
46# Maps a nice printable name to the changing part of the pid file, which
47# is also the name of the program
48my %servicenames =
49(
33e1f48c
CS
50 $Lang::tr{'dhcp server'} => 'dhcpd',
51 $Lang::tr{'web server'} => 'httpd',
52 $Lang::tr{'cron server'} => 'fcron',
53 $Lang::tr{'dns proxy server'} => 'dnsmasq',
54 $Lang::tr{'logging server'} => 'syslogd',
55 $Lang::tr{'kernel logging server'} => 'klogd',
56 $Lang::tr{'ntp server'} => 'ntpd',
57 $Lang::tr{'secure shell server'} => 'sshd',
58 $Lang::tr{'vpn'} => 'pluto',
59 $Lang::tr{'web proxy'} => 'squid',
60 'OpenVPN' => 'openvpn'
72fe12a9
MT
61);
62
63my $iface = '';
64if (open(FILE, "${General::swroot}/red/iface"))
65{
33e1f48c
CS
66 $iface = <FILE>;
67 close FILE;
68 chomp $iface;
72fe12a9
MT
69}
70$servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
71$servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
72if ($netsettings{'ORANGE_DEV'} ne '') {
33e1f48c 73 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
72fe12a9
MT
74}
75if ($netsettings{'BLUE_DEV'} ne '') {
33e1f48c 76 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
72fe12a9
MT
77}
78
350b52c5
CS
79# Generate Graphs from rrd Data
80&Graphs::updatecpugraph ("day");
350b52c5 81&Graphs::updateloadgraph ("day");
72fe12a9 82
350b52c5 83&Header::showhttpheaders();
72fe12a9 84&Header::getcgihash(\%cgiparams);
72fe12a9 85&Header::openpage($Lang::tr{'status information'}, 1, '');
72fe12a9
MT
86&Header::openbigbox('100%', 'left');
87
88&Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}");
89if (-e "$Header::graphdir/cpu-day.png") {
90 my $ftime = localtime((stat("$Header::graphdir/cpu-day.png"))[9]);
91 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
92 print "<a href='/cgi-bin/graphs.cgi?graph=cpu'>";
93 print "<img alt='' src='/graphs/cpu-day.png' border='0' />";
94 print "</a>";
95} else {
96 print $Lang::tr{'no information available'};
97}
98print "<br />\n";
99&Header::closebox();
100
101&Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}");
102if (-e "$Header::graphdir/load-day.png") {
103 my $ftime = localtime((stat("$Header::graphdir/load-day.png"))[9]);
104 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
105 print "<a href='/cgi-bin/graphs.cgi?graph=load'>";
106 print "<img alt='' src='/graphs/load-day.png' border='0' />";
107 print "</a>";
108} else {
109 print $Lang::tr{'no information available'};
110}
111print "<br />\n";
112&Header::closebox();
113
114&Header::openbox('100%', 'left', $Lang::tr{'services'});
115
116print <<END
117<div align='center'>
33e1f48c
CS
118<table width='60%' cellspacing='1' border='0'>
119<tr><td align='left'><b>$Lang::tr{'services'}</b></td><td align='center'><b>$Lang::tr{'status'}</b></td><td align='center'><b>PID</b></td><td align='center'><b>$Lang::tr{'memory'}</b></td></tr>
72fe12a9
MT
120END
121;
122
72fe12a9
MT
123my $key = '';
124foreach $key (sort keys %servicenames)
125{
33e1f48c
CS
126 print "<tr>\n<td align='left'>$key</td>\n";
127 my $shortname = $servicenames{$key};
128 my $status = &isrunning($shortname);
129 print "$status\n";
130 print "</tr>\n";
72fe12a9
MT
131}
132
133
134print "</table></div>\n";
135
136&Header::closebox();
72fe12a9 137&Header::closebigbox();
72fe12a9
MT
138&Header::closepage();
139
140sub isrunning
141{
33e1f48c
CS
142 my $cmd = $_[0];
143 my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>";
144 my $pid = '';
145 my $testcmd = '';
146 my $exename;
147 my @memory;
148
149 $cmd =~ /(^[a-z]+)/;
150 $exename = $1;
151
152 if (open(FILE, "/var/run/${cmd}.pid")){
153 $pid = <FILE>; chomp $pid;
154 close FILE;
155 if (open(FILE, "/proc/${pid}/status")){
156 while (<FILE>){
157 if (/^Name:\W+(.*)/) {$testcmd = $1; }
158 }
159 close FILE;
160 }
161 if (open(FILE, "/proc/${pid}/statm")){
162 my $temp = <FILE>;
163 @memory = split(/ /,$temp);
164 }
165 close FILE;
166 if ($testcmd =~ /$exename/){$status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td><td align='center'>$pid</td><td align='center'>$memory[0] KB</td>";}
167 }
168return $status;
72fe12a9
MT
169}
170
171sub percentbar
172{
33e1f48c
CS
173 my $percent = $_[0];
174 my $fg = '#a0a0a0';
175 my $bg = '#e2e2e2';
72fe12a9 176
33e1f48c
CS
177 if ($percent =~ m/^(\d+)%$/ ){
178 print <<END
72fe12a9
MT
179<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
180<tr>
181END
182;
33e1f48c
CS
183 if ($percent eq "100%") {
184 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
185 } elsif ($percent eq "0%") {
186 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
187 } else {
188 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'>"
189 }
190 print <<END
72fe12a9
MT
191<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
192END
193;
194 }
195}