Project

General

Profile

Download (9.83 KB) Statistics
| Branch: | Tag: | Revision:
1 91bf75df Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 2900e518 Scott Ullrich
/*
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 6b07c15a Matthew Grooms
9
    Redistribution and use in source and binary forms, with or without
10
    modification, 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 the
17
       documentation and/or other materials provided with the distribution.
18
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29 2900e518 Scott Ullrich
*/
30
31 6b07c15a Matthew Grooms
##|+PRIV
32
##|*IDENT=page-diagnostics-command
33
##|*NAME=Diagnostics: Command page
34
##|*DESCR=Allow access to the 'Diagnostics: Command' page.
35
##|*MATCH=exec.php*
36
##|-PRIV
37
38
39 510e86d1 Scott Ullrich
require("guiconfig.inc");
40 458e0e0b Scott Ullrich
41 5b237745 Scott Ullrich
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
42
	session_cache_limiter('public');
43
	$fd = fopen($_POST['dlPath'], "rb");
44
	header("Content-Type: application/octet-stream");
45
	header("Content-Length: " . filesize($_POST['dlPath']));
46 be4b8e72 Scott Ullrich
	header("Content-Disposition: attachment; filename=\"" .
47 5b237745 Scott Ullrich
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
48 be4b8e72 Scott Ullrich
49 5b237745 Scott Ullrich
	fpassthru($fd);
50
	exit;
51
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
52
	move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
53
	$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
54
	unset($_POST['txtCommand']);
55
}
56 2900e518 Scott Ullrich
57 74285e13 Scott Ullrich
conf_mount_rw();
58
59 5b237745 Scott Ullrich
// Function: is Blank
60
// Returns true or false depending on blankness of argument.
61
62
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
63
64
65
// Function: Puts
66
// Put string, Ruby-style.
67
68
function puts( $arg ) { echo "$arg\n"; }
69
70
71
// "Constants".
72
73
$Version    = '';
74
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
75
76
// Get year.
77
78
$arrDT   = localtime();
79
$intYear = $arrDT[5] + 1900;
80
81 d88c6a9f Scott Ullrich
$pgtitle = array("Diagnostics","Execute command");
82 998abf60 Bill Marquette
include("head.inc");
83 5b237745 Scott Ullrich
?>
84 998abf60 Bill Marquette
85 5b237745 Scott Ullrich
<script language="javascript">
86
<!--
87
88
   // Create recall buffer array (of encoded strings).
89
90
<?php
91
92
if (isBlank( $_POST['txtRecallBuffer'] )) {
93
   puts( "   var arrRecallBuffer = new Array;" );
94
} else {
95
   puts( "   var arrRecallBuffer = new Array(" );
96
   $arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
97
   for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( "      '" . $arrBuffer[$i] . "'," );
98
   puts( "      '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
99
   puts( "   );" );
100
}
101
102
?>
103
104
   // Set pointer to end of recall buffer.
105
   var intRecallPtr = arrRecallBuffer.length-1;
106
107
   // Functions to extend String class.
108
   function str_encode() { return escape( this ) }
109
   function str_decode() { return unescape( this ) }
110 be4b8e72 Scott Ullrich
111 5b237745 Scott Ullrich
   // Extend string class to include encode() and decode() functions.
112
   String.prototype.encode = str_encode
113
   String.prototype.decode = str_decode
114
115
   // Function: is Blank
116
   // Returns boolean true or false if argument is blank.
117
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
118
119
   // Function: frmExecPlus onSubmit (event handler)
120
   // Builds the recall buffer from the command string on submit.
121
   function frmExecPlus_onSubmit( form ) {
122
123
      if (!isBlank(form.txtCommand.value)) {
124
		  // If this command is repeat of last command, then do not store command.
125
		  if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
126 be4b8e72 Scott Ullrich
127 5b237745 Scott Ullrich
		  // Stuff encoded command string into the recall buffer.
128
		  if (isBlank(form.txtRecallBuffer.value))
129
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
130
		  else
131
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
132
	  }
133
134
      return true;
135
   }
136
137
   // Function: btnRecall onClick (event handler)
138
   // Recalls command buffer going either up or down.
139
   function btnRecall_onClick( form, n ) {
140
141
      // If nothing in recall buffer, then error.
142
      if (!arrRecallBuffer.length) {
143
         alert( 'Nothing to recall!' );
144
         form.txtCommand.focus();
145
         return;
146
      }
147
148
      // Increment recall buffer pointer in positive or negative direction
149
      // according to <n>.
150
      intRecallPtr += n;
151
152
      // Make sure the buffer stays circular.
153
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
154
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
155
156
      // Recall the command.
157
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
158
   }
159
160
   // Function: Reset onClick (event handler)
161
   // Resets form on reset button click event.
162
   function Reset_onClick( form ) {
163
164
      // Reset recall buffer pointer.
165
      intRecallPtr = arrRecallBuffer.length;
166
167
      // Clear form (could have spaces in it) and return focus ready for cmd.
168
      form.txtCommand.value = '';
169
      form.txtCommand.focus();
170
171
      return true;
172
   }
173
//-->
174
</script>
175
<style>
176
<!--
177
178
input {
179
   font-family: courier new, courier;
180
   font-weight: normal;
181
   font-size: 9pt;
182
}
183
184
pre {
185
   border: 2px solid #435370;
186
   background: #F0F0F0;
187
   padding: 1em;
188
   font-family: courier new, courier;
189
   white-space: pre;
190
   line-height: 10pt;
191
   font-size: 10pt;
192
}
193
194
.label {
195
   font-family: tahoma, verdana, arial, helvetica;
196
   font-size: 11px;
197
   font-weight: bold;
198
}
199
200
.button {
201
   font-family: tahoma, verdana, arial, helvetica;
202
   font-weight: bold;
203
   font-size: 11px;
204
}
205
206
-->
207
</style>
208
</head>
209 998abf60 Bill Marquette
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
210
<?php include("fbegin.inc"); ?>
211 5b237745 Scott Ullrich
<?php if (isBlank($_POST['txtCommand'])): ?>
212
<p class="red"><strong>Note: this function is unsupported. Use it
213
on your own risk!</strong></p>
214
<?php endif; ?>
215
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
216
<?php
217
218
if (!isBlank($_POST['txtCommand'])) {
219
   puts("<pre>");
220
   puts("\$ " . htmlspecialchars($_POST['txtCommand']));
221
   putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
222
   putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
223
   $ph = popen($_POST['txtCommand'], "r" );
224
   while ($line = fgets($ph)) echo htmlspecialchars($line);
225
   pclose($ph);
226
   puts("</pre>");
227
}
228
229 fbcf0037 Scott Ullrich
230
if (!isBlank($_POST['txtPHPCommand'])) {
231
   puts("<pre>");
232
   require_once("config.inc");
233
   require_once("functions.inc");
234
   echo eval($_POST['txtPHPCommand']);
235
   puts("</pre>");
236
}
237
238
239 5b237745 Scott Ullrich
?>
240 ca8e4ed2 Scott Ullrich
<div id="niftyOutter">
241 f6f48dde Scott Ullrich
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
242 5b237745 Scott Ullrich
  <table>
243 fbcf0037 Scott Ullrich
	<tr>
244
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
245
	</tr>  
246 5b237745 Scott Ullrich
    <tr>
247
      <td class="label" align="right">Command:</td>
248 b5c78501 Seth Mos
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
249 5b237745 Scott Ullrich
    </tr>
250
    <tr>
251
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
252
      <td valign="top" class="label">
253
         <input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
254
         <input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
255
         <input type="submit" class="button" value="Execute">
256
         <input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form,  1 );">
