コード例 #1
0
/**
 * gets scrape-info of a torrent as string
 *
 * @param $transfer name of the torrent
 * @return string with torrent-scrape-info
 */
function getTorrentScrapeInfo($transfer)
{
    global $cfg;
    $hasClient = false;
    // transmissioncli
    if (!$cfg["transmission_rpc_enable"]) {
        $hasClient = true;
        $retVal = "";
        $retVal = @shell_exec("HOME=" . tfb_shellencode($cfg["path"]) . "; export HOME; " . $cfg["btclient_transmission_bin"] . " -s " . tfb_shellencode($cfg["transfer_file_path"] . $transfer));
        if (isset($retVal) && $retVal != "" && !preg_match('/.*failed.*/i', $retVal)) {
            return trim($retVal);
        }
    } else {
        require_once 'inc/functions/functions.transfer.php';
        require_once 'inc/functions/functions.rpc.transmission.php';
        if (isHash($transfer)) {
            $hash = $transfer;
        } else {
            $hash = getTransferHash($transfer);
        }
        $a = getTransmissionTransfer($hash, array("trackerStats"));
        if (!empty($a['trackerStats'])) {
            $stats = $a['trackerStats'][0];
            return $stats['seederCount'] . ' seeder(s), ' . $stats['leecherCount'] . ' leecher(s).' . "\n";
        }
    }
    // ttools.pl
    if (is_executable($cfg["perlCmd"])) {
        $hasClient = true;
        $retVal = "";
        $retVal = @shell_exec($cfg["perlCmd"] . ' -I ' . tfb_shellencode($cfg["docroot"] . 'bin/ttools') . ' ' . tfb_shellencode($cfg["docroot"] . 'bin/ttools/ttools.pl') . ' -s ' . tfb_shellencode($cfg["transfer_file_path"] . $transfer));
        if (isset($retVal) && $retVal != "" && !preg_match('/.*failed.*/i', $retVal)) {
            return trim($retVal);
        }
    }
    // failed
    return $hasClient ? "Scrape failed" : "No Scrape-Client";
}
コード例 #2
0
if ($cfg["transmission_rpc_enable"] > 0) {
    if (isHash($transfer)) {
        $hash = $transfer;
    } else {
        $hash = getTransferHash($transfer);
    }
    require_once 'inc/functions/functions.rpc.transmission.php';
    $isTransmissionTransfer = isTransmissionTransfer($hash);
    if (!$isTransmissionTransfer && $cfg["transmission_rpc_enable"] == 1) {
        $isTransmissionTransfer = getTransferClient($transfer) == 'transmissionrpc';
    }
}
$list_host = array();
if ($isTransmissionTransfer) {
    $options = array('peers');
    $transfer = getTransmissionTransfer($hash, $options);
    $isRunning = true;
    //TODO make this actually determine if the torrent is running
    if ($isRunning) {
        foreach ($transfer['peers'] as $peer) {
            array_push($list_host, array('host' => @gethostbyaddr($peer['address']), 'port' => $peer['port']));
        }
    }
} else {
    // stat
    $sf = new StatFile($transfer);
    // set vars
    if ($sf->running == 1) {
        $transfer_pid = getTransferPid($transfer);
        $transfer_cons = netstatConnectionsByPid($transfer_pid);
        $transfer_hosts = netstatHostsByPid($transfer_pid);
コード例 #3
0
 /**
  * gets current status of one Transfer (realtime)
  * for transferStat popup
  *
  * @return array (stat) or Error String
  */
 function monitorTransfer($transfer, $format = "rpc")
 {
     //by default, monitoring not available.
     // set vars
     $this->_setVarsForTransfer($transfer);
     if (isHash($transfer)) {
         $hash = $transfer;
     } else {
         $hash = getTransferHash($transfer);
     }
     if (empty($hash)) {
         return "Hash for {$transfer} was not found";
     }
     //original rpc format, you can add fields here
     $fields = array('id', 'name', 'status', 'hashString', 'totalSize', 'downloadedEver', 'uploadedEver', 'percentDone', 'uploadRatio', 'peersConnected', 'peersGettingFromUs', 'peersSendingToUs', 'rateDownload', 'rateUpload', 'downloadLimit', 'uploadLimit', 'downloadLimited', 'uploadLimited', 'seedRatioLimit', 'seedRatioMode', 'downloadDir', 'eta', 'error', 'errorString');
     $stat_rpc = getTransmissionTransfer($hash, $fields);
     $rpc = Transmission::getInstance();
     if (is_array($stat_rpc)) {
         if ($format == "rpc") {
             return $stat_rpc;
         } else {
             return $rpc->rpc_to_tf($stat_rpc);
         }
     }
     return $rpc->lastError;
 }
コード例 #4
0
/**
 * setFileVars
 */
function transfer_setFileVars()
{
    global $cfg, $tmpl, $transfer, $transferLabel, $ch;
    // set vars for transfer
    $transferFilesList = array();
    switch ($ch->type) {
        case "torrent":
            require_once "inc/classes/BDecode.php";
            $tFile = $cfg["transfer_file_path"] . $transfer;
            if ($fd = @fopen($tFile, "rd")) {
                $alltorrent = @fread($fd, @filesize($tFile));
                $btmeta = @BDecode($alltorrent);
                @fclose($fd);
            }
            $transferSizeSum = 0;
            $isTransmissionTorrent = false;
            if ($cfg["transmission_rpc_enable"] && isHash($transfer)) {
                require_once 'inc/functions/functions.rpc.transmission.php';
                $theTorrent = getTransmissionTransfer($transfer, array('hashString', 'id', 'name', 'files'));
                $isTransmissionTorrent = is_array($theTorrent);
            }
            if ($isTransmissionTorrent) {
                foreach ($theTorrent['files'] as $aFile) {
                    $transferSizeSum += $aFile['length'];
                    $fileNameParts = explode("/", $aFile['name']);
                    $name = $fileNameParts[count($fileNameParts) - 1];
                    $size = $aFile['length'];
                    array_push($transferFilesList, array('name' => $name, 'size' => $size != 0 ? formatBytesTokBMBGBTB($size) : 0));
                }
            } else {
                if (isset($btmeta) && is_array($btmeta) && isset($btmeta['info'])) {
                    if (array_key_exists('files', $btmeta['info'])) {
                        foreach ($btmeta['info']['files'] as $filenum => $file) {
                            $name = is_array($file['path']) ? implode("/", $file['path']) : $file['path'];
                            $size = isset($file['length']) && is_numeric($file['length']) ? $file['length'] : 0;
                            $transferSizeSum += $size;
                            array_push($transferFilesList, array('name' => $name, 'size' => $size != 0 ? formatBytesTokBMBGBTB($size) : 0));
                        }
                    } else {
                        $size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20);
                        $transferSizeSum += $size;
                        array_push($transferFilesList, array('name' => $btmeta["info"]["name"], 'size' => formatBytesTokBMBGBTB($size)));
                    }
                }
            }
            if (empty($transferFilesList)) {
                $tmpl->setvar('transferFilesString', "Empty");
                $tmpl->setvar('transferFileCount', count($btmeta['info']['files']));
            } else {
                $tmpl->setloop('transferFilesList', $transferFilesList);
                $tmpl->setvar('transferFileCount', count($transferFilesList));
            }
            $tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0);
            return;
        case "wget":
            $ch = ClientHandler::getInstance('wget');
            $ch->setVarsFromFile($transfer);
            $transferSizeSum = 0;
            if (!empty($ch->url)) {
                require_once "inc/classes/SimpleHTTP.php";
                $size = SimpleHTTP::getRemoteSize($ch->url);
                $transferSizeSum += $size;
                array_push($transferFilesList, array('name' => $ch->url, 'size' => formatBytesTokBMBGBTB($size)));
            }
            if (empty($transferFilesList)) {
                $tmpl->setvar('transferFilesString', "Empty");
                $tmpl->setvar('transferFileCount', 0);
            } else {
                $tmpl->setloop('transferFilesList', $transferFilesList);
                $tmpl->setvar('transferFileCount', count($transferFilesList));
            }
            $tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0);
            return;
        case "nzb":
            require_once "inc/classes/NZBFile.php";
            $nzb = new NZBFile($transfer);
            $transferSizeSum = 0;
            if (empty($nzb->files)) {
                $tmpl->setvar('transferFilesString', "Empty");
                $tmpl->setvar('transferFileCount', 0);
            } else {
                foreach ($nzb->files as $file) {
                    $transferSizeSum += $file['size'];
                    array_push($transferFilesList, array('name' => $file['name'], 'size' => formatBytesTokBMBGBTB($file['size'])));
                }
                $tmpl->setloop('transferFilesList', $transferFilesList);
                $tmpl->setvar('transferFileCount', $nzb->filecount);
            }
            $tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0);
            return;
    }
}
コード例 #5
0
/**
 * pieTransferPeers
 */
