PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/hosts/download/filecloud_io.php

http://rapidleech.googlecode.com/
PHP | 199 lines | 171 code | 24 blank | 4 comment | 50 complexity | 3b6a7344538a30709ac383b2c743eb10 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require_once('index.html');
  4. exit;
  5. }
  6. class filecloud_io extends DownloadClass {
  7. private $page, $cookie, $redir, $_url, $_ukey, $dlreq, $dlurl, $ab1, $captcha;
  8. public function Download($link) {
  9. global $premium_acc;
  10. $this->cookie = array();
  11. if (empty($_POST['skip']) || $_POST['skip'] != 'true') {
  12. global $Referer;
  13. $this->page = $this->GetPage($link, $this->cookie);
  14. if (substr($this->page, 9, 3) == '404') html_error('File not Found or Deleted');
  15. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  16. if (preg_match('@\r\nLocation: ((https?://(?:www\.)?filecloud\.io)?/[^\r\n]+)@i', $this->page, $redir)) {
  17. $this->redir = (empty($redir[2])) ? 'http://filecloud.io'.$redir[1] : $redir[1];
  18. $this->page = $this->GetPage($this->redir, $this->cookie, 0, $link);
  19. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  20. $Referer = $this->redir;
  21. } else $Referer = $link;
  22. }
  23. // Check https support for login.
  24. $cantlogin = false;
  25. if (!extension_loaded('openssl')) {
  26. if (extension_loaded('curl')) {
  27. $cV = curl_version();
  28. if (!in_array('https', $cV['protocols'], true)) $cantlogin = true;
  29. } else $cantlogin = true;
  30. if ($_REQUEST['premium_acc'] == 'on' && !empty($premium_acc['filecloud_io']['apikey'])) $cantlogin = false;
  31. if ($cantlogin) $this->changeMesg(lang(300).'<br /><br />Https support: NO<br />Login disabled.');
  32. }
  33. if ($_REQUEST['premium_acc'] == 'on' && (((!empty($_REQUEST['premium_user']) && !empty($_REQUEST['premium_pass'])) || (!empty($premium_acc['filecloud_io']['user']) && !empty($premium_acc['filecloud_io']['pass']))) || !empty($premium_acc['filecloud_io']['apikey']))) $this->Login($cantlogin);
  34. elseif (!empty($_POST['skip']) && $_POST['skip'] == 'true') {
  35. $this->_ukey = urldecode($_POST['_ukey']);
  36. $this->ab1 = urldecode($_POST['_ab1']);
  37. $this->chkcaptcha($link, true);
  38. } else $this->Prepare($link);
  39. }
  40. private function Prepare($link) {
  41. $_s = '[\s\t]'; //Still lazy XD
  42. if (!preg_match("@$_s'ukey'$_s*:$_s*'([^']+)'@i", $this->page, $_ukey)) html_error('Error: File ID not found.');
  43. $this->_ukey = $_ukey[1];
  44. if (!preg_match("@var$_s+__requestUrl$_s*=$_s*'([^']+)'@i", $this->page, $_url)) html_error('Error: Url for posting data not found.');
  45. $this->_url = $_url[1];
  46. if (!preg_match("@var$_s+__downloadUrl$_s*=$_s*'([^']+)'@i", $this->page, $dlreq)) $dlreq = array(1=>false);
  47. $this->dlreq = $dlreq[1];
  48. if (!preg_match("@var$_s+__recaptcha_public$_s*=$_s*'([^']+)'@i", $this->page, $this->captcha)) $this->captcha = false;
  49. $this->captcha = $this->captcha[1];
  50. $ab_js = $this->GetPage('http://filecloud.io/ads/adframe.js', $this->cookie);
  51. if (!preg_match("@var$_s+__ab1$_s*=$_s*[\'\"]([^\'\"]+)[\'\"]@i", $ab_js, $ab1)) html_error('Error: "Session" code not found.');
  52. $this->ab1 = $ab1[1];
  53. $this->chkcaptcha($link);
  54. }
  55. private function FreeDL($rply) {
  56. if ($rply['dl'] != '1') {
  57. $err = (!empty($rply['message'])) ? ': '.htmlentities($rply['message']) : '.';
  58. html_error("Error getting download-link$err");
  59. }
  60. $page = $this->GetPage($this->dlreq, $this->cookie);
  61. if (!preg_match('@https?://s\d+\.filecloud\.io/'.$this->_ukey.'/[^\r\n\s\t<>\'\"]+@i', $page, $dllink)) html_error('Error: Download-link not found.');
  62. $filename = urldecode(basename(parse_url($dllink[0], PHP_URL_PATH)));
  63. return $this->RedirectDownload($dllink[0], $filename, $this->cookie);
  64. }
  65. private function Get_Reply($page) {
  66. if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.');
  67. // First time using json_decode in plugins. :)
  68. $json = substr($page, strpos($page, "\r\n\r\n") + 4);
  69. $json = substr($json, strpos($json, '{'));$json = substr($json, 0, strrpos($json, '}') + 1);
  70. $rply = json_decode($json, true);
  71. if (!$rply || count($rply) == 0) html_error('Error getting json data.');
  72. return $rply;
  73. }
  74. private function chkcaptcha($link, $send = false) {
  75. $post = array();
  76. $post['ukey'] = $this->_ukey;
  77. $post['__ab1'] = $this->ab1; // More annoying ad-block trap.
  78. if ($send) {
  79. if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  80. $post['ctype'] = 'recaptcha';
  81. $post['recaptcha_response'] = $_POST['captcha'];
  82. $post['recaptcha_challenge'] = $_POST['challenge'];
  83. $this->_url = urldecode($_POST['_url']);
  84. $this->dlreq = urldecode($_POST['_dlreq']);
  85. $this->cookie = urldecode($_POST['cookie']);
  86. $page = $this->GetPage($this->_url, $this->cookie, $post);
  87. $rply = $this->Get_Reply($page);
  88. if ($rply['captcha'] == 0) $this->FreeDL($rply);
  89. elseif ($rply['retry'] == 1) html_error('Error: Wrong Captcha Entered.');
  90. else html_error('Error Sending Captcha.');
  91. } else {
  92. $page = $this->GetPage($this->_url, $this->cookie, $post);
  93. $rply = $this->Get_Reply($page);
  94. if ($rply['status'] == 'ok') {
  95. if ($rply['captcha'] == 0) {
  96. $this->FreeDL($rply);
  97. } else {
  98. if (!$this->captcha || empty($this->captcha)) html_error('Error: Captcha not found.');
  99. $data = $this->DefaultParamArr($link, $this->cookie);
  100. $data['_ukey'] = urlencode($this->_ukey);
  101. $data['_url'] = urlencode($this->_url);
  102. $data['_dlreq'] = urlencode($this->dlreq);
  103. $data['_ab1'] = urlencode($this->ab1);
  104. $data['skip'] = 'true';
  105. $this->DL_reCaptcha($this->captcha, $data);
  106. }
  107. } else html_error("Error getting download data ('{$rply['status']}' => '{$rply['message']}').");
  108. }
  109. return false;
  110. }
  111. private function DL_reCaptcha($pid, $data) {
  112. $page = $this->GetPage('http://www.google.com/recaptcha/api/challenge?k=' . $pid);
  113. if (!preg_match('/challenge \: \'([^\']+)/i', $page, $ch)) html_error('Error getting CAPTCHA data.');
  114. $challenge = $ch[1];
  115. $data['challenge'] = $challenge;
  116. //Download captcha img.
  117. $page = $this->GetPage('http://www.google.com/recaptcha/api/image?c=' . $challenge);
  118. $capt_img = substr($page, strpos($page, "\r\n\r\n") + 4);
  119. $imgfile = DOWNLOAD_DIR . 'filecloud_captcha.jpg';
  120. if (file_exists($imgfile)) unlink($imgfile);
  121. if (!write_file($imgfile, $capt_img)) html_error('Error getting CAPTCHA image.');
  122. $this->EnterCaptcha($imgfile.'?'.time(), $data, 20);
  123. exit;
  124. }
  125. private function Login($cantlogin) {
  126. global $premium_acc;
  127. if ($cantlogin && empty($premium_acc['filecloud_io']['apikey'])) html_error('Login Error: Empty apikey.');
  128. // Ping api
  129. $page = $this->GetPage('http://api.filecloud.io/api-ping.api');
  130. is_notpresent($page, '"message":"pong"', 'Error: filecloud.io api is down?.');
  131. if (empty($premium_acc['filecloud_io']['apikey'])) {
  132. if (!empty($_REQUEST['premium_user']) && !empty($_REQUEST['premium_pass'])) $pA = true;
  133. else $pA = false;
  134. $user = ($pA ? $_REQUEST['premium_user'] : $premium_acc['filecloud_io']['user']);
  135. $pass = ($pA ? $_REQUEST['premium_pass'] : $premium_acc['filecloud_io']['pass']);
  136. if (empty($user) || empty($pass)) html_error('Login Failed: Username or Password are empty. Please check login data.');
  137. $post = array();
  138. $post['username'] = urlencode($user);
  139. $post['password'] = urlencode($pass);
  140. $page = $this->GetPage('https://secure.filecloud.io/api-fetch_apikey.api', 0, $post);
  141. $rply = $this->Get_Reply($page);
  142. if ($rply['status'] != 'ok') html_error('Login Failed: '.htmlentities($rply['message']));
  143. if (empty($rply['akey'])) html_error('Login Failed: Akey not found.');
  144. } else $rply = array('akey' => $premium_acc['filecloud_io']['apikey']);
  145. $this->cookie = array('auth' => urlencode($rply['akey']));
  146. return $this->PremiumDL();
  147. }
  148. private function PremiumDL() {
  149. if (!preg_match('@\r\nLocation: (https?://s\d+\.filecloud\.io/[^\r\n]+)@i', $this->page, $dllink)) {
  150. if (!preg_match("@[\s\t]'ukey'[\s\t]*:[\s\t]*'([^']+)'@i", $this->page, $_ukey)) html_error('Error: FileID not found.');
  151. $page = $this->GetPage('http://api.filecloud.io/api-fetch_download_url.api', 0, array('akey' => $this->cookie['auth'], 'ukey' => $_ukey[1]));
  152. $rply = $this->Get_Reply($page);
  153. if ($rply['status'] != 'ok') html_error('Error getting premium dlink: '.htmlentities($rply['message']));
  154. if (empty($rply['download_url'])) html_error('Error getting premium dlink... Empty?');
  155. } else $rply = array('download_url' => $dllink);
  156. $filename = urldecode(basename(parse_url($rply['download_url'], PHP_URL_PATH)));
  157. return $this->RedirectDownload($rply['download_url'], $filename);
  158. }
  159. }
  160. //[26-Oct-2012] (Re)Written by Th3-822. // If you can't login, try wih your username in lowercase.
  161. ?>