Advertisement
Th3-822

[rapidleech][d] alfafile_net

Dec 20th, 2015
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.70 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once('index.html');
  5.     exit;
  6. }
  7.  
  8. class alfafile_net extends DownloadClass {
  9.     private $page, $cookie = array('lang' => 'en'), $pA, $login, $DLRegexp = '@https?://a\d+\.alfafile\.net/dl/\w+/[^\t\r\n\'\"<>]+@i';
  10.     public function Download($link) {
  11.         if (!preg_match('@(https?://alfafile\.net)/file/(\w+)@i', str_ireplace('://www.alfafile.net', '://alfafile.net', $link), $fid)) html_error('Invalid link?.');
  12.         $this->link = str_ireplace('http://', 'https://', $fid[0]);
  13.         $this->baseurl = $fid[1];
  14.         $this->fid = $fid[2];
  15.  
  16.         if (empty($_POST['step'])) {
  17.             $this->page = $this->GetPage($this->link, $this->cookie);
  18.             if (substr($this->page, 9, 3) == '404') html_error('File Not Found.');
  19.             $this->cookie = GetCookiesArr($this->page, $this->cookie);
  20.         }
  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']['alfafile_net']['user']) && !empty($GLOBALS['premium_acc']['alfafile_net']['pass']))))) {
  24.             $user = ($this->pA ? $_REQUEST['premium_user'] : $GLOBALS['premium_acc']['alfafile_net']['user']);
  25.             $pass = ($this->pA ? $_REQUEST['premium_pass'] : $GLOBALS['premium_acc']['alfafile_net']['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->Login($user, $pass);
  32.         } else return $this->AnonDL();
  33.     }
  34.  
  35.     private function AnonDL() {
  36.         if (empty($_POST['step']) || $_POST['step'] != '1') {
  37.             $page = $this->GetPage($this->baseurl . '/download/start_timer/' . $this->fid, $this->cookie, 0, $this->link . "\r\nX-Requested-With: XMLHttpRequest");
  38.             $this->cookie = GetCookiesArr($page, $this->cookie);
  39.             $start_timer = $this->json2array($page, 'StartTimer Error');
  40.  
  41.             if (empty($start_timer) || (empty($start_timer['show_timer']) && empty($start_timer['redirect_url']))) {
  42.                 if (!empty($start_timer['html'])) {
  43.                     if (preg_match('@Delay between downloads must be not less than \d+ minutes.\s+Try again in \d+ minutes@i', $page, $err)) html_error("[AnonDL] {$err[0]}");
  44.                     html_error('Error @ StartTimer: ' . htmlspecialchars(strip_tags($start_timer['html']), ENT_QUOTES));
  45.                 } else { //  if (substr($page, 9, 3) == '200')
  46.                     textarea($start_timer);
  47.                     html_error('Unknown error @ StartTimer');
  48.                 }
  49.             }
  50.             if (strpos($start_timer['redirect_url'], '://') === false) $start_timer['redirect_url'] = $this->baseurl . $start_timer['redirect_url'];
  51.  
  52.             if (!empty($start_timer['show_timer']) && $start_timer['timer'] > 0) $this->CountDown($start_timer['timer']);
  53.  
  54.             $page = $this->GetPage($start_timer['redirect_url'], $this->cookie, 0, $this->link);
  55.             $this->cookie = GetCookiesArr($page, $this->cookie);
  56.  
  57.             if (!preg_match('@https?://api(?:-secure)?\.solvemedia\.com/papi/challenge\.(?:no)?script\?k=([\w\-\.]+)@i', $page, $smKey)) {
  58.                 if (preg_match($this->DLRegexp, $page, $DL)) return $this->RedirectDownload($DL[0], urldecode(parse_url($DL[0], PHP_URL_PATH)));
  59.                 html_error('CAPTCHA not found.');
  60.             }
  61.  
  62.             $data = $this->DefaultParamArr($this->link, $this->cookie, $start_timer['redirect_url'], true);
  63.             $data['step'] = '1';
  64.             $data['posturl'] = urldecode(parse_url($start_timer['redirect_url'], PHP_URL_PATH));
  65.             return $this->SolveMedia($smKey[1], $data, $start_timer['redirect_url']);
  66.         } else {
  67.             $post = $this->verifySolveMedia();
  68.             $post['send'] = 'Submit';
  69.             $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  70.  
  71.             $page = $this->GetPage($this->baseurl . $_POST['posturl'], $this->cookie, $post);
  72.             $this->cookie = GetCookiesArr($page, $this->cookie);
  73.  
  74.             if (preg_match("@\nLocation: (?:https?://(?:www\.)?alfafile\.net)?/file/{$this->fid}/?\r?\n@i", $page)) {
  75.                 $page = $this->GetPage($this->link, $this->cookie);
  76.             }
  77.  
  78.             if (!preg_match($this->DLRegexp, $page, $DL)) html_error('Download Link Not Found.');
  79.  
  80.             return $this->RedirectDownload($DL[0], urldecode(parse_url($DL[0], PHP_URL_PATH)));
  81.         }
  82.     }
  83.  
  84.     private function ApiDL() {
  85.         $DL = $this->ApiReq('file/download', array('file_id' => $this->fid));
  86.  
  87.         if (empty($DL['download_url'])) html_error('Download-Link Not Found.');
  88.  
  89.         return $this->RedirectDownload($DL['download_url'], urldecode(parse_url($DL['download_url'], PHP_URL_PATH)));
  90.     }
  91.  
  92.     private function Login($user, $pass) {
  93.         $this->login = $this->ApiReq('user/login', array('login' => $user, 'password' => $pass));
  94.         if (empty($this->login['token'])) html_error('Login Token Not Found.');
  95.         if (empty($this->login['user'])) html_error('User Data Not Found.');
  96.         if (empty($this->login['user']['is_premium'])) $this->changeMesg('<br /><b>Account isn\'t premium</b>', true);
  97.  
  98.         return $this->ApiDL();
  99.     }
  100.  
  101.     private function ApiReq($path, $post = array()) {
  102.         if (!is_array($post)) $post = array();
  103.         if ($path != 'user/login' && !empty($this->login['token'])) $post['token'] = $this->login['token'];
  104.  
  105.         $page = $this->GetPage("https://alfafile.net/api/v1/$path", 0, array_map('urlencode', $post), 'https://alfafile.net/');
  106.         $reply = $this->json2array($page, "ApiReq($path) Error");
  107.  
  108.         if (empty($reply['response']) && !empty($reply['details'])) html_error("[ApiReq($path) Error] " . htmlspecialchars($reply['details'], ENT_QUOTES));
  109.  
  110.         return $reply['response'];
  111.     }
  112.  
  113.     private function json2array($content, $errorPrefix = 'Error') {
  114.         if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.');
  115.         if (empty($content)) return NULL;
  116.         $content = ltrim($content);
  117.         if (($pos = strpos($content, "\r\n\r\n")) > 0) $content = trim(substr($content, $pos + 4));
  118.         $cb_pos = strpos($content, '{');
  119.         $sb_pos = strpos($content, '[');
  120.         if ($cb_pos === false && $sb_pos === false) html_error("[$errorPrefix]: JSON start braces not found.");
  121.         $sb = ($cb_pos === false || $sb_pos < $cb_pos) ? true : false;
  122.         $content = substr($content, strpos($content, ($sb ? '[' : '{')));$content = substr($content, 0, strrpos($content, ($sb ? ']' : '}')) + 1);
  123.         if (empty($content)) html_error("[$errorPrefix]: No JSON content.");
  124.         $rply = json_decode($content, true);
  125.         if ($rply === NULL) html_error("[$errorPrefix]: Error reading JSON.");
  126.         return $rply;
  127.     }
  128.  
  129.     // Special Function Called by verifySolveMedia When Captcha Is Incorrect, To Allow Retry. - Optional
  130.     protected function retrySolveMedia() {
  131.         $data = $this->DefaultParamArr($this->link);
  132.         $data['cookie'] = (!empty($_POST['cookie']) ? $_POST['cookie'] : '');
  133.         $data['step'] = '1';
  134.         $data['posturl'] = $_POST['posturl'];
  135.  
  136.         return $this->SolveMedia($_POST['sm_public_key'], $data, $this->baseurl . $_POST['posturl']);
  137.     }
  138. }
  139.  
  140. //[20-12-2015]  Written by Th3-822.
  141.  
  142. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement