functions.compat.tf.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /* $Id: functions.compat.tf.php 2906 2007-04-15 10:45:37Z 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. * indexDispatch
  17. */
  18. function compat_tf_indexDispatch() {
  19. // dispatcher-functions
  20. require_once("inc/functions/functions.dispatcher.php");
  21. // start
  22. if (isset($_REQUEST['torrent']))
  23. dispatcher_startTransfer(urldecode(tfb_getRequestVar('torrent')));
  24. // stop
  25. if (isset($_REQUEST["kill_torrent"]))
  26. dispatcher_stopTransfer(urldecode(tfb_getRequestVar('kill_torrent')));
  27. // del
  28. if (isset($_REQUEST['delfile']))
  29. dispatcher_deleteTransfer(urldecode(tfb_getRequestVar('delfile')));
  30. // deQueue
  31. if (isset($_REQUEST["QEntry"]))
  32. dispatcher_deQueueTransfer(urldecode(tfb_getRequestVar('QEntry')));
  33. // get torrent via url
  34. if (isset($_REQUEST['url_upload']))
  35. dispatcher_processDownload(tfb_getRequestVarRaw('url_upload'), 'torrent');
  36. // file upload
  37. if ((isset($_FILES['upload_file'])) && (!empty($_FILES['upload_file']['name'])))
  38. compat_tf_processUpload();
  39. }
  40. /**
  41. * Function with which metafiles are uploaded and injected
  42. *
  43. * @deprecated
  44. */
  45. function compat_tf_processUpload() {
  46. global $cfg;
  47. $filename = "";
  48. $uploadMessages = array();
  49. if ((isset($_FILES['upload_file'])) && (!empty($_FILES['upload_file']['name']))) {
  50. $filename = stripslashes($_FILES['upload_file']['name']);
  51. $filename = tfb_cleanFileName($filename);
  52. if ($filename === false) {
  53. // invalid file
  54. array_push($uploadMessages, "The type of file you are uploading is not allowed.");
  55. array_push($uploadMessages, "\nvalid file-extensions: ");
  56. array_push($uploadMessages, $cfg["file_types_label"]);
  57. } else {
  58. // file is valid
  59. if (substr($filename, -5) == ".wget") {
  60. // is enabled ?
  61. if ($cfg["enable_wget"] == 0) {
  62. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to upload wget-file ".$filename);
  63. @error("wget is disabled", "", "");
  64. } else if ($cfg["enable_wget"] == 1) {
  65. if (!$cfg['isAdmin']) {
  66. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to upload wget-file ".$filename);
  67. @error("wget is disabled for users", "", "");
  68. }
  69. }
  70. } else if (substr($filename, -4) == ".nzb") {
  71. // is enabled ?
  72. if ($cfg["enable_nzbperl"] == 0) {
  73. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to upload nzb-file ".$filename);
  74. @error("nzbperl is disabled", "", "");
  75. } else if ($cfg["enable_nzbperl"] == 1) {
  76. if (!$cfg['isAdmin']) {
  77. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to upload nzb-file ".$filename);
  78. @error("nzbperl is disabled for users", "", "");
  79. }
  80. }
  81. }
  82. if ($_FILES['upload_file']['size'] <= $cfg["upload_limit"] && $_FILES['upload_file']['size'] > 0) {
  83. //FILE IS BEING UPLOADED
  84. if (@is_file($cfg["transfer_file_path"].$filename)) {
  85. // Error
  86. array_push($uploadMessages, "the file ".$filename." already exists on the server.");
  87. } else {
  88. if (@move_uploaded_file($_FILES['upload_file']['tmp_name'], $cfg["transfer_file_path"].$filename)) {
  89. @chmod($cfg["transfer_file_path"].$filename, 0644);
  90. AuditAction($cfg["constants"]["file_upload"], $filename);
  91. // inject
  92. injectTransfer($filename);
  93. // instant action ?
  94. $actionId = tfb_getRequestVar('aid');
  95. if ($actionId > 1) {
  96. $ch = ClientHandler::getInstance(getTransferClient($filename));
  97. switch ($actionId) {
  98. case 3:
  99. $ch->start($filename, false, true);
  100. break;
  101. case 2:
  102. $ch->start($filename, false, false);
  103. break;
  104. }
  105. if (count($ch->messages) > 0)
  106. $uploadMessages = array_merge($uploadMessages, $ch->messages);
  107. }
  108. } else {
  109. array_push($uploadMessages, "File not uploaded, file could not be found or could not be moved: ".$cfg["transfer_file_path"].$filename);
  110. }
  111. }
  112. } else {
  113. array_push($uploadMessages, "File not uploaded, file size limit is ".$cfg["upload_limit"].". file has ".$_FILES['upload_file']['size']);
  114. }
  115. }
  116. }
  117. if (count($uploadMessages) > 0) {
  118. AuditAction($cfg["constants"]["error"], $cfg["constants"]["file_upload"]." :: ".$filename);
  119. @error("There were Problems", "", "", $uploadMessages);
  120. }
  121. }
  122. ?>