function image_pieTransferPeers()
{
    global $cfg;
    // transfer-id
    $transfer = tfb_getRequestVar('transfer');
    if (empty($transfer)) {
        Image::paintNoOp();
    }
    // validate transfer
    $validTransfer = false;
    if (isHash($transfer)) {
        $hash = $transfer;
    } else {
        $hash = getTransferHash($transfer);
    }
    if ($cfg["transmission_rpc_enable"]) {
        require_once 'inc/functions/functions.rpc.transmission.php';
        $options = array('trackerStats', 'peers');
        $transTransfer = getTransmissionTransfer($hash, $options);
        // false if not found; TODO check if transmission enabled
        if (is_array($transTransfer)) {
            $validTransfer = true;
            $client = "transmissionrpc";
        }
    }
    if (!$validTransfer) {
        // If not found in transmission transfer
        if (tfb_isValidTransfer($transfer)) {
            // stat
            $sf = new StatFile($transfer);
            $seeds = trim($sf->seeds);
            $peers = trim($sf->peers);
            // client-switch + get peer-data
            $peerData = array();
            $peerData['seeds'] = 0;
            $peerData['peers'] = 0;
            $peerData['seedsLabel'] = $seeds != "" ? $seeds : 0;
            $peerData['peersLabel'] = $peers != "" ? $peers : 0;
            $client = getTransferClient($transfer);
            $validTransfer = true;
        }
    }
    if (!$validTransfer) {
        AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer);
        Image::paintNoOp();
    }
    switch ($client) {
        case "tornado":
            if ($seeds != "") {
                if (strpos($seeds, "+") !== false) {
                    $seeds = preg_replace('/(\\d+)\\+.*/i', '${1}', $seeds);
                }
                if (is_numeric($seeds)) {
                    $peerData['seeds'] = $seeds;
                }
                $peerData['seedsLabel'] = $seeds;
            }
            if ($peers != "") {
                if (strpos($peers, "+") !== false) {
                    $peers = preg_replace('/(\\d+)\\+.*/i', '${1}', $peers);
                }
                if (is_numeric($peers)) {
                    $peerData['peers'] = $peers;
                }
                $peerData['peersLabel'] = $peers;
            }
            break;
        case "transmission":
        case "transmissionrpc":
            $peers = sizeof($transTransfer['peers']);
            $seeds = 0;
            foreach ($transTransfer['trackerStats'] as $tracker) {
                $seeds += $tracker['seederCount'] == -1 ? 0 : $tracker['seederCount'];
            }
            $peerData['seedsLabel'] = $seeds;
            $peerData['seeds'] = $seeds;
            $peerData['peersLabel'] = $peers;
            $peerData['peers'] = $peers;
            break;
        case "vuzerpc":
            if (empty($seeds) || empty($peers)) {
                $ch = ClientHandler::getInstance($client);
                $running = $ch->monitorRunningTransfers();
                $hash = strtoupper(getTransferHash($transfer));
                if (!empty($running[$hash])) {
                    $t = $running[$hash];
                    $peerData['seeds'] = $t['seeds'];
                    $peerData['seedsLabel'] = $t['seeds'];
                    $peerData['peers'] = $t['peers'];
                    $peerData['peersLabel'] = $t['peers'];
                }
            }
            break;
        case "azureus":
            if ($seeds != "") {
                if (strpos($seeds, "(") !== false) {
                    $seeds = preg_replace('/.*(\\d+) .*/i', '${1}', $seeds);
                }
                if (is_numeric($seeds)) {
                    $peerData['seeds'] = $seeds;
                }
                $peerData['seedsLabel'] = $seeds;
            }
            if ($peers != "") {
                if (strpos($peers, "(") !== false) {
                    $peers = preg_replace('/.*(\\d+) .*/i', '${1}', $peers);
                }
                if (is_numeric($peers)) {
                    $peerData['peers'] = $peers;
                }
                $peerData['peersLabel'] = $peers;
            }
            break;
        case "mainline":
            if ($seeds != "" && is_numeric($seeds)) {
                $peerData['seeds'] = $seeds;
                $peerData['seedsLabel'] = $seeds;
            }
            if ($peers != "" && is_numeric($peers)) {
                $peerData['peers'] = $peers;
                $peerData['peersLabel'] = $peers;
            }
            break;
        case "wget":
        case "nzbperl":
            $peerData['seeds'] = $seeds != "" ? $seeds : 0;
            $peerData['peers'] = $peers != "" ? $peers : 0;
            break;
        default:
            AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer);
            Image::paintNoOp();
    }
    // draw image
    Image::paintPie3D(202, 160, 100, 50, 200, 100, 20, Image::stringToRGBColor($cfg["body_data_bg"]), array($peerData['seeds'] + 1.0E-5, $peerData['peers'] + 1.0E-5), image_getColors(), array('Seeds : ' . $peerData['seedsLabel'], 'Peers : ' . $peerData['peersLabel']), 58, 130, 2, 14);
}
コード例 #6
0
function getTransmissionTrackerStats($transfer)
{
    $options = array('trackerStats');
    $transfer = getTransmissionTransfer($transfer, $options);
    if (is_array($transfer)) {
        return $transfer['trackerStats'][0];
    } else {
        return array();
    }
}
コード例 #7
0
    }
    if ($debugtofile) {
        $fh = fopen($debuglog, 'a') or die("Can't open file");
        fwrite($fh, date("Ymd G:i:s") . ' ' . $message);
        fclose($fh);
    }
}
debug("Get Transfer with hash {$tHash}\n");
chdir(dirname(__FILE__) . '/../');
debug("The current working directory: " . getcwd() . "\n");
require_once 'inc/functions/functions.common.php';
// Necessary for message functions
require_once 'inc/functions/functions.rpc.transmission.php';
require_once 'inc/main.core.php';
$options = array('files', 'downloadDir', 'name');
$returnArr = getTransmissionTransfer($tHash, $options);
SaveMessage("administrator", "administrator", htmlentities("Torrent " . $returnArr['name'] . " has finished"), 0, 0);
if (!$returnArr) {
    debug("No result. Exiting...\n");
    exit;
} else {
    print_r($returnArr);
}
$supportedCompression = array('zip', 'rar', 'gz', 'bzip', 'tbz', 'tgz', 'tar');
foreach ($returnArr['files'] as $fileentry) {
    $filename = $fileentry['name'];
    debug("The filename is {$filename}\n");
    $ext = end(explode('.', $filename));
    debug("The extension is {$ext}\n");
    if (in_array($ext, $supportedCompression)) {
        debug("{$filename} is a supported archive\n");
コード例 #8
0
/**
 * multi
 *
 * @param $action
 */
function dispatcher_multi($action)
{
    global $cfg;
    // is enabled ?
    if ($cfg["enable_multiops"] != 1) {
        AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use multi-op " . $action);
        @error("multiops are disabled", "", "");
    }
    // messages-ary
    $dispatcherMessages = array();
    // loop
    if (empty($_POST['transfer'])) {
        return;
    }
    foreach ($_POST['transfer'] as $key => $element) {
        // url-decode
        $transfer = urldecode($element);
        $isTransmissionTorrent = false;
        if ($cfg["transmission_rpc_enable"] && isHash($transfer)) {
            require_once 'inc/functions/functions.rpc.transmission.php';
            $theTorrent = getTransmissionTransfer($transfer, array('id'));
            $isTransmissionTorrent = is_array($theTorrent);
            //	$torrentId = $theTorrent['id'];
            if ($isTransmissionTorrent) {
                switch ($action) {
                    case "transferData":
                        deleteTransmissionTransfer($cfg['uid'], $transfer, true);
                        $dispatcherMessages[] = "Torrent deleted with data";
                        break;
                    case "transfer":
                        deleteTransmissionTransfer($cfg['uid'], $transfer, false);
                        $dispatcherMessages[] = "Torrent deleted";
                        break;
                }
            }
        }
        if (!$isTransmissionTorrent) {
            // is valid transfer ? + check permissions
            $invalid = true;
            if (tfb_isValidTransfer($transfer) === true) {
                if (substr($transfer, -8) == ".torrent") {
                    // this is a torrent-client
                    $invalid = false;
                } else {
                    if (substr($transfer, -5) == ".wget") {
                        // this is wget.
                        $invalid = false;
                        // is enabled ?
                        if ($cfg["enable_wget"] == 0) {
                            $invalid = true;
                            AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use wget");
                            array_push($dispatcherMessages, "wget is disabled : " . $transfer);
                        } else {
                            if ($cfg["enable_wget"] == 1) {
                                if (!$cfg['isAdmin']) {
                                    $invalid = true;
                                    AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use wget");
                                    array_push($dispatcherMessages, "wget is disabled for users : " . $transfer);
                                }
                            }
                        }
                    } else {
                        if (substr($transfer, -4) == ".nzb") {
                            // This is nzbperl.
                            $invalid = false;
                            if ($cfg["enable_nzbperl"] == 0) {
                                $invalid = true;
                                AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use nzbperl");
                                array_push($dispatcherMessages, "nzbperl is disabled : " . $transfer);
                            } else {
                                if ($cfg["enable_nzbperl"] == 1) {
                                    if (!$cfg['isAdmin']) {
                                        $invalid = true;
                                        AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use nzbperl");
                                        array_push($dispatcherMessages, "nzbperl is disabled for users : " . $transfer);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($invalid) {
                AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $cfg["user"] . " tried to " . $action . " " . $transfer);
                array_push($dispatcherMessages, "Invalid Transfer : " . $transfer);
                continue;
            }
            // client
            $client = getTransferClient($transfer);
        }
        // is transfer running ?
        $tRunningFlag = isTransferRunning($transfer);
        // action switch
        switch ($action) {
            case "transferStart":
                /* transferStart */
                if (!$tRunningFlag) {
                    $ch = ClientHandler::getInstance($client);
                    $ch->start($transfer, false, FluxdQmgr::isRunning());
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                }
                break;
            case "transferStop":
                /* transferStop */
                if ($tRunningFlag) {
                    $ch = ClientHandler::getInstance($client);
                    $ch->stop($transfer);
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                }
                break;
            case "transferEnQueue":
                /* transferEnQueue */
                if (!$tRunningFlag) {
                    // enqueue it
                    $ch = ClientHandler::getInstance($client);
                    $ch->start($transfer, false, true);
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                }
                break;
            case "transferDeQueue":
                /* transferDeQueue */
                if (!$tRunningFlag) {
                    // dequeue it
                    FluxdQmgr::dequeueTransfer($transfer, $cfg['user']);
                }
                break;
            case "transferResetTotals":
                /* transferResetTotals */
                $msgs = resetTransferTotals($transfer, false);
                if (count($msgs) > 0) {
                    $dispatcherMessages = array_merge($dispatcherMessages, $msgs);
                }
                break;
            default:
                if ($tRunningFlag) {
                    // stop first
                    $ch = ClientHandler::getInstance($client);
                    $ch->stop($transfer);
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                    // is transfer running ?
                    $tRunningFlag = isTransferRunning($transfer);
                }
                // if it was running... hope the thing is down...
                // only continue if it is
                if (!$tRunningFlag) {
                    switch ($action) {
                        case "transferWipe":
                            /* transferWipe */
                            $msgsDelete = deleteTransferData($transfer);
                            if (count($msgsDelete) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $msgsDelete);
                            }
                            $msgsReset = resetTransferTotals($transfer, true);
                            if (count($msgsReset) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $msgsReset);
                            }
                            break;
                        case "transferData":
                            /* transferData */
                            $msgsDelete = deleteTransferData($transfer);
                            if (count($msgsDelete) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $msgsDelete);
                            }
                        case "transfer":
                            /* transfer */
                            $ch = ClientHandler::getInstance($client);
                            $ch->delete($transfer);
                            if (count($ch->messages) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                            }
                    }
                }
        }
        // end switch
    }
    // end loop
    // error if messages
    if (count($dispatcherMessages) > 0) {
        @error("There were Problems", "", "", $dispatcherMessages);
    }
}
コード例 #9
0
/**
 * File Prio Form
 *
 * @param $transfer
 * @param $withForm
 * @return string
 */
function getFilePrioForm($transfer, $withForm = false)
{
    /*
    	global $cfg;
    	$prioFileName = $cfg["transfer_file_path"].$transfer.".prio";
    	require_once('inc/classes/BDecode.php');
    	$retVal = "";
    	// theme-switch
    	if ((strpos($cfg["theme"], '/')) === false) {
    		$retVal .= '<link rel="StyleSheet" href="themes/'.$cfg["theme"].'/css/dtree.css" type="text/css" />';
    		$retVal .= '<script type="text/javascript">var dtree_path_images = "themes/'.$cfg["theme"].'/images/dtree/";</script>';
    	} else {
    		$retVal .= '<link rel="StyleSheet" href="themes/tf_standard_themes/css/dtree.css" type="text/css" />';
    		$retVal .= '<script type="text/javascript">var dtree_path_images = "themes/tf_standard_themes/images/dtree/";</script>';
    	}
    	$retVal .= '<script type="text/javascript" src="js/dtree.js"></script>';
    	$ftorrent = $cfg["transfer_file_path"].$transfer;
    	$fp = @fopen($ftorrent, "rd");
    	$alltorrent = @fread($fp, @filesize($ftorrent));
    	@fclose($fp);
    	$btmeta = @BDecode($alltorrent);
    	$torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20);
    	$dirnum = (array_key_exists('files',$btmeta['info'])) ? count($btmeta['info']['files']) : 0;
    	if (@is_readable($prioFileName)) {
    		$prio = explode(',', @file_get_contents($prioFileName));
    		$prio = array_splice($prio,1);
    	} else {
    		$prio = array();
    		for ($i=0; $i<$dirnum; $i++)
    			$prio[$i] = -1;
    	}
    */
    global $cfg;
    require_once 'inc/classes/BDecode.php';
    $retVal = "";
    // theme-switch
    if (strpos($cfg["theme"], '/') === false) {
        $retVal .= '<link rel="StyleSheet" href="themes/' . $cfg["theme"] . '/css/dtree.css" type="text/css" />';
        $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/' . $cfg["theme"] . '/images/dtree/";</script>';
    } else {
        $retVal .= '<link rel="StyleSheet" href="themes/tf_standard_themes/css/dtree.css" type="text/css" />';
        $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/tf_standard_themes/images/dtree/";</script>';
    }
    $retVal .= '<script type="text/javascript" src="js/dtree.js"></script>';
    $isTransmissionTorrent = false;
    if ($cfg["transmission_rpc_enable"]) {
        require_once 'inc/functions/functions.rpc.transmission.php';
        $isTransmissionTorrent = isTransmissionTransfer($transfer);
    }
    $files = array();
    if ($isTransmissionTorrent) {
        $allFilesResponse = getTransmissionTransfer($transfer, array('files'));
        $allFiles = $allFilesResponse['files'];
        $wantedFilesResponse = getTransmissionTransfer($transfer, array('wanted'));
        $wantedFiles = $wantedFilesResponse['wanted'];
        $dirnum = count($allFiles);
        // make sure this is in here otherwhise you will loose alot of time debugging your code on what is missing (the filetree selection is not displayed)
        $tree = new dir("/", $dirnum, -1);
        foreach ($allFiles as $file) {
            $fileparts = explode("/", $file[name]);
            $filesize = $file[length];
            $fileprops = array('length' => $filesize, 'path' => $fileparts);
            array_push($files, $fileprops);
        }
        $filescount = count($files);
        foreach ($files as $filenum => $file) {
            $depth = count($file['path']);
            $branch =& $tree;
            for ($i = 0; $i < $depth; $i++) {
                if ($i != $depth - 1) {
                    $d =& $branch->findDir($file['path'][$i]);
                    if ($d) {
                        $branch =& $d;
                    } else {
                        $dirnum++;
                        $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, -1));
                        $branch =& $d;
                    }
                } else {
                    $branch->addFile(new file($file['path'][$i] . " (" . $file['length'] . ")", $filenum, $file['length'], $wantedFiles[$filenum] == 1 ? 1 : -1));
                }
            }
        }
        $aTorrent = getTransmissionTransfer($transfer, array("pieceCount", "pieceSize", "totalSize", "dateCreated", "downloadDir", "comment"));
        #$torrent_size = $aTorrent[pieceSize] * $aTorrent[pieceCount];
        $torrent_size = $aTorrent['totalSize'];
        $torrent_chunksize = $aTorrent['pieceSize'];
        $torrent_directoryname = $aTorrent['downloadDir'];
        $torrent_announceurl = $aTorrent['comment'];
        $torrent_creationdate = $aTorrent['dateCreated'];
        $torrent_filescount = $filescount;
    } else {
        $prioFileName = $cfg["transfer_file_path"] . $transfer . ".prio";
        $ftorrent = $cfg["transfer_file_path"] . $transfer;
        $fp = @fopen($ftorrent, "rd");
        $alltorrent = @fread($fp, @filesize($ftorrent));
        @fclose($fp);
        $btmeta = @BDecode($alltorrent);
        $torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20);
        $dirnum = array_key_exists('files', $btmeta['info']) ? count($btmeta['info']['files']) : 0;
        if (@is_readable($prioFileName)) {
            $prio = explode(',', @file_get_contents($prioFileName));
            $prio = array_splice($prio, 1);
        } else {
            $prio = array();
            for ($i = 0; $i < $dirnum; $i++) {
                $prio[$i] = -1;
            }
        }
        $tree = new dir("/", $dirnum, isset($prio[$dirnum]) ? $prio[$dirnum] : -1);
        if (array_key_exists('files', $btmeta['info'])) {
            foreach ($btmeta['info']['files'] as $filenum => $file) {
                $depth = count($file['path']);
                $branch =& $tree;
                for ($i = 0; $i < $depth; $i++) {
                    if ($i != $depth - 1) {
                        $d =& $branch->findDir($file['path'][$i]);
                        if ($d) {
                            $branch =& $d;
                        } else {
                            $dirnum++;
                            $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, isset($prio[$dirnum]) ? $prio[$dirnum] : -1));
                            $branch =& $d;
                        }
                    } else {
                        $branch->addFile(new file($file['path'][$i] . " (" . $file['length'] . ")", $filenum, $file['length'], $prio[$filenum]));
                    }
                }
            }
        }
        $torrent_chunksize = $btmeta[info]['piece length'];
        $torrent_directoryname = $btmeta[info][name];
        $torrent_announceurl = $btmeta[announce];
        $torrent_creationdate = $btmeta['creation date'];
        $torrent_filescount = count($btmeta['info']['files']);
    }
    $retVal .= "<table><tr>";
    $retVal .= "<tr><td width=\"110\">Metainfo File:</td><td>" . $transfer . "</td></tr>";
    $retVal .= "<tr><td>Directory Name:</td><td>" . $torrent_directoryname . "</td></tr>";
    $retVal .= "<tr><td>Announce URL:</td><td>" . $torrent_announceurl . "</td></tr>";
    if (array_key_exists('comment', $btmeta)) {
        $retVal .= "<tr><td valign=\"top\">Comment:</td><td>" . tfb_htmlencode($btmeta['comment']) . "</td></tr>";
    }
    $retVal .= "<tr><td>Created:</td><td>" . ($torrent_creationdate == 0 ? 'n/a' : date("F j, Y, g:i a", $torrent_creationdate)) . "</td></tr>";
    $retVal .= "<tr><td>Torrent Size:</td><td>" . $torrent_size . " (" . @formatBytesTokBMBGBTB($torrent_size) . ")</td></tr>";
    $retVal .= "<tr><td>Chunk size:</td><td>" . $torrent_chunksize . " (" . @formatBytesTokBMBGBTB($torrent_chunksize) . ")</td></tr>";
    if (array_key_exists('files', $btmeta['info']) || count($files) > 0) {
        $retVal .= "<tr><td>Selected size:</td><td id=\"sel\">0</td></tr>";
        $retVal .= "</table><br>\n";
        if ($withForm) {
            $retVal .= "<form name=\"priority\" action=\"dispatcher.php?action=setFilePriority&riid=_referer_\" method=\"POST\" >";
            $retVal .= "<input type=\"hidden\" name=\"transfer\" value=\"" . $transfer . "\" >";
        }
        $retVal .= "<script type=\"text/javascript\">\n";
        $retVal .= "var sel = 0;\n";
        $retVal .= "d = new dTree('d');\n";
        $retVal .= $tree->draw(-1);
        $retVal .= "document.write(d);\n";
        $retVal .= "sel = getSizes();\n";
        $retVal .= "drawSel();\n";
        $retVal .= "</script>\n";
        $retVal .= "<input type=\"hidden\" name=\"filecount\" value=\"" . $torrent_filescount . "\">";
        $retVal .= "<input type=\"hidden\" name=\"count\" value=\"" . $dirnum . "\">";
        $retVal .= "<br>";
        if ($withForm) {
            $retVal .= '<input type="submit" value="Save" >';
            $retVal .= "<br>";
            $retVal .= "</form>";
        }
    } else {
        $retVal .= "</table><br>";
        $retVal .= $btmeta['info']['name'] . $torrent_size . " (" . @formatBytesTokBMBGBTB($torrent_size) . ")";
    }
    // return
    return $retVal;
}
コード例 #10
0
function transmissionSetVars($transfer, $tmpl)
{
    //require_once('inc/functions/functions.rpc.transmission.php');
    require_once 'functions.rpc.transmission.php';
    $options = array("eta", "percentDone", "rateDownload", "rateUpload", "downloadedEver", "uploadedEver", "percentDone", "sizeWhenDone", "peers", "trackerStats");
    $returnArr = getTransmissionTransfer($transfer, $options);
    $tmpl->setvar('transferowner', getTransmissionTransferOwner($transfer));
    $tmpl->setvar('size', @formatBytesTokBMBGBTB($returnArr['sizeWhenDone']));
    // sharing
    $tmpl->setvar('sharing', $returnArr["downloadedEver"] > 0 ? @number_format($returnArr["uploadedEver"] / $returnArr["downloadedEver"] * 100, 2) : "0");
    // totals
    $tmpl->setvar('downTotal', @formatFreeSpace($returnArr["downloadedEver"] / 1048576));
    $tmpl->setvar('upTotal', @formatFreeSpace($returnArr["uploadedEver"] / 1048576));
    // port + cons
    //$tmpl->setvar('size', @formatBytesTokBMBGBTB($transferSize));
    $isRunning = true;
    // TODO make this actually detect if torrent is running
    if ($isRunning) {
        $tmpl->setvar('running', 1);
        // current totals
        $tmpl->setvar('downTotalCurrent', formatFreeSpace($totalsCurrent["downtotal"] / 1048576));
        $tmpl->setvar('upTotalCurrent', formatFreeSpace($totalsCurrent["uptotal"] / 1048576));
        // seeds + peers
        $seeds = getTransmissionSeederCount($transfer);
        $tmpl->setvar('seeds', $seeds == "" ? "Could not be retrieved" : $seeds . " (might be incorrect)");
        $tmpl->setvar('peers', sizeof($returnArr['peers']));
        // port + cons
        $transfer_pid = getTransferPid($transfer);
        $tmpl->setvar('port', netstatPortByPid($transfer_pid));
        $tmpl->setvar('cons', netstatConnectionsByPid($transfer_pid));
        // TODO: this is probably incorrect
        // up speed
        $tmpl->setvar('up_speed', trim($returnArr['rateUpload']) != "" ? formatBytesTokBMBGBTB($returnArr['rateUpload']) . '/s' : '0.0 kB/s');
        // down speed
        $tmpl->setvar('down_speed', trim($returnArr['rateDownload']) != "" ? formatBytesTokBMBGBTB($returnArr['rateDownload']) . '/s' : '0.0 kB/s');
        // sharekill
        $tmpl->setvar('sharekill', $ch->sharekill != 0 ? $ch->sharekill . '%' : '&#8734');
    } else {
        // running
        $tmpl->setvar('running', 0);
        // current totals
        $tmpl->setvar('downTotalCurrent', "");
        $tmpl->setvar('upTotalCurrent', "");
        // seeds + peers
        $tmpl->setvar('seeds', "");
        $tmpl->setvar('peers', "");
        // port + cons
        $tmpl->setvar('port', "");
        $tmpl->setvar('cons', "");
        // up speed
        $tmpl->setvar('up_speed', "");
        // down speed
        $tmpl->setvar('down_speed', "");
        // sharekill
        $tmpl->setvar('sharekill', "");
    }
    if ($returnArr['eta'] < 0) {
        $tmpl->setvar('time_left', 'n/a');
    } else {
        $tmpl->setvar('time_left', convertTime($returnArr['eta']));
    }
    // graph width
    $tmpl->setvar('graph_width1', $returnArr['percentDone'] * 100);
    $tmpl->setvar('graph_width2', 100 - $returnArr['percentDone'] * 100);
    $tmpl->setvar('percent_done', $returnArr['percentDone'] * 100);
    // language vars
    global $cfg;
    $tmpl->setvar('_USER', $cfg['_USER']);
    $tmpl->setvar('_SHARING', $cfg['_SHARING']);
    $tmpl->setvar('_ID_CONNECTIONS', $cfg['_ID_CONNECTIONS']);
    $tmpl->setvar('_ID_PORT', $cfg['_ID_PORT']);
    $tmpl->setvar('_DOWNLOADSPEED', $cfg['_DOWNLOADSPEED']);
    $tmpl->setvar('_UPLOADSPEED', $cfg['_UPLOADSPEED']);
    $tmpl->setvar('_PERCENTDONE', $cfg['_PERCENTDONE']);
    $tmpl->setvar('_ESTIMATEDTIME', $cfg['_ESTIMATEDTIME']);
    return $tmpl;
}