Clean up entire file, improved error messages and HTML, fixed editing problem, double-checekd security.

git-svn-id: http://svn.automattic.com/wordpress/trunk@41 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2003-05-23 00:12:22 +00:00
parent fc2d7206bb
commit 374a57451b

View File

@ -37,21 +37,22 @@ for ($i=0; $i<count($b2varstoreset); $i += 1) {
switch($action) { switch($action) {
case "update": case 'update':
$standalone=1; $standalone = 1;
require_once("./b2header.php"); require("b2header.php");
if ($user_level < 3) { if ($user_level < 3) {
die("You have no right to edit the template for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)"); die('<p>You have no right to edit the template for this blog.<br />Ask for a promotion to your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
} }
$newcontent = stripslashes($HTTP_POST_VARS["newcontent"]); $newcontent = stripslashes($HTTP_POST_VARS["newcontent"]);
$file = $HTTP_POST_VARS["file"]; $file = $HTTP_POST_VARS["file"];
$f = fopen($file,"w+"); $f = fopen($file, 'w+');
fwrite($f,$newcontent); fwrite($f, $newcontent);
fclose($f); fclose($f);
$file = str_replace('../', '', $file);
header("Location: b2template.php?file=$file&a=te"); header("Location: b2template.php?file=$file&a=te");
exit(); exit();
@ -59,55 +60,51 @@ break;
default: default:
include("./b2header.php"); require('b2header.php');
if ($user_level <= 3) { if ($user_level <= 3) {
die("You have no right to edit the template for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)"); die('<p>You have no right to edit the template for this blog.<br>Ask for a promotion to your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
} }
if ($file=="") { if ('' == $file) {
if ($blogfilename != "") { if ('' != $blogfilename) {
$file = $blogfilename; $file = $blogfilename;
} else { } else {
$file = "b2.php"; $file = 'index.php';
} }
} }
if (substr($file,0,2) == "..") if ('..' == substr($file,0,2))
die ("Sorry, can't edit files that are up one directory or more."); die ('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.');
if (substr($file,1,1) == ":") if (':' == substr($file,1,1))
die ("Sorry, can't call files with their real path."); die ('Sorry, can&#8217;t call files with their real path.');
if (substr($file,0,1) == "/") if ('/' == substr($file,0,1))
$file = ".".$file; $file = '.' . $file;
$file = stripslashes($file);
$file = '../' . $file;
if (!is_file($file)) if (!is_file($file))
$error = 1; $error = 1;
$file = stripslashes($file); if ((substr($file,0,2) == 'b2') and (substr($file,-4,4) == '.php') and ($file != 'b2.php'))
$warning = ' &#8212; this is a WordPress file, be careful when editing it!';
if ((substr($file,0,2) == "b2") and (substr($file,-4,4) == ".php") and ($file != "b2.php"))
$warning = " - this is a b2 file, be careful when editing it !";
if (!$error) { if (!$error) {
$f = fopen($file,"r"); $f = fopen($file, 'r');
$content = fread($f,filesize($file)); $content = fread($f, filesize($file));
// $content = template_simplify($content);
$content = htmlspecialchars($content); $content = htmlspecialchars($content);
// $content = str_replace("</textarea","&lt;/textarea",$content); // $content = str_replace("</textarea","&lt;/textarea",$content);
} }
echo $blankline;
echo $tabletop;
?> ?>
<table width="100%" cellpadding="5" cellspacing="0"> <div class="wrap">
<tr>
<td>
<?php <?php
echo "Listing <b>$file</b>".$warning; echo "Listing <strong>$file</strong> $warning";
if ($a == "te") if ('te' == $a)
echo "<i> [ file edited ! ]</i>"; echo "<em>File edited successfully.</em>";
if (!$error) { if (!$error) {
?> ?>
@ -126,25 +123,26 @@ default:
</form> </form>
<?php <?php
} else { } else {
echo "<p>oops, no such file !</p>"; echo '<p>Oops, no such file exists! Double check the name and try again, merci.</p>';
} }
echo $tablebottom;
?> ?>
</td> </div>
</table>
<br /> <div class="wrap">
<?php echo $tabletop; ?> <p>You can also edit the <a href="b2template.php?file=b2comments.php">comments
You can also edit the <a href="b2template.php?file=b2comments.php">comments' template</a> or the <a href="b2template.php?file=b2commentspopup.php">popup comments' template</a>, or edit any other file (provided it's writable by the server, e.g. CHMOD 766).<br /> template</a> or the <a href="b2template.php?file=b2commentspopup.php">popup
<br /> comments template</a>, or edit any other file (provided it&#8217;s writable by
To edit a file, type its name here: the server, e.g. CHMOD 766).</p>
<form name="file" action="b2template.php" method="get"> <p>To edit a file, type its name here:</p>
<form name="file" action="b2template.php" method="get">
<input type="text" name="file" /> <input type="text" name="file" />
<input type="submit" name="submit" class="search" value="go" /> <input type="submit" name="submit" class="search" value="go" />
</form> </form>
<br />
Note: of course, you can also edit the files/templates in your text editor and upload them. This online editor is only meant to be used when you don't have access to a text editor...
<?php echo $tablebottom; ?> <p>Note: of course, you can also edit the files/templates in your text editor
and upload them. This online editor is only meant to be used when you don't
have access to a text editor.</p>
</div>
<?php <?php