1
0

Stats.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <?php
  2. /* $Id: Stats.php 3164 2007-07-23 09:58:35Z warion $ */
  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. * Stats
  17. */
  18. class Stats
  19. {
  20. // private fields
  21. // ids of server-details
  22. var $_serverIds = array(
  23. "speedDown", /* 0 */
  24. "speedUp", /* 1 */
  25. "speedTotal", /* 2 */
  26. "cons", /* 3 */
  27. "freeSpace", /* 4 */
  28. "loadavg", /* 5 */
  29. "running", /* 6 */
  30. "queued", /* 7 */
  31. "speedDownPercent", /* 8 */
  32. "speedUpPercent", /* 9 */
  33. "driveSpacePercent" /* 10 */
  34. );
  35. var $_serverIdCount = 11;
  36. // ids of transfer-details
  37. var $_transferIds = array(
  38. "running", /* 0 */
  39. "speedDown", /* 1 */
  40. "speedUp", /* 2 */
  41. "downCurrent", /* 3 */
  42. "upCurrent", /* 4 */
  43. "downTotal", /* 5 */
  44. "upTotal", /* 6 */
  45. "percentDone", /* 7 */
  46. "sharing", /* 8 */
  47. "eta", /* 9 */
  48. "seeds", /* 10 */
  49. "peers", /* 11 */
  50. "cons" /* 12 */
  51. );
  52. var $_transferIdCount = 13;
  53. // ids of xfer-details
  54. var $_xferIds = array(
  55. "xferGlobalTotal", /* 0 */
  56. "xferGlobalMonth", /* 1 */
  57. "xferGlobalWeek", /* 2 */
  58. "xferGlobalDay", /* 3 */
  59. "xferUserTotal", /* 4 */
  60. "xferUserMonth", /* 5 */
  61. "xferUserWeek", /* 6 */
  62. "xferUserDay" /* 7 */
  63. );
  64. var $_xferIdCount = 8;
  65. // ids of user-details
  66. var $_userIds = array(
  67. "state" /* 0 */
  68. );
  69. var $_userIdCount = 1;
  70. // stats-fields
  71. var $_serverLabels = array();
  72. var $_xferLabels = array();
  73. var $_transferList = array();
  74. var $_transferHeads = array();
  75. var $_serverStats = array();
  76. var $_xferStats = array();
  77. var $_transferDetails = array();
  78. var $_userList = array();
  79. var $_userCount = 0;
  80. var $_transferID = "";
  81. // options
  82. var $_type = "";
  83. var $_format = "";
  84. var $_header = 0;
  85. var $_compressed = 0;
  86. var $_attachment = 0;
  87. // content
  88. var $_indent = "";
  89. var $_content = "";
  90. // =========================================================================
  91. // public static methods
  92. // =========================================================================
  93. /**
  94. * process a request
  95. *
  96. * @param $params
  97. */
  98. function processRequest($params) {
  99. // create new instance
  100. $instanceStats = new Stats($params);
  101. // call instance-method
  102. $instanceStats->instance_processRequest();
  103. }
  104. // =========================================================================
  105. // ctor
  106. // =========================================================================
  107. /**
  108. * do not use direct, use the public static methods !
  109. *
  110. * @param $params
  111. * @return Stats
  112. */
  113. function Stats($params) {
  114. global $cfg;
  115. // type
  116. $this->_type = (isset($params["t"]))
  117. ? htmlentities(trim($params["t"]), ENT_QUOTES)
  118. : $cfg['stats_default_type'];
  119. // format
  120. $this->_format = (isset($params["f"]))
  121. ? htmlentities(trim($params["f"]), ENT_QUOTES)
  122. : $cfg['stats_default_format'];
  123. // header
  124. $this->_header = (isset($params["h"]))
  125. ? htmlentities(trim($params["h"]), ENT_QUOTES)
  126. : $cfg['stats_default_header'];
  127. // compressed
  128. $this->_compressed = (isset($params["c"]))
  129. ? htmlentities(trim($params["c"]), ENT_QUOTES)
  130. : $cfg['stats_default_compress'];
  131. // attachment
  132. $this->_attachment = (isset($params["a"]))
  133. ? htmlentities(trim($params["a"]), ENT_QUOTES)
  134. : $cfg['stats_default_attach'];
  135. // transfer-id
  136. $this->_transferID = (isset($params["i"]))
  137. ? htmlentities(trim($params["i"]), ENT_QUOTES)
  138. : "";
  139. // usage ?
  140. if (isset($params["usage"])) {
  141. $this->_type = "usage";
  142. } else {
  143. if (($cfg['stats_show_usage'] == 1) && (count($_GET) == 0))
  144. $this->_type = "usage";
  145. }
  146. }
  147. // =========================================================================
  148. // public methods
  149. // =========================================================================
  150. /**
  151. * process a request
  152. */
  153. function instance_processRequest() {
  154. global $cfg, $db;
  155. // type-switch
  156. switch ($this->_type) {
  157. case "all":
  158. if (!(($this->_format == "txt") && ($this->_header == 0)))
  159. $this->_transferHeads = getTransferListHeadArray();
  160. $this->_indent = " ";
  161. // xfer-init
  162. if ($cfg['xfer_realtime'] == 0) {
  163. $cfg['xfer_realtime'] = 1;
  164. // set xfer-newday
  165. Xfer::setNewday();
  166. }
  167. $this->_transferList = getTransferListArray();
  168. $this->_initServerStats();
  169. $this->_initXferStats();
  170. $this->_initUserStats();
  171. break;
  172. case "server":
  173. $this->_indent = "";
  174. $this->_transferList = getTransferListArray();
  175. $this->_initServerStats();
  176. break;
  177. case "xfer":
  178. $this->_indent = "";
  179. // xfer-init
  180. if ($cfg['xfer_realtime'] == 0) {
  181. $cfg['xfer_realtime'] = 1;
  182. // set xfer-newday
  183. Xfer::setNewday();
  184. }
  185. $this->_transferList = getTransferListArray();
  186. $this->_initXferStats();
  187. break;
  188. case "transfers":
  189. $this->_indent = "";
  190. $this->_transferList = getTransferListArray();
  191. if (!(($this->_format == "txt") && ($this->_header == 0)))
  192. $this->_transferHeads = getTransferListHeadArray();
  193. break;
  194. case "transfer":
  195. // transfer-id
  196. if (empty($this->_transferID))
  197. @error("missing params", "stats.php", "", array('i'));
  198. // validate transfer
  199. if (tfb_isValidTransfer($this->_transferID) !== true) {
  200. AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: ".$this->_transferID);
  201. @error("Invalid Transfer", "", "", array($this->_transferID));
  202. }
  203. $this->_indent = "";
  204. $this->_transferDetails = getTransferDetails($this->_transferID, false);
  205. break;
  206. case "users":
  207. $this->_indent = "";
  208. $this->_initUserStats();
  209. break;
  210. case "usage":
  211. $this->_sendUsage();
  212. }
  213. // action
  214. switch ($this->_format) {
  215. case "xml":
  216. $this->_sendXML();
  217. case "rss":
  218. $this->_sendRSS();
  219. case "txt":
  220. $this->_sendTXT();
  221. }
  222. }
  223. // =========================================================================
  224. // private methods
  225. // =========================================================================
  226. /**
  227. * sends current content
  228. *
  229. * @param $contentType
  230. * @param $fileName
  231. * @param $sendCompressed
  232. * @param $sendAsAttachment
  233. */
  234. function _sendContent($contentType, $fileName, $sendCompressed, $sendAsAttachment) {
  235. global $cfg;
  236. // send content
  237. @header("Cache-Control: no-cache");
  238. @header("Pragma: no-cache");
  239. if ($sendCompressed != 0) {
  240. $contentCompressed = gzdeflate($this->_content, $cfg['stats_deflate_level']);
  241. @header("Content-Type: application/octet-stream");
  242. if ($sendAsAttachment != 0) {
  243. @header("Content-Length: " .(string)(strlen($contentCompressed)) );
  244. @header('Content-Disposition: attachment; filename="'.$fileName.'"');
  245. }
  246. @header("Content-Transfer-Encoding: binary\n");
  247. echo $contentCompressed;
  248. } else {
  249. @header("Content-Type: ".$contentType);
  250. if ($sendAsAttachment != 0) {
  251. @header("Content-Length: ".(string)strlen($this->_content));
  252. @header('Content-Disposition: attachment; filename="'.$fileName.'"');
  253. }
  254. echo $this->_content;
  255. }
  256. exit();
  257. }
  258. /**
  259. * This method sends stats as xml.
  260. * xml-schema defined in tfbstats.xsd/tfbserver.xsd/tfbxfer.xsd/tfbtransfers.xsd/tfbtransfer.xsd/tfbusers.xsd
  261. */
  262. function _sendXML() {
  263. // build content
  264. $this->_content = '<?xml version="1.0" encoding="utf-8"?>'."\n";
  265. switch ($this->_type) {
  266. case "all":
  267. $this->_content .= '<tfbstats>'."\n";
  268. break;
  269. }
  270. // server stats
  271. switch ($this->_type) {
  272. case "all":
  273. case "server":
  274. $this->_content .= $this->_indent.'<server>'."\n";
  275. for ($i = 0; $i < $this->_serverIdCount; $i++)
  276. $this->_content .= $this->_indent.' <serverStat name="'.$this->_serverIds[$i].'">'.$this->_serverStats[$i].'</serverStat>'."\n";
  277. $this->_content .= $this->_indent.'</server>'."\n";
  278. }
  279. // xfer stats
  280. switch ($this->_type) {
  281. case "all":
  282. case "xfer":
  283. $this->_content .= $this->_indent.'<xfer>'."\n";
  284. for ($i = 0; $i < $this->_xferIdCount; $i++)
  285. $this->_content .= $this->_indent.' <xferStat name="'.$this->_xferIds[$i].'">'.$this->_xferStats[$i].'</xferStat>'."\n";
  286. $this->_content .= $this->_indent.'</xfer>'."\n";
  287. }
  288. // user-list
  289. switch ($this->_type) {
  290. case "all":
  291. case "users":
  292. $this->_content .= $this->_indent.'<users>'."\n";
  293. foreach ($this->_userList as $userAry) {
  294. $this->_content .= $this->_indent.' <user name="'.$userAry[0].'">'."\n";
  295. for ($i = 0; $i < $this->_userIdCount; $i++)
  296. $this->_content .= $this->_indent.' <userProp name="'.$this->_userIds[$i].'">'.$userAry[$i + 1].'</userProp>'."\n";
  297. $this->_content .= $this->_indent.' </user>'."\n";
  298. }
  299. $this->_content .= $this->_indent.'</users>'."\n";
  300. }
  301. // transfer-list
  302. switch ($this->_type) {
  303. case "all":
  304. case "transfers":
  305. $this->_content .= $this->_indent.'<transfers>'."\n";
  306. foreach ($this->_transferList as $transferAry) {
  307. $this->_content .= $this->_indent.' <transfer name="'.$transferAry[0].'">'."\n";
  308. $size = count($transferAry);
  309. for ($i = 1; $i < $size; $i++)
  310. $this->_content .= $this->_indent.' <transferStat name="'.$this->_transferHeads[$i-1].'">'.$transferAry[$i].'</transferStat>'."\n";
  311. $this->_content .= $this->_indent.' </transfer>'."\n";
  312. }
  313. $this->_content .= $this->_indent.'</transfers>'."\n";
  314. }
  315. // transfer-details
  316. switch ($this->_type) {
  317. case "transfer":
  318. $this->_content .= $this->_indent.'<transfer name="'.$this->_transferID.'">'."\n";
  319. for ($i = 0; $i < $this->_transferIdCount; $i++)
  320. $this->_content .= $this->_indent.' <transferStat name="'.$this->_transferIds[$i].'">'.$this->_transferDetails[$this->_transferIds[$i]].'</transferStat>'."\n";
  321. $this->_content .= $this->_indent.'</transfer>'."\n";
  322. }
  323. // end document
  324. switch ($this->_type) {
  325. case "all":
  326. $this->_content .= '</tfbstats>'."\n";
  327. break;
  328. }
  329. // send content
  330. $this->_sendContent("text/xml", "stats.xml", $this->_compressed, $this->_attachment);
  331. }
  332. /**
  333. * This method sends stats as rss 0.91.
  334. */
  335. function _sendRSS() {
  336. // build content
  337. $this->_content = "<?xml version='1.0' ?>\n\n";
  338. $this->_content .= "<rss version=\"0.91\">\n";
  339. $this->_content .= " <channel>\n";
  340. $this->_content .= " <title>torrentflux Stats</title>\n";
  341. // server stats
  342. switch ($this->_type) {
  343. case "all":
  344. case "server":
  345. $this->_content .= " <item>\n";
  346. $this->_content .= " <title>Server Stats</title>\n";
  347. $this->_content .= " <description>";
  348. for ($i = 0; $i < $this->_serverIdCount; $i++) {
  349. $this->_content .= $this->_serverLabels[$i].": ".$this->_serverStats[$i];
  350. if ($i < ($this->_serverIdCount - 1))
  351. $this->_content .= " || ";
  352. }
  353. $this->_content .= " </description>\n";
  354. $this->_content .= " </item>\n";
  355. }
  356. // xfer stats
  357. switch ($this->_type) {
  358. case "all":
  359. case "xfer":
  360. $this->_content .= " <item>\n";
  361. $this->_content .= " <title>Xfer Stats</title>\n";
  362. $this->_content .= " <description>";
  363. for ($i = 0; $i < $this->_xferIdCount; $i++) {
  364. $this->_content .= $this->_xferLabels[$i].": ".$this->_xferStats[$i];
  365. if ($i < ($this->_xferIdCount - 1))
  366. $this->_content .= " || ";
  367. }
  368. $this->_content .= " </description>\n";
  369. $this->_content .= " </item>\n";
  370. }
  371. // user-list
  372. switch ($this->_type) {
  373. case "all":
  374. case "users":
  375. $this->_content .= " <item>\n";
  376. $this->_content .= " <title>Users</title>\n";
  377. $this->_content .= " <description>";
  378. for ($i = 0; $i < $this->_userCount; $i++) {
  379. $this->_content .= $this->_userList[$i][0].": ";
  380. for ($j = 1; $j <= $this->_userIdCount; $j++) {
  381. $this->_content .= $this->_userList[$i][$j];
  382. if ($j < ($this->_userIdCount - 1))
  383. $this->_content .= ", ";
  384. }
  385. if ($i < ($this->_userCount - 1))
  386. $this->_content .= " || ";
  387. }
  388. $this->_content .= " </description>\n";
  389. $this->_content .= " </item>\n";
  390. }
  391. // transfer-list
  392. switch ($this->_type) {
  393. case "all":
  394. case "transfers":
  395. foreach ($this->_transferList as $transferAry) {
  396. $this->_content .= " <item>\n";
  397. $this->_content .= " <title>Transfer: ".$transferAry[0]."</title>\n";
  398. $this->_content .= " <description>";
  399. $size = count($transferAry);
  400. for ($i = 1; $i < $size; $i++) {
  401. $this->_content .= $this->_transferHeads[$i-1].': '.$transferAry[$i];
  402. if ($i < ($size - 1))
  403. $this->_content .= " || ";
  404. }
  405. $this->_content .= " </description>\n";
  406. $this->_content .= " </item>\n";
  407. }
  408. }
  409. // transfer-details
  410. switch ($this->_type) {
  411. case "transfer":
  412. $this->_content .= " <item>\n";
  413. $this->_content .= " <title>Transfer: ".$this->_transferID."</title>\n";
  414. $this->_content .= " <description>";
  415. for ($i = 0; $i < $this->_transferIdCount; $i++) {
  416. $this->_content .= $this->_transferIds[$i].': '.$this->_transferDetails[$this->_transferIds[$i]];
  417. if ($i < ($this->_transferIdCount - 1))
  418. $this->_content .= " || ";
  419. }
  420. $this->_content .= " </description>\n";
  421. $this->_content .= " </item>\n";
  422. }
  423. // end document
  424. $this->_content .= " </channel>\n";
  425. $this->_content .= "</rss>";
  426. // send content
  427. $this->_sendContent("text/xml", "stats.xml", $this->_compressed, $this->_attachment);
  428. }
  429. /**
  430. * This method sends stats as txt.
  431. */
  432. function _sendTXT() {
  433. global $cfg;
  434. // build content
  435. $this->_content = "";
  436. // server stats
  437. switch ($this->_type) {
  438. case "all":
  439. case "server":
  440. if ($this->_header == 1) {
  441. for ($j = 0; $j < $this->_serverIdCount; $j++) {
  442. $this->_content .= $this->_serverLabels[$j];
  443. if ($j < ($this->_serverIdCount - 1))
  444. $this->_content .= $cfg['stats_txt_delim'];
  445. }
  446. $this->_content .= "\n";
  447. }
  448. for ($i = 0; $i < $this->_serverIdCount; $i++) {
  449. $this->_content .= $this->_serverStats[$i];
  450. if ($i < ($this->_serverIdCount - 1))
  451. $this->_content .= $cfg['stats_txt_delim'];
  452. }
  453. $this->_content .= "\n";
  454. }
  455. // xfer stats
  456. switch ($this->_type) {
  457. case "all":
  458. case "xfer":
  459. if ($this->_header == 1) {
  460. for ($j = 0; $j < $this->_xferIdCount; $j++) {
  461. $this->_content .= $this->_xferLabels[$j];
  462. if ($j < ($this->_xferIdCount - 1))
  463. $this->_content .= $cfg['stats_txt_delim'];
  464. }
  465. $this->_content .= "\n";
  466. }
  467. for ($i = 0; $i < $this->_xferIdCount; $i++) {
  468. $this->_content .= $this->_xferStats[$i];
  469. if ($i < ($this->_xferIdCount - 1))
  470. $this->_content .= $cfg['stats_txt_delim'];
  471. }
  472. $this->_content .= "\n";
  473. }
  474. // user-list
  475. switch ($this->_type) {
  476. case "all":
  477. case "users":
  478. if ($this->_header == 1) {
  479. $this->_content .= "name" . $cfg['stats_txt_delim'];
  480. for ($j = 0; $j < $this->_userIdCount; $j++) {
  481. $this->_content .= $this->_userIds[$j];
  482. if ($j < ($this->_userIdCount - 1))
  483. $this->_content .= $cfg['stats_txt_delim'];
  484. }
  485. $this->_content .= "\n";
  486. }
  487. for ($i = 0; $i < $this->_userCount; $i++) {
  488. $this->_content .= $this->_userList[$i][0].$cfg['stats_txt_delim'];
  489. for ($j = 1; $j <= $this->_userIdCount; $j++) {
  490. $this->_content .= $this->_userList[$i][$j];
  491. if ($j < ($this->_userIdCount - 1))
  492. $this->_content .= $cfg['stats_txt_delim'];
  493. }
  494. $this->_content .= "\n";
  495. }
  496. }
  497. // transfer-list
  498. switch ($this->_type) {
  499. case "all":
  500. case "transfers":
  501. if ($this->_header == 1) {
  502. $this->_content .= "Name" . $cfg['stats_txt_delim'];
  503. $sizeHead = count($this->_transferHeads);
  504. for ($j = 0; $j < $sizeHead; $j++) {
  505. $this->_content .= $this->_transferHeads[$j];
  506. if ($j < ($sizeHead - 1))
  507. $this->_content .= $cfg['stats_txt_delim'];
  508. }
  509. $this->_content .= "\n";
  510. }
  511. foreach ($this->_transferList as $transferAry) {
  512. $size = count($transferAry);
  513. for ($i = 0; $i < $size; $i++) {
  514. $this->_content .= $transferAry[$i];
  515. if ($i < ($size - 1))
  516. $this->_content .= $cfg['stats_txt_delim'];
  517. }
  518. $this->_content .= "\n";
  519. }
  520. }
  521. // transfer-details
  522. switch ($this->_type) {
  523. case "transfer":
  524. if ($this->_header == 1) {
  525. for ($j = 0; $j < $this->_transferIdCount; $j++) {
  526. $this->_content .= $this->_transferIds[$j];
  527. if ($j < ($this->_transferIdCount - 1))
  528. $this->_content .= $cfg['stats_txt_delim'];
  529. }
  530. $this->_content .= "\n";
  531. }
  532. for ($i = 0; $i < $this->_transferIdCount; $i++) {
  533. $this->_content .= $this->_transferDetails[$this->_transferIds[$i]];
  534. if ($i < ($this->_transferIdCount - 1))
  535. $this->_content .= $cfg['stats_txt_delim'];
  536. }
  537. $this->_content .= "\n";
  538. }
  539. // send content
  540. $this->_sendContent("text/plain", "stats.txt", $this->_compressed, $this->_attachment);
  541. }
  542. /**
  543. * init server stats
  544. * note : this can only be used after a call to update transfer-values in cfg-
  545. * array (eg by getTransferListArray)
  546. */
  547. function _initServerStats() {
  548. // init labels
  549. $this->_serverLabels = array(
  550. "Speed Down",
  551. "Speed Up",
  552. "Speed Total",
  553. "Connections",
  554. "Free Space",
  555. "Load",
  556. "Running",
  557. "Queued",
  558. "Speed Down (Percent)",
  559. "Speed Up (Percent)",
  560. "Drive Space (Percent)"
  561. );
  562. $this->_serverStats = getServerStats();
  563. }
  564. /**
  565. * init xfer stats
  566. * note : this can only be used after a call to update transfer-values in cfg-
  567. * array (eg by getTransferListArray)
  568. */
  569. function _initXferStats() {
  570. global $cfg;
  571. // init labels
  572. $this->_xferLabels = array(
  573. 'Server : '.$cfg['_TOTALXFER'],
  574. 'Server : '.$cfg['_MONTHXFER'],
  575. 'Server : '.$cfg['_WEEKXFER'],
  576. 'Server : '.$cfg['_DAYXFER'],
  577. 'User : '.$cfg['_TOTALXFER'],
  578. 'User : '.$cfg['_MONTHXFER'],
  579. 'User : '.$cfg['_WEEKXFER'],
  580. 'User : '.$cfg['_DAYXFER']
  581. );
  582. $this->_xferStats = Xfer::getStatsFormatted();
  583. }
  584. /**
  585. * init user stats
  586. */
  587. function _initUserStats() {
  588. global $cfg;
  589. $this->_userList = array();
  590. $this->_userCount = count($cfg['users']);
  591. for ($i = 0; $i < $this->_userCount; $i++) {
  592. $userAry = array();
  593. // name
  594. array_push($userAry, $cfg['users'][$i]);
  595. // state
  596. if (IsOnline($cfg['users'][$i]))
  597. array_push($userAry, "online");
  598. else
  599. array_push($userAry, "offline");
  600. // add user to list
  601. array_push($this->_userList, $userAry);
  602. }
  603. }
  604. /**
  605. * sends usage
  606. */
  607. function _sendUsage() {
  608. global $cfg;
  609. // content
  610. $url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
  611. $this->_content = '
  612. Params :
  613. "t" : type : optional, default is "'.$cfg['stats_default_type'].'"
  614. "all" : server + xfer + transfers + users
  615. "server" : server-stats
  616. "xfer" : xfer-stats
  617. "users" : users-stats
  618. "transfers" : transfer-stats
  619. "transfer" : transfer-stats of a single transfer. needs extra-param "i" with the name of the transfer
  620. "f" : format : optional, default is "'.$cfg['stats_default_format'].'"
  621. "xml" : new xml-formats, see xml-schemas in dir "xml"
  622. "rss" : rss 0.91
  623. "txt" : csv-formatted text
  624. "h" : header : optional, only used in txt-format, default is "'.$cfg['stats_default_header'].'"
  625. "0" : send header
  626. "1" : dont send header.
  627. "a" : send as attachment : optional, default is "'.$cfg['stats_default_attach'].'"
  628. "0" : dont send as attachment
  629. "1" : send as attachment
  630. "c" : send compressed (deflate) : optional, default is "'.$cfg['stats_default_compress'].'"
  631. "0" : dont send compressed
  632. "1" : send compressed (deflate)
  633. Examples :
  634. * '.$url.'?t=all&f=xml : all stats sent as xml
  635. * '.$url.'?t=server&f=xml&a=1 : server stats as xml sent as attachment
  636. * '.$url.'?t=transfers&f=xml&c=1 : transfer stats as xml sent compressed
  637. * '.$url.'?t=all&f=rss : all stats sent as rss
  638. * '.$url.'?t=all&f=txt&h=0 : all stats sent as txt without headers
  639. * '.$url.'?t=xfer&f=txt&a=1&c=1 : xfer stats as text sent as compressed attachment
  640. * '.$url.'?t=transfer&i=foo.torrent : transfer-stats of foo sent in default-format
  641. * '.$url.'?t=transfer&i=bar.torrent&f=xml : transfer-stats of bar sent as xml
  642. * '.$url.'?t=all&f=xml&username=admin&iamhim=seceret : all stats sent as xml. use auth-credentials "admin/seceret"
  643. * '.$url.'?t=all&f=rss&username=admin&md5pass=dc5c74cfa3ba35eb87cf597a60fa756c : all stats sent as rss. use auth-credentials "admin/dc5c74cfa3ba35eb87cf597a60fa756c"
  644. ';
  645. // send content
  646. $this->_sendContent("text/plain", "usage.txt", 0, 0);
  647. }
  648. }
  649. ?>