]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/services.cgi
462b6bfa1a14a0c1b8a5f82b7b5ce30c575b72d8
[ipfire-2.x.git] / html / cgi-bin / services.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2021 IPFire Team #
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 ###############################################################################
21
22 use strict;
23 use feature "switch";
24 no warnings 'experimental';
25 # enable only the following on debugging purpose
26 #use warnings;
27 #use CGI::Carp 'fatalsToBrowser';
28
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";
34
35 my %color = ();
36 my %mainsettings = ();
37 my %netsettings=();
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);
41
42 #workaround to suppress a warning when a variable is used only once
43 my @dummy = ( ${Header::colourred} );
44 undef (@dummy);
45
46 my %cgiparams=();
47
48 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
49 $querry[0] = '' unless defined $querry[0];
50 $querry[1] = 'hour' unless defined $querry[1];
51
52 &Header::showhttpheaders();
53 &Header::openpage($Lang::tr{'status information'}, 1, '');
54 &Header::openbigbox('100%', 'left');
55
56 &Header::opensection();
57
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'} => {
111 "pidfile" => "/var/run/suricata.pid",
112 },
113
114 # OpenVPN Roadwarrior
115 $Lang::tr{'ovpn roadwarrior server'} => {
116 "process" => "openvpn",
117 "pidfile" => "/var/run/openvpn.pid",
118 }
119 });
120
121 &Header::closesection();
122
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
127 given ($param[1]) {
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]");
133 }
134 }
135 }
136
137 print <<END
138 <table class='tbl'>
139 <tr>
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>
145 </tr>
146 END
147 ;
148
149 my @paks;
150 my @addon_services;
151
152 # Generate list of installed addon pak services
153 my %paklist = &Pakfire::dblist("installed");
154
155 foreach my $pak (sort keys %paklist) {
156 my %metadata = &Pakfire::getmetadata($pak, "installed");
157
158 my $service;
159
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;
164
165 print "<td align='left' width='31%'>$displayname</td> ";
166
167 my $status = isautorun($pak,$service);
168 print "$status ";
169 my $status = isrunningaddon($pak,$service);
170 $status =~ s/\\e\[[0-1]\;[0-9]+m//g;
171
172 chomp($status);
173 print "$status";
174 print "</tr>";
175 }
176 }
177 }
178
179 print "</table>\n";
180
181 &Header::closebox();
182
183 &Header::closebigbox();
184 &Header::closepage();
185
186 sub isautorun (@) {
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>";
191
192 # Check if autorun for the given service is enabled.
193 if ( $testcmd =~ /enabled\ on\ boot/ ) {
194 # Adjust status.
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/ ) {
197 # Adjust status.
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>";
199 }
200
201 # Return the status.
202 return $status;
203 }
204
205 sub isrunningaddon (@) {
206 my ($pak, $service) = @_;
207
208 my $status = "<td class='status is-stopped is-fixed'>$Lang::tr{'stopped'}</td><td colspan='2'></td>";
209 my $testcmd = '';
210 my $exename;
211
212 my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$pak", "status", "$service");
213 my $testcmd = @testcmd[0];
214
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;
223 $testcmd =~ s/ //gi;
224 $testcmd =~ s/\e//gi;
225
226 my @pid = split(/\s/,$testcmd);
227
228 # Fetch the memory consumption
229 my $memory = &General::get_memory_consumption(@pid);
230
231 # Format memory
232 $memory = &General::formatBytes($memory);
233
234 $status .="<td align='right'>$memory</td>";
235 }else{
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>";
238 }
239 return $status;
240 }