Project

General

Profile

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

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

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

    
222
/* batch mode, allow other scripts to call this script */
223
if($_GET['batch'])
224
	exit;
225

    
226
$pgtitle = array(gettext("Status"),gettext("Services"));
227
include("head.inc");
228

    
229
?>
230

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

    
238
<p>
239

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

    
252
if (is_array($config['installedpackages']['service']))
253
	$services = $config['installedpackages']['service'];
254
else
255
	$services = array();
256

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

    
267
$pconfig = array();
268
$pconfig['name'] = "ntpd";
269
$pconfig['description'] = gettext("NTP clock sync");
270
$services[] = $pconfig;
271

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

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

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

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

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

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

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

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

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

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

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

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

    
415
?>
416
</tbody>
417
</table>
418
</div>
419
</p>
420
</form>
421
<?php include("fend.inc"); ?>
422
</body>
423
</html>
(192-192/247)