1 |
c83068f6
|
Colin Smith
|
<?php
|
2 |
|
|
/****h* pfSense/service-utils
|
3 |
|
|
* NAME
|
4 |
|
|
* service-utils.inc - Service facility
|
5 |
|
|
* DESCRIPTION
|
6 |
|
|
* This file contains various functions used by the pfSense service facility.
|
7 |
|
|
* HISTORY
|
8 |
|
|
* $Id$
|
9 |
|
|
******
|
10 |
|
|
*
|
11 |
0e16b9ca
|
Scott Ullrich
|
* Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
|
12 |
c83068f6
|
Colin Smith
|
* All rights reserved.
|
13 |
|
|
* Redistribution and use in source and binary forms, with or without
|
14 |
|
|
* modification, are permitted provided that the following conditions are met:
|
15 |
|
|
*
|
16 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
17 |
|
|
* this list of conditions and the following disclaimer.
|
18 |
|
|
*
|
19 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
20 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
21 |
|
|
* documentation and/or other materials provided with the distribution.
|
22 |
|
|
*
|
23 |
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24 |
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25 |
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26 |
|
|
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27 |
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28 |
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31 |
|
|
* RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32 |
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
33 |
|
|
*
|
34 |
|
|
*/
|
35 |
|
|
|
36 |
523855b0
|
Scott Ullrich
|
/*
|
37 |
05c4bfa0
|
Ermal
|
pfSense_BUILDER_BINARIES: /bin/pgrep /bin/sh /usr/bin/killall
|
38 |
523855b0
|
Scott Ullrich
|
pfSense_MODULE: utils
|
39 |
|
|
*/
|
40 |
ab1cf455
|
jim-p
|
require_once("globals.inc");
|
41 |
ee6e6011
|
jim-p
|
require_once("captiveportal.inc");
|
42 |
|
|
require_once("openvpn.inc");
|
43 |
|
|
require_once("ipsec.inc");
|
44 |
|
|
require_once("vpn.inc");
|
45 |
|
|
require_once("vslb.inc");
|
46 |
b05a8f35
|
jim-p
|
require_once("gwlb.inc");
|
47 |
523855b0
|
Scott Ullrich
|
|
48 |
e9d66ed4
|
phildd
|
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
|
49 |
c83068f6
|
Colin Smith
|
function write_rcfile($params) {
|
50 |
c2151973
|
Ermal
|
global $g;
|
51 |
af799b48
|
Renato Botelho
|
|
52 |
6f931ad2
|
Phil Davis
|
safe_mkdir(RCFILEPREFIX);
|
53 |
e9d66ed4
|
phildd
|
$rcfile_fullname = RCFILEPREFIX . $params['file'];
|
54 |
5e5c72be
|
Frank Wall
|
if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname))
|
55 |
af799b48
|
Renato Botelho
|
return false;
|
56 |
c2151973
|
Ermal
|
|
57 |
e9d66ed4
|
phildd
|
if (!is_writable($rcfile_fullname) || empty($params['start']))
|
58 |
ba8495f0
|
Ermal
|
return false;
|
59 |
af799b48
|
Renato Botelho
|
|
60 |
ba8495f0
|
Ermal
|
$towrite = "#!/bin/sh\n";
|
61 |
4dddf8c3
|
Warren Baker
|
$towrite .= "# This file was automatically generated\n# by the {$g['product_name']} service handler.\n\n";
|
62 |
ba8495f0
|
Ermal
|
|
63 |
c83068f6
|
Colin Smith
|
/* write our rc functions */
|
64 |
ba8495f0
|
Ermal
|
$towrite .= "rc_start() {\n";
|
65 |
|
|
$towrite .= "\t{$params['start']}\n";
|
66 |
|
|
$towrite .= "}\n\n";
|
67 |
|
|
if(!empty($params['stop'])) {
|
68 |
c83068f6
|
Colin Smith
|
$tokill =& $params['stop'];
|
69 |
ba8495f0
|
Ermal
|
} else if(!empty($params['executable'])) {
|
70 |
a8dbad89
|
Colin Smith
|
/* just nuke the executable */
|
71 |
873c1701
|
Renato Botelho
|
$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
|
72 |
c83068f6
|
Colin Smith
|
} else {
|
73 |
a8dbad89
|
Colin Smith
|
/* make an educated guess (bad) */
|
74 |
c83068f6
|
Colin Smith
|
$tokill = array_pop(explode('/', array_shift(explode(' ', $params['start']))));
|
75 |
|
|
}
|
76 |
ba8495f0
|
Ermal
|
$towrite .= "rc_stop() {\n";
|
77 |
|
|
$towrite .= "\t{$tokill}\n";
|
78 |
|
|
$towrite .= "}\n\n";
|
79 |
4685e464
|
Scott Ullrich
|
|
80 |
c83068f6
|
Colin Smith
|
/* begin rcfile logic */
|
81 |
ba8495f0
|
Ermal
|
$towrite .= "case \$1 in\n\tstart)\n\t\trc_start\n\t\t;;\n\tstop)\n\t\trc_stop\n\t\t;;\n\trestart)\n\t\trc_stop\n\t\trc_start\n\t\t;;\nesac\n\n";
|
82 |
|
|
|
83 |
44b19298
|
Ermal
|
@file_put_contents($rcfile_fullname, $towrite);
|
84 |
|
|
unset($towrite);
|
85 |
e9d66ed4
|
phildd
|
@chmod("{$rcfile_fullname}", 0755);
|
86 |
ba8495f0
|
Ermal
|
|
87 |
c83068f6
|
Colin Smith
|
return;
|
88 |
|
|
}
|
89 |
31f346a8
|
Colin Smith
|
|
90 |
58826c73
|
Colin Smith
|
function start_service($name) {
|
91 |
669e1adb
|
Bill Marquette
|
global $config;
|
92 |
ba8495f0
|
Ermal
|
|
93 |
b27ade8e
|
Ermal
|
if (empty($name))
|
94 |
|
|
return;
|
95 |
|
|
|
96 |
44b19298
|
Ermal
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
|
97 |
31f346a8
|
Colin Smith
|
foreach($config['installedpackages']['service'] as $service) {
|
98 |
a8dbad89
|
Colin Smith
|
if(strtolower($service['name']) == strtolower($name)) {
|
99 |
31f346a8
|
Colin Smith
|
if($service['rcfile']) {
|
100 |
e9d66ed4
|
phildd
|
$prefix = RCFILEPREFIX;
|
101 |
ba8495f0
|
Ermal
|
if (!empty($service['prefix'])) {
|
102 |
31f346a8
|
Colin Smith
|
$prefix =& $service['prefix'];
|
103 |
|
|
}
|
104 |
5e5c72be
|
Frank Wall
|
if(file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
|
105 |
ba8495f0
|
Ermal
|
mwexec_bg("{$prefix}{$service['rcfile']} start");
|
106 |
a4ea3340
|
Scott Ullrich
|
}
|
107 |
31f346a8
|
Colin Smith
|
}
|
108 |
ba8495f0
|
Ermal
|
if (!empty($service['startcmd']))
|
109 |
31f346a8
|
Colin Smith
|
eval($service['startcmd']);
|
110 |
|
|
break;
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
|
|
|
116 |
58826c73
|
Colin Smith
|
function stop_service($name) {
|
117 |
cd72ded3
|
Timo Boettcher
|
global $config;
|
118 |
246a887a
|
Ermal
|
|
119 |
8bf2e9e5
|
Ermal
|
if (empty($name))
|
120 |
|
|
return;
|
121 |
|
|
|
122 |
b4d772dc
|
Ermal Luçi
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
|
123 |
cd72ded3
|
Timo Boettcher
|
foreach($config['installedpackages']['service'] as $service) {
|
124 |
|
|
if(strtolower($service['name']) == strtolower($name)) {
|
125 |
|
|
if($service['rcfile']) {
|
126 |
e9d66ed4
|
phildd
|
$prefix = RCFILEPREFIX;
|
127 |
ba8495f0
|
Ermal
|
if(!empty($service['prefix'])) {
|
128 |
cd72ded3
|
Timo Boettcher
|
$prefix =& $service['prefix'];
|
129 |
|
|
}
|
130 |
5e5c72be
|
Frank Wall
|
if(file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
|
131 |
6ae78f08
|
Marcello Coutinho
|
mwexec("{$prefix}{$service['rcfile']} stop");
|
132 |
098820e2
|
Ermal
|
}
|
133 |
|
|
return;
|
134 |
cd72ded3
|
Timo Boettcher
|
}
|
135 |
ba8495f0
|
Ermal
|
if (!empty($service['stopcmd']))
|
136 |
cd72ded3
|
Timo Boettcher
|
eval($service['stopcmd']);
|
137 |
ba8495f0
|
Ermal
|
|
138 |
cd72ded3
|
Timo Boettcher
|
break;
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
31f346a8
|
Colin Smith
|
}
|
143 |
|
|
|
144 |
58826c73
|
Colin Smith
|
function restart_service($name) {
|
145 |
cd72ded3
|
Timo Boettcher
|
global $config;
|
146 |
ba8495f0
|
Ermal
|
|
147 |
8bf2e9e5
|
Ermal
|
if (empty($name))
|
148 |
|
|
return;
|
149 |
|
|
|
150 |
636ab238
|
Colin Smith
|
stop_service($name);
|
151 |
|
|
start_service($name);
|
152 |
ba8495f0
|
Ermal
|
|
153 |
b4d772dc
|
Ermal Luçi
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
|
154 |
cd72ded3
|
Timo Boettcher
|
foreach($config['installedpackages']['service'] as $service) {
|
155 |
|
|
if(strtolower($service['name']) == strtolower($name)) {
|
156 |
|
|
if($service['restartcmd']) {
|
157 |
|
|
eval($service['restartcmd']);
|
158 |
|
|
}
|
159 |
|
|
break;
|
160 |
|
|
}
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
31f346a8
|
Colin Smith
|
}
|
164 |
ec4e071a
|
Colin Smith
|
|
165 |
cd72ded3
|
Timo Boettcher
|
function is_pid_running($pidfile) {
|
166 |
ba8495f0
|
Ermal
|
if (!file_exists($pidfile))
|
167 |
|
|
return false;
|
168 |
|
|
|
169 |
17098641
|
Ermal
|
return (isvalidpid($pidfile));
|
170 |
cd72ded3
|
Timo Boettcher
|
}
|
171 |
|
|
|
172 |
8ff8520f
|
Scott Ullrich
|
function is_dhcp_running($interface) {
|
173 |
fda8dc28
|
Seth Mos
|
$status = find_dhclient_process($interface);
|
174 |
397e40d5
|
Renato Botelho
|
if($status != 0)
|
175 |
ca88e48f
|
Scott Ullrich
|
return true;
|
176 |
|
|
return false;
|
177 |
8ff8520f
|
Scott Ullrich
|
}
|
178 |
|
|
|
179 |
0661a033
|
Colin Smith
|
function restart_service_if_running($service) {
|
180 |
|
|
global $config;
|
181 |
4685e464
|
Scott Ullrich
|
if(is_service_running($service))
|
182 |
0661a033
|
Colin Smith
|
restart_service($service);
|
183 |
|
|
return;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
ccfc0269
|
phildd
|
function is_service_enabled($service_name) {
|
187 |
|
|
global $config;
|
188 |
|
|
if ($service_name == "")
|
189 |
|
|
return false;
|
190 |
762e8cf9
|
jim-p
|
if (is_array($config['installedpackages'])) {
|
191 |
|
|
if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
|
192 |
|
|
((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
|
193 |
|
|
($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
|
194 |
|
|
return false;
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
ccfc0269
|
phildd
|
return true;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
fbeb6d02
|
Colin Smith
|
function is_service_running($service, $ps = "") {
|
201 |
|
|
global $config;
|
202 |
ba8495f0
|
Ermal
|
|
203 |
c2b6723a
|
Scott Ullrich
|
if(is_array($config['installedpackages']['service'])) {
|
204 |
cd72ded3
|
Timo Boettcher
|
foreach($config['installedpackages']['service'] as $aservice) {
|
205 |
|
|
if(strtolower($service) == strtolower($aservice['name'])) {
|
206 |
ba8495f0
|
Ermal
|
if ($aservice['custom_php_service_status_command'] <> "") {
|
207 |
|
|
eval("\$rc={$aservice['custom_php_service_status_command']};");
|
208 |
c2d49311
|
Eirik Oeverby
|
return $rc;
|
209 |
|
|
}
|
210 |
ba8495f0
|
Ermal
|
if(empty($aservice['executable']))
|
211 |
ec4e071a
|
Colin Smith
|
return false;
|
212 |
ba8495f0
|
Ermal
|
if (is_process_running($aservice['executable']))
|
213 |
|
|
return true;
|
214 |
|
|
|
215 |
|
|
return false;
|
216 |
cd72ded3
|
Timo Boettcher
|
}
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
ba8495f0
|
Ermal
|
|
220 |
|
|
if (is_process_running($service))
|
221 |
|
|
return true;
|
222 |
|
|
|
223 |
|
|
return false;
|
224 |
ec4e071a
|
Colin Smith
|
}
|
225 |
ff074bf9
|
Scott Ullrich
|
|
226 |
e48cdc01
|
jim-p
|
function get_services() {
|
227 |
|
|
global $config;
|
228 |
|
|
if (is_array($config['installedpackages']['service']))
|
229 |
|
|
$services = $config['installedpackages']['service'];
|
230 |
|
|
else
|
231 |
|
|
$services = array();
|
232 |
|
|
|
233 |
|
|
/* Add services that are in the base.
|
234 |
|
|
*
|
235 |
|
|
*/
|
236 |
33232486
|
Warren Baker
|
if (is_radvd_enabled()) {
|
237 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
238 |
|
|
$pconfig['name'] = "radvd";
|
239 |
|
|
$pconfig['description'] = gettext("Router Advertisement Daemon");
|
240 |
|
|
$services[] = $pconfig;
|
241 |
|
|
}
|
242 |
|
|
|
243 |
33232486
|
Warren Baker
|
if (isset($config['dnsmasq']['enable'])) {
|
244 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
245 |
|
|
$pconfig['name'] = "dnsmasq";
|
246 |
|
|
$pconfig['description'] = gettext("DNS Forwarder");
|
247 |
|
|
$services[] = $pconfig;
|
248 |
|
|
}
|
249 |
|
|
|
250 |
33232486
|
Warren Baker
|
if (isset($config['unbound']['enable'])) {
|
251 |
|
|
$pconfig = array();
|
252 |
|
|
$pconfig['name'] = "unbound";
|
253 |
6c101e32
|
jim-p
|
$pconfig['description'] = gettext("Unbound DNS Resolver");
|
254 |
33232486
|
Warren Baker
|
$services[] = $pconfig;
|
255 |
|
|
}
|
256 |
|
|
|
257 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
258 |
|
|
$pconfig['name'] = "ntpd";
|
259 |
|
|
$pconfig['description'] = gettext("NTP clock sync");
|
260 |
|
|
$services[] = $pconfig;
|
261 |
|
|
|
262 |
|
|
if (is_array($config['captiveportal'])) {
|
263 |
|
|
foreach ($config['captiveportal'] as $zone => $setting) {
|
264 |
|
|
if (isset($setting['enable'])) {
|
265 |
|
|
$pconfig = array();
|
266 |
|
|
$pconfig['name'] = "captiveportal";
|
267 |
|
|
$pconfig['zone'] = $zone;
|
268 |
|
|
$pconfig['description'] = gettext("Captive Portal") . ": ".htmlspecialchars($setting['zone']);
|
269 |
|
|
$services[] = $pconfig;
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
$iflist = array();
|
275 |
|
|
$ifdescrs = get_configured_interface_list();
|
276 |
|
|
foreach ($ifdescrs as $if) {
|
277 |
|
|
$oc = $config['interfaces'][$if];
|
278 |
|
|
if ($oc['if'] && (!link_interface_to_bridge($if)))
|
279 |
|
|
$iflist[$if] = $if;
|
280 |
|
|
}
|
281 |
|
|
|
282 |
33232486
|
Warren Baker
|
if (isset($config['dhcrelay']['enable'])) {
|
283 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
284 |
|
|
$pconfig['name'] = "dhcrelay";
|
285 |
|
|
$pconfig['description'] = gettext("DHCP Relay");
|
286 |
|
|
$services[] = $pconfig;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
33232486
|
Warren Baker
|
if (isset($config['dhcrelay6']['enable'])) {
|
290 |
9590e0de
|
Phil Davis
|
$pconfig = array();
|
291 |
|
|
$pconfig['name'] = "dhcrelay6";
|
292 |
|
|
$pconfig['description'] = gettext("DHCPv6 Relay");
|
293 |
|
|
$services[] = $pconfig;
|
294 |
|
|
}
|
295 |
|
|
|
296 |
33232486
|
Warren Baker
|
if (is_dhcp_server_enabled()) {
|
297 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
298 |
|
|
$pconfig['name'] = "dhcpd";
|
299 |
|
|
$pconfig['description'] = gettext("DHCP Service");
|
300 |
|
|
$services[] = $pconfig;
|
301 |
|
|
}
|
302 |
|
|
|
303 |
b05a8f35
|
jim-p
|
$gateways_arr = return_gateways_array();
|
304 |
|
|
if (is_array($gateways_arr)) {
|
305 |
|
|
$pconfig = array();
|
306 |
|
|
$pconfig['name'] = "apinger";
|
307 |
|
|
$pconfig['description'] = gettext("Gateway Monitoring Daemon");
|
308 |
|
|
$services[] = $pconfig;
|
309 |
|
|
}
|
310 |
|
|
|
311 |
33232486
|
Warren Baker
|
if (isset($config['snmpd']['enable'])) {
|
312 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
313 |
|
|
$pconfig['name'] = "bsnmpd";
|
314 |
|
|
$pconfig['description'] = gettext("SNMP Service");
|
315 |
|
|
$services[] = $pconfig;
|
316 |
|
|
}
|
317 |
|
|
|
318 |
|
|
if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
|
319 |
|
|
$pconfig = array();
|
320 |
|
|
$pconfig['name'] = "igmpproxy";
|
321 |
|
|
$pconfig['description'] = gettext("IGMP proxy");
|
322 |
|
|
$services[] = $pconfig;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
|
326 |
|
|
$pconfig = array();
|
327 |
|
|
$pconfig['name'] = "miniupnpd";
|
328 |
|
|
$pconfig['description'] = gettext("UPnP Service");
|
329 |
|
|
$services[] = $pconfig;
|
330 |
|
|
}
|
331 |
|
|
|
332 |
d71fc5d3
|
jim-p
|
if (isset($config['installedpackages']['routed']) && $config['installedpackages']['routed']['config'][0]['enable']) {
|
333 |
|
|
$pconfig = array();
|
334 |
|
|
$pconfig['name'] = "routed";
|
335 |
|
|
$pconfig['description'] = gettext("RIP Daemon");
|
336 |
|
|
$services[] = $pconfig;
|
337 |
|
|
}
|
338 |
|
|
|
339 |
e48cdc01
|
jim-p
|
if (isset($config['ipsec']['enable'])) {
|
340 |
|
|
$pconfig = array();
|
341 |
8b4abd59
|
Ermal
|
$pconfig['name'] = "ipsec";
|
342 |
e48cdc01
|
jim-p
|
$pconfig['description'] = gettext("IPsec VPN");
|
343 |
|
|
$services[] = $pconfig;
|
344 |
|
|
}
|
345 |
|
|
|
346 |
aaa78416
|
jim-p
|
if (isset($config['system']['enablesshd'])) {
|
347 |
|
|
$pconfig = array();
|
348 |
|
|
$pconfig['name'] = "sshd";
|
349 |
|
|
$pconfig['description'] = gettext("Secure Shell Daemon");
|
350 |
|
|
$services[] = $pconfig;
|
351 |
|
|
}
|
352 |
|
|
|
353 |
e48cdc01
|
jim-p
|
foreach (array('server', 'client') as $mode) {
|
354 |
|
|
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
|
355 |
|
|
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
|
356 |
|
|
if (!isset($setting['disable'])) {
|
357 |
|
|
$pconfig = array();
|
358 |
|
|
$pconfig['name'] = "openvpn";
|
359 |
|
|
$pconfig['mode'] = $mode;
|
360 |
|
|
$pconfig['id'] = $id;
|
361 |
|
|
$pconfig['vpnid'] = $setting['vpnid'];
|
362 |
|
|
$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
|
363 |
|
|
$services[] = $pconfig;
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
}
|
367 |
|
|
}
|
368 |
|
|
|
369 |
|
|
if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
|
370 |
|
|
$pconfig = array();
|
371 |
|
|
$pconfig['name'] = "relayd";
|
372 |
|
|
$pconfig['description'] = gettext("Server load balancing daemon");
|
373 |
|
|
$services[] = $pconfig;
|
374 |
|
|
}
|
375 |
|
|
return $services;
|
376 |
|
|
}
|
377 |
|
|
|
378 |
76692ad2
|
jim-p
|
function find_service_by_name($name) {
|
379 |
|
|
$services = get_services();
|
380 |
|
|
foreach ($services as $service)
|
381 |
|
|
if ($service["name"] == $name)
|
382 |
|
|
return $service;
|
383 |
|
|
return array();
|
384 |
|
|
}
|
385 |
|
|
|
386 |
6d9b1074
|
jim-p
|
function find_service_by_openvpn_vpnid($vpnid) {
|
387 |
|
|
$services = get_services();
|
388 |
|
|
foreach ($services as $service)
|
389 |
d583aa71
|
jim-p
|
if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid))
|
390 |
6d9b1074
|
jim-p
|
return $service;
|
391 |
|
|
return array();
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
function find_service_by_cp_zone($zone) {
|
395 |
|
|
$services = get_services();
|
396 |
|
|
foreach ($services as $service)
|
397 |
d583aa71
|
jim-p
|
if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone))
|
398 |
6d9b1074
|
jim-p
|
return $service;
|
399 |
|
|
return array();
|
400 |
|
|
}
|
401 |
|
|
|
402 |
e48cdc01
|
jim-p
|
function service_name_compare($a, $b) {
|
403 |
|
|
if (strtolower($a['name']) == strtolower($b['name']))
|
404 |
|
|
return 0;
|
405 |
|
|
return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
function get_pkg_descr($package_name) {
|
409 |
|
|
global $config;
|
410 |
|
|
if (is_array($config['installedpackages']['package'])) {
|
411 |
|
|
foreach($config['installedpackages']['package'] as $pkg) {
|
412 |
|
|
if($pkg['name'] == $package_name)
|
413 |
|
|
return $pkg['descr'];
|
414 |
|
|
}
|
415 |
|
|
}
|
416 |
|
|
return gettext("Not available.");
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
function get_service_status($service) {
|
420 |
|
|
global $g;
|
421 |
|
|
switch ($service['name']) {
|
422 |
|
|
case "openvpn":
|
423 |
|
|
$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
|
424 |
|
|
break;
|
425 |
|
|
case "captiveportal":
|
426 |
|
|
$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
|
427 |
|
|
if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
|
428 |
|
|
$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
|
429 |
|
|
break;
|
430 |
18725085
|
Ermal
|
case "vhosts-http":
|
431 |
|
|
$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
|
432 |
|
|
break;
|
433 |
9590e0de
|
Phil Davis
|
case "dhcrelay6":
|
434 |
|
|
$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
|
435 |
|
|
break;
|
436 |
e381cc01
|
Ermal
|
case 'ipsec':
|
437 |
|
|
$running = is_pid_running("{$g['varrun_path']}/charon.pid");
|
438 |
|
|
break;
|
439 |
e48cdc01
|
jim-p
|
default:
|
440 |
|
|
$running = is_service_running($service['name']);
|
441 |
|
|
}
|
442 |
|
|
return $running;
|
443 |
|
|
}
|
444 |
|
|
|
445 |
36d1c798
|
jim-p
|
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
|
446 |
e48cdc01
|
jim-p
|
global $g;
|
447 |
|
|
$output = "";
|
448 |
|
|
if(get_service_status($service)) {
|
449 |
92421710
|
jim-p
|
$statustext = gettext("Running");
|
450 |
36d1c798
|
jim-p
|
$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
|
451 |
|
|
$output .= ($smallicon) ? "icon_pass.gif" : "icon_service_running.gif";
|
452 |
17b8c60a
|
Colin Fleming
|
$output .= "\" alt=\"status\" /> ";
|
453 |
e48cdc01
|
jim-p
|
if ($withtext)
|
454 |
17b8c60a
|
Colin Fleming
|
$output .= " " . $statustext;
|
455 |
e48cdc01
|
jim-p
|
} else {
|
456 |
ccfc0269
|
phildd
|
$service_enabled = is_service_enabled($service['name']);
|
457 |
|
|
$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
|
458 |
36d1c798
|
jim-p
|
$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
|
459 |
|
|
$output .= ($smallicon) ? "icon_block.gif" : "icon_service_stopped.gif";
|
460 |
17b8c60a
|
Colin Fleming
|
$output .= "\" alt=\"status\" /> ";
|
461 |
e48cdc01
|
jim-p
|
if ($withtext)
|
462 |
17b8c60a
|
Colin Fleming
|
$output .= " <font color=\"white\">{$statustext}</font>";
|
463 |
e48cdc01
|
jim-p
|
}
|
464 |
|
|
return $output;
|
465 |
|
|
}
|
466 |
|
|
|
467 |
f4daf025
|
jim-p
|
function get_service_control_links($service, $addname = false) {
|
468 |
e48cdc01
|
jim-p
|
global $g;
|
469 |
|
|
$output = "";
|
470 |
f4daf025
|
jim-p
|
$stitle = ($addname) ? $service['name'] . " " : "";
|
471 |
e48cdc01
|
jim-p
|
if(get_service_status($service)) {
|
472 |
|
|
switch ($service['name']) {
|
473 |
|
|
case "openvpn":
|
474 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
|
475 |
e48cdc01
|
jim-p
|
break;
|
476 |
|
|
case "captiveportal":
|
477 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=restartservice&service={$service['name']}&zone={$service['zone']}'>";
|
478 |
e48cdc01
|
jim-p
|
break;
|
479 |
|
|
default:
|
480 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
|
481 |
e48cdc01
|
jim-p
|
}
|
482 |
bb877f44
|
Colin Fleming
|
$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Restart %sService"),$stitle) . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif' alt='restart' /></a>\n";
|
483 |
e48cdc01
|
jim-p
|
switch ($service['name']) {
|
484 |
|
|
case "openvpn":
|
485 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
|
486 |
e48cdc01
|
jim-p
|
break;
|
487 |
|
|
case "captiveportal":
|
488 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=stopservice&service={$service['name']}&zone={$service['zone']}'>";
|
489 |
e48cdc01
|
jim-p
|
break;
|
490 |
|
|
default:
|
491 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
|
492 |
e48cdc01
|
jim-p
|
}
|
493 |
bb877f44
|
Colin Fleming
|
$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Stop %sService"),$stitle) . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif' alt='stop' />";
|
494 |
e48cdc01
|
jim-p
|
$output .= "</a>";
|
495 |
|
|
} else {
|
496 |
ccfc0269
|
phildd
|
$service_enabled = is_service_enabled($service['name']);
|
497 |
e48cdc01
|
jim-p
|
switch ($service['name']) {
|
498 |
|
|
case "openvpn":
|
499 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
|
500 |
e48cdc01
|
jim-p
|
break;
|
501 |
|
|
case "captiveportal":
|
502 |
bb877f44
|
Colin Fleming
|
$output .= "<a href='status_services.php?mode=startservice&service={$service['name']}&zone={$service['zone']}'>";
|
503 |
e48cdc01
|
jim-p
|
break;
|
504 |
|
|
default:
|
505 |
ccfc0269
|
phildd
|
if ($service_enabled)
|
506 |
|
|
$output .= "<a href='status_services.php?mode=startservice&service={$service['name']}'>";
|
507 |
e48cdc01
|
jim-p
|
}
|
508 |
ccfc0269
|
phildd
|
if ($service_enabled)
|
509 |
|
|
$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Start %sService"),$stitle) . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif' alt='start' /></a>\n";
|
510 |
e48cdc01
|
jim-p
|
}
|
511 |
|
|
return $output;
|
512 |
|
|
}
|
513 |
ee6e6011
|
jim-p
|
|
514 |
|
|
function service_control_start($name, $extras) {
|
515 |
|
|
global $g;
|
516 |
|
|
switch($name) {
|
517 |
|
|
case 'radvd':
|
518 |
|
|
services_radvd_configure();
|
519 |
|
|
break;
|
520 |
|
|
case 'captiveportal':
|
521 |
2f9951fe
|
Renato Botelho
|
$zone = htmlspecialchars($extras['zone']);
|
522 |
ee6e6011
|
jim-p
|
captiveportal_init_webgui_zonename($zone);
|
523 |
|
|
break;
|
524 |
|
|
case 'ntpd':
|
525 |
|
|
case 'openntpd':
|
526 |
|
|
system_ntp_configure();
|
527 |
|
|
break;
|
528 |
b05a8f35
|
jim-p
|
case 'apinger':
|
529 |
|
|
setup_gateways_monitor();
|
530 |
|
|
break;
|
531 |
ee6e6011
|
jim-p
|
case 'bsnmpd':
|
532 |
|
|
services_snmpd_configure();
|
533 |
|
|
break;
|
534 |
9590e0de
|
Phil Davis
|
case 'dhcrelay':
|
535 |
|
|
services_dhcrelay_configure();
|
536 |
|
|
break;
|
537 |
|
|
case 'dhcrelay6':
|
538 |
|
|
services_dhcrelay6_configure();
|
539 |
|
|
break;
|
540 |
ee6e6011
|
jim-p
|
case 'dnsmasq':
|
541 |
|
|
services_dnsmasq_configure();
|
542 |
|
|
break;
|
543 |
a8604dc6
|
Phil Davis
|
case 'unbound':
|
544 |
|
|
services_unbound_configure();
|
545 |
|
|
break;
|
546 |
ee6e6011
|
jim-p
|
case 'dhcpd':
|
547 |
|
|
services_dhcpd_configure();
|
548 |
|
|
break;
|
549 |
|
|
case 'igmpproxy':
|
550 |
|
|
services_igmpproxy_configure();
|
551 |
|
|
break;
|
552 |
|
|
case 'miniupnpd':
|
553 |
|
|
upnp_action('start');
|
554 |
|
|
break;
|
555 |
8b4abd59
|
Ermal
|
case 'ipsec':
|
556 |
ee6e6011
|
jim-p
|
vpn_ipsec_force_reload();
|
557 |
|
|
break;
|
558 |
aaa78416
|
jim-p
|
case 'sshd':
|
559 |
|
|
send_event("service restart sshd");
|
560 |
|
|
break;
|
561 |
ee6e6011
|
jim-p
|
case 'openvpn':
|
562 |
2f9951fe
|
Renato Botelho
|
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
|
563 |
ee6e6011
|
jim-p
|
if (($vpnmode == "server") || ($vpnmode == "client")) {
|
564 |
2f9951fe
|
Renato Botelho
|
$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
|
565 |
ee6e6011
|
jim-p
|
$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
|
566 |
|
|
if (file_exists($configfile))
|
567 |
|
|
openvpn_restart_by_vpnid($vpnmode, $id);
|
568 |
|
|
}
|
569 |
|
|
break;
|
570 |
|
|
case 'relayd':
|
571 |
|
|
relayd_configure();
|
572 |
|
|
break;
|
573 |
|
|
default:
|
574 |
|
|
start_service($name);
|
575 |
|
|
break;
|
576 |
|
|
}
|
577 |
|
|
return sprintf(gettext("%s has been started."),htmlspecialchars($name));
|
578 |
|
|
}
|
579 |
|
|
function service_control_stop($name, $extras) {
|
580 |
|
|
global $g;
|
581 |
|
|
switch($name) {
|
582 |
|
|
case 'radvd':
|
583 |
|
|
killbypid("{$g['varrun_path']}/radvd.pid");
|
584 |
|
|
break;
|
585 |
|
|
case 'captiveportal':
|
586 |
2f9951fe
|
Renato Botelho
|
$zone = htmlspecialchars($extras['zone']);
|
587 |
ee6e6011
|
jim-p
|
killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
|
588 |
|
|
killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
|
589 |
|
|
break;
|
590 |
|
|
case 'ntpd':
|
591 |
|
|
killbyname("ntpd");
|
592 |
|
|
break;
|
593 |
|
|
case 'openntpd':
|
594 |
|
|
killbyname("openntpd");
|
595 |
|
|
break;
|
596 |
b05a8f35
|
jim-p
|
case 'apinger':
|
597 |
|
|
killbypid("{$g['varrun_path']}/apinger.pid");
|
598 |
|
|
break;
|
599 |
ee6e6011
|
jim-p
|
case 'bsnmpd':
|
600 |
|
|
killbypid("{$g['varrun_path']}/snmpd.pid");
|
601 |
|
|
break;
|
602 |
|
|
case 'choparp':
|
603 |
|
|
killbyname("choparp");
|
604 |
|
|
break;
|
605 |
|
|
case 'dhcpd':
|
606 |
|
|
killbyname("dhcpd");
|
607 |
|
|
break;
|
608 |
|
|
case 'dhcrelay':
|
609 |
|
|
killbypid("{$g['varrun_path']}/dhcrelay.pid");
|
610 |
|
|
break;
|
611 |
9590e0de
|
Phil Davis
|
case 'dhcrelay6':
|
612 |
|
|
killbypid("{$g['varrun_path']}/dhcrelay6.pid");
|
613 |
|
|
break;
|
614 |
ee6e6011
|
jim-p
|
case 'dnsmasq':
|
615 |
|
|
killbypid("{$g['varrun_path']}/dnsmasq.pid");
|
616 |
|
|
break;
|
617 |
33232486
|
Warren Baker
|
case 'unbound':
|
618 |
|
|
killbypid("{$g['varrun_path']}/unbound.pid");
|
619 |
|
|
break;
|
620 |
ee6e6011
|
jim-p
|
case 'igmpproxy':
|
621 |
|
|
killbyname("igmpproxy");
|
622 |
|
|
break;
|
623 |
|
|
case 'miniupnpd':
|
624 |
|
|
upnp_action('stop');
|
625 |
|
|
break;
|
626 |
|
|
case 'sshd':
|
627 |
|
|
killbyname("sshd");
|
628 |
|
|
break;
|
629 |
8b4abd59
|
Ermal
|
case 'ipsec':
|
630 |
|
|
exec("/usr/local/sbin/ipsec stop");
|
631 |
ee6e6011
|
jim-p
|
break;
|
632 |
|
|
case 'openvpn':
|
633 |
2f9951fe
|
Renato Botelho
|
$vpnmode = htmlspecialchars($extras['vpnmode']);
|
634 |
ee6e6011
|
jim-p
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
635 |
2f9951fe
|
Renato Botelho
|
$id = htmlspecialchars($extras['id']);
|
636 |
ee6e6011
|
jim-p
|
$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
|
637 |
|
|
killbypid($pidfile);
|
638 |
|
|
}
|
639 |
|
|
break;
|
640 |
|
|
case 'relayd':
|
641 |
|
|
mwexec('pkill relayd');
|
642 |
|
|
break;
|
643 |
|
|
default:
|
644 |
|
|
stop_service($name);
|
645 |
|
|
break;
|
646 |
|
|
}
|
647 |
|
|
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
|
648 |
|
|
}
|
649 |
33232486
|
Warren Baker
|
|
650 |
ee6e6011
|
jim-p
|
function service_control_restart($name, $extras) {
|
651 |
|
|
global $g;
|
652 |
|
|
switch($name) {
|
653 |
|
|
case 'radvd':
|
654 |
|
|
services_radvd_configure();
|
655 |
|
|
break;
|
656 |
|
|
case 'captiveportal':
|
657 |
2f9951fe
|
Renato Botelho
|
$zone = htmlspecialchars($extras['zone']);
|
658 |
ee6e6011
|
jim-p
|
killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
|
659 |
|
|
killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
|
660 |
|
|
captiveportal_init_webgui_zonename($zone);
|
661 |
|
|
break;
|
662 |
|
|
case 'ntpd':
|
663 |
|
|
case 'openntpd':
|
664 |
|
|
system_ntp_configure();
|
665 |
|
|
break;
|
666 |
b05a8f35
|
jim-p
|
case 'apinger':
|
667 |
|
|
killbypid("{$g['varrun_path']}/apinger.pid");
|
668 |
|
|
setup_gateways_monitor();
|
669 |
|
|
break;
|
670 |
ee6e6011
|
jim-p
|
case 'bsnmpd':
|
671 |
|
|
services_snmpd_configure();
|
672 |
|
|
break;
|
673 |
9590e0de
|
Phil Davis
|
case 'dhcrelay':
|
674 |
|
|
services_dhcrelay_configure();
|
675 |
|
|
break;
|
676 |
|
|
case 'dhcrelay6':
|
677 |
|
|
services_dhcrelay6_configure();
|
678 |
|
|
break;
|
679 |
ee6e6011
|
jim-p
|
case 'dnsmasq':
|
680 |
|
|
services_dnsmasq_configure();
|
681 |
|
|
break;
|
682 |
33232486
|
Warren Baker
|
case 'unbound':
|
683 |
|
|
services_unbound_configure();
|
684 |
|
|
break;
|
685 |
ee6e6011
|
jim-p
|
case 'dhcpd':
|
686 |
|
|
services_dhcpd_configure();
|
687 |
|
|
break;
|
688 |
|
|
case 'igmpproxy':
|
689 |
|
|
services_igmpproxy_configure();
|
690 |
|
|
break;
|
691 |
|
|
case 'miniupnpd':
|
692 |
|
|
upnp_action('restart');
|
693 |
|
|
break;
|
694 |
8b4abd59
|
Ermal
|
case 'ipsec':
|
695 |
ee6e6011
|
jim-p
|
vpn_ipsec_force_reload();
|
696 |
|
|
break;
|
697 |
aaa78416
|
jim-p
|
case 'sshd':
|
698 |
|
|
send_event("service restart sshd");
|
699 |
|
|
break;
|
700 |
ee6e6011
|
jim-p
|
case 'openvpn':
|
701 |
2f9951fe
|
Renato Botelho
|
$vpnmode = htmlspecialchars($extras['vpnmode']);
|
702 |
ee6e6011
|
jim-p
|
if ($vpnmode == "server" || $vpnmode == "client") {
|
703 |
2f9951fe
|
Renato Botelho
|
$id = htmlspecialchars($extras['id']);
|
704 |
ee6e6011
|
jim-p
|
$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
|
705 |
|
|
if (file_exists($configfile))
|
706 |
|
|
openvpn_restart_by_vpnid($vpnmode, $id);
|
707 |
|
|
}
|
708 |
|
|
break;
|
709 |
|
|
case 'relayd':
|
710 |
|
|
relayd_configure(true);
|
711 |
|
|
break;
|
712 |
|
|
default:
|
713 |
|
|
restart_service($name);
|
714 |
|
|
break;
|
715 |
|
|
}
|
716 |
|
|
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
|
717 |
|
|
}
|
718 |
|
|
|
719 |
17098641
|
Ermal
|
?>
|