1
0

maketorrent.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* $Id: maketorrent.php 3082 2007-06-09 13:51:43Z danez $ */
  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. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // common functions
  23. require_once('inc/functions/functions.common.php');
  24. // dir functions
  25. require_once('inc/functions/functions.dir.php');
  26. // maketorrent
  27. require_once("inc/functions/functions.maketorrent.php");
  28. // is enabled ?
  29. if ($cfg["enable_maketorrent"] != 1) {
  30. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to use maketorrent");
  31. @error("maketorrent is disabled", "index.php?iid=index", "");
  32. }
  33. // check the needed bins
  34. // python
  35. if (@file_exists($cfg['pythonCmd']) !== true) {
  36. @error("Required binary could not be found", "", "",
  37. (
  38. ($cfg['isAdmin'])
  39. ? array(
  40. 'python is required for maketorrent',
  41. 'Specified python-binary does not exist: '.$cfg['pythonCmd'],
  42. 'Check Settings on Admin-Server-Settings Page')
  43. : array('Please contact an Admin')
  44. )
  45. );
  46. }
  47. /*******************************************************************************
  48. * create + page
  49. ******************************************************************************/
  50. // file + torrent vars
  51. $path = tfb_getRequestVarRaw('path');
  52. $torrent = "";
  53. if (!empty($path)) {
  54. $torrent = tfb_cleanFileName(StripFolders($path).".torrent");
  55. if ($torrent === false)
  56. @error("Invalid torrent-name", "", "", array($path));
  57. }
  58. // only valid dirs + entries with permission
  59. if (!((tfb_isValidPath($cfg["path"].$path)) &&
  60. (hasPermission($path, $cfg["user"], 'w')))) {
  61. AuditAction($cfg["constants"]["error"], "ILLEGAL MAKETORRENT: ".$cfg["user"]." tried to maketorrent with ".$path);
  62. @error("Illegal maketorrent. Action has been logged.", "", "");
  63. }
  64. // check if there is a var sent for client, if not use default
  65. $client = (isset($_REQUEST["client"])) ? tfb_getRequestVar('client') : $cfg["dir_maketorrent_default"];
  66. // client-generic vars
  67. $tfile = tfb_getRequestVar('torrent');
  68. $comment = tfb_getRequestVar('comments');
  69. $alert = (isset($_POST["alert"])) ? 1 : 0;
  70. // client-switch
  71. switch ($client) {
  72. default:
  73. case "tornado":
  74. $announce = (isset($_POST['announce'])) ? $_POST['announce'] : "http://";
  75. $ancelist = tfb_getRequestVar('announcelist');
  76. $private = @ ($_POST['Private'] == "Private") ? true : false;
  77. $dht = @ ($_POST['DHT'] == "DHT") ? true : false;
  78. $piece = tfb_getRequestVar('piecesize');
  79. break;
  80. case "mainline":
  81. $use_tracker = (isset($_POST['use_tracker'])) ? $_POST['use_tracker'] : 1;
  82. $tracker_name = (isset($_POST['tracker_name'])) ? $_POST['tracker_name'] : "http://";
  83. $piece = (isset($_POST['piecesize'])) ? $_POST['piecesize'] : 0;
  84. break;
  85. }
  86. /*******************************************************************************
  87. * create request
  88. ******************************************************************************/
  89. if (!empty($_REQUEST["create"])) {
  90. switch ($_REQUEST["create"]) {
  91. default:
  92. case "tornado":
  93. $onLoad = createTorrentTornado();
  94. break;
  95. case "mainline":
  96. $onLoad = createTorrentMainline();
  97. break;
  98. }
  99. }
  100. /*******************************************************************************
  101. * page
  102. ******************************************************************************/
  103. // init template-instance
  104. tmplInitializeInstance($cfg["theme"], "page.maketorrent.tmpl");
  105. // set vars
  106. $tmpl->setvar('path', $path);
  107. $tmpl->setvar('torrent', $torrent);
  108. $tmpl->setvar('comment', $comment);
  109. if (!empty($onLoad))
  110. $tmpl->setvar('onLoad', $onLoad);
  111. $tmpl->setvar('alert', $alert);
  112. // client-specific
  113. $tmpl->setvar('client', $client);
  114. $tmpl->setvar('client_select_action', $_SERVER['REQUEST_URI']);
  115. switch ($client) {
  116. default:
  117. case "tornado":
  118. $tmpl->setvar('form_action', $_SERVER['REQUEST_URI']."&create=tornado");
  119. $tmpl->setvar('is_private', ((!empty($private)) && ($private)) ? 1 : 0);
  120. $tmpl->setvar('announce', $announce);
  121. $tmpl->setvar('ancelist', $ancelist);
  122. $tmpl->setvar('dht', $dht);
  123. break;
  124. case "mainline":
  125. $tmpl->setvar('form_action', $_SERVER['REQUEST_URI']."&create=mainline");
  126. $tmpl->setvar('use_tracker', $use_tracker);
  127. $tmpl->setvar('tracker_name', $tracker_name);
  128. $tmpl->setvar('piecesize', $piece);
  129. break;
  130. }
  131. tmplSetTitleBar($cfg["pagetitle"]." - Torrent Maker", false);
  132. tmplSetIidVars();
  133. // parse template
  134. $tmpl->pparse();
  135. ?>