Beispiel #1
0
 public function correct($deltaUp, $deltaDown)
 {
     $tm = getdate();
     $ndx = $tm["hours"];
     $was = getdate($this->hourHitTimes[$ndx]);
     if ($tm[0] - $this->hourHitTimes[$ndx] > 3600 + 3600 || $ndx != $was["hours"]) {
         $this->hourHitTimes[$ndx] = $tm[0];
         $this->hourUp[$ndx] = 0;
         $this->hourDown[$ndx] = 0;
     }
     $this->hourUp[$ndx] += $deltaUp;
     $this->hourDown[$ndx] += $deltaDown;
     $ndx = $tm["mday"] - 1;
     $was = getdate($this->monthHitTimes[$ndx]);
     if ($tm[0] - $this->monthHitTimes[$ndx] > 3600 * 24 + 3600 || $ndx != $was["mday"] - 1) {
         $this->monthHitTimes[$ndx] = $tm[0];
         $this->monthUp[$ndx] = 0;
         $this->monthDown[$ndx] = 0;
     }
     $this->monthUp[$ndx] += $deltaUp;
     $this->monthDown[$ndx] += $deltaDown;
     $ndx = $tm["mon"] - 1;
     $was = getdate($this->yearHitTimes[$ndx]);
     if ($tm[0] - $this->yearHitTimes[$ndx] > 3600 * 24 * 31 + 3600 || $ndx != $was["mon"] - 1) {
         $this->yearHitTimes[$ndx] = $tm[0];
         $this->yearUp[$ndx] = 0;
         $this->yearDown[$ndx] = 0;
     }
     $this->yearUp[$ndx] += $deltaUp;
     $this->yearDown[$ndx] += $deltaDown;
     rTorrentSettings::get()->pushEvent("TraficUpdated", array("stat" => &$this));
 }
Beispiel #2
0
 public static function sendTorrent($fname, $isStart, $directory = null)
 {
     $hash = false;
     $torrent = is_object($fname) ? $fname : new \model\simple\Torrent($fname);
     if (!$torrent->errors()) {
         $raw_value = base64_encode($torrent->__toString());
         $filename = is_object($fname) ? $torrent->getFileName() : $fname;
         if (strlen($raw_value) < self::RTORRENT_PACKET_LIMIT || is_null($filename)) {
             $cmd = new rXMLRPCCommand(\config\Conf::$userscgi, $isStart ? 'load.raw_start' : 'load.raw');
             $cmd->addParameter("");
             $cmd->addParameter($raw_value, "base64");
             if (!is_null($filename) && !true) {
                 @unlink($filename);
             }
         } else {
             $cmd = new rXMLRPCCommand(\config\Conf::$userscgi, $isStart ? 'load.start' : 'load.normal');
             $cmd->addParameter("");
             $cmd->addParameter($filename);
         }
         if (!is_null($filename) && rTorrentSettings::get(\config\Conf::$userscgi)->iVersion >= 0x805) {
             $cmd->addParameter(rTorrentSettings::getCmd(\config\Conf::$userscgi, "d.custom.set") . "=x-filename," . rawurlencode(basename($filename)));
         }
         $req = new rXMLRPCRequest(\config\Conf::$userscgi);
         $req->addCommand($cmd);
         if (!is_null($directory)) {
             $cmd->addParameter(rTorrentSettings::getCmd(\config\Conf::$userscgi, "d.directory.set=") . "\"" . $directory . "\"");
         }
         if ($req->run() && !$req->fault) {
             $hash = $req->val;
         }
     }
     return $hash;
 }
Beispiel #3
0
 public function init()
 {
     $req = new rXMLRPCRequest();
     for ($i = 0; $i < MAX_THROTTLE; $i++) {
         if ($this->isCorrect($i)) {
             $up = $this->thr[$i]["up"];
             $down = $this->thr[$i]["down"];
         } else {
             $up = 0;
             $down = 0;
         }
         $req->addCommand(new rXMLRPCCommand("throttle_up", array("thr_" . $i, $up . "")));
         $req->addCommand(new rXMLRPCCommand("throttle_down", array("thr_" . $i, $down . "")));
     }
     if ($this->isCorrect($this->default - 1)) {
         $req->addCommand(rTorrentSettings::get()->getOnInsertCommand(array('_throttle' . getUser(), getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd("d.get_throttle_name") . '=,' . getCmd('d.set_throttle_name') . '=thr_' . ($this->default - 1))));
     } else {
         $req->addCommand(rTorrentSettings::get()->getOnInsertCommand(array('_throttle' . getUser(), getCmd('cat='))));
     }
     return $req->run() && !$req->fault;
 }
