Project

General

Profile

Download (7.24 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
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
?>
29
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
30
<html>
31
<head>
32
<?php
33

    
34
include("fbegin.inc");
35

    
36
// Function: is Blank
37
// Returns true or false depending on blankness of argument.
38

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

    
41

    
42
// Function: Puts
43
// Put string, Ruby-style.
44

    
45
function puts( $arg ) { echo "$arg\n"; }
46

    
47

    
48
// "Constants".
49

    
50
$Version    = '';
51
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
52
$Title      = 'pfSense: execute command';
53

    
54
// Get year.
55

    
56
$arrDT   = localtime();
57
$intYear = $arrDT[5] + 1900;
58

    
59
?>
60
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
61
<title><?=$Title ?></title>
62
<script language="javascript">
63
<!--
64

    
65
   // Create recall buffer array (of encoded strings).
66

    
67
<?php
68

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

    
79
?>
80

    
81
   // Set pointer to end of recall buffer.
82
   var intRecallPtr = arrRecallBuffer.length-1;
83

    
84
   // Functions to extend String class.
85
   function str_encode() { return escape( this ) }
86
   function str_decode() { return unescape( this ) }
87

    
88
   // Extend string class to include encode() and decode() functions.
89
   String.prototype.encode = str_encode
90
   String.prototype.decode = str_decode
91

    
92
   // Function: is Blank
93
   // Returns boolean true or false if argument is blank.
94
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
95

    
96
   // Function: frmExecPlus onSubmit (event handler)
97
   // Builds the recall buffer from the command string on submit.
98
   function frmExecPlus_onSubmit( form ) {
99

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

    
104
		  // Stuff encoded command string into the recall buffer.
105
		  if (isBlank(form.txtRecallBuffer.value))
106
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
107
		  else
108
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
109
	  }
110

    
111
      return true;
112
   }
113

    
114
   // Function: btnRecall onClick (event handler)
115
   // Recalls command buffer going either up or down.
116
   function btnRecall_onClick( form, n ) {
117

    
118
      // If nothing in recall buffer, then error.
119
      if (!arrRecallBuffer.length) {
120
         alert( 'Nothing to recall!' );
121
         form.txtCommand.focus();
122
         return;
123
      }
124

    
125
      // Increment recall buffer pointer in positive or negative direction
126
      // according to <n>.
127
      intRecallPtr += n;
128

    
129
      // Make sure the buffer stays circular.
130
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
131
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
132

    
133
      // Recall the command.
134
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
135
   }
136

    
137
   // Function: Reset onClick (event handler)
138
   // Resets form on reset button click event.
139
   function Reset_onClick( form ) {
140

    
141
      // Reset recall buffer pointer.
142
      intRecallPtr = arrRecallBuffer.length;
143

    
144
      // Clear form (could have spaces in it) and return focus ready for cmd.
145
      form.txtCommand.value = '';
146
      form.txtCommand.focus();
147

    
148
      return true;
149
   }
150
//-->
151
</script>
152
<link href="gui.css" rel="stylesheet" type="text/css">
153
<style>
154
<!--
155

    
156
input {
157
   font-family: courier new, courier;
158
   font-weight: normal;
159
   font-size: 9pt;
160
}
161

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

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

    
178
.button {
179
   font-family: tahoma, verdana, arial, helvetica;
180
   font-weight: bold;
181
   font-size: 11px;
182
}
183

    
184
-->
185
</style>
186
</head>
187
<body>
188
<p><span class="pgtitle"><?=$Title ?></span>
189
<?php if (isBlank($_POST['txtCommand'])): ?>
190
<p class="red"><strong>Note: this function is unsupported. Use it
191
on your own risk!</strong></p>
192
<?php endif; ?>
193
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
194
<?php
195

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

    
207
?>
208

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