Project

General

Profile

Download (12.1 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("openvpn.inc");
44
require_once("ipsec.inc");
45
require_once("vpn.inc");
46
require_once("vslb.inc");
47

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

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

    
64
if($_GET['mode'] == "restartservice" and !empty($_GET['service'])) {
65
	switch($_GET['service']) {
66
		case 'captiveportal':
67
			killbypid("{$g['varrun_path']}/lighty-CaptivePortal.pid");
68
			killbypid("{$g['varrun_path']}/lighty-CaptivePortal-SSL.pid");
69
			captiveportal_init_webgui();
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
				if (file_exists($configfile))
99
					openvpn_restart_by_vpnid($vpnmode, $id);
100
			}
101
			break;
102
		case 'relayd':
103
			relayd_configure(true);
104
			break;
105
		default:
106
			restart_service($_GET['service']);
107
			break;
108
	}
109
	$savemsg = sprintf(gettext("%s has been restarted."),htmlspecialchars($_GET['service']));
110
	sleep(5);
111
}
112

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

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

    
219
/* batch mode, allow other scripts to call this script */
220
if($_GET['batch'])
221
	exit;
222

    
223
$pgtitle = array(gettext("Status"),gettext("Services"));
224
include("head.inc");
225

    
226
?>
227

    
228
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
229
<?php
230
include("fbegin.inc");
231
?>
232
<form action="status_services.php" method="post">
233
<?php if ($savemsg) print_info_box($savemsg); ?>
234

    
235
<p>
236

    
237
<div id="boxarea">
238
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
239
	<thead>
240
	<tr>
241
		<td class="listhdrr" align="center"><?=gettext("Service");?></td>
242
		<td class="listhdrr" align="center"><?=gettext("Description");?></td>
243
		<td class="listhdrr" align="center"><?=gettext("Status");?></td>
244
	</tr>
245
	</thead>
246
	<tbody>
247
<?php
248

    
249
if (is_array($config['installedpackages']['service']))
250
	$services = $config['installedpackages']['service'];
251
else
252
	$services = array();
253

    
254
/*    Add services that are in the base.
255
 *
256
 */
257
if(isset($config['dnsmasq']['enable'])) {
258
	$pconfig = array();
259
	$pconfig['name'] = "dnsmasq";
260
	$pconfig['description'] = gettext("DNS Forwarder");
261
	$services[] = $pconfig;
262
}
263

    
264
$pconfig = array();
265
$pconfig['name'] = "ntpd";
266
$pconfig['description'] = gettext("NTP clock sync");
267
$services[] = $pconfig;
268

    
269
if(isset($config['captiveportal']['enable'])) {
270
	$pconfig = array();
271
	$pconfig['name'] = "captiveportal";
272
	$pconfig['description'] = gettext("Captive Portal");
273
	$services[] = $pconfig;
274
}
275

    
276
$iflist = array();
277
$ifdescrs = get_configured_interface_list();
278
foreach ($ifdescrs as $if) {
279
	$oc = $config['interfaces'][$if];
280
	if ($oc['if'] && (!link_interface_to_bridge($if)))
281
		$iflist[$if] = $if;
282
}
283
$show_dhcprelay = false;
284
foreach($iflist as $if) {
285
	if(isset($config['dhcrelay'][$if]['enable']))
286
		$show_dhcprelay = true;
287
}
288

    
289
if($show_dhcprelay == true) {
290
	$pconfig = array();
291
	$pconfig['name'] = "dhcrelay";
292
	$pconfig['description'] = gettext("DHCP Relay");
293
	$services[] = $pconfig;
294
}
295

    
296
if(is_dhcp_server_enabled()) {
297
	$pconfig = array();
298
	$pconfig['name'] = "dhcpd";
299
	$pconfig['description'] = gettext("DHCP Service");
300
	$services[] = $pconfig;
301
}
302

    
303
if(isset($config['snmpd']['enable'])) {
304
	$pconfig = array();
305
	$pconfig['name'] = "bsnmpd";
306
	$pconfig['description'] = gettext("SNMP Service");
307
	$services[] = $pconfig;
308
}
309

    
310
if (count($config['igmpproxy']['igmpentry']) > 0) {
311
	$pconfig = array();
312
	$pconfig['name'] = "igmpproxy";
313
	$pconfig['descritption'] = gettext("IGMP proxy");
314
	$services[] = $pconfig;
315
}
316

    
317
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
318
	$pconfig = array();