Beispiel #4
0
 public static function load($mngr = null)
 {
     $cache = new rCache();
     $ar = new rURLRewriteRulesList();
     $cache->get($ar);
     if (rTorrentSettings::get()->isPluginRegistered("rss")) {
         $changed = false;
         if (is_null($mngr)) {
             require_once dirname(__FILE__) . '/../rss/rss.php';
             $mngr = new rRSSManager();
         }
         foreach ($ar->lst as $rule) {
             if (!empty($rule->rssHash) && !$mngr->rssList->isExist($rule->rssHash) && !$mngr->groups->get($rule->rssHash)) {
                 $rule->rssHash = '';
                 $changed = true;
             }
         }
         if ($changed) {
             $ar->store();
         }
     }
     return $ar;
 }
Beispiel #5
0
 public static function run($hash, $state = null, $time = null, $successful_time = null)
 {
     if (is_null($state)) {
         self::getState($hash, $state, $time, $successful_time);
     }
     if ($state == self::STE_INPROGRESS && time() - $time > self::MAX_LOCK_TIME) {
         $state = 0;
     }
     if ($state !== self::STE_INPROGRESS) {
         $state = self::STE_INPROGRESS;
         if (!self::setState($hash, $state)) {
             return false;
         }
         $fname = rTorrentSettings::get()->session . $hash . ".torrent";
         if (is_readable($fname)) {
             $state = self::run_ex($hash, $fname);
         }
         if ($state == self::STE_INPROGRESS) {
             $state = self::STE_ERROR;
         }
         if (!is_null($state)) {
             self::setState($hash, $state);
         }
     }
     return $state != self::STE_CANT_REACH_TRACKER;
 }
Beispiel #6
0
<?php

