]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/system.cgi
66abeb8ae1f8e5c765447e7a3bc722abac3c71b3
[ipfire-2.x.git] / html / cgi-bin / system.cgi
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
11 use strict;
12
13 # enable only the following on debugging purpose
14 #use warnings;
15 #use CGI::Carp 'fatalsToBrowser';
16
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
20 require "${General::swroot}/graphs.pl";
21
22 #workaround to suppress a warning when a variable is used only once
23 my @dummy = ( ${Header::colourred} );
24 undef (@dummy);
25
26 my %netsettings=();
27 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
28
29 my %color = ();
30 my %mainsettings = ();
31 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
32 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
33
34 my %cgiparams=();
35 # Maps a nice printable name to the changing part of the pid file, which
36 # is also the name of the program
37 my %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
52 my $iface = '';
53 if (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'}";
61 if ($netsettings{'ORANGE_DEV'} ne '') {
62 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
63 }
64 if ($netsettings{'BLUE_DEV'} ne '') {
65 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
66 }
67
68 # Generate Graphs from rrd Data
69 &Graphs::updatecpugraph ("day");
70 &Graphs::updateloadgraph ("day");
71
72 &Header::showhttpheaders();
73 &Header::getcgihash(\%cgiparams);
74 &Header::openpage($Lang::tr{'status information'}, 1, '');
75 &Header::openbigbox('100%', 'left');
76
77 &Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}");
78 if (-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 }
87 print "<br />\n";
88 &Header::closebox();
89
90 &Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}");
91 if (-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 }
100 print "<br />\n";
101 &Header::closebox();
102
103 &Header::openbox('100%', 'left', $Lang::tr{'services'});
104
105 print <<END
106 <div align='center'>
107 <table width='60%' cellspacing='0' border='0'>
108 END
109 ;
110
111 my $key = '';
112 foreach $key (sort keys %servicenames)
113 {
114 print "<tr>\n<td align='left'>$key</td>\n";
115 my $shortname = $servicenames{$key};
116 my $status = &isrunning($shortname);
117 print "$status\n";
118 print "</tr>\n";
119 }
120
121
122 print "</table></div>\n";
123
124 &Header::closebox();
125 &Header::closebigbox();
126 &Header::closepage();
127
128 sub 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
161 sub 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>
172 END
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>
183 END
184 ;
185 }
186 }