Advertisement
Th3-822

[rapidleech][d] bayfiles_net.php

Jul 17th, 2012
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.44 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once ("index.html");
  5.     exit;
  6. }
  7.  
  8. class bayfiles_net extends DownloadClass {
  9.     private $link, $page, $cookie, $fid, $token;
  10.     public function Download($link) {
  11.         global $premium_acc;
  12.         $this->link = str_ireplace('bayfiles.com', 'bayfiles.net', $link);
  13.         $this->cookie = array();
  14.  
  15.         if (empty($_REQUEST['step']) || $_REQUEST['step'] != 1) { // Check link
  16.             $this->page = $this->GetPage($link);
  17.             is_present($this->page, 'Invalid security token', 'The link is incorrect or it has been deleted.');
  18.             is_present($this->page, 'The requested file could not be found.', 'The requested file could not be found. Please check the download link.');
  19.             $this->cookie = GetCookiesArr($this->page);
  20.             // Check direct link:
  21.             if (preg_match('@https?://([^/\'\"<>\r\n\s\t]+\.)?baycdn\.com/dl/[^\'\"<>\r\n\s\t]+@i', $this->page, $dlink)) {
  22.                 $FileName = urldecode(basename(parse_url(html_entity_decode($dlink[0]), PHP_URL_PATH)));
  23.                 return $this->RedirectDownload($dlink[0], $FileName, $this->cookie);
  24.             }
  25.         }
  26.  
  27.         if ($_REQUEST["premium_acc"] == "on" && ((!empty($_REQUEST["premium_user"]) && !empty($_REQUEST["premium_pass"])) || (!empty($premium_acc["bayfiles_net"]["user"]) && !empty($premium_acc["bayfiles_net"]["pass"])))) {
  28.             $this->Login();
  29.         } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == 1) {
  30.             $this->Captcha();
  31.         } else {
  32.             $this->Prepare();
  33.         }
  34.     }
  35.  
  36.     private function Prepare() {
  37.         is_present($this->page, 'has recently downloaded a file. Upgrade to premium or wait ', 'Your IP has recently downloaded a file. '.(($err = cut_str($this->page, 'Upgrade to premium or wait ', '.')) ? "Wait $err before trying again." : 'Try again later.'));
  38.         if (!preg_match('@var vfid = (\d+);@i', $this->page, $fid)) html_error("Error: Fileid not found");
  39.         $this->fid = $fid[1];
  40.  
  41.         $page = $this->GetPage('http://bayfiles.net/ajax_download?action=startTimer&vfid='.$this->fid);
  42.  
  43.         if (!preg_match('@"token":"([^\"]+)"@i', $page, $token)) html_error("Error: Countdown token not found");
  44.         $this->token = $token[1];
  45.  
  46.         if (!preg_match("@var delay = (\d+);@i", $this->page, $CD)) html_error("Error: Countdown not found");
  47.         $this->CountDown($CD[1]+2);
  48.  
  49.         // Uncomment next line when bayfiles have added a reCaptcha for download
  50.         // return $this->Captcha();
  51.  
  52.         $this->FreeDL();
  53.     }
  54.  
  55.     private function Captcha() {
  56.         if (isset($_REQUEST['step']) && $_REQUEST['step'] == 1) {
  57.             if (empty($_POST['fid']) || empty($_POST['fid']) || empty($_POST['cookie'])) html_error("Error: Invalid Captcha form data.");
  58.             if (empty($_POST['captcha'])) html_error("Error: You didn't enter the image verification code.");
  59.  
  60.             $this->cookie = decrypt(urldecode($_POST['cookie']));
  61.  
  62.             $post = array();
  63.             $post['action'] = 'verifyCaptcha';
  64.             $post['challenge'] = $_POST['challenge'];
  65.             $post['response'] = $_POST['captcha'];
  66.             $post['token'] = $this->token = $_POST['token'];
  67.             $this->fid = $_POST['fid'];
  68.  
  69.             $page = $this->GetPage('http://bayfiles.net/ajax_captcha', $this->cookie, $post);
  70.             is_present($page, 'Invalid captcha', 'Error: Wrong Captcha Entered.');
  71.  
  72.             if (!preg_match('@"token":"([^\"]+)"@i', $page, $token)) html_error("Error: Captcha token not found");
  73.             $this->token = $token[1];
  74.  
  75.             return $this->FreeDL();
  76.         } else {
  77.             $page = $this->GetPage('http://bayfiles.net/ajax_captcha', $this->cookie, array('action' => 'getCaptcha'));
  78.             if (!preg_match('@Recaptcha\.create\s*\(\s*[\"|\']([^\"|\'|\)]+)[\"|\']@i', $page, $pid)) html_error("Error: reCaptcha not found");
  79.  
  80.             $page = $this->GetPage("http://www.google.com/recaptcha/api/challenge?k=" . $pid[1]);
  81.             if (!preg_match('/challenge \: \'([^\']+)/i', $page, $ch)) html_error("Error getting Captcha data.");
  82.  
  83.             $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  84.             $data['challenge'] = $ch[1];
  85.             $data['fid'] = $this->fid;
  86.             $data['token'] = $this->token;
  87.             $data['step'] = '1';
  88.  
  89.             //Download captcha img.
  90.             $page = $this->GetPage("http://www.google.com/recaptcha/api/image?c=" . $ch[1]);
  91.             $capt_img = substr($page, strpos($page, "\r\n\r\n") + 4);
  92.             $imgfile = DOWNLOAD_DIR . "bayfiles_captcha.jpg";
  93.  
  94.             if (file_exists($imgfile)) unlink($imgfile);
  95.             if (!write_file($imgfile, $capt_img)) html_error("Error getting CAPTCHA image.", 0);
  96.  
  97.             $this->EnterCaptcha($imgfile.'?'.time(), $data, 20);
  98.             exit;
  99.         }
  100.     }
  101.  
  102.     private function FreeDL($act='getLink') {
  103.         $post = array('action' => $act, 'vfid' => $this->fid, 'token' => $this->token);
  104.         $page = $this->GetPage('http://bayfiles.net/ajax_download', $this->cookie, $post);
  105.  
  106.         if (!preg_match('@https?://([^/\'\"<>\r\n\s\t]+\.)?baycdn\.com/dl/[^\'\"<>\r\n\s\t]+@i', $page, $dlink)) html_error('Error: Download link not found');
  107.  
  108.         $FileName = urldecode(basename(parse_url(html_entity_decode($dlink[0]), PHP_URL_PATH)));
  109.         $this->RedirectDownload($dlink[0], $FileName, $this->cookie);
  110.     }
  111.  
  112.     private function PremiumDL() {
  113.         $page = $this->GetPage($this->link, $this->cookie);
  114.  
  115.         if (!preg_match('@https?://([^/\'\"<>\r\n\s\t]+\.)?baycdn\.com/dl/[^\'\"<>\r\n\s\t]+@i', $page, $dlink)) html_error('Error: Download link not found.');
  116.  
  117.         $FileName = urldecode(basename(parse_url(html_entity_decode($dlink[0]), PHP_URL_PATH)));
  118.         $this->RedirectDownload($dlink[0], $FileName, $this->cookie);
  119.     }
  120.  
  121.     private function Login() {
  122.         global $premium_acc;
  123.         if (!empty($_REQUEST["premium_user"]) && !empty($_REQUEST["premium_pass"])) $pA = true;
  124.         else $pA = false;
  125.         $user = ($pA ? $_REQUEST["premium_user"] : $premium_acc["bayfiles_net"]["user"]);
  126.         $pass = ($pA ? $_REQUEST["premium_pass"] : $premium_acc["bayfiles_net"]["pass"]);
  127.         if (empty($user) || empty($pass)) html_error("Login Failed: Username or Password are empty. Please check login data.");
  128.  
  129.         $post = array('action'=>'login','next'=>'%252F');
  130.         $post["username"] = urlencode($user);
  131.         $post["password"] = urlencode($pass);
  132.  
  133.         $page = $this->GetPage('http://bayfiles.net/ajax_login', $this->cookie, $post, 'http://bayfiles.net/');
  134.         is_present($page, 'Login failed. Please try again', 'Login Failed: Invalid username and/or password.');
  135.         if ($err = cut_str($page, '"error":"', '"')) html_error("Login Failed: $err.");
  136.         is_notpresent($page, 'Set-Cookie: SESSID=', 'Login Failed: Cannot get cookie.');
  137.         $this->cookie = array_merge($this->cookie, GetCookiesArr($page));
  138.  
  139.         $page = $this->GetPage('http://bayfiles.net/account', $this->cookie, 0, 'http://bayfiles.net/');
  140.         if (preg_match('@<div class="account-content">[\s|\t|\r|\n]+<p>((Normal)|(Premium))</p>@i', $page, $acctype) && $acctype[1] == 'Normal') {
  141.             $this->changeMesg(lang(300)."<br /><br /><b>Account isn\\\'t premium</b><br />Using Free Download.");
  142.             $this->page = $this->GetPage($this->link, $this->cookie);
  143.             return $this->Prepare();
  144.         }
  145.         return $this->PremiumDL();
  146.     }
  147.  
  148.     public function CheckBack($header) {
  149.         $statuscode = intval(substr($header, 9, 3));
  150.         if ($statuscode == 302) {
  151.             $length = trim(cut_str($header, "\r\nContent-Length: ", "\r\n"));
  152.             if (empty($length) || (strlen($length) <= 6 && intval($length) <= 102400)) {
  153.                 global $fp, $PHP_SELF;
  154.                 $page = '';
  155.                 while(strlen($data = @fread($fp, 16384)) > 0) $page .= $data;
  156.                 if (stripos($header, "\r\nTransfer-Encoding: chunked") !== false && function_exists('http_chunked_decode')) {
  157.                     $dechunked = http_chunked_decode($page);
  158.                     if ($dechunked !== false) $page = $dechunked;
  159.                     unset($dechunked);
  160.                 }
  161.                 $page = $header.$page;
  162.                 if (stripos($page, "\nyou need to wait 5 minutes between downloads") !== false) {
  163.                     insert_timer(10, 'Auto retry download:');//echo '<script type="text/javascript">location.reload();</script>';
  164.                     echo "<center><form name='retryf' action='$PHP_SELF' method='POST'>\n";
  165.                     if (!empty($_GET['proxy'])) $_GET['useproxy'] = 'on';
  166.                     $post = array(); // I can't reload because firefox shows an anoying alertbox.
  167.                     $post['filename'] = $_GET['filename'];
  168.                     if (!empty($_GET['force_name'])) $post['force_name'] = $_GET['force_name'];
  169.                     $post['host'] = $_GET['host'];
  170.                     $post['path'] = $_GET['path'];
  171.                     if (!empty($_GET['link'])) $post['link'] = $_GET['link'];
  172.                     if (!empty($_GET['referer'])) $post['referer'] = $_GET['referer'];
  173.                     if (!empty($_GET['post'])) $post['post'] = $_GET['post'];
  174.                     $post = array_merge($this->DefaultParamArr(), array_map('urlencode', $post));
  175.                     foreach ($post as $name => $input) echo "<input type='hidden' name='$name' id='$name' value='$input' />\n";
  176.                     echo "<input type='submit' value='Try Again' />\n";
  177.                     echo "</form></center><script type='text/javascript'>document.retryf.submit();</script><br />\n";
  178.                     html_error('You need to wait 5 minutes between downloads.');
  179.                 } elseif (stripos($page, "\ndownload link expired") !== false) {
  180.                     echo "<center><form action='$PHP_SELF' method='POST'>\n";
  181.                     $post = $this->DefaultParamArr(cut_str($header, 'Location: ', "\r\n"));
  182.                     $post['premium_acc'] = 'on';
  183.                     foreach ($post as $name => $input) echo "<input type='hidden' name='$name' id='$name' value='$input' />\n";
  184.                     echo "<input type='submit' value='Download Again' />\n";
  185.                     echo "</form></center><br />\n";
  186.                     html_error('Download link has expired.');
  187.                 }
  188.             }
  189.         }
  190.     }
  191. }
  192.  
  193. //[28-Jan-2012]  Written by Th3-822.
  194. //[01-Feb-2012]  Added premium support. -Th3-822
  195. //[17-Jul-2012]  Added support for direct links. - Th3-822
  196. //[10-Oct-2012]  Added checkback for show 2 error msgs and a autoretry/retry button. - Th3-822
  197. //[17-Jul-2013]  Updated for .net domain. - Th3-822
  198.  
  199. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement