\n"; echo "\n"; echo "".$ptitle."\n"; echo "\n"; echo "\n"; echo "\n"; echo "

".$ptitle."

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($ext != "") { $meh = split("/",$ext); $c = (count($meh) - 1); $meh2 = ""; for ($i = 0; $i < $c; $i++) { $meh2 .= $meh[$i]."/"; } $meh2 = rtrim($meh2,"/"); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } foreach ($drives as $d) { $path = $d."/.gh_trash/".$ext; if ($h = @opendir($path)) { while (false !== ($e = readdir($h))) { if ($e != "." && $e != "..") { $list[] = array($e,$d); } } closedir($h); } } if (@count($list) > 0) { foreach ($list as $l) { if (@in_array($l[0],@$r)) { $q[$l[0]] = (@$q[$l[0]] + 1); } else { $r[] = $l[0]; // First drive is fine if (!isset($z[$l[0]])) { $z[$l[0]] = $l[1]; } } } } if (@count($r) > 0) { foreach ($r as $k) { echo "\n"; if (is_dir($z[$k]."/.gh_trash/".$ext."/".$k)) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } else { $dr = (array_search($z[$k],$drives)+1); echo "\n"; $fsize = filesize($z[$k]."/.gh_trash/".$ext."/".$k); echo "\n"; $ftime = filemtime($z[$k]."/.gh_trash/".$ext."/".$k); echo "\n"; echo "\n"; } echo "\n"; echo ""; } } echo "\n"; echo "
PathSizeModifiedCopiesActions
Parent Directory - - - -
".$k."--".(@$q[$k]+1)."".$k."".$fsize." bytes (".friendlyBytes($fsize).")".strftime("%m/%e/%Y %r",$ftime)."".(@$q[$k]+1)."\n"; echo "
\n"; echo "
\n"; echo "
\n"; $space = getSpace(true); echo "Disk Space Status:
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Total:".$space['total']."
Used:".$space['used']."
Available:".$space['avail']."
Trash:".$space['trash']."
Possible:".$space['possible']."
\n"; echo "
\n"; echo "\n"; } else { if ($view != "" && $drive != "") { $dpath = $drives[($drive-1)]."/.gh_trash"; $fpath = $dpath.$view; $meh = split("/",$fpath); $file = $meh[(count($meh)-1)]; $mime = mime_content_type($fpath); http_send_content_disposition($file,true); http_send_content_type($mime); http_send_file($fpath); exit(); } if ($action == "remove" && $ext != "") { if ($confirm != "Yes") { echo "

Removing ".$ext."

\n"; if (is_dir($ext)) { echo "Are you sure you want to recursively destroy all copies of this directory, and the files within it?
\n"; } else { echo "Are you sure you want to destroy all copies of this file in the trash?
\n"; } echo "This action is not reversable!
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; } else { foreach ($drives as $driv) { $file = $driv."/.gh_trash".$ext; if (is_dir($file)) { rrmdir($file); $removed[] = $file; } else { if (file_exists($file)) { unlink($file); $removed[] = $file; } } } if (count(@$removed) > 0) { echo "

Removed ".$ext."

\n"; echo "The file has been removed from all Greyhole drives.
\n"; echo "
\n"; echo "Removed from:
\n"; foreach ($removed as $r) { echo $r."
\n"; } } else { echo "No such file. Perhaps it was already removed, or you refreshed the page.
"; } echo "
\n"; $meh = split("/",$ext); $c = (count($meh) - 1); $meh2 = ""; for ($i = 0; $i < $c; $i++) { $meh2 .= $meh[$i]."/"; } $meh2 = rtrim($meh2,"/"); echo "Back to directory"; } } if ($action == "restore" && $ext != "") { $dest = "/media/share".$ext; foreach ($drives as $driv) { $file = $driv."/.gh_trash".$ext; if (file_exists($file)) { $sources[] = $file; } } $meh = split("/",$ext); $c = (count($meh) - 1); $meh2 = ""; for ($i = 0; $i < $c; $i++) { $meh2 .= $meh[$i]."/"; } $meh2 = rtrim($meh2,"/"); // First one is fine $source = @$sources[0]; // Unless its an entire folder... if (is_dir($source)) { foreach ($sources as $s) { xcopy($s,$dest); } } elseif (file_exists($source)) { if (!is_dir(dirname($dest))) { mkdir(dirname($dest),0770,true); } copy($source,$dest); } else { echo "No such file. If you restored the file, it has been purged from the trash. Did you refresh the page?
"; } // Delete all copies from trash after restoring if (file_exists($dest)) { foreach ($sources as $s) { if (is_dir($s)) { rrmdir($s); } else { if (file_exists($s)) { unlink($s); } } } } else { echo "Internal error: failed to restore file. Trash untouched.\n"; echo "
\n"; echo "Back to directory"; exit(); } echo "

Restored ".$ext."

\n"; echo "The file has been restored to the share. It will no longer appear in the trash.
\n"; echo "
\n"; echo "Back to directory"; } } function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") { rrmdir($dir."/".$object); } else { unlink($dir."/".$object); } } } reset($objects); rmdir($dir); } } function xcopy($src,$dest) { if (!is_dir($dest)) { mkdir($dest); } foreach (scandir($src) as $file) { if (!is_readable($src.'/'.$file)) continue; if (is_dir($src.'/'.$file)) { if (($file!='.') && ($file!='..')) { if(!is_dir($dest.'/'.$file)) { mkdir($dest . '/' . $file); } xcopy($src.'/'.$file, $dest.'/'.$file); } } else { if (!file_exists($dest.'/'.$file)) { copy($src.'/'.$file, $dest.'/'.$file); } } } } function getSpace($friendlyBytes = false) { $dat = `/usr/bin/greyhole-dfree`; $dat = split(" ",$dat); $space['total'] = $dat[0]; $space['avail'] = $dat[1]; $space['used'] = ($space['total'] - $space['avail']); $space['trash'] = 0; $drives = getDrives(); foreach ($drives as $d) { $dudat = `du -sk $d/.gh_trash/`; $space['trash'] = ($space['trash'] + $dudat); } $space['possible'] = ($space['avail'] + $space['trash']); if ($friendlyBytes) { foreach ($space as $k => $v) { $space[$k] = friendlyBytes($v * 1024); } } return $space; } function getDrives() { $gh = '/etc/greyhole.conf'; $dat = ""; $fp = fopen($gh,'r'); if (!$fp) die("Access to /etc/greyhole.conf denied"); while (!feof($fp)) { $dat .= fread($fp,128); } fclose($fp); $dat = split("\n",$dat); foreach ($dat as $l) { if (substr($l,0,10) == "storage_po") { $m = split(" = ",$l); $n = split(",",$m[1]); $drives[] = $n[0]; } } return $drives; } function friendlyBytes($size) { // Uncomment below to enable rounding to Terabytes. // Leave commented to function as shown in example screenshots. // if ($size > 1099511627776) { // return round(($size / 1099511627776),2)."TB"; // } if ($size > 1073741824) { return round(($size / 1073741824),2)."GB"; } if ($size > 1048576) { return round(($size / 1048576),2)."MB"; } if ($size > 1024) { return round(($size / 1024),2)."KB"; } return $size."B"; }