1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
|
5
|
Created by technologEase (http://www.technologEase.com).
|
6
|
|
7
|
(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
|
8
|
|
9
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_MODULE: shell
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-diagnostics-command
|
38
|
##|*NAME=Diagnostics: Command page
|
39
|
##|*DESCR=Allow access to the 'Diagnostics: Command' page.
|
40
|
##|*MATCH=exec.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
$allowautocomplete = true;
|
44
|
|
45
|
require("guiconfig.inc");
|
46
|
|
47
|
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
|
48
|
session_cache_limiter('public');
|
49
|
$fd = fopen($_POST['dlPath'], "rb");
|
50
|
header("Content-Type: application/octet-stream");
|
51
|
header("Content-Length: " . filesize($_POST['dlPath']));
|
52
|
header("Content-Disposition: attachment; filename=\"" .
|
53
|
trim(htmlentities(basename($_POST['dlPath']))) . "\"");
|
54
|
if (isset($_SERVER['HTTPS'])) {
|
55
|
header('Pragma: ');
|
56
|
header('Cache-Control: ');
|
57
|
} else {
|
58
|
header("Pragma: private");
|
59
|
header("Cache-Control: private, must-revalidate");
|
60
|
}
|
61
|
|
62
|
fpassthru($fd);
|
63
|
exit;
|
64
|
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
|
65
|
move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
|
66
|
$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
|
67
|
unset($_POST['txtCommand']);
|
68
|
}
|
69
|
|
70
|
if($_POST)
|
71
|
conf_mount_rw();
|
72
|
|
73
|
// Function: is Blank
|
74
|
// Returns true or false depending on blankness of argument.
|
75
|
|
76
|
function isBlank( $arg ) { return preg_match( "/^\s*$/", $arg ); }
|
77
|
|
78
|
|
79
|
// Function: Puts
|
80
|
// Put string, Ruby-style.
|
81
|
|
82
|
function puts( $arg ) { echo "$arg\n"; }
|
83
|
|
84
|
|
85
|
// "Constants".
|
86
|
|
87
|
$Version = '';
|
88
|
$ScriptName = $REQUEST['SCRIPT_NAME'];
|
89
|
|
90
|
// Get year.
|
91
|
|
92
|
$arrDT = localtime();
|
93
|
$intYear = $arrDT[5] + 1900;
|
94
|
|
95
|
$closehead = false;
|
96
|
$pgtitle = array(gettext("Diagnostics"),gettext("Execute command"));
|
97
|
include("head.inc");
|
98
|
?>
|
99
|
<script>
|
100
|
// Create recall buffer array (of encoded strings).
|
101
|
<?php
|
102
|
|
103
|
if (isBlank( $_POST['txtRecallBuffer'] )) {
|
104
|
puts( " var arrRecallBuffer = new Array;" );
|
105
|
} else {
|
106
|
puts( " var arrRecallBuffer = new Array(" );
|
107
|
$arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
|
108
|
for ($i=0; $i < (count( $arrBuffer ) - 1); $i++)
|
109
|
puts( " '" . htmlspecialchars($arrBuffer[$i], ENT_QUOTES | ENT_HTML401) . "'," );
|
110
|
puts( " '" . htmlspecialchars($arrBuffer[count( $arrBuffer ) - 1], ENT_QUOTES | ENT_HTML401) . "'" );
|
111
|
puts( " );" );
|
112
|
}
|
113
|
?>
|
114
|
// Set pointer to end of recall buffer.
|
115
|
var intRecallPtr = arrRecallBuffer.length-1;
|
116
|
|
117
|
// Functions to extend String class.
|
118
|
function str_encode() { return escape( this ) }
|
119
|
function str_decode() { return unescape( this ) }
|
120
|
|
121
|
// Extend string class to include encode() and decode() functions.
|
122
|
String.prototype.encode = str_encode
|
123
|
String.prototype.decode = str_decode
|
124
|
|
125
|
// Function: is Blank
|
126
|
// Returns boolean true or false if argument is blank.
|
127
|
function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
|
128
|
|
129
|
// Function: frmExecPlus onSubmit (event handler)
|
130
|
// Builds the recall buffer from the command string on submit.
|
131
|
function frmExecPlus_onSubmit( form ) {
|
132
|
if (!isBlank(form.txtCommand.value)) {
|
133
|
// If this command is repeat of last command, then do not store command.
|
134
|
if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
|
135
|
|
136
|
// Stuff encoded command string into the recall buffer.
|
137
|
if (isBlank(form.txtRecallBuffer.value))
|
138
|
form.txtRecallBuffer.value = form.txtCommand.value.encode();
|
139
|
else
|
140
|
form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
|
141
|
}
|
142
|
|
143
|
return true;
|
144
|
}
|
145
|
|
146
|
// Function: btnRecall onClick (event handler)
|
147
|
// Recalls command buffer going either up or down.
|
148
|
function btnRecall_onClick( form, n ) {
|
149
|
|
150
|
// If nothing in recall buffer, then error.
|
151
|
if (!arrRecallBuffer.length) {
|
152
|
alert( '<?=gettext("Nothing to recall"); ?>!' );
|
153
|
form.txtCommand.focus();
|
154
|
return;
|
155
|
}
|
156
|
|
157
|
// Increment recall buffer pointer in positive or negative direction
|
158
|
// according to <n>.
|
159
|
intRecallPtr += n;
|
160
|
|
161
|
// Make sure the buffer stays circular.
|
162
|
if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
|
163
|
if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
|
164
|
|
165
|
// Recall the command.
|
166
|
form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
|
167
|
}
|
168
|
|
169
|
// Function: Reset onClick (event handler)
|
170
|
// Resets form on reset button click event.
|
171
|
function Reset_onClick( form ) {
|
172
|
|
173
|
// Reset recall buffer pointer.
|
174
|
intRecallPtr = arrRecallBuffer.length;
|
175
|
|
176
|
// Clear form (could have spaces in it) and return focus ready for cmd.
|
177
|
form.txtCommand.value = '';
|
178
|
form.txtCommand.focus();
|
179
|
|
180
|
return true;
|
181
|
}
|
182
|
//]]>
|
183
|
</script>
|
184
|
<?php
|
185
|
|
186
|
if (isBlank($_POST['txtCommand']) && isBlank($_POST['txtPHPCommand']) && isBlank($ulmsg))
|
187
|
print('<div class="alert alert-warning" role="alert">'.gettext("The capabilities offered here can be dangerous. No support is available. Use them at your own risk!").'</div>');
|
188
|
|
189
|
if (!isBlank($_POST['txtCommand'])):?>
|
190
|
<div class="panel panel-success responsive">
|
191
|
<div class="panel-heading">Shell Output - <?=htmlspecialchars($_POST['txtCommand'])?></div>
|
192
|
<div class="panel-body">
|
193
|
<pre>
|
194
|
<?php
|
195
|
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
|
196
|
putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));
|
197
|
print htmlspecialchars(system($_POST['txtCommand'].' 2>&1'));
|
198
|
?>
|
199
|
</pre>
|
200
|
</div>
|
201
|
</div>
|
202
|
<? endif ?>
|
203
|
|
204
|
<form action="exec.php" method="post" enctype="multipart/form-data" name="frmExecPlus" onsubmit="return frmExecPlus_onSubmit( this );">
|
205
|
<div class="panel panel-default">
|
206
|
<div class="panel-heading"><?=gettext('Execute Shell Command')?></div>
|
207
|
<div class="panel-body">
|
208
|
<input id="txtCommand" name="txtCommand" placeholder="Command" type="text" class="col-sm-4" value="<?=htmlspecialchars($_POST['txtCommand'])?>" />
|
209
|
<br /><br />
|
210
|
<input type="hidden" name="txtRecallBuffer" value="<?=htmlspecialchars($_POST['txtRecallBuffer']) ?>" />
|
211
|
<input type="button" class="btn btn-default btn-sm" name="btnRecallPrev" value="<" onclick="btnRecall_onClick( this.form, -1 );" />
|
212
|
<input type="submit" class="btn btn-default btn-sm" value="<?=gettext("Execute"); ?>" />
|
213
|
<input type="button" class="btn btn-default btn-sm" name="btnRecallNext" value=">" onclick="btnRecall_onClick( this.form, 1 );" />
|
214
|
<input type="button" class="btn btn-default btn-sm" value="<?=gettext("Clear"); ?>" onclick="return Reset_onClick( this.form );" />
|
215
|
</div>
|
216
|
</div>
|
217
|
|
218
|
<div class="panel panel-default">
|
219
|
<div class="panel-heading"><?=gettext('Download file')?></div>
|
220
|
<div class="panel-body">
|
221
|
<input name="dlPath" type="text" id="dlPath" placeholder="File to download" class="col-sm-4"/>
|
222
|
<br /><br />
|
223
|
<input name="submit" type="submit" class="btn btn-default btn-sm" id="download" value="<?=gettext("Download"); ?>" />
|
224
|
</div>
|
225
|
</div>
|
226
|
|
227
|
<?php
|
228
|
if ($ulmsg)
|
229
|
print('<div class="alert alert-success" role="alert">' . $ulmsg .'</div>');
|
230
|
?>
|
231
|
<div class="panel panel-default">
|
232
|
<div class="panel-heading"><?=gettext('Upload a file')?></div>
|
233
|
<div class="panel-body">
|
234
|
<input name="ulfile" type="file" class="btn btn-default btn-sm btn-file" id="ulfile" />
|
235
|
<br />
|
236
|
<input name="submit" type="submit" class="btn btn-default btn-sm pull-left" id="upload" value="<?=gettext("Upload"); ?>" />
|
237
|
|
238
|
</div>
|
239
|
</div>
|
240
|
<?php
|
241
|
if (!isBlank($_POST['txtPHPCommand'])) {
|
242
|
puts("<div class=\"panel panel-success responsive\"><div class=\"panel-heading\">PHP response</div>");
|
243
|
puts("<pre>");
|
244
|
require_once("config.inc");
|
245
|
require_once("functions.inc");
|
246
|
echo eval($_POST['txtPHPCommand']);
|
247
|
puts(" </pre>");
|
248
|
puts("</div>");
|
249
|
}
|
250
|
?>
|
251
|
<div class="panel panel-default responsive">
|
252
|
<div class="panel-heading"><?=gettext('Execute PHP Commands')?></div>
|
253
|
<div class="panel-body">
|
254
|
<textarea id="txtPHPCommand" placeholder="Command" name="txtPHPCommand" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand'])?></textarea>
|
255
|
<br />
|
256
|
<input type="submit" class="btn btn-default btn-sm" value="<?=gettext("Execute")?>" />
|
257
|
<?=gettext("Example"); ?>: <code>print("Hello World!");</code>
|
258
|
</div>
|
259
|
</div>
|
260
|
</form>
|
261
|
|
262
|
<?php
|
263
|
include("foot.inc");
|
264
|
|
265
|
if($_POST)
|
266
|
conf_mount_ro();
|