PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/pluginz/download/rapidshare_com.php

http://rapidleech36b.googlecode.com/
PHP | 236 lines | 195 code | 25 blank | 16 comment | 71 complexity | 90eb31c1000d5ec26ccdf7e4d599ec85 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require_once ("index.html");
  4. exit();
  5. }
  6. class rapidshare_com extends DownloadClass {
  7. public $lastmesg, $apiurl;
  8. private $fileid, $filename;
  9. public function Download($link) {
  10. global $premium_acc, $L;
  11. $this->apiurl = "https://api.rapidshare.com/cgi-bin/rsapi.cgi";
  12. $link = str_replace('http://', 'https://', $link);
  13. $URl = parse_url(trim($link));
  14. if (preg_match("/!download\|([^\|]+)\|(\d+)\|([^\|]+)/i", $URl["fragment"], $m)) $link = "https://rapidshare.com/files/{$m[2]}/{$m[3]}";
  15. $page = $this->GetPage($link);
  16. is_present($page, "ERROR: Filename invalid.", "Filename invalid. Please check the download link.");
  17. is_present($page, "ERROR: File ID invalid.", "File ID invalid. Please check the download link.");
  18. is_present($page, "ERROR: Unassigned file limit of 10 downloads reached.", "Unassigned file limit of 10 downloads reached.");
  19. is_present($page, "ERROR: Server under repair.", "Server under repair. Please try again later");
  20. if ($linkb = $this->ReLocation($page, 0)) $page = $this->GetPage($linkb);
  21. if (!preg_match("/!download\|([^\|]+)\|(\d+)\|([^\|]+)/i", $page, $m)) html_error("Cannot check link");
  22. $this->fileid = $m[2];
  23. $this->filename = $m[3];
  24. $rserrors = array("This file was not found on our server.",
  25. "The file was deleted by the owner or the administrators.",
  26. "The file was deleted due to our inactivity-rule (no downloads).",
  27. "The file is suspected to be contrary to our terms and conditions and has been locked up for clarification.",
  28. "The file has been removed from the server due of infringement of the copyright-laws.",
  29. "The file is corrupted or incomplete.");
  30. $errors = array("ERROR: File not found." => 0, "ERROR: File physically not found." => 0,
  31. "ERROR: File deleted R1." => 1, "ERROR: File deleted R2." => 1,
  32. "ERROR: File deleted R3." => 2, "ERROR: File deleted R5." => 2,
  33. "ERROR: File deleted R4." => 3, "ERROR: File deleted R8." => 3,
  34. "ERROR: File deleted R10." => 4, "ERROR: File deleted R11." => 4,
  35. "ERROR: File deleted R12." => 4, "ERROR: File deleted R13." => 4,
  36. "ERROR: File deleted R14." => 4, "ERROR: File deleted R15." => 4,
  37. "ERROR: This file is marked as illegal." => 4, // R10=Game;R11=Movie/Video;R12=Music;R13=Software;R14=Image;R15=Literature
  38. "ERROR: raid error on server." => 5, "ERROR: File incomplete." => 5);
  39. foreach ($errors as $err => $errn) {
  40. is_present($page, $err, $rserrors[$errn]);
  41. }
  42. unset($page);
  43. if ($_REQUEST["rs_acc"] == "on" && (!empty($_GET["rs_cookie"]) || !empty($_GET["rs_hash"]) || !empty($premium_acc["rapidshare_com"]["cookie"]))) {
  44. if (!empty($_GET["rs_cookie"])) {
  45. $cookie = $_GET["rs_cookie"];
  46. } elseif (!empty($_GET["rs_hash"])) {
  47. $cookie = strrev(dcd($_GET["rs_hash"]));
  48. } else {
  49. $cookie = $premium_acc["rapidshare_com"]["cookie"];
  50. }
  51. $this->lastmesg = $L->say['_retrieving']."<br />RS Premium Download [Cookie]";
  52. $this->changeMesg($this->lastmesg);
  53. return $this->PremiumCookieDownload($cookie);
  54. } elseif (!empty($_POST["sssid"]) || ($_REQUEST["premium_acc"] == "on" && (($_GET["maudl"] == 'multi' && !empty($_GET["auth_hash"])) || (!empty($_REQUEST["premium_user"]) && !empty($_REQUEST["premium_pass"])) || (!empty($premium_acc["rapidshare_com"]['user']) && !empty($premium_acc["rapidshare_com"]['pass']))))) {
  55. $this->lastmesg = $L->say['_retrieving']."<br />RS Premium Download";
  56. $this->changeMesg($this->lastmesg);
  57. return $this->DownloadPremium();
  58. } else {
  59. $this->lastmesg = $L->say['_retrieving'].'<br />RS Free Download';
  60. $this->changeMesg($this->lastmesg);
  61. return $this->DownloadFree($link);
  62. }
  63. }
  64. private function DownloadFree($link) {
  65. $page = $this->GetPage($this->apiurl."?sub=download&fileid={$this->fileid}&filename={$this->filename}&try=1");
  66. is_present($page, "ERROR: This file is too big to download it for free.", "This file is too big to download it for free.");
  67. is_present($page, "ERROR: You need RapidPro to download more files from your IP address.", "Too many parallel downloads from your IP address.");
  68. is_present($page, "ERROR: Please stop flooding our download servers.", "Flood: Please try again in 5 minutes or later.");
  69. is_present($page, "ERROR: Too many users downloading", "Too many users downloading right now. Please try again later.");
  70. is_present($page, "ERROR: All free download slots are full.", "All free download slots are full. Please try again later.");
  71. if (stristr($page, "ERROR: You need to wait ")) {
  72. $seconds = trim(cut_str($page, "ERROR: You need to wait ", " seconds until"));
  73. return $this->JSCountdown($seconds,0,'Download limit exceeded');
  74. }
  75. $data = substr(strrchr($page, "\n"), 1);
  76. $data = explode(":", $data);
  77. if ($data[0] == "DL") {
  78. $details = explode(",", $data[1]);
  79. $host = $details[0];
  80. $dlauth = $details[1];
  81. $countdown = $details[2];
  82. $dllink = "http://$host/cgi-bin/rsapi.cgi?sub=download&editparentlocation=0&bin=1&fileid={$this->fileid}&filename={$this->filename}&dlauth=$dlauth";
  83. if ($countdown == 0) $this->RedirectDownload($dllink, $this->filename);
  84. else {
  85. $url = parse_url($dllink);
  86. $data = $this->DefaultParamArr($dllink);
  87. unset($data['audl']); // Can't use audl in free dl.
  88. $data['filename'] = urlencode($this->filename);
  89. $data['host'] = $url["host"];
  90. $data['port'] = $url["port"];
  91. $data['path'] = urlencode($url["path"] . ($url["query"] ? "?" . $url["query"] : ""));
  92. $data['saveto'] = $_GET["path"];
  93. $this->JSCountdown($countdown, $data);
  94. }
  95. } else {
  96. html_error("Download link not found.");
  97. }
  98. }
  99. private function DownloadPremium() {
  100. global $premium_acc;
  101. if (!extension_loaded('openssl')) html_error("Need OpenSSL enabled for premium download.");
  102. if (($_GET["maudl"] == 'multi' && !empty($_GET["auth_hash"])) || (!empty($_POST["sssid"]))) {
  103. $ahash = (($_GET["maudl"] == 'multi' && !empty($_GET["auth_hash"])) ? $_GET["auth_hash"] : $_POST["sssid"]);
  104. $ahash = explode(":", base64_decode(utf8_strrev(dcd($ahash))));
  105. if (count($ahash) == 2 && (!empty($ahash[0]) && !empty($ahash[1]))) {
  106. $_REQUEST["premium_user"] = $ahash[0];
  107. $_REQUEST["premium_pass"] = $ahash[1];
  108. }
  109. unset($ahash);
  110. }
  111. if (!empty($_REQUEST["premium_user"]) && !empty($_REQUEST["premium_pass"])) {
  112. $pA = true;
  113. $user = $_REQUEST["premium_user"];
  114. $pass = $_REQUEST["premium_pass"];
  115. } else {
  116. $user = $premium_acc["rapidshare_com"]["user"];
  117. $pass = $premium_acc["rapidshare_com"]["pass"];
  118. }
  119. $user = urlencode($user);
  120. $pass = urlencode($pass);
  121. $cookie = $this->ChkAccInfo('login', $user, $pass, $pA);
  122. $cookie = "enc=$cookie;";
  123. $sendauth = 1;
  124. if ($pA) $sendauth = 0;
  125. else $cookie = 0;
  126. $page = $this->GetPage("https://rapidshare.com/files/{$this->fileid}/{$this->filename}", $cookie, 0, 0, ($sendauth) ? base64_encode("$user:$pass") : '');
  127. if (!stristr($page, "Location:")) html_error("Cannot use premium account", 0);
  128. $Href = $this->ReLocation($page);
  129. $this->RedirectDownload($Href, $this->filename, $cookie, 0, 0, 0, $sendauth);
  130. }
  131. private function PremiumCookieDownload($cookie) {
  132. if (!extension_loaded('openssl')) html_error("Need OpenSSL enabled for premium download.");
  133. $this->ChkAccInfo($cookie);
  134. $cookie = "enc=$cookie;";
  135. $page = $this->GetPage("https://rapidshare.com/files/{$this->fileid}/{$this->filename}", $cookie);
  136. if (!stristr($page, "Location:")) html_error("Cannot use premium account", 0);
  137. $Href = $this->ReLocation($page);
  138. $this->RedirectDownload($Href, $this->filename, $cookie);
  139. }
  140. private function ChkAccInfo($cookie, $user='', $pass='', $pA=false) {
  141. if ($cookie != "login") {
  142. $page = $this->GetPage($this->apiurl."?sub=getaccountdetails&cookie=$cookie");
  143. $t1 = 'Cookie';$t2 = 'cookie';
  144. } elseif (!empty($user) && !empty($pass)) {
  145. $page = $this->GetPage($this->apiurl."?sub=getaccountdetails&withcookie=1&login=$user&password=$pass");
  146. $t1 = 'Error';$t2 = 'login details';
  147. } else html_error("Login failed. User/Password empty.");
  148. is_present($page, "ERROR: IP blocked.", "[ERROR] Rapidshare has locked your IP. (Too many failed logins sended)");
  149. is_present($page, "ERROR: Login failed. Login data invalid.",
  150. "[$t1] Invalid $t2.");
  151. is_present($page, "ERROR: Login failed. Password incorrect or account not found.",
  152. "[$t1] Login failed. User/Password incorrect or could not be found.");
  153. is_present($page, "ERROR: Login failed. Account not validated.",
  154. "[$t1] Login failed. Account not validated.");
  155. is_present($page, "ERROR: Login failed. Account locked.",
  156. "[$t1] Login failed. Account locked.");
  157. is_present($page, "ERROR: Login failed.",
  158. "[$t1] Login failed. Invalid $t2?");
  159. $page = substr($page, strpos($page, "\r\n\r\n") + 4);
  160. $arr1 = explode("\n", $page);
  161. $info = array();
  162. foreach ($arr1 as $key => $val) {
  163. $arr2 = explode("=", $val);
  164. foreach ($arr2 as $key2 => $val2) {
  165. $arr3[] = $val2;
  166. }
  167. }
  168. for ($i = 0; $i <= count($arr3); $i += 2) {
  169. if (array_key_exists($i, $arr3)) {
  170. if ($arr3[$i] != "") {
  171. $info[trim($arr3[$i])] = trim($arr3[$i + 1]);
  172. }
  173. }
  174. }
  175. if ($info['servertime'] >= $info['billeduntil']) {
  176. html_error("[$t1] RapidPro has expired or is inactive.");
  177. } elseif ($info['directstart'] == 0 && (!$user || $pA)) {
  178. if ($pA) $cookie = $info['cookie'];
  179. $dd = $this->GetPage($this->apiurl."?cookie=$cookie&sub=setaccountdetails&directstart=1");
  180. if (substr(strrchr($dd, "\n"), 1) != 'OK') {
  181. html_error("Error enabling direct downloads. Please do it manually.");
  182. }
  183. $this->changeMesg($this->lastmesg.'<br />Direct downloads has been enabled in your account');
  184. }
  185. if ($user) return $info['cookie'];
  186. }
  187. private function ReLocation($page, $stop=1) {
  188. if (!preg_match('@Location: https?://((\w+\.)?rapidshare\.com/[^\r|\n]+)@i', $page, $rloc)) {
  189. if ($stop) html_error("Redirection not found.");
  190. else return false;
  191. }
  192. return "https://" . $rloc[1];
  193. }
  194. }
  195. // updated by rajmalhotra on 17 Dec 09 : added some error messages
  196. // Fixed by rajmalhotra on 28 Dec 09
  197. //updated 08-jun-2010 for standard auth system (szal)
  198. //[07-OCT-10] Free download rewritten/fixed by Th3-822
  199. //[30-OCT-10] Premium download fixed for new links/error msg support & Added 4 error msg to free download. -Th3-822
  200. //[13-NOV-10] Added error msg for "Account locked" in premium download && Fixed + Added 1 error msg to free download && Fixed regex for get link. -Th3-822
  201. //[13-JAN-11] & [22-JAN-11] Added full support for premium cookie & Added function for check RS-API limits & Minor change in 'ChkAccInfo'. -Th3-822
  202. //[17-MAR-11] Premium: Add var ($DisSSL) and code for Disable SSL downloads && Changed limit to 1000 & Err Msg in 'Check_Limit'. - Th3-822
  203. //[18-MAR-11] Premium: Now SSL downloads will be disabled if OpenSSL isn't loaded && Added 5 status msgs with changeMesg() :D - Th3-822
  204. //[19-APR-11] Plugin checked & fixed for work with new changes at RS && SSL support is needed (It will show error if OpenSSL isn't loaded)... Including for get data in Free download :( . - Th3-822
  205. //[20-APR-11] FreeDL: Added new functions for use https with cURL if OpenSSL isn't loaded. - Th3-822
  206. //[21-APR-11] Fixed $post in cURL function. (Oops, but isn't used by the plugin)... - Th3-822
  207. //[29-MAY-11] Premium: Removed support for multi RS logins (Isn't needed now) & changed the login process using 'ChkAccInfo'. Free: Changed countdown, added new function. And plugin checked. - Th3-822
  208. //[01-JUN-11] Premium: Fixed error in login. - Th3-822
  209. //[10-JUL-11] Check_Limit() function isn't needed now, removed & Thinking about delete the old fixes info (Too long for read. :D ). - Th3-822
  210. //[15-OCT-11] JSCountdown was added in DownloadClass.php... Removed declaration from plugin && Some edits in free dl countdown. - Th3-822
  211. ?>