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
|
##|+PRIV
|
30
|
##|*IDENT=page-status-services
|
31
|
##|*NAME=Status: Services page
|
32
|
##|*DESCR=Allow access to the 'Status: Services' page.
|
33
|
##|*MATCH=status_services.php*
|
34
|
##|-PRIV
|
35
|
|
36
|
|
37
|
require("guiconfig.inc");
|
38
|
|
39
|
function gentitle_pkg($pgname) {
|
40
|
global $config;
|
41
|
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
|
42
|
}
|
43
|
|
44
|
function get_pkg_descr($package_name) {
|
45
|
global $config;
|
46
|
foreach($config['installedpackages']['package'] as $pkg) {
|
47
|
if($pkg['name'] == $package_name)
|
48
|
return $pkg['descr'];
|
49
|
}
|
50
|
return "Not available.";
|
51
|
}
|
52
|
|
53
|
if($_GET['mode'] == "restartservice" and $_GET['service']) {
|
54
|
switch($_GET['service']) {
|
55
|
case 'bsnmpd':
|
56
|
services_snmpd_configure();
|
57
|
break;
|
58
|
case 'dnsmasq':
|
59
|
services_dnsmasq_configure();
|
60
|
break;
|
61
|
case 'dhcpd':
|
62
|
services_dhcpd_configure();
|
63
|
break;
|
64
|
case 'miniupnpd':
|
65
|
upnp_action('restart');
|
66
|
break;
|
67
|
case 'racoon':
|
68
|
exec("killall -9 racoon");
|
69
|
sleep(1);
|
70
|
vpn_ipsec_force_reload();
|
71
|
break;
|
72
|
case 'openvpn':
|
73
|
$vpnmode = $_GET['vpnmode'];
|
74
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
75
|
$id = $_GET['id'];
|
76
|
if (is_numeric($id)) {
|
77
|
$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
|
78
|
killbypid($pidfile);
|
79
|
sleep(1);
|
80
|
$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
|
81
|
mwexec_bg("openvpn --config $configfile");
|
82
|
}
|
83
|
}
|
84
|
break;
|
85
|
default:
|
86
|
restart_service($_GET['service']);
|
87
|
break;
|
88
|
}
|
89
|
$savemsg = "{$_GET['service']} has been restarted.";
|
90
|
sleep(5);
|
91
|
}
|
92
|
|
93
|
if($_GET['mode'] == "startservice" and $_GET['service']) {
|
94
|
switch($_GET['service']) {
|
95
|
case 'bsnmpd':
|
96
|
services_snmpd_configure();
|
97
|
break;
|
98
|
case 'dnsmasq':
|
99
|
services_dnsmasq_configure();
|
100
|
break;
|
101
|
case 'dhcpd':
|
102
|
services_dhcpd_configure();
|
103
|
break;
|
104
|
case 'miniupnpd':
|
105
|
upnp_action('start');
|
106
|
break;
|
107
|
case 'racoon':
|
108
|
exec("killall -9 racoon");
|
109
|
sleep(1);
|
110
|
vpn_ipsec_force_reload();
|
111
|
break;
|
112
|
case 'openvpn':
|
113
|
$vpnmode = $_GET['vpnmode'];
|
114
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
115
|
$id = $_GET['id'];
|
116
|
if (is_numeric($id)) {
|
117
|
$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
|
118
|
mwexec_bg("openvpn --config $configfile");
|
119
|
}
|
120
|
}
|
121
|
break;
|
122
|
default:
|
123
|
start_service($_GET['service']);
|
124
|
break;
|
125
|
}
|
126
|
$savemsg = "{$_GET['service']} has been started.";
|
127
|
sleep(5);
|
128
|
}
|
129
|
|
130
|
/* stop service */
|
131
|
if($_GET['mode'] == "stopservice" && $_GET['service']) {
|
132
|
switch($_GET['service']) {
|
133
|
case 'bsnmpd':
|
134
|
killbypid("{$g['varrun_path']}/snmpd.pid");
|
135
|
break;
|
136
|
case 'choparp':
|
137
|
killbyname("choparp");
|
138
|
break;
|
139
|
case 'dhcpd':
|
140
|
killbyname("dhcpd");
|
141
|
break;
|
142
|
case 'dhcrelay':
|
143
|
killbypid("{$g['varrun_path']}/dhcrelay.pid");
|
144
|
break;
|
145
|
case 'dnsmasq':
|
146
|
killbypid("{$g['varrun_path']}/dnsmasq.pid");
|
147
|
break;
|
148
|
case 'miniupnpd':
|
149
|
upnp_action('stop');
|
150
|
break;
|
151
|
case 'ntpd':
|
152
|
killbyname("ntpd");
|
153
|
break;
|
154
|
case 'sshd':
|
155
|
killbyname("sshd");
|
156
|
break;
|
157
|
case 'racoon':
|
158
|
exec("killall -9 racoon");
|
159
|
break;
|
160
|
case 'openvpn':
|
161
|
$vpnmode = $_GET['vpnmode'];
|
162
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
163
|
$id = $_GET['id'];
|
164
|
if (is_numeric($id)) {
|
165
|
$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
|
166
|
killbypid($pidfile);
|
167
|
}
|
168
|
}
|
169
|
break;
|
170
|
default:
|
171
|
stop_service($_GET['service']);
|
172
|
break;
|
173
|
}
|
174
|
$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
|
175
|
sleep(5);
|
176
|
}
|
177
|
|
178
|
/* batch mode, allow other scripts to call this script */
|
179
|
if($_GET['batch']) exit;
|
180
|
|
181
|
$pgtitle = array("Status","Services");
|
182
|
include("head.inc");
|
183
|
|
184
|
?>
|
185
|
|
186
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
187
|
<?php
|
188
|
include("fbegin.inc");
|
189
|
?>
|
190
|
<form action="status_services.php" method="post">
|
191
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
192
|
|
193
|
<p>
|
194
|
|
195
|
<div id="boxarea">
|
196
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
197
|
<tr>
|
198
|
<td>
|
199
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
200
|
<tr>
|
201
|
<td class="listhdrr"><b><center>Service</center></b></td>
|
202
|
<td class="listhdrr"><b><center>Description</center></b></td>
|
203
|
<td class="listhdrr"><b><center>Status</center></b></td>
|
204
|
</tr>
|
205
|
|
206
|
<?php
|
207
|
|
208
|
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
|
209
|
array_shift($psout);
|
210
|
foreach($psout as $line) {
|
211
|
$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
|
212
|
}
|
213
|
|
214
|
$services = $config['installedpackages']['service'];
|
215
|
|
216
|
/* Add services that are in the base.
|
217
|
*
|
218
|
*/
|
219
|
if(isset($config['dnsmasq']['enable'])) {
|
220
|
$pconfig['name'] = "dnsmasq";
|
221
|
$pconfig['description'] = "DNS Forwarder";
|
222
|
$services[] = $pconfig;
|
223
|
unset($pconfig);
|
224
|
}
|
225
|
|
226
|
if(isset($config['captiveportal']['enable'])) {
|
227
|
$pconfig['name'] = "lighttpd";
|
228
|
$pconfig['description'] = "Captive Portal";
|
229
|
$services[] = $pconfig;
|
230
|
$pconfig = "";
|
231
|
unset($pconfig);
|
232
|
}
|
233
|
|
234
|
$iflist = array();
|
235
|
$ifdescrs = get_configured_interface_list();
|
236
|
foreach ($ifdescrs as $if) {
|
237
|
$oc = $config['interfaces'][$if];
|
238
|
if ($oc['if'] && (!link_int_to_bridge_interface($if)))
|
239
|
$iflist[$if] = $if;
|
240
|
}
|
241
|
$show_dhcprelay = false;
|
242
|
foreach($iflist as $if) {
|
243
|
if(isset($config['dhcrelay'][$if]['enable']))
|
244
|
$show_dhcprelay = true;
|
245
|
}
|
246
|
|
247
|
if($show_dhcprelay == true) {
|
248
|
$pconfig['name'] = "dhcrelay";
|
249
|
$pconfig['description'] = "DHCP Relay";
|
250
|
$services[] = $pconfig;
|
251
|
unset($pconfig);
|
252
|
}
|
253
|
|
254
|
if(is_dhcp_server_enabled()) {
|
255
|
$pconfig['name'] = "dhcpd";
|
256
|
$pconfig['description'] = "DHCP Service";
|
257
|
$services[] = $pconfig;
|
258
|
unset($pconfig);
|
259
|
}
|
260
|
|
261
|
if(isset($config['snmpd']['enable'])) {
|
262
|
$pconfig['name'] = "bsnmpd";
|
263
|
$pconfig['description'] = "SNMP Service";
|
264
|
$services[] = $pconfig;
|
265
|
unset($pconfig);
|
266
|
}
|
267
|
|
268
|
if(isset($config['proxyarp']['proxyarpnet'])) {
|
269
|
$pconfig['name'] = "choparp";
|
270
|
$pconfig['description'] = "Proxy ARP";
|
271
|
$services[] = $pconfig;
|
272
|
unset($pconfig);
|
273
|
}
|
274
|
|
275
|
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
|
276
|
$pconfig['name'] = "miniupnpd";
|
277
|
$pconfig['description'] = gettext("UPnP Service");
|
278
|
$services[] = $pconfig;
|
279
|
unset($pconfig);
|
280
|
}
|
281
|
|
282
|
if (isset($config['ipsec']['enable'])) {
|
283
|
$pconfig['name'] = "racoon";
|
284
|
$pconfig['description'] = gettext("IPsec VPN");
|
285
|
$services[] = $pconfig;
|
286
|
unset($pconfig);
|
287
|
}
|
288
|
|
289
|
foreach (array('server', 'client') as $mode) {
|
290
|
if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
|
291
|
foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
|
292
|
$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
|
293
|
if (!$setting['disable']) {
|
294
|
$pconfig['name'] = "openvpn";
|
295
|
$pconfig['mode'] = $mode;
|
296
|
$pconfig['id'] = $id;
|
297
|
$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
|
298
|
$services[] = $pconfig;
|
299
|
unset($pconfig);
|
300
|
}
|
301
|
}
|
302
|
}
|
303
|
}
|
304
|
|
305
|
|
306
|
if($services) {
|
307
|
foreach($services as $service) {
|
308
|
if(!$service['name']) continue;
|
309
|
if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
|
310
|
echo '<tr><td class="listlr">' . $service['name'] . '</td>';
|
311
|
echo '<td class="listr">' . $service['description'] . '</td>';
|
312
|
if ($service['name'] == "openvpn") {
|
313
|
$running = (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
|
314
|
} else {
|
315
|
$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
|
316
|
}
|
317
|
if($running) {
|
318
|
echo '<td class="listr"><center>';
|
319
|
echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
|
320
|
} else {
|
321
|
echo '<td class="listbg"><center>';
|
322
|
echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
|
323
|
}
|
324
|
echo '<td valign="middle" class="list" nowrap>';
|
325
|
if($running) {
|
326
|
if ($service['name'] == "openvpn") {
|
327
|
echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
|
328
|
} else {
|
329
|
echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
|
330
|
}
|
331
|
echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
|
332
|
if ($service['name'] == "openvpn") {
|
333
|
echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
|
334
|
} else {
|
335
|
echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
|
336
|
}
|
337
|
echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
|
338
|
echo "</a>";
|
339
|
} else {
|
340
|
if ($service['name'] == "openvpn") {
|
341
|
echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
|
342
|
} else {
|
343
|
echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
|
344
|
}
|
345
|
|
346
|
echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
|
347
|
}
|
348
|
echo '</td>';
|
349
|
echo '</tr>';
|
350
|
}
|
351
|
} else {
|
352
|
echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
|
353
|
}
|
354
|
|
355
|
?>
|
356
|
</table>
|
357
|
|
358
|
</td>
|
359
|
</tr></table>
|
360
|
</div>
|
361
|
|
362
|
<?php include("fend.inc"); ?>
|
363
|
</body>
|
364
|
</html>
|