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