Exemple #1
0
 public static function fastResume($torrent, $base, $add_path = true)
 {
     $files = array();
     $info = $torrent->info;
     $psize = intval($info['piece length']);
     $base = trim($base);
     if ($base == '') {
         $req = new rXMLRPCRequest(new \model\xmlrpc\rXMLRPCCommand(\config\Conf::$userscgi, 'get_directory'));
         if ($req->success()) {
             $base = $req->val[0];
         }
     }
     if ($psize && \model\xmlrpc\rTorrentSettings::get(\config\Conf::$userscgi)->correctDirectory($base)) {
         $base = addslash($base);
         $tsize = 0.0;
         if (isset($info['files'])) {
             foreach ($info['files'] as $key => $file) {
                 $tsize += floatval($file['length']);
                 $files[] = $add_path ? $info['name'] . "/" . implode('/', $file['path']) : implode('/', $file['path']);
             }
         } else {
             $tsize = floatval($info['length']);
             $files[] = $info['name'];
         }
         $chunks = intval(($tsize + $psize - 1) / $psize);
         $torrent->{'libtorrent_resume'}['bitfield'] = intval($chunks);
         if (!isset($torrent->{'libtorrent_resume'}['files'])) {
             $torrent->{'libtorrent_resume'}['files'] = array();
         }
         foreach ($files as $key => $file) {
             $ss = LFS::stat($base . $file);
             if ($ss === false) {
                 return false;
             }
             if (count($torrent->{'libtorrent_resume'}['files']) < $key) {
                 $torrent->{'libtorrent_resume'}['files'][$key]['mtime'] = $ss["mtime"];
             } else {
                 $torrent->{'libtorrent_resume'}['files'][$key] = array("priority" => 2, "mtime" => $ss["mtime"]);
             }
         }
         return $torrent;
     }
     return false;
 }
 public function add($file, $duration, $password)
 {
     global $limits;
     $file = '/' . $file;
     $pch = explode($this->userdir, $file);
     if (count($pch) < 2 || ($stat = LFS::stat('/' . $file)) === FALSE) {
         die('Invalid file');
     }
     if ($duration < 1 || $this->islimited('duration', $duration)) {
         die('Invalid duration!');
     }
     if ($this->islimited('links', count($this->data))) {
         die('Link limit reached');
     }
     do {
         $token = $this->random_chars();
     } while (isset($this->data[$token]));
     $this->data[$token] = array('file' => $file, 'size' => $stat['size'], 'expire' => time() + 3600 * $duration, 'password' => $password);
     $this->write();
 }
    }
    $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; }
