public function Download($link) { $this->cookie = isset($_POST['yt_QS']) && !empty($_POST['cookie']) ? StrToCookies(decrypt(urldecode($_POST['cookie']))) : array(); $url = parse_url($link); $this->vid = array(); if (host_matches('youtu.be', $url['host'])) { preg_match('@/([\\w\\-\\.]{11})@i', $url['path'], $this->vid); } elseif (empty($url['query']) || ($this->vid[1] = cut_str('&' . $url['query'] . '&', '&v=', '&')) === false || !preg_match('@^[\\w\\-\\.]{11}$@i', $this->vid[1])) { preg_match('@/(?:v|(?:embed))/([\\w\\-\\.]{11})@i', $url['path'], $this->vid); } if (empty($this->vid[1])) { html_error('Video ID not found.'); } $this->vid = $this->vid[1]; $this->link = 'https://www.youtube.com/watch?v=' . $this->vid; $this->getFmtMaps(); $this->fmturlmaps = $this->GetVideosArr(); $yt_fmt = empty($_REQUEST['yt_fmt']) ? '' : $_REQUEST['yt_fmt']; if (empty($yt_fmt) && !isset($_GET['audl'])) { return $this->QSelector(); } elseif (isset($_REQUEST['ytube_mp4']) && $_REQUEST['ytube_mp4'] == 'on' && !empty($yt_fmt)) { //look for and download the highest quality we can find? if ($yt_fmt == 'highest') { foreach ($this->fmts as $fmt) { if (array_key_exists($fmt, $this->fmturlmaps)) { $furl = $this->fmturlmaps[$fmt]; break; } } } elseif (!($furl = $this->fmturlmaps[$yt_fmt])) { html_error('Specified video format not found'); } else { $fmt = $yt_fmt; } } else { //just get the one Youtube plays by default (in some cases it could also be the highest quality format) $fmt = key($this->fmturlmaps); $furl = $this->fmturlmaps[$fmt]; } $ext = '.flv'; $fmtexts = array('.mp4' => array(18, 22, 37, 38), '.webm' => array(43, 44, 45, 46), '.3gp' => array(36, 17)); foreach ($fmtexts as $k => $v) { if (!is_array($v)) { $v = array($v); } if (in_array($fmt, $v)) { $ext = $k; break; } } if (empty($this->response['title'])) { html_error('No video title found! Download halted.'); } $FileName = str_replace(str_split('\\\\:*?"<>|=;' . "\t\r\n\f"), '_', html_entity_decode(trim($this->response['title']), ENT_QUOTES)); if (!empty($_REQUEST['cleanname'])) { $FileName = preg_replace('@[^ A-Za-z_\\-\\d\\.,\\(\\)\\[\\]\\{\\}&\\!\'\\@\\%\\#]@u', '_', $FileName); } $FileName .= " [YT-f{$fmt}][{$this->vid}]{$ext}"; $this->RedirectDownload($furl, $FileName, $this->cookie, 0, 0, $FileName); }
$auth = urlencode(encrypt(base64_encode(rawurlencode($Url['user']) . ':' . rawurlencode($Url['pass'])))); unset($Url['user'], $Url['pass']); } elseif (empty($Url['user']) xor empty($Url['pass'])) { unset($Url['user'], $Url['pass']); } $LINK = rebuild_url($Url); if (!in_array($Url['scheme'], array('http', 'https', 'ftp'))) { echo "<script type='text/javascript'>updateStatus({$i}, '" . lang(24) . "');</script>{$nn}"; } else { require_once TEMPLATE_DIR . '/transloadui.php'; echo "<div id='progress{$i}' style='display:block;'>{$nn}"; $isHost = false; $redir = $lastError = ''; $GLOBALS['throwRLErrors'] = true; foreach ($host as $site => $file) { if (host_matches($site, $Url['host'])) { //if (preg_match("/^(.+\.)?".$site."$/i", $Url['host'])) { $isHost = true; try { require_once HOST_DIR . 'DownloadClass.php'; require_once HOST_DIR . 'download/' . $file; $class = substr($file, 0, -4); $firstchar = substr($file, 0, 1); if ($firstchar > 0) { $class = "d{$class}"; } if (class_exists($class)) { $hostClass = new $class(false); $hostClass->Download($LINK); } } catch (Exception $e) {
public function Download($link) { $this->cookie = isset($_POST['yt_QS']) && !empty($_POST['cookie']) ? StrToCookies(decrypt(urldecode($_POST['cookie']))) : array(); $url = parse_url($link); $this->vid = array(); if (host_matches('youtu.be', $url['host'])) { preg_match('@/([\\w\\-\\.]{11})@i', $url['path'], $this->vid); } elseif (empty($url['query']) || ($this->vid[1] = cut_str('&' . $url['query'] . '&', '&v=', '&')) === false || !preg_match('@^[\\w\\-\\.]{11}$@i', $this->vid[1])) { preg_match('@/(?:v|(?:embed))/([\\w\\-\\.]{11})@i', $url['path'], $this->vid); } if (empty($this->vid[1])) { html_error('Video ID not found.'); } $this->vid = $this->vid[1]; $link = 'http://www.youtube.com/watch?v=' . $this->vid; $this->page = $this->GetPage('http://www.youtube.com/get_video_info?video_id=' . $this->vid . '&asv=3&el=detailpage&hl=en_US', $this->cookie); $response = array_map('urldecode', $this->FormToArr(substr($this->page, strpos($this->page, "\r\n\r\n") + 4))); if (!empty($response['reason'])) { html_error('[' . htmlentities($response['errorcode']) . '] ' . htmlentities($response['reason'])); } if (isset($_REQUEST['step']) || preg_match('@Location: https?://(www\\.)?youtube\\.com/das_captcha@i', $this->page)) { $this->captcha($link); } if (empty($response['url_encoded_fmt_stream_map'])) { html_error('Video links not found.'); } $fmt_url_maps = explode(',', $response['url_encoded_fmt_stream_map']); $this->fmts = array(38, 37, 22, 45, 35, 44, 34, 43, 18, 5, 17); $yt_fmt = empty($_REQUEST['yt_fmt']) ? '' : $_REQUEST['yt_fmt']; $this->fmturlmaps = $this->GetVideosArr($fmt_url_maps); if (empty($yt_fmt) && !isset($_GET['audl'])) { return $this->QSelector($link); } elseif (isset($_REQUEST['ytube_mp4']) && $_REQUEST['ytube_mp4'] == 'on' && !empty($yt_fmt)) { //look for and download the highest quality we can find? if ($yt_fmt == 'highest') { foreach ($this->fmts as $fmt) { if (array_key_exists($fmt, $this->fmturlmaps)) { $furl = $this->fmturlmaps[$fmt]; break; } } } elseif (!($furl = $this->fmturlmaps[$yt_fmt])) { html_error('Specified video format not found'); } else { $fmt = $yt_fmt; } } else { //just get the one Youtube plays by default (in some cases it could also be the highest quality format) $fmt = key($this->fmturlmaps); $furl = $this->fmturlmaps[$fmt]; } $ext = '.flv'; $fmtexts = array('.3gp' => array(17), '.mp4' => array(18, 22, 37, 38), '.webm' => array(43, 44, 45)); foreach ($fmtexts as $k => $v) { if (!is_array($v)) { $v = array($v); } if (in_array($fmt, $v)) { $ext = $k; break; } } if (empty($response['title'])) { html_error('No video title found! Download halted.'); } $FileName = str_replace(str_split('\\/:*?"<>|'), '_', html_entity_decode(trim($response['title']), ENT_QUOTES)) . "-[YT-f{$fmt}][{$this->vid}]{$ext}"; if (isset($_REQUEST['ytdirect']) && $_REQUEST['ytdirect'] == 'on') { echo "<br /><br /><h4><a style='color:yellow' href='" . urldecode($furl) . "'>Click here or copy the link to your download manager to download</a></h4> (This may not work)"; echo "<input name='dlurl' style='width: 1000px; border: 1px solid #55AAFF; background-color: #FFFFFF; padding:3px' value='" . urldecode($furl) . "' onclick='javascript:this.select();' readonly></input>"; } else { $this->RedirectDownload($furl, $FileName, $this->cookie, 0, 0, $FileName); } }
function check_referer() { $refhost = !empty($_SERVER['HTTP_REFERER']) ? cut_str($_SERVER['HTTP_REFERER'], '://', '/') : false; if (empty($refhost)) { return; } //Remove the port. $httphost = ($pos = strpos($_SERVER['HTTP_HOST'], ':')) !== false ? substr($_SERVER['HTTP_HOST'], 0, $pos) : $_SERVER['HTTP_HOST']; $refhost = ($pos = strpos($refhost, ':')) !== false ? substr($refhost, 0, $pos) : $refhost; // If there is a login on the referer, remove it. $refhost = ($pos = strpos($refhost, '@')) !== false ? substr($refhost, $pos + 1) : $refhost; $whitelist = array($httphost, 'localhost', 'rapidleech.com'); $is_ext = $refhost == $_SERVER['SERVER_ADDR'] ? false : true; if ($is_ext) { foreach ($whitelist as $host) { if (host_matches($host, $refhost)) { $is_ext = false; break; } } } if ($is_ext) { // Uncomment next line if you want rickroll the users from Form leechers. // header("Location: http://www.youtube.com/watch?v=oHg5SJYRHA0"); html_error(sprintf(lang(7), $refhost, 'External referer not allowed.')); } }
function geturl($host, $port, $url, $referer = 0, $cookie = 0, $post = 0, $saveToFile = 0, $proxy = 0, $pauth = 0, $auth = 0, $scheme = 'http', $resume_from = 0, $XMLRequest = 0) { global $nn, $lastError, $Resume, $bytesReceived, $fp, $fs, $force_name, $options, $sFilters; $scheme = strtolower($scheme) . '://'; if ($post !== 0 && ($scheme == 'http://' || $scheme == 'https://')) { $method = 'POST'; $postdata = is_array($post) ? formpostdata($post) : $post; } else { $method = 'GET'; $postdata = ''; } if (!empty($cookie)) { if (is_array($cookie)) { $cookies = count($cookie) > 0 ? CookiesToStr($cookie) : 0; } else { $cookies = trim($cookie); } } if ($scheme == 'https://') { if (!extension_loaded('openssl')) { html_error('You need to install/enable PHP\'s OpenSSL extension to support downloading via HTTPS.'); } $scheme = 'tls://'; if ($port == 0 || $port == 80) { $port = 443; } } if ($proxy) { list($proxyHost, $proxyPort) = explode(':', $proxy, 2); $host = $host . ($port != 80 && ($scheme != 'tls://' || $port != 443) ? ':' . $port : ''); $url = "{$scheme}{$host}{$url}"; } if ($scheme != 'tls://') { $scheme = ''; } $request = array(); $request[] = $method . ' ' . str_replace(' ', '%20', $url) . ' HTTP/1.1'; $request[] = "Host: {$host}"; $request[] = 'User-Agent: ' . rl_UserAgent; $request[] = 'Accept: */*'; $request[] = 'Accept-Language: en-US,en;q=0.9'; $request[] = 'Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7'; if (!empty($referer)) { $request[] = "Referer: {$referer}"; } if (!empty($cookies)) { $request[] = "Cookie: {$cookies}"; } $request[] = 'Pragma: no-cache'; $request[] = 'Cache-Control: no-cache'; // if ($Resume['use'] === TRUE) $request[] = 'Range: bytes=' . $Resume['from'] . '-'; if (!empty($auth)) { $request[] = "Authorization: Basic {$auth}"; } if (!empty($pauth)) { $request[] = "Proxy-Authorization: Basic {$pauth}"; } if ($method == 'POST') { if (!empty($referer) && stripos($referer, "\nContent-Type: ") === false) { $request[] = 'Content-Type: application/x-www-form-urlencoded'; } $request[] = 'Content-Length: ' . strlen($postdata); } if ($XMLRequest) { $request[] = 'X-Requested-With: XMLHttpRequest'; } $request[] = 'Connection: Close'; $request = implode($nn, $request) . $nn . $nn . $postdata; $errno = 0; $errstr = ''; $hosts = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port); $fp = @stream_socket_client($hosts, $errno, $errstr, 120, STREAM_CLIENT_CONNECT); //$fp = @fsockopen($proxyHost ? $scheme.$proxyHost : $scheme.$host, $proxyPort ? $proxyPort : $port, $errno, $errstr, 15); if (!$fp) { if (!function_exists('stream_socket_client')) { html_error('[ERROR] stream_socket_client() is disabled.'); } $dis_host = !empty($proxyHost) ? $proxyHost : $host; $dis_port = !empty($proxyPort) ? $proxyPort : $port; html_error(sprintf(lang(88), $dis_host, $dis_port)); } if ($errno || $errstr) { $lastError = $errstr; return false; } if ($saveToFile) { if ($proxy) { echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />'; echo 'GET: <b>' . $url . "</b>...<br />\n"; } else { echo '<p>' . sprintf(lang(90), $host, $port) . '</p>'; } } ######################################################################### fwrite($fp, $request); fflush($fp); $timeStart = microtime(true); // Rewrote the get header function according to the proxy script // Also made sure it goes faster and I think 8192 is the best value for retrieving headers // Oops.. The previous function hooked up everything and now I'm returning it back to normal $llen = 0; $header = ''; do { $header .= fgets($fp, 16384); $len = strlen($header); if (!$header || $len == $llen) { $lastError = lang(91); stream_socket_shutdown($fp, STREAM_SHUT_RDWR); fclose($fp); return false; } $llen = $len; } while (strpos($header, $nn . $nn) === false); // Array for active stream filters $sFilters = array(); if (stripos($header, "\nTransfer-Encoding: chunked") !== false && in_array('dechunk', stream_get_filters())) { // Add built-in dechunk filter $sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ); if (!$sFilters['dechunk'] && $saveToFile) { html_error('Unknown error while initializing dechunk filter, cannot continue download.'); } } ######################################################################### if ($saveToFile) { if (!isset($_GET['dis_plug']) || $_GET['dis_plug'] != 'on') { $cbhost = strpos($host, ':') !== false ? substr($host, 0, strpos($host, ':')) : $host; // Remove the port that may be added when it's using proxy $chkhost = preg_match('/^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}$/', $cbhost) ? false : true; if (!empty($referer)) { $cbrefhost = stripos($referer, 'www.') === 0 ? substr($referer, 4) : $referer; $cbrefhost = parse_url($cbrefhost, PHP_URL_HOST); $chkref = empty($cbrefhost) || preg_match('/^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}$/', $cbrefhost) ? false : ($chkhost && strtolower($cbhost) == strtolower($cbrefhost) ? false : true); } else { $chkref = false; } $found = false; if ($chkhost || $chkref) { foreach ($GLOBALS['host'] as $site => $file) { if ($chkhost && host_matches($site, $cbhost)) { $found = true; break; } elseif ($chkref && host_matches($site, $cbrefhost)) { $found = true; break; } } } if ($found) { require_once HOST_DIR . 'DownloadClass.php'; require_once HOST_DIR . "download/{$file}"; $class = substr($file, 0, -4); $firstchar = substr($file, 0, 1); if ($firstchar > 0) { $class = "d{$class}"; } if (class_exists($class) && method_exists($class, 'CheckBack')) { // is_callable(array($class , 'CheckBack')) $hostClass = new $class(false); $hostClass->CheckBack($header); } } unset($cbhost, $cbrefhost, $chkhost, $chkref, $found); } if (preg_match('/^HTTP\\/1\\.[0|1] (\\d+) .*/', $header, $responsecode) && ($responsecode[1] == 404 || $responsecode[1] == 403)) { // Do some checking, please, at least tell them what error it was if ($responsecode[1] == 403) { $lastError = lang(92); } elseif ($responsecode[1] == 404) { $lastError = lang(93); } else { // Weird, it shouldn't come here... $lastError = lang(94); } return false; } //$bytesTotal = intval ( trim ( cut_str ( $header, "Content-Length:", "\n" ) ) ); $bytesTotal = trim(cut_str($header, "\nContent-Length: ", "\n")); global $options; if ($options['file_size_limit'] > 0 && $bytesTotal > $options['file_size_limit'] * 1024 * 1024) { $lastError = lang(336) . bytesToKbOrMbOrGb($options['file_size_limit'] * 1024 * 1024) . '.'; return false; } if (stripos($header, "\nLocation: ") !== false && preg_match('/\\nLocation: ([^\\r\\n]+)/i', $header, $redir)) { $redirect = trim($redir[1]); $lastError = sprintf(lang(95), $redirect); return FALSE; } if (in_array(cut_str($header, "\nWWW-Authenticate: ", ' '), array('Basic', 'Digest'))) { $lastError = lang(96); return FALSE; } //$ContentType = trim (cut_str($header, "\nContent-Type:", "\n")); // Unused if ($Resume['use'] === TRUE && stripos($header, "\nContent-Range: ") === false) { $lastError = stripos($header, '503 Limit Exceeded') !== false ? lang(97) : lang(98); return FALSE; } if ($force_name) { $FileName = $force_name; } else { $ContentDisposition = cut_str($header, "\nContent-Disposition: ", "\n"); if (!empty($ContentDisposition) && stripos($ContentDisposition, 'filename') !== false) { if (preg_match("@filename\\*=UTF-8''((?:[\\w\\-\\.]|%[0-F]{2})+)@i", $ContentDisposition, $fn)) { $FileName = rawurldecode($fn[1]); } elseif (preg_match('@filename=\\"?([^\\r\\n\\"\\;]+)\\"?@i', $ContentDisposition, $fn)) { $FileName = $fn[1]; } else { $FileName = $saveToFile; } } else { $FileName = $saveToFile; } } $FileName = str_replace(array_merge(range(chr(0), chr(31)), str_split("<>:\"/|?*\\")), '', basename(trim($FileName))); if (!empty($options['rename_prefix'])) { $FileName = $options['rename_prefix'] . '_' . $FileName; } if (!empty($options['rename_suffix'])) { $ext = strrchr($FileName, '.'); $before_ext = explode($ext, $FileName); $FileName = $before_ext[0] . '_' . $options['rename_suffix'] . $ext; } if ($options['rename_underscore']) { $FileName = str_replace(array(' ', '%20'), '_', $FileName); } $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $FileName; $filetype = strrchr($saveToFile, '.'); if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) { if ($options['forbidden_filetypes_block']) { $lastError = sprintf(lang(82), $filetype); return false; } else { $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile); } } if (@file_exists($saveToFile) && $options['bw_save']) { // Skip in audl. if (isset($_GET['audl'])) { echo '<script type="text/javascript">parent.nextlink();</script>'; } html_error(lang(99) . ': ' . link_for_file($saveToFile)); } if (@file_exists($saveToFile) && $Resume['use'] === TRUE) { $fs = @fopen($saveToFile, 'ab'); if (!$fs) { $lastError = sprintf(lang(101), basename($saveToFile), dirname($saveToFile)) . '<br />' . lang(102) . '<br /><a href="javascript:location.reload();">' . lang(103) . '</a>'; return FALSE; } } else { if (@file_exists($saveToFile)) { $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . '_' . basename($saveToFile); } $fs = @fopen($saveToFile, 'wb'); if (!$fs) { $secondName = dirname($saveToFile) . PATH_SPLITTER . str_replace(':', '', str_replace('?', '', basename($saveToFile))); $fs = @fopen($secondName, 'wb'); if (!$fs) { $lastError = sprintf(lang(101), basename($saveToFile), dirname($saveToFile)) . '<br />' . lang(102) . '<br /><a href="javascript:location.reload();">' . lang(103) . '</a>'; return FALSE; } } } flock($fs, LOCK_EX); if ($Resume['use'] === TRUE && stripos($header, "\nContent-Range: ") !== false) { list($temp, $Resume['range']) = explode(' ', trim(cut_str($header, "\nContent-Range: ", "\n"))); list($Resume['range'], $fileSize) = explode('/', $Resume['range']); $fileSize = bytesToKbOrMbOrGb($fileSize); } else { $fileSize = bytesToKbOrMbOrGb($bytesTotal); } $chunkSize = GetChunkSize($bytesTotal); echo lang(104) . ' <b>' . basename($saveToFile) . '</b>, ' . lang(56) . " <b>{$fileSize}</b>...<br />"; //$scriptStarted = false; require_once TEMPLATE_DIR . '/transloadui.php'; if ($Resume['use'] === TRUE) { $received = bytesToKbOrMbOrGb(filesize($saveToFile)); $percent = round($Resume['from'] / ($bytesTotal + $Resume['from']) * 100, 2); echo "<script type='text/javascript'>pr('{$percent}', '{$received}', '0');</script>"; //$scriptStarted = true; flush(); } } else { $page = ''; } $time = $last = $lastChunkTime = 0; do { $data = @fread($fp, $saveToFile ? $chunkSize : 16384); // 16384 saw this value in Pear HTTP_Request2 package // (fix - szal) using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!) if ($data == '') { break; } if ($saveToFile) { $bytesSaved = fwrite($fs, $data); if ($bytesSaved !== false && strlen($data) == $bytesSaved) { //if ($bytesSaved > - 1) { $bytesReceived += $bytesSaved; } else { $lastError = sprintf(lang(105), basename($saveToFile)); // unlink($saveToFile); return false; } if ($bytesReceived >= $bytesTotal) { $percent = 100; } else { $percent = @round(($bytesReceived + $Resume['from']) / ($bytesTotal + $Resume['from']) * 100, 2); } if ($bytesReceived > $last + $chunkSize) { $received = bytesToKbOrMbOrGb($bytesReceived + $Resume['from']); $time = microtime(true) - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime > 0 ? $chunkTime : 1; $lastChunkTime = $time; $speed = @round(($bytesReceived - $last) / 1024 / $chunkTime, 2); echo "<script type='text/javascript'>pr('{$percent}', '{$received}', '{$speed}');</script>"; $last = $bytesReceived; } if (!empty($bytesTotal) && $bytesReceived + $chunkSize > $bytesTotal) { $chunkSize = $bytesTotal - $bytesReceived; } } else { $page .= $data; } } while (!feof($fp) && strlen($data) > 0); if ($saveToFile) { flock($fs, LOCK_UN); fclose($fs); if ($bytesReceived <= 0) { $lastError = lang(106); stream_socket_shutdown($fp, STREAM_SHUT_RDWR); fclose($fp); return FALSE; } } stream_socket_shutdown($fp, STREAM_SHUT_RDWR); fclose($fp); if ($saveToFile) { return array('time' => sec2time(round($time)), 'speed' => @round($bytesTotal / 1024 / (microtime(true) - $timeStart), 2), 'received' => true, 'size' => $fileSize, 'bytesReceived' => $bytesReceived + $Resume['from'], 'bytesTotal' => $bytesTotal + $Resume['from'], 'file' => $saveToFile); } else { if (stripos($header, "\nTransfer-Encoding: chunked") !== false && empty($sFilters['dechunk']) && function_exists('http_chunked_decode')) { $dechunked = http_chunked_decode($page); if ($dechunked !== false) { $page = $dechunked; } unset($dechunked); } $page = $header . $page; return $page; } }
} $_GET['saveto'] = urldecode(trim($_GET['saveto'])); $_GET['host'] = urldecode(trim($_GET['host'])); $_GET['path'] = urldecode(trim($_GET['path'])); $_GET['port'] = !empty($_GET['port']) ? urldecode(trim($_GET['port'])) : 0; $_GET['referer'] = !empty($_GET['referer']) ? urldecode(trim($_GET['referer'])) : 0; $_GET['link'] = urldecode(trim($_GET['link'])); $_GET['post'] = !empty($_GET['post']) ? unserialize(decrypt(urldecode(trim($_GET['post'])))) : 0; $_GET['cookie'] = !empty($_GET['cookie']) ? decrypt(urldecode(trim($_GET['cookie']))) : ''; $_GET['proxy'] = !empty($_GET['proxy']) ? trim(urldecode($_GET['proxy'])) : ''; // $resume_from = $_GET["resume"] ? intval(urldecode(trim($_GET["resume"]))) : 0; // if ($_GET["resume"]) {unset($_GET["resume"]);} $redirectto = ''; if ($options['bw_save']) { $mydomain = ($pos = strpos($_SERVER['HTTP_HOST'], ':')) !== false ? substr($_SERVER['HTTP_HOST'], 0, $pos) : $_SERVER['HTTP_HOST']; if ($_GET['host'] == $_SERVER['SERVER_ADDR'] || host_matches($mydomain, $_GET['host'])) { html_error(sprintf(lang(7), $mydomain, $_SERVER['SERVER_ADDR'])); } unset($mydomain); } $pauth = !empty($_GET['pauth']) ? decrypt(urldecode(trim($_GET['pauth']))) : ''; $AUTH = array(); $_GET['auth'] = !empty($_GET['auth']) ? trim($_GET['auth']) : ''; if ($_GET['auth'] == '1') { if (!preg_match('|^(?:.+\\.)?(.+\\..+)$|i', $_GET['host'], $hostmatch)) { html_error('No valid hostname found for authorisation!'); } $hostmatch = str_replace('.', '_', $hostmatch[1]); if (isset($premium_acc["{$hostmatch}"]) && is_array($premium_acc["{$hostmatch}"]) && !empty($premium_acc["{$hostmatch}"]['user']) && !empty($premium_acc["{$hostmatch}"]['pass'])) { $auth = base64_encode($premium_acc["{$hostmatch}"]['user'] . ':' . $premium_acc["{$hostmatch}"]['pass']); } else {
$class = "d{$class}"; } if (class_exists($class)) { $hostClass = new $class(); $hostClass->Download($LINK); } exit; } } } $page_title = $L->say['leeching']; $shortcut_icon = IMAGE_DIR . "rsload_2.gif"; include TEMPLATE_DIR . 'header.php'; $FileName = isset($Url["path"]) ? basename($Url["path"]) : ''; $mydomain = ($pos = strpos($_SERVER['HTTP_HOST'], ':')) !== false ? substr($_SERVER['HTTP_HOST'], 0, $pos) : $_SERVER['HTTP_HOST']; if ($options['bw_save'] && ($Url['host'] == $_SERVER['SERVER_ADDR'] || host_matches($mydomain, $Url['host']))) { html_error($L->sprintf($L->say['leech_not_allowed'], $mydomain, $_SERVER['SERVER_ADDR'])); } $redir = GetDefaultParams(); $redir['dis_plug'] = 'on'; $redir['filename'] = urlencode($FileName); $redir['host'] = urlencode($Url['host']); if (!empty($Url['port'])) { $redir['port'] = urlencode($Url['port']); } $redir['path'] = urlencode($Url['path'] . (!empty($Url['query']) ? '?' . $Url['query'] : '')); if (!empty($Referer)) { $redir['referer'] = urlencode($Referer); } $redir['link'] = urlencode($LINK); if (!empty($_GET['cookie'])) {
function geturl($host, $port, $url, $referer = 0, $cookie = 0, $post = 0, $saveToFile = 0, $proxy = 0, $pauth = 0, $auth = 0, $scheme = "http", $resume_from = 0, $XMLRequest = 0) { global $nn, $lastError, $Resume, $bytesReceived, $fs, $force_name, $options, $L, $visitors, $ada_acc; $scheme .= '://'; if ($post !== 0 && ($scheme == 'http://' || $scheme == 'https://')) { $method = 'POST'; $postdata = is_array($post) ? formpostdata($post) : $post; $length = strlen($postdata); $content_tl = "Content-Type: application/x-www-form-urlencoded{$nn}" . "Content-Length: {$length}{$nn}"; } else { $method = 'GET'; $content_tl = $postdata = ''; } $cookies = ''; if (!empty($cookie)) { if (is_array($cookie)) { if (count($cookie) > 0) { $cookies = 'Cookie: ' . CookiesToStr($cookie) . $nn; } } else { $cookies = 'Cookie: ' . trim($cookie) . $nn; } } $referer = $referer ? "Referer: {$referer}{$nn}" : ''; if ($scheme == 'https://') { $scheme = 'ssl://'; if ($port == 0 || $port == 80) { $port = 443; } } if ($proxy) { list($proxyHost, $proxyPort) = explode(':', $proxy, 2); $host = $host . ($port != 80 && ($scheme != 'ssl://' || $port != 443) ? ':' . $port : ''); $url = $scheme . $host . $url; } if ($scheme != 'ssl://') { $scheme = ''; } $http_auth = !empty($auth) ? "Authorization: Basic {$auth}{$nn}" : ''; $proxyauth = !empty($pauth) ? "Proxy-Authorization: Basic {$pauth}{$nn}" : ''; $request = array(); $request[] = $method . ' ' . str_replace(' ', '%20', $url) . ' HTTP/1.1'; $request[] = "Host: {$host}"; $request[] = 'User-Agent: Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.12'; $request[] = 'Accept: */*'; $request[] = 'Accept-Language: en-US;q=0.7,en;q=0.3'; $request[] = 'Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7'; $request[] = 'Pragma: no-cache'; $request[] = 'Cache-Control: no-cache'; if ($Resume['use'] === TRUE) { $request[] = 'Range: bytes=' . $Resume['from'] . '-'; } if ($XMLRequest) { $request[] = 'X-Requested-With: XMLHttpRequest'; } $request = implode($nn, $request) . $nn . $http_auth . $proxyauth . $referer . $cookies . $content_tl . 'Connection: Close' . $nn . $nn . $postdata; if (isset($options['mip_enabled']) && $options['mip_enabled']) { $mip_action = "download"; echo "<p>Multi IP Enabled</b>...<br />\n"; if (file_exists(CLASS_DIR . "mip.php")) { @(include CLASS_DIR . "mip.php"); } } else { $errno = 0; $errstr = ''; $hosts = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port); $fp = @stream_socket_client($hosts, $errno, $errstr, 120, STREAM_CLIENT_CONNECT); } if (!$fp) { $dis_host = !empty($proxyHost) ? $proxyHost : $host; $dis_port = !empty($proxyPort) ? $proxyPort : $port; html_error($L->sprintf($L->say['_couldnt_con_to'], $dis_host, $dis_port)); } if ($errno || $errstr) { $lastError = $errstr; return false; } if ($saveToFile) { if ($proxy) { echo '<p>' . $L->sprintf($L->say['_con_proxy'], $proxyHost, $proxyPort) . '<br />'; echo "GET: <b>" . $url . "</b>...<br />\n"; } else { echo "<p>"; echo $L->sprintf($L->say['_con_to'], $host, $port) . '<br />'; echo isset($options['mip_enabled']) && $options['mip_enabled'] ? "using IP: " . $mip_ip . "<br />\n" : ""; } } ######################################################################### fputs($fp, $request); fflush($fp); $timeStart = getmicrotime(); // Rewrote the get header function according to the proxy script // Also made sure it goes faster and I think 8192 is the best value for retrieving headers // Oops.. The previous function hooked up everything and now I'm returning it back to normal $llen = 0; $header = ''; do { $header .= fgets($fp, 16384); $len = strlen($header); if (!$header || $len == $llen) { $lastError = $L->say['_noheader']; return false; } $llen = $len; } while (strpos($header, $nn . $nn) === false); ######################################################################### if ($saveToFile) { if (!isset($_GET['dis_plug']) || $_GET['dis_plug'] != 'on') { $cbhost = strpos($host, ':') !== false ? substr($host, 0, strpos($host, ':')) : $host; // Remove the port that may be added when it's using proxy $chkhost = preg_match('/^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}$/', $cbhost) ? false : true; if (!empty($referer)) { $cbrefhost = str_ireplace('www.', '', cut_str($referer, 'Referer: ', "\r\n")); $cbrefhost = parse_url($cbrefhost, PHP_URL_HOST); $chkref = empty($cbrefhost) || preg_match('/^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}$/', $cbrefhost) ? false : ($chkhost && strtolower($cbhost) == strtolower($cbrefhost) ? false : true); } else { $chkref = false; } $found = false; if ($chkhost || $chkref) { foreach ($GLOBALS['host'] as $site => $file) { if ($chkhost && host_matches($site, $cbhost)) { $found = true; } elseif ($chkref && host_matches($site, $cbrefhost)) { $found = true; } if ($found) { if ($options['limitbyIP']) { if ($ada_acc) { global $premium_acc; if (preg_match('|^(?:.+\\.)?(.+\\..+)$|i', $cbhost, $prematch) || preg_match('|^(?:.+\\.)?(.+\\..+)$|i', $cbrefhost, $prematch)) { $prematch = str_replace('.', '_', $prematch[1]); if (!empty($premium_acc[$prematch])) { $fname = basename($saveToFile) . "." . rand(1, 1000); $limitedfile = $visitors->userip . $fname; $ret = mkdir($visitors->tmp_dir . $limitedfile, 0777); } } } } require_once HOST_DIR . 'DownloadClass.php'; require_once HOST_DIR . "download/{$file}"; $class = substr($file, 0, -4); $firstchar = substr($file, 0, 1); if ($firstchar > 0) { $class = "d{$class}"; } if (!class_exists($class) || !method_exists($class, 'CheckBack')) { break; } // is_callable(array($class , 'CheckBack')) $hostClass = new $class(false); $hostClass->CheckBack($header); break; } } unset($cbhost, $cbrefhost, $chkhost, $chkref, $found); } } if (preg_match('/^HTTP\\/1\\.[0|1] (\\d+) .*/', $header, $responsecode) && ($responsecode[1] == 404 || $responsecode[1] == 403)) { // Do some checking, please, at least tell them what error it was if ($responsecode[1] == 403) { $lastError = $L->say['_page_notfound']; } elseif ($responsecode[1] == 404) { $lastError = $L->say['_forbidden_access']; } else { // Weird, it shouldn't come here... $lastError = $L->say['_notfound_forbidden']; } return false; } $bytesTotal = trim(cut_str($header, "Content-Length:", "\n")); if ($options['maxlimitsize'] > 0) { if ($bytesTotal > $options['maxlimitsize'] * 1024 * 1024) { $lastError = $L->sprintf($L->say['_sorry_tobig'], bytesToKbOrMbOrGb($bytesTotal), $options["maxlimitsize"]); return false; } } if ($options['minlimitsize'] > 0) { if ($bytesTotal < $options['minlimitsize'] * 1024 * 1024) { $lastError = $L->sprintf($L->say['_sorry_tosmall'], bytesToKbOrMbOrGb($bytesTotal), $options["minlimitsize"]); return false; } } // check storage limit (it is in MB) if ($options['storage_limit'] > 0) { $serverfiles = calcUsedSpace(); if ($serverfiles + $bytesTotal > $options['storage_limit'] * 1024 * 1024) { $lastError = $L->sprintf($L->say['_sorry_insuficient_storage'], bytesToKbOrMbOrGb($serverfiles), $options["storage_limit"]); return false; } } if (stripos($header, "\nLocation: ") !== false && preg_match('/\\nLocation: ([^\\r\\n]+)/i', $header, $redir)) { $redirect = trim($redir[1]); $lastError = $L->sprintf($L->say['_error_redirectto'], $redirect); return FALSE; } if (in_array(cut_str($header, "WWW-Authenticate: ", " "), array("Basic", "Digest"))) { $lastError = $L->say['_req_auth']; return FALSE; } //$ContentType = trim(cut_str($header, "Content-Type:", "\n")); if ($Resume['use'] === TRUE && stripos($header, "\nContent-Range: ") === false) { $lastError = stripos($header, '503 Limit Exceeded') !== false ? $L->say['_error_resume'] : $L->say['_error_noresume']; return FALSE; } if ($force_name) { $FileName = $force_name; $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $FileName; } else { $ContentDisposition = trim(cut_str($header, "Content-Disposition:", "\n")) . "\n"; if ($ContentDisposition && stripos($ContentDisposition, "filename=") !== false) { $FileName = trim(trim(trim(trim(trim(cut_str($ContentDisposition, "filename=", "\n")), "="), "?"), ";"), '"'); if (strpos($FileName, "/") !== false) { $FileName = basename($FileName); } if (preg_match("/UTF\\-8\\?B\\?(.*)\$/i", $FileName, $b64)) { $FileName = preg_replace("/[^a-zA-Z0-9\\-\\.]/", "_", base64_decode($b64[1])); } $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $FileName; } } if (!empty($options["add_ext_5city"]) || !empty($options['rename_suffix']) || !empty($options['rename_prefix']) || $options['rename_underscore']) { if (!empty($options["add_ext_5city"])) { $ext = str_replace(".", "", $options["add_ext_5city"]); $File_Name = basename($saveToFile) . "." . $options["add_ext_5city"]; } if (!empty($options['rename_prefix'])) { $File_Name = $options['rename_prefix'] . '_' . basename($saveToFile); } if (!empty($options['rename_suffix'])) { $ext = strrchr(basename($saveToFile), "."); $before_ext = explode($ext, basename($saveToFile)); $File_Name = $before_ext[0] . '_' . $options['rename_suffix'] . $ext; } if ($options['rename_underscore']) { $File_Name = str_replace(array(' ', '%20'), '_', basename($saveToFile)); } $saveToFile = dirname($saveToFile) . PATH_SPLITTER . $File_Name; } $filetype = strrchr($saveToFile, "."); if (is_array($options['forbidden_filetypes']) && in_array(strtolower($filetype), $options['forbidden_filetypes'])) { if ($options['forbidden_filetypes_block']) { $lastError = $L->sprintf($L->say['_forbid_filetype'], $filetype); return false; } else { $saveToFile = str_replace($filetype, $options['rename_these_filetypes_to'], $saveToFile); } } if (@file_exists($saveToFile) && $options['bw_save']) { html_error($L->say['_download'] . ': ' . link_for_file($saveToFile), 0); } if (@file_exists($saveToFile) && $Resume["use"] === TRUE) { $fs = @fopen($saveToFile, "ab"); if (!$fs) { $lastError = $L->sprintf($L->say['_error_cantsave'], basename($saveToFile)) . '<br />' . $L->say['_error_trychmod'] . '<br /><a href="javascript:location.reload();">' . $L->say['_error_tryagain'] . '</a>'; return FALSE; } } else { if (@file_exists($saveToFile)) { $saveToFile = dirname($saveToFile) . PATH_SPLITTER . TIME_NOW . "_" . basename($saveToFile); } $fs = @fopen($saveToFile, "wb"); if (!$fs) { $secondName = dirname($saveToFile) . PATH_SPLITTER . str_replace(":", "", str_replace("?", "", basename($saveToFile))); $fs = @fopen($secondName, "wb"); if (!$fs) { $lastError = $L->sprintf($L->say['_error_cantsave'], basename($saveToFile)) . '<br />' . $L->say['_error_trychmod'] . '<br /><a href="javascript:location.reload();">' . $L->say['_error_tryagain'] . '</a>'; return FALSE; } } } flock($fs, LOCK_EX); if ($Resume['use'] === TRUE && stripos($header, "\nContent-Range: ") !== false) { list($temp, $Resume['range']) = explode(' ', trim(cut_str($header, "\nContent-Range: ", "\n"))); list($Resume['range'], $fileSize) = explode('/', $Resume['range']); $fileSize = bytesToKbOrMbOrGb($fileSize); } else { $fileSize = bytesToKbOrMbOrGb($bytesTotal); } $chunkSize = GetChunkSize($bytesTotal); $File_Name = basename($saveToFile); if (!empty($options["add_ext_5city"])) { $ext = "." . get_extension(basename($saveToFile)); $File_Name = str_replace($ext, "", basename($saveToFile)); } echo $L->sprintf($L->say['_saveprogres'], $File_Name, $ext, $fileSize) . '<br />'; //$scriptStarted = false; require_once TEMPLATE_DIR . 'transloadui.php'; if ($Resume['use'] === TRUE) { $received = bytesToKbOrMbOrGb(filesize($saveToFile)); $percent = round($Resume['from'] / ($bytesTotal + $Resume['from']) * 100, 2); echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . $received . "', '0');</script>"; //$scriptStarted = true; flush(); } } else { $page = ""; } $time = $last = $lastChunkTime = 0; do { $data = @fread($fp, $saveToFile ? $chunkSize : 16384); // 16384 saw this value in Pear HTTP_Request2 package // (fix - szal) using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!) if ($data == '') { break; } if ($saveToFile) { $bytesSaved = fwrite($fs, $data); if ($bytesSaved !== false && strlen($data) == $bytesSaved) { //if ($bytesSaved > - 1) { $bytesReceived += $bytesSaved; } else { $lastError = $L->sprintf($L->say['_error_imposible_record'], $saveToFile); unlink($saveToFile); return false; } if ($bytesReceived >= $bytesTotal) { $percent = 100; } else { $percent = @round(($bytesReceived + $Resume['from']) / ($bytesTotal + $Resume['from']) * 100, 2); } if ($bytesReceived > $last + $chunkSize) { $received = bytesToKbOrMbOrGb($bytesReceived + $Resume['from']); $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime ? $chunkTime : 1; $lastChunkTime = $time; $speed = @round($chunkSize / 1024 / $chunkTime, 2); /* if (!$scriptStarted) { echo('<script type="text/javascript">'); $scriptStarted = true; } */ echo "<script type='text/javascript'>pr('" . $percent . "', '" . $received . "', '" . $speed . "');</script>"; $last = $bytesReceived; } } else { $page .= $data; } } while (strlen($data) > 0); //echo('</script>'); if ($saveToFile) { flock($fs, LOCK_UN); fclose($fs); if ($bytesReceived <= 0) { $lastError = $L->say['_error_misc']; fclose($fp); return FALSE; } } fclose($fp); if ($saveToFile) { return array('time' => sec2time(round($time)), 'speed' => @round($bytesTotal / 1024 / (getmicrotime() - $timeStart), 2), 'received' => true, 'size' => $fileSize, 'bytesReceived' => $bytesReceived + $Resume['from'], 'bytesTotal' => $bytesTotal + $Resume['from'], 'file' => $saveToFile); } else { if (stripos($header, "\nTransfer-Encoding: chunked") !== false && function_exists('http_chunked_decode')) { $dechunked = http_chunked_decode($page); if ($dechunked !== false) { $page = $dechunked; } unset($dechunked); } $page = $header . $page; return $page; } }
public function Download($link) { $this->cookie = isset($_POST['yt_QS']) && !empty($_POST['cookie']) ? StrToCookies(decrypt(urldecode($_POST['cookie']))) : array(); $url = parse_url($link); $this->vid = array(); if (host_matches('youtu.be', $url['host'])) { preg_match('@/([\\w\\-\\.]{11})@i', $url['path'], $this->vid); } elseif (empty($url['query']) || ($this->vid[1] = cut_str('&' . $url['query'] . '&', '&v=', '&')) === false || !preg_match('@^[\\w\\-\\.]{11}$@i', $this->vid[1])) { preg_match('@/(?:v|(?:embed))/([\\w\\-\\.]{11})@i', $url['path'], $this->vid); } if (empty($this->vid[1])) { html_error('Video ID not found.'); } $this->vid = $this->vid[1]; $link = 'http://www.youtube.com/watch?v=' . $this->vid; $this->page = $this->GetPage('http://www.youtube.com/get_video_info?video_id=' . $this->vid . '&asv=3&el=detailpage&hl=en_US&s' . 't' . 's' . '=0', $this->cookie); $response = array_map('urldecode', $this->FormToArr(substr($this->page, strpos($this->page, "\r\n\r\n") + 4))); if (!empty($response['reason'])) { html_error('[' . htmlentities($response['errorcode']) . '] ' . htmlentities($response['reason'])); } if (isset($_REQUEST['step']) || preg_match('@Location: https?://(www\\.)?youtube\\.com/das_captcha@i', $this->page)) { $this->captcha($link); } if (empty($response['url_encoded_fmt_stream_map'])) { html_error('Video links not found.'); } $fmt_url_maps = explode(',', $response['url_encoded_fmt_stream_map']); $this->fmts = array(38, 37, 46, 22, 45, 44, 35, 43, 34, 18, 6, 5); $yt_fmt = empty($_REQUEST['yt_fmt']) ? '' : $_REQUEST['yt_fmt']; $this->fmturlmaps = $this->GetVideosArr($fmt_url_maps); if (empty($yt_fmt) && !isset($_GET['audl'])) { return $this->QSelector($link); } elseif (isset($_REQUEST['ytube_mp4']) && $_REQUEST['ytube_mp4'] == 'on' && !empty($yt_fmt)) { //look for and download the highest quality we can find? if ($yt_fmt == 'highest') { foreach ($this->fmts as $fmt) { if (array_key_exists($fmt, $this->fmturlmaps)) { $furl = $this->fmturlmaps[$fmt]; break; } } } elseif (!($furl = $this->fmturlmaps[$yt_fmt])) { html_error('Specified video format not found'); } else { $fmt = $yt_fmt; } } else { //just get the one Youtube plays by default (in some cases it could also be the highest quality format) $fmt = key($this->fmturlmaps); $furl = $this->fmturlmaps[$fmt]; } $ext = '.flv'; $fmtexts = array('.mp4' => array(18, 22, 37, 38), '.webm' => array(43, 44, 45, 46)); foreach ($fmtexts as $k => $v) { if (!is_array($v)) { $v = array($v); } if (in_array($fmt, $v)) { $ext = $k; break; } } if (empty($response['title'])) { html_error('No video title found! Download halted.'); } $FileName = str_replace(str_split('\\:*?"<>|=;' . "\t\r\n\f"), '_', html_entity_decode(trim($response['title']), ENT_QUOTES)); if (!empty($_REQUEST['cleanname'])) { $FileName = preg_replace('@[^ A-Za-z_\\-\\d\\.,\\(\\)\\[\\]\\{\\}&\\!\'\\@\\%\\#]@u', '_', $FileName); } $FileName .= " [YT-f{$fmt}][{$this->vid}]{$ext}"; $this->RedirectDownload($furl, $FileName, $this->cookie, 0, 0, $FileName); }