edit_l3int.php 4.7 KB

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