functions.image.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. /* $Id: functions.image.php 2894 2007-04-14 13:34:05Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * login
  17. */
  18. function image_login() {
  19. global $cfg;
  20. $bgImage = ((strpos($cfg["default_theme"], '/')) === false)
  21. ? 'themes/'.$cfg["default_theme"].'/images/code_bg'
  22. : 'themes/tf_standard_themes/images/code_bg';
  23. $rndCode = loginImageCode($cfg["db_user"], tfb_getRequestVar('rnd'));
  24. Image::paintLabelFromImage($bgImage, $rndCode, 5, 12, 2, 80, 80, 80);
  25. }
  26. /**
  27. * test
  28. */
  29. function image_test() {
  30. global $cfg;
  31. $bgImage = ((strpos($cfg["theme"], '/')) === false)
  32. ? 'themes/'.$cfg["theme"].'/images/code_bg'
  33. : 'themes/tf_standard_themes/images/code_bg';
  34. Image::paintLabelFromImage($bgImage, 'tf-b4rt', 5, 8, 2, 0, 0, 0);
  35. }
  36. /**
  37. * pieTransferTotals
  38. */
  39. function image_pieTransferTotals() {
  40. global $cfg;
  41. // transfer-id
  42. $transfer = tfb_getRequestVar('transfer');
  43. if (empty($transfer))
  44. Image::paintNoOp();
  45. // validate transfer
  46. if (tfb_isValidTransfer($transfer) !== true) {
  47. AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
  48. Image::paintNoOp();
  49. }
  50. // client-handler + totals
  51. $ch = ClientHandler::getInstance(getTransferClient($transfer));
  52. $totals = $ch->getTransferTotal($transfer);
  53. // draw image
  54. Image::paintPie3D(
  55. 202,
  56. 160,
  57. 100,
  58. 50,
  59. 200,
  60. 100,
  61. 20,
  62. Image::stringToRGBColor($cfg["body_data_bg"]),
  63. array($totals["uptotal"] + 1, $totals["downtotal"] + 1),
  64. array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
  65. array('Up : '.@formatFreeSpace($totals["uptotal"] / 1048576), 'Down : '.@formatFreeSpace($totals["downtotal"] / 1048576)),
  66. 48,
  67. 130,
  68. 2,
  69. 14
  70. );
  71. }
  72. /**
  73. * pieTransferPeers
  74. */
  75. function image_pieTransferPeers() {
  76. global $cfg;
  77. // transfer-id
  78. $transfer = tfb_getRequestVar('transfer');
  79. if (empty($transfer))
  80. Image::paintNoOp();
  81. // validate transfer
  82. if (tfb_isValidTransfer($transfer) !== true) {
  83. AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
  84. Image::paintNoOp();
  85. }
  86. // stat
  87. $sf = new StatFile($transfer);
  88. $seeds = trim($sf->seeds);
  89. $peers = trim($sf->peers);
  90. // client-switch + get peer-data
  91. $peerData = array();
  92. $peerData['seeds'] = 0;
  93. $peerData['peers'] = 0;
  94. $peerData['seedsLabel'] = ($seeds != "") ? $seeds : 0;
  95. $peerData['peersLabel'] = ($peers != "") ? $peers : 0;
  96. $client = getTransferClient($transfer);
  97. switch ($client) {
  98. case "tornado":
  99. if ($seeds != "") {
  100. if (strpos($seeds, "+") !== false)
  101. $seeds = preg_replace('/(\d+)\+.*/i', '${1}', $seeds);
  102. if (is_numeric($seeds))
  103. $peerData['seeds'] = $seeds;
  104. $peerData['seedsLabel'] = $seeds;
  105. }
  106. if ($peers != "") {
  107. if (strpos($peers, "+") !== false)
  108. $peers = preg_replace('/(\d+)\+.*/i', '${1}', $peers);
  109. if (is_numeric($peers))
  110. $peerData['peers'] = $peers;
  111. $peerData['peersLabel'] = $peers;
  112. }
  113. break;
  114. case "transmission":
  115. case "azureus":
  116. if ($seeds != "") {
  117. if (strpos($seeds, "(") !== false)
  118. $seeds = preg_replace('/.*(\d+) .*/i', '${1}', $seeds);
  119. if (is_numeric($seeds))
  120. $peerData['seeds'] = $seeds;
  121. $peerData['seedsLabel'] = $seeds;
  122. }
  123. if ($peers != "") {
  124. if (strpos($peers, "(") !== false)
  125. $peers = preg_replace('/.*(\d+) .*/i', '${1}', $peers);
  126. if (is_numeric($peers))
  127. $peerData['peers'] = $peers;
  128. $peerData['peersLabel'] = $peers;
  129. }
  130. break;
  131. case "mainline":
  132. if (($seeds != "") && (is_numeric($seeds))) {
  133. $peerData['seeds'] = $seeds;
  134. $peerData['seedsLabel'] = $seeds;
  135. }
  136. if (($peers != "") && (is_numeric($peers))) {
  137. $peerData['peers'] = $peers;
  138. $peerData['peersLabel'] = $peers;
  139. }
  140. break;
  141. case "wget":
  142. case "nzbperl":
  143. $peerData['seeds'] = ($seeds != "") ? $seeds : 0;
  144. $peerData['peers'] = ($peers != "") ? $peers : 0;
  145. break;
  146. default:
  147. AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
  148. Image::paintNoOp();
  149. }
  150. // draw image
  151. Image::paintPie3D(
  152. 202,
  153. 160,
  154. 100,
  155. 50,
  156. 200,
  157. 100,
  158. 20,
  159. Image::stringToRGBColor($cfg["body_data_bg"]),
  160. array($peerData['seeds'] + 0.00001, $peerData['peers'] + 0.00001),
  161. array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
  162. array('Seeds : '.$peerData['seedsLabel'], 'Peers : '.$peerData['peersLabel']),
  163. 58,
  164. 130,
  165. 2,
  166. 14
  167. );
  168. }
  169. /**
  170. * pieTransferScrape
  171. */
  172. function image_pieTransferScrape() {
  173. global $cfg;
  174. // transfer-id
  175. $transfer = tfb_getRequestVar('transfer');
  176. if (empty($transfer))
  177. Image::paintNoOp();
  178. // validate transfer
  179. if (tfb_isValidTransfer($transfer) !== true) {
  180. AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$transfer);
  181. Image::paintNoOp();
  182. }
  183. // get scrape-data
  184. require_once('inc/functions/functions.common.php');
  185. $scrape = @trim(getTorrentScrapeInfo($transfer));
  186. if ((!empty($scrape)) && (preg_match("/(\d+) seeder\(s\), (\d+) leecher\(s\).*/i", $scrape, $reg))) {
  187. $seeder = $reg[1];
  188. $leecher = $reg[2];
  189. // draw image
  190. Image::paintPie3D(
  191. 202,
  192. 160,
  193. 100,
  194. 50,
  195. 200,
  196. 100,
  197. 20,
  198. Image::stringToRGBColor($cfg["body_data_bg"]),
  199. array($seeder + 0.00001, $leecher + 0.00001),
  200. array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
  201. array('Seeder : '.$seeder, 'Leecher : '.$leecher),
  202. 58,
  203. 130,
  204. 2,
  205. 14
  206. );
  207. } else {
  208. // output image
  209. Image::paintNoOp();
  210. }
  211. }
  212. /**
  213. * pieServerBandwidth
  214. */
  215. function image_pieServerBandwidth() {
  216. global $cfg;
  217. // get vars
  218. getTransferListArray();
  219. $bwU = (isset($cfg["total_upload"])) ? $cfg["total_upload"] : 0.0;
  220. $bwD = (isset($cfg["total_download"])) ? $cfg["total_download"] : 0.0;
  221. // check vars
  222. if (($bwU < 0) || ($bwD < 0)) {
  223. // output image
  224. Image::paintNoOp();
  225. }
  226. // draw image
  227. Image::paintPie3D(
  228. 202,
  229. 160,
  230. 100,
  231. 50,
  232. 200,
  233. 100,
  234. 20,
  235. Image::stringToRGBColor($cfg["body_data_bg"]),
  236. array($bwU + 0.00001, $bwD + 0.00001),
  237. array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
  238. array('Up : '.@number_format($bwU, 2)." kB/s", 'Down : '.@number_format($bwD, 2)." kB/s"),
  239. 48,
  240. 130,
  241. 2,
  242. 14
  243. );
  244. }
  245. /**
  246. * pieServerDrivespace
  247. */
  248. function image_pieServerDrivespace() {
  249. global $cfg;
  250. // get vars
  251. $df_b = @disk_free_space($cfg["path"]);
  252. $dt_b = @disk_total_space($cfg["path"]);
  253. // check vars
  254. if (($df_b < 0) || ($dt_b < 0)) {
  255. // output image
  256. Image::paintNoOp();
  257. }
  258. $du_b = $dt_b - $df_b;
  259. if ($du_b < 0) {
  260. // output image
  261. Image::paintNoOp();
  262. }
  263. // draw image
  264. Image::paintPie3D(
  265. 202,
  266. 160,
  267. 100,
  268. 50,
  269. 200,
  270. 100,
  271. 20,
  272. Image::stringToRGBColor($cfg["body_data_bg"]),
  273. array($df_b + 0.00001, $du_b + 0.00001),
  274. array(array('r' => 0x00, 'g' => 0xEB, 'b' => 0x0C), array('r' => 0x10, 'g' => 0x00, 'b' => 0xFF)),
  275. array('Free : '.formatFreeSpace($df_b / 1048576), 'Used : '.formatFreeSpace($du_b / 1048576)),
  276. 58,
  277. 130,
  278. 2,
  279. 14
  280. );
  281. }
  282. /**
  283. * mrtg
  284. */
  285. function image_mrtg() {
  286. global $cfg;
  287. // filename
  288. $fileName = tfb_getRequestVar('f');
  289. if (empty($fileName))
  290. Image::paintNoOp();
  291. $targetFile = $cfg["path"].'.mrtg/'.$fileName;
  292. // validate file
  293. if (!((tfb_isValidPath($targetFile) === true)
  294. && (preg_match('/^[0-9a-zA-Z_]+(-day|-week|-month|-year)(.png)$/D', $fileName))
  295. && (@is_file($targetFile))
  296. )) {
  297. AuditAction($cfg["constants"]["error"], "ILLEGAL MRTG-IMAGE: ".$cfg["user"]." tried to access ".$fileName);
  298. Image::paintNoOp();
  299. }
  300. // send content
  301. @header('Accept-Ranges: bytes');
  302. @header('Content-Length: '.filesize($targetFile));
  303. @header('Content-Type: image/png');
  304. @fpassthru(fopen($targetFile, 'rb'));
  305. exit();
  306. }
  307. /**
  308. * spacer
  309. */
  310. function image_spacer() {
  311. // output image
  312. Image::paintSpacer();
  313. }
  314. /**
  315. * notsup
  316. */
  317. function image_notsup() {
  318. // output image
  319. Image::paintNotSupported();
  320. }
  321. /**
  322. * noop
  323. */
  324. function image_noop() {
  325. // output image
  326. Image::paintNoOp();
  327. }
  328. ?>