Project

General

Profile

Download (11 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("guiconfig.inc");
41
require_once("service-utils.inc");
42

    
43
function gentitle_pkg($pgname) {
44
	global $config;
45
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
46
}
47

    
48
function get_pkg_descr($package_name) {
49
	global $config;
50
	foreach($config['installedpackages']['package'] as $pkg) {
51
		if($pkg['name'] == $package_name)
52
			return $pkg['descr'];
53
	}
54
	return "Not available.";
55
}
56

    
57
if($_GET['mode'] == "restartservice" and $_GET['service']) {
58
	switch($_GET['service']) {
59
		case 'ntpd':
60
			system_ntp_configure();
61
			break;
62
		case 'bsnmpd':
63
			services_snmpd_configure();
64
			break;
65
		case 'dnsmasq':
66
			services_dnsmasq_configure();
67
			break;
68
		case 'dhcpd':
69
			services_dhcpd_configure();
70
			break;
71
		case 'igmpproxy':
72
			services_igmpproxy_configure();
73
			break;
74
		case 'miniupnpd':
75
			upnp_action('restart');	
76
			break;
77
		case 'racoon':
78
			exec("/usr/bin/killall -9 racoon");
79
			sleep(1);
80
			vpn_ipsec_force_reload();
81
			break;
82
		case 'openvpn':         
83
			$vpnmode = $_GET['vpnmode'];
84
			if (($vpnmode == "server") or ($vpnmode == "client")) {
85
				$id = $_GET['id'];
86
				if (is_numeric($id)) {
87
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
88
					killbypid($pidfile);
89
					sleep(1);
90
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
91
					mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
92
				}
93
			}
94
			break;
95
		default:
96
			restart_service($_GET['service']);
97
			break;
98
	}
99
	$savemsg = "{$_GET['service']} has been restarted.";
100
	sleep(5);
101
}
102

    
103
if($_GET['mode'] == "startservice" and $_GET['service']) {
104
	switch($_GET['service']) {
105
		case 'ntpd':
106
			system_ntp_configure();
107
			break;		
108
		case 'bsnmpd':
109
			services_snmpd_configure();
110
			break;
111
		case 'dnsmasq':
112
			services_dnsmasq_configure();
113
			break;
114
		case 'dhcpd':
115
			services_dhcpd_configure();
116
			break;
117
		case 'igmpproxy':
118
			services_igmpproxy_configure();
119
			break;
120
		case 'miniupnpd':
121
			upnp_action('start');
122
			break;
123
		case 'racoon':
124
			exec("killall -9 racoon");
125
			sleep(1);
126
			vpn_ipsec_force_reload();
127
			break;
128
		case 'openvpn':
129
			$vpnmode = $_GET['vpnmode'];
130
			if (($vpnmode == "server") or ($vpnmode == "client")) {
131
				$id = $_GET['id'];
132
				if (is_numeric($id)) {
133
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
134
					mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
135
				}
136
			}
137
			break;
138
		default:
139
			start_service($_GET['service']);
140
			break;
141
	}
142
	$savemsg = "{$_GET['service']} has been started.";
143
	sleep(5);
144
}
145

    
146
/* stop service */
147
if($_GET['mode'] == "stopservice" && $_GET['service']) {
148
	switch($_GET['service']) {
149
		case 'ntpd':
150
			killbyname("ntpd");
151
			break;		
152
		case 'bsnmpd':
153
			killbypid("{$g['varrun_path']}/snmpd.pid");
154
			break;
155
		case 'choparp':
156
			killbyname("choparp");
157
			break;
158
		case 'dhcpd':
159
			killbyname("dhcpd");
160
			break;
161
		case 'dhcrelay':
162
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
163
			break;
164
		case 'dnsmasq':
165
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
166
			break;
167
		case 'igmpproxy':
168
			killbyname("igmpproxy");
169
			break;
170
		case 'miniupnpd':
171
			upnp_action('stop');
172
			break;
173
		case 'openntpd':
174
			killbyname("openntpd");
175
			break;
176
		case 'sshd':
177
			killbyname("sshd");
178
			break;
179
		case 'racoon':
180
			exec("killall -9 racoon");
181
			break;
182
		case 'openvpn':         
183
			$vpnmode = $_GET['vpnmode'];
184
			if (($vpnmode == "server") or ($vpnmode == "client")) {
185
				$id = $_GET['id'];
186
				if (is_numeric($id)) {
187
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
188
					killbypid($pidfile);
189
				}
190
			}
191
			break;
192
		default:
193
			stop_service($_GET['service']);
194
			break;
195
	}
196
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
197
	sleep(5);
198
}
199

    
200
/* batch mode, allow other scripts to call this script */
201
if($_GET['batch']) exit;
202

    
203
$pgtitle = array("Status","Services");
204
include("head.inc");
205

    
206
?>
207

    
208
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
209
<?php
210
include("fbegin.inc");
211
?>
212
<form action="status_services.php" method="post">
213
<?php if ($savemsg) print_info_box($savemsg); ?>
214

    
215
<p>
216

    
217
<div id="boxarea">
218
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
219
  <tr>
220
    <td>
221
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
222
	<tr>
223
	  <td class="listhdrr"><b><center>Service</center></b></td>
224
	  <td class="listhdrr"><b><center>Description</center></b></td>
225
	  <td class="listhdrr"><b><center>Status</center></b></td>
226
	</tr>
227

    
228
<?php
229

    
230
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
231
array_shift($psout);
232
foreach($psout as $line) {
233
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
234
}
235

    
236
$services = $config['installedpackages']['service'];
237

    
238
/*    Add services that are in the base.
239
 *
240
 */
241
if(isset($config['dnsmasq']['enable'])) {
242
	$pconfig['name'] = "dnsmasq";
243
	$pconfig['description'] = "DNS Forwarder";
244
	$services[] = $pconfig;
245
	unset($pconfig);
246
}
247

    
248
$pconfig['name'] = "ntpd";
249
$pconfig['description'] = "NTP clock sync";
250
$services[] = $pconfig;
251
unset($pconfig);
252

    
253
if(isset($config['captiveportal']['enable'])) {
254
	$pconfig['name'] = "lighttpd";
255
	$pconfig['description'] = "Captive Portal";
256
	$services[] = $pconfig;
257
	$pconfig = "";
258
	unset($pconfig);
259
}
260

    
261
$iflist = array();
262
$ifdescrs = get_configured_interface_list();
263
foreach ($ifdescrs as $if) {
264
	$oc = $config['interfaces'][$if];
265
	if ($oc['if'] && (!link_interface_to_bridge($if)))
266
		$iflist[$if] = $if;
267
}
268
$show_dhcprelay = false;
269
foreach($iflist as $if) {
270
	if(isset($config['dhcrelay'][$if]['enable']))
271
		$show_dhcprelay = true;
272
}
273

    
274
if($show_dhcprelay == true) {
275
	$pconfig['name'] = "dhcrelay";
276
	$pconfig['description'] = "DHCP Relay";
277
	$services[] = $pconfig;
278
	unset($pconfig);
279
}
280

    
281
if(is_dhcp_server_enabled()) {
282
	$pconfig['name'] = "dhcpd";
283
	$pconfig['description'] = "DHCP Service";
284
	$services[] = $pconfig;
285
	unset($pconfig);
286
}
287

    
288
if(isset($config['snmpd']['enable'])) {
289
	$pconfig['name'] = "bsnmpd";
290
	$pconfig['description'] = "SNMP Service";
291
	$services[] = $pconfig;
292
	unset($pconfig);
293
}
294

    
295
if(isset($config['proxyarp']['proxyarpnet'])) {
296
	$pconfig['name'] = "choparp";
297
	$pconfig['description'] = "Proxy ARP";
298
	$services[] = $pconfig;
299
	unset($pconfig);
300
}
301

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

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

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

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

    
389
?>
390
</table>
391

    
392
</td>
393
</tr></table>
394
</div>
395

    
396
<?php include("fend.inc"); ?>
397
</body>
398
</html>
(163-163/217)