Th3-822

[rapidleech][d] google_com.php

Dec 23rd, 2014
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.58 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once ("index.html");
  5.     exit();
  6. }
  7.  
  8. class google_com extends DownloadClass {
  9.     public $fNames = array('odt' => 'OpenDocument Text', 'docx' => 'Microsoft Word', 'rtf' => 'Rich Text Format', 'txt' => 'Plain Text', 'pdf' => 'PDF Document', 'epub' => 'EPUB Publication', 'zip' => 'Zipped html Document', 'pptx' => 'Microsoft PowerPoint', 'ods' => 'OpenDocument Spreadsheet', 'xlsx' => 'Microsoft Excel'), $dFormats = array('odt', 'docx', 'rtf', 'txt', 'pdf', 'epub', 'zip'), $pFormats = array('pptx', 'pdf'), $ssFormats = array('ods', 'xlsx', 'pdf', 'zip'), $sFormats = array(13 => 'ods', 420 => 'xlsx', 12 => 'pdf');
  10.     public function Download($link) {
  11.         $this->checkBug78902($link);
  12.         if (!preg_match('@https?://(?:[\w\-]+\.)*(?:drive|docs)\.google\.com/(?:(?:folderview|open|(?:a/[\w\-\.]+/)?uc)\?(?:[\w\-\%]+=[\w\-\%]*&)*id=|(?:folder|file|document|presentation|spreadsheets)/d/|spreadsheet/ccc\?(?:[\w\-\%]+=[\w\-\%]*&)*key=|drive/folders/)([\w\-]{28,})@i', $link, $this->ID)) html_error('File/Folder ID not found at link.');
  13.         $this->ID = $this->ID[1];
  14.  
  15.         // Use /open link for check if ID exists and also get it's type.
  16.         $page = $this->GetPage('https://drive.google.com/open?id='.$this->ID);
  17.         if (substr($page, 9, 3) == '404') html_error('File/Folder doesn\'t exists.');
  18.         if (substr($page, 9, 1) != '3' || !preg_match('@\nLocation: https?://(?:[\w\-]+\.)*(?:drive|docs)\.google\.com/(?:drive/)?(\w+)[\?/]@i', $page, $type)) html_error('Cannot find /open redirect.');
  19.  
  20.         switch (strtolower($type[1])) {
  21.             case 'file': $this->File();break;
  22.             case 'folder': case 'folders': case 'folderview': $this->Folder();break;
  23.             case 'document': $this->Document();break;
  24.             case 'presentation': $this->Presentation();break;
  25.             case 'spreadsheets': $this->Spreadsheets();break; // New spreadsheets
  26.             case 'spreadsheet': $this->Spreadsheet();break;
  27.             default: html_error('Unknown /open redirect.');break;
  28.         }
  29.     }
  30.  
  31.     private function checkBug78902($link = '') {
  32.         // 7.4 - 7.4.2, 7.3.11 - 7.3.14, 7.2.24 - 7.2.*
  33.         if (substr(PHP_OS, 0, 3) == 'WIN' || version_compare(PHP_VERSION, '7.2.24', '<') || version_compare(PHP_VERSION, '7.4.2', '>') || !version_compare(PHP_VERSION, '7.3.14', '<=')) return;
  34.  
  35.         if (empty($link)) echo('<div id="mesg" width="100%" align="center"></div><br />');
  36.         $this->changeMesg('Warning: Running on PHP v' . PHP_VERSION . ' (Please Upgrade)<br />Downloads with this PHP release will be affected by the bug <a href="https://bugs.php.net/bug.php?id=78902">#78902</a> and will leak RAM until exhausted.<br />File may stop at a random size (up to ~1 GB).');
  37.  
  38.         if (!empty($_GET['method']) && $_GET['method'] == '78902') return;
  39.         if (!empty($link)) {
  40.             $form = $this->DefaultParamArr($link);
  41.             $form['method'] = '78902';
  42.  
  43.             echo "\n<form name='f78902' action='{$_SERVER['SCRIPT_NAME']}' method='POST'>\n";
  44.             foreach ($form as $name => $input) echo "\t<input type='hidden' name='$name' id='$name' value='" . htmlspecialchars($input, ENT_QUOTES) . "' />\n";
  45.             echo "\t<div><br /><input type='submit' value='Continue' /></div></form>\n";
  46.             include(TEMPLATE_DIR.'footer.php');
  47.             exit();
  48.         }
  49.     }
  50.  
  51.     private function isPrivate($page) {
  52.         if (substr($page, 9, 2) == '30') is_present($page, 'Location: https://www.google.com/accounts/ServiceLogin', 'Private File/Folder.');
  53.         else is_present($page, "0; url='https://www.google.com/accounts/ServiceLogin", 'Private File/Folder.');
  54.     }
  55.  
  56.     private function File() {
  57.         $page = $this->GetPage('https://drive.google.com/uc?export=download&confirm=T822&id='.$this->ID, "download_warning_13058876669334088843_{$this->ID}=T822");
  58.         $this->isPrivate($page);
  59.         if (substr($page, 9, 1) != '3' || !preg_match('@\nLocation: (https?://(?:[\w\-]+\.)*googleusercontent\.com/[^\r\n]+)@i', $page, $dl)) html_error('File\'s download-link not found.');
  60.         $this->RedirectDownload($dl[1], 'fGoogle', 0, 0, 'https://drive.google.com/file/d/'.$this->ID);
  61.     }
  62.  
  63.     private function Folder() {
  64.         if (isset($_GET['audl'])) html_error('Cannot check folder in audl.');
  65.         $page = $this->GetPage('https://drive.google.com/drive/folders/'.$this->ID);
  66.         $this->isPrivate($page);
  67.         if (!preg_match_all('@\\\x5b\\\x22([\w\-]{28,})\\\x22,@i', $page, $ids) && !preg_match_all('@\[(\\\x22)([\w\-]{28,})\1,\[\1[\w\-]{28,}\1\]\\\n,\1(?>.*?\1),\1(?!application\\\/vnd\.google-apps\.folder)@i', $page, $ids, PREG_SET_ORDER)) html_error('Empty folder?');
  68.         $ids = $ids[1];
  69.         $links = array();
  70.         foreach ($ids as $id) $links[] = "https://drive.google.com/uc?id=$id&export=download";
  71.         $this->moveToAutoDownloader($links);
  72.     }
  73.  
  74.     private function Document() {
  75.         $url = 'https://docs.google.com/document/d/'.$this->ID;
  76.         $page = $this->GetPage("$url/edit");
  77.         $this->isPrivate($page);
  78.         if (empty($_GET['T8']['format']) && !isset($_GET['audl'])) $this->formatSelector(1);
  79.         $format = (!empty($_GET['T8']['format']) && in_array($_GET['T8']['format'], $this->dFormats)) ? $_GET['T8']['format'] : reset($this->dFormats);
  80.         $this->RedirectDownload("$url/export?format=$format", 'dGoogle', 0, 0, $url);
  81.     }
  82.  
  83.     private function Presentation() {
  84.         $url = 'https://docs.google.com/presentation/d/'.$this->ID;
  85.         $page = $this->GetPage("$url/edit");
  86.         $this->isPrivate($page);
  87.         if (empty($_GET['T8']['format']) && !isset($_GET['audl'])) $this->formatSelector(2);
  88.         $format = (!empty($_GET['T8']['format']) && in_array($_GET['T8']['format'], $this->pFormats)) ? $_GET['T8']['format'] : reset($this->pFormats);
  89.         $this->RedirectDownload("$url/export/$format", 'pGoogle', 0, 0, $url);
  90.     }
  91.  
  92.     private function Spreadsheets() {
  93.         $url = 'https://docs.google.com/spreadsheets/d/'.$this->ID;
  94.         $page = $this->GetPage("$url/edit");
  95.         $this->isPrivate($page);
  96.         if (empty($_GET['T8']['format']) && !isset($_GET['audl'])) $this->formatSelector(3);
  97.         $format = (!empty($_GET['T8']['format']) && in_array($_GET['T8']['format'], $this->ssFormats)) ? $_GET['T8']['format'] : reset($this->ssFormats);
  98.         $this->RedirectDownload("$url/export/$format", 'ssGoogle', 0, 0, $url);
  99.     }
  100.  
  101.     private function Spreadsheet() {
  102.         $url = 'https://docs.google.com/spreadsheet';
  103.         $page = $this->GetPage("$url/ccc?key=".$this->ID);
  104.         $this->isPrivate($page);
  105.         $cookie = GetCookiesArr($page);
  106.  
  107.         if (substr($page, 9, 1) != '3' || !preg_match('@\nLocation: (https?://(?:[\w\-]+\.)*google\.com/[^\r\n]+)@i', $page, $redir)) html_error("Redirect 1 not found");
  108.         $page = $this->GetPage($redir[1], $cookie);
  109.         $cookie = GetCookiesArr($page, $cookie);
  110.         if (empty($cookie['PREF'])) html_error("Cookie 'PREF' not found");
  111.  
  112.         $page = $this->GetPage("$url/ccc?key=".$this->ID, $cookie);
  113.  
  114.         if (empty($_GET['T8']['format']) && !isset($_GET['audl'])) $this->formatSelector(4);
  115.         if (empty($_GET['T8']['format']) || ($fmcmd = array_search($_GET['T8']['format'], $this->sFormats)) === false) {
  116.             reset($this->sFormats);
  117.             $fmcmd = key($this->sFormats);
  118.         }
  119.         if (($cmdUrl = cut_str($page, '/fm?id=', '"')) == false || !preg_match('@[\w\-\.]+@i', $cmdUrl, $cmdId)) html_error('Download ID not found.');
  120.         $this->RedirectDownload("$url/fm?id={$cmdId[0]}&fmcmd=$fmcmd", 'sGoogle', $cookie, 0, "$url/ccc?key=".$this->ID);
  121.     }
  122.  
  123.     private function formatSelector($type = 1) {
  124.         switch ($type) {
  125.             case 1: $tName = 'Document';$formats = $this->dFormats;break;
  126.             case 2: $tName = 'Presentation';$formats = $this->pFormats;break;
  127.             case 3: $tName = 'Spreadsheets';$formats = $this->ssFormats;break;
  128.             case 4: $tName = 'Spreadsheet';$formats = $this->sFormats;break;
  129.             default: html_error('formatSelector: Unknown type.');
  130.         }
  131.         if (count($formats) == 1) return $_GET['T8'] = array('format' => reset($formats));
  132.         echo "\n<br /><br /><h3 style='text-align: center;'>$tName format selector.</h4>";
  133.         echo "\n<center><form name='GD_FS' action='{$GLOBALS['PHP_SELF']}' method='POST'>\n";
  134.         echo "<select name='T8[format]' id='GD_ext'>\n";
  135.         foreach ($formats as $ext) echo "<option value='$ext'>".(!empty($this->fNames[$ext]) ? $this->fNames[$ext]." (.$ext)" : ".$ext")."</option>\n";
  136.         echo "</select>\n";
  137.         $data = $this->DefaultParamArr('https://drive.google.com/open?id='.$this->ID);
  138.         foreach ($data as $n => $v) echo("<input type='hidden' name='$n' id='FS_$n' value='$v' />\n");
  139.         echo "<input type='submit' name='Th3-822' value='".lang(209)."' />\n";
  140.         echo "</form></center>\n</body>\n</html>";
  141.         exit;
  142.     }
  143.  
  144.     // Add a Range header for get the filesize on chunked file downloads
  145.     public function RedirectDownload($link, $FileName = 0, $cookie = 0, $post = 0, $referer = 0, $force_name = 0, $auth = 0, $addon = array()) {
  146.         $referer .= "\r\nRange: bytes=0-";
  147.         return parent::RedirectDownload($link, $FileName, $cookie, $post, $referer, $force_name, $auth, $addon);
  148.     }
  149.  
  150.     public function CheckBack(&$headers) {
  151.         $this->checkBug78902();
  152.         if (substr($headers, 9, 3) == '416') html_error('[google_com.php] Plugin needs a fix, \'Range\' method is not working.');
  153.         if (stripos($headers, "\nTransfer-Encoding: chunked") !== false) {
  154.             global $fp, $sFilters;
  155.             if (empty($fp) || !is_resource($fp)) html_error('Error: Your rapidleech copy is outdated and it doesn\'t support functions required by this plugin.');
  156.             if (!in_array('dechunk', stream_get_filters())) html_error('Error: dechunk filter not available, cannot download chunked file.');
  157.             if (!isset($sFilters) || !is_array($sFilters)) $sFilters = array();
  158.             if (empty($sFilters['dechunk'])) $sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ);
  159.             if (!$sFilters['dechunk']) html_error('Error: Unknown error while initializing dechunk filter, cannot download chunked file.');
  160.             // Little hack to get the filesize.
  161.             $headers = preg_replace('@\nContent-Range\: bytes 0-\d+/@i', "\nContent-Length: ", $headers, 1);
  162.         }
  163.     }
  164. }
  165.  
  166. // [11-2-2014]  Written by Th3-822.
  167. // [23-12-2014]  Added support for new spreadsheets format/urls & Some workarounds to get filesize on chunked downloads... - Th3-822
  168. // [30-4-2018]  Fixed Folders. - Th3-822
Add Comment
Please, Sign In to add comment