1
0

include.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. error_reporting(E_ALL & ~(E_NOTICE|E_STRICT));
  3. define("INT_DAILY", 60*60*24*2);
  4. define("INT_WEEKLY", 60*60*24*8);
  5. define("INT_MONTHLY", 60*60*24*35);
  6. define("INT_YEARLY", 60*60*24*400);
  7. define("XOFFSET", 90);
  8. define("YOFFSET", 45);
  9. require("config.conf.php");
  10. function ConnectDb() {
  11. global $db_connect_string;
  12. try {
  13. $db = new PDO($db_connect_string);
  14. } catch (PDOException $ex) {
  15. die("DB Error, could not connect to database: " . $ex->getMessage());
  16. }
  17. return $db;
  18. }
  19. function fmtb($kbytes)
  20. {
  21. $Max = 1024;
  22. $Output = $kbytes;
  23. $Suffix = 'K';
  24. if ($Output > $Max)
  25. {
  26. $Output /= 1024;
  27. $Suffix = 'M';
  28. }
  29. if ($Output > $Max)
  30. {
  31. $Output /= 1024;
  32. $Suffix = 'G';
  33. }
  34. if ($Output > $Max)
  35. {
  36. $Output /= 1024;
  37. $Suffix = 'T';
  38. }
  39. return(sprintf("<td align=right><tt>%.1f%s</td>", $Output, $Suffix));
  40. }
  41. function ip2s32($ip) {
  42. $i = ip2long($ip);
  43. return ($i & 0x80000000 ? '-' . ((~$i & 0x7fffffff)+1) : ''. ($i & 0x7fffffff));
  44. }
  45. function prepare_sql_subnet($subnet) {
  46. list($snet, $smask) = explode('/', $subnet);
  47. $inet = ip2s32($snet);
  48. if($smask > 0 && $smask < 32) {
  49. $mask = -1 << (32 - (int)$smask);
  50. return "and (ip & $mask = $inet)";
  51. } elseif ($inet) {
  52. return "and ip = " . $inet;
  53. }
  54. return "";
  55. }
  56. $starttime = time();
  57. set_time_limit(300);
  58. ?>