Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1 a0e4cea2 Scott Ullrich
<?php
2
/*
3 ef09107d Colin Smith
    services_status.php
4
    Copyright (C) 2004, 2005 Scott Ullrich
5 a0e4cea2 Scott Ullrich
    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 ef09107d Colin Smith
    INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 a0e4cea2 Scott Ullrich
    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 1d333258 Scott Ullrich
/*	
29
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/openvpn	/usr/bin/killall	/bin/ps
30
	pfSense_MODULE:	services
31
*/
32 a0e4cea2 Scott Ullrich
33 6b07c15a Matthew Grooms
##|+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 bc2e6100 Colin Smith
require("guiconfig.inc");
41 44173def Ermal Lu?i
require_once("service-utils.inc");
42 9a76a52a Ermal Lu?i
require_once("ipsec.inc");
43 1ac7a864 Chris Buechler
require_once("vpn.inc");
44 a0e4cea2 Scott Ullrich
45
function gentitle_pkg($pgname) {
46
	global $config;
47
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
48
}
49
50 5d8bcb27 Scott Ullrich
function get_pkg_descr($package_name) {
51
	global $config;
52 c9359d05 Ermal Lu?i
	if (is_array($config['installedpackages']['package'])) {
53
		foreach($config['installedpackages']['package'] as $pkg) {
54
			if($pkg['name'] == $package_name)
55
				return $pkg['descr'];
56
		}
57 5d8bcb27 Scott Ullrich
	}
58
	return "Not available.";
59
}
60
61 b9eadc0c Colin Smith
if($_GET['mode'] == "restartservice" and $_GET['service']) {
62 6c3e2b19 Scott Ullrich
	switch($_GET['service']) {
63 96155ce4 Scott Ullrich
		case 'ntpd':
64
			system_ntp_configure();
65
			break;
66 6c3e2b19 Scott Ullrich
		case 'bsnmpd':
67
			services_snmpd_configure();
68
			break;
69
		case 'dnsmasq':
70
			services_dnsmasq_configure();
71
			break;
72
		case 'dhcpd':
73
			services_dhcpd_configure();
74 422e039b Scott Ullrich
			break;
75 41997fbb Ermal Luci
		case 'igmpproxy':
76
			services_igmpproxy_configure();
77
			break;
78 422e039b Scott Ullrich
		case 'miniupnpd':
79 431484c8 Ryan Wagoner
			upnp_action('restart');	
80 6c3e2b19 Scott Ullrich
			break;
81 cd72ded3 Timo Boettcher
		case 'racoon':
82 1d333258 Scott Ullrich
			exec("/usr/bin/killall -9 racoon");
83 cd72ded3 Timo Boettcher
			sleep(1);
84
			vpn_ipsec_force_reload();
85
			break;
86
		case 'openvpn':         
87
			$vpnmode = $_GET['vpnmode'];
88
			if (($vpnmode == "server") or ($vpnmode == "client")) {
89
				$id = $_GET['id'];
90
				if (is_numeric($id)) {
91
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
92
					killbypid($pidfile);
93
					sleep(1);
94
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
95 1d333258 Scott Ullrich
					mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
96 cd72ded3 Timo Boettcher
				}
97
			}
98
			break;
99 6c3e2b19 Scott Ullrich
		default:
100
			restart_service($_GET['service']);
101
			break;
102
	}
103 b9eadc0c Colin Smith
	$savemsg = "{$_GET['service']} has been restarted.";
104 422e039b Scott Ullrich
	sleep(5);
105 a0e4cea2 Scott Ullrich
}
106
107 b9eadc0c Colin Smith
if($_GET['mode'] == "startservice" and $_GET['service']) {
108 3e32a807 Scott Ullrich
	switch($_GET['service']) {
109 96155ce4 Scott Ullrich
		case 'ntpd':
110
			system_ntp_configure();
111
			break;		
112 3e32a807 Scott Ullrich
		case 'bsnmpd':
113 3af54e48 Scott Ullrich
			services_snmpd_configure();
114 3e32a807 Scott Ullrich
			break;
115
		case 'dnsmasq':
116
			services_dnsmasq_configure();
117
			break;
118
		case 'dhcpd':
119
			services_dhcpd_configure();
120 422e039b Scott Ullrich
			break;
121 41997fbb Ermal Luci
		case 'igmpproxy':
122
			services_igmpproxy_configure();
123
			break;
124 422e039b Scott Ullrich
		case 'miniupnpd':
125 431484c8 Ryan Wagoner
			upnp_action('start');
126 3e32a807 Scott Ullrich
			break;
127 cd72ded3 Timo Boettcher
		case 'racoon':
128
			exec("killall -9 racoon");
129
			sleep(1);
130
			vpn_ipsec_force_reload();
131
			break;
132
		case 'openvpn':
133
			$vpnmode = $_GET['vpnmode'];
134
			if (($vpnmode == "server") or ($vpnmode == "client")) {
135
				$id = $_GET['id'];
136
				if (is_numeric($id)) {
137
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
138 1d333258 Scott Ullrich
					mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
139 cd72ded3 Timo Boettcher
				}
140
			}
141
			break;
142 3e32a807 Scott Ullrich
		default:
143
			start_service($_GET['service']);
144
			break;
145
	}
146 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} has been started.";
147 422e039b Scott Ullrich
	sleep(5);
