]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/system.cgi
Pakfire laedt die Listen jetzt besser und hat eine veraenderte Oberflaeche bekommen.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / system.cgi
CommitLineData
72fe12a9
MT
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#
10
11use strict;
12
13# enable only the following on debugging purpose
cb5e9c6c
CS
14#use warnings;
15#use CGI::Carp 'fatalsToBrowser';
72fe12a9
MT
16
17require '/var/ipfire/general-functions.pl';
18require "${General::swroot}/lang.pl";
19require "${General::swroot}/header.pl";
350b52c5 20require "${General::swroot}/graphs.pl";
72fe12a9
MT
21
22#workaround to suppress a warning when a variable is used only once
23my @dummy = ( ${Header::colourred} );
24undef (@dummy);
25
26my %netsettings=();
27&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
28
f2fdd0c1
CS
29my %color = ();
30my %mainsettings = ();
31&General::readhash("${General::swroot}/main/settings", \%mainsettings);
32&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
33
72fe12a9
MT
34my %cgiparams=();
35# Maps a nice printable name to the changing part of the pid file, which
36# is also the name of the program
37my %servicenames =
38(
39 $Lang::tr{'dhcp server'} => 'dhcpd',
40 $Lang::tr{'web server'} => 'httpd',
41 $Lang::tr{'cron server'} => 'fcron',
42 $Lang::tr{'dns proxy server'} => 'dnsmasq',
43 $Lang::tr{'logging server'} => 'syslogd',
44 $Lang::tr{'kernel logging server'} => 'klogd',
45 $Lang::tr{'ntp server'} => 'ntpd',
46 $Lang::tr{'secure shell server'} => 'sshd',
47 $Lang::tr{'vpn'} => 'pluto',
48 $Lang::tr{'web proxy'} => 'squid',
49 'OpenVPN' => 'openvpn'
50);
51
52my $iface = '';
53if (open(FILE, "${General::swroot}/red/iface"))
54{
55 $iface = <FILE>;
56 close FILE;
57 chomp $iface;
58}
59$servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
60$servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
61if ($netsettings{'ORANGE_DEV'} ne '') {
62 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
63}
64if ($netsettings{'BLUE_DEV'} ne '') {
65 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
66}
67
350b52c5
CS
68# Generate Graphs from rrd Data
69&Graphs::updatecpugraph ("day");
350b52c5 70&Graphs::updateloadgraph ("day");
72fe12a9 71
350b52c5 72&Header::showhttpheaders();
72fe12a9 73&Header::getcgihash(\%cgiparams);
72fe12a9 74&Header::openpage($Lang::tr{'status information'}, 1, '');
72fe12a9
MT
75&Header::openbigbox('100%', 'left');
76
77&Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}");
78if (-e "$Header::graphdir/cpu-day.png") {
79 my $ftime = localtime((stat("$Header::graphdir/cpu-day.png"))[9]);
80 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
81 print "<a href='/cgi-bin/graphs.cgi?graph=cpu'>";
82 print "<img alt='' src='/graphs/cpu-day.png' border='0' />";
83 print "</a>";
84} else {
85 print $Lang::tr{'no information available'};
86}
87print "<br />\n";
88&Header::closebox();
89
90&Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}");
91if (-e "$Header::graphdir/load-day.png") {
92 my $ftime = localtime((stat("$Header::graphdir/load-day.png"))[9]);
93 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
94 print "<a href='/cgi-bin/graphs.cgi?graph=load'>";
95 print "<img alt='' src='/graphs/load-day.png' border='0' />";
96 print "</a>";
97} else {
98 print $Lang::tr{'no information available'};
99}
100print "<br />\n";
101&Header::closebox();
102
103&Header::openbox('100%', 'left', $Lang::tr{'services'});
104
105print <<END
106<div align='center'>
107<table width='60%' cellspacing='0' border='0'>
108END
109;
110
72fe12a9
MT
111my $key = '';
112foreach $key (sort keys %servicenames)
113{
f2fdd0c1 114 print "<tr>\n<td align='left'>$key</td>\n";
72fe12a9
MT
115 my $shortname = $servicenames{$key};
116 my $status = &isrunning($shortname);
117 print "$status\n";
118 print "</tr>\n";
72fe12a9
MT
119}
120
121
122print "</table></div>\n";
123
124&Header::closebox();
72fe12a9 125&Header::closebigbox();
72fe12a9
MT
126&Header::closepage();
127
128sub isrunning
129{
130 my $cmd = $_[0];
131 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
132 my $pid = '';
133 my $testcmd = '';
134 my $exename;
135
136 $cmd =~ /(^[a-z]+)/;
137 $exename = $1;
138
139 if (open(FILE, "/var/run/${cmd}.pid"))
140 {
141 $pid = <FILE>; chomp $pid;
142 close FILE;
143 if (open(FILE, "/proc/${pid}/status"))
144 {
145 while (<FILE>)
146 {
147 if (/^Name:\W+(.*)/) {
148 $testcmd = $1; }
149 }
150 close FILE;
151 if ($testcmd =~ /$exename/)
152 {
153 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
154 }
155 }
156 }
157
158 return $status;
159}
160
161sub percentbar
162{
163 my $percent = $_[0];
164 my $fg = '#a0a0a0';
165 my $bg = '#e2e2e2';
166
167 if ($percent =~ m/^(\d+)%$/ )
168 {
169 print <<END
170<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
171<tr>
172END
173;
174 if ($percent eq "100%") {
175 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
176 } elsif ($percent eq "0%") {
177 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
178 } else {
179 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'>"
180 }
181 print <<END
182<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
183END
184;
185 }
186}