Project

General

Profile

Download (10.7 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
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10

    
11
    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
*/
32
/*
33
	pfSense_MODULE:	shell
34
*/
35

    
36
##|+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
$allowautocomplete = true;
44

    
45
require("guiconfig.inc");
46

    
47
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
	header("Content-Disposition: attachment; filename=\"" .
53
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
54
	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

    
62
	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

    
70
if($_POST)
71
	conf_mount_rw();
72

    
73
// Function: is Blank
74
// Returns true or false depending on blankness of argument.
75

    
76
function isBlank( $arg ) { return preg_match( "/^\s*$/", $arg ); }
77

    
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
$ScriptName = $REQUEST['SCRIPT_NAME'];
89

    
90
// Get year.
91

    
92
$arrDT   = localtime();
93
$intYear = $arrDT[5] + 1900;
94

    
95
$closehead = false;
96
$pgtitle = array(gettext("Diagnostics"),gettext("Execute command"));
97
include("head.inc");
98
?>
99

    
100
<script type="text/javascript">
101
//<![CDATA[
102

    
103
   // Create recall buffer array (of encoded strings).
104

    
105
<?php
106

    
107
if (isBlank( $_POST['txtRecallBuffer'] )) {
108
	puts( "   var arrRecallBuffer = new Array;" );
109
} else {
110
	puts( "   var arrRecallBuffer = new Array(" );
111
	$arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
112
	for ($i=0; $i < (count( $arrBuffer ) - 1); $i++)
113
		puts( "      '" . htmlspecialchars($arrBuffer[$i], ENT_QUOTES | ENT_HTML401) . "'," );
114
	puts( "      '" . htmlspecialchars($arrBuffer[count( $arrBuffer ) - 1], ENT_QUOTES | ENT_HTML401) . "'" );
115
	puts( "   );" );
116
}
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

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

    
143
		  // 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
         alert( '<?=gettext("Nothing to recall"); ?>!' );
160
         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
//]]>
190
</script>
191
<style type="text/css">
192
/*<![CDATA[*/
193

    
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
/*]]>*/
223
</style>
224
</head>
225
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
226
<?php include("fbegin.inc"); ?>
227
<?php if (isBlank($_POST['txtCommand'])): ?>
228
<p class="red"><strong><?=gettext("Note: this function is unsupported. Use it " .
229
"on your own risk"); ?>!</strong></p>
230
<?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
   $ph = popen($_POST['txtCommand'] . ' 2>&1', "r" );
240
   while ($line = fgets($ph)) echo htmlspecialchars($line);
241
   pclose($ph);
242
   puts("&nbsp;</pre>");
243
}
244

    
245

    
246
if (!isBlank($_POST['txtPHPCommand'])) {
247
   puts("<pre>");
248
   require_once("config.inc");
249
   require_once("functions.inc");
250
   echo eval($_POST['txtPHPCommand']);
251
   puts("&nbsp;</pre>");
252
}
253

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

    
340
<?php
341

    
342
if($_POST)
343
	conf_mount_ro();
344

    
345
?>
(56-56/256)