Advertisement
Corosus

Untitled

Sep 19th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. $url = $_GET["url"];
  6. $server_root = "";
  7.  
  8.  
  9.  
  10. if (strlen($url) < 1) {
  11. die();
  12. }
  13.  
  14.  
  15.  
  16. //Delete old zip cache
  17. $filename="mctempjar/net/minecraft/client/Minecraft.class";
  18. $output="";
  19. if (file_exists($filename)) {
  20. unlink("mctempjar/net/minecraft/client/Minecraft.class");
  21. }
  22.  
  23. //Download file
  24. dl_file($url,"/","minecrafttemp2.jar");
  25.  
  26.  
  27. //Extract file
  28.  
  29. //servers that support ZipArchive class
  30. if (class_exists("ZipArchive")) {
  31. extractZip();
  32. } else {
  33. //This code is crafted for a specific dreamhost domain
  34. shell_exec("unzip -o " . $server_root . "mods/modsystem/minecrafttemp2.jar net/minecraft/client/Minecraft.class -d mctempjar");
  35. }
  36.  
  37. //Open class file for reading
  38. $filename="mctempjar/net/minecraft/client/Minecraft.class";
  39. $output="";
  40.  
  41. if (!file_exists($filename)) {
  42. echo "Extraction error.";
  43. } else {
  44. $file = fopen($filename, "r");
  45.  
  46. while(!feof($file)) {
  47.  
  48. //read file line by line into variable until we find the data we need
  49. $output = fgets($file, 4096);
  50. $strlook = "Minecraft Minecraft ";
  51. $strlen = strlen($strlook);
  52. if (strpos($output,$strlook) > 0) {
  53. $start = strpos($output,$strlook);
  54. //character ascii code '1' scan
  55. $end = strpos($output,"", $start+$strlen);
  56. $output = substr($output,$start + $strlen, $end-$start-$strlen);
  57. break;
  58. }
  59.  
  60. }
  61.  
  62. fclose ($file);
  63. echo "Extracted Minecraft Version: " . $output;
  64. }
  65.  
  66. function extractZip() {
  67. try {
  68. $zip = new ZipArchive;
  69. $res = $zip->open('minecrafttemp.jar');
  70. if ($res === TRUE) {
  71. //echo 'ok';
  72. $zip->extractTo('mctempjar', 'net/minecraft/client/Minecraft.class');
  73. $zip->close();
  74. } else {
  75. //echo 'failed, code:' . $res;
  76. }
  77. } catch (Exception $ex) { return false; }
  78. return true;
  79. }
  80.  
  81. function dl_file($file, $local_path, $newfilename)
  82. {
  83. $err_msg = '';
  84. $out = fopen($newfilename, 'wb');
  85. if ($out == FALSE){
  86. print "File not opened<br>";
  87. exit;
  88. }
  89.  
  90. $ch = curl_init();
  91.  
  92. curl_setopt($ch, CURLOPT_FILE, $out);
  93. curl_setopt($ch, CURLOPT_HEADER, 0);
  94. curl_setopt($ch, CURLOPT_URL, $file);
  95.  
  96. curl_exec($ch);
  97. //echo "<br>Error is : ".curl_error ( $ch);
  98.  
  99. curl_close($ch);
  100. }
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement