b18bb537ebc955dcf5e94197642f74fd2dd934a5
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / system.cgi
1 #!/usr/bin/perl
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 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
32
33 #workaround to suppress a warning when a variable is used only once
34 my @dummy = ( ${Header::colourred} );
35 undef (@dummy);
36
37 my %netsettings=();
38 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
39
40 my %color = ();
41 my %mainsettings = ();
42 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
43 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
44
45 my %cgiparams=();
46 # Maps a nice printable name to the changing part of the pid file, which
47 # is also the name of the program
48 my %servicenames =
49 (
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'
61 );
62
63 my $iface = '';
64 if (open(FILE, "${General::swroot}/red/iface"))
65 {
66 $iface = <FILE>;
67 close FILE;
68 chomp $iface;
69 }
70 $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
71 $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
72 if ($netsettings{'ORANGE_DEV'} ne '') {
73 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
74 }
75 if ($netsettings{'BLUE_DEV'} ne '') {
76 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
77 }
78
79 # Generate Graphs from rrd Data
80 &Graphs::updatecpugraph ("day");
81 &Graphs::updateloadgraph ("day");
82
83 &Header::showhttpheaders();
84 &Header::getcgihash(\%cgiparams);
85 &Header::openpage($Lang::tr{'status information'}, 1, '');
86 &Header::openbigbox('100%', 'left');
87
88 &Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}");
89 if (-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 }
98 print "<br />\n";
99 &Header::closebox();
100
101 &Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}");
102 if (-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 }
111 print "<br />\n";
112 &Header::closebox();
113
114 &Header::openbox('100%', 'left', $Lang::tr{'services'});
115
116 print <<END
117 <div align='center'>
118 <table width='60%' cellspacing='0' border='0'>
119 END
120 ;
121
122 my $key = '';
123 foreach $key (sort keys %servicenames)
124 {
125 print "<tr>\n<td align='left'>$key</td>\n";
126 my $shortname = $servicenames{$key};
127 my $status = &isrunning($shortname);
128 print "$status\n";
129 print "</tr>\n";
130 }
131
132
133 print "</table></div>\n";
134
135 &Header::closebox();
136 &Header::closebigbox();
137 &Header::closepage();
138
139 sub isrunning
140 {
141 my $cmd = $_[0];
142 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
143 my $pid = '';
144 my $testcmd = '';
145 my $exename;
146
147 $cmd =~ /(^[a-z]+)/;
148 $exename = $1;
149
150 if (open(FILE, "/var/run/${cmd}.pid"))
151 {
152 $pid = <FILE>; chomp $pid;
153 close FILE;
154 if (open(FILE, "/proc/${pid}/status"))
155 {
156 while (<FILE>)
157 {
158 if (/^Name:\W+(.*)/) {
159 $testcmd = $1; }
160 }
161 close FILE;
162 if ($testcmd =~ /$exename/)
163 {
164 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
165 }
166 }
167 }
168
169 return $status;
170 }
171
172 sub percentbar
173 {
174 my $percent = $_[0];
175 my $fg = '#a0a0a0';
176 my $bg = '#e2e2e2';
177
178 if ($percent =~ m/^(\d+)%$/ )
179 {
180 print <<END
181 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
182 <tr>
183 END
184 ;
185 if ($percent eq "100%") {
186 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
187 } elsif ($percent eq "0%") {
188 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
189 } else {
190 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'>"
191 }
192 print <<END
193 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
194 END
195 ;
196 }
197 }