Project

General

Profile

Download (9.86 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
if($_POST)
58
	conf_mount_rw();
59

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

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

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

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

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

    
323
<?php
324

    
325
if($_POST)
326
	conf_mount_ro();
327

    
328
?>
(39-39/217)