Exemple #1
0
 public function flush()
 {
     global $profileMask;
     $randName = uniqid(getTempDirectory() . "rutorrent-trafic-");
     if ($file = @fopen($randName, "w")) {
         if (fputcsv($file, $this->hourUp) !== false && fputcsv($file, $this->hourDown) !== false && fputcsv($file, $this->hourHitTimes) !== false && fputcsv($file, $this->monthUp) !== false && fputcsv($file, $this->monthDown) !== false && fputcsv($file, $this->monthHitTimes) !== false && fputcsv($file, $this->yearUp) !== false && fputcsv($file, $this->yearDown) !== false && fputcsv($file, $this->yearHitTimes) !== false) {
             if (fclose($file) !== false) {
                 rename($randName, $this->fname);
                 @chmod($this->fname, $profileMask & 0666);
                 return true;
             }
         }
         fclose($file);
         unlink($randName);
     }
     return false;
 }
Exemple #2
0
 public static function formatPath($taskNo)
 {
     return getTempDirectory() . 'rutorrent-tsk-' . getUser() . $taskNo;
 }
Exemple #3
0
}
$permissions = parse_ini_file($access);
$settingsFlags = array("showDownloadsPage" => 0x1, "showConnectionPage" => 0x2, "showBittorentPage" => 0x4, "showAdvancedPage" => 0x8, "showPluginsTab" => 0x10, "canChangeULRate" => 0x20, "canChangeDLRate" => 0x40, "canChangeTorrentProperties" => 0x80, "canAddTorrentsWithoutPath" => 0x100, "canAddTorrentsWithoutStarting" => 0x200, "canAddTorrentsWithResume" => 0x400, "canAddTorrentsWithRandomizeHash" => 0x800);
$perms = 0;
foreach ($settingsFlags as $flagName => $flagVal) {
    if (!array_key_exists($flagName, $permissions) || $permissions[$flagName]) {
        $perms |= $flagVal;
    }
}
$jResult .= "theWebUI.showFlags = " . $perms . ";\n";
$jResult .= "theURLs.XMLRPCMountPoint = '" . $XMLRPCMountPoint . "';\n";
$jResult .= "theWebUI.systemInfo = {};\ntheWebUI.systemInfo.php = { canHandleBigFiles : " . (PHP_INT_SIZE <= 4 ? "false" : "true") . " };\n";
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";
Exemple #4
0
<?php

require_once "../../php/util.php";
if (!isset($HTTP_RAW_POST_DATA)) {
    $HTTP_RAW_POST_DATA = file_get_contents("php://input");
}
$ret = array();
if (isset($HTTP_RAW_POST_DATA)) {
    $vars = explode('&', $HTTP_RAW_POST_DATA);
    foreach ($vars as $var) {
        $parts = explode("=", $var);
        if ($parts[0] == "hash") {
            $ret[] = $parts[1];
        }
    }
    if (count($ret)) {
        $fname = getTempDirectory() . 'rutorrent-prm-' . getUser() . time();
        file_put_contents($fname, serialize($ret));
        shell_exec(getPHP() . " -f " . escapeshellarg(dirname(__FILE__) . "/batch_check.php") . " " . escapeshellarg($fname) . " " . getUser() . " > /dev/null 2>&1 &");
        //		shell_exec( getPHP()." -f ".escapeshellarg(dirname( __FILE__)."/batch_check.php")." ".escapeshellarg($fname)." ".getUser()." > /tmp/1 2>/tmp/2 &" );
    }
}
cachedEcho('{}', "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 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 #7
0
}
$permissions = parse_ini_file($access);
$settingsFlags = array("showDownloadsPage" => 0x1, "showConnectionPage" => 0x2, "showBittorentPage" => 0x4, "showAdvancedPage" => 0x8, "showPluginsTab" => 0x10, "canChangeULRate" => 0x20, "canChangeDLRate" => 0x40, "canChangeTorrentProperties" => 0x80);
$perms = 0;
foreach ($settingsFlags as $flagName => $flagVal) {
    if (array_key_exists($flagName, $permissions) && $permissions[$flagName]) {
        $perms |= $flagVal;
    }
}
$jResult .= "theWebUI.showFlags = " . $perms . ";\n";
$jResult .= "theURLs.XMLRPCMountPoint = '" . $XMLRPCMountPoint . "';\n";
$jResult .= "theWebUI.systemInfo = {};\ntheWebUI.systemInfo.php = { canHandleBigFiles : " . (PHP_INT_SIZE <= 4 ? "false" : "true") . " };\n";
if ($handle = opendir('../plugins')) {
    ignore_user_abort(true);
    set_time_limit(0);
    makeDirectory(getTempDirectory());
    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');";
            $torrent->is_private(true);
        }
        $fname = getUniqueUploadedFilename($torrent->info['name'] . '.torrent');
        if (isset($request['start_seeding'])) {
            if (is_dir($path_edit)) {
                $path_edit = addslash($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());
            if ($resumed) {
                if (isset($torrent->{'rtorrent'})) {
                    unset($torrent->{'rtorrent'});
                }
                if (isset($torrent->{'libtorrent_resume'})) {
                    unset($torrent->{'libtorrent_resume'});
                }
                $torrent->save($fname);
            }
        } else {
            $torrent->save($fname);
        }
        @chmod($fname, $profileMask & 0666);
        file_put_contents(getTempDirectory() . getUser() . $taskNo . "/out", getFileName($fname));
        exit(0);
    }
    exit(1);
}
Exemple #9
0
                     $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;
         }
     }
     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;
Exemple #10
0
                }
            }
            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();
                }
            }
            exit("Can't send torrent file.");
    }
}
if (empty($ret)) {
    $ret = array("no" => 0, "errors" => array($error), "status" => -1, "out" => "");
Exemple #11
0
     $was = fgetcsv($file, 100);
     while (($data = fgetcsv($file, 1000)) !== false) {
         $wasTorrents[$data[0]] = array_slice($data, 1);
     }
     fclose($file);
 }
 $tm = time();
 $needUpdate = $was[2] + 3600 >= $tm;
 $now = array_slice($req->i8s, 0, 2);
 $now[2] = $tm;
 $nowTorrents = array();
 for ($i = 0; $i < count($req->strings); $i++) {
     $nowTorrents[$req->strings[$i]] = array_slice($req->i8s, ($i + 1) * 2, 2);
 }
 ksort($nowTorrents);
 $randName = uniqid(getTempDirectory() . "rutorrent-trafic-");
 if ($file = @fopen($randName, "w")) {
     if (($ok = fputcsv($file, $now)) !== false) {
         foreach ($nowTorrents as $key => $data) {
             $tmp = $data;
             array_unshift($tmp, $key);
             if (($ok = fputcsv($file, $tmp)) === false) {
                 break;
             }
         }
     }
     if ($ok !== false) {
         if (fclose($file) !== false) {
             rename($randName, $dir . 'last.csv');
             @chmod($dir . 'last.csv', $profileMask & 0666);
         } else {
Exemple #12
0
 protected static function formatPath($taskNo)
 {
     return getTempDirectory() . 'rutorrent-unpck-' . getUser() . $taskNo . ".";
 }