]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/services.cgi
vulnerabilities.cgi add indirect target selection
[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 #
31c46c07 5# Copyright (C) 2005-2021 IPFire Team #
70df8302
MT
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;
2b9b31b7 23use feature "switch";
4941ce00 24no warnings 'experimental';
2032b6f9 25# enable only the following on debugging purpose
2d281532
CS
26#use warnings;
27#use CGI::Carp 'fatalsToBrowser';
2032b6f9 28
f2fdd0c1 29require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
30require "${General::swroot}/lang.pl";
31require "${General::swroot}/header.pl";
773362c5 32require "${General::swroot}/graphs.pl";
5cc18f9c 33require "/opt/pakfire/lib/functions.pl";
ac1cfefa 34
2032b6f9
CS
35my %color = ();
36my %mainsettings = ();
4e481c3a 37my %netsettings=();
2032b6f9 38&General::readhash("${General::swroot}/main/settings", \%mainsettings);
8186b372 39&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
2032b6f9 40&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
ac1cfefa 41
4e481c3a
CS
42#workaround to suppress a warning when a variable is used only once
43my @dummy = ( ${Header::colourred} );
44undef (@dummy);
45
ac1cfefa 46my %cgiparams=();
2032b6f9 47
4e481c3a
CS
48my @querry = split(/\?/,$ENV{'QUERY_STRING'});
49$querry[0] = '' unless defined $querry[0];
50$querry[1] = 'hour' unless defined $querry[1];
51
4e481c3a
CS
52 &Header::showhttpheaders();
53 &Header::openpage($Lang::tr{'status information'}, 1, '');
54 &Header::openbigbox('100%', 'left');
55
42201c17 56 &Header::opensection();
ac1cfefa 57
bdb8ef8d
MT
58 &Header::ServiceStatus({
59 # DHCP Server
60 $Lang::tr{'dhcp server'} => {
61 "process" => "dhcpd",
62 },
63
64 # Web Server
65 $Lang::tr{'web server'} => {
66 "process" => "httpd",
67 },
68
69 # Cron Server
70 $Lang::tr{'cron server'} => {
71 "process" => "fcron",
72 },
73
74 # DNS Proxy
75 $Lang::tr{'dns proxy server'} => {
76 "process" => "unbound",
77 },
78
79 # Syslog
80 $Lang::tr{'logging server'} => {
81 "process" => "syslogd",
82 },
83
84 # Kernel Logger
85 $Lang::tr{'kernel logging server'} => {
86 "process" => "klogd",
87 },
88
89 # Time Server
90 $Lang::tr{'ntp server'} => {
91 "process" => "ntpd",
92 },
93
94 # SSH Server
95 $Lang::tr{'secure shell server'} => {
96 "process" => "sshd",
97 },
98
99 # IPsec
100 $Lang::tr{'vpn'} => {
101 "process" => "charon",
102 },
103
104 # Web Proxy
105 $Lang::tr{'web proxy'} => {
106 "process" => "squid",
107 },
108
109 # IPS
110 $Lang::tr{'intrusion prevention system'} => {
3fb7849c 111 "pidfile" => "/var/run/suricata.pid",
bdb8ef8d
MT
112 },
113
114 # OpenVPN Roadwarrior
115 $Lang::tr{'ovpn roadwarrior server'} => {
116 "process" => "openvpn",
117 "pidfile" => "/var/run/openvpn.pid",
118 }
119 });
ac1cfefa 120
42201c17 121 &Header::closesection();
ac1cfefa 122
e47370a1 123 &Header::openbox('100%', 'left', "$Lang::tr{addon} - $Lang::tr{services}");
4e481c3a
CS
124 my $paramstr=$ENV{QUERY_STRING};
125 my @param=split(/!/, $paramstr);
2b9b31b7
RR
126 # Make sure action parameter is actually one of the allowed service actions
127 given ($param[1]) {
4f205b54 128 when ( ['start', 'stop', 'restart', 'enable', 'disable'] ) {
2b9b31b7
RR
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]");
133 }
134 }
4e481c3a 135 }
ac1cfefa 136
4e481c3a 137 print <<END
33e76e6e 138<table class='tbl'>
a9d40c03 139<tr>
e47370a1 140 <th align='left'><b>$Lang::tr{addon} $Lang::tr{service}</b></th>
91a81810
AM
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>
91a81810 144 <th align='center'><b>$Lang::tr{'memory'}</b></th>
2032b6f9 145</tr>
ac1cfefa
MT
146END
147;
ac1cfefa 148
5cc18f9c
RR
149 my @paks;
150 my @addon_services;
151
152 # Generate list of installed addon pak services
153 my %paklist = &Pakfire::dblist("installed");
154
207ca114 155 foreach my $pak (sort keys %paklist) {
5cc18f9c 156 my %metadata = &Pakfire::getmetadata($pak, "installed");
bdb8ef8d 157
2b9b31b7
RR
158 my $service;
159
5cc18f9c 160 if ("$metadata{'Services'}") {
2b9b31b7 161 foreach $service (split(/ /, "$metadata{'Services'}")) {
2b9b31b7
RR
162 # Add addon name to displayname of service if servicename differs from addon
163 my $displayname = ($pak ne $service) ? "$service ($pak)" : $service;
8ed99710 164
094b9c66 165 print "<td align='left' width='31%'>$displayname</td> ";
2b9b31b7 166
094b9c66 167 my $status = isautorun($pak,$service);
2b9b31b7 168 print "$status ";
094b9c66 169 my $status = isrunningaddon($pak,$service);
2b9b31b7
RR
170 $status =~ s/\\e\[[0-1]\;[0-9]+m//g;
171
172 chomp($status);
173 print "$status";
174 print "</tr>";
175 }
5cc18f9c 176 }
5cc18f9c
RR
177 }
178
33e76e6e
MT
179 print "</table>\n";
180
4e481c3a 181 &Header::closebox();
ac1cfefa 182
4e481c3a
CS
183 &Header::closebigbox();
184 &Header::closepage();
ac1cfefa 185
f6340997 186sub isautorun (@) {
094b9c66 187 my ($pak, $service) = @_;
2b9b31b7
RR
188 my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$pak", "boot-status", "$service");
189 my $testcmd = @testcmd[0];
094b9c66 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>";
f6340997 191
2b9b31b7
RR
192 # Check if autorun for the given service is enabled.
193 if ( $testcmd =~ /enabled\ on\ boot/ ) {
f6340997 194 # Adjust status.
094b9c66 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>";
2b9b31b7 196 } elsif ( $testcmd =~ /disabled\ on\ boot/ ) {
f6340997 197 # Adjust status.
094b9c66 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>";
ac1cfefa 199 }
773362c5 200
f6340997 201 # Return the status.
4e481c3a 202 return $status;
2032b6f9
CS
203}
204
f6340997 205sub isrunningaddon (@) {
094b9c66 206 my ($pak, $service) = @_;
f6340997 207
397e0c52 208 my $status = "<td class='status is-stopped is-fixed'>$Lang::tr{'stopped'}</td><td colspan='2'></td>";
2032b6f9
CS
209 my $testcmd = '';
210 my $exename;
773362c5 211
2b9b31b7 212 my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$pak", "status", "$service");
31c46c07 213 my $testcmd = @testcmd[0];
ac1cfefa 214
2032b6f9 215 if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){
094b9c66
MT
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> ";
1392ccfe 218 $status .= "<td class='status is-running'>$Lang::tr{'running'}</td>";
7fb1b9f6 219 $testcmd =~ s/.* //gi;
4e481c3a
CS
220 $testcmd =~ s/[a-z_]//gi;
221 $testcmd =~ s/\[[0-1]\;[0-9]+//gi;
222 $testcmd =~ s/[\(\)\.]//gi;
223 $testcmd =~ s/ //gi;
224 $testcmd =~ s/\e//gi;
2032b6f9 225
4e481c3a 226 my @pid = split(/\s/,$testcmd);
773362c5 227
6fa4cdf7
MT
228 # Fetch the memory consumption
229 my $memory = &General::get_memory_consumption(@pid);
773362c5 230
6fa4cdf7
MT
231 # Format memory
232 $memory = &General::formatBytes($memory);
233
234 $status .="<td align='right'>$memory</td>";
4e481c3a 235 }else{
094b9c66 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>";
397e0c52 237 $status .= "<td class='status is-stopped is-fixed'>$Lang::tr{'stopped'}</td><td colspan='2'></td>";
ac1cfefa 238 }
4e481c3a 239 return $status;
ac1cfefa 240}