PageRenderTime 110ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/classes/other.php

http://rapidleech36b.googlecode.com/
PHP | 1757 lines | 1437 code | 143 blank | 177 comment | 470 complexity | f20eb7041d57ee415651dd9f9c4ba373 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require('../404.php');
  4. exit;
  5. }
  6. /* Index Function */ {
  7. // THIS FILE CONTAINS GENERAL FUNCTION NEEDED
  8. // METHODS IN THIS FILE:
  9. // create_hosts_file()
  10. // login_check()
  11. // is_present()
  12. // is_notpresent()
  13. // insert_location()
  14. // pause_download()
  15. // cut_str()
  16. // write_file()
  17. // read_file()
  18. // pre()
  19. // getmicrotime()
  20. // html_error()
  21. // sec1time()
  22. // sec2time()
  23. // updateListInFile()
  24. // _cmp_list_enums()
  25. // file_data_size_time()
  26. // _create_list()
  27. // _create_list_LIP()
  28. // checkmail()
  29. // fixfilename()
  30. // getfilesize()
  31. // bytesToKbOrMb()
  32. // bytesToKbOrMbOrGb()
  33. // defport()
  34. // getSize()
  35. // purge_files()
  36. // purge_files_ip()
  37. // file_put_contents()
  38. // file_get_contents()
  39. // http_chunked_decode()
  40. // is_hex()
  41. // is__writable()
  42. // link_for_file()
  43. // textarea()
  44. // jstime()
  45. // check_referer()
  46. // rebuild_url()
  47. // getNowzone()
  48. // checkExistence()
  49. // calcUsedSpace()
  50. // do_strtolower()
  51. // get_extension()
  52. // get_tpl()
  53. // urlcleaner()
  54. // trimlink()
  55. // xmlentities()
  56. // strip_quotes()
  57. // buildRetryform()
  58. // get_real_ip()
  59. // chk_this_ip()
  60. // dcd()
  61. // mcd()
  62. // encEnti()
  63. // decEnti()
  64. // rotN()
  65. // encrypt()
  66. // decrypt()
  67. // autoNext()
  68. // getServerPlatf()
  69. // color_cpu()
  70. // count_age()
  71. // cek_worktime()
  72. // relink_path()
  73. // utf8_strrev()
  74. // checkStrict()
  75. // ip counter()
  76. // renderAction()
  77. // vidlist()
  78. // ________()
  79. }
  80. function create_hosts_file($host_file = "hosts.php") {
  81. global $L;
  82. $fp = opendir(HOST_DIR . 'download/');
  83. while (($file = readdir($fp)) !== false) {
  84. if (substr($file, - 4) == ".inc") {
  85. require_once (HOST_DIR . 'download/' . $file);
  86. }
  87. }
  88. if (!is_array($host)) {
  89. print $L->say['no_host'];
  90. } else {
  91. $fs = fopen(HOST_DIR . 'download/' . $host_file, "wb");
  92. if (!$fs) {
  93. print $L->say['cant_write_host'];
  94. } else {
  95. fwrite($fs, "<?php\r\n\$host = array(\r\n");
  96. $i = 0;
  97. foreach ($host as $site => $file) {
  98. if ($i != (count($host) - 1)) {
  99. fwrite($fs, "'" . $site . "' => '" . $file . "',\r\n");
  100. } else {
  101. fwrite($fs, "'" . $site . "' => '" . $file . "');\r\n?>");
  102. }
  103. $i++;
  104. }
  105. closedir($fp);
  106. fclose($fs);
  107. }
  108. }
  109. }
  110. function login_check() {
  111. global $options;
  112. if ($options['login']) {
  113. function logged_user($ul) {
  114. foreach ($ul as $user => $pass) {
  115. if ($_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $pass) {
  116. return true;
  117. }
  118. }
  119. return false;
  120. }
  121. if ($options['login_cgi']) {
  122. 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);
  123. }
  124. if (empty($_SERVER['PHP_AUTH_USER']) || !logged_user($options['users'])) {
  125. header('WWW-Authenticate: Basic realm="Rx08"');
  126. header("HTTP/1.0 401 Unauthorized");
  127. get_tpl("404", "NuLL");
  128. exit;
  129. }
  130. }
  131. }
  132. function is_present($lpage, $mystr, $strerror = "", $head = 0) {
  133. $strerror = $strerror ? $strerror : $mystr;
  134. if (stripos($lpage, $mystr) !== false) {
  135. html_error($strerror, $head);
  136. }
  137. }
  138. function is_notpresent($lpage, $mystr, $strerror, $head = 0) {
  139. if (stripos($lpage, $mystr) === false) {
  140. html_error($strerror, $head);
  141. }
  142. }
  143. function insert_location($newlocation) {
  144. if (isset($_GET ["GO"]) && $_GET ["GO"] == "GO") {
  145. list ( $location, $list ) = explode("?", $newlocation);
  146. $list = explode("&", $list);
  147. foreach ($list as $l) {
  148. list ( $name, $value ) = explode("=", $l);
  149. $_GET [$name] = $value;
  150. }
  151. } else {
  152. global $nn;
  153. list ( $location, $list ) = explode("?", $newlocation);
  154. $list = explode("&", $list);
  155. print "<form action=\"$location\" method=\"post\">" . $nn;
  156. foreach ($list as $l) {
  157. list ( $name, $value ) = explode("=", $l);
  158. print "<input type=\"hidden\" name=\"$name\" value=\"$value\" />" . $nn;
  159. }
  160. echo ('<script type="text/javascript">void(document.forms[0].submit());</script>');
  161. echo ('</form>');
  162. echo ('</body>');
  163. echo ('</html>');
  164. flush();
  165. }
  166. }
  167. function pause_download() {
  168. global $pathWithName, $PHP_SELF, $_GET, $nn, $bytesReceived, $fs, $fp;
  169. $status = connection_status();
  170. if (($status == 2 || $status == 3) && $pathWithName && $bytesReceived > - 1) {
  171. flock($fs, LOCK_UN);
  172. fclose($fs);
  173. fclose($fp);
  174. }
  175. }
  176. // tweaked cut_str with pluresearch functionality
  177. function cut_str($str, $left, $right, $cont=1) {
  178. for ($iii = 1; $iii <= $cont; $iii++) {
  179. $str = substr(stristr($str, $left), strlen($left));
  180. }
  181. $leftLen = strlen(stristr($str, $right));
  182. $leftLen = $leftLen ? - ($leftLen) : strlen($str);
  183. $str = substr($str, 0, $leftLen);
  184. return $str;
  185. }
  186. function write_file($file_name, $data, $trunk = 1) {
  187. if ($trunk == 1) {
  188. $mode = "wb";
  189. } elseif ($trunk == 0) {
  190. $mode = "ab";
  191. }
  192. $fp = fopen($file_name, $mode);
  193. if (!$fp) {
  194. return FALSE;
  195. } else {
  196. if (!flock($fp, LOCK_EX)) {
  197. return FALSE;
  198. } else {
  199. if (!fwrite($fp, $data)) {
  200. return FALSE;
  201. } else {
  202. if (!flock($fp, LOCK_UN)) {
  203. return FALSE;
  204. } else {
  205. if (!fclose($fp)) {
  206. return FALSE;
  207. }
  208. }
  209. }
  210. }
  211. }
  212. return TRUE;
  213. }
  214. function read_file($file_name, $count = -1) {
  215. if ($count == - 1) {
  216. $count = filesize($file_name);
  217. }
  218. $fp = fopen($file_name, "rb");
  219. flock($fp, LOCK_SH);
  220. $ret = fread($fp, $count);
  221. flock($fp, LOCK_UN);
  222. fclose($fp);
  223. return $ret;
  224. }
  225. function pre($var, $stop = false) {
  226. if (!is_array($var) && strip_tags($var) != $var) {
  227. echo "<pre>"; var_dump(htmlentities($var)); echo "</pre>";
  228. } else {
  229. echo "<pre>"; var_dump($var); echo "</pre>";
  230. }
  231. if ($stop) exit;
  232. }
  233. function getmicrotime() {
  234. list ( $usec, $sec ) = explode(" ", microtime());
  235. return ((float) $usec + (float) $sec);
  236. }
  237. function html_error($msg, $newwin = 1, $retry = 0) {
  238. global $PHP_SELF, $options, $L, $RL_VER, $nn;
  239. //if ($head == 1)
  240. if (!headers_sent()) {
  241. $litehead = 1;
  242. include(TEMPLATE_DIR . 'header.php');
  243. }
  244. echo ('<div align="center">');
  245. echo ('<span class="htmlerror"><b>' . $msg . '</b></span><br /><br />');
  246. if ($retry == 1) {
  247. echo buildRetryform($msg);
  248. } elseif ($options['new_window'] && $newwin) {
  249. echo '<a href="javascript:window.close();">' . $L->say['closewin'] . '</a>';
  250. } else {
  251. echo ('<a id="tdone" href="' . $PHP_SELF . '"><b>' . $L->say['back_main'] . '</b></a>');
  252. }
  253. if ($audlparam != '') {
  254. $audlparam = explode('|', $audlparam);
  255. if ($audlparam[0] != '') {
  256. $audlparam[0] = true;
  257. }
  258. if ($audlparam[1] == '') {
  259. $audlparam[1] = 'none';
  260. }
  261. echo autoNext($audlparam[0], false, $audlparam[1]);
  262. }
  263. flush();
  264. echo ('</div>');
  265. echo ($nn . '</body></html>');
  266. exit();
  267. }
  268. function sec1time($time) {
  269. global $L;
  270. $hour = round($time / 3600, 2);
  271. if ($hour >= 1) {
  272. $hour = floor($hour);
  273. $time -= $hour * 3600;
  274. }
  275. $min = round($time / 60, 2);
  276. if ($min >= 1) {
  277. $min = floor($min);
  278. $time -= $min * 60;
  279. }
  280. $sec = $time;
  281. $hour = ($hour > 1) ? $hour . " " . $L->say['hours'] . " " : ($hour == 1) ? $hour . " " . $L->say['hours'] . " " : "";
  282. $min = ($min > 1) ? $min . " " . $L->say['minutes'] . " " : ($min == 1) ? $min . " " . $L->say['minutes'] . " " : "";
  283. $sec = ($sec > 1) ? $sec . " " . $L->say['seconds'] . "" : ($sec == 1) ? $sec . " " . $L->say['seconds'] . "" : "";
  284. return $hour . $min . $sec;
  285. }
  286. function sec2time($time) {
  287. global $L;
  288. $day = round($time / (3600 * 24), 2);
  289. if ($day >= 1) {
  290. $day = floor($day);
  291. $time -= $day * 3600 * 24;
  292. }
  293. $hour = round($time / 3600, 2);
  294. if ($hour >= 1) {
  295. $hour = floor($hour);
  296. $time -= $hour * 3600;
  297. }
  298. $min = round($time / 60, 2);
  299. if ($min >= 1) {
  300. $min = floor($min);
  301. $time -= $min * 60;
  302. }
  303. $sec = $time;
  304. $day = ( ($day > 1) ? $day . " " . $L->say['days'] . " " : (($day == 1) ? $day . " " . $L->say['days'] . " " : "") );
  305. $hour = ($hour > 1) ? $hour . " " . $L->say['hours'] . " " : ($hour == 1) ? $hour . " " . $L->say['hours'] . " " : "";
  306. $min = ($min > 1) ? $min . " " . $L->say['minutes'] . " " : ($min == 1) ? $min . " " . $L->say['minutes'] . " " : "";
  307. $sec = ($sec > 1) ? $sec . " " . $L->say['seconds'] : ($sec == 1 || $sec == 0) ? $sec . " " . $L->say['seconds'] : "";
  308. return $day . $hour . $min . $sec;
  309. }
  310. function updateListInFile($list) {
  311. if (is_array($list) && count($list) > 0) {
  312. foreach ($list as $key => $value) {
  313. $list [$key] = serialize($value);
  314. }
  315. //echo file_put_contents ( FILES_LST, implode ( "\r\n", $list ) . "\r\n" );
  316. if (!file_put_contents(FILES_LST, implode("\r\n", $list) . "\r\n") && count($list) > 0) {
  317. return FALSE;
  318. } else {
  319. return TRUE;
  320. }
  321. } elseif (@file_exists(FILES_LST)) {
  322. // Truncate files.lst instead of removing it since we don't have full
  323. // read/write permission on the configs folder
  324. $fh = fopen(FILES_LST, 'w');
  325. fclose($fh);
  326. return true;
  327. }
  328. }
  329. function _cmp_list_enums($a, $b) {
  330. //return strcmp ( $a ["name"], $b ["name"] );
  331. if (isset($a["date"]) && isset($b["date"])) {
  332. return strcmp($a["date"], $b["date"]);
  333. } else {
  334. return strcmp($a["name"], $b["name"]);
  335. }
  336. }
  337. function file_data_size_time($file) {
  338. global $options;
  339. $size = $time = false;
  340. if (is_file($file)) {
  341. $size = @filesize($file);
  342. $time = @filemtime($file);
  343. }
  344. if ($size === false && $options['2gb_fix'] && file_exists($file) && !is_dir($file) && !is_link($file)) {
  345. if (substr(PHP_OS, 0, 3) !== "WIN") {
  346. @exec('stat' . (stristr(@php_uname('s'), 'bsd') !== false ? '-f %m ' : ' -c %Y ') . escapeshellarg($file), $time, $tmp);
  347. if ($tmp == 0) {
  348. $time = trim(implode($time));
  349. }
  350. @exec('stat' . (stristr(@php_uname('s'), 'bsd') !== false ? '-f %z ' : ' -c %s ') . escapeshellarg($file), $size, $tmp);
  351. if ($tmp == 0) {
  352. $size = trim(implode($size));
  353. }
  354. }
  355. }
  356. if ($size === false || $time === false) {
  357. return false;
  358. }
  359. return array($size, $time);
  360. }
  361. function _create_list($lynx = false, $medic=false, $d_showall=false) {
  362. global $list, $_COOKIE, $options;
  363. $glist = array();
  364. //$unix_now = ( TIME_NOW - date("Z") + (3600 * $options["timezone"]));
  365. if (!$d_showall) $d_showall = (isset($_COOKIE["showAll"]) ? $_COOKIE["showAll"] : false);
  366. if (($options["show_all"] && ($d_showall == 1)) || $medic) {
  367. // Show Everything
  368. $totsize = 0; $cnt = 0;
  369. $dir = @dir(DOWNLOAD_DIR);
  370. while (false !== ($file = $dir->read())) {
  371. if ($file != "." && $file != ".." && is_array($options["forbidden_filetypes"]) && !in_array("." . get_extension($file), $options["forbidden_filetypes"]) && is_file(DOWNLOAD_DIR . $file) && basename($file) != basename(FILES_LST) && basename($file) != 'index.html' && basename($file) != 'index.php') {
  372. $file = DOWNLOAD_DIR . $file;
  373. if (($tmp = file_data_size_time($file)) === false) continue; list($size, $time) = $tmp;
  374. $time = getNowzone($time);
  375. while (isset($glist[$time])) $time++;
  376. $agefile = (TIME_NOW - $time);
  377. $glist[$time] = array("name" => realpath($file), "size" => bytesToKbOrMbOrGb($size), "date" => $time, "age" => count_age($agefile));
  378. if ($options["show_column_sfile"]["md5"] && !$lynx) $glist[$time]["md5"] = md5_file($file);
  379. $totsize+=$size; $cnt++;
  380. }
  381. }
  382. $dir->close();
  383. @uasort($glist, "_cmp_list_enums");
  384. if ($cnt > 0) {
  385. $glist["files"]["totalsize"] = $totsize;
  386. $glist["files"]["totalfile"] = $cnt;
  387. $glist["files"]["misc"] = "files";
  388. }
  389. } else {
  390. // Show Downloaded
  391. if (@file_exists(FILES_LST)) {
  392. $glist = file(FILES_LST);
  393. $glistReformat = null;
  394. foreach ($glist as $key => $record) {
  395. $recfile = @unserialize($record);
  396. if (is_array($recfile)) {
  397. foreach ($recfile as $field => $value) {
  398. if (in_array($field, array("date", "age", "misc"))) {
  399. $time = @filemtime($recfile["name"]);
  400. $time = getNowzone($time);
  401. //$unix_zone = ($time != $value ? $time - date("Z") + (3600 * $options["timezone"]) : $value);
  402. if ($field == "age") {
  403. $agefile = (TIME_NOW - $time);
  404. $listReformat[$key]["age"] = count_age($agefile);
  405. }
  406. if ($field == "date") {
  407. $listReformat[$key][$field] = $time;
  408. $date = $time;
  409. }
  410. }
  411. if ($field != "age" && $field != "date") $listReformat[$key][$field] = $value;
  412. }
  413. $glist[$date] = $listReformat[$key];
  414. unset($glist[$key], $glistReformat[$key]);
  415. }
  416. }
  417. @uasort($glist, "_cmp_list_enums");
  418. }
  419. }
  420. $list = $glist;
  421. }
  422. function _create_list_LIP() {
  423. global $list;
  424. $glist = array();
  425. $glistReformat = null;
  426. if (@file_exists(IP_L33CH_L0G)) {
  427. $glist = file(IP_L33CH_L0G);
  428. foreach ($glist as $key => $record) {
  429. foreach (unserialize($record) as $field => $value) {
  430. $listReformat[$key][$field] = $value;
  431. if ($field == "date") $date = $value;
  432. }
  433. $glist[$date] = $listReformat[$key];
  434. unset($glist[$key], $glistReformat[$key]);
  435. }
  436. }
  437. $list = $glist;
  438. }
  439. function checkmail($mail) {
  440. if (strlen($mail) == 0) {
  441. return false;
  442. }
  443. 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)) {
  444. return false;
  445. }
  446. return true;
  447. }
  448. /* Fixed Shell exploit by: icedog */
  449. function fixfilename($fname, $fpach = '') {
  450. $f_name = basename($fname);
  451. $f_dir = dirname(preg_replace("@\.\./@i", "", $fname));
  452. $f_dir = ($f_dir == '.') ? '' : $f_dir;
  453. $f_dir = preg_replace("@\.\./@i", "", $f_dir);
  454. $fpach = preg_replace("@\.\./@i", "", $fpach);
  455. $f_name = preg_replace("@\.(php|hta|pl|cgi|sph)@i", ".xxx", $f_name);
  456. $ret = ($fpach) ? $fpach . DIRECTORY_SEPARATOR . $f_name : ($f_dir ? $f_dir . DIRECTORY_SEPARATOR : '') . $f_name;
  457. return $ret;
  458. }
  459. function getfilesize($f) {
  460. global $is_windows;
  461. $stat = stat($f);
  462. if ($is_windows) return sprintf("%u", $stat [7]);
  463. if (($stat [11] * $stat [12]) < 4 * 1024 * 1024 * 1024) return sprintf("%u", $stat [7]);
  464. global $max_4gb;
  465. if ($max_4gb === false) {
  466. $tmp_ = trim(@shell_exec(" ls -Ll " . @escapeshellarg($f)));
  467. while (strstr($tmp_, ' ')) {
  468. $tmp_ = @str_replace(' ', ' ', $tmp_);
  469. }
  470. $r = @explode(' ', $tmp_);
  471. $size_ = $r [4];
  472. } else {
  473. $size_ = - 1;
  474. }
  475. return $size_;
  476. }
  477. function bytesToKbOrMb($bytes) {
  478. $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"));
  479. return $size;
  480. }
  481. // Updated function to be able to format up to Yotabytes!
  482. function bytesToKbOrMbOrGb($bytes) {
  483. if (is_numeric($bytes)) {
  484. $s = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  485. $e = floor(log($bytes) / log(1024));
  486. //return sprintf ( '%.2f ' . $s [$e], @($bytes / pow ( 1024, floor ( $e ) )) );
  487. return (pow(1024, floor($e)) > 0 ? sprintf('%.2f ' . $s[$e], ($bytes / pow(1024, floor($e)))) : '0 B');
  488. } else {
  489. //$size = "Unknown";
  490. $size = sprintf("%u", filesize($file));
  491. }
  492. return $size;
  493. }
  494. function defport($urls) {
  495. if ($urls ["port"] !== '' && isset($urls ["port"])) return $urls ["port"];
  496. switch (strtolower($urls ["scheme"])) {
  497. case "http" :
  498. return '80';
  499. case "https" :
  500. return '443';
  501. case "ftp" :
  502. return '21';
  503. }
  504. }
  505. function getSize($file) {
  506. $size = filesize($file);
  507. if ($size < 0) {
  508. if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
  509. $size = trim(`stat -c%s $file`);
  510. } else {
  511. $fsobj = new COM("Scripting.FileSystemObject");
  512. $f = $fsobj->GetFile($file);
  513. $size = $file->Size;
  514. }
  515. }
  516. return $size;
  517. }
  518. function purge_files($delay) {
  519. global $options;
  520. if (file_exists(FILES_LST) && is_numeric($delay) && $delay > 0) {
  521. $files_lst = file(FILES_LST);
  522. $files_new = "";
  523. $deleted["count"] = 0;
  524. $deleted["files"] = array();
  525. foreach ($files_lst as $files_line) {
  526. $files_data = unserialize(trim($files_line));
  527. if (isset($files_data["name"]) && @file_exists($files_data["name"]) && is_file($files_data["name"])) {
  528. $filedate = getNowzone(@filemtime($files_data["name"]));
  529. if ((TIME_NOW - $filedate) >= ($delay * 3600)) {
  530. @unlink($files_data["name"]);
  531. $deleted["count"]++;
  532. $deleted["files"][] = $options["download_dir"] . basename($files_data["name"]);
  533. } else {
  534. $files_new .= $files_line;
  535. }
  536. }
  537. }
  538. file_put_contents(FILES_LST, $files_new);
  539. }
  540. purge_files_ip($delay);
  541. //return $cnt_deleted;
  542. return $deleted;
  543. }
  544. // Delete ip log user download
  545. function purge_files_ip($delay) {
  546. if (file_exists(IP_L33CH_L0G) && is_numeric($delay) && $delay > 0) {
  547. $files_lst = file(IP_L33CH_L0G);
  548. $files_new = "";
  549. foreach ($files_lst as $files_line) {
  550. $files_data = unserialize(trim($files_line));
  551. $filedate = getNowzone(@filemtime($files_data["name"]));
  552. if (TIME_NOW - $filedate < ($delay * 3600)) {
  553. $files_new .= $files_line;
  554. }
  555. }
  556. file_put_contents(IP_L33CH_L0G, $files_new);
  557. }
  558. }
  559. // PHP4 compatibility
  560. if (!function_exists("file_put_contents") && !defined("FILE_APPEND")) {
  561. define("FILE_APPEND", 1);
  562. function file_put_contents($n, $d, $flag = false) {
  563. $mode = ($flag == FILE_APPEND || strtoupper($flag) == "FILE_APPEND") ? "a" : "w";
  564. $f = @fopen($n, $mode);
  565. if ($f === false) {
  566. return 0;
  567. } else {
  568. if (is_array($d)) {
  569. $d = implode($d);
  570. }
  571. $bytes_written = fwrite($f, $d);
  572. fclose($f);
  573. return $bytes_written;
  574. }
  575. }
  576. }
  577. if (!function_exists("file_get_contents")) {
  578. function file_get_contents($filename, $incpath = false) {
  579. if (false === $fh = fopen($filename, "rb", $incpath)) {
  580. trigger_error("file_get_contents() failed to open stream: No such file or directory", E_USER_WARNING);
  581. return false;
  582. }
  583. clearstatcache();
  584. if (($fsize = @filesize($filename))) {
  585. $data = fread($fh, $fsize);
  586. } else {
  587. $data = "";
  588. while (!feof($fh)) {
  589. $data .= fread($fh, 8192);
  590. }
  591. }
  592. fclose($fh);
  593. return $data;
  594. }
  595. }
  596. if (!function_exists('http_chunked_decode')) {
  597. // Added implementation from a comment at php.net's function page
  598. function http_chunked_decode($chunk) {
  599. $pos = 0;
  600. $len = strlen($chunk);
  601. $dechunk = null;
  602. while (($pos < $len) && ($chunkLenHex = substr($chunk, $pos, ($newlineAt = strpos($chunk, "\n", $pos + 1)) - $pos))) {
  603. if (!is_hex($chunkLenHex)) {
  604. trigger_error('Value is not properly chunk encoded_', E_USER_WARNING);
  605. return false;
  606. }
  607. $pos = $newlineAt + 1;
  608. $chunkLen = hexdec(rtrim($chunkLenHex, "\r\n"));
  609. $dechunk .= substr($chunk, $pos, $chunkLen);
  610. $pos = strpos($chunk, "\n", $pos + $chunkLen) + 1;
  611. }
  612. return $dechunk;
  613. }
  614. function is_hex($hex) {
  615. $hex = strtolower(trim(ltrim($hex, "0")));
  616. if (empty($hex)) $hex = 0;
  617. $dec = hexdec($hex);
  618. return ($hex == dechex($dec));
  619. }
  620. }
  621. // Using this function instead due to some compatibility problems
  622. function is__writable($path) {
  623. //will work in despite of Windows ACLs bug
  624. //NOTE: use a trailing slash for folders!!!
  625. //see http://bugs.php.net/bug.php?id=27609
  626. //see http://bugs.php.net/bug.php?id=30931
  627. if ($path {strlen($path) - 1} == '/') return is__writable($path . uniqid(mt_rand()) . '.tmp'); // recursively return a temporary file path
  628. else if (is_dir($path)) return is__writable($path . '/' . uniqid(mt_rand()) . '.tmp');
  629. // check tmp file for read/write capabilities
  630. $rm = file_exists($path);
  631. $f = @fopen($path, 'a');
  632. if ($f === false) return false;
  633. fclose($f);
  634. if (!$rm) unlink($path);
  635. return true;
  636. }
  637. function link_for_file($filename, $only_link = false, $checktime = false) {
  638. global $PHP_SELF;
  639. $inCurrDir = strstr(dirname($filename), ROOT_DIR) ? TRUE : FALSE;
  640. if ($inCurrDir) {
  641. $Path = parse_url($PHP_SELF);
  642. $Path = substr($Path["path"], 0, strlen($Path["path"]) - strlen(strrchr($Path["path"], "/")));
  643. $Path = str_replace('\\', '/', $Path . substr(dirname($filename), strlen(ROOT_DIR) - 1));
  644. } elseif (dirname($PHP_SELF . 'safe') != '/') {
  645. $in_webdir_path = dirname(str_replace('\\', '/', $PHP_SELF . 'safe'));
  646. $in_webdir_sub = substr_count($in_webdir_path, '/');
  647. $in_webdir_root = str_replace('\\', '/', ROOT_DIR);
  648. for ($i = 1; $i <= $in_webdir_sub; $i++) {
  649. $in_webdir_path = substr($in_webdir_path, 0, strrpos($in_webdir_path, '/'));
  650. $in_webdir_root = realpath($in_webdir_root . '/../') . '/';
  651. $in_webdir = (strpos(str_replace('\\', '/', dirname($filename) . '/'), str_replace('\\', '/', $in_webdir_root)) === 0) ? TRUE : FALSE;
  652. if ($in_webdir) {
  653. $Path = dirname($in_webdir_path . '/' . substr($filename, strlen($in_webdir_root)));
  654. break;
  655. }
  656. }
  657. } else {
  658. $Path = FALSE;
  659. if ($only_link) {
  660. return '';
  661. }
  662. }
  663. $basename = xmlentities(basename($filename));
  664. $Path = htmlentities($Path) . '/' . rawurlencode(basename($filename));
  665. $current_link = $time = '';
  666. if ($checktime) {
  667. $time = @filemtime($Path);
  668. }
  669. if ($only_link) {
  670. $current_link = 'http://' . urldecode($_SERVER['HTTP_HOST']) . $Path;
  671. } elseif ($Path === FALSE) {
  672. $current_link = '<span>' . $basename . '</span>';
  673. } else {
  674. $current_link = '<a href="' . $Path . '">' . $basename . '</a>';
  675. }
  676. if ($checktime) {
  677. return array($current_link, $time);
  678. } else {
  679. return $current_link;
  680. }
  681. }
  682. /**
  683. * Textarea for debugging variable
  684. * @param string The variable you want to debug
  685. * @param int Column for variable display
  686. * @param int Rows for variable display
  687. * @param bool Options to continue or not process
  688. * @param string Charset encoding for htmlentities
  689. */
  690. function textarea($var, $cols = 200, $rows = 30, $stop = false, $char = '') {
  691. $cols = ($cols == 0) ? 200 : $cols;
  692. $rows = ($rows == 0) ? 30 : $rows;
  693. echo "\n<br /><textarea cols='$cols' rows='$rows' readonly='readonly'>";
  694. if (is_array($var)) echo htmlentities(print_r($var, true), ENT_QUOTES, $char);
  695. else echo htmlentities($var, ENT_QUOTES, $char);
  696. echo "</textarea><br />\n";
  697. if ($stop) exit;
  698. }
  699. // Get time in miliseconds, like getTime() in javascript
  700. function jstime() {
  701. list($u, $s) = explode(' ', microtime());
  702. return sprintf('%d%03d', $s, $u * 1000);
  703. }
  704. function check_referer() {
  705. $refhost = !empty($_SERVER['HTTP_REFERER']) ? cut_str($_SERVER['HTTP_REFERER'], '://', '/') : false;
  706. if (!$refhost) return;
  707. if (!empty($_SERVER['HTTP_HOST'])) $httphost = preg_replace('@(:\d+)$@', '', $_SERVER['HTTP_HOST']);
  708. $httphost = !empty($httphost) && $httphost != $_SERVER['SERVER_NAME'] ? "|($httphost)" : '';
  709. if (!preg_match(str_replace('.', '\.', "@({$_SERVER['SERVER_NAME']})|({$_SERVER['SERVER_ADDR']})$httphost(:\d+)?$@i"), $refhost)) {
  710. // Uncomment next line if you want rickroll the users from Form leechers.
  711. // header("Location: http://www.youtube.com/watch?v=oHg5SJYRHA0");
  712. html_error($L->sprintf($L->say['not_allowed_leech'], $refhost, 'Referer not allowed.'));
  713. }
  714. }
  715. function rebuild_url($url) {
  716. 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'] : "");
  717. }
  718. // This function manualy set server timezone,
  719. // believe or not triggering date_default_timezone_set() may perform lil faster in manipulating date()
  720. function getNowzone($t='') {
  721. global $options;
  722. if ($t == '') $t = time();
  723. // incompatibile for PHP4
  724. if (!function_exists("date_default_timezone_set") || !function_exists("date_default_timezone_get")) {
  725. $nowzone = $t;
  726. } elseif ($options["timezone"] > 0) {
  727. date_default_timezone_set('UTC');
  728. //$nowzone = strtotime(date("Y M d H:i:s", time() - date("Z") + (3600 * $options["timezone"]) ) );
  729. $nowzone = ($t + round(3600 * $options["timezone"], 0) );
  730. } else {
  731. date_default_timezone_set(date_default_timezone_get());
  732. $nowzone = $t;
  733. }
  734. return $nowzone;
  735. }
  736. // This function check primary file and folder
  737. // returned filesize of the FILES_LST
  738. function checkExistence() {
  739. global $L;
  740. //Checking DOWNLOAD_DIR
  741. if (file_exists(DOWNLOAD_DIR)) {
  742. if (!is__writable(DOWNLOAD_DIR)) {
  743. html_error($L->sprintf($L->say['not_writable'], DOWNLOAD_DIR));
  744. }
  745. } else {
  746. html_error($L->sprintf($L->say['dir_not_exists'], DOWNLOAD_DIR));
  747. }
  748. // Check FILES_LST is not writable,
  749. if (file_exists(FILES_LST)) {
  750. if (!is__writable(FILES_LST)) {
  751. html_error($L->sprintf($L->say['not_writable'], FILES_LST));
  752. }
  753. return @filesize(FILES_LST);
  754. } else {
  755. html_error($L->sprintf($L->say['file_not_exists'], FILES_LST));
  756. }
  757. }
  758. function calcUsedSpace() {
  759. global $list;
  760. $total_size = 0;
  761. if (!$list) {
  762. _create_list();
  763. }
  764. if (isset($list["files"]["totalsize"])) {
  765. $total_size = $list["files"]["totalsize"];
  766. } else {
  767. foreach ($list as $key => $file) {
  768. if (@file_exists($file ["name"])) {
  769. $total_size += filesize($file ["name"]);
  770. }
  771. }
  772. }
  773. return $total_size;
  774. }
  775. /* lowers the case of a string, mb strings accounted for */
  776. function do_strtolower($string) {
  777. if (function_exists("mb_strtolower")) {
  778. $string = mb_strtolower($string);
  779. } else {
  780. $string = strtolower($string);
  781. }
  782. return $string;
  783. }
  784. /* Returns the extension of a file. */
  785. function get_extension($file) {
  786. return do_strtolower(substr(strrchr($file, "."), 1));
  787. }
  788. /* Render (dead) template needed */
  789. function get_tpl($keyname, $msg="Halted") {
  790. global $RL_VER, $options, $charSet, $nn;
  791. //error_reporting(E_ALL);
  792. $dead_msg = $msg;
  793. require_once(ROOT_DIR . $keyname . ".php");
  794. }
  795. // Clean Link from * if any. //kaskus filter
  796. function urlcleaner($url) {
  797. if (strpos($url, "*")) {
  798. return str_replace("*", "", $url);
  799. } else {
  800. return $url;
  801. }
  802. }
  803. // Limit long path download link
  804. function trimlink($link) {
  805. $max = 50;
  806. $range = 5;
  807. if (strlen($link) > ($max + $range)) {
  808. $opr = '://';
  809. $stfrom = (strpos($link, $opr) + strlen($opr) + 1);
  810. // get the host name
  811. $lhost = substr($link, 0, strpos(substr($link, $stfrom), "/") + $stfrom);
  812. $partlnk = explode("/", $link);
  813. $fname = $partlnk[count($partlnk) - 1];
  814. // trim filename
  815. if (strlen($lhost . $fname) > $max) {
  816. $fname = '&#8230;' . substr($fname, strlen($lhost . $fname) - $max, strlen($fname));
  817. }
  818. return $lhost . '/&#8230;/' . $fname;
  819. } else {
  820. return $link;
  821. }
  822. }
  823. // XML Entity Mandatory Escape Characters
  824. function xmlentities($string, $entities=true) {
  825. $string = ($entities ? htmlentities($string) : $string);
  826. return str_replace(array('&', '"', "'", '<', '>', ' '), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;', '&#32;'), $string);
  827. }
  828. // Inspector strip quotes Characters
  829. function strip_quotes($string) {
  830. return str_replace(array('"', "'", ' '), array('_', '_', '_'), $string);
  831. }
  832. // Return form for html_error for retry free download mode
  833. function buildRetryform($msg, $delay = 15) {
  834. global $PHP_SELF, $LINK, $L, $options;
  835. if (!$options['alternatefree']) html_error($msg);
  836. $form = '';
  837. $form .= ('<script type="text/javascript">');
  838. $form .= ('var d=document, di=' . $delay . '; // in second');
  839. $form .= ('function itung(){if(di>0){setTimeout("itung()",1000); di--;');
  840. $form .= ('d.getElementById("tmr").innerHTML=di; } else');
  841. $form .= ('{ d.frmretry.submit(); }}setTimeout("itung()", 1000);');
  842. $form .= ('</script>');
  843. $form .= ($L->say['try_free_dl'] . '[<b id="tmr" class="g">~</b>]&nbsp;');
  844. $form .= ('<a href="javascript:;" onclick=\"document.frmretry.submit();\">');
  845. $form .= ('[' . $L->say['execute'] . ']</a><br /><br />');
  846. $form .= ('<form name="frmretry" action="' . $PHP_SELF . '" method="post">');
  847. $form .= ('<input type="hidden" name="link" value="' . $LINK . '" />');
  848. $keyname = array('premium_acc', 'df_acc', 'hf_acc', 'net_acc', 'rs_acc', 'ul_acc', 'upl_acc', 'cookie_use');
  849. foreach ($keyname as $k => $v) {
  850. $form .= ('\n<input type="hidden" name="' . $v . '" value=""/>');
  851. }
  852. return $form;
  853. }
  854. // Get real IP
  855. function get_real_ip() {
  856. $ipRL = false;
  857. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  858. $ipRL = $_SERVER['HTTP_CLIENT_IP'];
  859. }
  860. if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  861. $ips = explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
  862. if ($ipRL) {
  863. array_unshift($ips, $ipRL);
  864. $ipRL = false;
  865. }
  866. for ($i = 0; $i < count($ips); $i++) {
  867. if (!preg_match("/^(10|172\.16|192\.168)\./i", $ips[$i])) {
  868. if (version_compare(phpversion(), "5.0.0", ">=")) {
  869. if (ip2long($ips[$i]) != false) {
  870. $ipRL = $ips[$i];
  871. break;
  872. }
  873. } else {
  874. if (ip2long($ips[$i]) != - 1) {
  875. $ipRL = $ips[$i];
  876. break;
  877. }
  878. }
  879. }
  880. }
  881. }
  882. return ($ipRL ? $ipRL : $_SERVER['REMOTE_ADDR']);
  883. }
  884. //Check allow / Banned IP Address
  885. function chk_this_ip($meth, $user_ip) {
  886. global $options, $L;
  887. $ip_allow_ar = array();
  888. if ($meth == 'is_baned') {
  889. $list_ip = $options["list_baned_ip"];
  890. } elseif ($meth == 'is_allow') {
  891. $list_ip = $options["list_allow_ip"];
  892. }
  893. $ip_allow_ar = explode(',', $list_ip);
  894. ksort($ip_allow_ar);
  895. $check_is = false;
  896. $ada_bintang = 0;
  897. $i = 0;
  898. if ($meth == 'is_allow' && !$ip_allow_ar[$i]) {
  899. html_error($L->say['malfunction_ip']);
  900. }
  901. while (!$check_is && ($ip_allow_ar[$i])) {
  902. $ada_bintang = ($ip_allow_ar[$i] != '*.*.*.*' ? substr_count($ip_allow_ar[$i], '.*') : 4);
  903. if ($ada_bintang > 0) {
  904. if ($ada_bintang != 4) {
  905. $sub_ip = substr($ip_allow_ar[$i], 0, strpos($ip_allow_ar[$i], '.*')) . ".";
  906. $u_ip_ar = explode('.', $user_ip);
  907. $bit = (int) (3 - $ada_bintang);
  908. $u_ip = '';
  909. for ($j = 0; $j <= $bit; $j++) {
  910. $u_ip = $u_ip . $u_ip_ar[$j] . ".";
  911. }
  912. if (trim($u_ip) == trim($sub_ip)) {
  913. $check_is = true;
  914. }
  915. } else {
  916. $check_is = true;
  917. }
  918. } else {
  919. if (trim($user_ip) == trim($ip_allow_ar[$i])) {
  920. $check_is = true;
  921. }
  922. }
  923. $i++;
  924. }
  925. return $check_is;
  926. }
  927. //encryption
  928. function dcd($c) {
  929. $pt = "";
  930. $bfC = $c;
  931. if ($c == "") {
  932. return $pt;
  933. }
  934. $rRot = (int) substr($c, -2);
  935. if (!is_numeric($rRot)) {
  936. return false;
  937. } else {
  938. $bfC = strtoupper(substr($c, 0, -2));
  939. $pj = strlen($bfC);
  940. $i = 0;
  941. }
  942. if ($pj % 2 != 0) {
  943. return false;
  944. }
  945. while ($i < $pj) {
  946. $hs = chr(hexdec(substr($bfC, $i, 2)));
  947. $pt.=$hs;
  948. $i = $i + 2;
  949. }
  950. $pt = strrev(rotN($pt, -$rRot));
  951. return $pt;
  952. }
  953. function mcd($armacc) {
  954. $dar = array();
  955. $n_a = count($armacc);
  956. for ($i = 0; $i < $n_a; $i++) {
  957. $buf_ac = array();
  958. $cl_all = array();
  959. $buf_ac = explode(chr(hexdec("3A")), dcd($armacc[$i]));
  960. $cl_all["user"] = $buf_ac[0];
  961. $cl_all["pass"] = $buf_ac[1];
  962. $dar[] = $cl_all;
  963. }
  964. return $dar;
  965. }
  966. function encEnti($v) {
  967. $rt = "";
  968. for ($i = 0; $i < strlen($v); $i++) {
  969. $ktr = strtoupper(dechex(ord($v{$i})));
  970. $rt.=$ktr;
  971. }
  972. return $rt;
  973. }
  974. function decEnti($c) {
  975. $pt = "";
  976. $pj = strlen($c);
  977. $i = 0;
  978. if ($pj % 2 != 0) {
  979. return false;
  980. }
  981. while ($i < $pj) {
  982. $hs = chr(hexdec(substr($c, $i, 2)));
  983. $pt.=$hs;
  984. $i = $i + 2;
  985. }
  986. return $pt;
  987. }
  988. function rotN($s, $n) {
  989. $s2 = "";
  990. for ($i = 0; $i < strlen($s); $i++) {
  991. $char2 = $char = ord($s{$i});
  992. $cap = $char & 32;
  993. $char &= ~ $cap;
  994. $char = $char > 64 && $char < 123 ? (($char - 65 + $n) % 26 + 65) : $char;
  995. $char |= $cap;
  996. if ($char < 65 && $char2 > 64 || ($char > 90 && $char < 97 && ($char2 < 91 || $char2 > 96))) $char += 26;
  997. else if ($char > 122 && $char2 < 123) $char -= 52;
  998. if (strtoupper(chr($char2)) === chr($char2)) $char = strtoupper(chr($char)); else $char = strtolower(chr($char));
  999. $s2 .= $char;
  1000. }
  1001. return $s2;
  1002. }
  1003. function encrypt($string) {
  1004. global $secretkey;
  1005. if (empty($string)) {
  1006. return '';
  1007. }
  1008. if (!$secretkey) {
  1009. return html_error('Value for $secretkey is empty, please create a random one (56 chars max) in your config!', 0);
  1010. }
  1011. require_once 'class.pcrypt.php';
  1012. /*
  1013. MODE: MODE_ECB or MODE_CBC
  1014. ALGO: BLOWFISH
  1015. KEY: Your secret key :) (max lenght: 56)
  1016. */
  1017. $crypt = new pcrypt(MODE_CBC, "BLOWFISH", "$secretkey");
  1018. // Return encrypted string
  1019. return $crypt->encrypt($string);
  1020. }
  1021. function decrypt($string) {
  1022. global $secretkey;
  1023. if (empty($string)) {
  1024. return '';
  1025. }
  1026. if (!$secretkey) {
  1027. return html_error('Value for $secretkey is empty, please create a random one (56 chars max) in your config!', 0);
  1028. }
  1029. require_once 'class.pcrypt.php';
  1030. /*
  1031. MODE: MODE_ECB or MODE_CBC
  1032. ALGO: BLOWFISH
  1033. KEY: Your secret key :) (max lenght: 56)
  1034. */
  1035. $crypt = new pcrypt(MODE_CBC, "BLOWFISH", "$secretkey");
  1036. // Return decrypted string
  1037. return $crypt->decrypt($string);
  1038. }
  1039. /* ==========
  1040. autoNext function
  1041. param:
  1042. $iset : should it set autoDL true or not
  1043. $forceNext: if download found error keep evaluate next link
  1044. $audl: wot method send from audl.php. eg. sims, queue, manual
  1045. ========== */
  1046. function autoNext($iset, $forceNext, $audl) {
  1047. global $options;
  1048. $bfRet = "";
  1049. $bfRet = "\r\n<script type='text/javascript'>\n";
  1050. $bfRet.="try{if(parent.isAuto==true){id=parent.current_dlink;\n";
  1051. $bfRet.="parent.startisdone(id);}\nelse{\n id=self.name.substring(self.name.length-1); idLnk=parent.document.getElementById('idxlink'+id).innerHTML; parent.iframeReady(id); idx=eval(idLnk-1); parent.startisdone(idx);\n}\n}\ncatch(e){}\n";
  1052. if ($audl != "") {
  1053. if ($audl == "sims") {
  1054. $bfRet.="id=self.name;id=id.substring(id.length-1);\n";
  1055. $bfRet.="if(window.opener!=null){window.opener.startisdone(id);}\n";
  1056. } elseif ($audl == "queue" || $audl == "manual") {
  1057. $bfRet.="try{id=parent.current_dlink;\n";
  1058. $bfRet.="parent.startisdone(id);}catch(e){}\n";
  1059. }
  1060. }
  1061. $bfRet.="</script>\r\n";
  1062. if ($iset) {
  1063. $bfRet.="\r\n<script type='text/javascript'>var autoDL = true;\n";
  1064. } else {
  1065. $bfRet.= "\r\n<script type='text/javascript'>var autoDL;\n";
  1066. }
  1067. switch ($audl) {
  1068. case "sims" :
  1069. $bfRet.= "var not_simultan = false;";
  1070. break;
  1071. default :
  1072. $bfRet.= "var not_simultan = true;";
  1073. break;
  1074. }
  1075. if ($options["showautoclose"] == "true" && $forceNext) {
  1076. $bfRet.="\r\n<!-- \n var time = " . $options["timeautoclose"] . ";\nif(autoDL==true && not_simultan){parent.nextlink(id);}\nfunction vbaccept(){\ntime--;frm = document.vbaccept;\nif(frm)frm.submit.value = 'Auto-Close through '+time+'';\n";
  1077. $bfRet.="if(time>0){window.setTimeout(\"vbaccept()\",1);}\n else \nif(frm){frm.submit.value = 'done';\nfrm.submit.disabled=0;window.close(self);}}\n";
  1078. if ($audl == 'sims') {
  1079. $bfRet.="if(autoDL==true && not_simultan==false){ if(window.opener!=null){vbaccept(); var da = document.getElementById('tdone'); da.href='javascript:if(autoDL==true && not_simultan){window.opener.nextlink(id);}window.close(self);'; document.getElementById('txtdone').innerHTML='Done';}}\n\n";
  1080. }
  1081. $bfRet.="--></script>";
  1082. $bfRet.="<form id=vbaccept name=vbaccept><input type=submit name=submit style='color:#fff;' value=\"done\" disabled></form>";
  1083. } else {
  1084. $bfRet.="\r\nif(autoDL==true && not_simultan){parent.nextlink(id);}\n if(autoDL==true && not_simultan==false){if(window.opener!=null){\r\n var da = document.getElementById('tdone'); \n da.href='javascript:if(autoDL==true && not_simultan){window.opener.nextlink(id);} window.close(self);';\n document.getElementById('txtdone').innerHTML='Close';}}</script>";
  1085. }
  1086. return $bfRet;
  1087. }
  1088. // get server platform
  1089. function getServerPlatf($dash=0) {
  1090. $server["is_windows"] = (strtoupper(substr(PHP_OS, 0, 3)) == "WIN");
  1091. $server["is_linux"] = (stristr(PHP_OS, "Linux"));
  1092. $server["is_mac"] = (stristr(PHP_OS, "Darwin"));
  1093. $server["32bit"] = (PHP_INT_SIZE == 4);
  1094. $server["64bit"] = (PHP_INT_SIZE == 8);
  1095. $server["property"] = "Host:";
  1096. foreach ($server as $field => $vtrue) {
  1097. if ($vtrue === true) {
  1098. $server["property"].= str_replace("is_", "&nbsp;", $field) . "&nbsp;";
  1099. }
  1100. }
  1101. $server["property"].= ($dash == 1 ? "&#8212;&nbsp;" : "");
  1102. return $server;
  1103. }
  1104. // Needed for sload.php & sinfo.php
  1105. if (!function_exists('color_cpu')) {
  1106. function color_cpu($nilai) {
  1107. global $alert_sloadhigh;
  1108. if (!is_numeric($nilai)) {
  1109. return FALSE;
  1110. } else {
  1111. if ($nilai <= 33) {
  1112. $clr = "#3D612C";
  1113. } elseif ($nilai <= 66) {
  1114. $clr = "#FFCC33";
  1115. } else {
  1116. $clr = "#FF0000";
  1117. }
  1118. $nilai = '<b ' . ($alert_sloadhigh ? 'class="r' : 'style="color:' . $clr) . '">' . $nilai . '</b>';
  1119. return $nilai;
  1120. }
  1121. }
  1122. }
  1123. // age file facebook looks like
  1124. function count_age($age) {
  1125. global $L;
  1126. if ($age <= 60) return $L->say['less_a_minute'];
  1127. $jam_str = "";
  1128. $jam = floor($age / 3600);
  1129. if ($jam >= 1) {
  1130. $jam_str = ($jam . " " . $L->say['hours'] . " " );
  1131. $age -= $jam * 3600;
  1132. }
  1133. if ($age >= 60) {
  1134. $min = floor($age / 60);
  1135. } else {
  1136. $sec = $age;
  1137. }
  1138. return $jam_str .
  1139. (isset($min) && $min > 0 ? $min . " " . $L->say['minutes'] : "") .
  1140. (isset($sec) && $sec > 0 ? $sec . " " . $L->say['seconds'] : "") .
  1141. ($L->say['ago'] != "" ? " " . $L->say['ago'] : "");
  1142. }
  1143. // get working time
  1144. function cek_worktime($workstart, $workend) {
  1145. global $options;
  1146. $tdebug = false;
  1147. //$zone=3600 * $options["timezone"]; // GMT +7 ~ Indonesia
  1148. //$tn = getdate(strtotime(date("d M Y H:i:s", time() - date("Z") + $zone)));
  1149. $tn = getdate(TIME_NOW);
  1150. $dtstr = " Apr 1983 ";
  1151. $tgl = "14";
  1152. $tnH = $tn["hours"];
  1153. $tnM = $tn["minutes"];
  1154. $tnS = $tn["seconds"];
  1155. if ($tnH < 10) $tnH = '0' . $tnH;
  1156. if ($tnM < 10) $tnM = "0" . $tnM;
  1157. if ($tnS < 10) $tnS = "0" . $tnS;
  1158. $wstart = strtotime($tgl . $dtstr . $workstart);
  1159. $nowUnix = strtotime("$tgl $dtstr $tnH:$tnM:$tnS");
  1160. $ws = explode(":", $workstart);
  1161. $we = explode(":", $workend);
  1162. if ((int) $ws[0] >= (int) $we[0]) {
  1163. $tgl = "15";
  1164. if ((int) $tnH <= $we[0]) {
  1165. $nowUnix = strtotime("$tgl $dtstr $tnH:$tnM:$tnS");
  1166. }
  1167. }
  1168. $wend = strtotime($tgl . $dtstr . $workend);
  1169. if ($tdebug) {
  1170. echo $tn . "<br />" . "$tgl $dtstr $tnH:$tnM:$tnS<br />$nowUnix<br />" . "$workstart-" . $wstart . "-" . $wend . "-$workend";
  1171. }
  1172. if (($nowUnix - $wstart) > 0 && ($wend - $nowUnix) > 0) {
  1173. return true;
  1174. } else {
  1175. return false;
  1176. }
  1177. }
  1178. // rebuild link download_dir if notin current dir
  1179. function relink_path($DL_link, $phpself = "", $spliter = "/", $drname = false) {
  1180. global $PHP_SELF;
  1181. if ($phpself == "") {
  1182. $phpself = (!$PHP_SELF ? $_SERVER["PHP_SELF"] : $PHP_SELF);
  1183. }
  1184. $ddot_len = substr_count($DL_link, '../', 0);
  1185. $rPth = parse_url($phpself);
  1186. if ($phpself != "") {
  1187. $rPth = substr($rPth["path"], 0, strlen($rPth["path"]) - strlen(strrchr($rPth["path"], $spliter)));
  1188. }
  1189. for ($i = 0; $i < $ddot_len; $i++) {
  1190. $rPth = parse_url($rPth);
  1191. $rPth = substr($rPth["path"], 0, strlen($rPth["path"]) - strlen(strrchr($rPth["path"], $spliter)));
  1192. }
  1193. $rPth = ( (substr($rPth, -1) == $spliter) ? substr($rPth, 0, strlen($rPth) - 1) : $rPth);
  1194. $cPath["root"] = $rPth;
  1195. $cPath["download"] = str_replace("../", "", $DL_link);
  1196. return $cPath;
  1197. }
  1198. // reverse string
  1199. function utf8_strrev($str) {
  1200. preg_match_all('/./us', $str, $ar);
  1201. return join('', array_reverse($ar[0]));
  1202. }
  1203. // check strictly forbidden file in download dir
  1204. function checkStrict() {
  1205. global $options;
  1206. $dir = @dir(DOWNLOAD_DIR);
  1207. while (false !== ($file = $dir->read())) {
  1208. if (in_array(strtolower(strrchr($file, ".")), $options['forbidden_filetypes']) && $file != '.htaccess' && $file != '.htpasswd' && $file != 'index.html') {
  1209. @unlink(DOWNLOAD_DIR . $file);
  1210. }
  1211. }
  1212. $dir->close();
  1213. }
  1214. // check and count ip download
  1215. function ipcounter() {
  1216. global $heute, $options, $ipmu;
  1217. $xhandle = @opendir("tmp");
  1218. if ($xhandle) {
  1219. while ($buin = readdir($xhandle)) {
  1220. if (preg_match("@$ipmu@i", $buin)) {
  1221. $heute = $heute + 1;
  1222. }
  1223. }
  1224. $ckusr = decEnti((string) base64_decode(urldecode($_COOKIE['rxyzusr'])));
  1225. $ckusr = (is_numeric($ckusr) ? $ckusr : '0');
  1226. if (($ckusr != '') && ($ckusr > $heute)) {
  1227. $heute = $ckusr;
  1228. } else {
  1229. setcookie('rxyzusr', base64_encode(encEnti((string) $heute)), TIME_NOW + ($options['delay_per_ip'] * 60 * 60));
  1230. }
  1231. closedir($xhandle);
  1232. error_reporting(0);
  1233. $xhandle = @opendir("tmp");
  1234. while ($buin = readdir($xhandle)) {
  1235. if ($buin == "." || $buin == "..") {
  1236. $buin = "fu";
  1237. }
  1238. $xd = @filemtime("tmp/$buin");
  1239. $xd = getNowzone($xd);
  1240. $altr = TIME_NOW - $xd;
  1241. if ($altr > $options['delay_per_ip'] * 60 * 60) {
  1242. if (is_dir("tmp/$buin")) {
  1243. @rmdir("tmp/$buin");
  1244. } else {
  1245. @unlink("tmp/$buin");
  1246. }
  1247. }
  1248. }
  1249. closedir($xhandle);
  1250. error_reporting(1);
  1251. }
  1252. }
  1253. /**
  1254. * Renders the file actions, this function does NOT output directly to the browser
  1255. *
  1256. * @return string The string will contain the <select></select> tag
  1257. *
  1258. */
  1259. function renderActions() {
  1260. global $options, $L;
  1261. $return = "";
  1262. $return .= '<select name="act" onchange="javascript:void(document.flist.submit());" style="float:left;">';
  1263. $return .= '<option selected="selected">' . $L->say['action'] . '</option>';
  1264. if (!$options['disable_to']['act_upload']) $return .= '<option value="upload">' . $L->say['act_upload'] . '</option>';
  1265. if (!$options['disable_to']['act_ftp']) $return .= '<option value="ftp">' . $L->say['act_ftp'] . '</option>';
  1266. if (!$options['disable_to']['act_mail']) $return .= '<option value="mail">' . $L->say['act_mail'] . '</option>';
  1267. if (!$options['disable_to']['act_boxes']) $return .= '<option value="boxes">' . $L->say['act_boxes'] . '</option>';
  1268. if (!$options['disable_to']['act_split']) $return .= '<option value="split">' . $L->say['act_split'] . '</option>';
  1269. if (!$options['disable_to']['act_merge']) $return .= '<option value="merge">' . $L->say['act_merge'] . '</option>';
  1270. if (!$options['disable_to']['act_md5']) $return .= '<option value="md5">' . $L->say['act_md5'] . " / Changer". '</option>';
  1271. if ((file_exists(CLASS_DIR . "pear.php") || file_exists(CLASS_DIR . "tar.php")) && !$options['disable_to']['act_pack']) $return .= '<option value="pack">' . $L->say['act_pack'] . '</option>';
  1272. if (file_exists(CLASS_DIR . "pclzip.php") && !$options['disable_to']['act_zip']) $return .= '<option value="zip">' . $L->say['act_zip'] . '</option>';
  1273. if (file_exists(CLASS_DIR . "unzip.php") && !$options['disable_to']['act_unzip']) $return .= '<option value="unzip">' . $L->say['act_unzip'] . '</option>';
  1274. if (substr(PHP_OS, 0, 3) != "WIN" && @file_exists(CLASS_DIR . "rar.php")) {
  1275. if (!$options['disable_to']['act_rar']) {
  1276. $return .= '<option value="rar">' . $L->say['act_rar'] . '</option>';
  1277. }
  1278. if (!$options['disable_to']['act_unrar']) {
  1279. if (@file_exists(BINARY_DIR . 'rar/rar') || @file_exists(BINARY_DIR . 'rar/unrar')) {
  1280. $return .= '<option value="unrar">' . $L->say['act_unrar'] . '</option>';
  1281. }
  1282. }
  1283. }
  1284. if (!$options['disable_to']['act_rename']) $return .= '<option value="rename">' . $L->say['act_rename'] . '</option>';
  1285. if (!$options['disable_to']['act_mrename']) $return .= '<option value="mrename">' . $L->say['act_mrename'] . '</option>';
  1286. if (!$options['disable_to']['act_delete']) $return .= '<option value="delete">' . $L->say['act_delete'] . '</option>';
  1287. $return .= '</select>&nbsp;&nbsp;';
  1288. return $return;
  1289. }
  1290. function vidlist($dir, $exts = '') {
  1291. $results = array();
  1292. $handler = opendir($dir);
  1293. while ($file = readdir($handler)) {
  1294. if (strrchr($file, '.') != "") {
  1295. $ext = strtolower(strrchr($file, '.'));
  1296. } else {
  1297. $ext = '';
  1298. }
  1299. if ($file != '.' && $file != '..' && in_array($ext, $GLOBALS["exts"])) {
  1300. $results[] = $file;
  1301. }
  1302. }
  1303. closedir($handler);
  1304. sort($results);
  1305. return $results;
  1306. }
  1307. function view_size($size) {
  1308. if (!is_numeric($size)) {
  1309. return FALSE;
  1310. } else {
  1311. if ($size >= 1073741824) {
  1312. $size = round($size / 1073741824 * 100) / 100 . "&nbsp;GB";
  1313. } elseif ($size >= 1048576) {
  1314. $size = round($size / 1048576 * 100) / 100 . "&nbsp;MB";
  1315. } elseif ($size >= 1024) {
  1316. $size = round($size / 1024 * 100) / 100 . "&nbsp;KB";
  1317. } else {
  1318. $size = $size . "&nbsp;B";
  1319. }
  1320. return $size;
  1321. }
  1322. }
  1323. function lnkfilter($siLink) {
  1324. $linkres = $siLink;
  1325. if (strpos($siLink, "rapid*share.com/") || (strpos($siLink, "rapid^share.com/")) || (strpos($siLink, "rapdshare.com/"))) {
  1326. $rssuspect = array('rapid*share.com/', 'rapid^share.com/', 'rapdshare.com/');
  1327. $rsabs = 'rapidshare.com/';
  1328. $linkres = str_replace($rssuspect, $rsabs, $linkres);
  1329. }
  1330. return $linkres;
  1331. }
  1332. function get_traffic($filena) {
  1333. $isinya = array(' ', null);
  1334. $fl = @fopen($filena, "r");
  1335. if ($fl) {
  1336. $buftxt = @fgets($fl);
  1337. @fclose($fl);
  1338. $isinya = explode(":", trim($buftxt));
  1339. }
  1340. if (!is_numeric($isinya[0])) {
  1341. $isinya[0] = 0;
  1342. }
  1343. return $isinya;
  1344. }
  1345. function autoreset_traffic($days, $c_traf) {
  1346. global $options;
  1347. $zone = (3600 * $options['timezone']);
  1348. if ($days > 0) {
  1349. $reset_traffic = false;
  1350. $start_date = $c_traf[1];
  1351. $unix_now = strtotime("now") + $zone;
  1352. if (!preg_match("/\d{10}/i", $start_date)) {
  1353. $start_date = $unix_now;
  1354. } else {
  1355. if ($start_date > $unix_now) {
  1356. $start_date = $unix_now;
  1357. $reset_traffic = true;
  1358. }
  1359. }
  1360. $next_date = strtotime("+" . $days . " day", $start_date);
  1361. if ($next_date <= $unix_now) {
  1362. $reset_traffic = true;
  1363. $start_date = $unix_now;
  1364. }
  1365. if ($next_date <= $start_date) {
  1366. $value_trafic = ($reset_traffic ? '0' : $c_traf[0]);
  1367. $start_date = upd_traffictime($value_trafic); // reset traffic
  1368. }
  1369. return $start_date;
  1370. } else {
  1371. return false;
  1372. }
  1373. }
  1374. function upd_traffictime($cur_traffic) {
  1375. global $options;
  1376. $zone = (3600 * $options['timezone']);
  1377. $fn_trafic = TRAFFIC_LST;
  1378. if (@file_exists($fn_trafic)) {
  1379. $unix_now = strtotime("now") + $zone;
  1380. $value_trafic = $cur_traffic . ":" . $unix_now;
  1381. $ret = @write_traffic($fn_trafic, $value_trafic);
  1382. return $unix_now;
  1383. }
  1384. }
  1385. function timeremain_traffic($days, $start_date) {
  1386. global $options;
  1387. $zone = (3600 * $options['timezone']);
  1388. $unix_now = strtotime("now") + $zone;
  1389. $next_date = strtotime("+" . $days . " day", $start_date);
  1390. return ( $next_date - $unix_now );
  1391. }
  1392. // Log System
  1393. function chklatesvisitor($curvisit) {
  1394. $err = false;
  1395. $latestvisit = false;
  1396. if (!file_exists(LASTLOG_LST)) @touch(LASTLOG_LST);
  1397. //Check is this user the last IP
  1398. if (@file_exists(LASTLOG_LST)) {
  1399. $fl = fopen(LASTLOG_LST, 'r');
  1400. $buftxt = @fread($fl, @filesize(LASTLOG_LST));
  1401. fclose($fl);
  1402. if ($buftxt != "") {
  1403. if ($curvisit === $buftxt) {
  1404. $latestvisit = true;
  1405. }
  1406. }
  1407. } else {
  1408. $err = true;
  1409. }
  1410. if ($err) {
  1411. echo "<br />an error occurs with log system.";
  1412. }
  1413. return $latestvisit;
  1414. }
  1415. function saveLogsys($curvisit) {
  1416. global $ipmu, $ref, $options;
  1417. if (!file_exists(LOG_PHP)) @touch(LOG_PHP);
  1418. if (@file_exists(LOG_PHP)) {
  1419. // Get current content
  1420. $fl = fopen(LOG_PHP, 'r');
  1421. $buftxt = @fread($fl, @filesize(LOG_PHP));
  1422. fclose($fl);
  1423. $buftxt = cut_str($buftxt, "<isi id='isilog'>", "</isi>");
  1424. $_php = "<?php if(!defined(\"RAPIDLEECH\")){\n require_once(\"404.php\");exit;\n}?>\n";
  1425. //$style = "$_php\n<style>\nbody{\nfont-family:verdana;\n font-size:10px;\n color:#FFFFFF;\n background-color:#010e17;\n background-image:url(background_pm.gif);\n background-repeat:repeat-x;\n}\n.g{color:#00FF00;}\n.t{color:#00FF00;\nfont-size:14px;}\n</style>\n";
  1426. $style = "$_php\n\n";
  1427. $h = $options['timezone']; // GMT+7 for Indonesia.
  1428. $ms = $h * 60 * 60;
  1429. $gmdate = gmdate("d M Y H:i:s", time() + ($ms));
  1430. $time = ('GMT+' . $h);
  1431. $agent = $_SERVER['HTTP_USER_AGENT'];
  1432. $fl2 = fopen(LOG_PHP, 'w+');
  1433. $dash = "";
  1434. for ($i = 0; $i <= 50; $i++) {
  1435. $dash.="-";
  1436. }
  1437. $title = "<b class='t'>Log System <small>(descending sorted)</small></b><br />";
  1438. $towrite =
  1439. "$style<body>$title\n<isi id='isilog'><br />\nDate: $gmdate $time" . ($ref != "" ? "<br />\nRefferer: $ref" : "") .
  1440. "<br />\nBrowser: $agent<br />\nUser IP: <b class='g'>$ipmu</b><br />$dash\n$buftxt</isi></body>";
  1441. fwrite($fl2, $towrite);
  1442. fclose($fl2);
  1443. // Update IP Visitor
  1444. $fl = fopen(LASTLOG_LST, 'w');
  1445. fwrite($fl, $curvisit);
  1446. fclose($fl);
  1447. } else {
  1448. $err = true;
  1449. }
  1450. if ($err) {
  1451. echo "<br />an error occurs with log system.";
  1452. }
  1453. }
  1454. //---- Log System
  1455. //Online User
  1456. function GetOnline() {
  1457. if (!file_exists(VISITOR_LST)) @touch(VISITOR_LST);
  1458. if (@file_exists(VISITOR_LST)) {
  1459. $timeoffset = 15; // time offset for online user
  1460. $onlines = file_get_contents(VISITOR_LST);
  1461. $onlineList = unserialize($onlines);
  1462. $online = 0;
  1463. if (is_array($onlineList)) {
  1464. foreach ($onlineList as $time) {
  1465. if (time() - $time < $timeoffset * 60) {
  1466. $online++;
  1467. }
  1468. }
  1469. }
  1470. return $online;
  1471. }
  1472. }
  1473. function UpdateOnline() {
  1474. global $ipmu;
  1475. if (!file_exists(VISITOR_LST)) @touch(VISITOR_LST);
  1476. if (@file_exists(VISITOR_LST)) {
  1477. $onlines = file_get_contents(VISITOR_LST);
  1478. $onlineList = unserialize($onlines);
  1479. //$onlineList[$_SERVER['REMOTE_ADDR']] = time();
  1480. $onlineList[$ipmu] = time();
  1481. $content = serialize($onlineList);
  1482. file_put_contents(VISITOR_LST, $content);
  1483. }
  1484. }
  1485. //--End Online User
  1486. function ongoingAdd() {
  1487. global $onGoing;
  1488. if (!file_exists(ONGOING_LST)) @touch(ONGOING_LST);
  1489. if (@file_exists(ONGOING_LST)) {
  1490. $ongoings = file_get_contents(ONGOING_LST);
  1491. (is_numeric($ongoings) ? $ongoings++ : $ongoings = 1);
  1492. file_put_contents(ONGOING_LST, $ongoings);
  1493. }
  1494. $onGoing = true;
  1495. }
  1496. function ongoingGet() {
  1497. if (@file_exists(ONGOING_LST)) {
  1498. $ongoings = file_get_contents(ONGOING_LST);
  1499. return (int) $ongoings;
  1500. }
  1501. }
  1502. function ongoingRemove() {
  1503. global $onGoing;
  1504. if (@file_exists(ONGOING_LST)) {
  1505. $ongoings = file_get_contents(ONGOING_LST);
  1506. (is_numeric($ongoings) ? ($ongoings > 0 ? $ongoings-- : 0) : $ongoings = 0);
  1507. file_put_contents(ONGOING_LST, $ongoings);
  1508. }
  1509. $onGoing = false;
  1510. }
  1511. function write_traffic($fname, $isi) {
  1512. $fl = fopen($fname, "w");
  1513. if (!$fl) {
  1514. return FALSE;
  1515. } else {
  1516. if (!flock($fl, LOCK_EX)) {
  1517. return FALSE;
  1518. } else {
  1519. if (!fwrite($fl, $isi)) {
  1520. return FALSE;
  1521. } else {
  1522. if (!flock($fl, LOCK_UN)) {
  1523. return FALSE;
  1524. } else {
  1525. if (!fclose($fl)) {
  1526. return FALSE;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. //@fclose($fname);
  1533. return TRUE;
  1534. }
  1535. #============================
  1536. function updateCozEmpty($f) {
  1537. global $list;
  1538. updateListInFile($list);
  1539. }
  1540. function getBigFilesize($file) {
  1541. $INT = 4294967295; //2147483647+2147483647+1;
  1542. $size = filesize($file);
  1543. $fp = @fopen($file, 'r');
  1544. if ($fp) {
  1545. fseek($fp, 0, SEEK_END);
  1546. if (ftell($fp) == 0) {
  1547. $size += $INT;
  1548. }
  1549. if ($size < 0) {
  1550. $size += $INT;
  1551. }
  1552. @fclose($fp);
  1553. }
  1554. return $size;
  1555. }
  1556. // Load language in language folder; get css type; return array
  1557. function getArrayfromfile($loc, $predmatch, $succmatch, $find='file') {
  1558. if ($loc == '') {
  1559. return false;
  1560. }
  1561. $_CONSTANTS['D_DIR'] = $loc;
  1562. $cleanfn = array();
  1563. $dir = @dir($_CONSTANTS['D_DIR']);
  1564. if ($dir) {
  1565. while (false !== ($file = $dir->read())) {
  1566. switch ($find) {
  1567. ca

Large files files are truncated, but you can click here to view the full file