示例#1
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;
 }
示例#2
0
<?php

require_once 'rquota.php';
$qt = rQuota::load();
$qt->update();
$tm = getdate();
$startAt = mktime($tm["hours"], (int) ($tm["minutes"] / $quotaUpdateInterval) * $quotaUpdateInterval + $quotaUpdateInterval, 0, $tm["mon"], $tm["mday"], $tm["year"]) - $tm[0];
if ($startAt < 0) {
    $startAt = 0;
}
$interval = $quotaUpdateInterval * 60;
$req = new rXMLRPCRequest(array(new rXMLRPCCommand("schedule", array('quotaspace' . getUser(), $startAt . "", $interval . "", getCmd('execute') . '={sh,-c,' . escapeshellarg(getPHP()) . ' ' . escapeshellarg($rootPath . '/plugins/quotaspace/update.php') . ' ' . escapeshellarg(getUser()) . ' & exit 0}')), $theSettings->getOnResumedCommand(array('quotapauser' . getUser(), getCmd('execute') . '={sh,' . $rootPath . '/plugins/quotaspace/run.sh' . ',' . getPHP() . ',$' . getCmd("d.get_hash") . '=,$' . getCmd("d.get_complete") . '=,' . getUser() . '}'))));
if ($req->success()) {
    $theSettings->registerPlugin($plugin["name"], $pInfo["perms"]);
} else {
    $jResult .= "plugin.disable(); log('quotaspace: '+theUILang.pluginCantStart);";
}
示例#3
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;
 }