Project

General

Profile

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

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

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

    
81
// Function: Puts
82
// Put string, Ruby-style.
83

    
84
function puts($arg) {
85
	echo "$arg\n";
86
}
87

    
88
// "Constants".
89

    
90
$Version    = '';
91
$ScriptName = $REQUEST['SCRIPT_NAME'];
92

    
93
// Get year.
94

    
95
$arrDT   = localtime();
96
$intYear = $arrDT[5] + 1900;
97

    
98
$closehead = false;
99
$pgtitle = array(gettext("Diagnostics"),gettext("Execute command"));
100
include("head.inc");
101
?>
102

    
103
<script type="text/javascript">
104
//<![CDATA[
105

    
106
	// Create recall buffer array (of encoded strings).
107

    
108
<?php
109

    
110
if (isBlank( $_POST['txtRecallBuffer'] )) {
111
	puts( "   var arrRecallBuffer = new Array;" );
112
} else {
113
	puts( "   var arrRecallBuffer = new Array(" );
114
	$arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
115
	for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) {
116
		puts( "      '" . htmlspecialchars($arrBuffer[$i], ENT_QUOTES | ENT_HTML401) . "'," );
117
	}
118
	puts( "      '" . htmlspecialchars($arrBuffer[count( $arrBuffer ) - 1], ENT_QUOTES | ENT_HTML401) . "'" );
119
	puts( "   );" );
120
}
121

    
122
?>
123

    
124
	// Set pointer to end of recall buffer.
125
	var intRecallPtr = arrRecallBuffer.length-1;
126

    
127
	// Functions to extend String class.
128
	function str_encode() { return escape( this ) }
129
	function str_decode() { return unescape( this ) }
130

    
131
	// Extend string class to include encode() and decode() functions.
132
	String.prototype.encode = str_encode
133
	String.prototype.decode = str_decode
134

    
135
	// Function: is Blank
136
	// Returns boolean true or false if argument is blank.
137
	function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
138

    
139
	// Function: frmExecPlus onSubmit (event handler)
140
	// Builds the recall buffer from the command string on submit.
141
	function frmExecPlus_onSubmit( form ) {
142

    
143
		if (!isBlank(form.txtCommand.value)) {
144
			// If this command is repeat of last command, then do not store command.
145
			if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
146

    
147
			// Stuff encoded command string into the recall buffer.
148
			if (isBlank(form.txtRecallBuffer.value)) {
149
				form.txtRecallBuffer.value = form.txtCommand.value.encode();
150
			} else {
151
				form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
152
			}
153
		}
154

    
155
		return true;
156
	}
157

    
158
	// Function: btnRecall onClick (event handler)
159
	// Recalls command buffer going either up or down.
160
	function btnRecall_onClick( form, n ) {
161

    
162
		// If nothing in recall buffer, then error.
163
		if (!arrRecallBuffer.length) {
164
			alert( '<?=gettext("Nothing to recall"); ?>!' );
165
			form.txtCommand.focus();
166
			return;
167
		}
168

    
169
		// Increment recall buffer pointer in positive or negative direction
170
		// according to <n>.
171
		intRecallPtr += n;
172

    
173
		// Make sure the buffer stays circular.
174
		if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
175
		if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
176

    
177
		// Recall the command.
178
		form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
179
	}
180

    
181
	// Function: Reset onClick (event handler)
182
	// Resets form on reset button click event.
183
	function Reset_onClick( form ) {
184

    
185
		// Reset recall buffer pointer.
186
		intRecallPtr = arrRecallBuffer.length;
187

    
188
		// Clear form (could have spaces in it) and return focus ready for cmd.
189
		form.txtCommand.value = '';
190
		form.txtCommand.focus();
191

    
192
		return true;
193
	}
194
//]]>
195
</script>
196
<style type="text/css">
197
/*<![CDATA[*/
198

    
199
input {
200
	font-family: courier new, courier;
201
	font-weight: normal;
202
	font-size: 9pt;
203
}
204

    
205
pre {
206
	border: 2px solid #435370;
207
	background: #F0F0F0;
208
	padding: 1em;
209
	font-family: courier new, courier;
210
	white-space: pre;
211
	line-height: 10pt;
212
	font-size: 10pt;
213
}
214

    
215
.label {
216
	font-family: tahoma, verdana, arial, helvetica;
217
	font-size: 11px;
218
	font-weight: bold;
219
}
220

    
221
.button {
222
	font-family: tahoma, verdana, arial, helvetica;
223
	font-weight: bold;
224
	font-size: 11px;
225
}
226

    
227
/*]]>*/
228
</style>
229
</head>
230
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
231
<?php include("fbegin.inc"); ?>
232
<?php if (isBlank($_POST['txtCommand'])): ?>
233
<p class="red"><strong><?=gettext("Note: this function is unsupported. Use it " .
234
"on your own risk"); ?>!</strong></p>
235
<?php endif; ?>
236
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
237
<?php
238

    
239
if (!isBlank($_POST['txtCommand'])) {
240
	puts("<pre>");
241
	puts("\$ " . htmlspecialchars($_POST['txtCommand']));
242
	putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
243
	putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
244
	$ph = popen($_POST['txtCommand'] . ' 2>&1', "r" );
245
	while ($line = fgets($ph)) {
246
		echo htmlspecialchars($line);
247
	}
248
	pclose($ph);
249
	puts("&nbsp;</pre>");
250
}
251

    
252

    
253
if (!isBlank($_POST['txtPHPCommand'])) {
254
	puts("<pre>");
255
	require_once("config.inc");
256
	require_once("functions.inc");
257
	echo eval($_POST['txtPHPCommand']);
258
	puts("&nbsp;</pre>");
259
}
260

    
261
?>
262
<div id="niftyOutter">
263
<form action="exec.php" method="post" enctype="multipart/form-data" name="frmExecPlus" onsubmit="return frmExecPlus_onSubmit( this );">
264
	<table summary="exec">
