Project

General

Profile

Download (11.7 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

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

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

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

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

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

    
210
/* batch mode, allow other scripts to call this script */
211
if($_GET['batch'])
212
	exit;
213

    
214
$pgtitle = array(gettext("Status"),gettext("Services"));
215
include("head.inc");
216

    
217
?>
218

    
219
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220
<?php
221
include("fbegin.inc");
222
?>
223
<form action="status_services.php" method="post">
224
<?php if ($savemsg) print_info_box($savemsg); ?>
225

    
226
<p>
227

    
228
<div id="boxarea">
229
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
230
	<thead>
231
	<tr>
232
		<td class="listhdrr" align="center"><?=gettext("Service");?></td>
233
		<td class="listhdrr" align="center"><?=gettext("Description");?></td>
234
		<td class="listhdrr" align="center"><?=gettext("Status");?></td>
235
	</tr>
236
	</thead>
237
	<tbody>
238
<?php
239

    
240
if (is_array($config['installedpackages']['service']))
241
	$services = $config['installedpackages']['service'];
242
else
243
	$services = array();
244

    
245
/*    Add services that are in the base.
246
 *
247
 */
248
if(isset($config['dnsmasq']['enable'])) {
249
	$pconfig = array();
250
	$pconfig['name'] = "dnsmasq";
251
	$pconfig['description'] = gettext("DNS Forwarder");
252
	$services[] = $pconfig;
253
}
254

    
255
$pconfig = array();
256
$pconfig['name'] = "ntpd";
257
$pconfig['description'] = gettext("NTP clock sync");
258
$services[] = $pconfig;
259

    
260
if(isset($config['captiveportal']['enable'])) {
261
	$pconfig = array();
262
	$pconfig['name'] = "captiveportal";
263
	$pconfig['description'] = gettext("Captive Portal");
264
	$services[] = $pconfig;
265
}
266

    
267
$iflist = array();
268
$ifdescrs = get_configured_interface_list();
269
foreach ($ifdescrs as $if) {
270
	$oc = $config['interfaces'][$if];
271
	if ($oc['if'] && (!link_interface_to_bridge($if)))
272
		$iflist[$if] = $if;
273
}
274
$show_dhcprelay = false;
275
foreach($iflist as $if) {
276
	if(isset($config['dhcrelay'][$if]['enable']))
277
		$show_dhcprelay = true;
278
}
279

    
280
if($show_dhcprelay == true) {
281
	$pconfig = array();
282
	$pconfig['name'] = "dhcrelay";
283
	$pconfig['description'] = gettext("DHCP Relay");
284
	$services[] = $pconfig;
285
}
286

    
287
if(is_dhcp_server_enabled()) {
288
	$pconfig = array();
289
	$pconfig['name'] = "dhcpd";
290
	$pconfig['description'] = gettext("DHCP Service");
291
	$services[] = $pconfig;
292
}
293

    
294
if(isset($config['snmpd']['enable'])) {
295
	$pconfig = array();
296
	$pconfig['name'] = "bsnmpd";
297
	$pconfig['description'] = gettext("SNMP Service");
298
	$services[] = $pconfig;
299
}
300

    
301
if (count($config['igmpproxy']['igmpentry']) > 0) {
302
	$pconfig = array();
303
	$pconfig['name'] = "igmpproxy";
304
	$pconfig['descritption'] = gettext("IGMP proxy");
305
	$services[] = $pconfig;
306
}
307

    
308
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
309
	$pconfig = array();
310
	$pconfig['name'] = "miniupnpd";
311
	$pconfig['description'] = gettext("UPnP Service");
312
	$services[] = $pconfig;
313
}
314

    
315
if (isset($config['ipsec']['enable'])) {
316
	$pconfig = array();
317
	$pconfig['name'] = "racoon";
318
	$pconfig['description'] = gettext("IPsec VPN");
319
	$services[] = $pconfig;
320
}
321

    
322
foreach (array('server', 'client') as $mode) {
323
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
324
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
325
			if (!isset($setting['disable'])) {
326
				$pconfig = array();
327
				$pconfig['name'] = "openvpn";
328
				$pconfig['mode'] = $mode;
329
				$pconfig['id'] = $id;
330
				$pconfig['vpnid'] = $setting['vpnid'];
331
				$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
332
				$services[] = $pconfig;
333
			}
334
		}
335
	}
336
}
337

    
338
function service_name_compare($a, $b) {
339
	if (strtolower($a['name']) == strtolower($b['name']))
340
		return 0;
341
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
342
}
343

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

    
396
?>
397
</tbody>
398
</table>
399
</div>
400
</p>
401
</form>
402
<?php include("fend.inc"); ?>
403
</body>
404
</html>
(173-173/225)