PageRenderTime 46ms CodeModel.GetById 2ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 1ms

/index.php

http://rapidleech.googlecode.com/
PHP | 324 lines | 259 code | 50 blank | 15 comment | 135 complexity | ca0fefb8f662bdb9bc664058d899f3d6 MD5 | raw file
  1<?php
  2// ini_set('display_errors', 0);
  3@set_time_limit(0);
  4ini_alter('memory_limit', '1024M');
  5if (ob_get_level()) ob_end_clean();
  6ob_implicit_flush(true);
  7ignore_user_abort(true);
  8clearstatcache();
  9error_reporting(6135);
 10$nn = "\r\n";
 11$fromaddr = 'RapidLeech';
 12$dev_name = 'Development Stage';
 13$rev_num = '43';
 14$plusrar_v = '4.1';
 15$PHP_SELF = $_SERVER['SCRIPT_NAME'];
 16define('RAPIDLEECH', 'yes');
 17define('ROOT_DIR', realpath ('./'));
 18define('PATH_SPLITTER', ((strpos(ROOT_DIR, "\\") !== false) ? "\\" : '/'));
 19define('HOST_DIR', 'hosts/');
 20define('CLASS_DIR', 'classes/');
 21define('CONFIG_DIR', 'configs/');
 22define('BUILD', '30May2011');
 23define('CREDITS', '<a href="http://www.rapidleech.com/" class="rl-link"><b>RapidLeech</b></a>&nbsp;<b class="rev-dev">PlugMod (eqbal) rev. ' . $rev_num . '</b> <span class="rev-dev">' . $dev_name . '</span><br><small class="small-credits">Credits to Pramode &amp; Checkmate &amp; Kloon</small><br /><p class="rapidleechhost"><a href="http://www.rapidleechhost.com/aff.php?aff=001" target="_blank">RapidleechHost Offical Hosting</a></p>');
 24
 25require_once(CONFIG_DIR . 'setup.php');
 26// $options['download_dir'] should always end with a '/'
 27if (substr($options['download_dir'], - 1) != '/') $options['download_dir'] .= '/';
 28define('DOWNLOAD_DIR', (substr ($options['download_dir'], 0, 6) == 'ftp://' ? '' : $options['download_dir']));
 29
 30define('TEMPLATE_DIR', 'templates/' . $options['template_used'] . '/');
 31define('IMAGE_DIR', TEMPLATE_DIR . 'images/');
 32
 33if ($options['no_cache']) {
 34	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
 35	header('Last-Modified: ' . gmdate ("D, d M Y H:i:s") . 'GMT');
 36	header('Cache-Control: no-cache, must-revalidate');
 37	header('Pragma: no-cache');
 38}
 39if (!defined('CRLF')) define ('CRLF', "\r\n");
 40if (!defined('FTP_AUTOASCII')) define('FTP_AUTOASCII', -1);
 41if (!defined('FTP_BINARY')) define('FTP_BINARY', 1);
 42if (!defined('FTP_ASCII')) define('FTP_ASCII', 0);
 43if (!defined('FTP_FORCE')) define('FTP_FORCE', true);
 44define('FTP_OS_Unix', 'u');
 45define('FTP_OS_Windows', 'w');
 46define('FTP_OS_Mac', 'm');
 47
 48require_once(CLASS_DIR . 'other.php');
 49
 50require_once(TEMPLATE_DIR . 'functions.php');
 51// If configs/files.lst is not writable, give a warning
 52if (!is__writable(CONFIG_DIR . 'files.lst')) html_error(lang(304));
 53
 54// If the download path is not writable, show error
 55if (!is__writable (DOWNLOAD_DIR)) html_error(DOWNLOAD_DIR . lang(305));
 56
 57purge_files($options['delete_delay']);
 58
 59register_shutdown_function('pause_download');
 60
 61login_check();
 62
 63$_REQUEST['premium_acc'] = $_POST['premium_acc'] = isset($_REQUEST['premium_acc']) && $_REQUEST['premium_acc'] == 'on' ? 'on' : false;
 64$_REQUEST['cookieuse'] = $_POST['cookieuse'] = isset($_REQUEST['cookieuse']) && $_REQUEST['cookieuse'] == 'on' ? 'on' : false;
 65
 66foreach($_POST as $key => $value) $_GET[$key] = $value;
 67
 68if (!$_COOKIE) {
 69	if (isset($_SERVER['HTTP_COOKIE']) && strpos ($_SERVER['HTTP_COOKIE'], ';') !== false) {
 70		foreach(explode('; ', $_SERVER['HTTP_COOKIE']) as $key => $value) {
 71			list ($var, $val) = explode('=', $value);
 72			$_COOKIE[$var] = $val;
 73		}
 74	}
 75	else if (!empty($_SERVER['HTTP_COOKIE'])) {
 76		list($var, $val) = @explode('=', $_SERVER['HTTP_COOKIE']);
 77		$_COOKIE[$var] = $val;
 78	}
 79}
 80
 81require_once(CLASS_DIR . 'cookie.php');
 82
 83if (!@file_exists(HOST_DIR . 'download/hosts.php')) html_error(lang(127));
 84
 85// require "hosts.php";
 86require_once(HOST_DIR . 'download/hosts.php');
 87
 88if (!empty ($_GET['image'])) {
 89	require_once(CLASS_DIR . 'http.php');
 90	require_once(CLASS_DIR . 'image.php');
 91	exit();
 92}
 93
 94if (isset($_GET['useproxy']) && (empty($_GET['proxy']) || strpos($_GET['proxy'], ':') === false)) {
 95	html_error(lang(324));
 96} else {
 97	if (!empty($_GET['pauth'])) $pauth = decrypt(urldecode(trim($_GET['pauth'])));
 98	else $pauth = (!empty($_GET['proxyuser']) && !empty($_GET['proxypass'])) ? base64_encode($_GET['proxyuser'] . ':' . $_GET['proxypass']) : '';
 99}
