Project

General

Profile

Download (8.51 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
##|+PRIV
57
##|*IDENT=page-status-services
58
##|*NAME=Status: Services
59
##|*DESCR=Allow access to the 'Status: Services' page.
60
##|*MATCH=status_services.php*
61
##|-PRIV
62

    
63
require_once("guiconfig.inc");
64
require_once("service-utils.inc");
65
require_once("shortcuts.inc");
66

    
67
// Leave GET enabled in case any other pages use it.
68
// ToDo: Check other pages and remove GET completely
69
if (!$_GET && $_POST) {
70
	$_GET = $_POST;
71
}
72

    
73
$service_name = '';
74
if (isset($_GET['service'])) {
75
	$service_name = htmlspecialchars($_GET['service']);
76
}
77

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

    
91
	sleep(5);
92
}
93

    
94

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

    
100
$pgtitle = array(gettext("Status"), gettext("Services"));
101
include("head.inc");
102

    
103
if ($savemsg) {
104
	print_info_box($savemsg, 'success');
105
}
106

    
107
$services = get_services();
108

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

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

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

    
135
	uasort($services, "service_name_compare");
136

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

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

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

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

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

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

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

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

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

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

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

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

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

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