$req = new rXMLRPCRequest(rTorrentSettings::get()->getRemoveScheduleCommand('rutracker_check'));
$req->run();
Beispiel #7
0
    Debug("enabled          : " . $at->enable_watch);
    Debug("autostart        : " . $at->watch_start);
    if ($at->enable_watch) {
        $auto_start = $at->watch_start;
        $path_to_watch = rtAddTailSlash(trim($at->path_to_watch));
        Debug("path_to_watch    : " . $path_to_watch);
        if ($path_to_watch == '' || $path_to_watch == '/') {
            $is_ok = false;
        }
    } else {
        $is_ok = false;
    }
}
// Ask info from rTorrent
if ($is_ok) {
    $directory = rtAddTailSlash(rTorrentSettings::get()->directory);
    Debug("get_directory    : " . $directory);
    if ($directory == '' || $directory == '/') {
        $is_ok = false;
    }
}
// Scan for *.torrent files at $path_to_watch
if ($is_ok) {
    $files = rtScanFiles($path_to_watch, "/.*\\.torrent\$/i");
    // ignore case
    foreach ($files as $file) {
        $torrent_file = $path_to_watch . $file;
        // don't use realpath() here !!!
        $dest_path = rtAddTailSlash(dirname($directory . $file));
        Debug("torrent file     : " . $torrent_file);
        Debug("save data to     : " . $dest_path);
Beispiel #8
0
<?php

require_once "xmlrpc.php";
eval(getPluginConf($plugin["name"]));
$session = rTorrentSettings::get()->session;
if (!strlen($session) || !@file_exists(addslash(rTorrentSettings::get()->session) . '.')) {
    $jResult .= "plugin.disable(); noty('" . $plugin["name"] . ": '+theUILang.webBadSessionError+' (" . $session . ").','error');";
} else {
    if ($updateInterval) {
        $req = new rXMLRPCRequest($theSettings->getScheduleCommand('rutracker_check', $updateInterval, getCmd('execute') . '={sh,-c,' . escapeshellarg(getPHP()) . ' ' . escapeshellarg(dirname(__FILE__) . '/update.php') . ' ' . escapeshellarg(getUser()) . ' &}'));
        if ($req->success()) {
            $theSettings->registerPlugin($plugin["name"], $pInfo["perms"]);
        } else {
            $jResult .= "plugin.disable(); noty('rutracker_check: '+theUILang.pluginCantStart, 'error');";
        }
    } else {
        require 'done.php';
        $theSettings->registerPlugin($plugin["name"], $pInfo["perms"]);
    }
}
Beispiel #9
0
     }
     break;
 case "add_peer":
     $req = new rXMLRPCRequest(new rXMLRPCCommand("add_peer", array($hash[0], $vs[0])));
     if ($req->success()) {
         $result = $req->val;
     }
     break;
 case "getchunks":
     $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_bitfield", $hash[0]), new rXMLRPCCommand("d.get_chunk_size", $hash[0]), new rXMLRPCCommand("d.get_size_chunks", $hash[0])));
     if (rTorrentSettings::get()->apiVersion >= 4) {
         $req->addCommand(new rXMLRPCCommand("d.chunks_seen", $hash[0]));
     }
     if ($req->success()) {
         $result = array("chunks" => $req->val[0], "size" => $req->val[1], "tsize" => $req->val[2]);
         if (rTorrentSettings::get()->apiVersion >= 4) {
             $result["seen"] = $req->val[3];
         }
     }
     break;
 default:
     if (isset($HTTP_RAW_POST_DATA)) {
         $result = rXMLRPCRequest::send($HTTP_RAW_POST_DATA);
         if (!empty($result)) {
             $pos = strpos($result, "\r\n\r\n");
             if ($pos !== false) {
                 $result = substr($result, $pos + 4);
             }
             cachedEcho($result, "text/xml");
         }
     }
Beispiel #10
0
 protected function makeCall()
 {
     rTorrentSettings::get()->patchDeprecatedRequest($this->commands);
     $this->fault = false;
     $this->content = "";
     $cnt = count($this->commands);
     if ($cnt > 0) {
         $this->content = '<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>';
         if ($cnt == 1) {
             $cmd = $this->commands[0];
             $this->content .= "{$cmd->command}</methodName><params>\r\n";
             foreach ($cmd->params as &$prm) {
                 $this->content .= "<param><value><{$prm->type}>{$prm->value}</{$prm->type}></value></param>\r\n";
             }
         } else {
             $this->content .= "system.multicall</methodName><params><param><value><array><data>";
             foreach ($this->commands as &$cmd) {
                 $this->content .= "\r\n<value><struct><member><name>methodName</name><value><string>" . "{$cmd->command}</string></value></member><member><name>params</name><value><array><data>";
                 foreach ($cmd->params as &$prm) {
                     $this->content .= "\r\n<value><{$prm->type}>{$prm->value}</{$prm->type}></value>";
                 }
                 $this->content .= "\r\n</data></array></value></member></struct></value>";
             }
             $this->content .= "\r\n</data></array></value></param>";
         }
         $this->content .= "</params></methodCall>";
     }
     return $cnt > 0;
 }
Beispiel #11
0
        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);
            }
        }
        exit(0);
    }
    exit(1);
}
Beispiel #12
0
if ($at->setHandlers()) {
    $jResult .= $at->get();
    if ($do_diagnostic) {
        if ($at->enable_move) {
            $path_to_finished = trim($at->path_to_finished);
            if (!rTorrentSettings::get()->correctDirectory($path_to_finished)) {
                $path_to_finished = '';
            }
            if ($path_to_finished == '') {
                $jResult .= "plugin.showError('theUILang.autotoolsNoPathToFinished');";
            } else {
                $session = rTorrentSettings::get()->session;
                if (!strlen($session) || !@file_exists(addslash(rTorrentSettings::get()->session) . '.')) {
                    $jResult .= "plugin.disable(); noty('" . $plugin["name"] . ": '+theUILang.webBadSessionWarning+' (" . $session . ").','error');";
                }
            }
        }
        if ($at->enable_watch) {
            $path_to_watch = trim($at->path_to_watch);
            if (!rTorrentSettings::get()->correctDirectory($path_to_watch)) {
                $path_to_watch = '';
            }
            if ($path_to_watch == '') {
                $jResult .= "plugin.showError('theUILang.autotoolsNoPathToWatch');";
            }
        }
    }
    $theSettings->registerPlugin($plugin["name"], $pInfo["perms"]);
} else {
    $jResult .= "plugin.disable(); noty('autotools: '+theUILang.pluginCantStart,'error');";
}
Beispiel #13
0
 public function setHandlers()
 {
     global $rootPath;
     $throttleRulesExist = false;
     $ratioRulesExist = false;
     foreach ($this->lst as $item) {
         if ($item->ratio != '') {
             $ratioRulesExist = true;
         }
         if ($item->channel != '') {
             $throttleRulesExist = true;
         }
     }
     if ($ratioRulesExist) {
         eval(getPluginConf('ratio'));
         $insCmd = '';
         for ($i = 0; $i < MAX_RATIO; $i++) {
             $insCmd .= getCmd('d.views.has=') . 'rat_' . $i . ',,';
         }
         $ratCmd = getCmd('d.set_custom') . '=x-extratio1,"$' . getCmd('execute_capture') . '={' . getPHP() . ',' . $rootPath . '/plugins/extratio/update.php,\\"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#\\",$' . getCmd('d.get_custom1') . '=,ratio,' . getUser() . '}" ; ' . getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd('d.get_custom') . '=x-extratio1,,' . $insCmd . getCmd('view.set_visible') . '=$' . getCmd('d.get_custom') . '=x-extratio1';
     } else {
         $ratCmd = getCmd('cat=');
     }
     if ($throttleRulesExist) {
         $thrCmd = getCmd('d.set_custom') . '=x-extratio2,"$' . getCmd('execute_capture') . '={' . getPHP() . ',' . $rootPath . '/plugins/extratio/update.php,\\"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#\\",$' . getCmd('d.get_custom1') . '=,channel,' . getUser() . '}" ; ' . getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd('d.get_custom') . '=x-extratio2,,' . getCmd('d.set_throttle_name') . '=$' . getCmd('d.get_custom') . '=x-extratio2';
     } else {
         $thrCmd = getCmd('cat=');
     }
     $req = new rXMLRPCRequest(array(rTorrentSettings::get()->getOnInsertCommand(array('_exratio1' . getUser(), $ratCmd)), rTorrentSettings::get()->getOnInsertCommand(array('_exratio2' . getUser(), $thrCmd))));
     return $req->success();
 }
