}
    $dh = @opendir($dir);
}
$files = array();
$dirs = array();
if ($dh) {
    $dir = addslash($dir);
    while (false !== ($file = readdir($dh))) {
        $path = fullpath($dir . $file);
        if ($file == ".." && $dir == $topDirectory) {
            continue;
        }
        if (is_dir($path) && is_readable($path) && strpos(addslash($path), $topDirectory) === 0 && ($theSettings->uid < 0 || isUserHavePermission($theSettings->uid, $theSettings->gid, $path, 0x5))) {
            $dirs['/' . $file] = $path;
        } else {
            if (LFS::is_file($path) && is_readable($path) && ($theSettings->uid < 0 || isUserHavePermission($theSettings->uid, $theSettings->gid, $path, 0x4))) {
                $files[$file] = $path;
            }
        }
    }
    closedir($dh);
    ksort($files, SORT_STRING);
    ksort($dirs, SORT_STRING);
    $files = array_merge($dirs, $files);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<head>
<style>
body { background-color: window; color: windowtext; border: 0px; margin: 0px; padding: 0px; -moz-user-select:none; }
Beispiel #2
0
function rtIsFile($path)
{
    // use Novik's implementation
    return LFS::is_file($path);
    //if( is_file( $path ) )
    //	return true;
    //$out = array();
    //$ret = "1";
    //exec( 'test -f '.escapeshellarg( $path ), $out, $ret );
    //return (int)$ret == 0;
}
Beispiel #3
0
function sendFile($filename, $contentType = null, $nameToSent = null, $mustExit = true)
{
    $stat = @LFS::stat($filename);
    if ($stat && @LFS::is_file($filename) && @LFS::is_readable($filename)) {
        $etag = sprintf('"%x-%x-%x"', $stat['ino'], $stat['size'], $stat['mtime'] * 1000000);
        if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag || isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $stat['mtime']) {
            header('HTTP/1.0 304 Not Modified');
        } else {
            header('Content-Type: ' . (is_null($contentType) ? 'application/octet-stream' : $contentType));
            if (is_null($nameToSent)) {
                $nameToSent = end(explode('/', $filename));
            }
            if (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
                $nameToSent = rawurlencode($nameToSent);
            }
            header('Content-Disposition: attachment; filename="' . $nameToSent . '"');
            if ($mustExit && function_exists('apache_get_modules') && in_array('mod_xsendfile', apache_get_modules())) {
                header("X-Sendfile: " . $filename);
            } else {
                header('Cache-Control: ');
                header('Expires: ');
                header('Pragma: ');
                header('Etag: ' . $etag);
                header('Last-Modified: ' . date('r', $stat['mtime']));
                set_time_limit(0);
                ignore_user_abort(!$mustExit);
                header('Accept-Ranges: bytes');
                header('Content-Transfer-Encoding: binary');
                header('Content-Description: File Transfer');
                if (ob_get_level()) {
                    while (@ob_end_clean()) {
                    }
                }
                $begin = 0;
                $end = $stat['size'];
                if (isset($_SERVER['HTTP_RANGE'])) {
                    if (preg_match('/bytes=\\h*(\\d+)-(\\d*)[\\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
                        $begin = intval($matches[0]);
                        if (!empty($matches[1])) {
                            $end = intval($matches[1]);
                        }
                    }
                }
                $size = $end - $begin;
                if (PHP_INT_SIZE <= 4 && $size >= 2147483647) {
                    passthru('cat ' . escapeshellarg($filename));
                } else {
                    if (!ini_get("zlib.output_compression")) {
                        header('Content-Length:' . $size);
                    }
                    if ($size != $stat['size']) {
                        $f = @fopen($filename, 'rb');
                        if ($f === false) {
                            header("HTTP/1.0 505 Internal Server Error");
                        } else {
                            header('HTTP/1.0 206 Partial Content');
                            header("Content-Range: bytes " . $begin . "-" . $end . "/" . $stat['size']);
                            $cur = $begin;
                            fseek($f, $begin, 0);
                            while (!feof($f) && $cur < $end && !connection_aborted() && connection_status() == 0) {
                                print fread($f, min(1024 * 16, $end - $cur));
                                $cur += 1024 * 16;
                            }
                            fclose($f);
                        }
                    } else {
                        header('HTTP/1.0 200 OK');
                        readfile($filename);
                    }
                }
            }
        }
        if ($mustExit) {
            exit(0);
        } else {
            return true;
        }
    }
    return false;
}
Beispiel #4
0
 public function startTask($hash, $outPath, $mode = null, $fileno = null, $all = false)
 {
     global $rootPath;
     $ret = false;
     if (rTorrentSettings::get()->isPluginRegistered('quotaspace')) {
         require_once dirname(__FILE__) . "/../quotaspace/rquota.php";
         $qt = rQuota::load();
         if (!$qt->check()) {
             return false;
         }
     }
     if ($outPath != '' && !rTorrentSettings::get()->correctDirectory($outPath)) {
         $outPath = '';
     }
     if (!is_null($fileno) && !is_null($mode)) {
         $req = new rXMLRPCRequest(new rXMLRPCCommand("f.get_frozen_path", array($hash, intval($fileno))));
         if ($req->success()) {
             $filename = $req->val[0];
             if ($filename == '') {
                 $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.open", $hash), new rXMLRPCCommand("f.get_frozen_path", array($hash, intval($fileno))), new rXMLRPCCommand("d.close", $hash)));
                 if ($req->success()) {
                     $filename = $req->val[1];
                 }
             }
             if ($outPath == '') {
                 $outPath = dirname($filename);
             }
             if (LFS::is_file($filename) && $outPath != '') {
                 $taskNo = time();
                 $dir = self::formatPath($taskNo);
                 $pathToUnrar = getExternal('unrar');
                 $pathToUnzip = getExternal('unzip');
                 $arh = $mode == "zip" ? $pathToUnzip : $pathToUnrar;
                 $c = new rXMLRPCCommand("execute", array("sh", "-c", escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . '_file.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($filename) . " " . escapeshellarg(addslash($outPath)) . " " . escapeshellarg($dir . "log") . " " . escapeshellarg($dir . "status") . " &"));
                 if ($all) {
                     $c->addParameter("-v");
                 }
                 $req = new rXMLRPCRequest($c);
                 if ($req->success()) {
                     $ret = array("no" => $taskNo, "name" => $filename, "out" => $outPath);
                 }
             }
         }
     } else {
         $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_base_path", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_name", $hash)));
         if ($req->success()) {
             $basename = $req->val[0];
             $label = rawurldecode($req->val[1]);
             $tname = $req->val[2];
             if ($basename == '') {
                 $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.open", $hash), new rXMLRPCCommand("d.get_base_path", $hash), new rXMLRPCCommand("d.close", $hash)));
                 if ($req->success()) {
                     $basename = $req->val[1];
                 }
             }
             $req = new rXMLRPCRequest(new rXMLRPCCommand("f.multicall", array($hash, "", getCmd("f.get_path="))));
             if ($req->success()) {
                 $rarPresent = false;
                 $zipPresent = false;
                 foreach ($req->val as $no => $name) {
                     if (USE_UNRAR && preg_match("'.*\\.(rar|r\\d\\d|\\d\\d\\d)\$'si", $name) == 1) {
                         $rarPresent = true;
                     } else {
                         if (USE_UNZIP && preg_match("'.*\\.zip\$'si", $name) == 1) {
                             $zipPresent = true;
                         }
                     }
                 }
                 $mode = $rarPresent && $zipPresent ? 'all' : ($rarPresent ? 'rar' : ($zipPresent ? 'zip' : null));
                 if ($mode) {
                     $taskNo = time();
                     $dir = self::formatPath($taskNo);
                     $pathToUnrar = getExternal("unrar");
                     $pathToUnzip = getExternal("unzip");
                     $arh = $mode == "zip" ? $pathToUnzip : $pathToUnrar;
                     if (is_dir($basename)) {
                         $postfix = "_dir";
                         if ($outPath == '') {
                             $outPath = $basename;
                         }
                         $basename = addslash($basename);
                     } else {
                         $postfix = "_file";
                         if ($outPath == '') {
                             $outPath = dirname($basename);
                         }
                         $pathToUnzip = "";
                     }
                     $outPath = addslash($outPath);
                     if ($this->addLabel && $label != '') {
                         $outPath .= addslash($label);
                     }
                     if ($this->addName && $tname != '') {
                         $outPath .= addslash($tname);
                     }
                     $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", array("sh", "-c", escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . $postfix . '.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($basename) . " " . escapeshellarg($outPath) . " " . escapeshellarg($dir . "log") . " " . escapeshellarg($dir . "status") . " " . escapeshellarg($pathToUnzip) . " &")));
                     if ($req->success()) {
                         $ret = array("no" => $taskNo, "name" => $basename, "out" => $outPath);
                     }
                 } else {
                     $ret = array("no" => 0, "name" => $basename, "out" => "");
                 }
             }
         }
     }
     return $ret;
 }