Project

General

Profile

Download (10.1 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
	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

    
58
	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

    
66
if($_POST)
67
	conf_mount_rw();
68

    
69
// 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
$pgtitle = array("Diagnostics","Execute command");
92
include("head.inc");
93
?>
94

    
95
<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
   for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( "      '" . $arrBuffer[$i] . "'," );
108
   puts( "      '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
109
   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

    
121
   // 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

    
137
		  // 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
         alert( 'Nothing to recall!' );
154
         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
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220
<?php include("fbegin.inc"); ?>
221
<?php if (isBlank($_POST['txtCommand'])): ?>
222
<p class="red"><strong>Note: this function is unsupported. Use it
223
on your own risk!</strong></p>
224
<?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

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

    
331
<?php
332

    
333
if($_POST)
334
	conf_mount_ro();
335

    
336
?>
(42-42/221)