Project

General

Profile

Download (9.96 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
	header("Pragma: private");
51
	header("Cache-Control: private, must-revalidate");
52

    
53
	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

    
61
if($_POST)
62
	conf_mount_rw();
63

    
64
// 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
$pgtitle = array("Diagnostics","Execute command");
87
include("head.inc");
88
?>
89

    
90
<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

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

    
132
		  // 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
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
215
<?php include("fbegin.inc"); ?>
216
<?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

    
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
?>
244
<div id="niftyOutter">
245
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
246
  <table>
247
	<tr>
248
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
249
	</tr>  
250
    <tr>
251
      <td class="label" align="right">Command:</td>
252
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
253
    </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
	<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
    <tr>
271
      <td align="right">File to download:</td>
272
      <td>
273
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50">
274
	</td></tr>
275
    <tr>
276
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
277
      <td valign="top" class="label">	
278
        <input name="submit" type="submit"  class="button" id="download" value="Download">
279
        </td>
280
    </tr>
281
	<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
    <tr>
288
      <td align="right">File to upload:</td>
289
      <td valign="top" class="label">
290
	<input name="ulfile" type="file" class="formfld file" id="ulfile">
291
	</td></tr>
292
    <tr>
293
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
294
      <td valign="top" class="label">	
295
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
296
    </tr>
297
	<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
		<td align="right">Command:</td>
305
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
306
	</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
	 <strong>Example:</strong>   interfaces_carp_setup();
313
      </td>
314
    </tr>
315
    
316
  </table>
317
</div>
318
<?php include("fend.inc"); ?>
319
</form>
320
<script language="Javascript">
321
document.forms[0].txtCommand.focus();
322
</script>
323
</body>
324
</html>
325

    
326
<?php
327

    
328
if($_POST)
329
	conf_mount_ro();
330

    
331
?>
(42-42/215)