ClientHandler.azureus.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. /* $Id: ClientHandler.azureus.php 3223 2007-09-22 16:58:14Z 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. * class ClientHandler for azureus-client
  17. */
  18. class ClientHandlerAzureus extends ClientHandler
  19. {
  20. // =========================================================================
  21. // ctor
  22. // =========================================================================
  23. /**
  24. * ctor
  25. */
  26. function ClientHandlerAzureus() {
  27. $this->type = "torrent";
  28. $this->client = "azureus";
  29. $this->binSystem = "java";
  30. $this->binSocket = "java";
  31. $this->binClient = "java";
  32. }
  33. // =========================================================================
  34. // public methods
  35. // =========================================================================
  36. /**
  37. * starts a client
  38. *
  39. * @param $transfer name of the transfer
  40. * @param $interactive (boolean) : is this a interactive startup with dialog ?
  41. * @param $enqueue (boolean) : enqueue ?
  42. */
  43. function start($transfer, $interactive = false, $enqueue = false) {
  44. global $cfg;
  45. // set vars
  46. $this->_setVarsForTransfer($transfer);
  47. // log
  48. $this->logMessage($this->client."-start : ".$transfer."\n", true);
  49. // FluAzu
  50. require_once("inc/classes/FluAzu.php");
  51. // do azureus special-pre-start-checks
  52. // check to see if fluazu is running
  53. if (!FluAzu::isRunning()) {
  54. $this->state = CLIENTHANDLER_STATE_ERROR;
  55. $msg = "fluazu not running, cannot start transfer ".$transfer;
  56. AuditAction($cfg["constants"]["error"], $msg);
  57. $this->logMessage($msg."\n", true);
  58. array_push($this->messages, $msg);
  59. // write error to stat
  60. $sf = new StatFile($this->transfer, $this->owner);
  61. $sf->time_left = 'Error: fluazu down';
  62. $sf->write();
  63. // return
  64. return false;
  65. }
  66. // init starting of client
  67. $this->_init($interactive, $enqueue, true, false);
  68. // only continue if init succeeded (skip start / error)
  69. if ($this->state != CLIENTHANDLER_STATE_READY) {
  70. if ($this->state == CLIENTHANDLER_STATE_ERROR) {
  71. $msg = "Error after init (".$transfer.",".$interactive.",".$enqueue.",true,".$cfg['enable_sharekill'].")";
  72. array_push($this->messages , $msg);
  73. $this->logMessage($msg."\n", true);
  74. }
  75. // return
  76. return false;
  77. }
  78. // build the command-string
  79. $content = $cfg['user']."\n";
  80. $content .= $this->savepath."\n";
  81. $content .= $this->rate."\n";
  82. $content .= $this->drate."\n";
  83. $content .= $this->maxuploads."\n";
  84. $content .= $this->superseeder."\n";
  85. $content .= $this->runtime."\n";
  86. $content .= $this->sharekill_param."\n";
  87. $content .= $this->minport."\n";
  88. $content .= $this->maxport."\n";
  89. $content .= $this->maxcons."\n";
  90. $content .= $this->rerequest;
  91. $this->command = "echo -e ".tfb_shellencode($content)." > ".tfb_shellencode($cfg["path"].'.fluazu/run/'.$transfer);
  92. $this->command .= " && ";
  93. $this->command .= "echo r > ".tfb_shellencode($cfg["path"].'.fluazu/fluazu.cmd');
  94. // start the client
  95. $this->_start();
  96. }
  97. /**
  98. * stops a client
  99. *
  100. * @param $transfer name of the transfer
  101. * @param $kill kill-param (optional)
  102. * @param $transferPid transfer Pid (optional)
  103. */
  104. function stop($transfer, $kill = false, $transferPid = 0) {
  105. // set vars
  106. $this->_setVarsForTransfer($transfer);
  107. // FluAzu
  108. require_once("inc/classes/FluAzu.php");
  109. // only if fluazu running and transfer exists in fluazu
  110. if (!FluAzu::isRunning()) {
  111. array_push($this->messages , "fluazu not running, cannot stop transfer ".$transfer);
  112. return false;
  113. }
  114. if (!FluAzu::transferExists($transfer)) {
  115. array_push($this->messages , "transfer ".$transfer." does not exist in fluazu, cannot stop it");
  116. return false;
  117. }
  118. // stop the client
  119. $this->_stop($kill, $transferPid);
  120. }
  121. /**
  122. * deletes a transfer
  123. *
  124. * @param $transfer name of the transfer
  125. * @return boolean of success
  126. */
  127. function delete($transfer) {
  128. // set vars
  129. $this->_setVarsForTransfer($transfer);
  130. // FluAzu
  131. require_once("inc/classes/FluAzu.php");
  132. // only if transfer exists in fluazu
  133. if (FluAzu::transferExists($transfer)) {
  134. // only if fluazu running
  135. if (!FluAzu::isRunning()) {
  136. array_push($this->messages , "fluazu not running, cannot delete transfer ".$transfer);
  137. return false;
  138. }
  139. // remove from azu
  140. if (!FluAzu::delTransfer($transfer)) {
  141. array_push($this->messages , $this->client.": error when deleting transfer ".$transfer." :");
  142. $this->messages = array_merge($this->messages, FluAzu::getMessages());
  143. return false;
  144. }
  145. }
  146. // delete
  147. return $this->_delete();
  148. }
  149. /**
  150. * gets current transfer-vals of a transfer
  151. *
  152. * @param $transfer
  153. * @return array with downtotal and uptotal
  154. */
  155. function getTransferCurrent($transfer) {
  156. global $db, $transfers;
  157. $retVal = array();
  158. // transfer from stat-file
  159. $sf = new StatFile($transfer);
  160. $retVal["uptotal"] = $sf->uptotal;
  161. $retVal["downtotal"] = $sf->downtotal;
  162. // transfer from db
  163. $torrentId = getTransferHash($transfer);
  164. $sql = "SELECT uptotal,downtotal FROM tf_transfer_totals WHERE tid = ".$db->qstr($torrentId);
  165. $result = $db->Execute($sql);
  166. $row = $result->FetchRow();
  167. if (!empty($row)) {
  168. $retVal["uptotal"] -= $row["uptotal"];
  169. $retVal["downtotal"] -= $row["downtotal"];
  170. }
  171. return $retVal;
  172. }
  173. /**
  174. * gets current transfer-vals of a transfer. optimized version
  175. *
  176. * @param $transfer
  177. * @param $tid of the transfer
  178. * @param $sfu stat-file-uptotal of the transfer
  179. * @param $sfd stat-file-downtotal of the transfer
  180. * @return array with downtotal and uptotal
  181. */
  182. function getTransferCurrentOP($transfer, $tid, $sfu, $sfd) {
  183. global $transfers;
  184. $retVal = array();
  185. $retVal["uptotal"] = (isset($transfers['totals'][$tid]['uptotal']))
  186. ? $sfu - $transfers['totals'][$tid]['uptotal']
  187. : $sfu;
  188. $retVal["downtotal"] = (isset($transfers['totals'][$tid]['downtotal']))
  189. ? $sfd - $transfers['totals'][$tid]['downtotal']
  190. : $sfd;
  191. return $retVal;
  192. }
  193. /**
  194. * gets total transfer-vals of a transfer
  195. *
  196. * @param $transfer
  197. * @return array with downtotal and uptotal
  198. */
  199. function getTransferTotal($transfer) {
  200. global $transfers;
  201. // transfer from stat-file
  202. $sf = new StatFile($transfer);
  203. return array("uptotal" => $sf->uptotal, "downtotal" => $sf->downtotal);
  204. }
  205. /**
  206. * gets total transfer-vals of a transfer. optimized version
  207. *
  208. * @param $transfer
  209. * @param $tid of the transfer
  210. * @param $sfu stat-file-uptotal of the transfer
  211. * @param $sfd stat-file-downtotal of the transfer
  212. * @return array with downtotal and uptotal
  213. */
  214. function getTransferTotalOP($transfer, $tid, $sfu, $sfd) {
  215. return array("uptotal" => $sfu, "downtotal" => $sfd);
  216. }
  217. /**
  218. * set upload rate of a transfer
  219. *
  220. * @param $transfer
  221. * @param $uprate
  222. * @param $autosend
  223. */
  224. function setRateUpload($transfer, $uprate, $autosend = false) {
  225. // set rate-field
  226. $this->rate = $uprate;
  227. // add command
  228. CommandHandler::add($transfer, "u".$uprate);
  229. // send command to client
  230. if ($autosend)
  231. CommandHandler::send($transfer);
  232. }
  233. /**
  234. * set download rate of a transfer
  235. *
  236. * @param $transfer
  237. * @param $downrate
  238. * @param $autosend
  239. */
  240. function setRateDownload($transfer, $downrate, $autosend = false) {
  241. // set rate-field
  242. $this->drate = $downrate;
  243. // add command
  244. CommandHandler::add($transfer, "d".$downrate);
  245. // send command to client
  246. if ($autosend)
  247. CommandHandler::send($transfer);
  248. }
  249. /**
  250. * set runtime of a transfer
  251. *
  252. * @param $transfer
  253. * @param $runtime
  254. * @param $autosend
  255. * @return boolean
  256. */
  257. function setRuntime($transfer, $runtime, $autosend = false) {
  258. // set runtime-field
  259. $this->runtime = $runtime;
  260. // add command
  261. CommandHandler::add($transfer, "r".(($this->runtime == "True") ? "1" : "0"));
  262. // send command to client
  263. if ($autosend)
  264. CommandHandler::send($transfer);
  265. }
  266. /**
  267. * set sharekill of a transfer
  268. *
  269. * @param $transfer
  270. * @param $sharekill
  271. * @param $autosend
  272. * @return boolean
  273. */
  274. function setSharekill($transfer, $sharekill, $autosend = false) {
  275. // set sharekill
  276. $this->sharekill = $sharekill;
  277. // add command
  278. CommandHandler::add($transfer, "s".$this->sharekill);
  279. // send command to client
  280. if ($autosend)
  281. CommandHandler::send($transfer);
  282. // return
  283. return true;
  284. }
  285. }
  286. ?>