Project

General

Profile

Download (10.8 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 a0e4cea2 Scott Ullrich
43
function gentitle_pkg($pgname) {
44
	global $config;
45
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
46
}
47
48 5d8bcb27 Scott Ullrich
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 b9eadc0c Colin Smith
if($_GET['mode'] == "restartservice" and $_GET['service']) {
58 6c3e2b19 Scott Ullrich
	switch($_GET['service']) {
59 96155ce4 Scott Ullrich
		case 'ntpd':
60
			system_ntp_configure();
61
			break;
62 6c3e2b19 Scott Ullrich
		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 422e039b Scott Ullrich
			break;
71 41997fbb Ermal Luci
		case 'igmpproxy':
72
			services_igmpproxy_configure();
73
			break;
74 422e039b Scott Ullrich
		case 'miniupnpd':
75 431484c8 Ryan Wagoner
			upnp_action('restart');	
76 6c3e2b19 Scott Ullrich
			break;
77 cd72ded3 Timo Boettcher
		case 'racoon':
78 1d333258 Scott Ullrich
			exec("/usr/bin/killall -9 racoon");
79 cd72ded3 Timo Boettcher
			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 1d333258 Scott Ullrich
					mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
92 cd72ded3 Timo Boettcher
				}
93
			}
94
			break;
95 6c3e2b19 Scott Ullrich
		default:
96
			restart_service($_GET['service']);
97
			break;
98
	}
99 b9eadc0c Colin Smith
	$savemsg = "{$_GET['service']} has been restarted.";
100 422e039b Scott Ullrich
	sleep(5);
101 a0e4cea2 Scott Ullrich
}
102
103 b9eadc0c Colin Smith
if($_GET['mode'] == "startservice" and $_GET['service']) {
104 3e32a807 Scott Ullrich
	switch($_GET['service']) {
105 96155ce4 Scott Ullrich
		case 'ntpd':
106
			system_ntp_configure();
107
			break;		
108 3e32a807 Scott Ullrich
		case 'bsnmpd':
109 3af54e48 Scott Ullrich
			services_snmpd_configure();
110 3e32a807 Scott Ullrich
			break;
111
		case 'dnsmasq':
112
			services_dnsmasq_configure();
113
			break;
114
		case 'dhcpd':
115
			services_dhcpd_configure();
116 422e039b Scott Ullrich
			break;
117 41997fbb Ermal Luci
		case 'igmpproxy':
118
			services_igmpproxy_configure();
119
			break;
120 422e039b Scott Ullrich
		case 'miniupnpd':
121 431484c8 Ryan Wagoner
			upnp_action('start');
122 3e32a807 Scott Ullrich
			break;
123 cd72ded3 Timo Boettcher
		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 1d333258 Scott Ullrich
					mwexec_bg("/usr/local/sbin/openvpn --config $configfile");
135 cd72ded3 Timo Boettcher
				}
136
			}
137
			break;
138 3e32a807 Scott Ullrich
		default:
139
			start_service($_GET['service']);
140
			break;
141
	}
142 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} has been started.";
143 422e039b Scott Ullrich
	sleep(5);