148 a0e4cea2 Scott Ullrich
}
149
150 25b66ec5 Scott Ullrich
/* stop service */
151
if($_GET['mode'] == "stopservice" && $_GET['service']) {
152 422e039b Scott Ullrich
	switch($_GET['service']) {
153 96155ce4 Scott Ullrich
		case 'ntpd':
154
			killbyname("ntpd");
155
			break;		
156 25b66ec5 Scott Ullrich
		case 'bsnmpd':
157
			killbypid("{$g['varrun_path']}/snmpd.pid");
158
			break;
159
		case 'choparp':
160
			killbyname("choparp");
161
			break;
162 cd72ded3 Timo Boettcher
		case 'dhcpd':
163 25b66ec5 Scott Ullrich
			killbyname("dhcpd");
164 cd72ded3 Timo Boettcher
			break;
165
		case 'dhcrelay':
166
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
167
			break;
168
		case 'dnsmasq':
169 25b66ec5 Scott Ullrich
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
170
			break;
171 41997fbb Ermal Luci
		case 'igmpproxy':
172
			killbyname("igmpproxy");
173
			break;
174 422e039b Scott Ullrich
		case 'miniupnpd':
175 431484c8 Ryan Wagoner
			upnp_action('stop');
176 25b66ec5 Scott Ullrich
			break;
177 9e226d16 Scott Ullrich
		case 'openntpd':
178
			killbyname("openntpd");
179 cd72ded3 Timo Boettcher
			break;
180
		case 'sshd':
181 25b66ec5 Scott Ullrich
			killbyname("sshd");
182 cd72ded3 Timo Boettcher
			break;
183
		case 'racoon':
184
			exec("killall -9 racoon");
185
			break;
186
		case 'openvpn':         
187
			$vpnmode = $_GET['vpnmode'];
188
			if (($vpnmode == "server") or ($vpnmode == "client")) {
189
				$id = $_GET['id'];
190
				if (is_numeric($id)) {
191
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
192
					killbypid($pidfile);
193
				}
194
			}
195
			break;
196 422e039b Scott Ullrich
		default:
197 cd72ded3 Timo Boettcher
			stop_service($_GET['service']);
198 422e039b Scott Ullrich
			break;
199
	}
200 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
201
	sleep(5);
202 a0e4cea2 Scott Ullrich
}
203
204
/* batch mode, allow other scripts to call this script */
205 b9eadc0c Colin Smith
if($_GET['batch']) exit;
206
207 d88c6a9f Scott Ullrich
$pgtitle = array("Status","Services");
208 4df96eff Scott Ullrich
include("head.inc");
209
210 a0e4cea2 Scott Ullrich
?>
211
212
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
213
<?php
214
include("fbegin.inc");
215
?>
216
<form action="status_services.php" method="post">
217
<?php if ($savemsg) print_info_box($savemsg); ?>
218
219
<p>
220
221 0f10aee4 Bill Marquette
<div id="boxarea">
222 3473bb6a Scott Ullrich
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
223 a9bc3b82 Scott Ullrich
  <tr>
