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