]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/services.cgi
Removed an old file reference: /var/ipfire/firebuild
[ipfire-2.x.git] / html / cgi-bin / services.cgi
CommitLineData
ac1cfefa 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###############################################################################
ac1cfefa
MT
21
22use strict;
23
2032b6f9
CS
24# enable only the following on debugging purpose
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
27
f2fdd0c1 28require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
773362c5 31require "${General::swroot}/graphs.pl";
ac1cfefa 32
2032b6f9
CS
33#workaround to suppress a warning when a variable is used only once
34my @dummy = ( ${Header::colourred} );
35undef (@dummy);
ac1cfefa 36
2032b6f9
CS
37my %color = ();
38my %mainsettings = ();
39&General::readhash("${General::swroot}/main/settings", \%mainsettings);
40&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
41
42my %netsettings=();
43&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
ac1cfefa 44
773362c5
CS
45&Graphs::updateprocessesgraph ("day");
46
ac1cfefa 47my %cgiparams=();
2032b6f9
CS
48# Maps a nice printable name to the changing part of the pid file, which
49# is also the name of the program
50my %servicenames =
51(
52 $Lang::tr{'dhcp server'} => 'dhcpd',
53 $Lang::tr{'web server'} => 'httpd',
54 $Lang::tr{'cron server'} => 'fcron',
55 $Lang::tr{'dns proxy server'} => 'dnsmasq',
56 $Lang::tr{'logging server'} => 'syslogd',
57 $Lang::tr{'kernel logging server'} => 'klogd',
58 $Lang::tr{'ntp server'} => 'ntpd',
59 $Lang::tr{'secure shell server'} => 'sshd',
60 $Lang::tr{'vpn'} => 'pluto',
61 $Lang::tr{'web proxy'} => 'squid',
62 'OpenVPN' => 'openvpn'
63);
64
65my $lines=0; # Used to count the outputlines to make different bgcolor
66
67my $iface = '';
68if (open(FILE, "${General::swroot}/red/iface"))
69{
70 $iface = <FILE>;
71 close FILE;
72 chomp $iface;
ac1cfefa 73}
2032b6f9
CS
74$servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
75$servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
76if ($netsettings{'ORANGE_DEV'} ne '') {
77 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
ac1cfefa 78}
2032b6f9
CS
79if ($netsettings{'BLUE_DEV'} ne '') {
80 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
ac1cfefa
MT
81}
82
2032b6f9
CS
83&Header::showhttpheaders();
84&Header::getcgihash(\%cgiparams);
85&Header::openpage($Lang::tr{'status information'}, 1, '');
86&Header::openbigbox('100%', 'left');
ac1cfefa 87
2032b6f9 88&Header::openbox('100%', 'left', $Lang::tr{'services'});
ac1cfefa 89
2032b6f9
CS
90print <<END
91<div align='center'>
92<table width='80%' cellspacing='1' border='0'>
93<tr bgcolor='$color{'color20'}'><td align='left'><b>$Lang::tr{'services'}</b></td><td align='center' ><b>$Lang::tr{'status'}</b></td><td align='center'><b>PID</b></td><td align='center'><b>$Lang::tr{'memory'}</b></td></tr>
94END
95;
ac1cfefa 96
2032b6f9
CS
97my $key = '';
98foreach $key (sort keys %servicenames)
ac1cfefa 99{
2032b6f9
CS
100 $lines++;
101 if ($lines % 2)
102 { print "<tr bgcolor='$color{'color22'}'>\n<td align='left'>$key</td>\n";}
103 else
104 { print "<tr bgcolor='$color{'color20'}'>\n<td align='left'>$key</td>\n";}
ac1cfefa 105
2032b6f9
CS
106 my $shortname = $servicenames{$key};
107 my $status = &isrunning($shortname);
ac1cfefa 108
2032b6f9
CS
109 print "$status\n";
110 print "</tr>\n";
ac1cfefa
MT
111}
112
2032b6f9
CS
113
114print "</table></div>\n";
ac1cfefa
MT
115
116&Header::closebox();
117
2032b6f9 118&Header::openbox('100%', 'left', "Addon - $Lang::tr{services}");
ac1cfefa 119
2032b6f9
CS
120my $paramstr=$ENV{QUERY_STRING};
121my @param=split(/!/, $paramstr);
122if ($param[1] ne '') {
08efdb4f 123 system("/usr/local/bin/addonctrl @param[0] @param[1] > /dev/null 2>&1");
ac1cfefa
MT
124}
125
126print <<END
2032b6f9
CS
127<div align='center'>
128<table width='80%' cellspacing='1' border='0'>
129<tr bgcolor='$color{'color20'}'>
130<td align='center'><b>Addon</b></td>
131<td align='center'><b>Boot</b></td>
132<td align='center' colspan=2><b>$Lang::tr{'action'}</b></td>
133<td align='center'><b>$Lang::tr{'status'}</b></td>
134<td align='center'><b>PID</b></td>
135<td align='center'><b>$Lang::tr{'memory'}</b></td>
136</tr>
ac1cfefa
MT
137END
138;
ac1cfefa 139
2032b6f9 140my $lines=0; # Used to count the outputlines to make different bgcolor
ac1cfefa 141
2032b6f9
CS
142# Generate list of installed addon pak's
143my @pak = `find /opt/pakfire/db/installed/meta-* | cut -d"-" -f2`;
144foreach (@pak)
ac1cfefa 145{
2032b6f9 146 chomp($_);
773362c5 147
2032b6f9
CS
148 # Check which of the paks are services
149 my @svc = `find /etc/init.d/$_ | cut -d"/" -f4`;
150 foreach (@svc)
ac1cfefa 151 {
2032b6f9
CS
152 # blacklist some packages
153 #
154 # alsa has trouble with the volume saving and was not really stopped
155 #
156 chomp($_);
157 if ($_ ne "alsa")
158 {
159 $lines++;
773362c5 160 if ($lines % 2)
2032b6f9
CS
161 {
162 print "<tr bgcolor='$color{'color22'}'>";
ac1cfefa 163 }
2032b6f9
CS
164 else
165 {
166 print "<tr bgcolor='$color{'color20'}'>";
ac1cfefa 167 }
2032b6f9
CS
168 print "<td align='left'>$_</td> ";
169 my $status = isautorun($_);
170 print "$status ";
171 print "<td align='center'><A HREF=services.cgi?$_!start><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></A></td>";
172 print "<td align='center'><A HREF=services.cgi?$_!stop><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></A></td> ";
173 my $status = &isrunningaddon($_);
174 $status =~ s/\\e\[[0-1]\;[0-9]+m//g;
773362c5 175
2032b6f9
CS
176 chomp($status);
177 print "$status";
178 print "</tr>";
179 }
ac1cfefa
MT
180 }
181}
182
2032b6f9 183print "</table></div>\n";
ac1cfefa 184
773362c5
CS
185&Header::closebox();
186
187&Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'graph'}");
188if (-e "$Header::graphdir/processes-day.png") {
189 my $ftime = localtime((stat("$Header::graphdir/processes-day.png"))[9]);
190 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
191 print "<a href='/cgi-bin/graphs.cgi?graph=processes'>";
192 print "<img alt='' src='/graphs/processes-day.png' border='0' />";
193 print "</a>";
194} else {
195 print $Lang::tr{'no information available'};
196}
197print "<br />\n";
198&Header::closebox();
199
200&Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph'}");
201if (-e "$Header::graphdir/processesmem-day.png") {
202 my $ftime = localtime((stat("$Header::graphdir/processesmem-day.png"))[9]);
203 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
204 print "<a href='/cgi-bin/graphs.cgi?graph=processesmem'>";
205 print "<img alt='' src='/graphs/processesmem-day.png' border='0' />";
206 print "</a>";
207} else {
208 print $Lang::tr{'no information available'};
209}
210print "<br />\n";
2032b6f9
CS
211&Header::closebox();
212&Header::closebigbox();
213&Header::closepage();
ac1cfefa 214
2032b6f9 215sub isautorun
ac1cfefa 216{
2032b6f9
CS
217 my $cmd = $_[0];
218 my $status = "<td align='center'></td>";
219 my $init = `find /etc/rc.d/rc3.d/S??${cmd}`;
220 chomp ($init);
221 if ($init ne '') {
222 $status = "<td align='center'><A HREF=services.cgi?$_!disable><img alt='$Lang::tr{'deactivate'}' title='$Lang::tr{'deactivate'}' src='/images/on.gif' border='0' width='16' height='16' /></A></td>";
ac1cfefa 223 }
2032b6f9
CS
224 $init = `find /etc/rc.d/rc3.d/off/S??${cmd}`;
225 chomp ($init);
226 if ($init ne '') {
227 $status = "<td align='center'><A HREF=services.cgi?$_!enable><img alt='$Lang::tr{'activate'}' title='$Lang::tr{'activate'}' src='/images/off.gif' border='0' width='16' height='16' /></A></td>";
ac1cfefa 228 }
773362c5 229
2032b6f9
CS
230return $status;
231}
232
233sub isrunning
234{
235 my $cmd = $_[0];
236 my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>";
237 my $pid = '';
238 my $testcmd = '';
239 my $exename;
240 my @memory;
241
242 $cmd =~ /(^[a-z]+)/;
243 $exename = $1;
244
245 if (open(FILE, "/var/run/${cmd}.pid")){
246 $pid = <FILE>; chomp $pid;
247 close FILE;
248 if (open(FILE, "/proc/${pid}/status")){
249 while (<FILE>){
250 if (/^Name:\W+(.*)/) {$testcmd = $1; }
ac1cfefa 251 }
2032b6f9 252 close FILE;
ac1cfefa 253 }
2032b6f9
CS
254 if (open(FILE, "/proc/${pid}/statm")){
255 my $temp = <FILE>;
256 @memory = split(/ /,$temp);
ac1cfefa 257 }
2032b6f9
CS
258 close FILE;
259 if ($testcmd =~ /$exename/){$status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td><td align='center'>$pid</td><td align='center'>$memory[0] KB</td>";}
260 }
261return $status;
ac1cfefa
MT
262}
263
2032b6f9 264sub isrunningaddon
ac1cfefa 265{
2032b6f9
CS
266 my $cmd = $_[0];
267 my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>";
268 my $pid = '';
269 my $testcmd = '';
270 my $exename;
271 my @memory;
773362c5 272
2032b6f9 273 my $testcmd = `/usr/local/bin/addonctrl $_ status`;
ac1cfefa 274
2032b6f9
CS
275 if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){
276 $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
277 $testcmd =~ s/[a-z_]//gi; $testcmd =~ s/\[[0-1]\;[0-9]+//gi; $testcmd =~ s/[\(\)\.]//gi; $testcmd =~ s/ //gi; $testcmd =~ s/\e//gi;
278
279 my @pid = split(/\s/,$testcmd);
280 $status .="<td align='center'>$pid[0]</td>";
773362c5 281
2032b6f9 282 my $memory = 0;
773362c5 283
2032b6f9
CS
284 foreach (@pid){
285 chomp($_);
286 if (open(FILE, "/proc/$_/statm")){
287 my $temp = <FILE>;
288 @memory = split(/ /,$temp);
ac1cfefa 289 }
2032b6f9
CS
290 $memory+=$memory[0];
291 }
292 $status .="<td align='center'>$memory KB</td>";
ac1cfefa 293 }
2032b6f9
CS
294 else {$status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>";}
295return $status;
ac1cfefa 296}