public function remove($files) { $temp = Helper::getTempDir(); $args = array('action' => 'recursiveRemove', 'params' => array('files' => $files), 'temp' => $temp); $task = $temp['dir'] . 'task'; file_put_contents($task, json_encode($args)); /* // var_dump(Helper::getTaskCmd(), escapeshellarg($task)); RemoteShell::get()->execBackground(Helper::getTaskCmd(), $task ); return $temp;*/ $task_opts = array('requester' => 'filemanager', 'name' => 'remove'); $rtask = new \rTask($task_opts); $commands = array(Helper::getTaskCmd() . " " . escapeshellarg($task)); $ret = $rtask->start($commands, 0); // var_dump($ret); return $temp; }
public static function remove($list) { $tasks = array(); $dir = getSettingsPath() . '/tasks/'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && is_dir($dir . $file) && in_array($file, $list)) { $tasks[] = $file; } } closedir($handle); foreach ($tasks as $id) { rTask::kill($id); } $tasks = self::obtain(); } return $tasks; }
if ($trackersCount > 1) { $torrent->announce_list($announce_list); } } else { $torrent = new Torrent($path_edit, array(), $piece_size, $callback_log, $callback_err); } if (isset($request['comment'])) { $comment = trim($request['comment']); if (strlen($comment)) { $torrent->comment($comment); } } if ($request['private']) { $torrent->is_private(true); } $fname = rTask::formatPath($taskNo) . '/result.torrent'; $torrent->save($fname); if ($request['start_seeding']) { $fname = getUniqueUploadedFilename($torrent->info['name'] . '.torrent'); $path_edit = trim($request['path_edit']); if (is_dir($path_edit)) { $path_edit = addslash($path_edit); } if (rTorrentSettings::get()->correctDirectory($path_edit)) { $path_edit = dirname($path_edit); if ($resumed = rTorrent::fastResume($torrent, $path_edit)) { $torrent = $resumed; } $torrent->save($fname); rTorrent::sendTorrent($torrent, true, true, $path_edit, null, true, isLocalMode()); @chmod($fname, $profileMask & 0666);
public function sfvCreate($paths) { $sfvfile = $this->getUserDir($paths->target); $files = array_map(array($this, 'getWorkDir'), (array) $paths->fls); if (Fs::get()->isFile($sfvfile)) { throw new Exception("File already exists", 16); } $temp = Helper::getTempDir(); $args = array('action' => 'sfvCreate', 'params' => array('files' => $files, 'target' => $sfvfile), 'temp' => $temp); $task = $temp['dir'] . 'task'; file_put_contents($task, json_encode($args)); $task_opts = array('requester' => 'filemanager', 'name' => 'SFV create'); $rtask = new \rTask($task_opts); $commands = array(Helper::getTaskCmd() . " " . escapeshellarg($task)); $ret = $rtask->start($commands, 0); //var_dump($ret); return $temp; }
$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");
<?php require_once "task.php"; $ret = array(); switch ($_REQUEST['cmd']) { case "kill": $ret = rTask::kill($_REQUEST['no']); break; case "check": $ret = rTask::check($_REQUEST['no']); break; case "list": $ret = rTaskManager::obtain(); break; case "remove": $list = array(); if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents("php://input"); } if (isset($HTTP_RAW_POST_DATA)) { $vars = explode('&', $HTTP_RAW_POST_DATA); foreach ($vars as $var) { $parts = explode("=", $var); if ($parts[0] == "no") { $value = trim(rawurldecode($parts[1])); if (strlen($value) && intval($value)) { $list[] = $value; } } } }
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; }
} $piece_size = 262144; if (isset($_REQUEST['piece_size'])) { $piece_size = $_REQUEST['piece_size'] * 1024; } if (!$pathToCreatetorrent || $pathToCreatetorrent == "") { $pathToCreatetorrent = $useExternal; } if ($useExternal == "mktorrent") { $piece_size = log($piece_size, 2); } else { if ($useExternal === false) { $useExternal = "inner"; } } $task = new rTask(array('arg' => call_user_func('getFileName', $path_edit), 'requester' => 'create', 'name' => 'create', 'path_edit' => $_REQUEST['path_edit'], 'trackers' => $_REQUEST['trackers'], 'comment' => $_REQUEST['comment'], 'start_seeding' => $_REQUEST['start_seeding'], 'piece_size' => $_REQUEST['piece_size'], 'private' => $_REQUEST['private'])); $commands = array(); $commands[] = escapeshellarg($rootPath . '/plugins/create/' . $useExternal . '.sh') . " " . $task->id . " " . escapeshellarg(getPHP()) . " " . escapeshellarg($pathToCreatetorrent) . " " . escapeshellarg($path_edit) . " " . $piece_size . " " . escapeshellarg(getUser()) . " " . escapeshellarg(rTask::formatPath($task->id)); $commands[] = '{'; $commands[] = 'chmod a+r "${dir}"/result.torrent'; $commands[] = '}'; $ret = $task->start($commands, 0); break; } else { $error = 'Incorrect directory (' . mb_substr($path_edit, mb_strlen($topDirectory) - 1) . ')'; } } $ret = array("no" => -1, "pid" => 0, "status" => 255, "log" => array(), "errors" => array($error)); break; case "getfile": $dir = rTask::formatPath($_REQUEST['no']);
} if ($filename !== '') { $commands = array(); $offs = $st->data['exfrmoffs']; $useWidth = $st->data['exusewidth']; for ($i = 0; $i < $st->data['exfrmcount']; $i++) { $name = '"${dir}"/frame' . $i . ($st->data['exformat'] ? '.png' : '.jpg'); $commands[] = getExternal("ffmpeg") . ' -ss ' . $offs . " -i " . escapeshellarg($filename) . ' -y -vframes 1 -an ' . ($useWidth ? '-vf "scale=' . $st->data['exfrmwidth'] . ':-1"' : '') . ' ' . $name; $commands[] = '{'; $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; } }
<?php require_once '../_task/task.php'; eval(getPluginConf('mediainfo')); $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(); $commands[] = getExternal("mediainfo") . " " . escapeshellarg($filename); $ret = rTask::start($commands, 0); } } break; } } cachedEcho(json_encode($ret), "application/json");
$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 "ffmpegclose": $dir = rTask::formatPath($_REQUEST['no']); for ($i = 0; $i < $st->data['exfrmcount']; $i++) { @unlink($dir . '/frame' . $i . ($st->data['exformat'] ? '.png' : '.jpg')); } @rmdir($dir); exit; case "ffmpegset": $ret = $st->set(); break; } } cachedEcho(json_encode($ret), "application/json");
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; }