Project

General

Profile

Download (8.58 KB) Statistics
| Branch: | Tag: | Revision:
1 a0e4cea2 Scott Ullrich
<?php
2
/*
3 ce77a9c4 Phil Davis
	status_services.php
4 a0e4cea2 Scott Ullrich
*/
5 74b0f23e Stephen Beaver
/* ====================================================================
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 517d3109 sbeaver
/*
56 74b0f23e Stephen Beaver
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/openvpn /usr/bin/killall	/bin/ps
57
	pfSense_MODULE: services
58 1d333258 Scott Ullrich
*/
59 a0e4cea2 Scott Ullrich
60 6b07c15a Matthew Grooms
##|+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 e3c88b77 Ermal
require_once("guiconfig.inc");
68 44173def Ermal Lu?i
require_once("service-utils.inc");
69 a517a108 jmkizer
require_once("shortcuts.inc");
70 a0e4cea2 Scott Ullrich
71 74b0f23e Stephen Beaver
// 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 2f9951fe Renato Botelho
$service_name = '';
77 42b0c921 Phil Davis
if (isset($_GET['service'])) {
78 2f9951fe Renato Botelho
	$service_name = htmlspecialchars($_GET['service']);
79 42b0c921 Phil Davis
}
80 2f9951fe Renato Botelho
81
if (!empty($service_name)) {
82 8b88ac79 jim-p
	switch ($_GET['mode']) {
83
		case "restartservice":
84 2f9951fe Renato Botelho
			$savemsg = service_control_restart($service_name, $_GET);
85 8b88ac79 jim-p
			break;
86
		case "startservice":
87 2f9951fe Renato Botelho
			$savemsg = service_control_start($service_name, $_GET);
88 8b88ac79 jim-p
			break;
89
		case "stopservice":
90 2f9951fe Renato Botelho
			$savemsg = service_control_stop($service_name, $_GET);
91 8b88ac79 jim-p
			break;
92
	}
93 517d3109 sbeaver
94 cd72ded3 Timo Boettcher
	sleep(5);
95 a0e4cea2 Scott Ullrich
}
96
97 74b0f23e Stephen Beaver
98 a0e4cea2 Scott Ullrich
/* batch mode, allow other scripts to call this script */
99 42b0c921 Phil Davis
if ($_GET['batch']) {
100 246a887a Ermal
	exit;
101 42b0c921 Phil Davis
}
102 b9eadc0c Colin Smith
103 6c07db48 Phil Davis
$pgtitle = array(gettext("Status"), gettext("Services"));
104 4df96eff Scott Ullrich
include("head.inc");
105
106 517d3109 sbeaver
if ($savemsg)
107
	print_info_box($savemsg, 'success');
108 a0e4cea2 Scott Ullrich
109 517d3109 sbeaver
$services = get_services();
110
111 74b0f23e Stephen Beaver
// $debugsvcs = array('name' => 'captiveportal', 'description' => 'Captive Portal', 'zone' => '14');
112
// array_push($services, $debugsvcs);
113
114 517d3109 sbeaver
if (count($services) > 0) {
115 a0e4cea2 Scott Ullrich
?>
116
<form action="status_services.php" method="post">
117 74b0f23e Stephen Beaver
	<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 517d3109 sbeaver
	<div class="panel-body panel-default">
124
		<div class="table-responsive">
125 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
126 517d3109 sbeaver
				<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 a0e4cea2 Scott Ullrich
<?php
136
137 b2254c7f jim-p
	uasort($services, "service_name_compare");
138 517d3109 sbeaver
139 25d3fbd5 Scott Ullrich
	foreach($services as $service) {
140 246a887a Ermal
		if (empty($service['name']))
141
			continue;
142 517d3109 sbeaver
143 74b0f23e Stephen Beaver
		if (empty($service['description'])) {
144 246a887a Ermal
			$service['description'] = get_pkg_descr($service['name']);
145 74b0f23e Stephen Beaver
		}
146 517d3109 sbeaver
?>
147
					<tr>
148
						<td>
149
							<?=$service['name']?>
150
						</td>
151
152
						<td>
153
							<?=$service['description']?>
154
						</td>
155
<?php
156 17b8c60a Colin Fleming
		// if service is running then listr else listbg
157
		$bgclass = null;
158 517d3109 sbeaver
		$running = false;
159
160 74b0f23e Stephen Beaver
		if (get_service_status($service)) {
161 517d3109 sbeaver
			$running = true;
162 74b0f23e Stephen Beaver
		}
163 517d3109 sbeaver
?>
164
						<td>
165 9c9617a5 Jared Dillard
							<?=$running ? '<span class="text-success">Running</span>':'<span class="text-danger">Stopped</span>'?>
166 517d3109 sbeaver
						</td>
167
						<td>
168
							<?=get_service_control_links($service)?>
169
170
<?php
171 391abfcf jim-p
		$scut = get_shortcut_by_service_name($service['name']);
172 517d3109 sbeaver
173 391abfcf jim-p
		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 517d3109 sbeaver
?>
179
						</td>
180
					</tr>
181
<?php
182 a0e4cea2 Scott Ullrich
	}
183 517d3109 sbeaver
?>
184
				</tbody>
185
			</table>
186
		</div>
187
	</div>
188
</form>
189
<?php
190 b9eadc0c Colin Smith
} else {
191 517d3109 sbeaver
	print_info_box(gettext("No services found"), 'danger');
192 b9eadc0c Colin Smith
}
193 74b0f23e Stephen Beaver
?>
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 cd72ded3 Timo Boettcher
211 74b0f23e Stephen Beaver
	// 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");