Project

General

Profile

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

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

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

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

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

    
219
?>
220

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

    
228
<p>
229

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
398
?>
399
</tbody>
400
</table>
401
</div>
402
</p>
403
</form>
404
<?php include("fend.inc"); ?>
405
</body>
406
</html>
(180-180/233)