Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Tag: | Revision:
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_once("guiconfig.inc");
41
require_once("captiveportal.inc");
42
require_once("service-utils.inc");
43
require_once("ipsec.inc");
44
require_once("vpn.inc");
45
require_once("vslb.inc");
46

    
47
function gentitle_pkg($pgname) {
48
	global $config;
49
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
50
}
51

    
52
function get_pkg_descr($package_name) {
53
	global $config;
54
	if (is_array($config['installedpackages']['package'])) {
55
		foreach($config['installedpackages']['package'] as $pkg) {
56
			if($pkg['name'] == $package_name)
57
				return $pkg['descr'];
58
		}
59
	}
60
	return gettext("Not available.");
61
}
62

    
63
if($_GET['mode'] == "restartservice" and !empty($_GET['service'])) {
64
	switch($_GET['service']) {
65
		case 'captiveportal':
66
			$zone = $_GET['zone'];
67
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
68
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
69
			captiveportal_init_webgui_zonename($zone);
70
			break;
71
		case 'ntpd':
72
		case 'openntpd':
73
			system_ntp_configure();
74
			break;
75
		case 'bsnmpd':
76
			services_snmpd_configure();
77
			break;
78
		case 'dnsmasq':
79
			services_dnsmasq_configure();
80
			break;
81
		case 'dhcpd':
82
			services_dhcpd_configure();
83
			break;
84
		case 'igmpproxy':
85
			services_igmpproxy_configure();
86
			break;
87
		case 'miniupnpd':
88
			upnp_action('restart');	
89
			break;
90
		case 'racoon':
91
			vpn_ipsec_force_reload();
92
			break;
93
		case 'openvpn':         
94
			$vpnmode = $_GET['vpnmode'];
95
			if ($vpnmode == "server" || $vpnmode == "client") {
96
				$id = $_GET['id'];
97
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
98
				$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
99
				if (file_exists($configfile)) {
100
					killbypid($pidfile);
101
					sleep(1);
102
					mwexec_bg("/usr/local/sbin/openvpn --config {$configfile}");
103
				}
104
			}
105
			break;
106
		case 'relayd':
107
			relayd_configure(true);
108
			break;
109
		default:
110
			restart_service($_GET['service']);
111
			break;
112
	}
113
	$savemsg = sprintf(gettext("%s has been restarted."),htmlspecialchars($_GET['service']));
114
	sleep(5);
115
}
116

    
117
if($_GET['mode'] == "startservice" and !empty($_GET['service'])) {
118
	switch($_GET['service']) {
119
		case 'captiveportal':
120
			$zone = $_GET['zone'];
121
			captiveportal_init_webgui_zonename($zone);
122
			break;
123
		case 'ntpd':
124
		case 'openntpd':
125
			system_ntp_configure();
126
			break;
127
		case 'bsnmpd':
128
			services_snmpd_configure();
129
			break;
130
		case 'dnsmasq':
131
			services_dnsmasq_configure();
132
			break;
133
		case 'dhcpd':
134
			services_dhcpd_configure();
135
			break;
136
		case 'igmpproxy':
137
			services_igmpproxy_configure();
138
			break;
139
		case 'miniupnpd':
140
			upnp_action('start');
141
			break;
142
		case 'racoon':
143
			vpn_ipsec_force_reload();
144
			break;
145
		case 'openvpn':
146
			$vpnmode = $_GET['vpnmode'];
147
			if (($vpnmode == "server") || ($vpnmode == "client")) {
148
				$id = $_GET['id'];
149
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
150
				if (file_exists($configfile))
151
					mwexec_bg("/usr/local/sbin/openvpn --config {$configfile}");
152
			}
153
			break;
154
		case 'relayd':
155
			relayd_configure();
156
			break;
157
		default:
158
			start_service($_GET['service']);
159
			break;
160
	}
161
	$savemsg = sprintf(gettext("%s has been started."),htmlspecialchars($_GET['service']));
162
	sleep(5);
163
}
164

    
165
/* stop service */
166
if($_GET['mode'] == "stopservice" && !empty($_GET['service'])) {
167
	switch($_GET['service']) {
168
		case 'captiveportal':
169
			$zone = $_GET['zone'];
170
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
171
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
172
			break;
173
		case 'ntpd':
174
			killbyname("ntpd");
175
			break;		
176
		case 'openntpd':
177
			killbyname("openntpd");
178
			break;
179
		case 'bsnmpd':
180
			killbypid("{$g['varrun_path']}/snmpd.pid");
181
			break;
182
		case 'choparp':
183
			killbyname("choparp");
184
			break;
185
		case 'dhcpd':
186
			killbyname("dhcpd");
187
			break;
188
		case 'dhcrelay':
189
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
190
			break;
191
		case 'dnsmasq':
192
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
193
			break;
194
		case 'igmpproxy':
195
			killbyname("igmpproxy");
196
			break;
197
		case 'miniupnpd':
198
			upnp_action('stop');
199
			break;
200
		case 'sshd':
201
			killbyname("sshd");
202
			break;
203
		case 'racoon':
204
			exec("killall -9 racoon");
205
			break;
206
		case 'openvpn':         
207
			$vpnmode = $_GET['vpnmode'];
208
			if (($vpnmode == "server") or ($vpnmode == "client")) {
209
				$id = $_GET['id'];
210
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
211
				killbypid($pidfile);
212
			}
213
			break;
214
		case 'relayd':
215
			mwexec('pkill relayd');
216
			break;
217
		default:
218
			stop_service($_GET['service']);
219
			break;
220
	}
221
	$savemsg = sprintf(gettext("%s has been stopped."), htmlspecialchars($_GET['service']));
222
	sleep(5);
223
}
224

    
225
/* batch mode, allow other scripts to call this script */
226
if($_GET['batch'])
227
	exit;
