public function videoScreenshots($file, $output)
 {
     $fs = Fs::get();
     $video_file = $this->getUserDir($file);
     $screens_file = $this->getUserDir($output);
     if (!$fs->isFile($video_file)) {
         throw new Exception("Error Processing Request", 6);
     } else {
         if ($fs->isFile($screens_file)) {
             throw new Exception("dest is file", 16);
         }
     }
     $defaults = array('scrows' => '12', 'sccols' => 4, 'scwidth' => 300);
     $uisettings = json_decode(file_get_contents(getSettingsPath() . '/uisettings.json'), true);
     $settings = array();
     foreach ($defaults as $k => $value) {
         $settings[$k] = isset($uisettings['webui.fManager.' . $k]) && $uisettings['webui.fManager.' . $k] > 1 ? $uisettings['webui.fManager.' . $k] : $value;
     }
     $vinfo = $this->video_info($video_file);
     $frame_step = floor($vinfo['total_frames'] / ($settings['scrows'] * $settings['sccols']));
     $settings['frame_step'] = $frame_step;
     $temp = Helper::getTempDir();
     $args = array('action' => 'makeScreensheet', 'params' => array('imgfile' => $screens_file, 'file' => $video_file, 'options' => $settings, 'binary' => getExternal('ffmpeg')), 'temp' => $temp);
     $task = $temp['dir'] . 'task';
     file_put_contents($task, json_encode($args));
     $task_opts = array('requester' => 'filemanager', 'name' => 'screensheet');
     $rtask = new \rTask($task_opts);
     $commands = array(Helper::getTaskCmd() . " " . escapeshellarg($task));
     $ret = $rtask->start($commands, 0);
     //   var_dump($ret);
     return $temp;
 }
Exemple #2
0
 public static function kill($taskNo, $flags = null)
 {
     $dir = self::formatPath($taskNo);
     $ret = array("no" => $taskNo, "pid" => 0, "status" => -1, "log" => array(), "errors" => array());
     if (is_file($dir . '/pid') && is_readable($dir . '/pid')) {
         if (is_null($flags)) {
             $flags = intval(file_get_contents($dir . '/flags'));
         }
         $pid = trim(file_get_contents($dir . '/pid'));
         self::run("kill -9 " . $pid . " ; kill -9 `" . getExternal("pgrep") . " -P " . $pid . "`", $flags & self::FLG_RUN_AS_WEB | self::FLG_WAIT | self::FLG_RUN_AS_CMD);
         self::clean($dir);
     }
     return true;
 }
Exemple #3
0
 public function startTask($hash, $outPath, $mode, $fileno)
 {
     global $rootPath;
     $ret = array("no" => -1, "pid" => 0, "status" => 255, "log" => array(), "errors" => array("Unknown error."));
     if (rTorrentSettings::get()->isPluginRegistered('quotaspace')) {
         require_once dirname(__FILE__) . "/../quotaspace/rquota.php";
         $qt = rQuota::load();
         if (!$qt->check()) {
             $ret["errors"] = array("Quota limitation was reached. Unpack failed.");
             return $ret;
         }
     }
     $taskArgs = array('requester' => 'unpack', 'name' => 'unpack', 'hash' => $hash, 'dir' => $outPath, 'mode' => $mode, 'no' => $fileno);
     if ($outPath != '' && !rTorrentSettings::get()->correctDirectory($outPath)) {
         $outPath = '';
     }
     if (!empty($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);
             }
             $commands = array();
             $arh = getExternal($mode == "zip" ? 'unzip' : 'unrar');
             $commands[] = escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . '_file.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($filename) . " " . escapeshellarg(addslash($outPath));
             $taskArgs['arg'] = call_user_func('end', explode('/', $filename));
             $task = new rTask($taskArgs);
             $ret = $task->start($commands, 0);
         }
     } 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) {
                     $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);
                     }
                     $commands[] = escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . $postfix . '.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($basename) . " " . escapeshellarg($outPath) . " " . escapeshellarg($pathToUnzip);
                     $taskArgs['arg'] = call_user_func('end', explode('/', delslash($basename)));
                     $task = new rTask($taskArgs);
                     $ret = $task->start($commands, 0);
                 }
             }
         }
     }
     return $ret;
 }
