Project

General

Profile

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