Project

General

Profile

Download (9.86 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 61a90ed5 Scott Ullrich
if($_POST)
58
	conf_mount_rw();
59 74285e13 Scott Ullrich
60 5b237745 Scott Ullrich
// Function: is Blank
61
// Returns true or false depending on blankness of argument.
62
63
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
64
65
66
// Function: Puts
67
// Put string, Ruby-style.
68
69
function puts( $arg ) { echo "$arg\n"; }
70
71
72
// "Constants".
73
74
$Version    = '';
75
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
76
77
// Get year.
78
79
$arrDT   = localtime();
80
$intYear = $arrDT[5] + 1900;
81
82 d88c6a9f Scott Ullrich
$pgtitle = array("Diagnostics","Execute command");
83 998abf60 Bill Marquette
include("head.inc");
84 5b237745 Scott Ullrich
?>
85 998abf60 Bill Marquette
86 5b237745 Scott Ullrich
<script language="javascript">
87
<!--
88
89
   // Create recall buffer array (of encoded strings).
90
91
<?php
92
93
if (isBlank( $_POST['txtRecallBuffer'] )) {
94
   puts( "   var arrRecallBuffer = new Array;" );
95
} else {
96
   puts( "   var arrRecallBuffer = new Array(" );
97
   $arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
98
   for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( "      '" . $arrBuffer[$i] . "'," );
99
   puts( "      '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
100
   puts( "   );" );
101
}
102
103
?>
104
105
   // Set pointer to end of recall buffer.
106
   var intRecallPtr = arrRecallBuffer.length-1;
107
108
   // Functions to extend String class.
109
   function str_encode() { return escape( this ) }
110
   function str_decode() { return unescape( this ) }
111 be4b8e72 Scott Ullrich
112 5b237745 Scott Ullrich
   // Extend string class to include encode() and decode() functions.
113
   String.prototype.encode = str_encode
114
   String.prototype.decode = str_decode
115
116
   // Function: is Blank
117
   // Returns boolean true or false if argument is blank.
118
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
119
120
   // Function: frmExecPlus onSubmit (event handler)
121
   // Builds the recall buffer from the command string on submit.
122
   function frmExecPlus_onSubmit( form ) {
123
124
      if (!isBlank(form.txtCommand.value)) {
125
		  // If this command is repeat of last command, then do not store command.
126
		  if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
127 be4b8e72 Scott Ullrich
128 5b237745 Scott Ullrich
		  // Stuff encoded command string into the recall buffer.
129
		  if (isBlank(form.txtRecallBuffer.value))
130
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
131
		  else
132
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
133
	  }
134
135
      return true;
136
   }
137
138
   // Function: btnRecall onClick (event handler)
139
   // Recalls command buffer going either up or down.
140
   function btnRecall_onClick( form, n ) {
141
142
      // If nothing in recall buffer, then error.
143
      if (!arrRecallBuffer.length) {
144
         alert( 'Nothing to recall!' );
145
         form.txtCommand.focus();
146
         return;
147
      }
148
149
      // Increment recall buffer pointer in positive or negative direction
150
      // according to <n>.
151
      intRecallPtr += n;
152
153
      // Make sure the buffer stays circular.
154
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
155
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
156
157
      // Recall the command.
158
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
159
   }
160
161
   // Function: Reset onClick (event handler)
162
   // Resets form on reset button click event.
163
   function Reset_onClick( form ) {
164
165
      // Reset recall buffer pointer.
166
      intRecallPtr = arrRecallBuffer.length;
167
168
      // Clear form (could have spaces in it) and return focus ready for cmd.
169
      form.txtCommand.value = '';
170
      form.txtCommand.focus();
171
172
      return true;
173
   }
174
//-->
175
</script>
176
<style>
177
<!--
178
179
input {
180
   font-family: courier new, courier;
181
   font-weight: normal;
182
   font-size: 9pt;
183
}
184
185
pre {
186
   border: 2px solid #435370;
187
   background: #F0F0F0;
188
   padding: 1em;
189
   font-family: courier new, courier;
190
   white-space: pre;
191
   line-height: 10pt;
192
   font-size: 10pt;
193
}
194
195
.label {
196
   font-family: tahoma, verdana, arial, helvetica;
197
   font-size: 11px;
198
   font-weight: bold;
199
}
200
201
.button {
202
   font-family: tahoma, verdana, arial, helvetica;
203
   font-weight: bold;
204
   font-size: 11px;
205
}
206
207
-->
208
</style>
209
</head>
210 998abf60 Bill Marquette
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
211
<?php include("fbegin.inc"); ?>
212 5b237745 Scott Ullrich
<?php if (isBlank($_POST['txtCommand'])): ?>
213
<p class="red"><strong>Note: this function is unsupported. Use it
214
on your own risk!</strong></p>
215
<?php endif; ?>
216
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
217
<?php
218
219
if (!isBlank($_POST['txtCommand'])) {
220
   puts("<pre>");
221
   puts("\$ " . htmlspecialchars($_POST['txtCommand']));
222
   putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
223
   putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
224
   $ph = popen($_POST['txtCommand'], "r" );
225
   while ($line = fgets($ph)) echo htmlspecialchars($line);
226
   pclose($ph);
227
   puts("</pre>");
228
}
229
230 fbcf0037 Scott Ullrich
231
if (!isBlank($_POST['txtPHPCommand'])) {
232
   puts("<pre>");
233
   require_once("config.inc");
234
   require_once("functions.inc");
235
   echo eval($_POST['txtPHPCommand']);
236
   puts("</pre>");
237
}
238
239
240 5b237745 Scott Ullrich
?>
241 ca8e4ed2 Scott Ullrich
<div id="niftyOutter">
242 f6f48dde Scott Ullrich
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
243 5b237745 Scott Ullrich
  <table>
244 fbcf0037 Scott Ullrich
	<tr>
245
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
246
	</tr>  
247 5b237745 Scott Ullrich
    <tr>
248
      <td class="label" align="right">Command:</td>
249 b5c78501 Seth Mos
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
250 5b237745 Scott Ullrich
    </tr>
251
    <tr>
252
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
253
      <td valign="top" class="label">
254
         <input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
255
         <input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
256
         <input type="submit" class="button" value="Execute">
257
         <input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form,  1 );">
258
         <input type="button"  class="button" value="Clear" onClick="return Reset_onClick( this.form );">
259
      </td>
260
    </tr>
261 fbcf0037 Scott Ullrich
	<tr>
262
	  <td colspan="2" valign="top" height="16"></td>
263
	</tr>
264
	<tr>
265
	  <td colspan="2" valign="top" class="vnsepcell">Download</td>
266
	</tr>    
267 5b237745 Scott Ullrich
    <tr>
268 fbcf0037 Scott Ullrich
      <td align="right">File to download:</td>
269 5b237745 Scott Ullrich
      <td>
270 b5c78501 Seth Mos
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50">
271 fbcf0037 Scott Ullrich
	</td></tr>
272
    <tr>
273
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
274
      <td valign="top" class="label">	
275 5b237745 Scott Ullrich
        <input name="submit" type="submit"  class="button" id="download" value="Download">
276
        </td>
277
    </tr>
278 fbcf0037 Scott Ullrich
	<tr>
279
	  <td colspan="2" valign="top" height="16"></td>
280
	</tr>
281
	<tr>
282
	  <td colspan="2" valign="top" class="vnsepcell">Upload</td>
283
	</tr>    
284 5b237745 Scott Ullrich
    <tr>
285 fbcf0037 Scott Ullrich
      <td align="right">File to upload:</td>
286 5b237745 Scott Ullrich
      <td valign="top" class="label">
287 b5c78501 Seth Mos
	<input name="ulfile" type="file" class="formfld file" id="ulfile">
288 fbcf0037 Scott Ullrich
	</td></tr>
289
    <tr>
290
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
291
      <td valign="top" class="label">	
292 5b237745 Scott Ullrich
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
293
    </tr>
294 fbcf0037 Scott Ullrich
	<tr>
295
	  <td colspan="2" valign="top" height="16"></td>
296
	</tr>
297
	<tr>
298
	  <td colspan="2" valign="top" class="vnsepcell">PHP Execute</td>
299
	</tr>
300
	<tr>
301 69fbe36f Scott Ullrich
		<td align="right">Command:</td>
302 2dc9ff46 Scott Ullrich
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
303 fbcf0037 Scott Ullrich
	</tr>
304
    <tr>
305
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
306
      <td valign="top" class="label">
307
         <input type="submit" class="button" value="Execute">
308
	 <p>
309 0e79d356 Scott Ullrich
	 <strong>Example:</strong>   interfaces_carp_configure();
310 fbcf0037 Scott Ullrich
      </td>
311
    </tr>
312
    
313 5b237745 Scott Ullrich
  </table>
314 ca8e4ed2 Scott Ullrich
</div>
315 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
316 5b237745 Scott Ullrich
</form>
317 be4b8e72 Scott Ullrich
<script language="Javascript">
318
document.forms[0].txtCommand.focus();
319
</script>
320 5b237745 Scott Ullrich
</body>
321
</html>
322 74285e13 Scott Ullrich
323
<?php
324
325 61a90ed5 Scott Ullrich
if($_POST)
326
	conf_mount_ro();
327 74285e13 Scott Ullrich
328 61a90ed5 Scott Ullrich
?>