Exemple #4
0
$ret = array("status" => 255, "errors" => array("Can't retrieve information"));
if (isset($_REQUEST['hash']) && isset($_REQUEST['no']) && isset($_REQUEST['cmd'])) {
    switch ($_REQUEST['cmd']) {
        case "mediainfo":
            $req = new rXMLRPCRequest(new rXMLRPCCommand("f.get_frozen_path", array($_REQUEST['hash'], intval($_REQUEST['no']))));
            if ($req->success()) {
                $filename = $req->val[0];
                if ($filename == '') {
                    $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.open", $_REQUEST['hash']), new rXMLRPCCommand("f.get_frozen_path", array($_REQUEST['hash'], intval($_REQUEST['no']))), new rXMLRPCCommand("d.close", $_REQUEST['hash'])));
                    if ($req->success()) {
                        $filename = $req->val[1];
                    }
                }
                if ($filename !== '') {
                    $commands = array();
                    $flags = '';
                    $st = mediainfoSettings::load();
                    $task = new rTask(array('arg' => call_user_func('end', explode('/', $filename)), 'requester' => 'mediainfo', 'name' => 'mediainfo', 'hash' => $_REQUEST['hash'], 'no' => $_REQUEST['no']));
                    if ($st && !empty($st->data["mediainfousetemplate"])) {
                        $randName = $task->makeDirectory() . "/opts";
                        file_put_contents($randName, $st->data["mediainfotemplate"]);
                        $flags = "--Inform=file://" . escapeshellarg($randName);
                    }
                    $commands[] = getExternal("mediainfo") . " " . $flags . " " . escapeshellarg($filename);
                    $ret = $task->start($commands, rTask::FLG_WAIT);
                }
            }
            break;
    }
}
cachedEcho(json_encode($ret), "application/json");
Exemple #5
0
function cachedEcho($content, $type = null, $cacheable = false, $exit = true)
{
    header("X-Server-Timestamp: " . strftime('%s'));
    if ($cacheable && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
        $etag = '"' . strtoupper(dechex(crc32($content))) . '"';
        header('Expires: ');
        header('Pragma: ');
        header('Cache-Control: ');
        if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
            header('HTTP/1.0 304 Not Modified');
            return;
        }
        header('Etag: ' . $etag);
    }
    if (!is_null($type)) {
        header("Content-Type: " . $type . "; charset=UTF-8");
    }
    $len = strlen($content);
    if (ini_get("zlib.output_compression") && $len < 2048) {
        ini_set("zlib.output_compression", false);
    }
    if (!ini_get("zlib.output_compression")) {
        if (PHP_USE_GZIP && isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
            if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
                $encoding = 'x-gzip';
            } else {
                if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
                    $encoding = 'gzip';
                }
            }
            if ($encoding && $len >= 2048) {
                $gzip = getExternal('gzip');
                header('Content-Encoding: ' . $encoding);
                $randName = uniqid(getTempDirectory() . "rutorrent-ans-");
                file_put_contents($randName, $content);
                passthru($gzip . " -" . PHP_GZIP_LEVEL . " -c < " . $randName);
                unlink($randName);
                return;
            }
        }
        header("Content-Length: " . $len);
    }
    if ($exit) {
        exit($content);
    } else {
        echo $content;
    }
}
Exemple #6
0
 public function obtain()
 {
     $req = new rXMLRPCRequest(new rXMLRPCCommand("system.client_version"));
     if ($req->run() && count($req->val)) {
         $this->linkExist = true;
         $this->version = $req->val[0];
         $parts = explode('.', $this->version);
         $this->iVersion = 0;
         for ($i = 0; $i < count($parts); $i++) {
             $this->iVersion = ($this->iVersion << 8) + $parts[$i];
         }
         if ($this->iVersion > 0x806) {
             $this->mostOfMethodsRenamed = true;
             $this->aliases = array("d.set_peer_exchange" => "d.peer_exchange.set", "d.set_connection_seed" => "d.connection_seed.set");
         }
         if ($this->iVersion == 0x808) {
             $req = new rXMLRPCRequest(new rXMLRPCCommand("file.prioritize_toc"));
             $req->important = false;
             if ($req->success()) {
                 $this->iVersion = 0x809;
             }
         }
         $this->apiVersion = 0;
         if ($this->iVersion >= 0x901) {
             $req = new rXMLRPCRequest(new rXMLRPCCommand("system.api_version"));
             $req->important = false;
             if ($req->success()) {
                 $this->apiVersion = $req->val[0];
             }
         }
         $req = new rXMLRPCRequest(new rXMLRPCCommand("to_kb", floatval(1024)));
         if ($req->run()) {
             if (!$req->fault) {
                 $this->badXMLRPCVersion = false;
             }
             $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_directory"), new rXMLRPCCommand("get_session"), new rXMLRPCCommand("system.library_version"), new rXMLRPCCommand("set_xmlrpc_size_limit", 67108863), new rXMLRPCCommand("get_name"), new rXMLRPCCommand("get_port_range")));
             if ($req->run() && !$req->fault) {
                 $this->directory = $req->val[0];
                 $this->session = $req->val[1];
                 $this->libVersion = $req->val[2];
                 $this->server = $req->val[4];
                 $this->portRange = $req->val[5];
                 $this->port = intval($this->portRange);
                 if ($this->iVersion >= 0x809) {
                     $req = new rXMLRPCRequest(new rXMLRPCCommand("network.listen.port"));
                     $req->important = false;
                     if ($req->success()) {
                         $this->port = intval($req->val[0]);
                     }
                 }
                 if (isLocalMode()) {
                     if (!empty($this->session)) {
                         $this->started = @filemtime($this->session . '/rtorrent.lock');
                         if ($this->started === false) {
                             $this->started = 0;
                         }
                     }
                     $id = getExternal('id');
                     $req = new rXMLRPCRequest(new rXMLRPCCommand("execute_capture", array("sh", "-c", $id . " -u ; " . $id . " -G ; echo ~ ")));
                     if ($req->run() && !$req->fault && ($line = explode("\n", $req->val[0])) !== false && count($line) > 2) {
                         $this->uid = intval(trim($line[0]));
                         $this->gid = explode(' ', trim($line[1]));
                         $this->home = trim($line[2]);
                         if (!empty($this->directory) && $this->directory[0] == '~') {
                             $this->directory = $this->home . substr($this->directory, 1);
                         }
                     } else {
                         $this->idNotFound = true;
                     }
                 }
                 $this->store();
             }
         }
     }
 }