Beispiel #14
0
 public function setHandlers()
 {
     global $rootPath;
     if ($this->log["addition"] || $this->log["pushbullet_enabled"] && $this->log["pushbullet_addition"]) {
         $addCmd = getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/history/update.php' . ',1,$' . getCmd('d.get_name') . '=,$' . getCmd('d.get_size_bytes') . '=,$' . getCmd('d.get_bytes_done') . '=,$' . getCmd('d.get_up_total') . '=,$' . getCmd('d.get_ratio') . '=,$' . getCmd('d.get_creation_date') . '=,$' . getCmd('d.get_custom') . '=addtime,$' . getCmd('d.get_custom') . '=seedingtime' . ',"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#",$' . getCmd('d.get_custom1') . "=,\$" . getCmd('d.get_custom') . "=x-pushbullet," . getUser() . '}';
     } else {
         $addCmd = getCmd('cat=');
     }
     if ($this->log["finish"] || $this->log["pushbullet_enabled"] && $this->log["pushbullet_finish"]) {
         $finCmd = getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/history/update.php' . ',2,$' . getCmd('d.get_name') . '=,$' . getCmd('d.get_size_bytes') . '=,$' . getCmd('d.get_bytes_done') . '=,$' . getCmd('d.get_up_total') . '=,$' . getCmd('d.get_ratio') . '=,$' . getCmd('d.get_creation_date') . '=,$' . getCmd('d.get_custom') . '=addtime,$' . getCmd('d.get_custom') . '=seedingtime' . ',"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#",$' . getCmd('d.get_custom1') . "=,\$" . getCmd('d.get_custom') . "=x-pushbullet," . getUser() . '}';
     } else {
         $finCmd = getCmd('cat=');
     }
     if ($this->log["deletion"] || $this->log["pushbullet_enabled"] && $this->log["pushbullet_deletion"]) {
         $delCmd = getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/history/update.php' . ',3,$' . getCmd('d.get_name') . '=,$' . getCmd('d.get_size_bytes') . '=,$' . getCmd('d.get_bytes_done') . '=,$' . getCmd('d.get_up_total') . '=,$' . getCmd('d.get_ratio') . '=,$' . getCmd('d.get_creation_date') . '=,$' . getCmd('d.get_custom') . '=addtime,$' . getCmd('d.get_custom') . '=seedingtime' . ',"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#",$' . getCmd('d.get_custom1') . "=,\$" . getCmd('d.get_custom') . "=x-pushbullet," . getUser() . '}';
     } else {
         $delCmd = getCmd('cat=');
     }
     $req = new rXMLRPCRequest(array(rTorrentSettings::get()->getOnInsertCommand(array('thistory' . getUser(), $addCmd)), rTorrentSettings::get()->getOnFinishedCommand(array('thistory' . getUser(), $finCmd)), rTorrentSettings::get()->getOnEraseCommand(array('thistory' . getUser(), $delCmd))));
     return $req->success();
 }
