Projet

Général

Profil

Télécharger (10,6 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / exec.php @ daeab6c4

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
    Redistribution and use in source and binary forms, with or without
10
    modification, are permitted provided that the following conditions are met:
11

    
12
    1. Redistributions of source code must retain the above copyright notice,
13
       this list of conditions and the following disclaimer.
14

    
15
    2. Redistributions in binary form must reproduce the above copyright
16
       notice, this list of conditions and the following disclaimer in the
17
       documentation and/or other materials provided with the distribution.
18

    
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_MODULE:	shell
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-diagnostics-command
36
##|*NAME=Diagnostics: Command page
37
##|*DESCR=Allow access to the 'Diagnostics: Command' page.
38
##|*MATCH=exec.php*
39
##|-PRIV
40

    
41
$allowautocomplete = true;
42

    
43
require("guiconfig.inc");
44

    
45
if (($_POST['submit'] == "Download") && file_exists($_POST['dlPath'])) {
46
	session_cache_limiter('public');
47
	$fd = fopen($_POST['dlPath'], "rb");
48
	header("Content-Type: application/octet-stream");
49
	header("Content-Length: " . filesize($_POST['dlPath']));
50
	header("Content-Disposition: attachment; filename=\"" .
51
		trim(htmlentities(basename($_POST['dlPath']))) . "\"");
52
	if (isset($_SERVER['HTTPS'])) {
53
		header('Pragma: ');
54
		header('Cache-Control: ');
55
	} else {
56
		header("Pragma: private");
57
		header("Cache-Control: private, must-revalidate");
58
	}
59

    
60
	fpassthru($fd);
61
	exit;
62
} else if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
63
	move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $_FILES['ulfile']['name']);
64
	$ulmsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']);
65
	unset($_POST['txtCommand']);
66
}
67

    
68
if($_POST)
69
	conf_mount_rw();
70

    
71
// Function: is Blank
72
// Returns true or false depending on blankness of argument.
73

    
74
function isBlank( $arg ) { return preg_match( "/^\s*$/", $arg ); }
75

    
76

    
77
// Function: Puts
78
// Put string, Ruby-style.
79

    
80
function puts( $arg ) { echo "$arg\n"; }
81

    
82

    
83
// "Constants".
84

    
85
$Version    = '';
86
$ScriptName = $REQUEST['SCRIPT_NAME'];
87

    
88
// Get year.
89

    
90
$arrDT   = localtime();
91
$intYear = $arrDT[5] + 1900;
92

    
93
$closehead = false;
94
$pgtitle = array(gettext("Diagnostics"),gettext("Execute command"));
95
include("head.inc");
96
?>
97

    
98
<script type="text/javascript">
99
//<![CDATA[
100

    
101
   // Create recall buffer array (of encoded strings).
102

    
103
<?php
104

    
105
if (isBlank( $_POST['txtRecallBuffer'] )) {
106
	puts( "   var arrRecallBuffer = new Array;" );
107
} else {
108
	puts( "   var arrRecallBuffer = new Array(" );
109
	$arrBuffer = explode( "&", $_POST['txtRecallBuffer'] );
110
	for ($i=0; $i < (count( $arrBuffer ) - 1); $i++)
111
		puts( "      '" . htmlspecialchars($arrBuffer[$i]) . "'," );
112
	puts( "      '" . htmlspecialchars($arrBuffer[count( $arrBuffer ) - 1]) . "'" );
113
	puts( "   );" );
114
}
115

    
116
?>
117

    
118
   // Set pointer to end of recall buffer.
119
   var intRecallPtr = arrRecallBuffer.length-1;
120

    
121
   // Functions to extend String class.
122
   function str_encode() { return escape( this ) }
123
   function str_decode() { return unescape( this ) }
124

    
125
   // Extend string class to include encode() and decode() functions.
126
   String.prototype.encode = str_encode
127
   String.prototype.decode = str_decode
128

    
129
   // Function: is Blank
130
   // Returns boolean true or false if argument is blank.
131
   function isBlank( strArg ) { return strArg.match( /^\s*$/ ) }
132

    
133
   // Function: frmExecPlus onSubmit (event handler)
