Projet

Général

Profil

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

univnautes / usr / local / www / exec.php @ 8aca755a

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 = $HTTP_SERVER_VARS['SCRIPT_NAME'];
87

    
88
// Get year.
89

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

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

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

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

    
102
<?php
103

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

    
115
?>
116

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

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

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

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

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

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

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

    
147
      return true;
148
   }
149

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

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

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

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

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

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

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

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

    
184
      return true;
185
   }
186
//]]>
187
</script>
188
<style>
189
<!--
190

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

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

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

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

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

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

    
242

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

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

    
334
<?php
335

    
336
if($_POST)
337
	conf_mount_ro();
338

    
339
?>
(54-54/246)