edit_l3int.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. $int_list = getIpAdEntIfIndex($db_link,$device['ip'],$device['community'],$device['snmp_version']);
  8. if (isset($_POST["s_remove"])) {
  9. $s_id = $_POST["s_id"];
  10. foreach ($s_id as $key => $val) {
  11. if (isset($val)) {
  12. LOG_INFO($db_link, "Remove l3_interface id: $val ". dump_record($db_link,'device_l3_interfaces','id='.$val));
  13. delete_record($db_link, "device_l3_interfaces", "id=" . $val);
  14. }
  15. }
  16. header("Location: " . $_SERVER["REQUEST_URI"]);
  17. exit;
  18. }
  19. if (isset($_POST['s_save'])) {
  20. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  21. for ($i = 0; $i < $len; $i ++) {
  22. $save_id = intval($_POST['s_save'][$i]);
  23. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  24. for ($j = 0; $j < $len_all; $j ++) {
  25. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  26. $new['interface_type'] = $_POST['s_type'][$j]*1;
  27. update_record($db_link, "device_l3_interfaces", "id='{$save_id}'", $new);
  28. }
  29. }
  30. header("Location: " . $_SERVER["REQUEST_URI"]);
  31. exit;
  32. }
  33. if (isset($_POST["s_create"])) {
  34. if (!empty($_POST["s_create_name"])) {
  35. $new = NULL;
  36. list($new['name'],$new['snmpin'],$new['interface_type']) = explode(";", trim($_POST["s_create_name"]));
  37. $new['device_id'] = $id;
  38. $new['name']=preg_replace('/\"/','',$new['name']);
  39. LOG_INFO($db_link, "Create new l3_interface ".$new['name']);
  40. insert_record($db_link, "device_l3_interfaces", $new);
  41. }
  42. header("Location: " . $_SERVER["REQUEST_URI"]);
  43. exit;
  44. }
  45. unset($_POST);
  46. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  47. print_device_submenu($page_url);
  48. print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
  49. ?>
  50. <div id="contsubmenu">
  51. <br>
  52. <?php print "<form name=def action='edit_l3int.php?id=".$id."' method=post>"; ?>
  53. <?php print WEB_list_l3_interfaces."<b>"; print_url($device['device_name'],"/admin/devices/editdevice.php?id=$id"); ?>
  54. </b> <br>
  55. <table class="data">
  56. <tr align="center">
  57. <td></td>
  58. <td width=30><b>id</b></td>
  59. <td><b><?php echo WEB_cell_name; ?></b></td>
  60. <td><b><?php echo WEB_cell_type; ?></b></td>
  61. <td>
  62. <input type="submit" onclick="return confirm('<?php print WEB_msg_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>">
  63. </td>
  64. </tr>
  65. <?php
  66. $t_l3_interface = get_records($db_link,'device_l3_interfaces',"device_id=$id ORDER BY name");
  67. $int_by_name = [];
  68. foreach ($int_list as $row) {
  69. $row['name'] = preg_replace('/\"/','',$row['name']);
  70. $int_by_name[$row['name']]=$row;
  71. }
  72. $fixed = 0;
  73. //fixing snmp index if not exists by interface name
  74. foreach ( $t_l3_interface as $row ) {
  75. $fix = NULL;
  76. if (empty($row['snmpin']) and !empty($int_by_name[$row['name']])) {
  77. $fix['snmpin']=$int_by_name[$row['name']]['index'];
  78. if (!empty($fix)) {
  79. update_record($db_link,'device_l3_interfaces','id='.$row['id'],$fix);
  80. }
  81. $fixed = 1;
  82. }
  83. }
  84. //updating interface name by snmp index
  85. foreach ( $t_l3_interface as $row ) {
  86. $fix = NULL;
  87. if (!empty($int_list[$row['snmpin']]) and $int_list[$row['snmpin']]['name'] !== $row['name']) {
  88. $fix['name']=$int_list[$row['snmpin']]['name'];
  89. if (!empty($fix)) {
  90. update_record($db_link,'device_l3_interfaces','id='.$row['id'],$fix);
  91. }
  92. $fixed = 1;
  93. }
  94. }
  95. if ($fixed) {
  96. $t_l3_interface = get_records($db_link,'device_l3_interfaces',"device_id=$id ORDER BY name");
  97. }
  98. foreach ( $t_l3_interface as $row ) {
  99. print "<tr align=center>\n";
  100. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  101. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['snmpin']}</td>\n";
  102. print "<td class=\"data\">".$row['name'].'/'.$int_list[$row['snmpin']]['ip']."</td>\n";
  103. print "<td class=\"data\">"; print_qa_l3int_select('s_type[]',$row['interface_type']); print "</td>\n";
  104. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  105. print "</tr>\n";
  106. }
  107. ?>
  108. <tr>
  109. <td colspan=4><?php print WEB_l3_interface_add; print_add_dev_interface($db_link, $id, $int_list, 's_create_name');?>
  110. </td>
  111. <td>
  112. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  113. </td>
  114. </tr>
  115. </table>
  116. </form>
  117. <?php
  118. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  119. ?>