1
0

ClientHandler.nzbperl.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /* $Id: ClientHandler.nzbperl.php 3298 2007-12-04 22:42:29Z 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 nzbperl-client
  17. */
  18. class ClientHandlerNzbperl extends ClientHandler
  19. {
  20. // public fields
  21. // nzbperl bin
  22. var $nzbbin = "";
  23. // =====================================================================
  24. // ctor
  25. // =====================================================================
  26. /**
  27. * ctor
  28. */
  29. function ClientHandlerNzbperl() {
  30. global $cfg;
  31. $this->type = "nzb";
  32. $this->client = "nzbperl";
  33. $this->binSystem = "perl";
  34. $this->binSocket = "perl";
  35. $this->binClient = "tfnzbperl.pl";
  36. $this->nzbbin = $cfg["docroot"]."bin/clients/nzbperl/tfnzbperl.pl";
  37. }
  38. // =====================================================================
  39. // Public Methods
  40. // =====================================================================
  41. /**
  42. * starts a client
  43. *
  44. * @param $transfer name of the transfer
  45. * @param $interactive (boolean) : is this a interactive startup with dialog ?
  46. * @param $enqueue (boolean) : enqueue ?
  47. */
  48. function start($transfer, $interactive = false, $enqueue = false) {
  49. global $cfg;
  50. // set vars
  51. $this->_setVarsForTransfer($transfer);
  52. // log
  53. $this->logMessage($this->client."-start : ".$transfer."\n", true);
  54. // do nzbperl special-pre-start-checks
  55. // check to see if the path to the nzbperl script is valid
  56. if (!is_file($this->nzbbin)) {
  57. $this->state = CLIENTHANDLER_STATE_ERROR;
  58. $msg = "path for tfnzbperl.pl is not valid";
  59. AuditAction($cfg["constants"]["error"], $msg);
  60. $this->logMessage($msg."\n", true);
  61. array_push($this->messages, $msg);
  62. array_push($this->messages, "nzbbin : ".$this->nzbbin);
  63. // write error to stat
  64. $sf = new StatFile($this->transfer, $this->owner);
  65. $sf->time_left = 'Error';
  66. $sf->write();
  67. // return
  68. return false;
  69. }
  70. // init starting of client
  71. $this->_init($interactive, $enqueue, false, false);
  72. // only continue if init succeeded (skip start / error)
  73. if ($this->state != CLIENTHANDLER_STATE_READY) {
  74. if ($this->state == CLIENTHANDLER_STATE_ERROR) {
  75. $msg = "Error after init (".$transfer.",".$interactive.",".$enqueue.",true,".$cfg['enable_sharekill'].")";
  76. array_push($this->messages , $msg);
  77. $this->logMessage($msg."\n", true);
  78. }
  79. // return
  80. return false;
  81. }
  82. // Build Command String (do not change order of last args !)
  83. $this->command = "cd ".tfb_shellencode($this->savepath).";";
  84. $this->command .= " HOME=".tfb_shellencode(substr($cfg["path"], 0, -1));
  85. $this->command .= "; export HOME;";
  86. $this->command .= $this->umask;
  87. $this->command .= " nohup ";
  88. $this->command .= $this->nice;
  89. $this->command .= $cfg['perlCmd'];
  90. $this->command .= " -I ".tfb_shellencode($cfg["docroot"]."bin/lib");
  91. $this->command .= " ".tfb_shellencode($this->nzbbin);
  92. $this->command .= " --conn ".tfb_shellencode($cfg['nzbperl_conn']);
  93. $this->command .= " --uudeview ".tfb_shellencode($cfg["bin_uudeview"]);
  94. $this->command .= ($cfg['nzbperl_badAction'])
  95. ? " --insane --keepbrokenbin"
  96. : " --dropbad";
  97. switch ($cfg['nzbperl_create']) {
  98. case 1:
  99. $this->command .= " --dlcreate";
  100. break;
  101. case 2:
  102. $this->command .= " --dlcreategrp";
  103. break;
  104. }
  105. $this->command .= " --dthreadct ".tfb_shellencode($cfg['nzbperl_threads']);
  106. $this->command .= " --speed ".tfb_shellencode($this->drate);
  107. $this->command .= " --server ".tfb_shellencode($cfg['nzbperl_server']);
  108. if ($cfg['nzbperl_user'] != "") {
  109. $this->command .= " --user ".tfb_shellencode($cfg['nzbperl_user']);
  110. $this->command .= " --pw ".tfb_shellencode($cfg['nzbperl_pw']);
  111. }
  112. if (strlen($cfg["nzbperl_options"]) > 0)
  113. $this->command .= " ".$cfg['nzbperl_options'];
  114. // do NOT change anything below (not even order)
  115. $this->command .= " --dlpath ".tfb_shellencode($this->savepath);
  116. $this->command .= " --tfuser ".tfb_shellencode($this->owner);
  117. $this->command .= " ".tfb_shellencode($this->transferFilePath);
  118. $this->command .= " 1>> ".tfb_shellencode($this->transferFilePath.".log");
  119. $this->command .= " 2>> ".tfb_shellencode($this->transferFilePath.".log");
  120. $this->command .= " &";
  121. // state
  122. $this->state = CLIENTHANDLER_STATE_READY;
  123. // Start the client
  124. $this->_start();
  125. }
  126. /**
  127. * set download rate of a transfer
  128. *
  129. * @param $transfer
  130. * @param $downrate
  131. * @param $autosend
  132. */
  133. function setRateDownload($transfer, $downrate, $autosend = false) {
  134. // set rate-field
  135. $this->drate = $downrate;
  136. // add command
  137. CommandHandler::add($transfer, "d".$downrate);
  138. // send command to client
  139. if ($autosend)
  140. CommandHandler::send($transfer);
  141. }
  142. /**
  143. * sets fields from default-vals
  144. *
  145. * @param $transfer
  146. */
  147. function settingsDefault($transfer = "") {
  148. global $cfg;
  149. // transfer vars
  150. if ($transfer != "")
  151. $this->_setVarsForTransfer($transfer);
  152. // common vars
  153. $this->hash = getTransferHash($this->transfer);
  154. $this->datapath = getTransferDatapath($this->transfer);
  155. $this->savepath = getTransferSavepath($this->transfer);
  156. $this->running = 0;
  157. $this->rate = 0;
  158. $this->drate = $cfg["nzbperl_rate"];
  159. $this->maxuploads = 1;
  160. $this->superseeder = 0;
  161. $this->runtime = "True";
  162. $this->sharekill = 0;
  163. $this->minport = 1;
  164. $this->maxport = 65535;
  165. $this->maxcons = $cfg["nzbperl_conn"];
  166. $this->rerequest = 1;
  167. }
  168. }
  169. ?>