Exemple #4
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;
}
Exemple #5
0
 public function startSilentTask($basename, $downloadname, $label, $name, $hash)
 {
     global $rootPath;
     global $cleanupAutoTasks;
     global $deleteAutoArchives;
     global $unpackToTemp;
     global $unpack_debug_enabled;
     if (rTorrentSettings::get()->isPluginRegistered('quotaspace')) {
         require_once dirname(__FILE__) . "/../quotaspace/rquota.php";
         $qt = rQuota::load();
         if (!$qt->check()) {
             return;
         }
     }
     $pathToUnrar = getExternal("unrar");
     $pathToUnzip = getExternal("unzip");
     $zipPresent = false;
     $rarPresent = false;
     $outPath = $this->path;
     if ($outPath != '' && !rTorrentSettings::get()->correctDirectory($outPath)) {
         $outPath = '';
     }
     if (is_dir($basename)) {
         $postfix = "_dir";
         if ($outPath == '') {
             $outPath = $basename;
         }
         $basename = addslash($basename);
         $filesToDelete = "";
         $downloadname = addslash($downloadname);
         $Directory = new RecursiveDirectoryIterator($basename);
         $Iterator = new RecursiveIteratorIterator($Directory);
         $rarRegex = new RegexIterator($Iterator, '/.*\\.(rar|r\\d\\d|\\d\\d\\d)$/si');
         $zipRegex = new RegexIterator($Iterator, '/.*\\.zip$/si');
         if (USE_UNRAR && sizeof(iterator_to_array($rarRegex)) > 0) {
             $rarPresent = true;
             if ($deleteAutoArchives) {
                 if ($downloadname === $basename) {
                     if ($unpack_debug_enabled) {
                         toLog("Unpack: No move operation enabled. Not deleting files.");
                     }
                 } else {
                     if (!file_exists($downloadname)) {
                         if ($unpack_debug_enabled) {
                             toLog("Unpack: Move operation enabled. Not deleting files.");
                         }
                     } else {
                         foreach ($rarRegex as $fileName) {
                             $filePath = $fileName->getPathname();
                             if (is_link($filePath)) {
                                 if ($unpack_debug_enabled) {
                                     toLog("Unpack: SoftLink operation enabled. Deleting " . $filePath);
                                 }
                                 $filesToDelete .= $filePath . ";";
                             } else {
                                 $stat = LFS::stat($filePath);
                                 if ($stat) {
                                     if ($stat['nlink'] > 1) {
                                         if ($unpack_debug_enabled) {
                                             toLog("Unpack: HardLink operation enabled. Deleting " . $filePath);
                                         }
                                         $filesToDelete .= $filePath . ";";
                                     } else {
                                         if ($unpack_debug_enabled) {
                                             toLog("Unpack: Copy operation enabled. Deleting " . $filePath);
                                         }
                                         $filesToDelete .= $filePath . ";";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (USE_UNZIP && sizeof(iterator_to_array($zipRegex)) > 0) {
             $zipPresent = true;
             if ($deleteAutoArchives) {
                 if ($downloadname === $basename) {
                     if ($unpack_debug_enabled) {
                         toLog("Unpack: No move operation enabled. Not deleting files.");
                     }
                 } else {
                     if (!file_exists($downloadname)) {
                         if ($unpack_debug_enabled) {
                             toLog("Unpack: Move operation enabled. Not deleting files.");
                         }
                     } else {
                         foreach ($zipRegex as $fileName) {
                             $filePath = $fileName->getPathname();
                             if (is_link($filePath)) {
                                 if ($unpack_debug_enabled) {
                                     toLog("Unpack: SoftLink operation enabled. Deleting " . $filePath);
                                 }
                                 $filesToDelete .= $filePath . ";";
                             } else {
                                 $stat = LFS::stat($filePath);
                                 if ($stat) {
                                     if ($stat['nlink'] > 1) {
                                         if ($unpack_debug_enabled) {
                                             toLog("Unpack: HardLink operation enabled. Deleting " . $filePath);
                                         }
                                         $filesToDelete .= $filePath . ";";
                                     } else {
                                         if ($unpack_debug_enabled) {
                                             toLog("Unpack: Copy operation enabled. Deleting " . $filePath);
                                         }
                                         $filesToDelete .= $filePath . ";";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $mode = $rarPresent && $zipPresent ? "all" : ($zipPresent ? "zip" : ($rarPresent ? "rar" : null));
     } else {
         $postfix = "_file";
         if (USE_UNRAR && preg_match("'.*\\.(rar|r\\d\\d|\\d\\d\\d)\$'si", $basename) == 1) {
             $rarPresent = true;
             if ($deleteAutoArchives) {
                 if ($downloadname === $basename) {
                     if ($unpack_debug_enabled) {
                         toLog("Unpack: No move operation enabled. Not deleting files.");
                     }
                 } else {
                     if (!file_exists($downloadname)) {
                         if ($unpack_debug_enabled) {
                             toLog("Unpack: Move operation enabled. Not deleting files.");
                         }
                     } else {
                         if (is_link($basename)) {
                             if ($unpack_debug_enabled) {
                                 toLog("Unpack: SoftLink operation enabled. Deleting " . $basename);
                             }
                             $filesToDelete .= $basename;
                         } else {
                             $stat = LFS::stat($basename);
                             if ($stat) {
                                 if ($stat['nlink'] > 1) {
                                     if ($unpack_debug_enabled) {
                                         toLog("Unpack: HardLink operation enabled. Deleting " . $basename);
                                     }
                                     $filesToDelete .= $basename;
                                 } else {
                                     if ($unpack_debug_enabled) {
                                         toLog("Unpack: Copy operation enabled. Deleting " . $basename);
                                     }
                                     $filesToDelete .= $basename;
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if (USE_UNZIP && preg_match("'.*\\.zip\$'si", $basename) == 1) {
                 $zipPresent = true;
                 if ($deleteAutoArchives) {
                     if ($downloadname === $basename) {
                         if ($unpack_debug_enabled) {
                             toLog("Unpack: No move operation enabled. Not deleting files.");
                         }
                     } else {
                         if (!file_exists($downloadname)) {
                             if ($unpack_debug_enabled) {
                                 toLog("Unpack: Move operation enabled. Not deleting files.");
                             }
                         } else {
                             if (is_link($basename)) {
                                 if ($unpack_debug_enabled) {
                                     toLog("Unpack: SoftLink operation enabled. Deleting " . $basename);
                                 }
                                 $filesToDelete .= $basename;
                             } else {
                                 $stat = LFS::stat($basename);
                                 if ($stat) {
                                     if ($stat['nlink'] > 1) {
                                         if ($unpack_debug_enabled) {
                                             toLog("Unpack: HardLink operation enabled. Deleting " . $basename);
                                         }
                                         $filesToDelete .= $basename;
                                     } else {
                                         if ($unpack_debug_enabled) {
                                             toLog("Unpack: Copy operation enabled. Deleting " . $basename);
                                         }
                                         $filesToDelete .= $basename;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($outPath == '') {
             $outPath = dirname($basename);
         }
         $mode = $zipPresent ? 'zip' : ($rarPresent ? 'rar' : null);
     }
     if ($mode) {
         $arh = $mode == "zip" ? $pathToUnzip : $pathToUnrar;
         $outPath = addslash($outPath);
         if ($this->addLabel && $label != '') {
             $outPath .= addslash($label);
         }
         if ($this->addName && $name != '') {
             $outPath .= addslash($name);
         }
         if ($unpackToTemp) {
             $randTempDirectory = addslash(uniqid(getTempDirectory() . "archive-"));
             if ($unpack_debug_enabled) {
                 toLog("Unpack: Unpack to temp enabled. Unpacking to " . $randTempDirectory);
             }
         } else {
             $randTempDirectory = "";
         }
         $commands[] = escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . $postfix . '.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($basename) . " " . escapeshellarg($outPath) . " " . escapeshellarg($pathToUnzip) . " " . escapeshellarg($filesToDelete) . " " . escapeshellarg($randTempDirectory);
         if ($cleanupAutoTasks) {
             $commands[] = 'rm -r "${dir}"';
         }
         $task = new rTask(array('arg' => call_user_func('getFileName', delslash($basename)), 'requester' => 'unpack', 'name' => 'unpack', 'hash' => $hash, 'dir' => $outPath, 'mode' => null, 'no' => null));
         $ret = $task->start($commands, 0);
     }
 }
Exemple #6
0
function rtMoveFile($src, $dst, $dbg = false)
{
    $ss = LFS::stat($src);
    if (!rename($src, $dst)) {
        if ($dbg) {
            rtDbg(__FUNCTION__, "from " . $src);
        }
        if ($dbg) {
            rtDbg(__FUNCTION__, "to   " . $dst);
        }
        if ($dbg) {
            rtDbg(__FUNCTION__, "move fail, try to copy");
        }
        if (!copy($src, $dst)) {
            if ($dbg) {
                rtDbg(__FUNCTION__, "copy fail");
            }
            return false;
        }
        if (!unlink($src)) {
            if ($dbg) {
                rtDbg(__FUNCTION__, "delete fail (" . $src . ")");
            }
        }
    }
    // there are problems here, if run-user is not file owner
    if ($ss !== false) {
        touch($dst, $ss['mtime'], $ss['atime']);
    }
    return true;
}
function isUserHavePermission($uid, $gid, $file, $flags)
{
    if ($gid <= 0) {
        if ($flags & 0x1 && !is_dir($file)) {
            return ($ss = LFS::stat($file)) && $ss['mode'] & 0x49;
        } else {
            return true;
        }
    }
    if (is_link($file)) {
        $file = readlink($file);
    }
    if (isUserHavePermissionPrim($uid, $gid, $file, $flags)) {
        if ($flags & 0x2 && !is_dir($file)) {
            $flags = 0x7;
        } else {
            $flags = 0x5;
        }
        return isUserHavePermissionPrim($uid, $gid, dirname($file), $flags);
    }
    return false;
}
Exemple #8
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;
 }