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