228

    
229
$pgtitle = array(gettext("Status"),gettext("Services"));
230
include("head.inc");
231

    
232
?>
233

    
234
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
235
<?php
236
include("fbegin.inc");
237
?>
238
<form action="status_services.php" method="post">
239
<?php if ($savemsg) print_info_box($savemsg); ?>
240

    
241
<p>
242

    
243
<div id="boxarea">
244
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
245
	<thead>
246
	<tr>
247
		<td class="listhdrr" align="center"><?=gettext("Service");?></td>
248
		<td class="listhdrr" align="center"><?=gettext("Description");?></td>
249
		<td class="listhdrr" align="center"><?=gettext("Status");?></td>
250
	</tr>
251
	</thead>
252
	<tbody>
253
<?php
254

    
255
if (is_array($config['installedpackages']['service']))
256
	$services = $config['installedpackages']['service'];
257
else
258
	$services = array();
259

    
260
/*    Add services that are in the base.
261
 *
262
 */
263
if(isset($config['dnsmasq']['enable'])) {
264
	$pconfig = array();
265
	$pconfig['name'] = "dnsmasq";
266
	$pconfig['description'] = gettext("DNS Forwarder");
267
	$services[] = $pconfig;
268
}
269

    
270
$pconfig = array();
271
$pconfig['name'] = "ntpd";
272
$pconfig['description'] = gettext("NTP clock sync");
273
$services[] = $pconfig;
274

    
275
if (is_array($config['captiveportal'])) {
276
	foreach ($config['captiveportal'] as $id => $setting) {
277
		if (isset($setting['enable'])) {
278
			$pconfig = array();
279
			$pconfig['name'] = "captiveportal";
280
			$pconfig['zone'] = $setting['zone'];
281
			$pconfig['description'] = gettext("Captive Portal") . ": ".htmlspecialchars($setting['zone']);
282
			$services[] = $pconfig;
283
		}
284
	}
285
}
286

    
287
$iflist = array();
288
$ifdescrs = get_configured_interface_list();
289
foreach ($ifdescrs as $if) {
290
	$oc = $config['interfaces'][$if];
291
	if ($oc['if'] && (!link_interface_to_bridge($if)))
292
		$iflist[$if] = $if;
293
}
294
$show_dhcprelay = false;
295
foreach($iflist as $if) {
296
	if(isset($config['dhcrelay'][$if]['enable']))
297
		$show_dhcprelay = true;
298
}
299

    
300
if($show_dhcprelay == true) {
301
	$pconfig = array();
302
	$pconfig['name'] = "dhcrelay";
303
	$pconfig['description'] = gettext("DHCP Relay");
304
	$services[] = $pconfig;
305
}
306

    
307
if(is_dhcp_server_enabled()) {
308
	$pconfig = array();
309
	$pconfig['name'] = "dhcpd";
310
	$pconfig['description'] = gettext("DHCP Service");
311
	$services[] = $pconfig;
312
}
313

    
314
if(isset($config['snmpd']['enable'])) {
315
	$pconfig = array();
316
	$pconfig['name'] = "bsnmpd";
317
	$pconfig['description'] = gettext("SNMP Service");
318
	$services[] = $pconfig;
319
}
320

    
321
if (count($config['igmpproxy']['igmpentry']) > 0) {
322
	$pconfig = array();
323
	$pconfig['name'] = "igmpproxy";
324
	$pconfig['descritption'] = gettext("IGMP proxy");
325
	$services[] = $pconfig;
326
}
327

    
328
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
329
	$pconfig = array();