319
	$pconfig['name'] = "miniupnpd";
320
	$pconfig['description'] = gettext("UPnP Service");
321
	$services[] = $pconfig;
322
}
323

    
324
if (isset($config['ipsec']['enable'])) {
325
	$pconfig = array();
326
	$pconfig['name'] = "racoon";
327
	$pconfig['description'] = gettext("IPsec VPN");
328
	$services[] = $pconfig;
329
}
330

    
331
foreach (array('server', 'client') as $mode) {
332
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
333
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
334
			if (!isset($setting['disable'])) {
335
				$pconfig = array();
336
				$pconfig['name'] = "openvpn";
337
				$pconfig['mode'] = $mode;
338
				$pconfig['id'] = $id;
339
				$pconfig['vpnid'] = $setting['vpnid'];
340
				$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
341
				$services[] = $pconfig;
342
			}
343
		}
344
	}
345
}
346

    
347
if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
348
	$pconfig = array();
349
	$pconfig['name'] = "relayd";
350
	$pconfig['description'] = gettext("Server load balancing daemon");
351
	$services[] = $pconfig;
352
}
353

    
354
function service_name_compare($a, $b) {
355
	if (strtolower($a['name']) == strtolower($b['name']))
356
		return 0;
357
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
358
}
359

    
360
if (count($services) > 0) {
361
	uasort($services, "service_name_compare");
362
	foreach($services as $service) {
363
		if (empty($service['name']))
364
			continue;
365
		if (empty($service['description']))
366
			$service['description'] = get_pkg_descr($service['name']);
367
		echo '<tr><td class="listlr">' . $service['name'] . '</td>' . "\n";
368
		echo '<td class="listr">' . $service['description'] . '</td>' . "\n";
369
		if ($service['name'] == "openvpn")
370
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
371
		else if ($service['name'] == "captiveportal")
372
			$running = is_pid_running("{$g['varrun_path']}/lighty-CaptivePortal.pid");
373
		else
374
			$running = is_service_running($service['name']);
375
		if($running) {
376
			echo '<td class="listr"><center>' . "\n";
377
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> " . gettext("Running") . "</td>\n";
378
		} else {
379
			echo '<td class="listbg"><center>' . "\n";
380
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">" . gettext("Stopped") . "</td>\n";
381
		}
382
		echo '<td valign="middle" class="list" nowrap>';
383
		if($running) {
384
			if ($service['name'] == "openvpn") {
385
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
386
			} else {
387
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
388
			}
389
			echo "<img title='" . gettext("Restart Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a>\n";
390
			if ($service['name'] == "openvpn") {
391
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
392
			} else {
393
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
394
			}
395
			echo "<img title='" . gettext("Stop Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'>";
396
			echo "</a>";
397
		} else {
398
			if ($service['name'] == "openvpn") {
399
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
400
			} else { 
401
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
402
			}
403
			
404
			echo "<img title='" . gettext("Start Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a>\n";
405
		}
406
		echo "</td></tr>\n";
407
	}
408
} else {
409
	echo "<tr><td colspan=\"3\"><center>" . gettext("No services found") . ".</td></tr>\n";
410
}
411

    
412
?>
413
</tbody>
414
</table>
415
</div>
416
</p>
417
</form>
418
<?php include("fend.inc"); ?>
419
</body>
420
</html>
(174-174/226)