224 0f10aee4 Bill Marquette
    <td>
225 a9bc3b82 Scott Ullrich
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
226
	<tr>
227
	  <td class="listhdrr"><b><center>Service</center></b></td>
228
	  <td class="listhdrr"><b><center>Description</center></b></td>
229
	  <td class="listhdrr"><b><center>Status</center></b></td>
230
	</tr>
231
232 a0e4cea2 Scott Ullrich
<?php
233
234 3af54e48 Scott Ullrich
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
235 ef09107d Colin Smith
array_shift($psout);
236
foreach($psout as $line) {
237
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
238
}
239
240 7670e4d2 Scott Ullrich
$services = $config['installedpackages']['service'];
241 25d3fbd5 Scott Ullrich
242
/*    Add services that are in the base.
243
 *
244
 */
245
if(isset($config['dnsmasq']['enable'])) {
246
	$pconfig['name'] = "dnsmasq";
247
	$pconfig['description'] = "DNS Forwarder";
248
	$services[] = $pconfig;
249 7670e4d2 Scott Ullrich
	unset($pconfig);
250 25d3fbd5 Scott Ullrich
}
251
252 f4c155cd Scott Ullrich
$pconfig['name'] = "ntpd";
253 9e226d16 Scott Ullrich
$pconfig['description'] = "NTP clock sync";
254
$services[] = $pconfig;
255
unset($pconfig);
256
257 25d3fbd5 Scott Ullrich
if(isset($config['captiveportal']['enable'])) {
258 a17d277c Scott Ullrich
	$pconfig['name'] = "lighttpd";
259 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "Captive Portal";
260
	$services[] = $pconfig;
261 7670e4d2 Scott Ullrich
	$pconfig = "";
262
	unset($pconfig);
263 25d3fbd5 Scott Ullrich
}
264
265 3e321df2 Ermal Luçi
$iflist = array();
266
$ifdescrs = get_configured_interface_list();
267
foreach ($ifdescrs as $if) {
268
	$oc = $config['interfaces'][$if];
269 7ec05d27 Ermal Luçi
	if ($oc['if'] && (!link_interface_to_bridge($if)))
270 3e321df2 Ermal Luçi
		$iflist[$if] = $if;
271 51bb9b94 Scott Ullrich
}
272
$show_dhcprelay = false;
273
foreach($iflist as $if) {
274
	if(isset($config['dhcrelay'][$if]['enable']))
275
		$show_dhcprelay = true;
276
}
277
278
if($show_dhcprelay == true) {
279 c214e575 Scott Ullrich
	$pconfig['name'] = "dhcrelay";
280 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "DHCP Relay";
281
	$services[] = $pconfig;
282 7670e4d2 Scott Ullrich
	unset($pconfig);
283 25d3fbd5 Scott Ullrich
}
284
285 3af54e48 Scott Ullrich
if(is_dhcp_server_enabled()) {
286 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "dhcpd";
287 967fcdd0 Scott Ullrich
	$pconfig['description'] = "DHCP Service";
288 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
289 7670e4d2 Scott Ullrich
	unset($pconfig);
290 25d3fbd5 Scott Ullrich
}
291
292
if(isset($config['snmpd']['enable'])) {
293
	$pconfig['name'] = "bsnmpd";
294 967fcdd0 Scott Ullrich
	$pconfig['description'] = "SNMP Service";
295 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
296 7670e4d2 Scott Ullrich
	unset($pconfig);
297 25d3fbd5 Scott Ullrich
}
298
299 41997fbb Ermal Luci
if (count($config['igmpproxy']['igmpentry']) > 0) {
300
	$pconfig['name'] = "igmpproxy";
301
	$pconfig['descritption'] = "IGMP proxy";
302
	$services[] = $pconfig;
303
	unset($pconfig);
304
}
305
306 422e039b Scott Ullrich
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
307 cd72ded3 Timo Boettcher
	$pconfig['name'] = "miniupnpd";
