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 panel-default">
|
122
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Services')?></h2></div>
|
123
|
<div class="panel-body">
|
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">' . gettext("Running") . '</span>':'<span class="text-danger">' . gettext("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
|
|
192
|
</div>
|
193
|
</div>
|
194
|
|
195
|
</form>
|
196
|
<?php
|
197
|
} else {
|
198
|
print_info_box(gettext("No services found"), 'danger');
|
199
|
}
|
200
|
?>
|
201
|
<script type="text/javascript">
|
202
|
//<![CDATA[
|
203
|
events.push(function() {
|
204
|
// If a restart button is clicked, populate the hidden inputs and submit the form (via POST)
|
205
|
$('[id^=restartservice-]').click(function(event) {
|
206
|
$('#mode').val('restartservice');
|
207
|
$('#service').val(this.id.replace("restartservice-", ""));
|
208
|
$(this).parents('form').submit();
|
209
|
});
|
210
|
|
211
|
// If a stop button is clicked, populate the hidden inputs and submit the form (via POST)
|
212
|
$('[id^=stopservice-]').click(function(event) {
|
213
|
$('#mode').val('stopservice');
|
214
|
$('#service').val(this.id.replace("stopservice-", ""));
|
215
|
$(this).parents('form').submit();
|
216
|
});
|
217
|
|
218
|
// If a start button is clicked, populate the hidden inputs and submit the form (via POST)
|
219
|
$('[id^=startservice-]').click(function(event) {
|
220
|
$('#mode').val('startservice');
|
221
|
$('#service').val(this.id.replace("startservice-", ""));
|
222
|
$(this).parents('form').submit();
|
223
|
});
|
224
|
|
225
|
// If an openvpn start button is clicked, populate the hidden inputs and submit the form (via POST)
|
226
|
$('[id^=openvpn-startservice-]').click(function(event) {
|
227
|
var args = this.id.split('-');
|
228
|
$('#mode').val('startservice');
|
229
|
$('#service').val('openvpn');
|
230
|
$('#id').val(args[3]);
|
231
|
$('#vpnmode').val(args[2]);
|
232
|
$(this).parents('form').submit();
|
233
|
});
|
234
|
|
235
|
// If an openvpn restart button is clicked, populate the hidden inputs and submit the form (via POST)
|
236
|
$('[id^=openvpn-restartservice-]').click(function(event) {
|
237
|
var args = this.id.split('-');
|
238
|
$('#mode').val('restartservice');
|
239
|
$('#service').val('openvpn');
|
240
|
$('#id').val(args[3]);
|
241
|
$('#vpnmode').val(args[2]);
|
242
|
$(this).parents('form').submit();
|
243
|
});
|
244
|
|
245
|
// If an openvpn stop button is clicked, populate the hidden inputs and submit the form (via POST)
|
246
|
$('[id^=openvpn-stopservice-]').click(function(event) {
|
247
|
var args = this.id.split('-');
|
248
|
$('#mode').val('stopservice');
|
249
|
$('#service').val('openvpn');
|
250
|
$('#id').val(args[3]);
|
251
|
$('#vpnmode').val(args[2]);
|
252
|
$(this).parents('form').submit();
|
253
|
});
|
254
|
|
255
|
// If a captiveportal start button is clicked, populate the hidden inputs and submit the form (via POST)
|
256
|
$('[id^=captiveportal-startservice-]').click(function(event) {
|
257
|
var args = this.id.split('-');
|
258
|
$('#mode').val('startservice');
|
259
|
$('#service').val('captiveportal');
|
260
|
$('#zone').val(args[2]);
|
261
|
$(this).parents('form').submit();
|
262
|
});
|
263
|
|
264
|
// If a captiveportal restart button is clicked, populate the hidden inputs and submit the form (via POST)
|
265
|
$('[id^=captiveportal-restartservice-]').click(function(event) {
|
266
|
var args = this.id.split('-');
|
267
|
$('#mode').val('restartservice');
|
268
|
$('#service').val('captiveportal');
|
269
|
$('#zone').val(args[2]);
|
270
|
$(this).parents('form').submit();
|
271
|
});
|
272
|
|
273
|
// If a captiveportal stop button is clicked, populate the hidden inputs and submit the form (via POST)
|
274
|
$('[id^=captiveportal-stopservice-]').click(function(event) {
|
275
|
var args = this.id.split('-');
|
276
|
$('#mode').val('stopservice');
|
277
|
$('#service').val('captiveportal');
|
278
|
$('#zone').val(args[2]);
|
279
|
$(this).parents('form').submit();
|
280
|
});
|
281
|
});
|
282
|
//]]>
|
283
|
</script>
|
284
|
<?php
|
285
|
include("foot.inc");
|