Project

General

Profile

Download (8.46 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
*/
9
10 5c4b23a9 Scott Ullrich
require("guiconfig.inc");
11 458e0e0b Scott Ullrich
12 5b237745 Scott Ullrich
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
13
	session_cache_limiter('public');
14
	$fd = fopen($_POST['dlPath'], "rb");
15
	header("Content-Type: application/octet-stream");
16
	header("Content-Length: " . filesize($_POST['dlPath']));
17 be4b8e72 Scott Ullrich
	header("Content-Disposition: attachment; filename=\"" .
18 5b237745 Scott Ullrich
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
19 be4b8e72 Scott Ullrich
20 5b237745 Scott Ullrich
	fpassthru($fd);
21
	exit;
22
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
23
	move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
24
	$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
25
	unset($_POST['txtCommand']);
26
}
27 2900e518 Scott Ullrich
28 3e1b29a8 Scott Ullrich
if($_POST)
29
	conf_mount_rw();
30 74285e13 Scott Ullrich
31 5b237745 Scott Ullrich
// Function: is Blank
32
// Returns true or false depending on blankness of argument.
33
34
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
35
36
37
// Function: Puts
38
// Put string, Ruby-style.
39
40
function puts( $arg ) { echo "$arg\n"; }
41
42
43
// "Constants".
44
45
$Version    = '';
46
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
47
48
// Get year.
49
50
$arrDT   = localtime();
51
$intYear = $arrDT[5] + 1900;
52
53 998abf60 Bill Marquette
$pgtitle = "Diagnostics: Execute command";
54
include("head.inc");
55 5b237745 Scott Ullrich
?>
56 998abf60 Bill Marquette
57 5b237745 Scott Ullrich
<script language="javascript">
58
<!--
59
60
   // Create recall buffer array (of encoded strings).
61
62
<?php
63
64
if (isBlank( $_POST['txtRecallBuffer'] )) {
65
   puts( "   var arrRecallBuffer = new Array;" );
66
} else {
67
   puts( "   var arrRecallBuffer = new Array(" );
68
   $arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
69
   for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( "      '" . $arrBuffer[$i] . "'," );
70
   puts( "      '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
71
   puts( "   );" );
72
}
73
74
?>
75
76
   // Set pointer to end of recall buffer.
77
   var intRecallPtr = arrRecallBuffer.length-1;
78
79
   // Functions to extend String class.
80
   function str_encode() { return escape( this ) }
81
   function str_decode() { return unescape( this ) }
82 be4b8e72 Scott Ullrich
83 5b237745 Scott Ullrich
   // Extend string class to include encode() and decode() functions.
84
   String.prototype.encode = str_encode
85
   String.prototype.decode = str_decode
86
87
   // Function: is Blank
88
   // Returns boolean true or false if argument is blank.
89
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
90
91
   // Function: frmExecPlus onSubmit (event handler)
92
   // Builds the recall buffer from the command string on submit.
93
   function frmExecPlus_onSubmit( form ) {
94
95
      if (!isBlank(form.txtCommand.value)) {
96
		  // If this command is repeat of last command, then do not store command.
97
		  if (form.txtCommand.value.encode() == arrRecallBuffer[arrRecallBuffer.length-1]) { return true }
98 be4b8e72 Scott Ullrich
99 5b237745 Scott Ullrich
		  // Stuff encoded command string into the recall buffer.
100
		  if (isBlank(form.txtRecallBuffer.value))
101
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
102
		  else
103
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
104
	  }
105
106
      return true;
107
   }
108
109
   // Function: btnRecall onClick (event handler)
110
   // Recalls command buffer going either up or down.
111
   function btnRecall_onClick( form, n ) {
112
113
      // If nothing in recall buffer, then error.
114
      if (!arrRecallBuffer.length) {
115
         alert( 'Nothing to recall!' );
116
         form.txtCommand.focus();
117
         return;
118
      }
119
120
      // Increment recall buffer pointer in positive or negative direction
121
      // according to <n>.
122
      intRecallPtr += n;
123
124
      // Make sure the buffer stays circular.
125
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
126
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
127
128
      // Recall the command.
129
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
130
   }
131
132
   // Function: Reset onClick (event handler)
133
   // Resets form on reset button click event.
134
   function Reset_onClick( form ) {
135
136
      // Reset recall buffer pointer.
137
      intRecallPtr = arrRecallBuffer.length;
138
139
      // Clear form (could have spaces in it) and return focus ready for cmd.
140
      form.txtCommand.value = '';
141
      form.txtCommand.focus();
142
143
      return true;
144
   }
145
//-->
146
</script>
147
<style>
148
<!--
149
150
input {
151
   font-family: courier new, courier;
152
   font-weight: normal;
153
   font-size: 9pt;
154
}
155
156
pre {
157
   border: 2px solid #435370;
158
   background: #F0F0F0;
159
   padding: 1em;
160
   font-family: courier new, courier;
161
   white-space: pre;
162
   line-height: 10pt;
163
   font-size: 10pt;
164
}
165
166
.label {
167
   font-family: tahoma, verdana, arial, helvetica;
168
   font-size: 11px;
169
   font-weight: bold;
170
}
171
172
.button {
173
   font-family: tahoma, verdana, arial, helvetica;
174
   font-weight: bold;
175
   font-size: 11px;
176
}
177
178
-->
179
</style>
180
</head>
181 998abf60 Bill Marquette
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
182
<?php include("fbegin.inc"); ?>
183
<p class="pgtitle"><?=$pgtitle?></p>
184 5b237745 Scott Ullrich
<?php if (isBlank($_POST['txtCommand'])): ?>
185
<p class="red"><strong>Note: this function is unsupported. Use it
186
on your own risk!</strong></p>
187
<?php endif; ?>
188
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
189
<?php
190
191
if (!isBlank($_POST['txtCommand'])) {
192
   puts("<pre>");
193
   puts("\$ " . htmlspecialchars($_POST['txtCommand']));
194
   putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
195
   putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
196
   $ph = popen($_POST['txtCommand'], "r" );
197
   while ($line = fgets($ph)) echo htmlspecialchars($line);
198
   pclose($ph);
199
   puts("</pre>");
200
}
201
202 fbcf0037 Scott Ullrich
203
if (!isBlank($_POST['txtPHPCommand'])) {
204
   puts("<pre>");
205
   require_once("config.inc");
206
   require_once("functions.inc");
207
   echo eval($_POST['txtPHPCommand']);
208
   puts("</pre>");
209
}
210
211
212 5b237745 Scott Ullrich
?>
213 ca8e4ed2 Scott Ullrich
<div id="niftyOutter">
214 f6f48dde Scott Ullrich
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
215 5b237745 Scott Ullrich
  <table>
216 fbcf0037 Scott Ullrich
	<tr>
217
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
218
	</tr>  
219 5b237745 Scott Ullrich
    <tr>
220
      <td class="label" align="right">Command:</td>
221 be4b8e72 Scott Ullrich
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
222 5b237745 Scott Ullrich
    </tr>
223
    <tr>
224
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
225
      <td valign="top" class="label">
226
         <input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
227
         <input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
228
         <input type="submit" class="button" value="Execute">
229
         <input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form,  1 );">
230
         <input type="button"  class="button" value="Clear" onClick="return Reset_onClick( this.form );">
231
      </td>
232
    </tr>
233 fbcf0037 Scott Ullrich
	<tr>
234
	  <td colspan="2" valign="top" height="16"></td>
235
	</tr>
236
	<tr>
237
	  <td colspan="2" valign="top" class="vnsepcell">Download</td>
238
	</tr>    
239 5b237745 Scott Ullrich
    <tr>
240 fbcf0037 Scott Ullrich
      <td align="right">File to download:</td>
241 5b237745 Scott Ullrich
      <td>
242
        <input name="dlPath" type="text" id="dlPath" size="50">
243 fbcf0037 Scott Ullrich
	</td></tr>
244
    <tr>
245
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
246
      <td valign="top" class="label">	
247 5b237745 Scott Ullrich
        <input name="submit" type="submit"  class="button" id="download" value="Download">
248
        </td>
249
    </tr>
250 fbcf0037 Scott Ullrich
	<tr>
251
	  <td colspan="2" valign="top" height="16"></td>
252
	</tr>
253
	<tr>
254
	  <td colspan="2" valign="top" class="vnsepcell">Upload</td>
255
	</tr>    
256 5b237745 Scott Ullrich
    <tr>
257 fbcf0037 Scott Ullrich
      <td align="right">File to upload:</td>
258 5b237745 Scott Ullrich
      <td valign="top" class="label">
259 fbcf0037 Scott Ullrich
	<input name="ulfile" type="file" class="button" id="ulfile">
260
	</td></tr>
261
    <tr>
262
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
263
      <td valign="top" class="label">	
264 5b237745 Scott Ullrich
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
265
    </tr>
266 fbcf0037 Scott Ullrich
	<tr>
267
	  <td colspan="2" valign="top" height="16"></td>
268
	</tr>
269
	<tr>
270
	  <td colspan="2" valign="top" class="vnsepcell">PHP Execute</td>
271
	</tr>
272
	<tr>
273 69fbe36f Scott Ullrich
		<td align="right">Command:</td>
274 992ac32f Scott Ullrich
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="3" cols="50"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
275 fbcf0037 Scott Ullrich
	</tr>
276
    <tr>
277
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
278
      <td valign="top" class="label">
279
         <input type="submit" class="button" value="Execute">
280
	 <p>
281 abe20b85 Scott Ullrich
	 <strong>Example:</strong>   interfaces_carp_bring_up_final();
282 fbcf0037 Scott Ullrich
      </td>
283
    </tr>
284
    
285 5b237745 Scott Ullrich
  </table>
286 ca8e4ed2 Scott Ullrich
</div>
287 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
288 5b237745 Scott Ullrich
</form>
289 be4b8e72 Scott Ullrich
<script language="Javascript">
290
document.forms[0].txtCommand.focus();
291
</script>
292 5b237745 Scott Ullrich
</body>
293
</html>
294 74285e13 Scott Ullrich
295
<?php
296
297 3e1b29a8 Scott Ullrich
if($_POST)
298
	conf_mount_ro();
299 74285e13 Scott Ullrich
300 998abf60 Bill Marquette
?>