]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/services.cgi
462b6bfa1a14a0c1b8a5f82b7b5ce30c575b72d8
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 no warnings
'experimental';
25 # enable only the following on debugging purpose
27 #use CGI::Carp 'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
32 require "${General::swroot}/graphs.pl";
33 require "/opt/pakfire/lib/functions.pl";
36 my %mainsettings = ();
38 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
39 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
40 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
42 #workaround to suppress a warning when a variable is used only once
43 my @dummy = ( ${Header
::colourred
} );
48 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
49 $querry[0] = '' unless defined $querry[0];
50 $querry[1] = 'hour' unless defined $querry[1];
52 &Header
::showhttpheaders
();
53 &Header
::openpage
($Lang::tr
{'status information'}, 1, '');
54 &Header
::openbigbox
('100%', 'left');
56 &Header
::opensection
();
58 &Header
::ServiceStatus
({
60 $Lang::tr
{'dhcp server'} => {
65 $Lang::tr
{'web server'} => {
70 $Lang::tr
{'cron server'} => {
75 $Lang::tr
{'dns proxy server'} => {
76 "process" => "unbound",
80 $Lang::tr
{'logging server'} => {
81 "process" => "syslogd",
85 $Lang::tr
{'kernel logging server'} => {
90 $Lang::tr
{'ntp server'} => {
95 $Lang::tr
{'secure shell server'} => {
100 $Lang::tr
{'vpn'} => {
101 "process" => "charon",
105 $Lang::tr
{'web proxy'} => {
106 "process" => "squid",
110 $Lang::tr
{'intrusion prevention system'} => {
111 "pidfile" => "/var/run/suricata.pid",
114 # OpenVPN Roadwarrior
115 $Lang::tr
{'ovpn roadwarrior server'} => {
116 "process" => "openvpn",
117 "pidfile" => "/var/run/openvpn.pid",
121 &Header
::closesection
();
123 &Header
::openbox
('100%', 'left', "$Lang::tr{addon} - $Lang::tr{services}");
124 my $paramstr=$ENV{QUERY_STRING
};
125 my @param=split(/!/, $paramstr);
126 # Make sure action parameter is actually one of the allowed service actions
128 when ( ['start', 'stop', 'restart', 'enable', 'disable'] ) {
129 # Make sure pak-name and service name don't contain any illegal character
130 if ( $param[0] !~ /[^a-zA-Z_0-9\-]/ &&
131 $param[2] !~ /[^a-zA-Z_0-9\-]/ ) {
132 &General
::system("/usr/local/bin/addonctrl", "$param[0]", "$param[1]", "$param[2]");
140 <th align='left'><b>$Lang::tr{addon} $Lang::tr{service}</b></th>
141 <th align='center'><b>Boot</b></th>
142 <th align='center' colspan=2><b>$Lang::tr{'action'}</b></th>
143 <th align='center'><b>$Lang::tr{'status'}</b></th>
144 <th align='center'><b>$Lang::tr{'memory'}</b></th>
152 # Generate list of installed addon pak services
153 my %paklist = &Pakfire
::dblist
("installed");
155 foreach my $pak (sort keys %paklist) {
156 my %metadata = &Pakfire
::getmetadata
($pak, "installed");
160 if ("$metadata{'Services'}") {
161 foreach $service (split(/ /, "$metadata{'Services'}")) {
162 # Add addon name to displayname of service if servicename differs from addon
163 my $displayname = ($pak ne $service) ?
"$service ($pak)" : $service;
165 print "<td align='left' width='31%'>$displayname</td> ";
167 my $status = isautorun
($pak,$service);
169 my $status = isrunningaddon
($pak,$service);
170 $status =~ s/\\e\[[0-1]\;[0-9]+m//g;
183 &Header
::closebigbox
();
184 &Header
::closepage
();
187 my ($pak, $service) = @_;
188 my @testcmd = &General
::system_output
("/usr/local/bin/addonctrl", "$pak", "boot-status", "$service");
189 my $testcmd = @testcmd[0];
190 my $status = "<td align='center'><img alt='$Lang::tr{'service boot setting unavailable'}' title='$Lang::tr{'service boot setting unavailable'}' src='/images/dialog-warning.png' border='0' width='16' height='16' /></td>";
192 # Check if autorun for the given service is enabled.
193 if ( $testcmd =~ /enabled\ on\ boot/ ) {
195 $status = "<td align='center'><a href='services.cgi?$pak!disable!$service'><img alt='$Lang::tr{'deactivate'}' title='$Lang::tr{'deactivate'}' src='/images/on.gif' border='0' width='16' height='16' /></a></td>";
196 } elsif ( $testcmd =~ /disabled\ on\ boot/ ) {
198 $status = "<td align='center'><a href='services.cgi?$pak!enable!$service'><img alt='$Lang::tr{'activate'}' title='$Lang::tr{'activate'}' src='/images/off.gif' border='0' width='16' height='16' /></a></td>";
205 sub isrunningaddon
(@
) {
206 my ($pak, $service) = @_;
208 my $status = "<td class='status is-stopped is-fixed'>$Lang::tr{'stopped'}</td><td colspan='2'></td>";
212 my @testcmd = &General
::system_output
("/usr/local/bin/addonctrl", "$pak", "status", "$service");
213 my $testcmd = @testcmd[0];
215 if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){
216 $status = "<td align='center' width='8%'><a href='services.cgi?$pak!stop!$service'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> ";
217 $status .= "<td align='center' width='8%'><a href='services.cgi?$pak!restart!$service'><img alt='$Lang::tr{'restart'}' title='$Lang::tr{'restart'}' src='/images/reload.gif' border='0' /></a></td> ";
218 $status .= "<td class='status is-running'>$Lang::tr{'running'}</td>";
219 $testcmd =~ s/.* //gi;
220 $testcmd =~ s/[a-z_]//gi;
221 $testcmd =~ s/\[[0-1]\;[0-9]+//gi;
222 $testcmd =~ s/[\(\)\.]//gi;
224 $testcmd =~ s/\e//gi;
226 my @pid = split(/\s/,$testcmd);
228 # Fetch the memory consumption
229 my $memory = &General
::get_memory_consumption
(@pid);
232 $memory = &General
::formatBytes
($memory);
234 $status .="<td align='right'>$memory</td>";
236 $status = "<td align='center' width='16%' colspan=2><a href='services.cgi?$pak!start!$service'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>";
237 $status .= "<td class='status is-stopped is-fixed'>$Lang::tr{'stopped'}</td><td colspan='2'></td>";