Project

General

Profile

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

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

    
26
require("guiconfig.inc");
27

    
28
conf_mount_rw();
29

    
30
// Function: is Blank
31
// Returns true or false depending on blankness of argument.
32

    
33
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
34

    
35

    
36
// Function: Puts
37
// Put string, Ruby-style.
38

    
39
function puts( $arg ) { echo "$arg\n"; }
40

    
41

    
42
// "Constants".
43

    
44
$Version    = '';
45
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
46

    
47
// Get year.
48

    
49
$arrDT   = localtime();
50
$intYear = $arrDT[5] + 1900;
51

    
52
$pgtitle = "Diagnostics: Execute command";
53
include("head.inc");
54
?>
55

    
56
<script language="javascript">
57
<!--
58

    
59
   // Create recall buffer array (of encoded strings).
60

    
61
<?php
62

    
63
if (isBlank( $_POST['txtRecallBuffer'] )) {
64
   puts( "   var arrRecallBuffer = new Array;" );
65
} else {
66
   puts( "   var arrRecallBuffer = new Array(" );
67
   $arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
68
   for ($i=0; $i < (count( $arrBuffer ) - 1); $i++) puts( "      '" . $arrBuffer[$i] . "'," );
69
   puts( "      '" . $arrBuffer[count( $arrBuffer ) - 1] . "'" );
70
   puts( "   );" );
71
}
72

    
73
?>
74

    
75
   // Set pointer to end of recall buffer.
76
   var intRecallPtr = arrRecallBuffer.length-1;
77

    
78
   // Functions to extend String class.
79
   function str_encode() { return escape( this ) }
80
   function str_decode() { return unescape( this ) }
81

    
82
   // Extend string class to include encode() and decode() functions.
83
   String.prototype.encode = str_encode
84
   String.prototype.decode = str_decode
85

    
86
   // Function: is Blank
87
   // Returns boolean true or false if argument is blank.
88
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
89

    
90
   // Function: frmExecPlus onSubmit (event handler)
91
   // Builds the recall buffer from the command string on submit.
92
   function frmExecPlus_onSubmit( form ) {
93

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

    
98
		  // Stuff encoded command string into the recall buffer.
99
		  if (isBlank(form.txtRecallBuffer.value))
100
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
101
		  else
102
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
103
	  }
104

    
105
      return true;
106
   }
107

    
108
   // Function: btnRecall onClick (event handler)
109
   // Recalls command buffer going either up or down.
110
   function btnRecall_onClick( form, n ) {
111

    
112
      // If nothing in recall buffer, then error.
113
      if (!arrRecallBuffer.length) {
114
         alert( 'Nothing to recall!' );
115
         form.txtCommand.focus();
116
         return;
117
      }
118

    
119
      // Increment recall buffer pointer in positive or negative direction
120
      // according to <n>.
121
      intRecallPtr += n;
122

    
123
      // Make sure the buffer stays circular.
124
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
125
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
126

    
127
      // Recall the command.
128
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
129
   }
130

    
131
   // Function: Reset onClick (event handler)
132
   // Resets form on reset button click event.
133
   function Reset_onClick( form ) {
134

    
135
      // Reset recall buffer pointer.
136
      intRecallPtr = arrRecallBuffer.length;
137

    
138
      // Clear form (could have spaces in it) and return focus ready for cmd.
139
      form.txtCommand.value = '';
140
      form.txtCommand.focus();
141

    
142
      return true;
143
   }
144
//-->
145
</script>
146
<style>
147
<!--
148

    
149
input {
150
   font-family: courier new, courier;
151
   font-weight: normal;
152
   font-size: 9pt;
153
}
154

    
155
pre {
156
   border: 2px solid #435370;
157
   background: #F0F0F0;
158
   padding: 1em;
159
   font-family: courier new, courier;
160
   white-space: pre;
161
   line-height: 10pt;
162
   font-size: 10pt;
163
}
164

    
165
.label {
166
   font-family: tahoma, verdana, arial, helvetica;
167
   font-size: 11px;
168
   font-weight: bold;
169
}
170

    
171
.button {
172
   font-family: tahoma, verdana, arial, helvetica;
173
   font-weight: bold;
174
   font-size: 11px;
175
}
176

    
177
-->
178
</style>
179
</head>
180
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
181
<?php include("fbegin.inc"); ?>
182
<p class="pgtitle"><?=$pgtitle?></p>
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" 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" 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="button" 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
?>
(31-31/162)