Exemple #7
0
                     $commands[] = '>' . $i;
                     $commands[] = '}';
                     $offs += $st->data['exfrminterval'];
                 }
                 $commands[] = 'chmod a+r "${dir}"/frame*.*';
             }
             $task = new rTask(array('arg' => call_user_func('getFileName', $filename), 'requester' => 'screenshots', 'name' => 'ffmpeg', 'hash' => $_REQUEST['hash'], 'no' => $_REQUEST['no']));
             $ret = $task->start($commands, rTask::FLG_NO_ERR);
         }
     }
     break;
 case "ffmpeggetall":
     $dir = rTask::formatPath($_REQUEST['no']);
     if (@chdir($dir)) {
         $randName = uniqid(getTempDirectory() . "rutorrent-scrn-");
         exec(escapeshellarg(getExternal('tar')) . " -cf " . $randName . " ./*." . ($st->data['exformat'] ? 'png' : 'jpg'), $results, $return);
         if (is_file($randName)) {
             sendFile($randName, "application/x-tar", $_REQUEST['file'] . '.tar', false);
             unlink($randName);
             exit;
         }
     }
     header('HTTP/1.0 404 Not Found');
     exit;
 case "ffmpeggetimage":
     $dir = rTask::formatPath($_REQUEST['no']);
     $ext = $st->data['exformat'] ? '.png' : '.jpg';
     $filename = $dir . '/frame' . $_REQUEST['fno'] . $ext;
     sendFile($filename, $st->data['exformat'] ? 'image/png' : 'image/jpeg', $_REQUEST['file'] . "-" . str_pad($_REQUEST['fno'] + 1, 3, "0", STR_PAD_LEFT) . $ext);
     exit;
 case "ffmpegset":
Exemple #8
0
             if ($status >= 0) {
                 $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", array("rm", "-fr", $dir)));
                 $req->run();
                 @unlink(getTempDirectory() . "rutorrent-" . getUser() . $taskNo . ".prm");
             }
             $ret = array("no" => intval($taskNo), "status" => $status, "pid" => intval($pid), "out" => $out, "log" => $log, "errors" => $errors);
         }
     }
     break;
 case "kill":
     if (isset($_REQUEST['no'])) {
         $taskNo = $_REQUEST['no'];
         $dir = getTempDirectory() . getUser() . $taskNo;
         if (is_file($dir . '/pid') && is_readable($dir . '/pid')) {
             $pid = trim(file_get_contents($dir . '/pid'));
             $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", array("sh", "-c", "kill -9 `" . getExternal("pgrep") . " -P " . $pid . "`")));
             if ($req->success()) {
                 $ret = array("no" => $taskNo);
             }
             $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", array("rm", "-fr", $dir)));
             $req->run();
             @unlink(getTempDirectory() . "rutorrent-" . getUser() . $taskNo . ".prm");
         }
     }
     break;
 case "get":
     if (isset($_REQUEST['tname'])) {
         $torrent = new Torrent(getUploadsPath() . "/" . $_REQUEST['tname']);
         if (!$torrent->errors()) {
             $torrent->send();
         }
Exemple #9
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;
 }
 public static function getTaskCmd()
 {
     return getExternal("php") . ' ' . dirname(__FILE__) . '/..' . DIRECTORY_SEPARATOR . self::task_file;
 }
 public function extract($to)
 {
     $formatBin = self::getFormatBinary($this->file);
     if (!$formatBin) {
         throw new Exception("Error Processing Request", 18);
     }
     $temp = Helper::getTempDir();
     $args = array('action' => 'extract', 'params' => array('file' => $this->file, 'to' => $to, 'binary' => getExternal($formatBin)), 'temp' => $temp);
     $task = $temp['dir'] . 'task';
     file_put_contents($task, json_encode($args));
     $task_opts = array('requester' => 'filemanager', 'name' => 'unpack');
     $rtask = new \rTask($task_opts);
     $commands = array(Helper::getTaskCmd() . " " . escapeshellarg($task));
     $ret = $rtask->start($commands, 0);
     return $temp;
 }