PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/ban_client.php

https://github.com/delete66/sikevux-s-tracker
PHP | 357 lines | 319 code | 4 blank | 34 comment | 38 complexity | 7ac87aa22493b078cf8bea9bcc4f4c0c MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // *****************************************************************
  3. // Version: 1.1
  4. // *****************************************************************
  5. //
  6. // Filename: ban_client.php
  7. // Parent: details.php
  8. // Requires: bittorrent.php, banned_clients.php
  9. // Author: Petr1fied
  10. // Date: 2007-06-17
  11. // Updated: 2007-07-01
  12. //
  13. // Usage:
  14. // - Bans specific BitTorrent Clients, both individual versions and
  15. // all versions of a client can be banned.
  16. //
  17. // ####### HISTORY ################################################
  18. //
  19. // 1.0 2007-06-17 - Petr1fied - Intital development.
  20. // 1.1 2007-07-01 - Petr1fied - Ported to TBDev and changed to be
  21. // SQL free.
  22. //
  23. // *****************************************************************
  24. require_once ("include/bittorrent.php");
  25. require_once("include/bbcode_functions.php");
  26. require_once("include/user_functions.php");
  27. dbconn(false);
  28. maxcoder();
  29. if(!logged_in())
  30. {
  31. header("HTTP/1.0 404 Not Found");
  32. // moddifed logginorreturn by retro//Remember to change the following line to match your server
  33. print("<html><h1>Not Found</h1><p>The requested URL /{$_SERVER['PHP_SELF']} was not found on this server.</p><hr /><address>Apache/1.1.11 (xxxxx) Server at ".$_SERVER['SERVER_NAME']." Port 80</address></body></html>\n");
  34. die();
  35. }
  36. stdhead('Ban BitTorrent Client');
  37. if (get_user_class() < UC_ADMINISTRATOR)
  38. {
  39. stdmsg(ERROR,"You're not authorised to view this page");
  40. stdfoot();
  41. exit;
  42. }
  43. else
  44. {
  45. (isset($_GET["agent"]) ? $agent=urldecode($_GET["agent"]) : $agent="");
  46. (isset($_GET["peer_id"]) ? $peer_id=urldecode($_GET["peer_id"]) : $peer_id="");
  47. (isset($_GET["returnto"]) ? $url=urldecode($_GET["returnto"]) : $url="index.php");
  48. (isset($_POST["confirm"]) ? $confirm=$_POST["confirm"] : $confirm="");
  49. (isset($_POST["reason"]) ? $reason=$_POST["reason"] : $reason="");
  50. (isset($_POST["banall"]) ? $banall="yes" : $banall="no");
  51. $peer_id_ascii=hex2bin($peer_id);
  52. $client=getagent($agent, $peer_id);
  53. $filename = "include/banned_clients.txt";
  54. if (filesize($filename)==0 || !file_exists($filename))
  55. $banned_clients=array();
  56. else
  57. {
  58. $handle = fopen($filename, "r");
  59. $banned_clients = unserialize(fread($handle, filesize($filename)));
  60. fclose($handle);
  61. }
  62. if($_POST["confirm"])
  63. {
  64. if($confirm=="Yes" && $reason!="")
  65. {
  66. $banned=0;
  67. foreach($banned_clients as $k => $v)
  68. {
  69. if(substr($peer_id, 0, (($banall=="yes") ? 6 : 16 )) == $v["peer_id"])
  70. $banned=1;
  71. }
  72. if($banned==1)
  73. {
  74. stdmsg(ERROR,"This client is already banned");
  75. stdfoot();
  76. exit;
  77. }
  78. if(empty($banned_clients))
  79. {
  80. if($banall=="yes")
  81. {
  82. $client=substr($client, 0, stripos($client, " "))." (All versions)";
  83. $banned_clients[1]=array('peer_id' => substr($peer_id, 0, 6), 'peer_id_ascii' => substr($peer_id_ascii, 0, 3), 'user_agent' => 'N/A', 'client_name' => $client, 'reason' => $reason);
  84. }
  85. else
  86. $banned_clients[1]=array('peer_id' => substr($peer_id, 0, 16), 'peer_id_ascii' => substr($peer_id_ascii, 0, 8), 'user_agent' => $agent, 'client_name' => $client, 'reason' => $reason);
  87. }
  88. else
  89. {
  90. if($banall=="yes")
  91. {
  92. $client=substr($client, 0, stripos($client, " "))." (All versions)";
  93. $banned_clients[]=array('peer_id' => substr($peer_id, 0, 6), 'peer_id_ascii' => substr($peer_id_ascii, 0, 3), 'user_agent' => 'N/A', 'client_name' => $client, 'reason' => $reason);
  94. }
  95. else
  96. $banned_clients[]=array('peer_id' => substr($peer_id, 0, 16), 'peer_id_ascii' => substr($peer_id_ascii, 0, 8), 'user_agent' => $agent, 'client_name' => $client, 'reason' => $reason);
  97. }
  98. $data=serialize($banned_clients);
  99. $fd = fopen($filename, "w") or die("Can't update $filename, please CHMOD it to 777");
  100. fwrite($fd,$data) or die("Can't save file");
  101. fclose($fd);
  102. stdmsg("Success","This client has been added to the banned list");
  103. print("<center><a href='$url'>Return</a></center>");
  104. stdfoot();
  105. exit();
  106. }
  107. elseif($confirm=="No")
  108. {
  109. redirect($url);
  110. }
  111. else
  112. {
  113. stdmsg(ERROR,"You must enter a reason!");
  114. stdfoot();
  115. exit();
  116. }
  117. }
  118. ?>
  119. <p align='center'>By visiting this page you are indicating that
  120. you want to ban the following client:</p>
  121. <form method='post' name='action'>
  122. <table align='center' width=70%>
  123. <tr>
  124. <td class='header' align='center'><strong>Client</strong></td>
  125. <td class='header' align='center'><strong>User Agent</strong></td>
  126. <td class='header' align='center'><strong>peer_id</strong></td>
  127. <td class='header' align='center'><strong>peer_id ascii</strong></td>
  128. </tr>
  129. <tr>
  130. <td class='lista' align='center'><?=$client?></td>
  131. <td class='lista' align='center'><?=$agent?></td>
  132. <td class='lista' align='center'><?=$peer_id?></td>
  133. <td class='lista' align='center'><?=$peer_id_ascii?></td>
  134. </tr>
  135. <tr>
  136. <td class='lista' align='right'><strong>Reason</strong></td>
  137. <td class='lista' colspan='3'><input type='text' name='reason' value='' size='70' maxlength='255'>
  138. &nbsp;&nbsp;&nbsp;<strong>Ban all versions?</strong><input type='checkbox' name='banall'></td>
  139. </tr>
  140. <tr>
  141. <td class='block' colspan='4'>&nbsp</td>
  142. <tr>
  143. </table>
  144. <p align='center'>Are you sure you want to do this? (you will receive no further confirmation).</p>
  145. <center>
  146. <input type='submit' name='confirm' value='Yes'>&nbsp;<input type='submit' name='confirm' value='No'>
  147. <center></form><br />
  148. <?php
  149. }
  150. stdfoot();
  151. function hex2bin ($input, $assume_safe=true)
  152. {
  153. if ($assume_safe !== true && ! ((strlen($input) % 2) === 0 || preg_match ('/^[0-9a-f]+$/i', $input)))
  154. return "";
  155. return pack('H*', $input );
  156. }
  157. #========================================
  158. #getAgent function by deliopoulos
  159. #========================================
  160. function StdDecodePeerId($id_data, $id_name){
  161. $version_str = "";
  162. for ($i=0; $i<=strlen($id_data); $i++){
  163. $c = $id_data[$i];
  164. if ($id_name=="BitTornado" || $id_name=="ABC") {
  165. if ($c!='-' && ctype_digit($c)) $version_str .= "$c.";
  166. elseif ($c!='-' && ctype_alpha($c)) $version_str .= (ord($c)-55).".";
  167. else break;
  168. }
  169. elseif($id_name=="BitComet"||$id_name=="BitBuddy"||$id_name=="Lphant"||$id_name=="BitPump"||$id_name=="BitTorrent Plus! v2") {
  170. if ($c != '-' && ctype_alnum($c)){
  171. $version_str .= "$c";
  172. if($i==0) $version_str = intval($version_str) .".";
  173. }
  174. else{
  175. $version_str .= ".";
  176. break;
  177. }
  178. }
  179. else {
  180. if ($c != '-' && ctype_alnum($c)) $version_str .= "$c.";
  181. else break;
  182. }
  183. }
  184. $version_str = substr($version_str,0,strlen($version_str)-1);
  185. return "$id_name $version_str";
  186. }
  187. function MainlineDecodePeerId($id_data, $id_name){
  188. $version_str = "";
  189. for ($i=0; $i<=strlen($id_data); $i++){
  190. $c = $id_data[$i];
  191. if ($c != '-' && ctype_alnum($c)) $version_str .= "$c.";
  192. }
  193. $version_str = substr($version_str,0,strlen($version_str)-1);
  194. return "$id_name $version_str";
  195. }
  196. function DecodeVersionString ($ver_data, $id_name){
  197. $version_str = "";
  198. $version_str .= intval(ord($ver_data[0]) + 0).".";
  199. $version_str .= intval(ord($ver_data[1])/10 + 0);
  200. $version_str .= intval(ord($ver_data[1])%10 + 0);
  201. return "$id_name $version_str";
  202. }
  203. function getagent($httpagent, $peer_id="") {
  204. if($peer_id!="") $peer_id=hex2bin($peer_id);
  205. if(substr($peer_id,0,3)=='-AX') return StdDecodePeerId(substr($peer_id,4,4),"BitPump"); # AnalogX BitPump
  206. if(substr($peer_id,0,3)=='-BB') return StdDecodePeerId(substr($peer_id,3,5),"BitBuddy"); # BitBuddy
  207. if(substr($peer_id,0,3)=='-BC') return StdDecodePeerId(substr($peer_id,4,4),"BitComet"); # BitComet
  208. if(substr($peer_id,0,3)=='-BS') return StdDecodePeerId(substr($peer_id,3,7),"BTSlave"); # BTSlave
  209. if(substr($peer_id,0,3)=='-BX') return StdDecodePeerId(substr($peer_id,3,7),"BittorrentX"); # BittorrentX
  210. if(substr($peer_id,0,3)=='-CT') return "Ctorrent $peer_id[3].$peer_id[4].$peer_id[6]"; # CTorrent
  211. if(substr($peer_id,0,3)=='-KT') return StdDecodePeerId(substr($peer_id,3,7),"KTorrent"); # KTorrent
  212. if(substr($peer_id,0,3)=='-LT') return StdDecodePeerId(substr($peer_id,3,7),"libtorrent"); # libtorrent
  213. if(substr($peer_id,0,3)=='-LP') return StdDecodePeerId(substr($peer_id,4,4),"Lphant"); # Lphant
  214. if(substr($peer_id,0,3)=='-MP') return StdDecodePeerId(substr($peer_id,3,7),"MooPolice"); # MooPolice
  215. if(substr($peer_id,0,3)=='-MT') return StdDecodePeerId(substr($peer_id,3,7),"Moonlight"); # MoonlightTorrent
  216. if(substr($peer_id,0,3)=='-PO') return StdDecodePeerId(substr($peer_id,3,7),"PO Client"); #unidentified clients with versions
  217. if(substr($peer_id,0,3)=='-QT') return StdDecodePeerId(substr($peer_id,3,7),"Qt 4 Torrent"); # Qt 4 Torrent
  218. if(substr($peer_id,0,3)=='-RT') return StdDecodePeerId(substr($peer_id,3,7),"Retriever"); # Retriever
  219. if(substr($peer_id,0,3)=='-S2') return StdDecodePeerId(substr($peer_id,3,7),"S2 Client"); #unidentified clients with versions
  220. if(substr($peer_id,0,3)=='-SB') return StdDecodePeerId(substr($peer_id,3,7),"Swiftbit"); # Swiftbit
  221. if(substr($peer_id,0,3)=='-SN') return StdDecodePeerId(substr($peer_id,3,7),"ShareNet"); # ShareNet
  222. if(substr($peer_id,0,3)=='-SS') return StdDecodePeerId(substr($peer_id,3,7),"SwarmScope"); # SwarmScope
  223. if(substr($peer_id,0,3)=='-SZ') return StdDecodePeerId(substr($peer_id,3,7),"Shareaza"); # Shareaza
  224. if(preg_match("/^RAZA ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $httpagent, $matches)) return "Shareaza $matches[1]";
  225. if(substr($peer_id,0,3)=='-TN') return StdDecodePeerId(substr($peer_id,3,7),"Torrent.NET"); # Torrent.NET
  226. if(substr($peer_id,0,3)=='-TR') return StdDecodePeerId(substr($peer_id,3,7),"Transmission"); # Transmission
  227. if(substr($peer_id,0,3)=='-TS') return StdDecodePeerId(substr($peer_id,3,7),"TorrentStorm"); # Torrentstorm
  228. if(substr($peer_id,0,3)=='-UR') return StdDecodePeerId(substr($peer_id,3,7),"UR Client"); # unidentified clients with versions
  229. if(substr($peer_id,0,3)=='-UT') return StdDecodePeerId(substr($peer_id,3,7),"uTorrent"); # uTorrent
  230. if(substr($peer_id,0,3)=='-XT') return StdDecodePeerId(substr($peer_id,3,7),"XanTorrent"); # XanTorrent
  231. if(substr($peer_id,0,3)=='-ZT') return StdDecodePeerId(substr($peer_id,3,7),"ZipTorrent"); # ZipTorrent
  232. if(substr($peer_id,0,3)=='-bk') return StdDecodePeerId(substr($peer_id,3,7),"BitKitten"); # BitKitten
  233. if(substr($peer_id,0,3)=='-lt') return StdDecodePeerId(substr($peer_id,3,7),"libTorrent"); # libTorrent
  234. if(substr($peer_id,0,3)=='-pX') return StdDecodePeerId(substr($peer_id,3,7),"pHoeniX"); # pHoeniX
  235. if(substr($peer_id,0,2)=='BG') return StdDecodePeerId(substr($peer_id,2,4),"BTGetit"); # BTGetit
  236. if(substr($peer_id,2,2)=='BM') return DecodeVersionString(substr($peer_id,0,2),"BitMagnet"); # BitMagnet
  237. if(substr($peer_id,0,2)=='OP') return StdDecodePeerId(substr($peer_id,2,4),"Opera"); # Opera
  238. if(substr($peer_id,0,4)=='270-') return "GreedBT 2.7.0"; # GreedBT
  239. if(substr($peer_id,0,4)=='271-') return "GreedBT 2.7.1"; # GreedBT 2.7.1
  240. if(substr($peer_id,0,4)=='346-') return "TorrentTopia"; # TorrentTopia
  241. if(substr($peer_id,0,3)=='-AR') return "Arctic Torrent"; # Arctic (no way to know the version)
  242. if(substr($peer_id,0,3)=='-G3') return "G3 Torrent"; # G3 Torrent
  243. if(substr($peer_id,0,6)=='BTDWV-') return "Deadman Walking"; # Deadman Walking
  244. if(substr($peer_id,5,7)=='Azureus') return "Azureus 2.0.3.2"; # Azureus 2.0.3.2
  245. if(substr($peer_id,0,8)=='PRC.P---') return "BitTorrent Plus! II"; # BitTorrent Plus! II
  246. if(substr($peer_id,0,8)=='P87.P---') return "BitTorrent Plus!"; # BitTorrent Plus!
  247. if(substr($peer_id,0,4)=='Plus') return StdDecodePeerId(substr($peer_id,4,5),"BitTorrent Plus! v2"); # BitTorrent Plus! v2 (not 100% sure on this one)
  248. if(substr($peer_id,0,8)=='S587Plus') return "BitTorrent Plus!"; # BitTorrent Plus!
  249. if(substr($peer_id,0,7)=='martini') return "Martini Man"; # Martini Man
  250. if(substr($peer_id,4,6)=='btfans') return "SimpleBT"; # SimpleBT
  251. if(substr($peer_id,3,9)=='SimpleBT?') return "SimpleBT"; # SimpleBT
  252. if(ereg("MFC_Tear_Sample", $httpagent)) return "SimpleBT";
  253. if(substr($peer_id,0,5)=='btuga') return "BTugaXP"; # BTugaXP
  254. if(substr($peer_id,0,5)=='BTuga') return "BTuga"; # BTugaXP
  255. if(substr($peer_id,0,5)=='oernu') return "BTugaXP"; # BTugaXP
  256. if(substr($peer_id,0,10)=='DansClient') return "XanTorrent"; # XanTorrent
  257. if(substr($peer_id,0,16)=='Deadman Walking-') return "Deadman"; # Deadman client
  258. if(substr($peer_id,0,8)=='XTORR302') return "TorrenTres 0.0.2"; # TorrenTres
  259. if(substr($peer_id,0,7)=='turbobt') return "TurboBT ".(substr($peer_id,7,5)); # TurboBT
  260. if(substr($peer_id,0,7)=='a00---0') return "Swarmy"; # Swarmy
  261. if(substr($peer_id,0,7)=='a02---0') return "Swarmy"; # Swarmy
  262. if(substr($peer_id,0,7)=='T00---0') return "Teeweety"; # Teeweety
  263. if(substr($peer_id,0,7)=='rubytor') return "Ruby Torrent v".ord($peer_id[7]); # Ruby Torrent
  264. if(substr($peer_id,0,5)=='Mbrst') return MainlineDecodePeerId(substr($peer_id,5,5),"burst!"); # burst!
  265. if(substr($peer_id,0,4)=='btpd') return "BT Protocol Daemon ".(substr($peer_id,5,3)); # BT Protocol Daemon
  266. if(substr($peer_id,0,8)=='XBT022--') return "BitTorrent Lite"; # BitTorrent Lite based on XBT code
  267. if(substr($peer_id,0,3)=='XBT') return StdDecodePeerId(substr($peer_id,3,3), "XBT"); # XBT Client
  268. if(substr($peer_id,0,4)=='-BOW') return StdDecodePeerId(substr($peer_id,4,5),"Bits on Wheels"); # Bits on Wheels
  269. if(substr($peer_id,1,2)=='ML') return MainlineDecodePeerId(substr($peer_id,3,5),"MLDonkey"); # MLDonkey
  270. if(substr($peer_id,0,8)=='AZ2500BT') return "AzureusBitTyrant 1.0/1";
  271. if($peer_id[0]=='A') return StdDecodePeerId(substr($peer_id,1,9),"ABC"); # ABC
  272. if($peer_id[0]=='R') return StdDecodePeerId(substr($peer_id,1,5),"Tribler"); # Tribler
  273. if($peer_id[0]=='M'){
  274. if(preg_match("/^Python/", $httpagent, $matches)) return "Spoofing BT Client"; # Spoofing BT Client
  275. return MainlineDecodePeerId(substr($peer_id,1,7),"Mainline"); # Mainline BitTorrent with version
  276. }
  277. if($peer_id[0]=='O') return StdDecodePeerId(substr($peer_id,1,9),"Osprey Permaseed"); # Osprey Permaseed
  278. if($peer_id[0]=='S'){
  279. if(preg_match("/^BitTorrent\/3.4.2/", $httpagent, $matches)) return "Spoofing BT Client"; # Spoofing BT Client
  280. return StdDecodePeerId(substr($peer_id,1,9),"Shad0w"); # Shadow's client
  281. }
  282. if($peer_id[0]=='T'){
  283. if(preg_match("/^Python/", $httpagent, $matches)) return "Spoofing BT Client"; # Spoofing BT Client
  284. return StdDecodePeerId(substr($peer_id,1,9),"BitTornado"); # BitTornado
  285. }
  286. if($peer_id[0]=='U') return StdDecodePeerId(substr($peer_id,1,9),"UPnP"); # UPnP NAT Bit Torrent
  287. # Azureus / Localhost
  288. if(substr($peer_id,0,3)=='-AZ') {
  289. if(preg_match("/^Localhost ([0-9]+\.[0-9]+\.[0-9]+)/", $httpagent, $matches)) return "Localhost $matches[1]";
  290. if(preg_match("/^BitTorrent\/3.4.2/", $httpagent, $matches)) return "Spoofing BT Client"; # Spoofing BT Client
  291. if(preg_match("/^Python/", $httpagent, $matches)) return "Spoofing BT Client"; # Spoofing BT Client
  292. return StdDecodePeerId(substr($peer_id,3,7),"Azureus");
  293. }
  294. if(ereg("Azureus", $peer_id)) return "Azureus 2.0.3.2";
  295. # BitComet/BitLord/BitVampire/Modded FUTB BitComet
  296. if(substr($peer_id,0,4)=='exbc' || substr($peer_id,1,3)=='UTB'){
  297. if(substr($peer_id,0,4)=='FUTB') return DecodeVersionString(substr($peer_id,4,2),"BitComet Mod1");
  298. elseif(substr($peer_id,0,4)=='xUTB') return DecodeVersionString(substr($peer_id,4,2),"BitComet Mod2");
  299. elseif(substr($peer_id,6,4)=='LORD') return DecodeVersionString(substr($peer_id,4,2),"BitLord");
  300. elseif(substr($peer_id,6,3)=='---' && DecodeVersionString(substr($peer_id,4,2),"BitComet")=='BitComet 0.54') return "BitVampire";
  301. else return DecodeVersionString(substr($peer_id,4,2),"BitComet");
  302. }
  303. # Rufus
  304. if(substr($peer_id,2,2)=='RS'){
  305. for ($i=0; $i<=strlen(substr($peer_id,4,9)); $i++){
  306. $c = $peer_id[$i+4];
  307. if (ctype_alnum($c) || $c == chr(0)) $rufus_chk = true;
  308. else break;
  309. }
  310. if ($rufus_chk) return DecodeVersionString(substr($peer_id,0,2),"Rufus"); # Rufus
  311. }
  312. # BitSpirit
  313. if(substr($peer_id,14,6)=='HTTPBT' || substr($peer_id,16,4)=='UDP0') {
  314. if(substr($peer_id,2,2)=='BS') {
  315. if($peer_id[1]==chr(0)) return "BitSpirit v1";
  316. if($peer_id[1]== chr(2)) return "BitSpirit v2";
  317. }
  318. return "BitSpirit";
  319. }
  320. #BitSpirit
  321. if(substr($peer_id,2,2)=='BS') {
  322. if($peer_id[1]==chr(0)) return "BitSpirit v1";
  323. if($peer_id[1]==chr(2)) return "BitSpirit v2";
  324. return "BitSpirit";
  325. }
  326. # eXeem beta
  327. if(substr($peer_id,0,3)=='-eX') {
  328. $version_str = "";
  329. $version_str .= intval($peer_id[3],16).".";
  330. $version_str .= intval($peer_id[4],16);
  331. return "eXeem $version_str";
  332. }
  333. if(substr($peer_id,0,2)=='eX') return "eXeem"; # eXeem beta .21
  334. if(substr($peer_id,0,12)==(chr(0)*12) && $peer_id[12]==chr(97) && $peer_id[13]==chr(97)) return "Experimental 3.2.1b2"; # Experimental 3.2.1b2
  335. if(substr($peer_id,0,12)==(chr(0)*12) && $peer_id[12]==chr(0) && $peer_id[13]==chr(0)) return "Experimental 3.1"; # Experimental 3.1
  336. //if(substr($peer_id,0,12)==(chr(0)*12)) return "Mainline (obsolete)"; # Mainline BitTorrent (obsolete)
  337. //return "$httpagent [$peer_id]";
  338. return "Unknown client";
  339. }
  340. #========================================
  341. #getAgent function by deliopoulos
  342. #========================================
  343. ?>