Beispiel #15
0
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 if (count($trackers) > 0) {
     $announce_list[] = $trackers;
 }
 if ($setComment || $setTrackers || $setPrivate) {
     foreach ($hashes as $hash) {
         $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_session"), new rXMLRPCCommand("d.is_open", $hash), new rXMLRPCCommand("d.is_active", $hash), new rXMLRPCCommand("d.get_state", $hash), new rXMLRPCCommand("d.get_tied_to_file", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_directory_base", $hash), new rXMLRPCCommand("d.get_connection_seed", $hash), new rXMLRPCCommand("d.get_complete", $hash)));
         $throttle = null;
         if (rTorrentSettings::get()->isPluginRegistered("throttle")) {
             $req->addCommand(new rXMLRPCCommand("d.get_throttle_name", $hash));
         }
         if ($req->run() && !$req->fault) {
             $isStart = $req->val[1] != 0 && $req->val[2] != 0 && $req->val[3] != 0;
             $fname = $req->val[0] . $hash . ".torrent";
             if (empty($req->val[0]) || !is_readable($fname)) {
                 if (strlen($req->val[4]) && is_readable($req->val[4])) {
                     $fname = $req->val[4];
                 } else {
                     $fname = null;
                 }
             }
             if ($fname) {
                 $torrent = new Torrent($fname);
                 if (!$torrent->errors()) {
Beispiel #16
0
require_once "./util_rt.php";
require_once "./autotools.php";
$base_path = $argv[1];
$base_name = $argv[2];
$is_multy = $argv[3];
$base_path = rtRemoveTailSlash($base_path);
$base_path = rtRemoveLastToken($base_path, '/');
// filename or dirname
$base_path = rtAddTailSlash($base_path);
$dest_path = $base_path;
$at = rAutoTools::load();
if ($at->enable_move) {
    $path_to_finished = trim($at->path_to_finished);
    if ($path_to_finished != '') {
        $path_to_finished = rtAddTailSlash($path_to_finished);
        $directory = rTorrentSettings::get()->directory;
        if (!empty($directory)) {
            $directory = rtAddTailSlash($directory);
            $rel_path = rtGetRelativePath($directory, $base_path);
            //------------------------------------------------------------------------------
            // !! this is a feature !!
            // ($rel_path == '') means, that $base_path is NOT a SUBDIR of $directory at all
            // so, we have to skip all automove actions
            // for example, if we don't want torrent to be automoved - we save it out of $directory subtree
            //------------------------------------------------------------------------------
            if ($rel_path != '') {
                if ($rel_path == './') {
                    $rel_path = '';
                }
                $dest_path = rtAddTailSlash($path_to_finished . $rel_path);
            }
Beispiel #17
0
 public static function loadHistory($withRSS = false)
 {
     $cache = new rCache();
     $history = new rSearchHistory();
     $cache->get($history);
     if ($withRSS) {
         if (rTorrentSettings::get()->isPluginRegistered("rss")) {
             global $rootPath;
             require_once $rootPath . '/plugins/rss/rss.php';
             $cache = new rCache('/rss/cache');
             $rssHistory = new rRSSHistory();
             if ($cache->get($rssHistory)) {
                 foreach ($rssHistory->lst as $url => $info) {
                     if (strlen($info["hash"]) == 40) {
                         $history->add($url, $info["hash"]);
                     }
                 }
             }
         }
     }
     return $history;
 }
Beispiel #18
0
function rtSetDataDir($hash, $dest_path, $add_path, $move_files, $fast_resume, $dbg = false)
{
    if ($dbg) {
        rtDbg(__FUNCTION__, "hash        : " . $hash);
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "dest_path   : " . $dest_path);
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "add path    : " . ($add_path ? "1" : "0"));
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "move files  : " . ($move_files ? "1" : "0"));
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "fast resume : " . ($fast_resume ? "1" : "0"));
    }
    $is_open = false;
    $is_active = false;
    $is_multy_file = false;
    $base_name = '';
    $base_path = '';
    $base_file = '';
    $is_ok = true;
    if ($dest_path == '') {
        $is_ok = false;
    } else {
        $dest_path = rtAddTailSlash($dest_path);
    }
    // Check if torrent is open or active
    if ($is_ok) {
        $req = rtExec(array("d.is_open", "d.is_active"), $hash, $dbg);
        if (!$req) {
            $is_ok = false;
        } else {
            $is_open = $req->val[0] != 0;
            $is_active = $req->val[1] != 0;
            if ($dbg) {
                rtDbg(__FUNCTION__, "is_open=" . $req->val[0] . ", is_active=" . $req->val[1]);
            }
        }
    }
    // Open closed torrent to get d.get_base_path, d.get_base_filename
    if ($is_ok && $move_files) {
        if (!$is_open && !rtExec("d.open", $hash, $dbg)) {
            $is_ok = false;
        }
    }
    // Ask info from rTorrent
    if ($is_ok && $move_files) {
        $req = rtExec(array("d.get_name", "d.get_base_path", "d.get_base_filename", "d.is_multi_file", "d.get_complete"), $hash, $dbg);
        if (!$req) {
            $is_ok = false;
        } else {
            $base_name = trim($req->val[0]);
            $base_path = trim($req->val[1]);
            $base_file = trim($req->val[2]);
            $is_multy_file = $req->val[3] != 0;
            if ($req->val[4] == 0) {
                // if torrent is not completed -> "fast start" is impossible
                $fast_resume = false;
            }
            if ($dbg) {
                rtDbg(__FUNCTION__, "d.get_name          : " . $base_name);
            }
            if ($dbg) {
                rtDbg(__FUNCTION__, "d.get_base_path     : " . $base_path);
            }
            if ($dbg) {
                rtDbg(__FUNCTION__, "d.get_base_filename : " . $base_file);
            }
            if ($dbg) {
                rtDbg(__FUNCTION__, "d.is_multy_file     : " . $req->val[3]);
            }
            if ($dbg) {
                rtDbg(__FUNCTION__, "d.get_complete      : " . $req->val[4]);
            }
        }
    }
    // Check if paths are valid
    if ($is_ok && $move_files) {
        if ($base_path == '' || $base_file == '') {
            if ($dbg) {
                rtDbg(__FUNCTION__, "base paths are empty");
            }
            $is_ok = false;
        } else {
            // Make $base_path a really BASE path for downloading data
            // (not including single file or subdir for multiple files).
            // Add trailing slash, if none.
            $base_path = rtRemoveTailSlash($base_path);
            $base_path = rtRemoveLastToken($base_path, '/');
            // filename or dirname
            $base_path = rtAddTailSlash($base_path);
        }
    }
    // Get list of torrent data files
    $torrent_files = array();
    if ($is_ok && $move_files) {
        $req = rtExec("f.multicall", array($hash, "", "f.get_path="), $dbg);
        if (!$req) {
            $is_ok = false;
        } else {
            $torrent_files = $req->val;
            if ($dbg) {
                rtDbg(__FUNCTION__, "files in torrent    : " . count($torrent_files));
            }
        }
    }
    // 1. Stop torrent if active (if not, then rTorrent can crash)
    // 2. Close torrent anyway
    if ($is_ok) {
        $cmds = array();
        if ($is_active) {
            $cmds[] = "d.stop";
        }
        if ($is_open || $move_files) {
            $cmds[] = "d.close";
        }
        if (count($cmds) > 0 && !rtExec($cmds, $hash, $dbg)) {
            $is_ok = false;
        }
    }
    // Move torrent data files to new location
    if ($is_ok && $move_files) {
        $full_base_path = $base_path;
        $full_dest_path = $dest_path;
        // Don't use "count( $torrent_files ) > 1" check (there can be one file in a subdir)
        if ($is_multy_file) {
            // torrent is a directory
            $full_base_path .= rtAddTailSlash($base_file);
            $full_dest_path .= $add_path ? rtAddTailSlash($base_name) : "";
        } else {
            // torrent is a single file
        }
        if ($dbg) {
            rtDbg(__FUNCTION__, "from " . $full_base_path);
        }
        if ($dbg) {
            rtDbg(__FUNCTION__, "to   " . $full_dest_path);
        }
        if ($full_base_path != $full_dest_path && is_dir($full_base_path)) {
            if (!rtOpFiles($torrent_files, $full_base_path, $full_dest_path, "Move", $dbg)) {
                $is_ok = false;
            } else {
                // Recursively remove source dirs without files
                if ($dbg) {
                    rtDbg(__FUNCTION__, "clean " . $full_base_path);
                }
                if ($is_multy_file) {
                    rtRemoveDirectory($full_base_path, false);
                    if ($dbg && is_dir($full_base_path)) {
                        rtDbg(__FUNCTION__, "some files were not deleted");
                    }
                }
            }
        }
    }
    if ($is_ok) {
        // fast resume is requested
        if ($fast_resume) {
            if ($dbg) {
                rtDbg(__FUNCTION__, "trying fast resume");
            }
            // collect variables
            $session = rTorrentSettings::get()->session;
            $tied_to_file = null;
            $label = null;
            $addition = null;
            $req = rtExec(array("get_session", "d.get_tied_to_file", "d.get_custom1", "d.get_connection_seed", "d.get_throttle_name"), $hash, $dbg);
            if (!$req) {
                $fast_resume = false;
            } else {
                $session = $req->val[0];
                $tied_to_file = $req->val[1];
                $label = rawurldecode($req->val[2]);
                $addition = array();
                if (!empty($req->val[3])) {
                    $addition[] = getCmd("d.set_connection_seed=") . $req->val[3];
                }
                if (!empty($req->val[4])) {
                    $addition[] = getCmd("d.set_throttle_name=") . $req->val[4];
                }
                // build path to .torrent file
                $fname = rtAddTailSlash($session) . $hash . ".torrent";
                if (empty($session) || !is_readable($fname)) {
                    if (!strlen($tied_to_file) || !is_readable($tied_to_file)) {
                        if ($dbg) {
                            rtDbg(__FUNCTION__, "empty session or inaccessible .torrent file");
                        }
                        $fname = null;
                        $fast_resume = false;
                    } else {
                        $fname = $tied_to_file;
                    }
                }
            }
            // create torrent, remove old and add new one
            if ($fast_resume) {
                $torrent = new Torrent($fname);
                if ($torrent->errors()) {
                    if ($dbg) {
                        rtDbg(__FUNCTION__, "fail to create Torrent object");
                    }
                    $fast_resume = false;
                } else {
                    $is_ok = $add_path ? rtExec("d.set_directory", array($hash, $dest_path), $dbg) : rtExec("d.set_directory_base", array($hash, $dest_path), $dbg);
                    // for erasedata plugin
                    if ($is_ok) {
                        if (!rtExec("d.erase", $hash, $dbg)) {
                            if ($dbg) {
                                rtDbg(__FUNCTION__, "fail to erase old torrent");
                            }
                            $fast_resume = false;
                        } else {
                            if (!rTorrent::sendTorrent($torrent, true, $add_path, $dest_path, $label, true, true, false, $addition)) {
                                if ($dbg) {
                                    rtDbg(__FUNCTION__, "fail to add new torrent");
                                }
                                $fast_resume = false;
                                $is_ok = false;
                            }
                        }
                    }
                }
            }
            if ($dbg) {
                rtDbg(__FUNCTION__, "fast resume " . ($fast_resume ? "done" : "fail"));
            }
        }
        // fast resume is fail or not requested at all
        if ($is_ok && !$fast_resume) {
            // Setup new directory for torrent (we need to stop it first)
            $is_ok = $add_path ? rtExec("d.set_directory", array($hash, $dest_path), $dbg) : rtExec("d.set_directory_base", array($hash, $dest_path), $dbg);
            if ($is_ok) {
                // Start torrent if need
                if ($is_active) {
                    $is_ok = rtExec(array("d.open", "d.start"), $hash, $dbg);
                } elseif ($is_open) {
                    $is_ok = rtExec("d.open", $hash, $dbg);
                } else {
                    $is_ok = rtExec(array("d.open", "d.close"), $hash, $dbg);
                }
            }
        }
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "finished");
    }
    return $is_ok;
}
Beispiel #19
0
 public function setHandlers()
 {
     $theSettings = rTorrentSettings::get();
     $pathToXmpp = dirname(__FILE__);
     $req = new rXMLRPCRequest();
     if ($this->message !== '' && isset($this->jabberServer) && isset($this->jabberLogin) && isset($this->jabberPasswd) && isset($this->jabberFor)) {
         $cmd = $theSettings->getOnFinishedCommand(array('xmpp' . getUser(), getCmd('execute.nothrow.bg') . '={' . getPHP() . ',' . $pathToXmpp . '/notify.php,"$' . getCmd('d.name') . '=","' . getUser() . '"}'));
     } else {
         $cmd = $theSettings->getOnFinishedCommand(array('xmpp' . getUser(), getCmd('cat=')));
     }
     $req->addCommand($cmd);
     return $req->success();
 }
Beispiel #20
0
if ($handle = opendir('../plugins')) {
    ignore_user_abort(true);
    set_time_limit(0);
    $tmp = getTempDirectory();
    if ($tmp != '/tmp/') {
        makeDirectory($tmp);
    }
    if (!@file_exists($tempDirectory . '/.') || !is_readable($tempDirectory) || !is_writable($tempDirectory)) {
        $jResult .= "noty(theUILang.badTempPath+' (" . $tempDirectory . ")','error');";
    }
    if (!function_exists('preg_match_all')) {
        $jResult .= "noty(theUILang.PCRENotFound,'error');";
        $jResult .= "theWebUI.systemInfo.rTorrent = { started: false, iVersion : 0, version : '?', libVersion : '?' };\n";
    } else {
        $remoteRequests = array();
        $theSettings = rTorrentSettings::get(true);
        if (!$theSettings->linkExist) {
            $jResult .= "noty(theUILang.badLinkTorTorrent,'error');";
            $jResult .= "theWebUI.systemInfo.rTorrent = { started: false, iVersion : 0, version : '?', libVersion : '?', apiVersion : 0 };\n";
        } else {
            if ($theSettings->idNotFound) {
                $jResult .= "noty(theUILang.idNotFound,'error');";
            }
            $jResult .= "theWebUI.systemInfo.rTorrent = { started: true, iVersion : " . $theSettings->iVersion . ", version : '" . $theSettings->version . "', libVersion : '" . $theSettings->libVersion . "', apiVersion : " . $theSettings->apiVersion . " };\n";
            if ($do_diagnostic) {
                $up = getUploadsPath();
                $st = getSettingsPath();
                @chmod($up, $profileMask);
                @chmod($st, $profileMask);
                @chmod('./test.sh', $profileMask & 0755);
                if (PHP_USE_GZIP && findEXE('gzip') === false) {
Beispiel #21
0
<?php

require_once dirname(__FILE__) . "/../../php/settings.php";
require_once dirname(__FILE__) . "/../../php/Snoopy.class.inc";
$ret = 0;
$port = rTorrentSettings::get()->port;
$client = new Snoopy();
$client->read_timeout = 15;
$client->use_gzip = HTTP_USE_GZIP;
@$client->fetch("http://www.canyouseeme.org", "POST", "application/x-www-form-urlencoded", "port=" . $port . "&submit=Check+Your+Port");
if ($client->status == 200) {
    if (strpos($client->results, ">Error:<") !== false) {
        $ret = 1;
    } else {
        if (strpos($client->results, ">Success:<") !== false) {
            $ret = 2;
        }
    }
}
cachedEcho('{ "port": ' . $port . ', "status": ' . $ret . ' }', "application/json");
<?php

require_once '../../php/util.php';
require_once '../../php/settings.php';
$theSettings = rTorrentSettings::get();
$dh = false;
$curFile = null;
$btn_id = "'" . $_REQUEST['btn'] . "'";
$edit_id = "'" . $_REQUEST['edit'] . "'";
$frame_id = "'" . $_REQUEST['frame'] . "'";
if (isset($_REQUEST['dir'])) {
    $dir = rawurldecode($_REQUEST['dir']);
    if (LFS::is_file($dir) && ($theSettings->uid < 0 || isUserHavePermission($theSettings->uid, $theSettings->gid, $dir, 0x4))) {
        $curFile = basename($dir);
        $dir = dirname($dir);
    }
    if (is_dir($dir)) {
        $dh = @opendir($dir);
        $dir = addslash($dir);
        if ($dh && (strpos($dir, $topDirectory) !== 0 || $theSettings->uid >= 0 && !isUserHavePermission($theSettings->uid, $theSettings->gid, $dir, 0x5))) {
            closedir($dh);
            $dh = false;
        }
    }
}
if (!$dh) {
    $curFile = null;
    $dir = isLocalMode() ? $theSettings->directory : $topDirectory;
    if (strpos(addslash($dir), $topDirectory) !== 0) {
        $dir = $topDirectory;
    }
Beispiel #23
0
<?php

$diskUpdateInterval = 10;
// in seconds
$notifySpaceLimit = 512;
// in Mb
// If we run locally && we the download directory seems to exists
if (isLocalMode() && rTorrentSettings::get()->linkExist && file_exists(rTorrentSettings::get()->directory)) {
    $partitionDirectory = rTorrentSettings::get()->directory;
    // Then we can show the disk space of the download directory
} else {
    $partitionDirectory =& $topDirectory;
    // Else, we show $topDirectory by default as fallback
}
Beispiel #24
0
<?php

rTorrentSettings::get()->unregisterEventHook("rssurlrewrite", "RSSFetched");
Beispiel #25
0
 public function setHandlers()
 {
     global $rootPath;
     if ($this->enabled) {
         $cmd = rTorrentSettings::get()->getOnFinishedCommand(array('unpack' . getUser(), getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/unpack/update.php,$' . getCmd('d.get_directory') . '=,$' . getCmd('d.get_base_filename') . '=,$' . getCmd('d.is_multi_file') . '=,$' . getCmd('d.get_custom1') . '=,$' . getCmd('d.get_name') . '=,' . getCmd('d.get_hash') . '=,' . getUser() . '}'));
     } else {
         $cmd = rTorrentSettings::get()->getOnFinishedCommand(array('unpack' . getUser(), getCmd('cat=')));
     }
     $req = new rXMLRPCRequest($cmd);
     return $req->success();
 }
Beispiel #26
0
<?php

$req = new rXMLRPCRequest(rTorrentSettings::get()->getOnInsertCommand(array('_throttle' . getUser(), getCmd('cat='))));
$req->run();
Beispiel #27
0
<?php

$req = new rXMLRPCRequest(rTorrentSettings::get()->getRemoveScheduleCommand("rss"));
$req->run();
Beispiel #28
0
<?php

require_once '../../php/util.php';
require_once '../../php/settings.php';
$dh = false;
$theSettings = rTorrentSettings::get();
$btn_id = "'" . $_REQUEST['btn'] . "'";
$edit_id = "'" . $_REQUEST['edit'] . "'";
$frame_id = "'" . $_REQUEST['frame'] . "'";
if (isset($_REQUEST['dir']) && strlen($_REQUEST['dir'])) {
    $dir = rawurldecode($_REQUEST['dir']);
    rTorrentSettings::get()->correctDirectory($dir);
    $dh = @opendir($dir);
    $dir = addslash($dir);
    if ($dh && (strpos($dir, $topDirectory) !== 0 || $theSettings->uid >= 0 && !isUserHavePermission($theSettings->uid, $theSettings->gid, $dir, 0x7))) {
        closedir($dh);
        $dh = false;
    }
}
if (!$dh) {
    $dir = isLocalMode() ? $theSettings->directory : $topDirectory;
    if (strpos(addslash($dir), $topDirectory) !== 0) {
        $dir = $topDirectory;
    }
    $dh = @opendir($dir);
}
$files = array();
if ($dh) {
    $dir = addslash($dir);
    while (false !== ($file = readdir($dh))) {
        $path = fullpath($dir . $file);
Beispiel #29
0
 public static function run($cmd, $flags = 0)
 {
     $ret = -1;
     $params = " >/dev/null 2>&1";
     if (!($flags & self::FLG_WAIT)) {
         $params .= " &";
     }
     if ($flags & self::FLG_RUN_AS_WEB) {
         if (self::FLG_RUN_AS_CMD) {
             $cmd = '-c "' . $cmd . '"';
         }
         exec('sh ' . $cmd . $params, $output, $ret);
     } else {
         $req = new rXMLRPCRequest(rTorrentSettings::get()->iVersion >= 0x900 && !($flags & self::FLG_WAIT) ? new rXMLRPCCommand("execute.nothrow.bg", array("", "sh", $cmd)) : new rXMLRPCCommand("execute_nothrow", array("sh", "-c", $cmd . $params)));
         if ($req->success() && count($req->val)) {
             $ret = intval($req->val[0]);
         }
     }
     return $ret;
 }
Beispiel #30
0
function getCmd($cmd)
{
    return rTorrentSettings::get()->getCommand($cmd);
}