Project

General

Profile

Download (8.61 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
$services = get_services();
111

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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