100
101if (empty($_GET['path']) || $options['download_dir_is_changeable'] == false) {
102	if (empty($_GET['host'])) $_GET['path'] = (substr($options['download_dir'], 0, 6) != 'ftp://') ? realpath(DOWNLOAD_DIR) : $options['download_dir'];
103	else $_GET['saveto'] = (substr($options['download_dir'], 0, 6) != 'ftp://') ? realpath(DOWNLOAD_DIR) : $options['download_dir'];
104}
105
106if (empty($_GET['filename']) || empty($_GET['host']) || empty($_GET['path'])) {
107	$LINK = !empty($_GET['link']) ? trim(rawurldecode($_GET['link'])) : false;
108	if (!$LINK) {
109		require_once(CLASS_DIR . 'main.php');
110		exit();
111	}
112
113	check_referer();
114
115	// Detect if it doesn't have a protocol assigned
116	if (stripos($LINK, '://') === false || (substr($LINK, 0, 7) != 'http://' && substr($LINK, 0, 6) != 'ftp://' && substr($LINK, 0, 6) != 'ssl://' && substr($LINK, 0, 8) != 'https://')) {
117		// Automatically assign http://
118		$LINK = 'http://' . $LINK;
119	}
120
121	if (!empty($_GET['saveto']) && empty($_GET['path'])) html_error(lang(6));
122
123	if (empty($_GET['useproxy'])) $_GET['proxy'] = '';
124
125	if (!empty($_GET['domail']) && !checkmail($_GET['email'])) {
126		html_error(lang(3));
127		if (!empty($_GET['split']) && !is_numeric($_GET['partSize'])) html_error(lang(4)); // T-8: Check this.
128	}
129
130	$Url = parse_url($LINK);
131
132	$Url['path'] = (empty($Url['path'])) ? '/' :str_replace('%2F', '/', rawurlencode(rawurldecode($Url['path'])));
133	$LINK = rebuild_url($Url);
134
135	if (empty($_GET['referer'])) {
136		$Referer = $Url;
137		// Remove login from Referer
138		unset($Referer['user'], $Referer['pass']);
139		$Referer = rebuild_url($Referer);
140	} else $Referer = trim(rawurldecode($_GET['referer']));
141
142	if ($Url['scheme'] != 'http' && $Url['scheme'] != 'https' && $Url['scheme'] != 'ftp') html_error(lang(5));
143
144	if (empty($Url['user']) xor empty($Url['pass'])) {
145		unset($Url['user'], $Url['pass']);
146		$LINK = rebuild_url($Url);
147	}
148
149	if (isset($_GET['user_pass']) && $_GET['user_pass'] == 'on' && !empty($_GET['iuser']) && !empty($_GET['ipass'])) {
150		$Url['user'] = $_GET['iuser'];
151		$Url['pass'] = $_GET['ipass'];
152		// Rebuild url
153		$LINK = rebuild_url($Url);
154	}
155
156	// If Url has user & pass, use them as premium login for plugins and set $auth for direct download.
157	if (!empty($Url['user']) && !empty($Url['pass'])) {
158		if (empty($_REQUEST['premium_acc'])) $_GET['premium_acc'] = $_POST['premium_acc'] = $_REQUEST['premium_acc'] = 'on';
159		$_GET['premium_user'] = $_POST['premium_user'] = $_REQUEST['premium_user'] = $Url['user'];
160		$_GET['premium_pass'] = $_POST['premium_pass'] = $_REQUEST['premium_pass'] = $Url['pass'];
161
162		$auth = urlencode(encrypt(base64_encode(rawurlencode($Url['user']) . ':' . rawurlencode($Url['pass']))));
163
164		// Lets delete User and Pass from link because isn't needed now.
165		unset($Url['user'], $Url['pass']);
166		$LINK = rebuild_url($Url);
167	} else $auth = '';
168
169	if (empty($_GET['dis_plug']) || $_GET ['dis_plug'] != 'on') {
170		// check Domain-Host
171		foreach ($host as $site => $file) {
172			if (host_matchs($site, $Url['host'])) {
173				include(TEMPLATE_DIR . '/header.php');
174				require_once (CLASS_DIR . 'http.php');
175				require_once (HOST_DIR . 'DownloadClass.php');
176				require_once (HOST_DIR . 'download/' . $file);
177				$class = substr($file, 0, -4);
178				$firstchar = substr($file, 0, 1);
179				if ($firstchar > 0) $class = "d$class";
180				if (class_exists($class)) {
181					$hostClass = new $class();
182					$hostClass->Download($LINK);
183				}
184				exit();
185			}
186		}
187	}
188	// print "<html>$nn<head>$nn<title>Downloading $LINK</title>$nn<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />$nn</head>$nn<body>$nn";
189	include(TEMPLATE_DIR . '/header.php');
190
191	$FileName = isset($Url['path']) ? basename($Url['path']) : '';
192	$mydomain = ($pos = strpos($_SERVER['HTTP_HOST'], ':')) !== false ? substr($_SERVER['HTTP_HOST'], 0, $pos) : $_SERVER['HTTP_HOST'];
193	if ($options['bw_save'] && ($Url['host'] == $_SERVER['SERVER_ADDR'] || host_matchs($mydomain, $Url['host']))) html_error(sprintf(lang(7), $mydomain, $_SERVER['SERVER_ADDR']));
194
195	$redir = GetDefaultParams();
196	$redir['dis_plug'] = 'on';
197	$redir['filename'] = urlencode($FileName);
198	$redir['host'] = urlencode($Url['host']);
199	if (!empty($Url['port'])) $redir['port'] = urlencode($Url['port']);
200	$redir['path'] = urlencode($Url['path'] . (!empty($Url['query']) ? '?' . $Url['query'] : ''));
201	if (!empty($Referer)) $redir['referer'] = urlencode($Referer);
202	$redir['link'] = urlencode($LINK);
203	if (!empty($_GET['cookie'])) $redir['cookie'] = urlencode(encrypt($_GET['cookie']));
204	if (!empty($auth)) $redir['auth'] = $auth;
205
206	insert_location($redir);
207} else {
208	include(TEMPLATE_DIR . '/header.php');
209	check_referer();
210	echo('<div align="center">');
211
212	do {
213		$_GET['filename'] = urldecode(trim($_GET['filename']));
214		if (strpos($_GET['filename'], '?') !== false) $_GET['filename'] = substr($_GET['filename'], 0, strpos($_GET['filename'], '?'));
215		$_GET['saveto'] = urldecode(trim($_GET['saveto']));
216		$_GET['host'] = urldecode(trim($_GET['host']));
217		$_GET['path'] = urldecode(trim($_GET['path']));
218		$_GET['port'] = !empty($_GET['port']) ? urldecode(trim($_GET['port'])) : 80;
219		$_GET['referer'] = !empty($_GET['referer']) ? urldecode(trim($_GET['referer'])) : 0;
220		$_GET['link'] = urldecode(trim($_GET['link']));
221
222		$_GET['post'] = !empty($_GET['post']) ? unserialize(decrypt(urldecode(trim($_GET['post'])))) : 0;
223		$_GET['cookie'] = !empty($_GET['cookie']) ? decrypt(urldecode(trim($_GET['cookie']))) : '';
224		$_GET['proxy'] = !empty($_GET['proxy']) ? trim(urldecode($_GET['proxy'])) : '';
225		// $resume_from = $_GET["resume"] ? intval(urldecode(trim($_GET["resume"]))) : 0;
226		// if ($_GET["resume"]) {unset($_GET["resume"]);}
227		$redirectto = '';
228
229		$pauth = !empty($_GET['pauth']) ? decrypt(urldecode(trim($_GET['pauth']))) : '';
230
231		$_GET['auth'] = !empty($_GET['auth']) ? trim($_GET['auth']) : '';
232		if ($_GET['auth'] == '1') {
233			if (!preg_match('|^(?:.+\.)?(.+\..+)$|i', $_GET['host'], $hostmatch)) html_error('No valid hostname found for authorisation!');
234			$hostmatch = str_replace('.', '_', $hostmatch[1]);
235			if (isset($premium_acc["$hostmatch"]) && is_array($premium_acc["$hostmatch"]) && !empty($premium_acc["$hostmatch"]['user']) && !empty($premium_acc["$hostmatch"]['pass'])) {
236				$auth = base64_encode($premium_acc["$hostmatch"]['user'] . ":" . $premium_acc["$hostmatch"]['pass']);
237			} else html_error('No usable premium account found for this download - please set one in accounts.php');
238		} elseif (!empty($_GET['auth'])) {
239			$auth = decrypt(urldecode($_GET['auth']));
240			$AUTH['use'] = true;
241			$AUTH['str'] = $auth;
242		} else $auth = $AUTH = false;
243
244		$pathWithName = $_GET['saveto'] . PATH_SPLITTER . $_GET['filename'];
245		while (stripos($pathWithName, "\\\\") !== false) {
246			$pathWithName = str_replace("\\\\", "\\", $pathWithName);
247		}
248
249		if (strpos($pathWithName, '?') !== false) $pathWithName = substr($pathWithName, 0, strpos($pathWithName, '?'));
250
251		$url = parse_url($_GET['link']);
252		if (isset($url['scheme']) && $url['scheme'] == 'ftp' && empty($_GET['proxy'])) {
253			$AUTH['ftp'] = array('login' => !empty($url['user']) ? $url['user'] : 'anonymous', 'password' => !empty($url['pass']) ? $url['pass'] : 'anonymous@leechget.com');
254			require_once(CLASS_DIR . 'ftp.php');
255			$file = getftpurl($_GET['host'], !empty($url['port']) ? $url['port'] : 21, $_GET['path'], $pathWithName);
256		} else {
257			require_once(CLASS_DIR . 'http.php');
258			!empty($_GET['force_name']) ? $force_name = urldecode($_GET['force_name']) : '';
259			$file = geturl($_GET['host'], $_GET['port'], $_GET['path'], $_GET['referer'], $_GET['cookie'], $_GET['post'], $pathWithName, $_GET['proxy'], $pauth, $auth, $url['scheme']);
260		}
261
262		if ($options['redir'] && $lastError && strpos($lastError, substr(lang(95), 0, strpos(lang(95), '%1$s'))) !== false) {
263			$redirectto = trim(cut_str($lastError, substr(lang(95), 0, strpos(lang(95), '%1$s')), ']'));
264			print lang(8) . " <b>$redirectto</b> ... <br />$nn";
265			$_GET['referer'] = urlencode($_GET['link']);
266			if (strpos($redirectto, '://') === false) { // If redirect doesn't have the host
267				$ref = parse_url(urldecode($_GET['referer']));
268				unset($ref['user'], $ref['pass'], $ref['query'], $ref['fragment']);
269				if (substr($redirectto, 0, 1) != '/') $redirectto = "/$redirectto";
270				$purl = array_merge($ref, parse_url($redirectto));
271			} else $purl = parse_url($redirectto);
272			$_GET['link'] = urlencode(rebuild_url($purl));
273			$_GET['filename'] = urlencode(basename($purl['path']));
274			$_GET['host'] = urlencode($purl['host']);
275			$_GET['path'] = urlencode($purl['path'] . (!empty($purl['query']) ? '?' . $purl['query'] : ''));
276			$_GET['port'] = !empty($purl['port']) ? $purl['port'] : 80;
277			$_GET['cookie'] = !empty($_GET['cookie']) ? urlencode(encrypt($_GET['cookie'])) : '';
278			if (is_array($_GET['post'])) $_GET['post'] = urlencode(encrypt(serialize($_GET['post'])));
279			if (!empty($_GET['proxy'])) {
280				$_GET['proxy'] = urlencode($_GET['proxy']);
281				if (!empty($pauth)) $_GET['pauth'] = urlencode(encrypt($pauth));
282			}
283			$lastError = $_GET['auth'] = ''; // With $_GET['auth'] empty it will still using the $auth
284			unset($ref, $purl);
285		}
286	} while ($redirectto && !$lastError);
287
288	if ($lastError) html_error($lastError, 0);
289	elseif ($file['bytesReceived'] == $file['bytesTotal'] || $file['size'] == 'Unknown') {
290		echo '<script type="text/javascript">' . "pr(100, '" . $file['size'] . "', '" . $file['speed'] . "')</script>\r\n";
291		echo sprintf(lang(10), link_for_file(dirname($pathWithName) . '/' . basename($file['file'])), $file['size'], $file['time'], $file['speed']);
292		$file['date'] = time();
293
294		if (!write_file(CONFIG_DIR . 'files.lst', serialize(array('name' => $file['file'], 'size' => $file['size'], 'date' => $file['date'], 'link' => $_GET['link'], 'comment' => (!empty($_GET['comment']) ? str_replace(array("\r", "\n"), array('\r', '\n'), $_GET['comment']) : ''))) . "\r\n", 0)) echo lang(9) . '<br />';
295
296		if (!empty($_GET['email']) && !$options['disable_email']) {
297			require_once(CLASS_DIR . 'mail.php');
298			$_GET['partSize'] = (isset($_GET['partSize']) && is_numeric($_GET['partSize']) ? $_GET['partSize'] * 1024 * 1024 : false);
299			if (xmail($fromaddr, $_GET['email'], 'File ' . basename($file['file']), 'File: ' . basename($file['file']) . "\r\n" . 'Link: ' . $_GET['link'] . (!empty($_GET['comment']) ? "\r\n" . 'Comments: ' . str_replace (array('\r', '\n'), array("\r", "\n"), $_GET['comment']) : ''), $pathWithName, $_GET['partSize'], ($_GET['partSize'] && !empty($_GET['method']) ? $_GET['method'] : ''))) {
300				printf(lang(11), $_GET['email'], basename($file['file']));
301			} else echo lang(12) . '<br />';
302		}
303		echo "\n<form method='POST' name='flist' action='$PHP_SELF'>\n";
304		echo "\t<input type='hidden' name='files[]' value='{$file['date']}' /><br />\n";
305		echo "\t<div style='text-align:center;'>\n";
306		echo renderActions();
307		echo "\t</div>\n";
308		echo "</form>\n";
309		if ($options['new_window']) echo '<br /><a href="javascript:window.close();">' . lang(378) . '</a>';
310		else echo "<br /><a href='$PHP_SELF'>" . lang(13) . "</a>";
311
312		if (!empty($_GET['audl'])) echo $nn . '<script type="text/javascript">parent.nextlink();</script>';
313	} else {
314		unlink($pathWithName);
315		print lang(14) . '<br /><a href="javascript:location.reload();">' . lang(15) . '</a>';
316		if (!empty($_GET['audl'])) {
317			echo $nn . '<script type="text/javascript">parent.nextlink();</script>';
318		}
319		echo '<script type="text/javascript">location.reload();</script>';
320	}
321	echo "\n</div>\n</body>\n</html>";
322}
323
324?>