editswitches.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. if (isset($_POST["editswitches"]) and isset($id)) {
  6. if (isset($_POST["f_port_count"])) {
  7. $sw_ports = $_POST["f_port_count"] * 1;
  8. } else {
  9. $sw_ports = 0;
  10. }
  11. $sSQL = "SELECT count(id) from device_ports WHERE device_ports.device_id=$id";
  12. $flist = mysqli_query($db_link, $sSQL);
  13. list ($d_ports) = mysqli_fetch_array($flist);
  14. if ($d_ports != $sw_ports) {
  15. LOG_DEBUG($db_link, "Device id: $id changed port count!");
  16. if ($sw_ports > $d_ports) {
  17. $start_port = $d_ports + 1;
  18. LOG_DEBUG($db_link, "Device id: $id add connection for port from $start_port to $sw_ports.");
  19. for ($port = $start_port; $port <= $sw_ports; $port ++) {
  20. $new['device_id'] = $id;
  21. $new['snmp_index'] = $port;
  22. $new['port'] = $port;
  23. insert_record($db_link, "device_ports", $new);
  24. }
  25. }
  26. if ($sw_ports < $d_ports) {
  27. LOG_DEBUG($db_link, "Device id: $id remove connection for port from $d_ports to $sw_ports");
  28. for ($port = $d_ports; $port > $sw_ports; $port --) {
  29. $port_id = get_id_record($db_link, 'device_ports', "device_id='" . $id . "' and port='" . $port . "'");
  30. if ($port_id) {
  31. delete_record($db_link, "device_ports", "id='" . $port_id . "'");
  32. delete_record($db_link, "connections", "port_id='" . $port_id . "'");
  33. } else {
  34. LOG_DEBUG($db_link, "Device id: $id port_id not found for port: $port!");
  35. }
  36. }
  37. }
  38. }
  39. unset($new);
  40. if (isset($_POST["f_device_name"])) { $new['device_name'] = substr($_POST["f_device_name"], 0, 50); }
  41. if (isset($_POST["f_device_model"])) { $new['device_model'] = substr($_POST["f_device_model"], 0, 50); }
  42. if (isset($_POST["f_devtype_id"])) { $new['device_type'] = $_POST["f_devtype_id"]*1; }
  43. if (isset($_POST["f_comment"])) { $new['comment'] = $_POST["f_comment"]; }
  44. if (isset($_POST["f_SN"])) { $new['SN'] = $_POST["f_SN"]; }
  45. if (isset($_POST["f_ip"])) { $new['ip'] = substr($_POST["f_ip"], 0, 15); }
  46. if (isset($_POST["f_snmp_version"])) { $new['snmp_version'] = $_POST["f_snmp_version"] * 1; }
  47. if (isset($_POST["f_community"])) { $new['community'] = substr($_POST["f_community"], 0, 50); }
  48. if (isset($_POST["f_rw_community"])) { $new['rw_community'] = substr($_POST["f_rw_community"], 0, 50); }
  49. if (isset($_POST["f_queue_enabled"])) { $new['queue_enabled'] = $_POST["f_queue_enabled"] * 1; }
  50. if (isset($_POST["f_connected_user_only"])) { $new['connected_user_only'] = $_POST["f_connected_user_only"] * 1; }
  51. if (isset($_POST["f_snmp3_user_rw"])) { $new['snmp3_user_rw'] = substr($_POST["f_snmp3_user_rw"], 0, 20); }
  52. if (isset($_POST["f_snmp3_user_ro"])) { $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20); }
  53. if (isset($_POST["f_snmp3_user_rw_password"])) { $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20); }
  54. if (isset($_POST["f_snmp3_user_ro_password"])) { $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20); }
  55. if (isset($_POST["f_fdb_snmp"])) { $new['fdb_snmp_index'] = $_POST["f_fdb_snmp"]; }
  56. if (isset($_POST["f_discovery"])) { $new['discovery'] = $_POST["f_discovery"]; }
  57. if (isset($_POST["f_dhcp"])) { $new['dhcp'] = $_POST["f_dhcp"] * 1; }
  58. if (isset($_POST["f_user_acl"])) { $new['user_acl'] = $_POST["user_acl"] * 1; }
  59. if (isset($_POST["f_wan"])) { $new['wan_int'] = $_POST["f_wan"]; }
  60. if (isset($_POST["f_lan"])) { $new['lan_int'] = $_POST["f_lan"]; }
  61. if (isset($_POST["f_building_id"])) { $new['building_id'] = $_POST["f_building_id"] * 1; }
  62. if (isset($_POST["f_user_id"])) { $new['user_id'] = $_POST["f_user_id"] * 1; }
  63. if (isset($_POST["f_nagios"])) { $new['nagios'] = $_POST["f_nagios"] * 1; }
  64. if (empty($new['nagios'])) { $new['nagios_status'] = 'UP'; }
  65. if (isset($_POST["f_vendor_id"])) { $new['vendor_id'] = $_POST["f_vendor_id"] * 1; }
  66. if (isset($_POST["f_port_count"])) { $new['port_count'] = $sw_ports; }
  67. update_record($db_link, "devices", "id='$id'", $new);
  68. header("Location: " . $_SERVER["REQUEST_URI"]);
  69. }
  70. if (isset($_POST["undelete"]) and isset($id)) {
  71. unset($new);
  72. $new['deleted'] = 0;
  73. LOG_INFO($db_link, "Recovery deleted device id: $id");
  74. update_record($db_link, "devices", "id='$id'", $new);
  75. header("Location: " . $_SERVER["REQUEST_URI"]);
  76. }
  77. $device=get_record($db_link,'devices',"id=".$id);
  78. unset($_POST);
  79. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  80. print_editdevice_submenu($page_url,$id);
  81. ?>
  82. <div id="cont">
  83. <form name="def" action="editswitches.php?id=<? echo $id; ?>" method="post">
  84. <table class="data">
  85. <tr>
  86. <td>Название</td>
  87. <td>IP</td>
  88. <td>Тип</td>
  89. <td>Портов</td>
  90. </tr>
  91. <?php
  92. print "<tr>\n";
  93. print "<td class=\"data\"><input type=\"text\" name='f_device_name' value='".$device['device_name']."'></td>\n";
  94. print "<td class=\"data\"><input type=\"text\" name='f_ip' value='".$device['ip']."'></td>\n";
  95. print "<td class=\"data\">"; print_devtype_select($db_link,'f_devtype_id',$device['device_type']); print "</td>\n";
  96. print "<td class=\"data\"><input type=\"text\" name='f_port_count' value='".$device['port_count']."' size=5></td>\n";
  97. print "</tr>\n";
  98. ?>
  99. </tr>
  100. <td>Вендор</td>
  101. <td>Модель</td>
  102. <td colspan=2>SN</td>
  103. <?php
  104. print "<tr>\n";
  105. print "<td class=\"data\">"; print_vendor_select($db_link, 'f_vendor_id', $device['vendor_id']); print "</td>\n";
  106. print "<td class=\"data\"><input type=\"text\" name='f_device_model' value='".$device['device_model']."'></td>\n";
  107. print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_SN' value='".$device['SN']."'></td>\n";
  108. print "</tr>\n";
  109. print "<tr><td>Расположен</td><td colspan=2>Комментарий</td>";
  110. if (isset($device['user_id']) and $device['user_id']>0) { print "<td align=right><a href=/admin/users/edituser.php?id=".$device['user_id'].">Auth user</a><td>\n"; } else { print "<td>Auth user<td>"; }
  111. print "</tr><tr>";
  112. print "<td class=\"data\">"; print_building_select($db_link, 'f_building_id', $device['building_id']); print "</td>\n";
  113. print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_comment' value='".$device['comment']."'></td>\n";
  114. print "<td class=\"data\">"; print_login_select($db_link,'f_user_id', $device['user_id']); print "</td>\n";
  115. print "</tr>";
  116. if ($device['device_type']==2) {
  117. print "<tr><td>Управление доступом</td><td>DHCP-Server</td><td>Шейперы</td><td>Только connected юзеры</td>";
  118. print "<tr>";
  119. print "<td class=\"data\">"; print_qa_select('f_user_acl', $device['user_acl']); print "</td>\n";
  120. print "<td class=\"data\">"; print_qa_select('f_dhcp', $device['dhcp']); print "</td>\n";
  121. print "<td class=\"data\">"; print_qa_select('f_queue_enabled', $device['queue_enabled']); print "</td>\n";
  122. print "<td class=\"data\">"; print_qa_select('f_connected_user_only', $device['connected_user_only']); print "</td>\n";
  123. print "</tr>\n";
  124. print "<tr><td colspan=4>"; print_url("Список интерфейсов","/admin/devices/edit_l3int.php?id=$id"); print "</td></tr>";
  125. print "<tr>\n";
  126. print "<td colspan=4 class=\"data\">"; print get_l3_interfaces($db_link,$device['id']); print "</td>\n";
  127. print "<tr>\n";
  128. }
  129. ?>
  130. </tr>
  131. <td>Snmp Version</td>
  132. <td>fdb by snmp</td>
  133. <td>Discovery</td>
  134. <td>Nagios</td>
  135. <td>
  136. </td>
  137. <?php
  138. print "<tr>\n";
  139. print "<td class=\"data\">"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
  140. print "<td class=\"data\">"; print_qa_select('f_fdb_snmp', $device['fdb_snmp_index']); print "</td>\n";
  141. print "<td class=\"data\">"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
  142. print "<td class=\"data\">"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
  143. print "</tr>\n";
  144. if ($device['snmp_version'] ==3) {
  145. print "<tr><td>Snmpv3 RO user</td><td>Snmpv3 RW user</td><td>Snmpv3 RO password</td><td>Snmpv3 RW password</td><td></td>";
  146. print "</tr><tr>";
  147. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro' value=".$device['snmp3_user_ro']."></td>\n";
  148. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw' value=".$device['snmp3_user_rw']."></td>\n";
  149. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro_password' value=".$device['snmp3_user_ro_password']."></td>\n";
  150. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw_password' value=".$device['snmp3_user_rw_password']."></td>\n";
  151. print "<td></td></tr>\n";
  152. }
  153. ?>
  154. <tr>
  155. <td>Snmp RO Community</td>
  156. <td>Snmp RW Community</td>
  157. <td></td>
  158. <td></td>
  159. </tr>
  160. <?php
  161. print "<tr>\n";
  162. print "<td class=\"data\"><input type=\"text\" name='f_community' value=".$device['community']."></td>\n";
  163. print "<td class=\"data\"><input type=\"text\" name='f_rw_community' value=".$device['rw_community']."></td>\n";
  164. print "<td><button name=\"port_walk\" onclick=\"window.open('mactable.php?id=" . $id . "')\">Mac table</button>\n";
  165. print "<button name=\"port_walk\" onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">Port Walk</button>";
  166. print "<td align=right>";
  167. if ($device['deleted']) { print "<input type=\"submit\" name=\"undelete\" value=\"Воскресить\">"; }
  168. print "<input type=\"submit\" name=\"editswitches\" value=\"Сохранить\"></td>\n";
  169. print "</tr>\n";
  170. print "</table>\n";
  171. ?>
  172. </form>
  173. <?
  174. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  175. ?>