144 a0e4cea2 Scott Ullrich
}
145
146 25b66ec5 Scott Ullrich
/* stop service */
147
if($_GET['mode'] == "stopservice" && $_GET['service']) {
148 422e039b Scott Ullrich
	switch($_GET['service']) {
149 96155ce4 Scott Ullrich
		case 'ntpd':
150
			killbyname("ntpd");
151
			break;		
152 25b66ec5 Scott Ullrich
		case 'bsnmpd':
153
			killbypid("{$g['varrun_path']}/snmpd.pid");
154
			break;
155
		case 'choparp':
156
			killbyname("choparp");
157
			break;
158 cd72ded3 Timo Boettcher
		case 'dhcpd':
159 25b66ec5 Scott Ullrich
			killbyname("dhcpd");
160 cd72ded3 Timo Boettcher
			break;
161
		case 'dhcrelay':
162
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
163
			break;
164
		case 'dnsmasq':
165 25b66ec5 Scott Ullrich
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
166
			break;
167 41997fbb Ermal Luci
		case 'igmpproxy':
168
			killbyname("igmpproxy");
169
			break;
170 422e039b Scott Ullrich
		case 'miniupnpd':
171 431484c8 Ryan Wagoner
			upnp_action('stop');
172 25b66ec5 Scott Ullrich
			break;
173 9e226d16 Scott Ullrich
		case 'openntpd':
174
			killbyname("openntpd");
175 cd72ded3 Timo Boettcher
			break;
176
		case 'sshd':
177 25b66ec5 Scott Ullrich
			killbyname("sshd");
178 cd72ded3 Timo Boettcher
			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 422e039b Scott Ullrich
		default:
193 cd72ded3 Timo Boettcher
			stop_service($_GET['service']);
194 422e039b Scott Ullrich
			break;
195
	}
196 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
197
	sleep(5);
198 a0e4cea2 Scott Ullrich
}
199
200
/* batch mode, allow other scripts to call this script */
201 b9eadc0c Colin Smith
if($_GET['batch']) exit;
202
203 d88c6a9f Scott Ullrich
$pgtitle = array("Status","Services");
204 4df96eff Scott Ullrich
include("head.inc");
205
206 a0e4cea2 Scott Ullrich
?>
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 0f10aee4 Bill Marquette
<div id="boxarea">
218 3473bb6a Scott Ullrich
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
219 a9bc3b82 Scott Ullrich
  <tr>
220 0f10aee4 Bill Marquette
    <td>
221 a9bc3b82 Scott Ullrich
    <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 a0e4cea2 Scott Ullrich
<?php
229
230 3af54e48 Scott Ullrich
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
231 ef09107d Colin Smith
array_shift($psout);
232
foreach($psout as $line) {
233
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
234
}
235
236 7670e4d2 Scott Ullrich
$services = $config['installedpackages']['service'];
237 25d3fbd5 Scott Ullrich
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 7670e4d2 Scott Ullrich
	unset($pconfig);
246 25d3fbd5 Scott Ullrich
}
247
248 f4c155cd Scott Ullrich
$pconfig['name'] = "ntpd";
249 9e226d16 Scott Ullrich
$pconfig['description'] = "NTP clock sync";
250
$services[] = $pconfig;
251
unset($pconfig);
252
253 25d3fbd5 Scott Ullrich
if(isset($config['captiveportal']['enable'])) {
254 a17d277c Scott Ullrich
	$pconfig['name'] = "lighttpd";
255 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "Captive Portal";
256
	$services[] = $pconfig;
257 7670e4d2 Scott Ullrich
	$pconfig = "";
258
	unset($pconfig);
259 25d3fbd5 Scott Ullrich
}
260
261 3e321df2 Ermal Luçi
$iflist = array();
262
$ifdescrs = get_configured_interface_list();
263
foreach ($ifdescrs as $if) {
264
	$oc = $config['interfaces'][$if];
265 7ec05d27 Ermal Luçi
	if ($oc['if'] && (!link_interface_to_bridge($if)))
266 3e321df2 Ermal Luçi
		$iflist[$if] = $if;
267 51bb9b94 Scott Ullrich
}
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 c214e575 Scott Ullrich
	$pconfig['name'] = "dhcrelay";
276 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "DHCP Relay";
277
	$services[] = $pconfig;
278 7670e4d2 Scott Ullrich
	unset($pconfig);
