editswitches.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. $new[device_name] = substr($_POST["f_device_name"], 0, 50);
  41. $new[device_model] = substr($_POST["f_device_model"], 0, 50);
  42. $new[comment] = $_POST["f_comment"];
  43. $new[ip] = substr($_POST["f_ip"], 0, 15);
  44. $new[mac] = mac_dotted($_POST["f_mac"]);
  45. $new[snmp_version] = $_POST["f_snmp_version"] * 1;
  46. $new[community] = substr($_POST["f_community"], 0, 50);
  47. $new[rw_community] = substr($_POST["f_rw_community"], 0, 50);
  48. $new[queue_enabled] = $_POST["f_queue_enabled"] * 1;
  49. $new[connected_user_only] = $_POST["f_connected_user_only"] * 1;
  50. $new[snmp3_user_rw] = substr($_POST["f_snmp3_user_rw"], 0, 20);
  51. $new[snmp3_user_ro] = substr($_POST["f_snmp3_user_ro"], 0, 20);
  52. $new[snmp3_user_rw_password] = substr($_POST["f_snmp3_user_rw_password"], 0, 20);
  53. $new[snmp3_user_ro_password] = substr($_POST["f_snmp3_user_ro_password"], 0, 20);
  54. $new[fdb_snmp_index] = $_POST["f_fdb_snmp"];
  55. $new[discovery] = $_POST["f_discovery"];
  56. $new[dhcp] = $_POST["f_dhcp"] * 1;
  57. $new[internet_gateway] = $_POST["f_gateway"] * 1;
  58. $new[wan_int] = $_POST["f_wan"];
  59. $new[lan_int] = $_POST["f_lan"];
  60. $new[building_id] = $_POST["f_building_id"] * 1;
  61. $new[user_id] = $_POST["f_user_id"] * 1;
  62. if ($new[internet_gateway]) {
  63. $new[is_router] = 1;
  64. } else {
  65. $new[is_router] = $_POST["f_router"];
  66. }
  67. $new[nagios] = $_POST["f_nagios"] * 1;
  68. if (! $new[nagios]) {
  69. $new[nagios_status] = 'UP';
  70. }
  71. $new[vendor_id] = $_POST["f_vendor_id"] * 1;
  72. $new[port_count] = $sw_ports;
  73. update_record($db_link, "devices", "id='$id'", $new);
  74. header("Location: " . $_SERVER["REQUEST_URI"]);
  75. }
  76. if (isset($_POST["undelete"]) and isset($id)) {
  77. unset($new);
  78. $new[deleted] = 0;
  79. LOG_INFO($db_link, "Recovery deleted device id: $id");
  80. update_record($db_link, "devices", "id='$id'", $new);
  81. header("Location: " . $_SERVER["REQUEST_URI"]);
  82. }
  83. $switch=get_record($db_link,'devices',"id=".$id);
  84. unset($_POST);
  85. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  86. print_editdevice_submenu($page_url,$id);
  87. ?>
  88. <div id="cont">
  89. <form name="def" action="editswitches.php?id=<? echo $id; ?>" method="post">
  90. <table class="data">
  91. <tr>
  92. <td>Название</td>
  93. <td>IP</td>
  94. <td>Mac</td>
  95. <td>Портов</td>
  96. <td>Расположен</td>
  97. </tr>
  98. <?php
  99. print "<tr>\n";
  100. print "<td class=\"data\"><input type=\"text\" name='f_device_name' value='$switch[device_name]'></td>\n";
  101. print "<td class=\"data\"><input type=\"text\" name='f_ip' value='$switch[ip]'></td>\n";
  102. print "<td class=\"data\"><input type=\"text\" name='f_mac' value='$switch[mac]'></td>\n";
  103. print "<td class=\"data\"><input type=\"text\" name='f_port_count' value=$switch[port_count] size=5></td>\n";
  104. print "<td class=\"data\">";
  105. print_building_select($db_link, 'f_building_id', $switch[building_id]);
  106. print "</td>\n";
  107. print "</tr>\n";
  108. ?>
  109. </tr>
  110. <td>Вендор</td>
  111. <td>Модель</td>
  112. <td colspan=3>Комментарий</td>
  113. </tr>
  114. <?php
  115. print "<tr>\n";
  116. print "<td class=\"data\">";
  117. print_vendor_select($db_link, 'f_vendor_id', $switch[vendor_id]);
  118. print "</td>\n";
  119. print "<td class=\"data\"><input type=\"text\" name='f_device_model' value='$switch[device_model]'></td>\n";
  120. print "<td class=\"data\" colspan=3><input type=\"text\" size=70 name='f_comment' value='$switch[comment]'></td>\n";
  121. print "</tr>\n";
  122. ?>
  123. <tr>
  124. <td>Шлюз в интернет</td>
  125. <td>Роутер</td>
  126. <td>DHCP-Server</td>
  127. <td>Шейперы</td>
  128. <td>Только connected юзеры</td>
  129. </tr>
  130. <?php
  131. print "<td class=\"data\">";
  132. print_qa_select('f_gateway', $switch[internet_gateway]);
  133. print "</td>\n";
  134. print "<td class=\"data\">";
  135. print_qa_select('f_router', $switch[is_router]);
  136. print "</td>\n";
  137. print "<td class=\"data\">";
  138. print_qa_select('f_dhcp', $switch[dhcp]);
  139. print "</td>\n";
  140. print "<td class=\"data\">";
  141. print_qa_select('f_queue_enabled', $switch[queue_enabled]);
  142. print "</td>\n";
  143. print "<td class=\"data\">";
  144. print_qa_select('f_connected_user_only', $switch[connected_user_only]);
  145. print "</td></tr>\n";
  146. if ($switch[is_router] or $switch[internet_gateway] or $switch[dhcp]) {
  147. print "<tr><td colspan=2>WAN интерфейс</td><td colspan=2>LAN интерфейсы</td><td></td></tr>";
  148. print "<tr>\n";
  149. print "<td colspan=2 class=\"data\"><input type=\"text\" size=50 name='f_wan' value=$switch[wan_int]></td>\n";
  150. print "<td colspan=2 class=\"data\"><input type=\"text\" size=50 name='f_lan' value=$switch[lan_int]></td>\n";
  151. print "<td class=\"data\"></td>\n";
  152. print "<tr>\n";
  153. }
  154. ?>
  155. </tr>
  156. <td>Snmp Version</td>
  157. <td>fdb by snmp</td>
  158. <td>Discovery</td>
  159. <td>Nagios</td>
  160. <td>
  161. <?php
  162. if (isset($switch[user_id]) and $switch[user_id]>0) { print "<a href=/admin/users/edituser.php?id=$switch[user_id]>Auth user</a>\n"; } else { print "Auth user"; }
  163. ?>
  164. </td>
  165. </tr>
  166. <?php
  167. print "<td class=\"data\">";
  168. print_snmp_select('f_snmp_version', $switch[snmp_version]);
  169. print "</td>\n";
  170. print "<td class=\"data\">";
  171. print_qa_select('f_fdb_snmp', $switch[fdb_snmp_index]);
  172. print "</td>\n";
  173. print "<td class=\"data\">";
  174. print_qa_select('f_discovery', $switch[discovery]);
  175. print "</td>\n";
  176. print "<td class=\"data\">";
  177. print_qa_select('f_nagios', $switch[nagios]);
  178. print "</td>\n";
  179. print "<td class=\"data\">";
  180. print_login_select($db_link,'f_user_id', $switch[user_id]);
  181. print "</td>\n";
  182. print "</tr>\n";
  183. ?>
  184. <tr>
  185. <td>Snmpv3 RO user</td>
  186. <td>Snmpv3 RW user</td>
  187. <td>Snmp RO Community</td>
  188. <td>Snmp RW Community</td>
  189. <?php
  190. print "<td><button name=\"port_walk\" onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">Port Walk</button>";
  191. ?>
  192. <tr>
  193. <?php
  194. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro' value=$switch[snmp3_user_ro]></td>\n";
  195. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw' value=$switch[snmp3_user_rw]></td>\n";
  196. print "<td class=\"data\"><input type=\"text\" name='f_community' value=$switch[community]></td>\n";
  197. print "<td class=\"data\"><input type=\"text\" name='f_rw_community' value=$switch[rw_community]></td>\n";
  198. print "<td><button name=\"port_walk\" onclick=\"window.open('mactable.php?id=" . $id . "')\">Mac table</button></td>\n";
  199. print "</tr>\n";
  200. ?>
  201. <tr>
  202. <td>Snmpv3 RO password</td>
  203. <td>Snmpv3 RW password</td>
  204. <td></td>
  205. <td></td>
  206. </tr>
  207. <?php
  208. print "<tr>\n";
  209. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro_password' value=$switch[snmp3_user_ro_password]></td>\n";
  210. print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw_password' value=$switch[snmp3_user_rw_password]></td>\n";
  211. print "<td colspan=2>";
  212. if ($switch[deleted]) { print "<input type=\"submit\" name=\"undelete\" value=\"Воскресить\">"; }
  213. print "</td>\n";
  214. print "<td><input type=\"submit\" name=\"editswitches\" value=\"Сохранить\"></td>\n";
  215. print "</tr>\n";
  216. print "</table>\n";
  217. ?>
  218. </form>
  219. <?
  220. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php");
  221. ?>