265
		<tr>
266
		<td colspan="2" valign="top" class="vnsepcell"><?=gettext("Execute Shell command"); ?></td>
267
		</tr>
268
		<tr>
269
			<td class="label" align="right"><?=gettext("Command"); ?>:</td>
270
			<td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>" /></td>
271
		</tr>
272
		<tr>
273
			<td valign="top">&nbsp;&nbsp;&nbsp;</td>
274
			<td valign="top" class="label">
275
				<input type="hidden" name="txtRecallBuffer" value="<?=htmlspecialchars($_POST['txtRecallBuffer']) ?>" />
276
				<input type="button" class="button" name="btnRecallPrev" value="<" onclick="btnRecall_onClick( this.form, -1 );" />
277
				<input type="submit" class="button" value="<?=gettext("Execute"); ?>" />
278
				<input type="button" class="button" name="btnRecallNext" value=">" onclick="btnRecall_onClick( this.form,  1 );" />
279
				<input type="button"  class="button" value="<?=gettext("Clear"); ?>" onclick="return Reset_onClick( this.form );" />
280
			</td>
281
		</tr>
282
		<tr>
283
			<td colspan="2" valign="top" height="16"></td>
284
		</tr>
285
		<tr>
286
			<td colspan="2" valign="top" class="vnsepcell"><?=gettext("Download"); ?></td>
287
		</tr>
288
		<tr>
289
			<td align="right"><?=gettext("File to download"); ?>:</td>
290
			<td>
291
				<input name="dlPath" type="text" class="formfld file" id="dlPath" size="50" />
292
			</td>
293
		</tr>
294
		<tr>
295
			<td valign="top">&nbsp;&nbsp;&nbsp;</td>
296
			<td valign="top" class="label">
297
				<input name="submit" type="submit"  class="button" id="download" value="<?=gettext("Download"); ?>" />
298
			</td>
299
		</tr>
300
		<tr>
301
			<td colspan="2" valign="top" height="16"></td>
302
		</tr>
303
		<tr>
304
			<td colspan="2" valign="top" class="vnsepcell"><?=gettext("Upload"); ?></td>
305
		</tr>
306
		<tr>
307
			<td align="right"><?=gettext("File to upload"); ?>:</td>
308
			<td valign="top" class="label">
309
				<input name="ulfile" type="file" class="formfld file" id="ulfile" />
310
			</td>
311
		</tr>
312
		<tr>
313
			<td valign="top">&nbsp;&nbsp;&nbsp;</td>
314
			<td valign="top" class="label">
315
				<input name="submit" type="submit"  class="button" id="upload" value="<?=gettext("Upload"); ?>" /></td>
316
		</tr>
317
		<tr>
318
			<td colspan="2" valign="top" height="16"></td>
319
		</tr>
320
		<tr>
321
			<td colspan="2" valign="top" class="vnsepcell"><?=gettext("PHP Execute"); ?></td>
322
		</tr>
323
		<tr>
324
			<td align="right"><?=gettext("Command"); ?>:</td>
325
			<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
326
		</tr>
327
		<tr>
328
			<td valign="top">&nbsp;&nbsp;&nbsp;</td>
329
			<td valign="top" class="label">
330
				<input type="submit" class="button" value="<?=gettext("Execute"); ?>" />
331
				<p>
332
					<strong><?=gettext("Example"); ?>:</strong>   interfaces_sync_setup();
333
				</p>
334
			</td>
335
		</tr>
336

    
337
	</table>
338
</form>
339
</div>
340
<?php include("fend.inc"); ?>
341
<script type="text/javascript">
342
//<![CDATA[
343
document.forms[0].txtCommand.focus();
344
//]]>
345
</script>
346
</body>
347
</html>
348

    
349
<?php
350

    
351
if ($_POST) {
352
	conf_mount_ro();
353
}
354

    
355
?>
(56-56/256)