Project

General

Profile

Download (7.08 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
4
	session_cache_limiter('public');
5
	$fd = fopen($_POST['dlPath'], "rb");
6
	header("Content-Type: application/octet-stream");
7
	header("Content-Length: " . filesize($_POST['dlPath']));
8
	header("Content-Disposition: attachment; filename=\"" . 
9
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
10
	
11
	fpassthru($fd);
12
	exit;
13
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
14
	move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
15
	$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
16
	unset($_POST['txtCommand']);
17
}
18
?>
19
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
20
<html>
21
<head>
22
<?php
23

    
24
/*
25
	Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
26
	Created by technologEase (http://www.technologEase.com).
27
	
28
	(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
29
*/
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
$Title      = 'm0n0wall: execute command';
48

    
49
// Get year.
50

    
51
$arrDT   = localtime();
52
$intYear = $arrDT[5] + 1900;
53

    
54
?>
55
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
56
<title><?=$Title ?></title>
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
<link href="gui.css" rel="stylesheet" type="text/css">
148
<style>
149
<!--
150

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

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

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

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

    
179
-->
180
</style>
181
</head>
182
<body>
183
<p><span class="pgtitle"><?=$Title ?></span>
184
<?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
?>
203

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