Project

General

Profile

Download (7.28 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
?>
32
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
33
<html>
34
<head>
35
<?php
36

    
37
include("fbegin.inc");
38

    
39
// Function: is Blank
40
// Returns true or false depending on blankness of argument.
41

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

    
44

    
45
// Function: Puts
46
// Put string, Ruby-style.
47

    
48
function puts( $arg ) { echo "$arg\n"; }
49

    
50

    
51
// "Constants".
52

    
53
$Version    = '';
54
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
55
$Title      = 'pfSense: execute command';
56

    
57
// Get year.
58

    
59
$arrDT   = localtime();
60
$intYear = $arrDT[5] + 1900;
61

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

    
68
   // Create recall buffer array (of encoded strings).
69

    
70
<?php
71

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

    
82
?>
83

    
84
   // Set pointer to end of recall buffer.
85
   var intRecallPtr = arrRecallBuffer.length-1;
86

    
87
   // Functions to extend String class.
88
   function str_encode() { return escape( this ) }
89
   function str_decode() { return unescape( this ) }
90

    
91
   // Extend string class to include encode() and decode() functions.
92
   String.prototype.encode = str_encode
93
   String.prototype.decode = str_decode
94

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

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

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

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

    
114
      return true;
115
   }
116

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

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

    
128
      // Increment recall buffer pointer in positive or negative direction
129
      // according to <n>.
130
      intRecallPtr += n;
131

    
132
      // Make sure the buffer stays circular.
133
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
134
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
135

    
136
      // Recall the command.
137
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
138
   }
139

    
140
   // Function: Reset onClick (event handler)
141
   // Resets form on reset button click event.
142
   function Reset_onClick( form ) {
143

    
144
      // Reset recall buffer pointer.
145
      intRecallPtr = arrRecallBuffer.length;
146

    
147
      // Clear form (could have spaces in it) and return focus ready for cmd.
148
      form.txtCommand.value = '';
149
      form.txtCommand.focus();
150

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

    
159
input {
160
   font-family: courier new, courier;
161
   font-weight: normal;
162
   font-size: 9pt;
163
}
164

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

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

    
181
.button {
182
   font-family: tahoma, verdana, arial, helvetica;
183
   font-weight: bold;
184
   font-size: 11px;
185
}
186

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

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

    
210
?>
211

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

    
254
<?php
255

    
256
conf_mount_ro();
257

    
258
?>
(22-22/127)