Advertisement
Th3-822

[rapidleech][d] turbobit_net.php

Jan 9th, 2013
1,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.36 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once('index.html');
  5.     exit;
  6. }
  7.  
  8. class turbobit_net extends DownloadClass {
  9.     private $link, $page, $cookie, $pA, $RDregexp, $DLregexp;
  10.     public function Download($link) {
  11.         if (!preg_match('@^https?://(?:[^/]+\.)?turbobit\.(?:net|ru)/(?:download/free/)?(\w+)(?:\.html)?@i', str_ireplace('unextfiles.com', 'turbobit.net', $link), $id)) html_error('Error: Invalid link entered.');
  12.         $this->link = $GLOBALS['Referer'] = 'https://turbobit.net/' . $id[1] . '.html';
  13.         $this->pA = (empty($_REQUEST['premium_user']) || empty($_REQUEST['premium_pass']) ? false : true);
  14.         $this->cookie = array('user_lang' => 'en');
  15.         $this->RDregexp = '@(https?://(?:[^/\"\'\t\r\n<>]+\.)?turbobit\.(?:ru|net)(?:\:\d+)?)?//?download/redirect/[^\"\'\t\r\n<>]+@i';
  16.         $this->DLregexp = '@https?://s\d+\.turbobit\.(?:ru|net)(?:\:\d+)?/download\.php\?[^\"\'\t\r\n<>]+@i';
  17.  
  18.         if (empty($_POST['step'])) {
  19.             $this->page = $this->GetPage($this->link);
  20.             is_present($this->page, '>Our service is currently unavailable in your country.<', 'Turbobit is not available in your server\'s country.');
  21.             is_present($this->page, 'This document was not found in System', 'File Not Found.'); // 404
  22.             is_present($this->page, 'File not found. Probably it was deleted.', 'The requested file is not found.');
  23.             is_present($this->page, 'File was not found. It could possibly be deleted.', 'The requested file is not found');
  24.             $this->cookie = GetCookiesArr($this->page, $this->cookie);
  25.         }
  26.  
  27.         if (!empty($_REQUEST['premium_acc']) && $_REQUEST['premium_acc'] == 'on' && ($this->pA || (!empty($GLOBALS['premium_acc']['turbobit_net']['user']) && !empty($GLOBALS['premium_acc']['turbobit_net']['pass'])))) {
  28.             $user = ($this->pA ? $_REQUEST['premium_user'] : $GLOBALS['premium_acc']['turbobit_net']['user']);
  29.             $pass = ($this->pA ? $_REQUEST['premium_pass'] : $GLOBALS['premium_acc']['turbobit_net']['pass']);
  30.             if ($this->pA && !empty($_POST['pA_encrypted'])) {
  31.                 $user = decrypt(urldecode($user));
  32.                 $pass = decrypt(urldecode($pass));
  33.                 unset($_POST['pA_encrypted']);
  34.             }
  35.             return $this->CookieLogin($user, $pass);
  36.         } else {
  37.             $this->link = 'https://turbobit.net/download/free/' . $id[1];
  38.             return $this->FreeDL();
  39.         }
  40.     }
  41.  
  42.     private function FreeDL() {
  43.         $_POST['step'] = empty($_POST['step']) ? '' : $_POST['step'];
  44.         switch ($_POST['step']) {
  45.             case '1': { // Send Captcha && Get Countdown
  46.                 if (empty($_POST['captcha'])) html_error('You didn\'t enter the image-verification code.');
  47.                 $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  48.  
  49.                 $post = array();
  50.                 $post['captcha_response'] = urlencode($_POST['captcha']);
  51.                 $post['captcha_type'] = urlencode($_POST['c_type']);
  52.                 $post['captcha_subtype'] = (!empty($_POST['c_subtype']) ? urlencode($_POST['c_subtype']) : '');
  53.                 $page = $this->GetPage($this->link, $this->cookie, $post);
  54.  
  55.                 is_present($page, 'Incorrect, try again!', 'Error: Wrong CAPTCHA entered.');
  56.                 is_present($page, 'Looks like your browser has disabled cookies.', 'Error: Invalid cookies.');
  57.  
  58.                 if (!preg_match('@\W(?:min)?Limit[\s\t]*:[\s\t]*([\d\s\t\r\n\+\-\*/\(\)]+)[\s\t]*[\,\;]@i', $page, $count)) html_error('Countdown not found.');
  59.                 $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  60.                 $data['step'] = '2';
  61.                 return $this->JSCountdown($count[1], $data);
  62.                 break;
  63.             }
  64.             case '2': { // Download
  65.                 $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  66.                 $page = $this->GetPage(str_replace('/download/free/', '/download/getLinkTimeout/', $this->link), $this->cookie, 0, $this->link . "\r\nX-Requested-With: XMLHttpRequest");
  67.  
  68.                 if (preg_match($this->RDregexp, $page, $redir)) {
  69.                     $redir = (empty($redir[1])) ? 'https://turbobit.net'.$redir[0] : $redir[0];
  70.                     $page = $this->GetPage($redir, $this->cookie, 0, $this->link);
  71.                     if (!preg_match($this->DLregexp, $page, $dllink)) html_error('Download-Link not Found.');
  72.                 } elseif (!preg_match($this->DLregexp, $page, $dllink)) html_error('Redirect-Link not Found.');
  73.                 return $this->RedirectDownload(html_entity_decode($dllink[0]), 'turbobit_fr', $this->cookie);
  74.                 break;
  75.             }
  76.             default : { // Get Captcha
  77.                 $page = $this->GetPage($this->link, $this->cookie);
  78.  
  79.                 if (preg_match('@\W(?:min)?Limit[\s\t]*:[\s\t]*([\d\s\t\r\n\+\-\*/\(\)]+)[\s\t]*[\,\;]@i', $page, $count)) {
  80.                     $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  81.                     $this->JSCountdown($count[1], $data, 'FreeDL limit reached');
  82.                 }
  83.  
  84.                 if (!preg_match('@(?:id|class)="g-recaptcha"\s+data-sitekey="([\w\.\-]+)"@i', $page, $pid)) html_error('Error: reCAPTCHA2 not found.');
  85.  
  86.                 if (!preg_match('@\Wvalue\s*=\s*[\'\"]([^\'\"\r\n<>]+)[\'\"]\s+name\s*=\s*[\'\"]captcha_type[\'\"]@i', $page, $c_type) || !preg_match('@\Wvalue\s*=\s*[\'\"]([^\'\"\r\n<>]*)[\'\"]\s+name\s*=\s*[\'\"]captcha_subtype[\'\"]@i', $page, $c_subtype)) html_error('CAPTCHA data not found');
  87.  
  88.                 $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  89.                 $data['step'] = '1';
  90.                 $data['c_type'] = urlencode($c_type[1]);
  91.                 $data['c_subtype'] = urlencode($c_subtype[1]);
  92.  
  93.                 return $this->reCAPTCHAv2($pid[1], $data);
  94.             }
  95.         }
  96.     }
  97.  
  98.     private function PremiumDL() {
  99.         $page = $this->GetPage($this->link, $this->cookie);
  100.         if (preg_match($this->RDregexp, $page, $redir)) {
  101.             $redir = (empty($redir[1])) ? 'https://turbobit.net'.$redir[0] : $redir[0];
  102.             $page = $this->GetPage($redir, $this->cookie);
  103.  
  104.             if (!preg_match($this->DLregexp, $page, $dllink)) html_error('Download Link not Found.');
  105.         } elseif (!preg_match($this->DLregexp, $page, $dllink)) html_error('Redirect Link not Found.');
  106.         $this->RedirectDownload(html_entity_decode($dllink[0]), 'turbobit_pr', $this->cookie);
  107.     }
  108.  
  109.     private function Login($user, $pass) {
  110.         $purl = 'https://turbobit.net/';
  111.         $post = array();
  112.         $post['user%5Blogin%5D'] = urlencode($user);
  113.         $post['user%5Bpass%5D'] = urlencode($pass);
  114.         $post['user%5Bmemory%5D'] = 'on';
  115.         $post['user%5Bsubmit%5D'] = 'Login';
  116.         $page = $this->GetPage($purl.'user/login', $this->cookie, $post, $purl.'login');
  117.         $this->cookie = GetCookiesArr($page, $this->cookie);
  118.  
  119.         $x = 0;
  120.         while ($x < 3 && stripos($page, "\nLocation: ") !== false && preg_match('@\nLocation: ((https?://[^/\r\n]+)?/[^\r\n]*)@i', $page, $redir)) {
  121.             $redir = (empty($redir[2])) ? 'https://turbobit.net'.$redir[1] : $redir[1];
  122.             $page = $this->GetPage($redir, $this->cookie);
  123.             $this->cookie = GetCookiesArr($page, $this->cookie);
  124.             $x++;
  125.         }
  126.         if ($x < 1) html_error('Login Redirect not Found');
  127.  
  128.         is_present($page, 'Incorrect login or password', 'Login Failed: Login/Password incorrect');
  129.         is_present($page, 'E-Mail address appears to be invalid.', 'Login Failed: Invalid E-Mail');
  130.         is_present($page, 'Username(Email) does not exist', 'Login Failed: E-Mail is not registered.');
  131.         // is_present($page, 'Limit of login attempts exceeded for your account. It has been temporarily locked.', 'Login Failed: Account Temporally Locked');
  132.  
  133.         is_present($page, 'Please enter the captcha code.', 'CAPTCHA not supported.');
  134.         if (empty($this->cookie['user_isloggedin'])) html_error('Login Error: Cookie "user_isloggedin" not found or empty.');
  135.         is_notpresent($page, '/user/logout', 'Login Failed.');
  136.  
  137.         $this->SaveCookies($user, $pass); // Update cookies file
  138.         is_present($page, '<u>Turbo Access</u> denied', 'Login Failed: Account isn\'t premium');
  139.         return $this->PremiumDL();
  140.     }
  141.  
  142.     private function IWillNameItLater($cookie, $decrypt=true) {
  143.         if (!is_array($cookie)) {
  144.             if (!empty($cookie)) return $decrypt ? decrypt(urldecode($cookie)) : urlencode(encrypt($cookie));
  145.             return '';
  146.         }
  147.         if (count($cookie) < 1) return $cookie;
  148.         $keys = array_keys($cookie);
  149.         $values = array_values($cookie);
  150.         $keys = $decrypt ? array_map('decrypt', array_map('urldecode', $keys)) : array_map('urlencode', array_map('encrypt', $keys));
  151.         $values = $decrypt ? array_map('decrypt', array_map('urldecode', $values)) : array_map('urlencode', array_map('encrypt', $values));
  152.         return array_combine($keys, $values);
  153.     }
  154.  
  155.     private function CookieLogin($user, $pass, $filename = 'turbobit_dl.php') {
  156.         global $secretkey;
  157.         if (empty($user) || empty($pass)) html_error('Login Failed: User or Password is empty.');
  158.  
  159.         $filename = DOWNLOAD_DIR . basename($filename);
  160.         if (!file_exists($filename)) return $this->Login($user, $pass);
  161.  
  162.         $file = file($filename);
  163.         $savedcookies = unserialize($file[1]);
  164.         unset($file);
  165.  
  166.         $hash = hash('crc32b', $user.':'.$pass);
  167.         if (array_key_exists($hash, $savedcookies)) {
  168.             $_secretkey = $secretkey;
  169.             $secretkey = sha1($user.':'.$pass);
  170.             $testCookie = (decrypt(urldecode($savedcookies[$hash]['enc'])) == 'OK') ? $this->IWillNameItLater($savedcookies[$hash]['cookie']) : '';
  171.             $secretkey = $_secretkey;
  172.             if (empty($testCookie) || (is_array($testCookie) && count($testCookie) < 1)) return $this->Login($user, $pass);
  173.  
  174.             $page = $this->GetPage('https://turbobit.net/', $testCookie);
  175.             if (stripos($page, '/user/logout') === false) return $this->Login($user, $pass);
  176.             $this->cookie = GetCookiesArr($page, $testCookie); // Update cookies
  177.             $this->SaveCookies($user, $pass); // Update cookies file
  178.             is_present($page, '<u>Turbo Access</u> denied', 'Account isn\'t premium.');
  179.             return $this->PremiumDL();
  180.         }
  181.         return $this->Login($user, $pass);
  182.     }
  183.  
  184.     private function SaveCookies($user, $pass, $filename = 'turbobit_dl.php') {
  185.         global $secretkey;
  186.         $maxdays = 31; // Max days to keep cookies saved
  187.         $filename = DOWNLOAD_DIR . basename($filename);
  188.         if (file_exists($filename)) {
  189.             $file = file($filename);
  190.             $savedcookies = unserialize($file[1]);
  191.             unset($file);
  192.  
  193.             // Remove old cookies
  194.             foreach ($savedcookies as $k => $v) if (time() - $v['time'] >= ($maxdays * 24 * 60 * 60)) unset($savedcookies[$k]);
  195.         } else $savedcookies = array();
  196.         $hash = hash('crc32b', $user.':'.$pass);
  197.         $_secretkey = $secretkey;
  198.         $secretkey = sha1($user.':'.$pass);
  199.         $savedcookies[$hash] = array('time' => time(), 'enc' => urlencode(encrypt('OK')), 'cookie' => $this->IWillNameItLater($this->cookie, false));
  200.         $secretkey = $_secretkey;
  201.  
  202.         file_put_contents($filename, "<?php exit(); ?>\r\n" . serialize($savedcookies), LOCK_EX);
  203.     }
  204. }
  205.  
  206. //[09-1-2013] Written by Th3-822.
  207. //[07-6-2013] Added login recaptcha support. - Th3-822
  208. //[12-2-2017] Removed CAPTCHA (Unsupported ATM) and Fixed Login. - Th3-822
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement