Project

General

Profile

Download (7.19 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
6
	Created by technologEase (http://www.technologEase.com).
7

    
8
	(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
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 = "Diagnostics: Execute command";
54
$closehead = false;
55
include("head.inc");
56
?>
57

    
58
<script language="javascript">
59
<!--
60

    
61
   // Create recall buffer array (of encoded strings).
62

    
63
<?php
64

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

    
75
?>
76

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

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

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

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

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

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

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

    
107
      return true;
108
   }
109

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

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

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

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

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

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

    
137
      // Reset recall buffer pointer.
138
      intRecallPtr = arrRecallBuffer.length;
139

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

    
144
      return true;
145
   }
146
//-->
147
</script>
148
<link href="gui.css" rel="stylesheet" type="text/css">
149
<style>
150
<!--
151

    
152
input {
153
   font-family: courier new, courier;
154
   font-weight: normal;
155
   font-size: 9pt;
156
}
157

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

    
168
.label {
169
   font-family: tahoma, verdana, arial, helvetica;
170
   font-size: 11px;
171
   font-weight: bold;
172
}
173

    
174
.button {
175
   font-family: tahoma, verdana, arial, helvetica;
176
   font-weight: bold;
177
   font-size: 11px;
178
}
179

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

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

    
204
?>
205

    
206
<form action="exec.php" method="POST" enctype="multipart/form-data" name="frmExecPlus" onSubmit="return frmExecPlus_onSubmit( this );">
207
  <table>
208
    <tr>
209
      <td class="label" align="right">Command:</td>
210
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>"></td>
211
    </tr>
212
    <tr>
213
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
214
      <td valign="top" class="label">
215
         <input type="hidden" name="txtRecallBuffer" value="<?=$_POST['txtRecallBuffer'] ?>">
216
         <input type="button" class="button" name="btnRecallPrev" value="<" onClick="btnRecall_onClick( this.form, -1 );">
217
         <input type="submit" class="button" value="Execute">
218
         <input type="button" class="button" name="btnRecallNext" value=">" onClick="btnRecall_onClick( this.form,  1 );">
219
         <input type="button"  class="button" value="Clear" onClick="return Reset_onClick( this.form );">
220
      </td>
221
    </tr>
222
    <tr>
223
      <td height="8"></td>
224
      <td></td>
225
    </tr>
226
    <tr>
227
      <td align="right">Download:</td>
228
      <td>
229
        <input name="dlPath" type="text" id="dlPath" size="50">
230
        <input name="submit" type="submit"  class="button" id="download" value="Download">
231
        </td>
232
    </tr>
233
    <tr>
234
      <td align="right">Upload:</td>
235
      <td valign="top" class="label">
236
<input name="ulfile" type="file" class="button" id="ulfile">
237
        <input name="submit" type="submit"  class="button" id="upload" value="Upload"></td>
238
    </tr>
239
  </table>
240
<?php include("fend.inc"); ?>
241
</form>
242
<script language="Javascript">
243
document.forms[0].txtCommand.focus();
244
</script>
245
</body>
246
</html>
247

    
248
<?php
249

    
250
conf_mount_ro();
251

    
252
?>
(22-22/128)