index-subnets.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. // Удаление подсетей
  5. if (getPOST("s_remove") !== null) {
  6. $s_id = getPOST("s_id", null, []);
  7. if (!empty($s_id) && is_array($s_id)) {
  8. foreach ($s_id as $net_id) {
  9. $net_id = trim($net_id);
  10. if ($net_id === '') continue;
  11. delete_record($db_link, "subnets", "id = ?", [$net_id]);
  12. delete_record($db_link, "gateway_subnets", "subnet_id = ?", [$net_id]);
  13. }
  14. }
  15. header("Location: " . $_SERVER["REQUEST_URI"]);
  16. exit;
  17. }
  18. // Создание новой подсети
  19. if (getPOST("s_create") !== null) {
  20. $new_subnet = trim(getPOST("s_create_subnet", null, ''));
  21. if ($new_subnet !== '') {
  22. $range = cidrToRange($new_subnet);
  23. $first_user_ip = $range[0] ?? '';
  24. $last_user_ip = $range[1] ?? '';
  25. $cidr = $range[2] ?? null;
  26. // Формируем корректный CIDR
  27. if ($cidr !== null && $cidr < 32) {
  28. $new_subnet = "$first_user_ip/$cidr";
  29. } else {
  30. $range = cidrToRange($first_user_ip.'/24');
  31. $first_user_ip = $range[0] ?? '';
  32. $last_user_ip = $range[1] ?? '';
  33. $cidr = $range[2] ?? null;
  34. if ($cidr !== null && $cidr < 32) {
  35. $new_subnet = "$first_user_ip/$cidr";
  36. } else {
  37. //abort
  38. header("Location: " . $_SERVER["REQUEST_URI"]);
  39. exit;
  40. }
  41. }
  42. $start_ip = ip2long($first_user_ip);
  43. $stop_ip = ip2long($last_user_ip);
  44. $new = [
  45. 'subnet' => $new_subnet,
  46. 'ip_int_start' => $start_ip,
  47. 'ip_int_stop' => $stop_ip,
  48. 'dhcp_start' => ip2long($range[3] ?? $first_user_ip),
  49. 'dhcp_stop' => ip2long($range[4] ?? $first_user_ip),
  50. 'gateway' => ip2long($range[5] ?? $first_user_ip)
  51. ];
  52. insert_record($db_link, "subnets", $new);
  53. }
  54. header("Location: " . $_SERVER["REQUEST_URI"]);
  55. exit;
  56. }
  57. unset($_POST);
  58. fix_auth_rules($db_link);
  59. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  60. print_control_submenu($page_url);
  61. ?>
  62. <div id="cont">
  63. <br>
  64. <form name="def" action="index-subnets.php" method="post">
  65. <div>
  66. <?php print WEB_network_create . "&nbsp:<input type=\"text\" name='s_create_subnet' value=''>"; ?>
  67. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  68. <input class="button_right" type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>">
  69. </div>
  70. <b><?php echo WEB_network_org_title; ?></b> <br>
  71. <table class="data">
  72. <tr align="center">
  73. <td></td>
  74. <td><b><?php echo WEB_network_subnet; ?></b></td>
  75. <td><b><?php echo WEB_network_vlan; ?></b></td>
  76. <td><b><?php echo WEB_network_use_dhcp; ?></b></td>
  77. <td><b><?php echo WEB_network_static; ?></b></td>
  78. <td><b><?php echo WEB_network_office_subnet; ?></b></td>
  79. <td><b><?php echo WEB_network_hotspot; ?></b></td>
  80. <td><b><?php echo WEB_network_vpn; ?></b></td>
  81. <td><b><?php echo WEB_network_free; ?></b></td>
  82. <td><b><?php echo WEB_network_dyndns; ?></b></td>
  83. <td><b><?php echo WEB_network_discovery; ?></b></td>
  84. <td><b><?php echo WEB_network_notify; ?></b></td>
  85. <td><b><?php echo WEB_cell_description; ?></b></td>
  86. </tr>
  87. <?php
  88. $t_subnets = get_records_sql($db_link, 'SELECT * FROM subnets ORDER BY ip_int_start');
  89. foreach ($t_subnets as $row) {
  90. print "<tr align=center>\n";
  91. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='" . $row['id'] . "'></td>\n";
  92. print "<td class=\"data\" align=left><a href=editsubnet.php?id=".$row["id"].">" . $row["subnet"] . "</a></td>\n";
  93. print "<td class=\"data\">" . $row['vlan_tag'] . " </td>\n";
  94. print_td_yes_no($row['dhcp']);
  95. print_td_yes_no($row['static']);
  96. print_td_yes_no($row['office']);
  97. print_td_yes_no($row['hotspot']);
  98. print_td_yes_no($row['vpn']);
  99. print_td_yes_no($row['free']);
  100. print_td_yes_no($row['dhcp_update_hostname']);
  101. print_td_yes_no($row['discovery']);
  102. print "<td class=\"data\">" . printFlagsByFirstLetter($row['notify']) . " </td>\n";
  103. print "<td class=\"data\">" . $row['description'] . " </td>\n";
  104. print "</tr>\n";
  105. }
  106. ?>
  107. </table>
  108. </form>
  109. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>