Project

General

Profile

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