Project

General

Profile

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

    
10

    
11
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
12
	session_cache_limiter('public');
13
	$fd = fopen($_POST['dlPath'], "rb");
14
	header("Content-Type: application/octet-stream");
15
	header("Content-Length: " . filesize($_POST['dlPath']));
16
	header("Content-Disposition: attachment; filename=\"" .
17
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
18

    
19
	fpassthru($fd);
20
	exit;
21
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
22
	move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
23
	$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
24
	unset($_POST['txtCommand']);
25
}
26

    
27
require("guiconfig.inc");
28

    
29
conf_mount_rw();
30

    
31
// 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
$pgtitle = array("Diagnostics","Execute command");
54
include("head.inc");
55
?>
56

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

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

    
99
		  // 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
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
182
<?php include("fbegin.inc"); ?>
183
<?php if (isBlank($_POST['txtCommand'])): ?>
184
<p class="red"><strong>Note: this function is unsupported. Use it
185
on your own risk!</strong></p>
186
<?php endif; ?>
187
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
188
<?php
189

    
190
if (!isBlank($_POST['txtCommand'])) {
191
   puts("<pre>");
192
   puts("\$ " . htmlspecialchars($_POST['txtCommand']));
193
   putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
194
   putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
195
   $ph = popen($_POST['txtCommand'], "r" );
196
   while ($line = fgets($ph)) echo htmlspecialchars($line);
197
   pclose($ph);
198
   puts("</pre>");
199
}
200

    
201

    
202
if (!isBlank($_POST['txtPHPCommand'])) {
203
   puts("<pre>");
204
   require_once("config.inc");
205
   require_once("functions.inc");
206
   echo eval($_POST['txtPHPCommand']);
207
   puts("</pre>");
208
}
209

    
210

    
211
?>
212
<div id="niftyOutter">
213
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
214
  <table>
215
	<tr>
216
	  <td colspan="2" valign="top" class="vnsepcell">Execute Shell command</td>
217
	</tr>  
218
    <tr>
219
      <td class="label" align="right">Command:</td>
220
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
221
    </tr>
222
    <tr>
223
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
224
      <td valign="top" class="label">
225
         <input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
226
         <input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
227
         <input type="submit" class="button" value="Execute">
228
         <input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form,  1 );">
229
         <input type="button"  class="button" value="Clear" onClick="return Reset_onClick( this.form );">
230
      </td>
231
    </tr>
232
	<tr>
233
	  <td colspan="2" valign="top" height="16"></td>
234
	</tr>
235
	<tr>
236
	  <td colspan="2" valign="top" class="vnsepcell">Download</td>
237
	</tr>    
238
    <tr>
239
      <td align="right">File to download:</td>
240
      <td>
241
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50">
242
	</td></tr>
243
    <tr>
244
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
245
      <td valign="top" class="label">	
246
        <input name="submit" type="submit"  class="button" id="download" value="Download">
247
        </td>
248
    </tr>
249
	<tr>
250
	  <td colspan="2" valign="top" height="16"></td>
251
	</tr>
252
	<tr>
253
	  <td colspan="2" valign="top" class="vnsepcell">Upload</td>
254
	</tr>    
255
    <tr>
256
      <td align="right">File to upload:</td>
257
      <td valign="top" class="label">
258
	<input name="ulfile" type="file" class="formfld file" id="ulfile">
259
	</td></tr>
260
    <tr>
261
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
262
      <td valign="top" class="label">	
263
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
264
    </tr>
265
	<tr>
266
	  <td colspan="2" valign="top" height="16"></td>
267
	</tr>
268
	<tr>
269
	  <td colspan="2" valign="top" class="vnsepcell">PHP Execute</td>
270
	</tr>
271
	<tr>
272
		<td align="right">Command:</td>
273
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" type="text" rows="3" cols="50"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
274
	</tr>
275
    <tr>
276
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
277
      <td valign="top" class="label">
278
         <input type="submit" class="button" value="Execute">
279
	 <p>
280
	 <strong>Example:</strong>   interfaces_carp_bring_up_final();
281
      </td>
282
    </tr>
283
    
284
  </table>
285
</div>
286
<?php include("fend.inc"); ?>
287
</form>
288
<script language="Javascript">
289
document.forms[0].txtCommand.focus();
290
</script>
291
</body>
292
</html>
293

    
294
<?php
295

    
296
conf_mount_ro();
297

    
298
?>
(34-34/189)