maketorrent.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* $Id: maketorrent.js 2874 2007-04-12 11:19:49Z munk $ */
  2. // fields
  3. var trackerState = 1;
  4. var anlst = "(optional) announce_list = list of tracker URLs<BR />\n";
  5. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;<i>url[,url...][|url[,url...]...]</i><BR />\n";
  6. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLs separated by commas are tried first<BR />\n";
  7. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;before URLs separated by the pipe is checked.<BR />\n";
  8. anlst += "Examples:<BR />\n";
  9. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;<i>http://a.com<strong>|</strong>http://b.com<strong>|</strong>http://c.com</i><BR />\n";
  10. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(tries <b>a-c</b> in order)<BR />\n";
  11. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;<i>http://a.com<strong>,</strong>http://b.com<strong>,</strong>http://c.com</i><BR />\n";
  12. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(tries <b>a-c</b> in a randomly selected order)<BR />\n";
  13. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;<i>http://a.com<strong>|</strong>http://b.com<strong>,</strong>http://c.com</i><BR />\n";
  14. anlst += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(tries <b>a</b> first, then tries <b>b-c</b> randomly)<BR />\n";
  15. var annce = "tracker announce URL.<BR /><BR />\n";
  16. annce += "Example:<BR />\n";
  17. annce += "&nbsp;&nbsp;&nbsp;&nbsp;<i>http://tracker.com/announce</i><BR />\n";
  18. var tornt = "torrent name to be saved as<BR /><BR />\n";
  19. tornt += "Example:<BR />\n";
  20. tornt += "&nbsp;&nbsp;&nbsp;&nbsp;<i>gnome-livecd-2.10.torrent</i><BR />\n";
  21. var comnt = "add a comment to your torrent file (optional)<BR />\n";
  22. comnt += "";
  23. var piece = "data piece size for torrent<BR />\n";
  24. piece += "power of 2 value to set the piece size to<BR />\n";
  25. piece += "(0 = automatic) (0 only option in this version)<BR />\n";
  26. var prvte = "private tracker support<BR />\n";
  27. prvte += "(disallows DHT if enabled)<BR />\n";
  28. var dhtbl = "DHT (Distributed Hash Table)<BR /><BR />\n";
  29. dhtbl += "can only be set abled if private flag is not set true<BR />\n";
  30. /**
  31. * doSubmit
  32. */
  33. function doSubmit(obj, client) {
  34. // Basic check to see if maketorrent is already running
  35. if (obj.value === "Creating...")
  36. return false;
  37. // Run some basic validation
  38. var valid = true;
  39. var tlength = document.maketorrent.torrent.value.length - 8;
  40. var torrent = document.maketorrent.torrent.value.substr(tlength);
  41. document.getElementById('output').innerHTML = "";
  42. document.getElementById('ttag').innerHTML = "";
  43. // torrent
  44. if (torrent !== ".torrent") {
  45. document.getElementById('ttag').innerHTML = "<b style=\"color: #990000;\">*</b>";
  46. document.getElementById('output').innerHTML += "<b style=\"color: #990000;\">* Torrent file must end in .torrent</b><BR />";
  47. valid = false;
  48. }
  49. // client-specific checks
  50. if (client === "tornado") {
  51. // tornado-special-checks
  52. document.getElementById('atag').innerHTML = "";
  53. // announce-url
  54. if (document.maketorrent.announce.value === "http://") {
  55. document.getElementById('atag').innerHTML = "<b style=\"color: #990000;\">*</b>";
  56. document.getElementById('output').innerHTML += "<b style=\"color: #990000;\">* Please enter a valid announce URL.</b><BR />";
  57. valid = false;
  58. }
  59. // For safety reason, let's force the property to false if it's disabled (private tracker)
  60. if (document.maketorrent.DHT.disabled) {
  61. document.maketorrent.DHT.checked = false;
  62. }
  63. } else {
  64. // mainline-special-checks
  65. document.getElementById('trtag').innerHTML = "";
  66. /*
  67. due to bugs (?) in mainlines maketorrent, this is disabled.
  68. if (trackerState == 1) {
  69. if ((document.maketorrent.tracker_name.value === "http://") || (document.maketorrent.tracker_name.value === "")) {
  70. document.getElementById('trtag').innerHTML = "<b style=\"color: #990000;\">*</b>";
  71. document.getElementById('output').innerHTML += "<b style=\"color: #990000;\">* Please enter a valid Tracker Name.</b><BR />";
  72. valid = false;
  73. }
  74. } else {
  75. if (document.maketorrent.tracker_name.value === "http://") {
  76. document.getElementById('trtag').innerHTML = "<b style=\"color: #990000;\">*</b>";
  77. document.getElementById('output').innerHTML += "<b style=\"color: #990000;\">* Please enter a valid Node (&lt;ip&gt;:&lt;port&gt;) or an empty to pull some nodes from your routing table.</b><BR />";
  78. valid = false;
  79. }
  80. }
  81. */
  82. if (trackerState == 1) {
  83. if ((document.maketorrent.tracker_name.value === "http://") || (document.maketorrent.tracker_name.value === "")) {
  84. document.getElementById('trtag').innerHTML = "<b style=\"color: #990000;\">*</b>";
  85. document.getElementById('output').innerHTML += "<b style=\"color: #990000;\">* Please enter a valid Tracker Name.</b><BR />";
  86. valid = false;
  87. }
  88. }
  89. }
  90. // If validation passed, submit form
  91. if (valid === true) {
  92. disableForm(client);
  93. toggleLayer('progress');
  94. document.getElementById('output').innerHTML += "<b>Creating torrent...</b><BR /><BR />";
  95. document.getElementById('output').innerHTML += "<i>* Note that larger folder/files will take some time to process,</i><BR />";
  96. document.getElementById('output').innerHTML += "<i>&nbsp;&nbsp;&nbsp;do not close the window until it has been completed.</i><BR /><BR />";
  97. document.getElementById('output').innerHTML += "&nbsp;&nbsp;&nbsp;When completed, the torrent will show in your list<BR />";
  98. document.getElementById('output').innerHTML += "&nbsp;&nbsp;&nbsp;and a download link will be provided.<BR />";
  99. return true;
  100. }
  101. return false;
  102. }
  103. /**
  104. * disableForm
  105. */
  106. function disableForm(client) {
  107. // Because of IE issue of disabling the submit button,
  108. // we change the text and don't allow resubmitting
  109. document.maketorrent.tsubmit.value = "Creating...";
  110. document.maketorrent.torrent.readOnly = true;
  111. if (client === "tornado")
  112. document.maketorrent.announce.readOnly = true;
  113. }
  114. /**
  115. * toggleDHT
  116. */
  117. function toggleDHT(dhtstatus) {
  118. document.maketorrent.DHT.disabled = dhtstatus;
  119. }
  120. /**
  121. * toggleTracker
  122. */
  123. function toggleTracker(tState) {
  124. /*
  125. trackerState = tState;
  126. if (trackerState == 1) {
  127. document.maketorrent.tracker_name.value = "http://";
  128. } else {
  129. document.maketorrent.tracker_name.value = "";
  130. }
  131. */
  132. trackerState = 1;
  133. }
  134. /**
  135. * toggleLayer
  136. */
  137. function toggleLayer(whichLayer) {
  138. if (document.getElementById) {
  139. // This is the way the standards work
  140. var style2 = document.getElementById(whichLayer).style;
  141. style2.display = style2.display ? "" : "block";
  142. } else if (document.all) {
  143. // This is the way old msie versions work
  144. var style2 = document.all[whichLayer].style;
  145. style2.display = style2.display ? "" : "block";
  146. } else if (document.layers) {
  147. // This is the way nn4 works
  148. var style2 = document.layers[whichLayer].style;
  149. style2.display = style2.display ? "" : "block";
  150. }
  151. }
  152. /**
  153. * completed
  154. */
  155. function completed(downpath, alertme, timetaken) {
  156. document.getElementById('output').innerHTML = "<b style='color: #005500;'>Creation completed!</b><BR />";
  157. document.getElementById('output').innerHTML += "Time taken: <i>" + timetaken + "</i><BR />";
  158. document.getElementById('output').innerHTML += "The new torrent has been added to your list.<BR /><BR />"
  159. document.getElementById('output').innerHTML += "You can download the <a style='font-weight: bold;' href='dispatcher.php?action=metafileDownload&transfer=" + downpath + "'>torrent here</a><BR />";
  160. if(alertme === 1)
  161. alert('Creation of torrent completed!');
  162. }
  163. /**
  164. * failed
  165. */
  166. function failed(downpath, alertme) {
  167. document.getElementById('output').innerHTML = "<b style='color: #AA0000;'>Creation failed!</b><BR /><BR />";
  168. document.getElementById('output').innerHTML += "An error occurred while trying to create the torrent.<BR />";
  169. if(alertme === 1)
  170. alert('Creation of torrent failed!');
  171. }