Project

General

Profile

Download (10.9 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
require_once("vpn.inc");
43

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

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

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

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

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

    
203
/* batch mode, allow other scripts to call this script */
204
if($_GET['batch']) exit;
205

    
206
$pgtitle = array("Status","Services");
207
include("head.inc");
208

    
209
?>
210

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

    
218
<p>
219

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

    
231
<?php
232

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

    
239
$services = $config['installedpackages']['service'];
240

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

    
251
$pconfig['name'] = "ntpd";
252
$pconfig['description'] = "NTP clock sync";
253
$services[] = $pconfig;
254
unset($pconfig);
255

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

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

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

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

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

    
298
if (count($config['igmpproxy']['igmpentry']) > 0) {
299
	$pconfig['name'] = "igmpproxy";
300
	$pconfig['descritption'] = "IGMP proxy";
301
	$services[] = $pconfig;
302
	unset($pconfig);
303
}
304

    
305
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
306
	$pconfig['name'] = "miniupnpd";
307
	$pconfig['description'] = gettext("UPnP Service");
308
	$services[] = $pconfig;
309
	unset($pconfig);
310
}
311

    
312
if (isset($config['ipsec']['enable'])) {
313
	$pconfig['name'] = "racoon";
314
	$pconfig['description'] = gettext("IPsec VPN");
315
	$services[] = $pconfig;
316
	unset($pconfig);
317
}
318

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

    
385
?>
386
</table>
387

    
388
</td>
389
</tr></table>
390
</div>
391

    
392
<?php include("fend.inc"); ?>
393
</body>
394
</html>
(161-161/215)