2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2021 IPFire Team #
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. #
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. #
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/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
34 my %mainsettings = ();
36 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
37 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
38 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
40 #workaround to suppress a warning when a variable is used only once
41 my @dummy = ( ${Header
::colourred
} );
46 # Maps a nice printable name to the changing part of the pid file, which
47 # is also the name of the program
49 $Lang::tr
{'dhcp server'} => 'dhcpd',
50 $Lang::tr
{'web server'} => 'httpd',
51 $Lang::tr
{'cron server'} => 'fcron',
52 $Lang::tr
{'dns proxy server'} => 'unbound',
53 $Lang::tr
{'logging server'} => 'syslogd',
54 $Lang::tr
{'kernel logging server'} => 'klogd',
55 $Lang::tr
{'ntp server'} => 'ntpd',
56 $Lang::tr
{'secure shell server'} => 'sshd',
57 $Lang::tr
{'vpn'} => 'charon',
58 $Lang::tr
{'web proxy'} => 'squid',
59 $Lang::tr
{'intrusion detection system'} => 'suricata',
60 'OpenVPN' => 'openvpn'
64 $Lang::tr
{'dhcp server'} => "<a href=\'dhcp.cgi\'>$Lang::tr{'dhcp server'}</a>",
65 $Lang::tr
{'web server'} => $Lang::tr
{'web server'},
66 $Lang::tr
{'cron server'} => $Lang::tr
{'cron server'},
67 $Lang::tr
{'dns proxy server'} => $Lang::tr
{'dns proxy server'},
68 $Lang::tr
{'logging server'} => $Lang::tr
{'logging server'},
69 $Lang::tr
{'kernel logging server'} => $Lang::tr
{'kernel logging server'},
70 $Lang::tr
{'ntp server'} => "<a href=\'time.cgi\'>$Lang::tr{'ntp server'}</a>",
71 $Lang::tr
{'secure shell server'} => "<a href=\'remote.cgi\'>$Lang::tr{'secure shell server'}</a>",
72 $Lang::tr
{'vpn'} => "<a href=\'vpnmain.cgi\'>$Lang::tr{'vpn'}</a>",
73 $Lang::tr
{'web proxy'} => "<a href=\'proxy.cgi\'>$Lang::tr{'web proxy'}</a>",
74 'OpenVPN' => "<a href=\'ovpnmain.cgi\'>OpenVPN</a>",
75 "$Lang::tr{'intrusion detection system'}" => "<a href=\'ids.cgi\'>$Lang::tr{'intrusion detection system'}</a>",
78 # Hash to overwrite the process name of a process if it differs fromt the launch command.
79 my %overwrite_exename_hash = (
80 "suricata" => "Suricata-Main"
83 my $lines=0; # Used to count the outputlines to make different bgcolor
85 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
86 $querry[0] = '' unless defined $querry[0];
87 $querry[1] = 'hour' unless defined $querry[1];
89 if ( $querry[0] =~ "processescpu"){
90 print "Content-type: image/png\n\n";
92 &Graphs
::updateprocessescpugraph
($querry[1]);
93 }elsif ( $querry[0] =~ "processesmemory"){
94 print "Content-type: image/png\n\n";
96 &Graphs
::updateprocessesmemorygraph
($querry[1]);
98 &Header
::showhttpheaders
();
99 &Header
::openpage
($Lang::tr
{'status information'}, 1, '');
100 &Header
::openbigbox
('100%', 'left');
102 &Header
::openbox
('100%', 'left', $Lang::tr
{'services'});
105 <table width='80%' cellspacing='1' class='tbl'>
107 <th align='left'><b>$Lang::tr{'services'}</b></th>
108 <th align='center' ><b>$Lang::tr{'status'}</b></th>
109 <th align='center'><b>PID</b></th>
110 <th align='center'><b>$Lang::tr{'memory'}</b></th>
116 foreach $key (sort keys %servicenames){
119 $col="bgcolor='$color{'color22'}'";
120 print "<tr><td align='left' $col>";
124 $col="bgcolor='$color{'color20'}'";
125 print "<tr><td align='left' $col>";
130 my $shortname = $servicenames{$key};
131 my $status = &isrunning
($shortname,$col);
137 print "</table></div>\n";
140 &Header
::openbox
('100%', 'left', "Addon - $Lang::tr{services}");
141 my $paramstr=$ENV{QUERY_STRING
};
142 my @param=split(/!/, $paramstr);
143 if ($param[1] ne ''){
144 &General
::system("/usr/local/bin/addonctrl", "$param[0]", "$param[1]");
149 <table width='80%' cellspacing='1' class='tbl'>
151 <th align='center'><b>Addon</b></th>
152 <th align='center'><b>Boot</b></th>
153 <th align='center' colspan=2><b>$Lang::tr{'action'}</b></th>
154 <th align='center'><b>$Lang::tr{'status'}</b></th>
155 <th align='center'><b>PID</b></th>
156 <th align='center'><b>$Lang::tr{'memory'}</b></th>
161 my $lines=0; # Used to count the outputlines to make different bgcolor
163 # Generate list of installed addon pak's
164 opendir (DIR
, "/opt/pakfire/db/installed") || die "Cannot opendir /opt/pakfire/db/installed/: $!";
165 my @pak = sort readdir DIR
;
170 next unless (m/^meta-/);
173 # Check which of the paks are services
174 if (-e
"/etc/init.d/$_") {
175 # blacklist some packages
177 # alsa has trouble with the volume saving and was not really stopped
178 # mdadm should not stopped with webif because this could crash the system
180 if ( $_ eq 'squid' ) {
183 if ( ($_ ne "alsa") && ($_ ne "mdadm") ) {
187 $col="bgcolor='$color{'color22'}'";
190 $col="bgcolor='$color{'color20'}'";
193 print "<td align='left' $col width='31%'>$_</td> ";
194 my $status = isautorun
($_,$col);
196 print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>";
197 print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> ";
198 my $status = &isrunningaddon
($_,$col);
199 $status =~ s/\\e\[[0-1]\;[0-9]+m//g;
208 print "</table></div>\n";
211 &Header
::openbox
('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'graph'}");
212 &Graphs
::makegraphbox
("services.cgi","processescpu","day");
215 &Header
::openbox
('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph'}");
216 &Graphs
::makegraphbox
("services.cgi","processesmemory","day");
219 &Header
::closebigbox
();
220 &Header
::closepage
();
224 my ($cmd, $col) = @_;
227 my $initdir = "/etc/rc.d/rc3.d/";
229 my $status = "<td align='center' $col></td>";
231 # Check if autorun for the given cmd is enabled.
232 if ( &find_init
("$cmd", "$initdir") ) {
234 $status = "<td align='center' $col><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>";
237 $status = "<td align='center' $col><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>";
245 my ($cmd, $dir) = @_;
247 # Open given init directory.
248 opendir (INITDIR
, "$dir") || die "Cannot opendir $dir: $!";
250 # Read-in init files from directory.
251 my @inits = readdir(INITDIR
);
253 # Close directory handle.
256 # Loop through the directory.
257 foreach my $init (@inits) {
258 # Check if the current processed file belongs to the given command.
259 if ($init =~ /S\d+\d+$cmd\z/) {
260 # Found, return "1" - True.
265 # Nothing found, return nothing.
270 my ($cmd, $col) = @_;
271 my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>";
279 # Check if the exename needs to be overwritten.
280 # This happens if the expected process name string
281 # differs from the real one. This may happened if
282 # a service uses multiple processes or threads.
283 if (exists($overwrite_exename_hash{$1})) {
284 # Grab the string which will be reported by
285 # the process from the corresponding hash.
286 $exename = $overwrite_exename_hash{$1};
288 # Directly expect the launched command as
293 if (open(FILE
, "/var/run/${cmd}.pid")){
294 $pid = <FILE
>; chomp $pid;
296 if (open(FILE
, "/proc/${pid}/status")){
298 if (/^Name:\W+(.*)/) {
304 if (open(FILE
, "/proc/${pid}/status")) {
306 my ($key, $val) = split(":", $_, 2);
307 if ($key eq 'VmRSS') {
314 if ($testcmd =~ /$exename/){
315 $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td><td align='center' $col>$pid</td><td align='center' $col>$memory</td>";
321 sub isrunningaddon
(@
) {
322 my ($cmd, $col) = @_;
324 my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>";
330 my @testcmd = &General
::system_output
("/usr/local/bin/addonctrl", "$cmd", "status");
331 my $testcmd = @testcmd[0];
333 if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){
334 $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
335 $testcmd =~ s/.* //gi;
336 $testcmd =~ s/[a-z_]//gi;
337 $testcmd =~ s/\[[0-1]\;[0-9]+//gi;
338 $testcmd =~ s/[\(\)\.]//gi;
340 $testcmd =~ s/\e//gi;
342 my @pid = split(/\s/,$testcmd);
343 $status .="<td align='center' $col>$pid[0]</td>";
349 if (open(FILE
, "/proc/$_/statm")){
351 @memory = split(/ /,$temp);
355 $status .="<td align='center' $col>$memory KB</td>";
357 $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>";