279 25d3fbd5 Scott Ullrich
}
280
281 3af54e48 Scott Ullrich
if(is_dhcp_server_enabled()) {
282 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "dhcpd";
283 967fcdd0 Scott Ullrich
	$pconfig['description'] = "DHCP Service";
284 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
285 7670e4d2 Scott Ullrich
	unset($pconfig);
286 25d3fbd5 Scott Ullrich
}
287
288
if(isset($config['snmpd']['enable'])) {
289
	$pconfig['name'] = "bsnmpd";
290 967fcdd0 Scott Ullrich
	$pconfig['description'] = "SNMP Service";
291 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
292 7670e4d2 Scott Ullrich
	unset($pconfig);
293 25d3fbd5 Scott Ullrich
}
294
295 41997fbb Ermal Luci
if (count($config['igmpproxy']['igmpentry']) > 0) {
296
	$pconfig['name'] = "igmpproxy";
297
	$pconfig['descritption'] = "IGMP proxy";
298
	$services[] = $pconfig;
299
	unset($pconfig);
300
}
301
302 422e039b Scott Ullrich
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
303 cd72ded3 Timo Boettcher
	$pconfig['name'] = "miniupnpd";
304
	$pconfig['description'] = gettext("UPnP Service");
305
	$services[] = $pconfig;
306
	unset($pconfig);
307 422e039b Scott Ullrich
}
308
309 25b66ec5 Scott Ullrich
if (isset($config['ipsec']['enable'])) {
310 cd72ded3 Timo Boettcher
	$pconfig['name'] = "racoon";
311 0f266b2e Chris Buechler
	$pconfig['description'] = gettext("IPsec VPN");
312 cd72ded3 Timo Boettcher
	$services[] = $pconfig;
313
	unset($pconfig);
314 25b66ec5 Scott Ullrich
}
315
316 cd72ded3 Timo Boettcher
foreach (array('server', 'client') as $mode) {
317
	if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
318
		foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
319
			$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
320
			if (!$setting['disable']) {
321
				$pconfig['name'] = "openvpn";
322
				$pconfig['mode'] = $mode;
323
				$pconfig['id'] = $id;
324
				$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
325
				$services[] = $pconfig;
326
				unset($pconfig);
327
			}
328
		}
329
	}
330
}
331
 
332
 
333 25d3fbd5 Scott Ullrich
if($services) {
334
	foreach($services as $service) {
335 b9eadc0c Colin Smith
		if(!$service['name']) continue;
336 5d8bcb27 Scott Ullrich
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
337 b9eadc0c Colin Smith
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
338 271b638f Scott Ullrich
		echo '<td class="listr">' . $service['description'] . '</td>';
339 cd72ded3 Timo Boettcher
		if ($service['name'] == "openvpn") {
340
			$running =  (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
341
		} else {
342
			$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
343
		}
344
		if($running) {
345 4fd12c25 Scott Ullrich
			echo '<td class="listr"><center>';
346
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
347 b9eadc0c Colin Smith
		} else {
348 4fd12c25 Scott Ullrich
			echo '<td class="listbg"><center>';
349
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
350 b9eadc0c Colin Smith
		}
351 ef09107d Colin Smith
		echo '<td valign="middle" class="list" nowrap>';
352 b9eadc0c Colin Smith
		if($running) {
353 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
354
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
355
			} else {
356
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
357
			}
358 677c0869 Erik Kristensen
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
359 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
360
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
361
			} else {
362
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
363
			}
364 677c0869 Erik Kristensen
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
365 b9eadc0c Colin Smith
			echo "</a>";
366 a0e4cea2 Scott Ullrich
		} else {
367 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
368
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
369
			} else { 
370
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
371
			}
372
			
373 677c0869 Erik Kristensen
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
374 a0e4cea2 Scott Ullrich
		}
375 ef09107d Colin Smith
		echo '</td>';
376 b9eadc0c Colin Smith
		echo '</tr>';
377 a0e4cea2 Scott Ullrich
	}
378 b9eadc0c Colin Smith
} else {
379
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
380
}
381 cd72ded3 Timo Boettcher
382 a0e4cea2 Scott Ullrich
?>
383
</table>
384
385 a9bc3b82 Scott Ullrich
</td>
386
</tr></table>
387 12af52d9 Scott Ullrich
</div>
388 a9bc3b82 Scott Ullrich
389 a0e4cea2 Scott Ullrich
<?php include("fend.inc"); ?>
390
</body>
391
</html>