1
|
<?php
|
2
|
/*
|
3
|
services_status.php
|
4
|
Copyright (C) 2004, 2005 Scott Ullrich
|
5
|
All rights reserved.
|
6
|
|
7
|
Redistribution and use in source and binary forms, with or without
|
8
|
modification, are permitted provided that the following conditions are met:
|
9
|
|
10
|
1. Redistributions of source code must retain the above copyright notice,
|
11
|
this list of conditions and the following disclaimer.
|
12
|
|
13
|
2. Redistributions in binary form must reproduce the above copyright
|
14
|
notice, this list of conditions and the following disclaimer in the
|
15
|
documentation and/or other materials provided with the distribution.
|
16
|
|
17
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18
|
INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
POSSIBILITY OF SUCH DAMAGE.
|
27
|
*/
|
28
|
/*
|
29
|
pfSense_BUILDER_BINARIES: /usr/local/sbin/openvpn /usr/bin/killall /bin/ps
|
30
|
pfSense_MODULE: services
|
31
|
*/
|
32
|
|
33
|
##|+PRIV
|
34
|
##|*IDENT=page-status-services
|
35
|
##|*NAME=Status: Services page
|
36
|
##|*DESCR=Allow access to the 'Status: Services' page.
|
37
|
##|*MATCH=status_services.php*
|
38
|
##|-PRIV
|
39
|
|
40
|
require("guiconfig.inc");
|
41
|
require_once("service-utils.inc");
|
42
|
require_once("ipsec.inc");
|
43
|
require_once("vpn.inc");
|
44
|
|
45
|
function gentitle_pkg($pgname) {
|
46
|
global $config;
|
47
|
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
|
48
|
}
|
49
|
|
50
|
function get_pkg_descr($package_name) {
|
51
|
global $config;
|
52
|
if (is_array($config['installedpackages']['package'])) {
|
53
|
foreach($config['installedpackages']['package'] as $pkg) {
|
54
|
if($pkg['name'] == $package_name)
|
55
|
return $pkg['descr'];
|
56
|
}
|
57
|
}
|
58
|
return "Not available.";
|
59
|
}
|
60
|
|
61
|
if($_GET['mode'] == "restartservice" and $_GET['service']) {
|
62
|
switch($_GET['service']) {
|
63
|
case 'ntpd':
|
64
|
system_ntp_configure();
|
65
|
break;
|
66
|
case 'bsnmpd':
|
67
|
services_snmpd_configure();
|
68
|
break;
|
69
|
case 'dnsmasq':
|
70
|
services_dnsmasq_configure();
|
71
|
break;
|
72
|
case 'dhcpd':
|
73
|
services_dhcpd_configure();
|
74
|
break;
|
75
|
case 'igmpproxy':
|
76
|
services_igmpproxy_configure();
|
77
|
break;
|
78
|
case 'miniupnpd':
|
79
|
upnp_action('restart');
|
80
|
break;
|
81
|
case 'racoon':
|
82
|
exec("/usr/bin/killall -9 racoon");
|
83
|
sleep(1);
|
84
|
vpn_ipsec_force_reload();
|
85
|
break;
|
86
|
case 'openvpn':
|
87
|
$vpnmode = $_GET['vpnmode'];
|
88
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
89
|
$id = $_GET['id'];
|
90
|
if (is_numeric($id)) {
|
91
|
$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
|
92
|
killbypid($pidfile);
|
93
|
sleep(1);
|
94
|
$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
|
95
|
mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
|
96
|
}
|
97
|
}
|
98
|
break;
|
99
|
default:
|
100
|
restart_service($_GET['service']);
|
101
|
break;
|
102
|
}
|
103
|
$savemsg = "{$_GET['service']} has been restarted.";
|
104
|
sleep(5);
|
105
|
}
|
106
|
|
107
|
if($_GET['mode'] == "startservice" and $_GET['service']) {
|
108
|
switch($_GET['service']) {
|
109
|
case 'ntpd':
|
110
|
system_ntp_configure();
|
111
|
break;
|
112
|
case 'bsnmpd':
|
113
|
services_snmpd_configure();
|
114
|
break;
|
115
|
case 'dnsmasq':
|
116
|
services_dnsmasq_configure();
|
117
|
break;
|
118
|
case 'dhcpd':
|
119
|
services_dhcpd_configure();
|
120
|
break;
|
121
|
case 'igmpproxy':
|
122
|
services_igmpproxy_configure();
|
123
|
break;
|
124
|
case 'miniupnpd':
|
125
|
upnp_action('start');
|
126
|
break;
|
127
|
case 'racoon':
|
128
|
exec("killall -9 racoon");
|
129
|
sleep(1);
|
130
|
vpn_ipsec_force_reload();
|
131
|
break;
|
132
|
case 'openvpn':
|
133
|
$vpnmode = $_GET['vpnmode'];
|
134
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
135
|
$id = $_GET['id'];
|
136
|
if (is_numeric($id)) {
|
137
|
$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
|
138
|
mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
|
139
|
}
|
140
|
}
|
141
|
break;
|
142
|
default:
|
143
|
start_service($_GET['service']);
|
144
|
break;
|
145
|
}
|
146
|
$savemsg = "{$_GET['service']} has been started.";
|
147
|
sleep(5);
|
148
|
}
|
149
|
|
150
|
/* stop service */
|
151
|
if($_GET['mode'] == "stopservice" && $_GET['service']) {
|
152
|
switch($_GET['service']) {
|
153
|
case 'ntpd':
|
154
|
killbyname("ntpd");
|
155
|
break;
|
156
|
case 'bsnmpd':
|
157
|
killbypid("{$g['varrun_path']}/snmpd.pid");
|
158
|
break;
|
159
|
case 'choparp':
|
160
|
killbyname("choparp");
|
161
|
break;
|
162
|
case 'dhcpd':
|
163
|
killbyname("dhcpd");
|
164
|
break;
|
165
|
case 'dhcrelay':
|
166
|
killbypid("{$g['varrun_path']}/dhcrelay.pid");
|
167
|
break;
|
168
|
case 'dnsmasq':
|
169
|
killbypid("{$g['varrun_path']}/dnsmasq.pid");
|
170
|
break;
|
171
|
case 'igmpproxy':
|
172
|
killbyname("igmpproxy");
|
173
|
break;
|
174
|
case 'miniupnpd':
|
175
|
upnp_action('stop');
|
176
|
break;
|
177
|
case 'openntpd':
|
178
|
killbyname("openntpd");
|
179
|
break;
|
180
|
case 'sshd':
|
181
|
killbyname("sshd");
|
182
|
break;
|
183
|
case 'racoon':
|
184
|
exec("killall -9 racoon");
|
185
|
break;
|
186
|
case 'openvpn':
|
187
|
$vpnmode = $_GET['vpnmode'];
|
188
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
189
|
$id = $_GET['id'];
|
190
|
if (is_numeric($id)) {
|
191
|
$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
|
192
|
killbypid($pidfile);
|
193
|
}
|
194
|
}
|
195
|
break;
|
196
|
default:
|
197
|
stop_service($_GET['service']);
|
198
|
break;
|
199
|
}
|
200
|
$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
|
201
|
sleep(5);
|
202
|
}
|
203
|
|
204
|
/* batch mode, allow other scripts to call this script */
|
205
|
if($_GET['batch']) exit;
|
206
|
|
207
|
$pgtitle = array("Status","Services");
|
208
|
include("head.inc");
|
209
|
|
210
|
?>
|
211
|
|
212
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
213
|
<?php
|
214
|
include("fbegin.inc");
|
215
|
?>
|
216
|
<form action="status_services.php" method="post">
|
217
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
218
|
|
219
|
<p>
|
220
|
|
221
|
<div id="boxarea">
|
222
|
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
223
|
<tr>
|
224
|
<td>
|
225
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
226
|
<tr>
|
227
|
<td class="listhdrr"><b><center>Service</center></b></td>
|
228
|
<td class="listhdrr"><b><center>Description</center></b></td>
|
229
|
<td class="listhdrr"><b><center>Status</center></b></td>
|
230
|
</tr>
|
231
|
|
232
|
<?php
|
233
|
|
234
|
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
|
235
|
array_shift($psout);
|
236
|
foreach($psout as $line) {
|
237
|
$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
|
238
|
}
|
239
|
|
240
|
$services = $config['installedpackages']['service'];
|
241
|
|
242
|
/* Add services that are in the base.
|
243
|
*
|
244
|
*/
|
245
|
if(isset($config['dnsmasq']['enable'])) {
|
246
|
$pconfig['name'] = "dnsmasq";
|
247
|
$pconfig['description'] = "DNS Forwarder";
|
248
|
$services[] = $pconfig;
|
249
|
unset($pconfig);
|
250
|
}
|
251
|
|
252
|
$pconfig['name'] = "ntpd";
|
253
|
$pconfig['description'] = "NTP clock sync";
|
254
|
$services[] = $pconfig;
|
255
|
unset($pconfig);
|
256
|
|
257
|
if(isset($config['captiveportal']['enable'])) {
|
258
|
$pconfig['name'] = "lighttpd";
|
259
|
$pconfig['description'] = "Captive Portal";
|
260
|
$services[] = $pconfig;
|
261
|
$pconfig = "";
|
262
|
unset($pconfig);
|
263
|
}
|
264
|
|
265
|
$iflist = array();
|
266
|
$ifdescrs = get_configured_interface_list();
|
267
|
foreach ($ifdescrs as $if) {
|
268
|
$oc = $config['interfaces'][$if];
|
269
|
if ($oc['if'] && (!link_interface_to_bridge($if)))
|
270
|
$iflist[$if] = $if;
|
271
|
}
|
272
|
$show_dhcprelay = false;
|
273
|
foreach($iflist as $if) {
|
274
|
if(isset($config['dhcrelay'][$if]['enable']))
|
275
|
$show_dhcprelay = true;
|
276
|
}
|
277
|
|
278
|
if($show_dhcprelay == true) {
|
279
|
$pconfig['name'] = "dhcrelay";
|
280
|
$pconfig['description'] = "DHCP Relay";
|
281
|
$services[] = $pconfig;
|
282
|
unset($pconfig);
|
283
|
}
|
284
|
|
285
|
if(is_dhcp_server_enabled()) {
|
286
|
$pconfig['name'] = "dhcpd";
|
287
|
$pconfig['description'] = "DHCP Service";
|
288
|
$services[] = $pconfig;
|
289
|
unset($pconfig);
|
290
|
}
|
291
|
|
292
|
if(isset($config['snmpd']['enable'])) {
|
293
|
$pconfig['name'] = "bsnmpd";
|
294
|
$pconfig['description'] = "SNMP Service";
|
295
|
$services[] = $pconfig;
|
296
|
unset($pconfig);
|
297
|
}
|
298
|
|
299
|
if (count($config['igmpproxy']['igmpentry']) > 0) {
|
300
|
$pconfig['name'] = "igmpproxy";
|
301
|
$pconfig['descritption'] = "IGMP proxy";
|
302
|
$services[] = $pconfig;
|
303
|
unset($pconfig);
|
304
|
}
|
305
|
|
306
|
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
|
307
|
$pconfig['name'] = "miniupnpd";
|
308
|
$pconfig['description'] = gettext("UPnP Service");
|
309
|
$services[] = $pconfig;
|
310
|
unset($pconfig);
|
311
|
}
|
312
|
|
313
|
if (isset($config['ipsec']['enable'])) {
|
314
|
$pconfig['name'] = "racoon";
|
315
|
$pconfig['description'] = gettext("IPsec VPN");
|
316
|
$services[] = $pconfig;
|
317
|
unset($pconfig);
|
318
|
}
|
319
|
|
320
|
foreach (array('server', 'client') as $mode) {
|
321
|
if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
|
322
|
foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
|
323
|
$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
|
324
|
if (!$setting['disable']) {
|
325
|
$pconfig['name'] = "openvpn";
|
326
|
$pconfig['mode'] = $mode;
|
327
|
$pconfig['id'] = $id;
|
328
|
$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
|
329
|
$services[] = $pconfig;
|
330
|
unset($pconfig);
|
331
|
}
|
332
|
}
|
333
|
}
|
334
|
}
|
335
|
|
336
|
|
337
|
if($services) {
|
338
|
foreach($services as $service) {
|
339
|
if(!$service['name']) continue;
|
340
|
if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
|
341
|
echo '<tr><td class="listlr">' . $service['name'] . '</td>';
|
342
|
echo '<td class="listr">' . $service['description'] . '</td>';
|
343
|
if ($service['name'] == "openvpn") {
|
344
|
$running = (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
|
345
|
} else {
|
346
|
$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
|
347
|
}
|
348
|
if($running) {
|
349
|
echo '<td class="listr"><center>';
|
350
|
echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
|
351
|
} else {
|
352
|
echo '<td class="listbg"><center>';
|
353
|
echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
|
354
|
}
|
355
|
echo '<td valign="middle" class="list" nowrap>';
|
356
|
if($running) {
|
357
|
if ($service['name'] == "openvpn") {
|
358
|
echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
|
359
|
} else {
|
360
|
echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
|
361
|
}
|
362
|
echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
|
363
|
if ($service['name'] == "openvpn") {
|
364
|
echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
|
365
|
} else {
|
366
|
echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
|
367
|
}
|
368
|
echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
|
369
|
echo "</a>";
|
370
|
} else {
|
371
|
if ($service['name'] == "openvpn") {
|
372
|
echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
|
373
|
} else {
|
374
|
echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
|
375
|
}
|
376
|
|
377
|
echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
|
378
|
}
|
379
|
echo '</td>';
|
380
|
echo '</tr>';
|
381
|
}
|
382
|
} else {
|
383
|
echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
|
384
|
}
|
385
|
|
386
|
?>
|
387
|
</table>
|
388
|
|
389
|
</td>
|
390
|
</tr></table>
|
391
|
</div>
|
392
|
|
393
|
<?php include("fend.inc"); ?>
|
394
|
</body>
|
395
|
</html>
|