1
0

edit_gw_subnets.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. $device = get_record($db_link, 'devices', "id = ?", [$id]);
  6. $user_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$device['user_id']]);
  7. // Удаление подсетей шлюза
  8. if (getPOST("s_remove") !== null) {
  9. $s_id = getPOST("gs_id", null, []);
  10. if (!empty($s_id) && is_array($s_id)) {
  11. foreach ($s_id as $val) {
  12. $val = trim($val);
  13. if ($val === '') continue;
  14. LOG_INFO($db_link, "Remove subnet from gateway id: $val " . dump_record($db_link, 'gateway_subnets', 'id = ?', [$val]));
  15. delete_record($db_link, "gateway_subnets", "id = ?", [(int)$val]);
  16. }
  17. }
  18. header("Location: " . $_SERVER["REQUEST_URI"]);
  19. exit;
  20. }
  21. // Добавление подсети к шлюзу
  22. if (getPOST("s_create") !== null) {
  23. $new_subnet = trim(getPOST("new_subnet", null, ''));
  24. if ($new_subnet !== '') {
  25. $new = [
  26. 'subnet_id' => $new_subnet,
  27. 'device_id' => $id
  28. ];
  29. LOG_INFO($db_link, "Add subnet id: " . $new['subnet_id'] . " for gateway id: " . $id);
  30. insert_record($db_link, "gateway_subnets", $new);
  31. }
  32. header("Location: " . $_SERVER["REQUEST_URI"]);
  33. exit;
  34. }
  35. unset($_POST);
  36. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  37. print_device_submenu($page_url);
  38. print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
  39. ?>
  40. <div id="contsubmenu">
  41. <br>
  42. <?php print "<form name=def action='edit_gw_subnets.php?id=".$id."' method=post>"; ?>
  43. <?php
  44. if ($device['device_type'] == 0) { print WEB_list_l3_networks; } else { print WEB_list_gateway_subnets."<b>"; }
  45. print_url($device['device_name'],"/admin/devices/editdevice.php?id=$id"); ?>
  46. </b> <br>
  47. <table class="data">
  48. <tr align="center">
  49. <td></td>
  50. <td width=10><b>id</b></td>
  51. <td><b><?php echo WEB_network_subnet; ?></b></td>
  52. <td>
  53. <input type="submit" onclick="return confirm('<?php print WEB_msg_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>">
  54. </td>
  55. </tr>
  56. <?php
  57. $gateway_subnets = get_records_sql($db_link,'SELECT gateway_subnets.*,subnets.subnet,subnets.description FROM gateway_subnets LEFT JOIN subnets ON gateway_subnets.subnet_id = subnets.id WHERE gateway_subnets.device_id=?', [$id]);
  58. foreach ( $gateway_subnets as $row ) {
  59. print "<tr align=center>\n";
  60. print "<td class=\"data\" style='padding:0' width=30><input type=checkbox name=gs_id[] value='{$row['id']}'></td>\n";
  61. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  62. print "<td class=\"data\">"; print get_subnet_description($db_link,$row['subnet_id']); print "</td>\n";
  63. print "<td></td></tr>\n";
  64. }
  65. ?>
  66. <tr>
  67. <td colspan=3><?php print WEB_btn_add; print_add_gw_subnets($db_link,$id,"new_subnet"); ?>
  68. </td>
  69. <td>
  70. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  71. </td>
  72. </tr>
  73. </table>
  74. </form>
  75. <?php
  76. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  77. ?>