]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/system.cgi
Ein Paar Dateien fuer die GPLv3 angepasst.
[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(
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
63my $iface = '';
64if (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'}";
72if ($netsettings{'ORANGE_DEV'} ne '') {
73 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
74}
75if ($netsettings{'BLUE_DEV'} ne '') {
76 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
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'>
118<table width='60%' cellspacing='0' border='0'>
119END
120;
121
72fe12a9
MT
122my $key = '';
123foreach $key (sort keys %servicenames)
124{
f2fdd0c1 125 print "<tr>\n<td align='left'>$key</td>\n";
72fe12a9
MT
126 my $shortname = $servicenames{$key};
127 my $status = &isrunning($shortname);
128 print "$status\n";
129 print "</tr>\n";
72fe12a9
MT
130}
131
132
133print "</table></div>\n";
134
135&Header::closebox();
72fe12a9 136&Header::closebigbox();
72fe12a9
MT
137&Header::closepage();
138
139sub 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
172sub 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>
183END
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>
194END
195;
196 }
197}