308
	$pconfig['description'] = gettext("UPnP Service");
309
	$services[] = $pconfig;
310
	unset($pconfig);
311 422e039b Scott Ullrich
}
312
313 25b66ec5 Scott Ullrich
if (isset($config['ipsec']['enable'])) {
314 cd72ded3 Timo Boettcher
	$pconfig['name'] = "racoon";
315 0f266b2e Chris Buechler
	$pconfig['description'] = gettext("IPsec VPN");
316 cd72ded3 Timo Boettcher
	$services[] = $pconfig;
317
	unset($pconfig);
318 25b66ec5 Scott Ullrich
}
319
320 cd72ded3 Timo Boettcher
foreach (array('server', 'client') as $mode) {
321
	if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
322
		foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
323
			$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
324
			if (!$setting['disable']) {
325
				$pconfig['name'] = "openvpn";
326
				$pconfig['mode'] = $mode;
327
				$pconfig['id'] = $id;
328
				$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
329
				$services[] = $pconfig;
330
				unset($pconfig);
331
			}
332
		}
333
	}
334
}
335
 
336
 
337 25d3fbd5 Scott Ullrich
if($services) {
338
	foreach($services as $service) {
339 b9eadc0c Colin Smith
		if(!$service['name']) continue;
340 5d8bcb27 Scott Ullrich
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
341 b9eadc0c Colin Smith
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
342 271b638f Scott Ullrich
		echo '<td class="listr">' . $service['description'] . '</td>';
343 cd72ded3 Timo Boettcher
		if ($service['name'] == "openvpn") {
344
			$running =  (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
345
		} else {
346
			$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
347
		}
348
		if($running) {
349 4fd12c25 Scott Ullrich
			echo '<td class="listr"><center>';
350
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
351 b9eadc0c Colin Smith
		} else {
352 4fd12c25 Scott Ullrich
			echo '<td class="listbg"><center>';
353
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
354 b9eadc0c Colin Smith
		}
355 ef09107d Colin Smith
		echo '<td valign="middle" class="list" nowrap>';
356 b9eadc0c Colin Smith
		if($running) {
357 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
358
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
359
			} else {
360
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
361
			}
362 677c0869 Erik Kristensen
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
363 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
364
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
365
			} else {
366
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
367
			}
368 677c0869 Erik Kristensen
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
369 b9eadc0c Colin Smith
			echo "</a>";
370 a0e4cea2 Scott Ullrich
		} else {
371 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
372
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
373
			} else { 
374
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
375
			}
376
			
377 677c0869 Erik Kristensen
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
378 a0e4cea2 Scott Ullrich
		}
379 ef09107d Colin Smith
		echo '</td>';
380 b9eadc0c Colin Smith
		echo '</tr>';
381 a0e4cea2 Scott Ullrich
	}
382 b9eadc0c Colin Smith
} else {
383
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
384
}
385 cd72ded3 Timo Boettcher
386 a0e4cea2 Scott Ullrich
?>
387
</table>
388
389 a9bc3b82 Scott Ullrich
</td>
390
</tr></table>
391 12af52d9 Scott Ullrich
</div>
392 a9bc3b82 Scott Ullrich
393 a0e4cea2 Scott Ullrich
<?php include("fend.inc"); ?>
394
</body>
395
</html>