134
   // Builds the recall buffer from the command string on submit.
135
   function frmExecPlus_onSubmit( form ) {
136

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

    
141
		  // Stuff encoded command string into the recall buffer.
142
		  if (isBlank(form.txtRecallBuffer.value))
143
			 form.txtRecallBuffer.value = form.txtCommand.value.encode();
144
		  else
145
			 form.txtRecallBuffer.value += '&' + form.txtCommand.value.encode();
146
	  }
147

    
148
      return true;
149
   }
150

    
151
   // Function: btnRecall onClick (event handler)
152
   // Recalls command buffer going either up or down.
153
   function btnRecall_onClick( form, n ) {
154

    
155
      // If nothing in recall buffer, then error.
156
      if (!arrRecallBuffer.length) {
157
         alert( '<?=gettext("Nothing to recall"); ?>!' );
158
         form.txtCommand.focus();
159
         return;
160
      }
161

    
162
      // Increment recall buffer pointer in positive or negative direction
163
      // according to <n>.
164
      intRecallPtr += n;
165

    
166
      // Make sure the buffer stays circular.
167
      if (intRecallPtr < 0) { intRecallPtr = arrRecallBuffer.length - 1 }
168
      if (intRecallPtr > (arrRecallBuffer.length - 1)) { intRecallPtr = 0 }
169

    
170
      // Recall the command.
171
      form.txtCommand.value = arrRecallBuffer[intRecallPtr].decode();
172
   }
173

    
174
   // Function: Reset onClick (event handler)
175
   // Resets form on reset button click event.
176
   function Reset_onClick( form ) {
177

    
178
      // Reset recall buffer pointer.
179
      intRecallPtr = arrRecallBuffer.length;
180

    
181
      // Clear form (could have spaces in it) and return focus ready for cmd.
182
      form.txtCommand.value = '';
183
      form.txtCommand.focus();
184

    
185
      return true;
186
   }
187
//]]>
188
</script>
189
<style type="text/css">
190
/*<![CDATA[*/
191

    
192
input {
193
   font-family: courier new, courier;
194
   font-weight: normal;
195
   font-size: 9pt;
196
}
197

    
198
pre {
199
   border: 2px solid #435370;
200
   background: #F0F0F0;
201
   padding: 1em;
202
   font-family: courier new, courier;
203
   white-space: pre;
204
   line-height: 10pt;
205
   font-size: 10pt;
206
}
207

    
208
.label {
209
   font-family: tahoma, verdana, arial, helvetica;
210
   font-size: 11px;
211
   font-weight: bold;
212
}
213

    
214
.button {
215
   font-family: tahoma, verdana, arial, helvetica;
216
   font-weight: bold;
217
   font-size: 11px;
218
}
219

    
220
/*]]>*/
221
</style>
222
</head>
223
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
224
<?php include("fbegin.inc"); ?>
225
<?php if (isBlank($_POST['txtCommand'])): ?>
226
<p class="red"><strong><?=gettext("Note: this function is unsupported. Use it " .
227
"on your own risk"); ?>!</strong></p>
228
<?php endif; ?>
229
<?php if ($ulmsg) echo "<p><strong>" . $ulmsg . "</strong></p>\n"; ?>
230
<?php
231

    
232
if (!isBlank($_POST['txtCommand'])) {
233
   puts("<pre>");
234
   puts("\$ " . htmlspecialchars($_POST['txtCommand']));
235
   putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
236
   putenv("SCRIPT_FILENAME=" . strtok($_POST['txtCommand'], " "));	/* PHP scripts */
237
   $ph = popen($_POST['txtCommand'] . ' 2>&1', "r" );
238
   while ($line = fgets($ph)) echo htmlspecialchars($line);
239
   pclose($ph);
240
   puts("&nbsp;</pre>");
241
}
242

    
243

    
244
if (!isBlank($_POST['txtPHPCommand'])) {
245
   puts("<pre>");
246
   require_once("config.inc");
247
   require_once("functions.inc");
248
   echo eval($_POST['txtPHPCommand']);
249
   puts("&nbsp;</pre>");
250
}
251

    
252
?>
253
<div id="niftyOutter">
254
<form action="exec.php" method="post" enctype="multipart/form-data" name="frmExecPlus" onsubmit="return frmExecPlus_onSubmit( this );">
255
  <table summary="exec">
