| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?php
- /* $Id: functions.image.php 2894 2007-04-14 13:34:05Z b4rt $ */
- /*******************************************************************************
- LICENSE
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License (GPL)
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- To read the license please visit http://www.gnu.org/copyleft/gpl.html
- *******************************************************************************/
- /**
- * login
- */
- function image_login() {
- global $cfg;
- $bgImage = ((strpos($cfg["default_theme"], '/')) === false)
- ? 'themes/'.$cfg["default_theme"].'/images/code_bg'
- : 'themes/tf_standard_themes/images/code_bg';
- $rndCode = loginImageCode($cfg["db_user"], tfb_getRequestVar('rnd'));
- Image::paintLabelFromImage($bgImage, $rndCode, 5, 12, 2, 80, 80, 80);
- }
- /**
- * test
- */
- function image_test() {
- global $cfg;
- $bgImage = ((strpos($cfg["theme"], '/')) === false)
- ? 'themes/'.$cfg["theme"].'/images/code_bg'
- : 'themes/tf_standard_themes/images/code_bg';
- Image::paintLabelFromImage($bgImage, 'tf-b4rt', 5, 8, 2, 0, 0, 0);
- }
- /**
- * pieTransferTotals
- */
- function image_pieTransferTotals() {
- global $cfg;
- // transfer-id
- $transfer = tfb_getRequestVar('transfer');
- if (empty($transfer))
- Image::paintNoOp();
- // validate transfer
- if (tfb_isValidTransfer($transfer) !== true) {
- AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
- Image::paintNoOp();
- }
- // client-handler + totals
- $ch = ClientHandler::getInstance(getTransferClient($transfer));
- $totals = $ch->getTransferTotal($transfer);
- // draw image
- Image::paintPie3D(
- 202,
- 160,
- 100,
- 50,
- 200,
- 100,
- 20,
- Image::stringToRGBColor($cfg["body_data_bg"]),
- array($totals["uptotal"] + 1, $totals["downtotal"] + 1),
- array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
- array('Up : '.@formatFreeSpace($totals["uptotal"] / 1048576), 'Down : '.@formatFreeSpace($totals["downtotal"] / 1048576)),
- 48,
- 130,
- 2,
- 14
- );
- }
- /**
- * pieTransferPeers
- */
- function image_pieTransferPeers() {
- global $cfg;
- // transfer-id
- $transfer = tfb_getRequestVar('transfer');
- if (empty($transfer))
- Image::paintNoOp();
- // validate transfer
- if (tfb_isValidTransfer($transfer) !== true) {
- AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
- Image::paintNoOp();
- }
- // 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);
- 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 "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'] + 0.00001, $peerData['peers'] + 0.00001),
- array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
- array('Seeds : '.$peerData['seedsLabel'], 'Peers : '.$peerData['peersLabel']),
- 58,
- 130,
- 2,
- 14
- );
- }
- /**
- * pieTransferScrape
- */
- function image_pieTransferScrape() {
- global $cfg;
- // transfer-id
- $transfer = tfb_getRequestVar('transfer');
- if (empty($transfer))
- Image::paintNoOp();
- // validate transfer
- if (tfb_isValidTransfer($transfer) !== true) {
- AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
- Image::paintNoOp();
- }
- // get scrape-data
- require_once('inc/functions/functions.common.php');
- $scrape = @trim(getTorrentScrapeInfo($transfer));
- if ((!empty($scrape)) && (preg_match("/(\d+) seeder\(s\), (\d+) leecher\(s\).*/i", $scrape, $reg))) {
- $seeder = $reg[1];
- $leecher = $reg[2];
- // draw image
- Image::paintPie3D(
- 202,
- 160,
- 100,
- 50,
- 200,
- 100,
- 20,
- Image::stringToRGBColor($cfg["body_data_bg"]),
- array($seeder + 0.00001, $leecher + 0.00001),
- array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
- array('Seeder : '.$seeder, 'Leecher : '.$leecher),
- 58,
- 130,
- 2,
- 14
- );
- } else {
- // output image
- Image::paintNoOp();
- }
- }
- /**
- * pieServerBandwidth
- */
- function image_pieServerBandwidth() {
- global $cfg;
- // get vars
- getTransferListArray();
- $bwU = (isset($cfg["total_upload"])) ? $cfg["total_upload"] : 0.0;
- $bwD = (isset($cfg["total_download"])) ? $cfg["total_download"] : 0.0;
- // check vars
- if (($bwU < 0) || ($bwD < 0)) {
- // output image
- Image::paintNoOp();
- }
- // draw image
- Image::paintPie3D(
- 202,
- 160,
- 100,
- 50,
- 200,
- 100,
- 20,
- Image::stringToRGBColor($cfg["body_data_bg"]),
- array($bwU + 0.00001, $bwD + 0.00001),
- array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
- array('Up : '.@number_format($bwU, 2)." kB/s", 'Down : '.@number_format($bwD, 2)." kB/s"),
- 48,
- 130,
- 2,
- 14
- );
- }
- /**
- * 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 + 0.00001, $du_b + 0.00001),
- array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
- array('Free : '.formatFreeSpace($df_b / 1048576), 'Used : '.formatFreeSpace($du_b / 1048576)),
- 58,
- 130,
- 2,
- 14
- );
- }
- /**
- * mrtg
- */
- function image_mrtg() {
- global $cfg;
- // filename
- $fileName = tfb_getRequestVar('f');
- if (empty($fileName))
- Image::paintNoOp();
- $targetFile = $cfg["path"].'.mrtg/'.$fileName;
- // validate file
- if (!((tfb_isValidPath($targetFile) === true)
- && (preg_match('/^[0-9a-zA-Z_]+(-day|-week|-month|-year)(.png)$/D', $fileName))
- && (@is_file($targetFile))
- )) {
- AuditAction($cfg["constants"]["error"], "ILLEGAL MRTG-IMAGE: ".$cfg["user"]." tried to access ".$fileName);
- Image::paintNoOp();
- }
- // send content
- @header('Accept-Ranges: bytes');
- @header('Content-Length: '.filesize($targetFile));
- @header('Content-Type: image/png');
- @fpassthru(fopen($targetFile, 'rb'));
- exit();
- }
- /**
- * spacer
- */
- function image_spacer() {
- // output image
- Image::paintSpacer();
- }
- /**
- * notsup
- */
- function image_notsup() {
- // output image
- Image::paintNotSupported();
- }
- /**
- * noop
- */
- function image_noop() {
- // output image
- Image::paintNoOp();
- }
- ?>
|