function displayDriveSpaceBar($drivespace) { global $cfg; switch ($cfg['drivespacebar']) { case "tf": $freeSpace = ""; if ($drivespace > 20) { $freeSpace = " (" . formatFreeSpace($cfg["free_space"]) . " Free)"; } ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr nowrap> <td width="2%"><div class="tiny"><?php echo _STORAGE; ?> :</div></td> <td width="80%"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td background="themes/<?php echo $cfg["theme"]; ?> /images/proglass.gif" width="<?php echo $drivespace; ?> %"><div class="tinypercent" align="center"><?php echo $drivespace . "%" . $freeSpace; ?> </div></td> <td background="themes/<?php echo $cfg["theme"]; ?> /images/noglass.gif" width="<?php echo 100 - $drivespace; ?> %"><img src="images/blank.gif" width="1" height="3" border="0"></td> </tr> </table> </td> </tr> </table> <?php break; case "xfer": $freeSpace = $drivespace ? ' (' . formatFreeSpace($cfg['free_space']) . ') Free' : ''; $drivespace = 100 - $drivespace; $bgcolor = '#'; $bgcolor .= str_pad(dechex(256 - 256 * ($drivespace / 100)), 2, 0, STR_PAD_LEFT); $bgcolor .= str_pad(dechex(256 * ($drivespace / 100)), 2, 0, STR_PAD_LEFT); $bgcolor .= '00'; echo '<table width="100%" border="0" cellpadding="0" cellspacing="0">'; echo '<tr nowrap>'; echo '<td width="2%"><div class="tiny">' . _STORAGE . ':</div></td>'; echo '<td width="92%">'; echo '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>'; echo '<td bgcolor="' . $bgcolor . '" width="' . $drivespace . '%">'; if ($drivespace >= 50) { echo '<div class="tinypercent" align="center"'; if ($drivespace == 100) { echo ' style="background:#ffffff;">'; } else { echo '>'; } echo $drivespace . '%' . $freeSpace; echo '</div>'; } echo '</td>'; echo '<td bgcolor="#000000" width="' . (100 - $drivespace) . '%">'; if ($drivespace < 50) { echo '<div class="tinypercent" align="center" style="color:' . $bgcolor; if ($drivespace == 0) { echo '; background:#ffffff;">'; } else { echo ';">'; } echo $drivespace . '%' . $freeSpace; echo '</div>'; } echo '</td>'; echo '</tr></table>'; echo '</td>'; echo '</tr>'; echo '</table>'; break; } }
/** * get server stats * note : this can only be used after a call to update transfer-values in cfg- * array (eg by getTransferListArray) * * @return array * * "speedDown" 0 * "speedUp" 1 * "speedTotal" 2 * "cons" 3 * "freeSpace" 4 * "loadavg" 5 * "running" 6 * "queued" 7 * "speedDownPercent" 8 * "speedUpPercent" 9 * "driveSpacePercent" 10 * */ function getServerStats() { global $cfg; $serverStats = array(); // speedDown $speedDown = "n/a"; $speedDown = @number_format($cfg["total_download"], 2); array_push($serverStats, $speedDown); // speedUp $speedUp = "n/a"; $speedUp = @number_format($cfg["total_upload"], 2); array_push($serverStats, $speedUp); // speedTotal $speedTotal = "n/a"; $speedTotal = @number_format($cfg["total_download"] + $cfg["total_upload"], 2); array_push($serverStats, $speedTotal); // cons $cons = "n/a"; $cons = @netstatConnectionsSum(); array_push($serverStats, $cons); // freeSpace $freeSpace = "n/a"; $freeSpace = @formatFreeSpace($cfg["free_space"]); array_push($serverStats, $freeSpace); // loadavg $loadavg = "n/a"; $loadavg = @getLoadAverageString(); array_push($serverStats, $loadavg); // running $running = "n/a"; $running = @getRunningTransferCount(); array_push($serverStats, $running); // queued $queued = FluxdQmgr::countQueuedTransfers(); array_push($serverStats, $queued); // speedDownPercent $percentDownload = 0; $maxDownload = $cfg["bandwidth_down"] / 8; $percentDownload = $maxDownload > 0 ? @number_format($cfg["total_download"] / $maxDownload * 100, 0) : 0; array_push($serverStats, $percentDownload); // speedUpPercent $percentUpload = 0; $maxUpload = $cfg["bandwidth_up"] / 8; $percentUpload = $maxUpload > 0 ? @number_format($cfg["total_upload"] / $maxUpload * 100, 0) : 0; array_push($serverStats, $percentUpload); // driveSpacePercent $driveSpacePercent = 0; $driveSpacePercent = @getDriveSpace($cfg["path"]); array_push($serverStats, $driveSpacePercent); // return return $serverStats; }
if ($cfg['enable_xfer'] != 0 && $cfg['xfer_realtime'] != 0) { $tmpl->setvar('_SERVERXFERSTATS', $cfg['_SERVERXFERSTATS']); $tmpl->setvar('_TOTALXFER', $cfg['_TOTALXFER']); $tmpl->setvar('_MONTHXFER', $cfg['_MONTHXFER']); $tmpl->setvar('_WEEKXFER', $cfg['_WEEKXFER']); $tmpl->setvar('_DAYXFER', $cfg['_DAYXFER']); $tmpl->setvar('_YOURXFERSTATS', $cfg['_YOURXFERSTATS']); $tmpl->setvar('totalxfer1', @formatFreeSpace($xfer_total['total']['total'] / 1048576)); $tmpl->setvar('monthxfer1', @formatFreeSpace($xfer_total['month']['total'] / 1048576)); $tmpl->setvar('weekxfer1', @formatFreeSpace($xfer_total['week']['total'] / 1048576)); $tmpl->setvar('dayxfer1', @formatFreeSpace($xfer_total['day']['total'] / 1048576)); $xfer = Xfer::getStats(); $tmpl->setvar('total2', @formatFreeSpace($xfer[$cfg["user"]]['total']['total'] / 1048576)); $tmpl->setvar('month2', @formatFreeSpace($xfer[$cfg["user"]]['month']['total'] / 1048576)); $tmpl->setvar('week2', @formatFreeSpace($xfer[$cfg["user"]]['week']['total'] / 1048576)); $tmpl->setvar('day2', @formatFreeSpace($xfer[$cfg["user"]]['day']['total'] / 1048576)); } // queue if (FluxdQmgr::isRunning()) { $tmpl->setvar('_QUEUEMANAGER', $cfg['_QUEUEMANAGER']); $tmpl->setvar('runningTransferCount', getRunningTransferCount()); $tmpl->setvar('countQueuedTransfers', FluxdQmgr::countQueuedTransfers()); $tmpl->setvar('limitGlobal', $cfg["fluxd_Qmgr_maxTotalTransfers"]); $tmpl->setvar('limitUser', $cfg["fluxd_Qmgr_maxUserTransfers"]); } // other $tmpl->setvar('_OTHERSERVERSTATS', $cfg['_OTHERSERVERSTATS']); $tmpl->setvar('downloadspeed1', @number_format($cfg["total_download"], 2)); $tmpl->setvar('downloadspeed11', @number_format($transfers['sum']['drate'], 2)); $tmpl->setvar('uploadspeed1', @number_format($cfg["total_upload"], 2)); $tmpl->setvar('uploadspeed11', @number_format($transfers['sum']['rate'], 2));
$tmpl->setvar('transferowner', $transferowner); // size $transferSize = floatval($sf->size); $tmpl->setvar('size', @formatBytesTokBMBGBTB($transferSize)); // sharing $tmpl->setvar('sharing', $totals["downtotal"] > 0 ? @number_format($totals["uptotal"] / $totals["downtotal"] * 100, 2) : "0"); // totals $tmpl->setvar('downTotal', @formatFreeSpace($totals["downtotal"] / 1048576)); $tmpl->setvar('upTotal', @formatFreeSpace($totals["uptotal"] / 1048576)); // more if ($sf->running == 1) { // running $tmpl->setvar('running', 1); // current totals $tmpl->setvar('downTotalCurrent', formatFreeSpace($totalsCurrent["downtotal"] / 1048576)); $tmpl->setvar('upTotalCurrent', formatFreeSpace($totalsCurrent["uptotal"] / 1048576)); // seeds + peers $tmpl->setvar('seeds', $sf->seeds); $tmpl->setvar('peers', $sf->peers); // port + cons $transfer_pid = getTransferPid($transfer); $tmpl->setvar('port', netstatPortByPid($transfer_pid)); $tmpl->setvar('cons', netstatConnectionsByPid($transfer_pid)); // up speed $tmpl->setvar('up_speed', trim($sf->up_speed) != "" ? $sf->up_speed : '0.0 kB/s'); // down speed $tmpl->setvar('down_speed', trim($sf->down_speed) != "" ? $sf->down_speed : '0.0 kB/s'); // sharekill $tmpl->setvar('sharekill', $ch->sharekill != 0 ? $ch->sharekill . '%' : '∞'); } else { // running
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 . '%' : '∞'); } 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; }
</tr> <tr> <td align="right"><div class="tiny">Down:</div></td> <td bgcolor="<?php echo $cfg["body_data_bg"]; ?> "><div class="tiny"><?php echo "<strong>" . formatFreeSpace($af->GetRealDownloadTotal()) . "</strong>"; ?> </div></td> <td align="right"><div class="tiny">Up:</div></td> <td bgcolor="<?php echo $cfg["body_data_bg"]; ?> "><div class="tiny"><?php echo "<strong>" . formatFreeSpace($af->uptotal / (1024 * 1024)) . "</strong>"; ?> </div></td> </tr> <tr> <td align="right"><div class="tiny">Seeds:</div></td> <td bgcolor="<?php echo $cfg["body_data_bg"]; ?> "><div class="tiny"><?php echo "<strong>" . $af->seeds . "</strong>"; ?> </div></td> <td align="right"><div class="tiny">Peers:</div></td> <td bgcolor="<?php echo $cfg["body_data_bg"];
/** * pieServerDrivespace */ function image_pieServerDrivespace() { global $cfg; // get vars $df_b = @disk_free_space($cfg["path"]); $dt_b = @disk_total_space($cfg["path"]); // check vars if ($df_b < 0 || $dt_b < 0) { // output image Image::paintNoOp(); } $du_b = $dt_b - $df_b; if ($du_b < 0) { // output image Image::paintNoOp(); } // draw image Image::paintPie3D(202, 160, 100, 50, 200, 100, 20, Image::stringToRGBColor($cfg["body_data_bg"]), array($df_b + 1.0E-5, $du_b + 1.0E-5), image_getColors(), array('Free : ' . formatFreeSpace($df_b / 1048576), 'Used : ' . formatFreeSpace($du_b / 1048576)), 58, 130, 2, 14); }
/** * gets xfer percentage bar * * @param $total * @param $used * @param $title * @return string */ function tmplGetXferBar($total, $used, $title, $type = 'xfer') { global $cfg; // create template-instance $tmpl = tmplGetInstance($cfg["theme"], "component.xferBar.tmpl"); $remaining = $total - $used / 1048576; $remaining = max(0, min($total, $remaining)); $percent = round($remaining / $total * 100, 0); $text = ' (' . formatFreeSpace($remaining) . ') ' . $cfg['_REMAINING']; if ($type == 'xfer') { $bgcolor = '#'; $bgcolor .= str_pad(dechex(255 - 255 * ($percent / 150)), 2, 0, STR_PAD_LEFT); $bgcolor .= str_pad(dechex(255 * ($percent / 150)), 2, 0, STR_PAD_LEFT); $bgcolor .= '00'; $tmpl->setvar('bgcolor', $bgcolor); } $tmpl->setvar('title', $title); $tmpl->setvar('percent', $percent); $tmpl->setvar('text', $text); $tmpl->setvar('type', $type); $percent_100 = 100 - $percent; $tmpl->setvar('percent_100', $percent_100); // grab the template $output = $tmpl->grab(); return $output; }
$cfg["theme"] = CheckandSetUserTheme(); } // Run internal maintenance regularly if (!empty($_SESSION['next_int_maintenance']) && $_SESSION['next_int_maintenance'] < time()) { require_once "inc/classes/MaintenanceAndRepair.php"; MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_INT); $_SESSION['next_int_maintenance'] = null; } } // schedule next internal maintenance if needed if (empty($_SESSION['next_int_maintenance'])) { $_SESSION['next_int_maintenance'] = time() + 2 * 3600 + mt_rand(-1200, 1200); } // 2h (+/- 20m) // free space in MB var $cfg["free_space"] = @disk_free_space($cfg["path"]) / 1048576; // drive space var $cfg['driveSpace'] = getDriveSpace($cfg["path"]); // free space formatted var $cfg['freeSpaceFormatted'] = formatFreeSpace($cfg["free_space"]); // Fluxd Fluxd::initialize(); // Qmgr FluxdServiceMod::initializeServiceMod('Qmgr'); // xfer if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { // set xfer-newday Xfer::setNewday(); } // vlib require_once "inc/lib/vlib/vlibTemplate.php";
echo _TOTALSPEED . ': <strong>' . number_format($cfg["total_download"] + $cfg["total_upload"], 2) . ' (' . number_format($sumMaxRate, 2) . ')</strong> kB/s<br>'; if ($cfg["index_page_connections"] != 0) { echo _ID_CONNECTIONS . ': <strong>' . $netstatConnectionsSum . ' (' . getSumMaxCons() . ')</strong><br>'; } echo _DRIVESPACE . ': <strong>' . formatFreeSpace($cfg["free_space"]) . '</strong><br>'; if ($cfg["show_server_load"] != 0) { echo _SERVERLOAD . ': <strong>' . $loadavgString . '</strong>'; } echo '</td>'; if ($cfg['enable_xfer'] != 0 && $cfg['xfer_realtime'] != 0) { echo '<td class="tiny" align="right" valign="bottom">'; echo '<b>' . _YOURXFERSTATS . '</b><br>'; echo _TOTALXFER . ': <strong>' . formatFreeSpace($xfer[$cfg['user']]['total']['total'] / (1024 * 1024)) . '</strong><br>'; echo _MONTHXFER . ': <strong>' . formatFreeSpace($xfer[$cfg['user']]['month']['total'] / (1024 * 1024)) . '</strong><br>'; echo _WEEKXFER . ': <strong>' . formatFreeSpace($xfer[$cfg['user']]['week']['total'] / (1024 * 1024)) . '</strong><br>'; echo _DAYXFER . ': <strong>' . formatFreeSpace($xfer[$cfg['user']]['day']['total'] / (1024 * 1024)) . '</strong><br>'; echo '</td>'; } echo '</tr></table>'; } ?> </div> </td> </tr> </table> </td></tr> </table>
$label_downTotal = formatFreeSpace($downTotal / 1048576); $label_upTotal = formatFreeSpace($upTotal / 1048576); $label_downTotalCurrent = ""; $label_upTotalCurrent = ""; $label_seeds = ""; $label_peers = ""; $label_maxcons = ""; $label_sharing = $sharing . '%'; if ($cfg["sharekill"] != 0) { $label_sharekill = $cfg["sharekill"] . '%'; } else { $label_sharekill = '∞'; } if ($af->running == 1 && $alias != "") { $label_downTotalCurrent = formatFreeSpace($downTotalCurrent / 1048576); $label_upTotalCurrent = formatFreeSpace($upTotalCurrent / 1048576); $label_seeds = $af->seeds; $label_peers = $af->peers; $torrent_pid = getTorrentPid($alias); $torrent_port = netstatPortByPid($torrent_pid); $torrent_cons = netstatConnectionsByPid($torrent_pid); if ($cfg["max_download_rate"] != 0) { $label_max_download_rate = " (" . number_format($cfg["max_download_rate"], 2) . ")"; } else { $label_max_download_rate = ' (∞)'; } if ($cfg["max_upload_rate"] != 0) { $label_max_upload_rate = " (" . number_format($cfg["max_upload_rate"], 2) . ")"; } else { $label_max_upload_rate = ' (∞)'; }
function sendRss() { global $cfg, $sendAsAttachment, $arList; $content = ""; $run = 0; // build content $content .= "<?xml version='1.0' ?>\n\n"; //$content .= '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">'."\n"; $content .= "<rss version=\"0.91\">\n"; $content .= "<channel>\n"; $content .= "<title>TorrentFlux Status</title>\n"; // transfer-list foreach ($arList as $entry) { $torrentowner = getOwner($entry); $torrentTotals = getTorrentTotals($entry); // alias / stat $alias = getAliasName($entry) . ".stat"; if (substr(strtolower($entry), -8) == ".torrent") { // this is a torrent-client $btclient = getTorrentClient($entry); $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias, $torrentowner, $cfg, $btclient); } else { if (substr(strtolower($entry), -4) == ".url") { // this is wget. use tornado statfile $alias = str_replace(".url", "", $alias); $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias, $cfg['user'], $cfg, 'tornado'); } else { // this is "something else". use tornado statfile as default $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias, $cfg['user'], $cfg, 'tornado'); } } // increment the totals if (!isset($cfg["total_upload"])) { $cfg["total_upload"] = 0; } if (!isset($cfg["total_download"])) { $cfg["total_download"] = 0; } $cfg["total_upload"] = $cfg["total_upload"] + GetSpeedValue($af->up_speed); $cfg["total_download"] = $cfg["total_download"] + GetSpeedValue($af->down_speed); // xml-string $remaining = str_replace('∞', 'Unknown', $af->time_left); if ($af->running == 1) { $run++; } else { $remaining = "Torrent Not Running"; } $sharing = number_format($torrentTotals['uptotal'] / ($af->size + 0), 2); $content .= "<item>\n"; $content .= "<title>" . $entry . " (" . $remaining . ")</title>\n"; $content .= "<description>Down Speed: " . $af->down_speed . " || Up Speed: " . $af->up_speed . " || Size: " . @formatBytesToKBMGGB($af->size) . " || Percent: " . $af->percent_done . " || Sharing: " . $sharing . " || Remaining: " . $remaining . " || Transfered Down: " . @formatBytesToKBMGGB($torrentTotals['downtotal']) . " || Transfered Up: " . @formatBytesToKBMGGB($torrentTotals['uptotal']) . "</description>\n"; $content .= "</item>\n"; } $content .= "<item>\n"; $content .= "<title>Total (" . $run . ")</title>\n"; $content .= "<description>Down Speed: " . @number_format($cfg["total_download"], 2) . " || Up Speed: " . @number_format($cfg["total_upload"], 2) . " || Free Space: " . @formatFreeSpace($cfg['free_space']) . "</description>\n"; $content .= "</item>\n"; $content .= "</channel>\n"; $content .= "</rss>"; // send content header("Cache-Control: "); header("Pragma: "); header("Content-Type: text/xml"); if ($sendAsAttachment != 0) { header("Content-Length: " . strlen($content)); header('Content-Disposition: attachment; filename="stats.xml"'); } echo $content; }
function displayXferList() { global $cfg, $xfer, $xfer_total, $db; echo "<table width='760' border=1 bordercolor='{$cfg['table_admin_border']}' cellpadding='2' cellspacing='0' bgcolor='{$cfg['table_data_bg']}'>"; echo '<tr>'; echo "<td bgcolor='{$cfg['table_header_bg']}' width='15%'><div align=center class='title'>" . _USER . '</div></td>'; echo "<td bgcolor='{$cfg['table_header_bg']}' width='22%'><div align=center class='title'>" . _TOTALXFER . '</div></td>'; echo "<td bgcolor='{$cfg['table_header_bg']}' width='22%'><div align=center class='title'>" . _MONTHXFER . '</div></td>'; echo "<td bgcolor='{$cfg['table_header_bg']}' width='22%'><div align=center class='title'>" . _WEEKXFER . '</div></td>'; echo "<td bgcolor='{$cfg['table_header_bg']}' width='22%'><div align=center class='title'>" . _DAYXFER . '</div></td>'; echo '</tr>'; $sql = 'SELECT user_id FROM tf_users ORDER BY user_id'; $rtnValue = $db->GetCol($sql); showError($db, $sql); foreach ($rtnValue as $user_id) { echo '<tr>'; echo '<td><a href="?op=xfer&user='******'">' . $user_id . '</a></td>'; $total = formatFreeSpace($xfer[$user_id]['total']['total'] / (1024 * 1024)); $month = formatFreeSpace(@$xfer[$user_id]['month']['total'] / (1024 * 1024)); $week = formatFreeSpace(@$xfer[$user_id]['week']['total'] / (1024 * 1024)); $day = formatFreeSpace(@$xfer[$user_id]['day']['total'] / (1024 * 1024)); echo '<td><div class="tiny" align="center">' . $total . '</div></td>'; echo '<td><div class="tiny" align="center">' . $month . '</div></td>'; echo '<td><div class="tiny" align="center">' . $week . '</div></td>'; echo '<td><div class="tiny" align="center">' . $day . '</div></td>'; echo '</tr>'; } echo '<td><a href="?op=xfer&user=%"><b>' . _TOTAL . '</b></a></td>'; $total = formatFreeSpace($xfer_total['total']['total'] / (1024 * 1024)); $month = formatFreeSpace($xfer_total['month']['total'] / (1024 * 1024)); $week = formatFreeSpace($xfer_total['week']['total'] / (1024 * 1024)); $day = formatFreeSpace($xfer_total['day']['total'] / (1024 * 1024)); echo '<td><div class="tiny" align="center"><b>' . $total . '</b></div></td>'; echo '<td><div class="tiny" align="center"><b>' . $month . '</b></div></td>'; echo '<td><div class="tiny" align="center"><b>' . $week . '</b></div></td>'; echo '<td><div class="tiny" align="center"><b>' . $day . '</b></div></td>'; echo '</table>'; }
/** * Xfer Shutdown * * @param $delta * @return mixed */ function _xfer($delta) { global $cfg, $db; // check xfer if ($cfg['enable_xfer'] != 1) { $this->_outputError("xfer must be enabled.\n"); return false; } // check arg if ($delta != "all" && $delta != "total" && $delta != "month" && $delta != "week" && $delta != "day") { $this->_outputMessage('invalid delta : "' . $delta . '"' . "\n"); return false; } $this->_outputMessage('checking xfer-limit(s) for "' . $delta . '" ...' . "\n"); // set xfer-realtime $cfg['xfer_realtime'] = 1; // set xfer-newday Xfer::setNewday(); // getTransferListArray to update xfer-stats $transferList = @getTransferListArray(); // get xfer-totals $xfer_total = Xfer::getStatsTotal(); // check if break needed // total if ($delta == "total" || $delta == "all") { // only do if a limit is set if ($cfg["xfer_total"] > 0) { if ($xfer_total['total']['total'] >= $cfg["xfer_total"] * 1048576) { // limit met, stop all Transfers now. $this->_outputMessage('Limit met for "total" : ' . formatFreeSpace($xfer_total['total']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_total"]) . "\n"); return $this->_transfersStop(); } else { $this->_outputMessage('Limit not met for "total" : ' . formatFreeSpace($xfer_total['total']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_total"]) . "\n"); } } else { $this->_outputMessage('no limit set for "total"' . "\n"); } } // month if ($delta == "month" || $delta == "all") { // only do if a limit is set if ($cfg["xfer_month"] > 0) { if ($xfer_total['month']['total'] >= $cfg["xfer_month"] * 1048576) { // limit met, stop all Transfers now. $this->_outputMessage('Limit met for "month" : ' . formatFreeSpace($xfer_total['month']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_month"]) . "\n"); return $this->_transfersStop(); } else { $this->_outputMessage('Limit not met for "month" : ' . formatFreeSpace($xfer_total['month']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_month"]) . "\n"); } } else { $this->_outputMessage('no limit set for "month"' . "\n"); } } // week if ($delta == "week" || $delta == "all") { // only do if a limit is set if ($cfg["xfer_week"] > 0) { if ($xfer_total['week']['total'] >= $cfg["xfer_week"] * 1048576) { // limit met, stop all Transfers now. $this->_outputMessage('Limit met for "week" : ' . formatFreeSpace($xfer_total['week']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_week"]) . "\n"); return $this->_transfersStop(); } else { $this->_outputMessage('Limit not met for "week" : ' . formatFreeSpace($xfer_total['week']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_week"]) . "\n"); } } else { $this->_outputMessage('no limit set for "week"' . "\n"); } } // day if ($delta == "day" || $delta == "all") { // only do if a limit is set if ($cfg["xfer_day"] > 0) { if ($xfer_total['day']['total'] >= $cfg["xfer_day"] * 1048576) { // limit met, stop all Transfers now. $this->_outputMessage('Limit met for "day" : ' . formatFreeSpace($xfer_total['day']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_day"]) . "\n"); return $this->_transfersStop(); } else { $this->_outputMessage('Limit not met for "day" : ' . formatFreeSpace($xfer_total['day']['total'] / 1048576) . " / " . formatFreeSpace($cfg["xfer_day"]) . "\n"); } } else { $this->_outputMessage('no limit set for "day"' . "\n"); } } // done $this->_outputMessage("done.\n"); return true; }
<td class="tiny" align="right"><?php echo _CURRENTUPLOAD; ?> :</td> <td class="tiny"><strong><?php echo number_format($cfg["total_upload"], 2); ?> </strong> kB/s</td> </tr> <tr> <td class="tiny" align="right"><?php echo _FREESPACE; ?> :</td> <td class="tiny"><strong><?php echo formatFreeSpace($cfg["free_space"]); ?> </strong></td> </tr> <tr> <td class="tiny" align="right"><?php echo _SERVERLOAD; ?> :</td> <td class="tiny"> <?php if ($cfg["show_server_load"] && @isFile($cfg["loadavg_path"])) { //$loadavg_array = explode(" ", exec("cat ".escapeshellarg($cfg["loadavg_path"]))); $loadavg = $loadavg_array[1]; //$loadavg = $loadavg_array[2]; echo "<strong>" . $loadavg . "</strong>";
/** * get Xfer-Usage * * @param $username * @return number */ function getUsage($username = "") { global $db; // sql-state $sql = "SELECT SUM(download) AS download, SUM(upload) AS upload FROM tf_xfer"; if ($username != "") { $sql .= " WHERE user_id LIKE " . $db->qstr($username); } // exec state $result = $db->Execute($sql); // error-check if ($db->ErrorNo() != 0) { dbError($sql); } // get usage $row = $result->FetchRow(); $rtnValue = "0"; if (!empty($row)) { $rtnValue = @formatFreeSpace($row["download"] / 1048576 + $row["upload"] / 1048576); } // return return $rtnValue; }
/** * gets details of a transfer as array * * @param $transfer * @param $full * @return array with details * * array-keys : * * running * speedDown * speedUp * downCurrent * upCurrent * downTotal * upTotal * percentDone * sharing * timeLeft * seeds * peers * cons * * owner * size * maxSpeedDown * maxSpeedUp * maxcons * sharekill * port * */ function getTransferDetails($transfer, $full) { global $cfg, $transfers; $details = array(); // common functions require_once 'inc/functions/functions.common.php'; $transferowner = getOwner($transfer); // settings if (isset($transfers['settings'][$transfer])) { $settingsAry = $transfers['settings'][$transfer]; } else { $settingsAry = array(); $ftransfer = str_replace('.imported', '', $transfer); if (substr($ftransfer, -8) == ".torrent") { // this is a t-client $settingsAry['type'] = "torrent"; $settingsAry['client'] = getTransferClient($transfer); if (empty($settingsAry['client'])) { $settingsAry['client'] = $cfg["btclient"]; } } else { if (substr($transfer, -5) == ".wget") { // this is wget. $settingsAry['type'] = "wget"; $settingsAry['client'] = "wget"; } else { if (substr($transfer, -4) == ".nzb") { // this is nzbperl. $settingsAry['type'] = "nzb"; $settingsAry['client'] = "nzbperl"; } else { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $ftransfer); @error("Invalid Transfer", "", "", array($transfer)); } } } $settingsAry['hash'] = ""; $settingsAry["savepath"] = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . $transferowner . '/' : $cfg["path"] . $cfg["path_incoming"] . '/'; $settingsAry['datapath'] = ""; } $totalsCurrent = array("downtotal" => 0, "uptotal" => 0); $totals = array("downtotal" => 0, "uptotal" => 0); // stat $sf = new StatFile($transfer, $transferowner); // totals $afu = $sf->uptotal; $afd = $sf->downtotal; if (isset($settingsAry['client'])) { $ch = ClientHandler::getInstance($settingsAry['client']); $totalsCurrent = $ch->getTransferCurrentOP($transfer, $settingsAry['hash'], $afu, $afd); $totals = $ch->getTransferTotalOP($transfer, $settingsAry['hash'], $afu, $afd); $ch->updateStatFiles($transfer); $sf = new StatFile($transfer, $transferowner); $bIsRPC = (int) $ch->useRPC; } // size $size = floatval($sf->size); // running $running = $sf->running; $details['running'] = $running; $details['cons'] = ""; $details['port'] = ""; // speed_down + speed_up + seeds + peers + cons if ($bIsRPC) { $stat = $ch->monitorTransfer($transfer, $format = "tf"); $totals["downtotal"] = $stat['downTotal']; $totals["uptotal"] = $stat['upTotal']; $details['running'] = $stat['running']; // speed_down $details['speedDown'] = empty($stat['speedDown']) ? '' : $stat['speedDown']; // speed_up $details['speedUp'] = empty($stat['speedUp']) ? '' : $stat['speedUp']; // down_current $details['downCurrent'] = formatFreeSpace($totals["downtotal"] / 1048576); // up_current $details['upCurrent'] = formatFreeSpace($totals["uptotal"] / 1048576); // seeds $details['seeds'] = $stat['seeds']; // peers $details['peers'] = $stat['peers']; // connections $details['cons'] = $stat['cons']; // percentage $percentage = $stat['percentDone']; // sharing $details['sharing'] = $stat['sharing']; // size $size = $stat['size']; // eta $details['eta'] = $stat['eta']; } elseif ($running == 1) { // pid $pid = (int) getTransferPid($transfer); // speed_down $details['speedDown'] = trim($sf->down_speed) != "" ? $sf->down_speed : '0.0 kB/s'; // speed_up $details['speedUp'] = trim($sf->up_speed) != "" ? $sf->up_speed : '0.0 kB/s'; // down_current $details['downCurrent'] = formatFreeSpace($totalsCurrent["downtotal"] / 1048576); // up_current $details['upCurrent'] = formatFreeSpace($totalsCurrent["uptotal"] / 1048576); // seeds $details['seeds'] = $sf->seeds; // peers $details['peers'] = $sf->peers; // percentage $percentage = $sf->percent_done; // eta $details['eta'] = $sf->time_left; // cons if ($pid > 0) { $details['cons'] = netstatConnectionsByPid($pid); } } else { // speed_down $details['speedDown'] = ""; // speed_up $details['speedUp'] = ""; // down_current $details['downCurrent'] = ""; // up_current $details['upCurrent'] = ""; // seeds $details['seeds'] = ""; // peers $details['peers'] = ""; // eta $details['eta'] = ""; // percentage $percentage = $sf->percent_done; } // down_total $details['downTotal'] = formatFreeSpace($totals["downtotal"] / 1048576); // up_total $details['upTotal'] = formatFreeSpace($totals["uptotal"] / 1048576); if ($percentage < 0) { $percentage = round($percentage * -1 - 100, 1); $sf->time_left = $cfg['_INCOMPLETE']; } elseif ($percentage > 100) { $percentage = 100; } $details['percentDone'] = $percentage; // sharing if (is_array($totals)) { $details['sharing'] = $totals["downtotal"] > 0 ? @number_format($totals["uptotal"] / $totals["downtotal"] * 100, 2) : 0; } // full (including static) details if ($full) { // owner $details['owner'] = $transferowner; // size $details['size'] = @formatBytesTokBMBGBTB($size); if ($running == 1) { // max_download_rate $details['maxSpeedDown'] = number_format($cfg["max_download_rate"], 2); // max_upload_rate $details['maxSpeedUp'] = number_format($cfg["max_upload_rate"], 2); // maxcons $details['maxcons'] = $cfg["maxcons"]; // sharekill $details['sharekill'] = $cfg["sharekill"]; // port if ($pid > 0) { $details['port'] = netstatPortByPid($pid); } } else { // max_download_rate $details['maxSpeedDown'] = ""; // max_upload_rate $details['maxSpeedUp'] = ""; // maxcons $details['maxcons'] = ""; // sharekill $details['sharekill'] = ""; } } // return return $details; }
$row[0] = $xfer_total['day']['download']; $row[1] = $xfer_total['day']['upload']; } else { $row[0] = $xfer[$username]['day']['download']; $row[1] = $xfer[$username]['day']['upload']; } } if ($upload + $download != 0) { array_push($day_list, array('start' => $start, 'downloadstr' => formatFreeSpace($download / 1048576), 'uploadstr' => formatFreeSpace($upload / 1048576), 'totalstr' => formatFreeSpace(($download + $upload) / 1048576))); } $download = $row[0]; $upload = $row[1]; $start = $newstart; } if ($upload + $download != 0) { array_push($day_list, array('start' => $start, 'downloadstr' => formatFreeSpace($download / 1048576), 'uploadstr' => formatFreeSpace($upload / 1048576), 'totalstr' => formatFreeSpace(($download + $upload) / 1048576))); } $tmpl->setloop('day_list', $day_list); // $tmpl->setvar('_TOTAL', $cfg["_TOTAL"]); $tmpl->setvar('_SERVERXFERSTATS', $cfg['_SERVERXFERSTATS']); $tmpl->setvar('_USERDETAILS', $cfg['_USERDETAILS']); $tmpl->setvar('_USER', $cfg["_USER"]); $tmpl->setvar('_TOTALXFER', $cfg["_TOTALXFER"]); $tmpl->setvar('_MONTHXFER', $cfg["_MONTHXFER"]); $tmpl->setvar('_WEEKXFER', $cfg["_WEEKXFER"]); $tmpl->setvar('_DAYXFER', $cfg["_DAYXFER"]); $tmpl->setvar('_DOWNLOAD', $cfg['_DOWNLOAD']); $tmpl->setvar('_UPLOAD', $cfg['_UPLOAD']); } //
function displayDriveSpaceBar($drivespace) { global $cfg; $freeSpace = ""; if ($drivespace > 20) { $freeSpace = " (" . formatFreeSpace($cfg["free_space"]) . " Free)"; } ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr nowrap> <td width="2%"><div class="tiny"><?php echo _STORAGE; ?> :</div></td> <td width="80%"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td background="themes/<?php echo $cfg["theme"]; ?> /images/proglass.gif" width="<?php echo $drivespace; ?> %"><div class="tinypercent" align="center"><?php echo $drivespace . "%" . $freeSpace; ?> </div></td> <td background="themes/<?php echo $cfg["theme"]; ?> /images/noglass.gif" width="<?php echo 100 - $drivespace; ?> %"><img src="images/blank.gif" width="1" height="3" border="0"></td> </tr> </table> </td> </tr> </table> <?php }