Project

General

Profile

Download (9.88 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
	pfSense_MODULE:	shell
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-diagnostics-command
36
##|*NAME=Diagnostics: Command page
37
##|*DESCR=Allow access to the 'Diagnostics: Command' page.
38
##|*MATCH=exec.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42

    
43
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
44
	session_cache_limiter('public');
45
	$fd = fopen($_POST['dlPath'], "rb");
46
	header("Content-Type: application/octet-stream");
47
	header("Content-Length: " . filesize($_POST['dlPath']));
48
	header("Content-Disposition: attachment; filename=\"" .
49
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
50

    
51
	fpassthru($fd);
52
	exit;
53
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
54
	move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
55
	$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
56
	unset($_POST['txtCommand']);
57
}
58

    
59
if($_POST)
60
	conf_mount_rw();
61

    
62
// Function: is Blank
63
// Returns true or false depending on blankness of argument.
64

    
65
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
66

    
67

    
68
// Function: Puts
69
// Put string, Ruby-style.
70

    
71
function puts( $arg ) { echo "$arg\n"; }
72

    
73

    
74
// "Constants".
75

    
76
$Version    = '';
77
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
78

    
79
// Get year.
80

    
81
$arrDT   = localtime();
82
$intYear = $arrDT[5] + 1900;
83

    
84
$pgtitle = array("Diagnostics","Execute command");
85
include("head.inc");
86
?>
87

    
88
<script language="javascript">
89
<!--
90

    
91
   // Create recall buffer array (of encoded strings).
92

    
93
<?php
94

    
95
if (isBlank( $_POST['txtRecallBuffer'] )) {
96
   puts( "   var arrRecallBuffer = new Array;" );
97
} else {
98
   puts( "   var arrRecallBuffer = new Array(" );
99
   $arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
100
   for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( "      '" . $arrBuffer[$i] . "'," );
101
   puts( "      '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
102
   puts( "   );" );
103
}
104

    
105
?>
106

    
107
   // Set pointer to end of recall buffer.
108
   var intRecallPtr = arrRecallBuffer.length-1;
109

    
110
   // Functions to extend String class.
111
   function str_encode() { return escape( this ) }
112
   function str_decode() { return unescape( this ) }
113

    
114
   // Extend string class to include encode() and decode() functions.
115
   String.prototype.encode = str_encode
116
   String.prototype.decode = str_decode
117

    
118
   // Function: is Blank
119
   // Returns boolean true or false if argument is blank.
120
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
121

    
122
   // Function: frmExecPlus onSubmit (event handler)
123
   // Builds the recall buffer from the command string on submit.
124
   function frmExecPlus_onSubmit( form ) {
125

    
126
      if (!isBlank(form.txtCommand.value)) {
127
		  // If this command is repeat of last command, then do not store command.
128
		  if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
129

    
130
		  // Stuff encoded command string into the recall buffer.
131
		  if (isBlank(form.txtRecallBuffer.value))
132
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
133
		  else
134
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
135
	  }
136

    
137
      return true;
138
   }
139

    
140
   // Function: btnRecall onClick (event handler)
141
   // Recalls command buffer going either up or down.
142
   function btnRecall_onClick( form, n ) {
143

    
144
      // If nothing in recall buffer, then error.
145
      if (!arrRecallBuffer.length) {
146
         alert( 'Nothing to recall!' );
147
         form.txtCommand.focus();
148
         return;
149
      }
150

    
151
      // Increment recall buffer pointer in positive or negative direction
152
      // according to <n>.
153
      intRecallPtr += n;
154

    
155
      // Make sure the buffer stays circular.
156
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
157
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
158

    
159
      // Recall the command.
160
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
161
   }
162

    
163
   // Function: Reset onClick (event handler)
164
   // Resets form on reset button click event.
165
   function Reset_onClick( form ) {
166

    
167
      // Reset recall buffer pointer.
168
      intRecallPtr = arrRecallBuffer.length;
169

    
170
      // Clear form (could have spaces in it) and return focus ready for cmd.
171
      form.txtCommand.value = '';
172
      form.txtCommand.focus();
173

    
174
      return true;
175
   }
176
//-->
177
</script>
178
<style>
179
<!--
180

    
181
input {
182
   font-family: courier new, courier;
183
   font-weight: normal;
184
   font-size: 9pt;
185
}
186

    
187
pre {
188
   border: 2px solid #435370;
189
   background: #F0F0F0;
190
   padding: 1em;
191
   font-family: courier new, courier;
192
   white-space: pre;
193
   line-height: 10pt;
194
   font-size: 10pt;
195
}
196

    
197
.label {
198
   font-family: tahoma, verdana, arial, helvetica;
199
   font-size: 11px;
200
   font-weight: bold;
201
}
202

    
203
.button {
204
   font-family: tahoma, verdana, arial, helvetica;
205
   font-weight: bold;
206
   font-size: 11px;
207
}
208

    
209
-->
210
</style>
211
</head>
212
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
213
<?php include("fbegin.inc"); ?>
214
<?php if (isBlank($_POST['txtCommand'])): ?>
215
<p class="red"><strong>Note: this function is unsupported. Use it
216
on your own risk!</strong></p>
217
<?php endif; ?>
218
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
219
<?php
220

    
221
if (!isBlank($_POST['txtCommand'])) {
222
   puts("<pre>");
223
   puts("\$ " . htmlspecialchars($_POST['txtCommand']));
224
   putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
225
   putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
226
   $ph = popen($_POST['txtCommand'], "r" );
227
   while ($line = fgets($ph)) echo htmlspecialchars($line);
228
   pclose($ph);
229
   puts("</pre>");
230
}
231

    
232

    
233
if (!isBlank($_POST['txtPHPCommand'])) {
234
   puts("<pre>");
235
   require_once("config.inc");
236
   require_once("functions.inc");
237
   echo eval($_POST['txtPHPCommand']);
238
   puts("</pre>");
239
}
240

    
241
?>
242
<div id="niftyOutter">
243
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
244
  <table>
245
	<tr>
246
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
247
	</tr>  
248
    <tr>
249
      <td class="label" align="right">Command:</td>
250
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
251
    </tr>
252
    <tr>
253
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
254
      <td valign="top" class="label">
255
         <input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
256
         <input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
257
         <input type="submit" class="button" value="Execute">
258
         <input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form,  1 );">
259
         <input type="button"  class="button" value="Clear" onClick="return Reset_onClick( this.form );">
260
      </td>
261
    </tr>
262
	<tr>
263
	  <td colspan="2" valign="top" height="16"></td>
264
	</tr>
265
	<tr>
266
	  <td colspan="2" valign="top" class="vnsepcell">Download</td>
267
	</tr>    
268
    <tr>
269
      <td align="right">File to download:</td>
270
      <td>
271
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50">
272
	</td></tr>
273
    <tr>
274
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
275
      <td valign="top" class="label">	
276
        <input name="submit" type="submit"  class="button" id="download" value="Download">
277
        </td>
278
    </tr>
279
	<tr>
280
	  <td colspan="2" valign="top" height="16"></td>
281
	</tr>
282
	<tr>
283
	  <td colspan="2" valign="top" class="vnsepcell">Upload</td>
284
	</tr>    
285
    <tr>
286
      <td align="right">File to upload:</td>
287
      <td valign="top" class="label">
288
	<input name="ulfile" type="file" class="formfld file" id="ulfile">
289
	</td></tr>
290
    <tr>
291
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
292
      <td valign="top" class="label">	
293
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
294
    </tr>
295
	<tr>
296
	  <td colspan="2" valign="top" height="16"></td>
297
	</tr>
298
	<tr>
299
	  <td colspan="2" valign="top" class="vnsepcell">PHP Execute</td>
300
	</tr>
301
	<tr>
302
		<td align="right">Command:</td>
303
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
304
	</tr>
305
    <tr>
306
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
307
      <td valign="top" class="label">
308
         <input type="submit" class="button" value="Execute">
309
	 <p>
310
	 <strong>Example:</strong>   interfaces_carp_configure();
311
      </td>
312
    </tr>
313
    
314
  </table>
315
</div>
316
<?php include("fend.inc"); ?>
317
</form>
318
<script language="Javascript">
319
document.forms[0].txtCommand.focus();
320
</script>
321
</body>
322
</html>
323

    
324
<?php
325

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

    
329
?>
(41-41/216)