index-subnets.php 5.1 KB

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