PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/hosts/download/depfile_com.php

https://gitlab.com/billyprice1/rapidleech
PHP | 251 lines | 211 code | 36 blank | 4 comment | 74 complexity | ba6be3b48d0e00c9fb1a841a9e640062 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require_once('index.html');
  4. exit;
  5. }
  6. class depfile_com extends DownloadClass {
  7. private $page, $cookie = array('sdlanguageid' => '2'), $pA, $DLRegexp = '@https?://(?:[\w\-]+\.)+[\w\-]+(?:\:\d+)?/\d/\d+/\d/\w+/[^\t\r\n\'\"<>]+@i';
  8. public function Download($link) {
  9. if (!preg_match('@(https://depfile\.com)/(?>downloads|([a-zA-Z\d]{8,})(?=/|$))(?(2)|/i/(\d+)/f/[^\s]+\.html)@i', str_ireplace(array('http://', '//www.depfile.com'), array('https://', '//depfile.com'), $link), $fid)) html_error('Invalid link?.');
  10. $this->link = $GLOBALS['Referer'] = $fid[0];
  11. $this->baseUrl = $fid[1];
  12. $this->fid = empty($fid[3]) ? $fid[2] : $fid[3];
  13. if (empty($_POST['step'])) {
  14. $this->page = $this->GetPage($this->link, $this->cookie);
  15. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  16. if (substr($this->page, 9, 3) == '404') html_error('Page Not Found.');
  17. if (is_numeric($this->fid)) is_present($this->page, 'File was not found in the DepFile database.', 'File Not Found or Link Invalid.');
  18. else is_present($this->page, "\nLocation: /premium", 'File Not Found.');
  19. $this->cookie['sdlanguageid'] = '2';
  20. if (stripos($this->page, '<h1>Download folder</h1>') !== false) return $this->Folder();
  21. }
  22. $this->pA = (empty($_REQUEST['premium_user']) || empty($_REQUEST['premium_pass']) ? false : true);
  23. if (($_REQUEST['premium_acc'] == 'on' && ($this->pA || (!empty($GLOBALS['premium_acc']['depfile_com']['user']) && !empty($GLOBALS['premium_acc']['depfile_com']['pass']))))) {
  24. $user = ($this->pA ? $_REQUEST['premium_user'] : $GLOBALS['premium_acc']['depfile_com']['user']);
  25. $pass = ($this->pA ? $_REQUEST['premium_pass'] : $GLOBALS['premium_acc']['depfile_com']['pass']);
  26. if ($this->pA && !empty($_POST['pA_encrypted'])) {
  27. $user = decrypt(urldecode($user));
  28. $pass = decrypt(urldecode($pass));
  29. unset($_POST['pA_encrypted']);
  30. }
  31. return $this->CookieLogin($user, $pass);
  32. } else return $this->FreeDL();
  33. }
  34. private function Folder() {
  35. if (isset($_GET['audl'])) return html_error('Cannot check folder in audl.');
  36. if (!preg_match_all('@https?://(?:www\.)?depfile\.com/[a-zA-Z\d]{8,}(?=\')@i', $this->page, $links)) html_error('Empty folder?');
  37. return $this->moveToAutoDownloader($links[0]);
  38. }
  39. private function FreeDL() {
  40. if (empty($_POST['step']) || $_POST['step'] != '1') {
  41. is_present($this->page, 'File is available only for Premium users', 'This File Is Only Available For Premium Users.');
  42. if (!preg_match('@/includes/vvc\.php\?vvcid=(\d+)@i', $this->page, $vvc)) html_error('CAPTCHA not Found.');
  43. $data = $this->DefaultParamArr($this->link, $this->cookie, 1, 1);
  44. $data['step'] = '1';
  45. $data['vvcid'] = $vvc[1];
  46. list($headers, $imgBody) = explode("\r\n\r\n", $this->GetPage($this->baseUrl.$vvc[0]), 2);
  47. if (substr($headers, 9, 3) != '200') html_error('FreeDL: Error downloading captcha img.');
  48. $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/png');
  49. return $this->EnterCaptcha("data:$mimetype;base64," . base64_encode($imgBody), $data);
  50. }
  51. if (empty($_POST['vvcid'])) html_error('FreeDL: Captcha\'s vvcid not Found.');
  52. if (empty($_POST['captcha'])) html_error('FreeDL: You didn\'t enter the image verification code.');
  53. $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  54. $this->cookie['sdlanguageid'] = '2';
  55. $post = array('vvcid' => urlencode($_POST['vvcid']), 'verifycode' => urlencode($_POST['captcha']), 'FREE' => 'Low+Speed+Download');
  56. $page = $this->GetPage($this->link, $this->cookie, $post);
  57. is_present($page, 'Wrong CAPTCHA', 'Incorrect CAPTCHA Answer.');
  58. is_present($page, '>Download limit for free user.<', 'FreeDL Limit Reached.');
  59. if (preg_match('@A file was recently downloaded from your IP address. No less than \d+ \w+ should pass before next download.@i', $page, $err)) html_error($err[0]);
  60. // Search Download Link
  61. if (!preg_match($this->DLRegexp, $page, $DL)) {
  62. if (!preg_match('@document\.getElementById\("wait_url"\)\.innerHTML\s*=\s*unescape\(\'([^\']+)\'\)@', $page, $inner)) html_error('Download Link Container not Found.');
  63. $inner = rawurldecode($inner[1]);
  64. if (!preg_match($this->DLRegexp, $inner, $DL)) html_error('Download Link not Found.');
  65. }
  66. // Countdown
  67. if (!preg_match('@var\s+sec\s*=\s*(\d+)\s*;@', $page, $cD)) html_error('Countdown not Found.');
  68. $this->CountDown($cD[1]);
  69. return $this->RedirectDownload($DL[0], urldecode(parse_url($DL[0], PHP_URL_PATH)));
  70. }
  71. private function PremiumDL() {
  72. $page = $this->GetPage($this->link, $this->cookie);
  73. $this->chkPremCaptcha($page);
  74. is_present($page, 'Sorry, you spent downloads limit on urls/files per 24 hours.', 'Premium Download Limit Reached.');
  75. if (!preg_match($this->DLRegexp, $page, $DL)) html_error('Download Link not Found.');
  76. return $this->RedirectDownload($DL[0], urldecode(parse_url($DL[0], PHP_URL_PATH)));
  77. }
  78. private function chkPremCaptcha(&$page) {
  79. if (!preg_match('@/includes/vvc\.php\?vvcid=(\d+)@i', $page, $vvc)) return false;
  80. if (empty($_POST['step']) || $_POST['step'] != '3') {
  81. $data = $this->DefaultParamArr($this->link, $this->cookie, 1, 1);
  82. $data['step'] = '3';
  83. $data['vvcid'] = $vvc[1];
  84. if ($this->pA) {
  85. $data['pA_encrypted'] = 'true';
  86. $data['premium_user'] = urlencode(encrypt($_REQUEST['premium_user']));
  87. $data['premium_pass'] = urlencode(encrypt($_REQUEST['premium_pass']));
  88. }
  89. list($headers, $imgBody) = explode("\r\n\r\n", $this->GetPage($this->baseUrl.$vvc[0]), 2);
  90. if (substr($headers, 9, 3) != '200') html_error('PremiumDL: Error downloading captcha img.');
  91. $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/png');
  92. return $this->EnterCaptcha("data:$mimetype;base64," . base64_encode($imgBody), $data);
  93. }
  94. if (empty($_POST['vvcid'])) html_error('PremiumDL: Captcha\'s vvcid not Found.');
  95. if (empty($_POST['captcha'])) html_error('PremiumDL: You didn\'t enter the image verification code.');
  96. $post = array('vvcid' => urlencode($_POST['vvcid']), 'verifycode' => urlencode($_POST['captcha']), 'prem_plus' => 'Next');
  97. $page = $this->GetPage($this->link, $this->cookie, $post);
  98. is_present($page, 'Wrong CAPTCHA', 'Incorrect CAPTCHA Answer.');
  99. return true;
  100. }
  101. private function loginTOTP(&$page) {
  102. if (empty($_POST['step']) || $_POST['step'] != '2') {
  103. if (strpos($page, "' name='user_otp_code'") === false) return false;
  104. // Found otp input field
  105. $data = $this->DefaultParamArr($this->link, $this->cookie, 1, 1);
  106. $data['step'] = '2';
  107. if ($this->pA) {
  108. $data['pA_encrypted'] = 'true';
  109. $data['premium_user'] = urlencode(encrypt($_REQUEST['premium_user']));
  110. $data['premium_pass'] = urlencode(encrypt($_REQUEST['premium_pass']));
  111. }
  112. echo "<form action='{$_SERVER['SCRIPT_NAME']}' method='POST'>\n";
  113. foreach ($data as $key => $value) echo "<input type='hidden' name='$key' value='" . htmlspecialchars($value, ENT_QUOTES) . "' />\n";
  114. echo 'Enter login TOTP' . ($this->pA ? ' for ' . htmlspecialchars($_REQUEST['premium_user']) : '') . ":<br />\n<input type='text' pattern='[0-9]{6}' name='totp_code' placeholder='Enter OTP token here' autofocus='autofocus' required='required' />\n<input type='submit' />\n</form>";
  115. return html_error('Login TOTP (Time-based One-Time Password) Required');
  116. }
  117. $_POST['step'] = false;
  118. if (empty($_POST['totp_code']) || !preg_match('/^\d{6}$/', $_POST['totp_code'])) html_error('Empty TOTP Code or Incomplete.');
  119. $page = $this->GetPage($this->baseUrl . '/', $this->cookie, array('user_otp_code' => $_POST['totp_code']));
  120. is_present($page, "' name='user_otp_code'", 'Incorrect Login TOTP Token.');
  121. $this->cookie = GetCookiesArr($page, $this->cookie); // Update cookies
  122. $this->cookie['sdlanguageid'] = '2';
  123. return true;
  124. }
  125. private function Login($user, $pass) {
  126. $post = array('login' => 'login');
  127. $post['loginemail'] = urlencode($user);
  128. $post['loginpassword'] = urlencode($pass);
  129. $post['submit'] = 'login';
  130. $post['rememberme'] = 'on';
  131. $page = $this->GetPage($this->baseUrl . '/', $this->cookie, $post);
  132. is_present($page, 'E-mail not found.', 'Login Error: Wrong Email.');
  133. is_present($page, 'Incorrect password', 'Login Error: Wrong Password.');
  134. $this->cookie = GetCookiesArr($page, $this->cookie); // Update cookies
  135. $this->cookie['sdlanguageid'] = '2';
  136. if (empty($this->cookie['sduserid'])) html_error('Login Error: "sduserid" cookie not found.');
  137. if (empty($this->cookie['sdpassword'])) html_error('Login Error: "sdpassword" cookie not found.');
  138. $this->SaveCookies($user, $pass); // Update cookies file
  139. if ($this->loginTOTP($page)) $this->SaveCookies($user, $pass);
  140. if (stripos($page, "<img src='/images/i_premium.png'") === false) {
  141. $this->changeMesg('<br /><b>Account isn\'t premium?</b>', true);
  142. $this->page = $this->GetPage($this->link, $this->cookie);
  143. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  144. $this->cookie['sdlanguageid'] = '2';
  145. return $this->FreeDL();
  146. } else return $this->PremiumDL();
  147. }
  148. private function IWillNameItLater($cookie, $decrypt = true) {
  149. if (!is_array($cookie)) {
  150. if (!empty($cookie)) return $decrypt ? decrypt(urldecode($cookie)) : urlencode(encrypt($cookie));
  151. return '';
  152. }
  153. if (count($cookie) < 1) return $cookie;
  154. $keys = array_keys($cookie);
  155. $values = array_values($cookie);
  156. $keys = $decrypt ? array_map('decrypt', array_map('urldecode', $keys)) : array_map('urlencode', array_map('encrypt', $keys));
  157. $values = $decrypt ? array_map('decrypt', array_map('urldecode', $values)) : array_map('urlencode', array_map('encrypt', $values));
  158. return array_combine($keys, $values);
  159. }
  160. private function CookieLogin($user, $pass, $filename = 'depfile_dl.php') {
  161. global $secretkey;
  162. if (empty($user) || empty($pass)) html_error('Login Failed: User or Password is empty.');
  163. $user = strtolower($user);
  164. $filename = DOWNLOAD_DIR . basename($filename);
  165. if (!file_exists($filename)) return $this->Login($user, $pass);
  166. $file = file($filename);
  167. $savedcookies = unserialize($file[1]);
  168. unset($file);
  169. $hash = hash('crc32b', $user.':'.$pass);
  170. if (is_array($savedcookies) && array_key_exists($hash, $savedcookies)) {
  171. $_secretkey = $secretkey;
  172. $secretkey = hash('crc32b', $pass).sha1($user.':'.$pass).hash('crc32b', $user); // A 56 char key should be safer. :D
  173. $testCookie = (decrypt(urldecode($savedcookies[$hash]['enc'])) == 'OK') ? $this->IWillNameItLater($savedcookies[$hash]['cookie']) : '';
  174. $secretkey = $_secretkey;
  175. if (empty($testCookie) || (is_array($testCookie) && count($testCookie) < 1)) return $this->Login($user, $pass);
  176. $page = $this->GetPage($this->baseUrl.'/', $testCookie);
  177. if (stripos($page, '\'/uploads/logout\'>') === false) return $this->Login($user, $pass);
  178. $this->cookie = GetCookiesArr($page, $testCookie); // Update cookies
  179. $this->cookie['sdlanguageid'] = '2';
  180. $this->SaveCookies($user, $pass); // Update cookies file
  181. if ($this->loginTOTP($page)) $this->SaveCookies($user, $pass);
  182. if (stripos($page, "<img src='/images/i_premium.png'") === false) {
  183. $this->changeMesg('<br /><b>Account isn\'t premium?</b>', true);
  184. $this->page = $this->GetPage($this->link, $this->cookie);
  185. $this->cookie = GetCookiesArr($this->page, $this->cookie);
  186. $this->cookie['sdlanguageid'] = '2';
  187. return $this->FreeDL();
  188. } else return $this->PremiumDL();
  189. }
  190. return $this->Login($user, $pass);
  191. }
  192. private function SaveCookies($user, $pass, $filename = 'depfile_dl.php') {
  193. global $secretkey;
  194. $maxdays = 31; // Max days to keep extra cookies saved
  195. $filename = DOWNLOAD_DIR . basename($filename);
  196. if (file_exists($filename)) {
  197. $file = file($filename);
  198. $savedcookies = unserialize($file[1]);
  199. unset($file);
  200. if (is_array($savedcookies)) {
  201. // Remove old cookies
  202. foreach ($savedcookies as $k => $v) if (empty($v['time']) || time() - $v['time'] >= ($maxdays * 24 * 60 * 60)) unset($savedcookies[$k]);
  203. } else $savedcookies = array();
  204. } else $savedcookies = array();
  205. $hash = hash('crc32b', $user.':'.$pass);
  206. $_secretkey = $secretkey;
  207. $secretkey = hash('crc32b', $pass).sha1($user.':'.$pass).hash('crc32b', $user); // A 56 char key should be safer. :D
  208. $savedcookies[$hash] = array('time' => time(), 'enc' => urlencode(encrypt('OK')), 'cookie' => $this->IWillNameItLater($this->cookie, false));
  209. $secretkey = $_secretkey;
  210. file_put_contents($filename, "<?php exit(); ?>\r\n" . serialize($savedcookies), LOCK_EX);
  211. }
  212. }
  213. // [28-4-2016] Written by Th3-822.
  214. ?>