PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/classes/other.php

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