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

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

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

    
72
// Leave GET enabled in case any other pages use it.
73
// ToDo: Check other pages and remove GET completely
74
if(!$_GET && $_POST)
75
	$_GET = $_POST;
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">
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
		if (empty($service['description'])) {
145
			$service['description'] = get_pkg_descr($service['name']);
146
		}
147
?>
148
					<tr>
149
						<td>
150
							<?=$service['name']?>
151
						</td>
152

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

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

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

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

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

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

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

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

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

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

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

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