Project

General

Profile

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