1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
<?php
/* $Id$ */
/*
Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
Created by technologEase (http://www.technologEase.com).
(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
*/
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
session_cache_limiter('public');
$fd = fopen($_POST['dlPath'], "rb");
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($_POST['dlPath']));
header("Content-Disposition: attachment; filename=\"" .
trim(htmlentities(basename($_POST['dlPath']))) . "\"");
fpassthru($fd);
exit;
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
unset($_POST['txtCommand']);
}
require("guiconfig.inc");
conf_mount_rw();
// Function: is Blank
// Returns true or false depending on blankness of argument.
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
// Function: Puts
// Put string, Ruby-style.
function puts( $arg ) { echo "$arg\n"; }
// "Constants".
$Version = '';
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
// Get year.
$arrDT = localtime();
$intYear = $arrDT[5] + 1900;
$pgtitle = "Diagnostics: Execute command";
include("head.inc");
?>
<script language="javascript">
<!--
// Create recall buffer array (of encoded strings).
<?php
if (isBlank( $_POST['txtRecallBuffer'] )) {
puts( " var arrRecallBuffer = new Array;" );
} else {
puts( " var arrRecallBuffer = new Array(" );
$arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( " '" . $arrBuffer[$i] . "'," );
puts( " '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
puts( " );" );
}
?>
// Set pointer to end of recall buffer.
var intRecallPtr = arrRecallBuffer.length-1;
// Functions to extend String class.
function str_encode() { return escape( this ) }
function str_decode() { return unescape( this ) }
// Extend string class to include encode() and decode() functions.
String.prototype.encode = str_encode
String.prototype.decode = str_decode
// Function: is Blank
// Returns boolean true or false if argument is blank.
function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
// Function: frmExecPlus onSubmit (event handler)
// Builds the recall buffer from the command string on submit.
function frmExecPlus_onSubmit( form ) {
if (!isBlank(form.txtCommand.value)) {
// If this command is repeat of last command, then do not store command.
if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
// Stuff encoded command string into the recall buffer.
if (isBlank(form.txtRecallBuffer.value))
form.txtRecallBuffer.value = form.txtCommand.value.encode();
else
form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
}
return true;
}
// Function: btnRecall onClick (event handler)
// Recalls command buffer going either up or down.
function btnRecall_onClick( form, n ) {
// If nothing in recall buffer, then error.
if (!arrRecallBuffer.length) {
alert( 'Nothing to recall!' );
form.txtCommand.focus();
return;
}
// Increment recall buffer pointer in positive or negative direction
// according to <n>.
intRecallPtr += n;
// Make sure the buffer stays circular.
if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
// Recall the command.
form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
}
// Function: Reset onClick (event handler)
// Resets form on reset button click event.
function Reset_onClick( form ) {
// Reset recall buffer pointer.
intRecallPtr = arrRecallBuffer.length;
// Clear form (could have spaces in it) and return focus ready for cmd.
form.txtCommand.value = '';
form.txtCommand.focus();
return true;
}
//-->
</script>
<style>
<!--
input {
font-family: courier new, courier;
font-weight: normal;
font-size: 9pt;
}
pre {
border: 2px solid #435370;
background: #F0F0F0;
padding: 1em;
font-family: courier new, courier;
white-space: pre;
line-height: 10pt;
font-size: 10pt;
}
.label {
font-family: tahoma, verdana, arial, helvetica;
font-size: 11px;
font-weight: bold;
}
.button {
font-family: tahoma, verdana, arial, helvetica;
font-weight: bold;
font-size: 11px;
}
-->
</style>
</head>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<p class="pgtitle"><?=$pgtitle?></p>
<?php if (isBlank($_POST['txtCommand'])): ?>
<p class="red"><strong>Note: this function is unsupported. Use it
on your own risk!</strong></p>
<?php endif; ?>
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
<?php
if (!isBlank($_POST['txtCommand'])) {
puts("<pre>");
puts("\$ " . htmlspecialchars($_POST['txtCommand']));
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " ")); /* PHP scripts */
$ph = popen($_POST['txtCommand'], "r" );
while ($line = fgets($ph)) echo htmlspecialchars($line);
pclose($ph);
puts("</pre>");
}
if (!isBlank($_POST['txtPHPCommand'])) {
puts("<pre>");
require_once("config.inc");
require_once("functions.inc");
echo eval($_POST['txtPHPCommand']);
puts("</pre>");
}
?>
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
<table>
<tr>
<td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
</tr>
<tr>
<td class="label" align="right">Command:</td>
<td class="type"><input id="txtCommand" name="txtCommand" type="text" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top" class="label">
<input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
<input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
<input type="submit" class="button" value="Execute">
<input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form, 1 );">
<input type="button" class="button" value="Clear" onClick="return Reset_onClick( this.form );">
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="16"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="vnsepcell">Download</td>
</tr>
<tr>
<td align="right">File to download:</td>
<td>
<input name="dlPath" type="text" id="dlPath" size="50">
</td></tr>
<tr>
<td valign="top"> </td>
<td valign="top" class="label">
<input name="submit" type="submit" class="button" id="download" value="Download">
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="16"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="vnsepcell">Upload</td>
</tr>
<tr>
<td align="right">File to upload:</td>
<td valign="top" class="label">
<input name="ulfile" type="file" class="button" id="ulfile">
</td></tr>
<tr>
<td valign="top"> </td>
<td valign="top" class="label">
<input name="submit" type="submit" class="button" id="upload" value="Upload"></td>
</tr>
<tr>
<td colspan="2" valign="top" height="16"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="vnsepcell">PHP Execute</td>
</tr>
<tr>
<td align="right">Command:</td>
<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="3" cols="50"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top" class="label">
<input type="submit" class="button" value="Execute">
<p>
<strong>Example:</strong> interfaces_carp_bring_up_final();
</td>
</tr>
</table>
<?php include("fend.inc"); ?>
</form>
<script language="Javascript">
document.forms[0].txtCommand.focus();
</script>
</body>
</html>
<?php
conf_mount_ro();
?>
|