257
         <input type="button"  class="button" value="Clear" onClick="return Reset_onClick( this.form );">
258
      </td>
259
    </tr>
260 fbcf0037 Scott Ullrich
	<tr>
261
	  <td colspan="2" valign="top" height="16"></td>
262
	</tr>
263
	<tr>
264
	  <td colspan="2" valign="top" class="vnsepcell">Download</td>
265
	</tr>    
266 5b237745 Scott Ullrich
    <tr>
267 fbcf0037 Scott Ullrich
      <td align="right">File to download:</td>
268 5b237745 Scott Ullrich
      <td>
269 b5c78501 Seth Mos
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50">
270 fbcf0037 Scott Ullrich
	</td></tr>
271
    <tr>
272
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
273
      <td valign="top" class="label">	
274 5b237745 Scott Ullrich
        <input name="submit" type="submit"  class="button" id="download" value="Download">
275
        </td>
276
    </tr>
277 fbcf0037 Scott Ullrich
	<tr>
278
	  <td colspan="2" valign="top" height="16"></td>
279
	</tr>
280
	<tr>
281
	  <td colspan="2" valign="top" class="vnsepcell">Upload</td>
282
	</tr>    
283 5b237745 Scott Ullrich
    <tr>
284 fbcf0037 Scott Ullrich
      <td align="right">File to upload:</td>
285 5b237745 Scott Ullrich
      <td valign="top" class="label">
286 b5c78501 Seth Mos
	<input name="ulfile" type="file" class="formfld file" id="ulfile">
287 fbcf0037 Scott Ullrich
	</td></tr>
288
    <tr>
289
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
290
      <td valign="top" class="label">	
291 5b237745 Scott Ullrich
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
292
    </tr>
293 fbcf0037 Scott Ullrich
	<tr>
294
	  <td colspan="2" valign="top" height="16"></td>
295
	</tr>
296
	<tr>
297
	  <td colspan="2" valign="top" class="vnsepcell">PHP Execute</td>
298
	</tr>
299
	<tr>
300 69fbe36f Scott Ullrich
		<td align="right">Command:</td>
301 2dc9ff46 Scott Ullrich
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
302 fbcf0037 Scott Ullrich
	</tr>
303
    <tr>
304
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
305
      <td valign="top" class="label">
306
         <input type="submit" class="button" value="Execute">
307
	 <p>
308 0e79d356 Scott Ullrich
	 <strong>Example:</strong>   interfaces_carp_configure();
309 fbcf0037 Scott Ullrich
      </td>
310
    </tr>
311
    
312 5b237745 Scott Ullrich
  </table>
313 ca8e4ed2 Scott Ullrich
</div>
314 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
315 5b237745 Scott Ullrich
</form>
316 be4b8e72 Scott Ullrich
<script language="Javascript">
317
document.forms[0].txtCommand.focus();
318
</script>
319 5b237745 Scott Ullrich
</body>
320
</html>
321 74285e13 Scott Ullrich
322
<?php
323
324
conf_mount_ro();
325
326 998abf60 Bill Marquette
?>