256
	<tr>
257
	  <td colspan="2" valign="top" class="vnsepcell"><?=gettext("Execute Shell command"); ?></td>
258
	</tr>  
259
    <tr>
260
      <td class="label" align="right"><?=gettext("Command"); ?>:</td>
261
      <td class="type"><input id="txtCommand" name="txtCommand" type="text" class="formfld unknown" size="80" value="<?=htmlspecialchars($_POST['txtCommand']);?>" /></td>
262
    </tr>
263
    <tr>
264
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
265
      <td valign="top" class="label">
266
         <input type="hidden" name="txtRecallBuffer" value="<?=htmlspecialchars($_POST['txtRecallBuffer']) ?>" />
267
         <input type="button" class="button" name="btnRecallPrev" value="<" onclick="btnRecall_onClick( this.form, -1 );" />
268
         <input type="submit" class="button" value="<?=gettext("Execute"); ?>" />
269
         <input type="button" class="button" name="btnRecallNext" value=">" onclick="btnRecall_onClick( this.form,  1 );" />
270
         <input type="button"  class="button" value="<?=gettext("Clear"); ?>" onclick="return Reset_onClick( this.form );" />
271
      </td>
272
    </tr>
273
	<tr>
274
	  <td colspan="2" valign="top" height="16"></td>
275
	</tr>
276
	<tr>
277
	  <td colspan="2" valign="top" class="vnsepcell"><?=gettext("Download"); ?></td>
278
	</tr>    
279
    <tr>
280
      <td align="right"><?=gettext("File to download"); ?>:</td>
281
      <td>
282
        <input name="dlPath" type="text" class="formfld file" id="dlPath" size="50" />
283
	</td></tr>
284
    <tr>
285
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
286
      <td valign="top" class="label">	
287
        <input name="submit" type="submit"  class="button" id="download" value="<?=gettext("Download"); ?>" />
288
        </td>
289
    </tr>
290
	<tr>
291
	  <td colspan="2" valign="top" height="16"></td>
292
	</tr>
293
	<tr>
294
	  <td colspan="2" valign="top" class="vnsepcell"><?=gettext("Upload"); ?></td>
295
	</tr>    
296
    <tr>
297
      <td align="right"><?=gettext("File to upload"); ?>:</td>
298
      <td valign="top" class="label">
299
	<input name="ulfile" type="file" class="formfld file" id="ulfile" />
300
	</td></tr>
301
    <tr>
302
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
303
      <td valign="top" class="label">	
304
        <input name="submit" type="submit"  class="button" id="upload" value="<?=gettext("Upload"); ?>" /></td>
305
    </tr>
306
	<tr>
307
	  <td colspan="2" valign="top" height="16"></td>
308
	</tr>
309
	<tr>
310
	  <td colspan="2" valign="top" class="vnsepcell"><?=gettext("PHP Execute"); ?></td>
311
	</tr>
312
	<tr>
313
		<td align="right"><?=gettext("Command"); ?>:</td>
314
		<td class="type"><textarea id="txtPHPCommand" name="txtPHPCommand" rows="9" cols="80"><?=htmlspecialchars($_POST['txtPHPCommand']);?></textarea></td>
315
	</tr>
316
    <tr>
317
      <td valign="top">&nbsp;&nbsp;&nbsp;</td>
318
      <td valign="top" class="label">
319
         <input type="submit" class="button" value="<?=gettext("Execute"); ?>" />
320
	 <p>
321
	 <strong><?=gettext("Example"); ?>:</strong>   interfaces_carp_setup();
322
	 </p>
323
      </td>
324
    </tr>
325
    
326
  </table>
327
</form>
328
</div>
329
<?php include("fend.inc"); ?>
330
<script type="text/javascript">
331
//<![CDATA[
332
document.forms[0].txtCommand.focus();
333
//]]>
334
</script>
335
</body>
336
</html>
337

    
338
<?php
339

    
340
if($_POST)
341
	conf_mount_ro();
342

    
343
?>
(55-55/255)