Project

General

Profile

Download (8.62 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
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

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

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

    
95
	sleep(5);
96
}
97

    
98

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

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

    
107
if ($savemsg) {
108
	print_info_box($savemsg, 'success');
109
}
110

    
111
$services = get_services();
112

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

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

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

    
139
	uasort($services, "service_name_compare");
140

    
141
	foreach ($services as $service) {
142
		if (empty($service['name'])) {
143
			continue;
144
		}
145

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

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

    
163
		if (get_service_status($service)) {
164
			$running = true;
165
		}
166
?>
167
						<td>
168
							<?=$running ? '<span class="text-success">Running</span>':'<span class="text-danger">Stopped</span>'?>
169
						</td>
170
						<td>
171
							<?=get_service_control_links($service)?>
172

    
173
<?php
174
		$scut = get_shortcut_by_service_name($service['name']);
175

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

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

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

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

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

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

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

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

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