Project

General

Profile

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