· 8 years ago · Nov 22, 2017, 04:22 AM
1<?php
2if (!defined('RAPIDLEECH')) {
3 require('../deny.php');
4 exit;
5}
6
7function create_hosts_file($host_file = 'hosts.php') { // To be rewritten or deleted
8 $fp = opendir(HOST_DIR . 'download/');
9 while (($file = readdir($fp)) !== false) {
10 if (substr($file, -4) == '.inc') require_once (HOST_DIR . "download/$file");
11 }
12 if (!is_array($host)) html_error(lang(127));
13 else {
14 $fs = fopen(HOST_DIR . "download/$host_file", 'wb');
15 if (!$fs) html_error(lang(128));
16 else {
17 fwrite($fs, "<?php\r\n\$host = array(\r\n");
18 $i = 0;
19 foreach ($host as $site => $file) {
20 if ($i != (count($host) - 1)) fwrite($fs, "'" . $site . "' => '" . $file . "',\r\n");
21 else fwrite($fs, "'" . $site . "' => '" . $file . "');\r\n?>");
22 $i++;
23 }
24 closedir($fp);
25 fclose($fs);
26 }
27 }
28}
29
30function login_check() {
31 global $options;
32 if ($options['login']) {
33 function logged_user($ul) {
34 foreach ($ul as $user => $pass) {
35 if ($_SERVER['PHP_AUTH_USER'] == $user && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_PW'] == $pass) return true;
36 }
37 return false;
38 }
39 if (empty($_SERVER['PHP_AUTH_USER']) && (!empty($_SERVER['HTTP_AUTHORIZATION']) || !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']))) {
40 $auth = !empty($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
41 if (stripos($auth, 'Basic ') === 0 && strpos(($auth = base64_decode(substr($auth, 6))), ':') > 0) list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $auth, 2);
42 unset($auth);
43 }
44 if (empty($_SERVER['PHP_AUTH_USER']) || !logged_user($options['users'])) {
45 header('WWW-Authenticate: Basic realm="RAPIDLEECH PLUGMOD"');
46 header('HTTP/1.0 401 Unauthorized');
47 include('deny.php');
48 exit;
49 }
50 }
51}
52
53function is_present($lpage, $mystr, $strerror = '') {
54 if (stripos($lpage, $mystr) !== false) html_error((!empty($strerror) ? $strerror : $mystr));
55}
56
57function is_notpresent($lpage, $mystr, $strerror) {
58 if (stripos($lpage, $mystr) === false) html_error($strerror);
59}
60
61function insert_location($inputs, $action = 0) {
62 if (!is_array($inputs)) {
63 if (strpos($inputs, '?') !== false) list($action, $inputs) = explode('?', $inputs, 2);
64 $query = explode('&', $inputs);
65 $inputs = array();
66 foreach($query as $q) {
67 list($name, $value) = explode('=', $q, 2);
68 if (empty($name) || empty($value)) continue;
69 $inputs[$name] = $value;
70 }
71 unset($query);
72 }
73
74 if (isset($_GET['GO']) && $_GET['GO'] == 'GO') $_GET = array_merge($_GET, $inputs);
75 else {
76
77 if ($action === 0) $action = $_SERVER['SCRIPT_NAME'];
78 $fname = 'r'.time().'l';
79 echo "\n<form name='$fname' ".(!empty($action) ? "action='$action' " : '')."method='POST'>\n";
80 foreach($inputs as $name => $value) echo "\t<input type='hidden' name='$name' value='" . htmlspecialchars($value, ENT_QUOTES) . "' />\n";
81 echo "</form>\n<script type='text/javascript'>void(document.$fname.submit());</script>\n</body>\n</html>";
82 flush();
83 }
84}
85
86function pause_download() { // To make sure that the files pointers and streams are closed and unlocked.
87 if (!empty($GLOBALS['fs']) && is_resource($GLOBALS['fs'])) {
88 flock($GLOBALS['fs'], LOCK_UN);
89 if (get_resource_type($GLOBALS['fs']) == 'stream') stream_socket_shutdown($GLOBALS['fs'], STREAM_SHUT_RDWR);
90 fclose($GLOBALS['fs']);
91 }
92 if (!empty($GLOBALS['fp']) && is_resource($GLOBALS['fp'])) {
93 flock($GLOBALS['fp'], LOCK_UN);
94 if (get_resource_type($GLOBALS['fp']) == 'stream') stream_socket_shutdown($GLOBALS['fp'], STREAM_SHUT_RDWR);
95 fclose($GLOBALS['fp']);
96 }
97}
98
99function cut_str($str, $left, $right) {
100 $str = substr(stristr($str, $left), strlen($left));
101 $leftLen = strlen(stristr($str, $right));
102 $leftLen = $leftLen ? -($leftLen) : strlen($str);
103 $str = substr($str, 0, $leftLen);
104 return $str;
105}
106
107// tweaked cutstr with pluresearch functionality
108function cutter($str, $left, $right, $cont = 1) {
109 for($iii = 1; $iii <= $cont; $iii++) $str = substr(stristr($str, $left), strlen($left));
110 $leftLen = strlen(stristr($str, $right));
111 $leftLen = $leftLen ? -($leftLen) : strlen($str);
112 $str = substr($str, 0, $leftLen);
113 return $str;
114}
115
116function write_file($file_name, $data, $trunk = 1) {
117 if ($trunk == 1) $mode = 'wb';
118 elseif ($trunk == 0) $mode = 'ab';
119 $fp = fopen($file_name, $mode);
120 if (!$fp || !flock($fp, LOCK_EX) || !fwrite($fp, $data) || !flock($fp, LOCK_UN) || !fclose($fp)) return FALSE;
121 return TRUE;
122}
123
124function read_file($file_name, $count = -1) {
125 if ($count == -1) $count = filesize($file_name);
126 $fp = fopen($file_name, 'rb');
127 flock($fp, LOCK_SH);
128 $ret = fread($fp, $count);
129 flock($fp, LOCK_UN);
130 fclose($fp);
131 return $ret;
132}
133
134function pre($var) {
135 echo "<pre>\n" . htmlspecialchars(print_r($var, true)) . "\n</pre>\n";
136}
137
138function getmicrotime() {
139 list ($usec, $sec) = explode(' ', microtime());
140 return ((float)$usec + (float)$sec);
141}
142
143function html_error($msg) {
144 if (!empty($GLOBALS['throwRLErrors']) || (strtolower(basename($_SERVER['SCRIPT_NAME'])) == 'audl.php' && isset($_REQUEST['GO']) && $_REQUEST['GO'] == 'GO' && $_REQUEST['server_side'] == 'on' && !empty($GLOBALS['isHost']))) throw new Exception($msg); // throw errors for try and catch usage.
145 else {
146 if (!headers_sent()) include_once(TEMPLATE_DIR.'header.php');
147 echo '<div align="center">';
148 echo "<span class='htmlerror'><b>$msg</b></span><br /><br />";
149 if (isset($_GET['audl'])) echo '<script type="text/javascript">parent.nextlink();</script>';
150 if (!empty($GLOBALS['options']['new_window'])) echo '<a href="javascript:window.close();">'.lang(378).'</a>';
151 else echo '<a href="'.htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES).'">'.lang(13).'</a>';
152 echo '</div>';
153 }
154 pause_download();
155 include(TEMPLATE_DIR.'footer.php');
156 exit();
157}
158
159function sec2time($time) {
160 $hour = round($time / 3600, 2);
161 if ($hour >= 1) {
162 $hour = floor($hour);
163 $time -= $hour * 3600;
164 }
165 $min = round($time / 60, 2);
166 if ($min >= 1) {
167 $min = floor($min);
168 $time -= $min * 60;
169 }
170 $sec = $time;
171 $hour = ($hour > 1) ? $hour . ' ' . lang(129) . ' ' : ($hour == 1) ? $hour . ' ' . lang(130).' ' : '';
172 $min = ($min > 1) ? $min . ' ' . lang(131) . ' ' : ($min == 1) ? $min . ' ' . lang(132).' ' : '';
173 $sec = ($sec > 1) ? $sec . ' ' . lang(133) : ($sec == 1 || $sec == 0) ? $sec . ' ' . lang(134) : '';
174 return $hour . $min . $sec;
175}
176
177// Updated function to be able to format up to Yotabytes!
178function bytesToKbOrMbOrGb($bytes) {
179 if (is_numeric($bytes)) {
180 $s = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
181 $e = floor(log($bytes) / log(1024));
182 return sprintf('%.2f ' . $s[$e], @($bytes / pow(1024, floor($e))));
183 } else $size = 'Unknown';
184 return $size;
185}
186
187function updateListInFile($list) {
188 if (count($list) > 0) {
189 foreach($list as $key => $value) $list[$key] = serialize($value);
190 if (!@write_file(CONFIG_DIR . 'files.lst', implode("\r\n", $list) . "\r\n") && count($list) > 0) return FALSE;
191 else return TRUE;
192 } elseif (@file_exists(CONFIG_DIR . 'files.lst')) {
193 // Truncate files.lst instead of removing it since we don't have full
194 // read/write permission on the configs folder
195 $fh = fopen(CONFIG_DIR . 'files.lst','w');
196 fclose($fh);
197 return true;
198 }
199}
200
201function _cmp_list_enums($a, $b) {
202 return strcmp($a['name'], $b['name']);
203}
204
205function file_data_size_time($file) {
206 $size = $time = false;
207 if (is_file($file)) {
208 $size = @filesize($file);
209 $time = @filemtime($file);
210 }
211 if ($size === false && $GLOBALS['options']['2gb_fix'] && file_exists($file) && !is_dir($file) && !is_link($file)) {
212 if (substr(PHP_OS, 0, 3) !== 'WIN') {
213 @exec('stat' . (stripos(@php_uname('s'), 'bsd') !== false ? '-f %m ' : ' -c %Y ') . escapeshellarg($file), $time, $tmp);
214 if ($tmp == 0) $time = trim(implode($time));
215 @exec('stat' . (stripos(@php_uname('s'), 'bsd') !== false ? '-f %z ' : ' -c %s ') . escapeshellarg($file), $size, $tmp);
216 if ($tmp == 0) $size = trim(implode($size));
217 }
218 }
219 if ($size === false || $time === false) { return false; }
220 return array($size, $time);
221}
222
223function _create_list() {
224 $glist = array();
225 if (($GLOBALS['options']['show_all'] === true) && (isset($_COOKIE['showAll']) && $_COOKIE['showAll'] == 1)) {
226 $dir = dir(DOWNLOAD_DIR);
227 while(false !== ($file = $dir->read())) {
228 if ($file == '.' || $file == '..' || ($tmp = file_data_size_time(DOWNLOAD_DIR.$file)) === false) continue;
229 list($size, $time) = $tmp;
230 if (!is_array($GLOBALS['options']['forbidden_filetypes']) || !in_array(strtolower(strrchr($file, '.')), $GLOBALS['options']['forbidden_filetypes'])) {
231 $file = DOWNLOAD_DIR . $file;
232 while(isset($glist[$time])) $time++;
233 $glist[$time] = array('name' => realpath($file), 'size' => bytesToKbOrMbOrGb($size), 'date' => $time);
234 }
235 }
236 $dir->close();
237 @uasort($glist, '_cmp_list_enums');
238 } else {
239 if (@file_exists(CONFIG_DIR . 'files.lst') && ($glist = file(CONFIG_DIR . 'files.lst')) !== false) {
240 $listReformat = array();
241 foreach($glist as $key => $record) {
242 if ($record = @unserialize($record)) {
243 $date = 0;
244 foreach($record as $field => $value) {
245 switch ($field) {
246 case 'date':
247 $date = $value;
248 default:
249 $listReformat[$key][$field] = $value;
250 break;
251 case 'comment':
252 $listReformat[$key][$field] = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
253 break;
254 }
255 }
256 if (!empty($date)) $glist[$date] = $listReformat[$key];
257 }
258 unset($glist[$key], $listReformat[$key]);
259 }
260 }
261 }
262 $GLOBALS['list'] = $glist;
263}
264
265function checkmail($mail) {
266 if (strlen($mail) == 0 || strpos($mail, '@') === false || strpos($mail, '.') === false || !preg_match('/^[a-z0-9_\.-]{1,20}@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/is', $mail)) return false;
267 return true;
268}
269
270/* Fixed Shell exploit by: icedog */
271function fixfilename($fname, $fpach = '') {
272 $f_name = basename($fname);
273 $f_dir = dirname(preg_replace('@\.\./@i', '', $fname));
274 $f_dir = ($f_dir == '.') ? '' : $f_dir;
275 $f_dir = preg_replace('@\.\./@i', '', $f_dir);
276 $fpach = preg_replace('@\.\./@i', '', $fpach);
277 $f_name = preg_replace('@\.(((s|\d)?php)|(hta)|(p[l|y])|(cgi)|(sph))@i', '.xxx', $f_name);
278 $ret = ($fpach) ? $fpach . DIRECTORY_SEPARATOR . $f_name : ($f_dir ? $f_dir . DIRECTORY_SEPARATOR : '') . $f_name;
279 return $ret;
280}
281
282function getfilesize($f) {
283 $stat = stat($f);
284
285 if ($GLOBALS['is_windows'] || (($stat[11] * $stat[12]) < 4 * 1024 * 1024 * 1024)) return sprintf('%u', $stat[7]);
286
287 global $max_4gb;
288 if ($max_4gb === false) {
289 $tmp_ = trim(@shell_exec('ls -Ll ' . @escapeshellarg($f)));
290 while(strstr($tmp_, ' ')) $tmp_ = @str_replace(' ', ' ', $tmp_);
291 $r = @explode(' ', $tmp_);
292 $size_ = $r[4];
293 } else $size_ = -1;
294
295 return $size_;
296}
297
298function bytesToKbOrMb($bytes) {
299 $size = ($bytes >= (1024 * 1024 * 1024 * 1024)) ? round($bytes / (1024 * 1024 * 1024 * 1024), 2) . ' TB' : (($bytes >= (1024 * 1024 * 1024)) ? round($bytes / (1024 * 1024 * 1024), 2) . ' GB' : (($bytes >= (1024 * 1024)) ? round($bytes / (1024 * 1024), 2) . ' MB' : round($bytes / 1024, 2) . ' KB'));
300 return $size;
301}
302
303function defport($urls) {
304 if (!empty($urls['port'])) return $urls['port'];
305 switch(strtolower($urls['scheme'])) {
306 case 'http' :
307 return '80';
308 case 'https' :
309 return '443';
310 case 'ftp' :
311 return '21';
312 }
313}
314
315function getSize($file) {
316 $size = filesize($file);
317 if ($size < 0) {
318 if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
319 $file = @escapeshellarg($file);
320 $size = trim(`stat -c%s $file`);
321 } else {
322 $fsobj = new COM('Scripting.FileSystemObject');
323 $f = $fsobj->GetFile($file);
324 $size = $file->Size;
325 }
326 }
327 return $size;
328}
329
330function purge_files($delay) {
331 if (file_exists(CONFIG_DIR . 'files.lst') && is_numeric($delay) && $delay > 0) {
332 $files_lst = file(CONFIG_DIR . 'files.lst');
333 $files_new = '';
334 foreach ($files_lst as $files_line) {
335 $files_data = unserialize(trim($files_line));
336 if (file_exists($files_data['name']) && is_file($files_data['name'])) {
337 if (time() - $files_data['date'] >= $delay) @unlink ($files_data['name']);
338 else $files_new .= $files_line;
339 }
340 }
341 file_put_contents(CONFIG_DIR . 'files.lst', $files_new);
342 }
343}
344
345// Using this function instead due to some compatibility problems
346function is__writable($path) {
347 //will work in despite of Windows ACLs bug
348 //NOTE: use a trailing slash for folders!!!
349 //see http://bugs.php.net/bug.php?id=27609
350 //see http://bugs.php.net/bug.php?id=30931
351
352 if ($path[strlen($path) - 1] == '/') return is__writable($path . uniqid(mt_rand()) . '.tmp');// recursively return a temporary file path
353 else if (is_dir($path)) return is__writable($path . '/' . uniqid(mt_rand()) . '.tmp');
354 // check tmp file for read/write capabilities
355 $rm = file_exists($path);
356 $f = @fopen($path, 'a');
357 if ($f === false) return false;
358 fclose($f);
359 if (!$rm) unlink($path);
360 return true;
361}
362
363function link_for_file($filename, $only_link = FALSE, $style = '') {
364
365 $inCurrDir = strpos(dirname($filename), ROOT_DIR) !== FALSE ? TRUE : FALSE;
366 if ($inCurrDir) {
367 $Path = parse_url($_SERVER['SCRIPT_NAME']);
368
369 $Path = substr($Path['path'], 0, strlen($Path['path']) - strlen(strrchr($Path['path'], '/')));
370 $Path = str_replace('\\', '/', $Path.substr(dirname($filename), strlen(ROOT_DIR)));
371
372
373 } elseif (dirname($_SERVER ['SCRIPT_NAME'].'safe') != '/') {
374 $in_webdir_path = dirname(str_replace('\\', '/', $_SERVER ['SCRIPT_NAME'].'safe'));
375 $in_webdir_sub = substr_count($in_webdir_path, '/');
376 $in_webdir_root = ROOT_DIR.'/';
377 for ($i=1; $i <= $in_webdir_sub; $i++) {
378 $in_webdir_path = substr($in_webdir_path, 0, strrpos($in_webdir_path, '/'));
379 $in_webdir_root = realpath($in_webdir_root.'/../').'/';
380 $in_webdir = (strpos(str_replace('\\', '/', dirname($filename).'/'), str_replace('\\', '/', $in_webdir_root)) === 0) ? TRUE : FALSE;
381 if ($in_webdir) {
382 $Path = dirname($in_webdir_path.'/'.substr($filename, strlen($in_webdir_root)));
383 break;
384 }
385 }
386 } else {
387 $Path = FALSE;
388 if ($only_link) return '';
389 }
390
391 $basename = basename($filename);
392 $Path = $Path.'/'.rawurlencode($basename);
393 if ($only_link) return 'http://'.$_SERVER['HTTP_HOST'].$Path;
394 elseif ($Path === FALSE) return '<span>' . htmlspecialchars($basename) . '</span>';
395 else return '<a href="downloader.php?file='. urlencode(base64_encode(urldecode(htmlspecialchars($Path, ENT_QUOTES)))).'"'.($style !== '' ? ' '.$style : '').'>'.htmlspecialchars($basename).'</a>';
396}
397
398function lang($id) {
399 global $lang;
400 if (empty($lang) || !is_array($lang)) $lang = array();
401 if (basename($GLOBALS['options']['default_language']) != 'en' && file_exists('languages/en.php')) require_once('languages/en.php');
402 require_once('languages/'.basename($GLOBALS['options']['default_language']).'.php');
403 return $lang[$id];
404}
405
406#need to keep premium account cookies safe!
407function encrypt($string) {
408 global $secretkey;
409 if (!$secretkey) return html_error('Value for $secretkey is empty, please create a random one (56 chars max) in config.php!');
410 require_once 'class.pcrypt.php';
411
412 /*
413 MODE: MODE_ECB or MODE_CBC
414 ALGO: BLOWFISH
415 KEY: Your secret key :) (max lenght: 56)
416 */
417 $crypt = new pcrypt(MODE_CBC, 'BLOWFISH', "$secretkey");
418
419 // to encrypt
420 $ciphertext = $crypt->encrypt($string);
421
422 return $ciphertext;
423}
424
425function decrypt($string) {
426 global $secretkey;
427 if (!$secretkey) return html_error('Value for $secretkey is empty, please create a random one (56 chars max) in config.php!');
428 require_once 'class.pcrypt.php';
429
430 /*
431 MODE: MODE_ECB or MODE_CBC
432 ALGO: BLOWFISH
433 KEY: Your secret key :) (max lenght: 56)
434 */
435 $crypt = new pcrypt(MODE_CBC, 'BLOWFISH', "$secretkey");
436
437 // to decrypt
438 $decrypted = $crypt->decrypt($string);
439
440 return $decrypted;
441}
442
443/**
444 * Textarea for debugging variable
445 * @param string The variable you want to debug
446 * @param int Column for variable display
447 * @param int Rows for variable display
448 * @param bool Options to continue or not process
449 * @param string Charset encoding for htmlspecialchars
450 */
451function textarea($var, $cols = 100, $rows = 30, $stop = false, $char = 'UTF-8') {
452 $cols = ($cols == 0) ? 100 : $cols;
453 $rows = ($rows == 0) ? 30 : $rows;
454 if ($char === false) $char = 'ISO-8859-1';
455 echo "\n<br /><textarea cols='$cols' rows='$rows' readonly='readonly'>";
456 if (is_array($var)) $text = htmlspecialchars(print_r($var, true), ENT_QUOTES, $char);
457 else $text = htmlspecialchars($var, ENT_QUOTES, $char);
458 if (empty($text) && !empty($var)) { // Fix "empty?" textarea bug
459 $char = ($char == 'ISO-8859-1') ? '' : 'ISO-8859-1';
460 if (is_array($var)) $text = htmlspecialchars(print_r($var, true), ENT_QUOTES, $char);
461 else $text = htmlspecialchars($var, ENT_QUOTES, $char);
462 }
463 echo "$text</textarea><br />\n";
464 if ($stop) exit;
465}
466
467// Get time in miliseconds, like getTime() in javascript
468function jstime() {
469 list($u, $s) = explode(' ', microtime());
470 return sprintf('%d%03d', $s, $u*1000);
471}
472
473function check_referer() {
474 $refhost = !empty($_SERVER['HTTP_REFERER']) ? cut_str($_SERVER['HTTP_REFERER'], '://', '/') : false;
475 if (empty($refhost)) return;
476
477 //Remove the port.
478 $httphost = ($pos = strpos($_SERVER['HTTP_HOST'], ':')) !== false ? substr($_SERVER['HTTP_HOST'], 0, $pos) : $_SERVER['HTTP_HOST'];
479 $refhost = ($pos = strpos($refhost, ':')) !== false ? substr($refhost, 0, $pos) : $refhost;
480 // If there is a login on the referer, remove it.
481 $refhost = ($pos = strpos($refhost, '@')) !== false ? substr($refhost, $pos+1) : $refhost;
482
483 $whitelist = array($httphost, 'localhost', 'rapidleech.com');
484 $is_ext = ($refhost == $_SERVER['SERVER_ADDR'] ? false : true);
485 if ($is_ext)
486 foreach ($whitelist as $host)
487 if (host_matches($host, $refhost)) {
488 $is_ext = false;
489 break;
490 }
491
492 if ($is_ext) {
493 // Uncomment next line if you want rickroll the users from Form leechers.
494 // header("Location: http://www.youtube.com/watch?v=oHg5SJYRHA0");
495 html_error(sprintf(lang(7), $refhost, 'External referer not allowed.'));
496 }
497}
498
499function rebuild_url($url) {
500 $url['scheme'] = strtolower($url['scheme']);
501 return $url['scheme'] . '://' . (!empty($url['user']) && !empty($url['pass']) ? rawurlencode($url['user']) . ':' . rawurlencode($url['pass']) . '@' : '') . strtolower($url['host']) . (!empty($url['port']) && $url['port'] != defport(array('scheme' => $url['scheme'])) ? ':' . $url['port'] : '') . (empty($url['path']) ? '/' : $url['path']) . (!empty($url['query']) ? '?' . $url['query'] : '') . (!empty($url['fragment']) ? '#' . $url['fragment'] : '');
502}
503
504if (!function_exists('http_chunked_decode')) {
505 // Added implementation from a comment at php.net's function page
506 function http_chunked_decode($chunk) {
507 $pos = 0;
508 $len = strlen($chunk);
509 $dechunk = null;
510
511 while(($pos < $len) && ($chunkLenHex = substr($chunk, $pos, ($newlineAt = strpos($chunk, "\n", $pos + 1)) - $pos))) {
512 if (!is_hex($chunkLenHex)) {
513 trigger_error('Value is not properly chunk encoded_', E_USER_WARNING);
514 return false;
515 }
516
517 $pos = $newlineAt + 1;
518 $chunkLen = hexdec(rtrim($chunkLenHex, "\r\n"));
519 $dechunk .= substr($chunk, $pos, $chunkLen);
520 $pos = strpos($chunk, "\n", $pos + $chunkLen) + 1;
521 }
522 return $dechunk;
523 }
524
525 function is_hex($hex) {
526 $hex = strtolower(trim(ltrim($hex, '0')));
527 if (empty($hex)) $hex = 0;
528 $dec = hexdec($hex);
529 return ($hex == dechex($dec));
530 }
531}
532
533function host_matches($site, $host) {
534 if (empty($site) || empty($host)) return false;
535 if (strtolower($site) == strtolower($host)) return true;
536 if (($pos = strripos($host, $site)) !== false && ($pos + strlen($site) == strlen($host)) && $pos > 1 && substr($host, $pos - 1, 1) == '.') return true;
537 return false;
538}
539
540function GetDefaultParams() {
541 $DParam = array();
542 if (!empty($_GET['useproxy']) && !empty($_GET['proxy'])) {
543 $DParam['useproxy'] = 'on';
544 $DParam['proxy'] = $_GET['proxy'];
545 if (!empty($GLOBALS['pauth'])) $DParam['pauth'] = urlencode(encrypt($GLOBALS['pauth']));
546 }
547 if (isset($_GET['autoclose'])) $DParam['autoclose'] = '1';
548 if (isset($_GET['audl'])) $DParam['audl'] = 'doum';
549 if (isset($_GET['premium_acc']) && $_GET['premium_acc'] == 'on') $DParam['premium_acc'] = 'on';
550 if ($GLOBALS['options']['download_dir_is_changeable'] && !empty($_GET['path'])) $DParam['saveto'] = urlencode($_GET['path']);
551 $params = array('add_comment', 'domail', 'comment', 'email', 'split', 'partSize', 'method', 'uploadlater', 'uploadtohost');
552 foreach ($params as $key) if (!empty($_GET[$key])) $DParam[$key] = $_GET[$key];
553 return $DParam;
554}
555
556?>