330
	$pconfig['name'] = "miniupnpd";
331
	$pconfig['description'] = gettext("UPnP Service");
332
	$services[] = $pconfig;
333
}
334

    
335
if (isset($config['ipsec']['enable'])) {
336
	$pconfig = array();
337
	$pconfig['name'] = "racoon";
338
	$pconfig['description'] = gettext("IPsec VPN");
339
	$services[] = $pconfig;
340
}
341

    
342
foreach (array('server', 'client') as $mode) {
343
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
344
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
345
			if (!isset($setting['disable'])) {
346
				$pconfig = array();
347
				$pconfig['name'] = "openvpn";
348
				$pconfig['mode'] = $mode;
349
				$pconfig['id'] = $id;
350
				$pconfig['vpnid'] = $setting['vpnid'];
351
				$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
352
				$services[] = $pconfig;
353
			}
354
		}
355
	}
356
}
357

    
358
if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
359
	$pconfig = array();
360
	$pconfig['name'] = "relayd";
361
	$pconfig['description'] = gettext("Server load balancing daemon");
362
	$services[] = $pconfig;
363
}
364

    
365
function service_name_compare($a, $b) {
366
	if (strtolower($a['name']) == strtolower($b['name']))
367
		return 0;
368
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
369
}
370

    
371
if (count($services) > 0) {
372
	uasort($services, "service_name_compare");
373
	foreach($services as $service) {
374
		if (empty($service['name']))
375
			continue;
376
		if (empty($service['description']))
377
			$service['description'] = get_pkg_descr($service['name']);
378
		echo '<tr><td class="listlr">' . $service['name'] . '</td>' . "\n";
379
		echo '<td class="listr">' . $service['description'] . '</td>' . "\n";
380
		switch ($service['name']) {
381
			case "openvpn":
382
				$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
383
				if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
384
					$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
385
				break;
386
			case "captiveportal":
387
				$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
388
				break;
389
			default:
390
				$running = is_service_running($service['name']);
391
		}
392
		if($running) {
393
			echo "<td class=\"listr\" align=\"center\">\n";
394
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> " . gettext("Running") . "</td>\n";
395
		} else {
396
			echo "<td class=\"listbg\" align=\"center\">\n";
397
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">" . gettext("Stopped") . "</td>\n";
398
		}
399
		echo '<td valign="middle" class="list" nowrap>';
400
		if($running) {
401
			switch ($service['name']) {
402
				case "openvpn":
403
					echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
404
					break;
405
				case "captiveportal":
406
					echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&zone={$service['zone']}'>";
407
					break;
408
				default:
409
					echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
410
			}
411
			echo "<img title='" . gettext("Restart Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a>\n";
412
			switch ($service['name']) {
413
				case "openvpn":
414
					echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
415
					break;
416
				case "captiveportal":
417
					echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&zone={$service['zone']}'>";
418
					break;
419
				default:
420
					echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
421
			}
422
			echo "<img title='" . gettext("Stop Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'>";
423
			echo "</a>";
424
		} else {
425
			switch ($service['name']) {
426
				case "openvpn":
427
					echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
428
					break;
429
				case "captiveportal":
430
					echo "<a href='status_services.php?mode=startservice&service={$service['name']}&zone={$service['zone']}'>";
431
					break;
432
				default:
433
					echo "<a href='status_services.php?mode=startservice&service={$service['name']}'>";
434
			}
435
			echo "<img title='" . gettext("Start Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a>\n";
436
		}
437
		echo "</td></tr>\n";
438
	}
439
} else {
440
	echo "<tr><td colspan=\"3\" align=\"center\">" . gettext("No services found") . ".</td></tr>\n";
441
}
442

    
443
?>
444
</tbody>
445
</table>
446
</div>
447
</p>
448
</form>
449
<?php include("fend.inc"); ?>
450
</body>
451
</html>
(194-194/249)