1
0

control-subnets-usage.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. unset($_POST);
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  6. print_control_submenu($page_url);
  7. $zombi_days = get_option($db_link, 35);
  8. // Создаём временную метку: сейчас минус $zombi_days дней
  9. $zombi_threshold = date('Y-m-d H:i:s', strtotime("-$zombi_days days"));
  10. ?>
  11. <div id="cont">
  12. <br>
  13. <b><?php echo WEB_network_usage_title; ?></b> <br>
  14. <table class="data">
  15. <tr align="center">
  16. <td><b><?php echo WEB_network_subnet; ?></b></td>
  17. <td><b><?php echo WEB_network_all_ip; ?></b></td>
  18. <td><b><?php echo WEB_network_used_ip; ?></b></td>
  19. <td><b><?php echo WEB_network_free_ip; ?></b></td>
  20. <td><b><?php echo WEB_network_dhcp_size; ?></b></td>
  21. <td><b><?php echo WEB_network_dhcp_used; ?></b></td>
  22. <td><b><?php echo WEB_network_dhcp_free; ?></b></td>
  23. <td><b><?php echo WEB_network_static_free; ?></b></td>
  24. <td><b><?php echo WEB_network_zombi; ?><br><?php print "(> ".$zombi_days." ".WEB_days.")"; ?></b></td>
  25. <td><b><?php echo WEB_network_zombi_dhcp; ?><br><?php print "(> ".$zombi_days." ".WEB_days.")"; ?></b></td>
  26. </tr>
  27. <?php
  28. $t_subnets = get_records_SQL($db_link, 'SELECT * FROM subnets WHERE office=1 ORDER BY ip_int_start');
  29. if (!empty($t_subnets)) {
  30. foreach ($t_subnets as $row) {
  31. print "<tr align=center>\n";
  32. $cl = "data";
  33. // Subnet
  34. print "<td class=\"$cl\"><a href=/admin/iplist/index.php?ou=0&cidr=" . htmlspecialchars($row['subnet']) . ">" . htmlspecialchars($row['subnet']) . "</a></td>\n";
  35. // Total IPs
  36. $subnet_ips = max(0, $row['ip_int_stop'] - $row['ip_int_start'] + 1);
  37. if ($subnet_ips > 4 ) { $all_ips = $subnet_ips - 3; } else { $all_ips = $subnet_ips; }
  38. print "<td class=\"$cl\">" . $all_ips . "</td>\n";
  39. // Used (total)
  40. $used_all = get_count_records($db_link, 'user_auth', 'deleted = 0 AND ip_int >= ? AND ip_int <= ?', [$row['ip_int_start'], $row['ip_int_stop']]);
  41. $total_used_percent = ($all_ips > 0) ? ($used_all / $all_ips) * 100 : 0;
  42. $total_class = '';
  43. if ($total_used_percent >= 95) {
  44. $total_class = 'error';
  45. } elseif ($total_used_percent >= 85) {
  46. $total_class = 'warn';
  47. }
  48. print "<td class=\"" . ($total_class ?: $cl) . "\">" . $used_all . "</td>\n";
  49. // Free (total)
  50. $free_all = max(0, $all_ips - $used_all);
  51. $free_total_class = '';
  52. if ($all_ips > 0) {
  53. $free_total_percent = ($free_all / $all_ips) * 100;
  54. if ($free_total_percent <= 5) {
  55. $free_total_class = 'error';
  56. } elseif ($free_total_percent <= 15) {
  57. $free_total_class = 'warn';
  58. }
  59. }
  60. print "<td class=\"" . ($free_total_class ?: $cl) . "\">" . $free_all . "</td>\n";
  61. // DHCP pool size
  62. $dhcp_pool = max(0, $row['dhcp_stop'] - $row['dhcp_start'] + 1);
  63. print "<td class=\"$cl\">" . $dhcp_pool . "</td>\n";
  64. // Used (DHCP)
  65. $used_dhcp = 0;
  66. if ($dhcp_pool > 0) {
  67. $used_dhcp = get_count_records($db_link, 'user_auth', 'deleted = 0 AND ip_int >= ? AND ip_int <= ?', [$row['dhcp_start'], $row['dhcp_stop']]);
  68. }
  69. $dhcp_used_percent = ($dhcp_pool > 0) ? ($used_dhcp / $dhcp_pool) * 100 : 0;
  70. $dhcp_used_class = '';
  71. if ($dhcp_used_percent >= 95) {
  72. $dhcp_used_class = 'error';
  73. } elseif ($dhcp_used_percent >= 85) {
  74. $dhcp_used_class = 'warn';
  75. }
  76. print "<td class=\"" . ($dhcp_used_class ?: $cl) . "\">" . $used_dhcp . "</td>\n";
  77. // Free (DHCP)
  78. $free_dhcp = max(0, $dhcp_pool - $used_dhcp);
  79. $free_dhcp_class = '';
  80. if ($dhcp_pool > 0) {
  81. $free_dhcp_percent = ($free_dhcp / $dhcp_pool) * 100;
  82. if ($free_dhcp_percent <= 5) {
  83. $free_dhcp_class = 'error';
  84. } elseif ($free_dhcp_percent <= 15) {
  85. $free_dhcp_class = 'warn';
  86. }
  87. }
  88. print "<td class=\"" . ($free_dhcp_class ?: $cl) . "\">" . $free_dhcp . "</td>\n";
  89. // Free static
  90. $free_static = max ( 0, $free_all - $free_dhcp);
  91. print "<td class=\"$cl\">" . $free_static . "</td>\n";
  92. // Zombie (total) — от общего размера подсети
  93. $zombi_total = get_count_records($db_link, 'user_auth', 'deleted = 0 AND ip_int >= ? AND ip_int <= ? AND last_found <= ?', [$row['ip_int_start'], $row['ip_int_stop'], $zombi_threshold]);
  94. $zombi_total_class = '';
  95. if ($all_ips > 0) {
  96. $zombi_total_ratio = ($zombi_total / $all_ips) * 100;
  97. if ($zombi_total_ratio >= 30) {
  98. $zombi_total_class = 'error';
  99. } elseif ($zombi_total_ratio >= 20) {
  100. $zombi_total_class = 'warn';
  101. }
  102. }
  103. print "<td class=\"" . ($zombi_total_class ?: $cl) . "\">" . $zombi_total . "</td>\n";
  104. // Zombie (DHCP) — от размера DHCP-пула
  105. $zombi_dhcp = get_count_records($db_link, 'user_auth', 'deleted = 0 AND ip_int >= ? AND ip_int <= ? AND last_found <= ?', [$row['dhcp_start'], $row['dhcp_stop'], $zombi_threshold]);
  106. $zombi_dhcp_class = '';
  107. if ($dhcp_pool > 0) {
  108. $zombi_dhcp_ratio = ($zombi_dhcp / $dhcp_pool) * 100;
  109. if ($zombi_dhcp_ratio >= 30) {
  110. $zombi_dhcp_class = 'error';
  111. } elseif ($zombi_dhcp_ratio >= 20) {
  112. $zombi_dhcp_class = 'warn';
  113. }
  114. }
  115. print "<td class=\"" . ($zombi_dhcp_class ?: $cl) . "\">" . $zombi_dhcp . "</td>\n";
  116. print "</tr>\n";
  117. }
  118. }
  119. ?>
  120. </table>
  121. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>