Unsupported scripts and control panel web app for a hosting company
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?PHP
  2. if (strpos(__FILE__, 'control-dev') !== false) {
  3. define('CP_PATH', '/dev/');
  4. define('DEVELOPMENT', True);
  5. } else {
  6. define('CP_PATH', '/control/');
  7. define('DEVELOPMENT', False);
  8. }
  9. require_once('lib/database.php');
  10. require_once('lib/log.php');
  11. function NiceSize($bytes) {
  12. $sizes = array();
  13. $sizes[1024] = ' <abbr title="Kibibytes">KiB</abbr>';
  14. $sizes[(1024*1024)] = ' <abbr title="Mebibytes">MiB</abbr>';
  15. $sizes[(1024*1024*1024)] = ' <abbr title="Gibibytes">GiB</abbr>';
  16. krsort($sizes);
  17. foreach ($sizes as $val => $name) {
  18. if ($bytes > ($val * 1.2)) {
  19. return round($bytes/$val, 2).$name;
  20. }
  21. }
  22. return $bytes.' <abbr title="Bytes">B</abbr>';
  23. }
  24. function h ($text) { return htmlspecialchars($text); }
  25. function m ($a) { return mysql_real_escape_string($a); }
  26. function l ($message, $uid = false) {
  27. logger::log($message, $uid);
  28. }
  29. function botlog ($message) {
  30. logger::log($message);
  31. }
  32. function bfc ($ip) {
  33. if (file_exists('/home/utd/bruteforce.dat')) {
  34. $data = unserialize(file_get_contents('/home/utd/bruteforce.dat'));
  35. } else {
  36. $data = array();
  37. }
  38. foreach ($data as $uip => $attempts) {
  39. foreach ($attempts as $id => $time) {
  40. if ($time < time()-1800) { unset($data[$uip][$id]); }
  41. }
  42. if (count($data[$uip]) == 0) { unset($data[$uip]); }
  43. }
  44. if (!isset($data[$ip])) { $data[$ip] = array(); }
  45. $data[$ip][] = time();
  46. file_put_contents('/home/utd/bruteforce.dat', serialize($data));
  47. if (count($data[$ip]) > 4) {
  48. $sql = 'INSERT INTO ipbans (ipban_ip, ipban_expires, ipban_message) ';
  49. $sql .= 'VALUES (\''.m($ip).'\', '.(time()+60*60*24).', \'Too many login';
  50. $sql .= ' attempts.\')';
  51. mysql_query($sql);
  52. logger::log('Placing IP ban on '.$ip.' for bruteforcing',logger::important);
  53. header('Location: '.CP_PATH.'403');
  54. exit;
  55. }
  56. }
  57. function duration ($secs, $dopast = false) {
  58. $res = '';
  59. $times = array();
  60. $times['year'] = (60*60*24*365);
  61. $times['month'] = (60*60*24*30);
  62. $times['week'] = (60*60*24*7);
  63. $times['day'] = (60*60*24);
  64. $times['hour'] = (60*60);
  65. if ($secs < $times['hour']) { $times['minute'] = 60; }
  66. if ($secs < $times['minute']) { $times['second'] = 1; }
  67. foreach ($times as $name => $val) {
  68. if ($secs >= $val) {
  69. $years = floor($secs/$val);
  70. $res .= ', '.$years.' '.$name.(($years!=1)?'s':'');
  71. $secs = $secs % $val;
  72. }
  73. }
  74. $res = substr($res, 2);
  75. if ($res == '' && $dopast === true) {
  76. $res = 'now';
  77. } elseif ($res == '' && $dopast == '0') {
  78. $res = '0 seconds';
  79. }
  80. return $res;
  81. }
  82. define('LIB_COMMON', true);
  83. ?>