Project

General

Profile

Download (8.57 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_services.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10
 *
11
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13
 *
14
 *	2. Redistributions in binary form must reproduce the above copyright
15
 *		notice, this list of conditions and the following disclaimer in
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18
 *
19
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28
 *
29
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *	====================================================================
53
 *
54
 */
55
/*
56
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/openvpn /usr/bin/killall	/bin/ps
57
	pfSense_MODULE: services
58
*/
59

    
60
##|+PRIV
61
##|*IDENT=page-status-services
62
##|*NAME=Status: Services page
63
##|*DESCR=Allow access to the 'Status: Services' page.
64
##|*MATCH=status_services.php*
65
##|-PRIV
66

    
67
require_once("guiconfig.inc");
68
require_once("service-utils.inc");
69
require_once("shortcuts.inc");
70

    
71
// Leave GET enabled in case any other pages use it.
72
// ToDo: Check other pages and remove GET completely
73
if(!$_GET && $_POST)
74
	$_GET = $_POST;
75

    
76
$service_name = '';
77
if (isset($_GET['service'])) {
78
	$service_name = htmlspecialchars($_GET['service']);
79
}
80

    
81
if (!empty($service_name)) {
82
	switch ($_GET['mode']) {
83
		case "restartservice":
84
			$savemsg = service_control_restart($service_name, $_GET);
85
			break;
86
		case "startservice":
87
			$savemsg = service_control_start($service_name, $_GET);
88
			break;
89
		case "stopservice":
90
			$savemsg = service_control_stop($service_name, $_GET);
91
			break;
92
	}
93

    
94
	sleep(5);
95
}
96

    
97

    
98
/* batch mode, allow other scripts to call this script */
99
if ($_GET['batch']) {
100
	exit;
101
}
102

    
103
$pgtitle = array(gettext("Status"), gettext("Services"));
104
include("head.inc");
105

    
106
if ($savemsg)
107
	print_info_box($savemsg, 'success');
108

    
109
$services = get_services();
110

    
111
// $debugsvcs = array('name' => 'captiveportal', 'description' => 'Captive Portal', 'zone' => '14');
112
// array_push($services, $debugsvcs);
113

    
114
if (count($services) > 0) {
115
?>
116
<form action="status_services.php" method="post">
117
	<input id="mode" type="hidden" name="mode" value=""/>
118
	<input id="vpnmode" type="hidden" name="vpnmode" value=""/>
119
	<input id="service" type="hidden" name="service" value=""/>
120
	<input id="id" type="hidden" name="id" value=""/>
121
	<input id="zone" type="hidden" name="zone" value=""/>
122

    
123
	<div class="panel-body panel-default">
124
		<div class="table-responsive">
125
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
126
				<thead>
127
					<tr>
128
						<th><?=gettext("Service")?></th>
129
						<th><?=gettext("Description")?></th>
130
						<th><?=gettext("Status")?></th>
131
						<th><?=gettext("Actions")?></th>
132
					</tr>
133
				</thead>
134
				<tbody>
135
<?php
136

    
137
	uasort($services, "service_name_compare");
138

    
139
	foreach($services as $service) {
140
		if (empty($service['name']))
141
			continue;
142

    
143
		if (empty($service['description'])) {
144
			$service['description'] = get_pkg_descr($service['name']);
145
		}
146
?>
147
					<tr>
148
						<td>
149
							<?=$service['name']?>
150
						</td>
151

    
152
						<td>
153
							<?=$service['description']?>
154
						</td>
155
<?php
156
		// if service is running then listr else listbg
157
		$bgclass = null;
158
		$running = false;
159

    
160
		if (get_service_status($service)) {
161
			$running = true;
162
		}
163
?>
164
						<td>
165
							<?=$running ? '<font color="green">Running</font>':'<font color="red">Stopped</font>'?>
166
						</td>
167
						<td>
168
							<?=get_service_control_links($service)?>
169

    
170
<?php
171
		$scut = get_shortcut_by_service_name($service['name']);
172

    
173
		if (!empty($scut)) {
174
			echo get_shortcut_main_link($scut, true, $service);
175
			echo get_shortcut_status_link($scut, true, $service);
176
			echo get_shortcut_log_link($scut, true);
177
		}
178
?>
179
						</td>
180
					</tr>
181
<?php
182
	}
183
?>
184
				</tbody>
185
			</table>
186
		</div>
187
	</div>
188
</form>
189
<?php
190
} else {
191
	print_info_box(gettext("No services found"), 'danger');
192
}
193
?>
194
<script>
195
//<![CDATA[
196
events.push(function(){
197
	// If a restart button is clicked, populate the hidden inputs and submit the form (via POST)
198
	$('[id^=restartservice-]').click(function(event) {
199
		$('#mode').val('restartservice');
200
		$('#service').val(this.id.replace("restartservice-", ""));
201
		$(this).parents('form').submit();
202
	});
203

    
204
	// If a stop button is clicked, populate the hidden inputs and submit the form (via POST)
205
	$('[id^=stopservice-]').click(function(event) {
206
		$('#mode').val('stopservice');
207
		$('#service').val(this.id.replace("stopservice-", ""));
208
		$(this).parents('form').submit();
209
	});
210

    
211
	// If a start button is clicked, populate the hidden inputs and submit the form (via POST)
212
	$('[id^=startservice-]').click(function(event) {
213
		$('#mode').val('startservice');
214
		$('#service').val(this.id.replace("startservice-", ""));
215
		$(this).parents('form').submit();
216
	});
217

    
218
	// If an openvpn start button is clicked, populate the hidden inputs and submit the form (via POST)
219
	$('[id^=openvpn-startservice-]').click(function(event) {
220
		var args = this.id.split('-');
221
		$('#mode').val('startservice');
222
		$('#service').val('openvpn');
223
		$('#id').val(args[3]);
224
		$('#vpnmode').val(args[2]);
225
		$(this).parents('form').submit();
226
	});
227

    
228
	// If an openvpn restart button is clicked, populate the hidden inputs and submit the form (via POST)
229
	$('[id^=openvpn-restartservice-]').click(function(event) {
230
		var args = this.id.split('-');
231
		$('#mode').val('restartservice');
232
		$('#service').val('openvpn');
233
		$('#id').val(args[3]);
234
		$('#vpnmode').val(args[2]);
235
		$(this).parents('form').submit();
236
	});
237

    
238
	// If an openvpn stop button is clicked, populate the hidden inputs and submit the form (via POST)
239
	$('[id^=openvpn-stopservice-]').click(function(event) {
240
		var args = this.id.split('-');
241
		$('#mode').val('stopservice');
242
		$('#service').val('openvpn');
243
		$('#id').val(args[3]);
244
		$('#vpnmode').val(args[2]);
245
		$(this).parents('form').submit();
246
	});
247

    
248
	// If a captiveportal start button is clicked, populate the hidden inputs and submit the form (via POST)
249
	$('[id^=captiveportal-startservice-]').click(function(event) {
250
		var args = this.id.split('-');
251
		$('#mode').val('startservice');
252
		$('#service').val('captiveportal');
253
		$('#zone').val(args[2]);
254
		$(this).parents('form').submit();
255
	});
256

    
257
	// If a captiveportal restart button is clicked, populate the hidden inputs and submit the form (via POST)
258
	$('[id^=captiveportal-restartservice-]').click(function(event) {
259
		var args = this.id.split('-');
260
		$('#mode').val('restartservice');
261
		$('#service').val('captiveportal');
262
		$('#zone').val(args[2]);
263
		$(this).parents('form').submit();
264
	});
265

    
266
	// If a captiveportal stop button is clicked, populate the hidden inputs and submit the form (via POST)
267
	$('[id^=captiveportal-stopservice-]').click(function(event) {
268
		var args = this.id.split('-');
269
		$('#mode').val('stopservice');
270
		$('#service').val('captiveportal');
271
		$('#zone').val(args[2]);
272
		$(this).parents('form').submit();
273
	});
274
});
275
//]]>
276
</script>
277
<?php
278
include("foot.inc");
(184-184/235)