Project

General

Profile

Download (11.5 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."),$_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."),$_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."), $_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
  <tr>
231
    <td>
232
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
233
	<tr>
234
	  <td class="listhdrr"><b><center><?=gettext("Service");?></center></b></td>
235
	  <td class="listhdrr"><b><center><?=gettext("Description");?></center></b></td>
236
	  <td class="listhdrr"><b><center><?=gettext("Status");?></center></b></td>
237
	</tr>
238

    
239
<?php
240

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

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

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

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

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

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

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

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

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

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

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

    
323
foreach (array('server', 'client') as $mode) {
324
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
325
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
326
			if (!isset($setting['disable'])) {
327
				$pconfig = array();
328
				$pconfig['name'] = "openvpn";
329
				$pconfig['mode'] = $mode;
330
				$pconfig['id'] = $id;
331
				$pconfig['vpnid'] = $settings['vpnid'];
332
				$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
333
				$services[] = $pconfig;
334
			}
335
		}
336
	}
337
}
338
 
339
 
340
if (count($services) > 0) {
341
	foreach($services as $service) {
342
		if (empty($service['name']))
343
			continue;
344
		if (empty($service['description']))
345
			$service['description'] = get_pkg_descr($service['name']);
346
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
347
		echo '<td class="listr">' . $service['description'] . '</td>';
348
		if ($service['name'] == "openvpn")
349
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
350
		else if ($service['name'] == "captiveportal")
351
			$running = is_pid_running("{$g['varrun_path']}/lighty-CaptivePortal.pid");
352
		else
353
			$running = is_service_running($service['name']);
354
		if($running) {
355
			echo '<td class="listr"><center>';
356
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> " . gettext("Running") . "</td>";
357
		} else {
358
			echo '<td class="listbg"><center>';
359
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">" . gettext("Stopped") . "</td>";
360
		}
361
		echo '<td valign="middle" class="list" nowrap>';
362
		if($running) {
363
			if ($service['name'] == "openvpn") {
364
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
365
			} else {
366
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
367
			}
368
			echo "<img title='" . gettext("Restart Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
369
			if ($service['name'] == "openvpn") {
370
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
371
			} else {
372
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
373
			}
374
			echo "<img title='" . gettext("Stop Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
375
			echo "</a>";
376
		} else {
377
			if ($service['name'] == "openvpn") {
378
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
379
			} else { 
380
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
381
			}
382
			
383
			echo "<img title='" . gettext("Start Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
384
		}
385
		echo '</td>';
386
		echo '</tr>';
387
	}
388
} else {
389
	echo "<tr><td colspan=\"3\"><center>" . gettext("No services found") . ".</td></tr>";
390
}
391

    
392
?>
393
</table>
394

    
395
</td>
396
</tr></table>
397
</div>
398
</p>
399
</form>
400
<?php include("fend.inc"); ?>
401
</body>
402
</html>
(168-168/219)