Project

General

Profile

Download (9.83 KB) Statistics
| Branch: | Tag: | Revision:
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
    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
*/
30

    
31
##|+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
require("guiconfig.inc");
40

    
41
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
	header("Content-Disposition: attachment; filename=\"" .
47
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
48

    
49
	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

    
57
conf_mount_rw();
58

    
59
// 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
$pgtitle = array("Diagnostics","Execute command");
82
include("head.inc");
83
?>
84

    
85
<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

    
111
   // 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

    
127
		  // 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
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
210
<?php include("fbegin.inc"); ?>
211
<?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

    
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
?>
240
<div id="niftyOutter">
241
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
242
  <table>
243
	<tr>
244
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
245
	</tr>  
246
    <tr>
247
      <td class="label" align="right">Command:</td>
248
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
249
    </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
	<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
    <tr>
267
      <td align="right">File to download:</td>
268
      <td>
269
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50">
270
	</td></tr>
271
    <tr>
272
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
273
      <td valign="top" class="label">	
274
        <input name="submit" type="submit"  class="button" id="download" value="Download">
275
        </td>
276
    </tr>
277
	<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
    <tr>
284
      <td align="right">File to upload:</td>
285
      <td valign="top" class="label">
286
	<input name="ulfile" type="file" class="formfld file" id="ulfile">
287
	</td></tr>
288
    <tr>
289
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
290
      <td valign="top" class="label">	
291
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
292
    </tr>
293
	<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
		<td align="right">Command:</td>
301
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
302
	</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
	 <strong>Example:</strong>   interfaces_carp_configure();
309
      </td>
310
    </tr>
311
    
312
  </table>
313
</div>
314
<?php include("fend.inc"); ?>
315
</form>
316
<script language="Javascript">
317
document.forms[0].txtCommand.focus();
318
</script>
319
</body>
320
</html>
321

    
322
<?php
323

    
324
conf_mount_ro();
325

    
326
?>
(33-33/206)