PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/hosts/download/filecloud_io.php

https://gitlab.com/billyprice1/rapidleech
PHP | 185 lines | 163 code | 18 blank | 4 comment | 44 complexity | 523d910333e497cd70361e04aa07d485 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. if (preg_match('@\nLocation: (https?://s\d+\.filecloud\.io/[^\r\n]+)@i', $this->page, $dllink)) {
  23. $filename = urldecode(basename(parse_url($dllink[1], PHP_URL_PATH)));
  24. return $this->RedirectDownload($dllink[1], $filename);
  25. }
  26. }
  27. // Check https support for login.
  28. $cantlogin = false;
  29. if (!extension_loaded('openssl')) {
  30. if (extension_loaded('curl')) {
  31. $cV = curl_version();
  32. if (!in_array('https', $cV['protocols'], true)) $cantlogin = true;
  33. } else $cantlogin = true;
  34. if ($cantlogin) $this->changeMesg(lang(300).'<br /><br />Https support: NO<br />Login disabled.');
  35. }
  36. 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);
  37. elseif (!empty($_POST['skip']) && $_POST['skip'] == 'true') {
  38. $this->_ukey = urldecode($_POST['_ukey']);
  39. $this->ab1 = urldecode($_POST['_ab1']);
  40. $this->chkcaptcha($link, true);
  41. } else $this->Prepare($link);
  42. }
  43. private function Prepare($link) {
  44. $_s = '[\s\t]'; //Still lazy XD
  45. if (!preg_match("@$_s'ukey'$_s*:$_s*'([^']+)'@i", $this->page, $_ukey)) html_error('Error: File ID not found.');
  46. $this->_ukey = $_ukey[1];
  47. if (!preg_match("@var$_s+__requestUrl$_s*=$_s*'([^']+)'@i", $this->page, $_url)) html_error('Error: Url for posting data not found.');
  48. $this->_url = $_url[1];
  49. if (!preg_match("@var$_s+__downloadUrl$_s*=$_s*'([^']+)'@i", $this->page, $dlreq)) $dlreq = array(1=>false);
  50. $this->dlreq = $dlreq[1];
  51. if (!preg_match("@var$_s+__recaptcha_public$_s*=$_s*'([^']+)'@i", $this->page, $this->captcha)) $this->captcha = false;
  52. $this->captcha = $this->captcha[1];
  53. $ab_js = $this->GetPage('http://filecloud.io/ads/adframe.js', $this->cookie);
  54. if (!preg_match("@var$_s+__ab1$_s*=$_s*[\'\"]([^\'\"]+)[\'\"]@i", $ab_js, $ab1)) html_error('Error: "Session" code not found.');
  55. $this->ab1 = $ab1[1];
  56. $this->chkcaptcha($link);
  57. }
  58. private function FreeDL($rply) {
  59. if ($rply['dl'] != '1') {
  60. $err = (!empty($rply['message'])) ? ': '.htmlentities($rply['message']) : '.';
  61. html_error("Error getting download-link$err");
  62. }
  63. $page = $this->GetPage($this->dlreq, $this->cookie);
  64. if (!preg_match('@https?://s\d+\.filecloud\.io/'.$this->_ukey.'/[^\r\n\s\t<>\'\"]+@i', $page, $dllink)) html_error('Error: Download-link not found.');
  65. $filename = urldecode(basename(parse_url($dllink[0], PHP_URL_PATH)));
  66. return $this->RedirectDownload($dllink[0], $filename, $this->cookie);
  67. }
  68. private function Get_Reply($page) {
  69. if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.');
  70. // First time using json_decode in plugins. :)
  71. $json = substr($page, strpos($page, "\r\n\r\n") + 4);
  72. $json = substr($json, strpos($json, '{'));$json = substr($json, 0, strrpos($json, '}') + 1);
  73. $rply = json_decode($json, true);
  74. if (!$rply || count($rply) == 0) html_error('Error getting json data.');
  75. return $rply;
  76. }
  77. private function chkcaptcha($link, $send = false) {
  78. $post = array();
  79. $post['ukey'] = $this->_ukey;
  80. $post['__ab1'] = $this->ab1; // More annoying ad-block trap.
  81. if ($send) {
  82. if (empty($_POST['recaptcha_response_field'])) html_error('You didn\'t enter the image verification code.');
  83. $post['ctype'] = 'recaptcha';
  84. $post['recaptcha_response'] = $_POST['recaptcha_response_field'];
  85. $post['recaptcha_challenge'] = $_POST['recaptcha_challenge_field'];
  86. $this->_url = urldecode($_POST['_url']);
  87. $this->dlreq = urldecode($_POST['_dlreq']);
  88. $this->cookie = urldecode($_POST['cookie']);
  89. $page = $this->GetPage($this->_url, $this->cookie, $post);
  90. $rply = $this->Get_Reply($page);
  91. if ($rply['captcha'] == 0) $this->FreeDL($rply);
  92. elseif ($rply['retry'] == 1) html_error('Error: Wrong Captcha Entered.');
  93. else html_error('Error Sending Captcha.');
  94. } else {
  95. $page = $this->GetPage($this->_url, $this->cookie, $post);
  96. $rply = $this->Get_Reply($page);
  97. if ($rply['status'] == 'ok') {
  98. if ($rply['captcha'] == 0) {
  99. $this->FreeDL($rply);
  100. } else {
  101. if (!$this->captcha || empty($this->captcha)) html_error('Error: Captcha not found.');
  102. $data = $this->DefaultParamArr($link, $this->cookie);
  103. $data['_ukey'] = urlencode($this->_ukey);
  104. $data['_url'] = urlencode($this->_url);
  105. $data['_dlreq'] = urlencode($this->dlreq);
  106. $data['_ab1'] = urlencode($this->ab1);
  107. $data['skip'] = 'true';
  108. $this->reCAPTCHA($this->captcha, $data);
  109. }
  110. } else html_error("Error getting download data ('{$rply['status']}' => '{$rply['message']}').");
  111. }
  112. return false;
  113. }
  114. private function Login($cantlogin) {
  115. global $premium_acc;
  116. if ($cantlogin && empty($premium_acc['filecloud_io']['apikey'])) html_error('Login Error: Empty apikey.');
  117. // Ping api
  118. $page = $this->GetPage('http://api.filecloud.io/api-ping.api');
  119. is_notpresent($page, '"message":"pong"', 'Error: filecloud.io api is down?.');
  120. if (!empty($_REQUEST['premium_user']) && !empty($_REQUEST['premium_pass'])) $pA = true;
  121. else $pA = false;
  122. if (empty($premium_acc['filecloud_io']['apikey']) || $pA) {
  123. $user = ($pA ? $_REQUEST['premium_user'] : $premium_acc['filecloud_io']['user']);
  124. $pass = ($pA ? $_REQUEST['premium_pass'] : $premium_acc['filecloud_io']['pass']);
  125. if (empty($user) || empty($pass)) html_error('Login Failed: Username or Password are empty. Please check login data.');
  126. $post = array();
  127. $post['username'] = urlencode(strtolower($user));
  128. $post['password'] = urlencode($pass);
  129. $page = $this->GetPage('https://secure.filecloud.io/api-fetch_apikey.api', 0, $post);
  130. $rply = $this->Get_Reply($page);
  131. if ($rply['status'] != 'ok') html_error('Login Failed: '.htmlentities($rply['message']));
  132. if (empty($rply['akey'])) html_error('Login Failed: Akey not found.');
  133. } else $rply = array('akey' => urldecode($premium_acc['filecloud_io']['apikey']));
  134. $this->cookie = array('auth' => urlencode($rply['akey']));
  135. return $this->PremiumDL();
  136. }
  137. private function PremiumDL() {
  138. if (!preg_match('@\nLocation: (https?://s\d+\.filecloud\.io/[^\r\n]+)@i', $this->page, $dllink)) {
  139. if (!preg_match("@[\s\t]'ukey'[\s\t]*:[\s\t]*'([^']+)'@i", $this->page, $_ukey)) html_error('Error: FileID not found.');
  140. $page = $this->GetPage('http://api.filecloud.io/api-fetch_download_url.api', 0, array('akey' => $this->cookie['auth'], 'ukey' => $_ukey[1]));
  141. $rply = $this->Get_Reply($page);
  142. if ($rply['status'] != 'ok') html_error('Error getting premium dlink: '.htmlentities($rply['message']));
  143. if (empty($rply['download_url'])) html_error('Error getting premium dlink... Empty?');
  144. } else $rply = array('download_url' => $dllink[1]);
  145. $filename = urldecode(basename(parse_url($rply['download_url'], PHP_URL_PATH)));
  146. return $this->RedirectDownload($rply['download_url'], $filename);
  147. }
  148. }
  149. //[26-Oct-2012] (Re)Written by Th3-822.
  150. //[17-Feb-2013] Login Fixes. - Th3-822
  151. //[16-Oct-2013] Fixed support for direct-links. - Th3-822
  152. ?>