editdevice.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. if (isset($_POST["editdevice"]) 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. $$d_ports = get_single_field($db_link,$sSQL);
  13. if ($d_ports != $sw_ports) {
  14. LOG_DEBUG($db_link, "Device id: $id changed port count!");
  15. if ($sw_ports > $d_ports) {
  16. $start_port = $d_ports + 1;
  17. LOG_DEBUG($db_link, "Device id: $id add connection for port from $start_port to $sw_ports.");
  18. for ($port = $start_port; $port <= $sw_ports; $port++) {
  19. $new['device_id'] = $id;
  20. $new['snmp_index'] = $port;
  21. $new['port'] = $port;
  22. insert_record($db_link, "device_ports", $new);
  23. }
  24. }
  25. if ($sw_ports < $d_ports) {
  26. LOG_DEBUG($db_link, "Device id: $id remove connection for port from $d_ports to $sw_ports");
  27. for ($port = $d_ports; $port > $sw_ports; $port--) {
  28. $port_id = get_id_record($db_link, 'device_ports', "device_id='" . $id . "' and port='" . $port . "'");
  29. if ($port_id) {
  30. delete_record($db_link, "device_ports", "id='" . $port_id . "'");
  31. run_sql($db_link, "DELETE FROM connections WHERE port_id='" . $port_id . "'");
  32. } else {
  33. LOG_DEBUG($db_link, "Device id: $id port_id not found for port: $port!");
  34. }
  35. }
  36. }
  37. }
  38. unset($new);
  39. if (isset($_POST["f_ip"])) {
  40. $new['ip'] = $_POST["f_ip"];
  41. $new['ip_int'] = ip2long($new['ip']);
  42. }
  43. $cur_device = get_record_sql($db_link, "SELECT * FROM devices WHERE id=" . $id);
  44. //main device info
  45. if (!empty($new['ip'])) {
  46. $cur_auth = get_record_sql($db_link, "SELECT * FROM User_auth WHERE deleted=0 AND ip='" . $new['ip'] . "'");
  47. }
  48. if (isset($_POST["f_device_model_id"])) {
  49. $new['device_model_id'] = $_POST["f_device_model_id"] * 1;
  50. $new['vendor_id'] = get_device_model_vendor($db_link, $new['device_model_id']);
  51. }
  52. if (isset($_POST["f_port_count"])) {
  53. $new['port_count'] = $sw_ports;
  54. }
  55. if (isset($_POST["f_devtype_id"])) {
  56. $new['device_type'] = $_POST["f_devtype_id"] * 1;
  57. }
  58. if (isset($_POST["f_comment"])) {
  59. $new['comment'] = $_POST["f_comment"];
  60. }
  61. if (isset($_POST["f_SN"])) {
  62. $new['SN'] = $_POST["f_SN"];
  63. }
  64. if (isset($_POST["f_firmware"])) {
  65. $new['firmware'] = $_POST["f_firmware"];
  66. }
  67. //snmp
  68. if (isset($_POST["f_snmp_version"])) {
  69. $new['snmp_version'] = $_POST["f_snmp_version"] * 1;
  70. }
  71. if (isset($_POST["f_community"])) {
  72. $new['community'] = substr($_POST["f_community"], 0, 50);
  73. }
  74. if (isset($_POST["f_snmp3_auth_proto"])) {
  75. $new['snmp3_auth_proto'] = trim(substr($_POST["f_snmp3_auth_proto"], 0, 10));
  76. }
  77. if (isset($_POST["f_snmp3_priv_proto"])) {
  78. $new['snmp3_priv_proto'] = trim(substr($_POST["f_snmp3_priv_proto"], 0, 10));
  79. }
  80. if (isset($_POST["f_rw_community"])) {
  81. $new['rw_community'] = substr($_POST["f_rw_community"], 0, 50);
  82. }
  83. if (isset($_POST["f_snmp3_user_rw"])) {
  84. $new['snmp3_user_rw'] = substr($_POST["f_snmp3_user_rw"], 0, 20);
  85. }
  86. if (isset($_POST["f_snmp3_user_ro"])) {
  87. $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20);
  88. }
  89. if (isset($_POST["f_snmp3_user_rw_password"])) {
  90. $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20);
  91. }
  92. if (isset($_POST["f_snmp3_user_ro_password"])) {
  93. $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20);
  94. }
  95. //acl & configuration options
  96. if (isset($_POST["f_queue_enabled"])) {
  97. $new['queue_enabled'] = $_POST["f_queue_enabled"] * 1;
  98. }
  99. if (isset($_POST["f_connected_user_only"])) {
  100. $new['connected_user_only'] = $_POST["f_connected_user_only"] * 1;
  101. }
  102. if (isset($_POST["f_dhcp"])) {
  103. $new['dhcp'] = $_POST["f_dhcp"] * 1;
  104. }
  105. if (isset($_POST["f_user_acl"])) {
  106. $new['user_acl'] = $_POST["f_user_acl"] * 1;
  107. }
  108. //interfaces
  109. if (isset($_POST["f_wan"])) {
  110. $new['wan_int'] = $_POST["f_wan"];
  111. }
  112. if (isset($_POST["f_lan"])) {
  113. $new['lan_int'] = $_POST["f_lan"];
  114. }
  115. //location
  116. if (isset($_POST["f_building_id"])) {
  117. $new['building_id'] = $_POST["f_building_id"] * 1;
  118. }
  119. //access
  120. if (isset($_POST["f_login"])) {
  121. $new['login'] = $_POST["f_login"];
  122. }
  123. if (!empty($_POST["f_password"])) {
  124. if (!preg_match('/^\*+$/', $_POST["f_password"])) {
  125. $new['password'] = crypt_string($_POST["f_password"]);
  126. }
  127. }
  128. if (isset($_POST["f_protocol"])) {
  129. $new['protocol'] = $_POST["f_protocol"] * 1;
  130. }
  131. if (isset($_POST["f_control_port"])) {
  132. $new['control_port'] = $_POST["f_control_port"] * 1;
  133. }
  134. if (isset($_POST["f_save_netflow"])) {
  135. $new['netflow_save'] = $_POST["f_save_netflow"] * 1;
  136. }
  137. //discovery
  138. if (isset($_POST["f_discovery"])) {
  139. $new['discovery'] = $_POST["f_discovery"];
  140. }
  141. //nagios
  142. if (isset($_POST["f_nagios"])) {
  143. $new['nagios'] = $_POST["f_nagios"] * 1;
  144. if ($new['nagios'] == 0) {
  145. $new['nagios_status'] = 'UP';
  146. }
  147. } else {
  148. if (!empty($cur_auth)) {
  149. $new['nagios'] = 0;
  150. $new['nagios_status'] = $cur_auth['nagios_status'];
  151. }
  152. }
  153. if ($new['device_type'] == 0 or $new['protocol']<0) {
  154. $new['queue_enabled'] = 0;
  155. $new['connected_user_only'] = 1;
  156. $new['user_acl'] = 0;
  157. }
  158. update_record($db_link, "devices", "id='$id'", $new);
  159. header("Location: " . $_SERVER["REQUEST_URI"]);
  160. exit;
  161. }
  162. $device = get_record($db_link, 'devices', "id=" . $id);
  163. $user_info = get_record_sql($db_link, "SELECT * FROM User_list WHERE id=" . $device['user_id']);
  164. unset($_POST);
  165. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  166. print_device_submenu($page_url);
  167. print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['login']);
  168. ?>
  169. <div id="contsubmenu">
  170. <?php
  171. if (!empty($_GET['status'])) {
  172. if ($_GET['status'] === 'locked') {
  173. print '<div id="msg">' . WEB_device_locked . '</div>';
  174. }
  175. }
  176. ?>
  177. <form name="def" action="editdevice.php?id=<?php echo $id; ?>" method="post">
  178. <table class="data">
  179. <tr>
  180. <td><?php echo WEB_cell_name; ?></td>
  181. <td><?php echo WEB_cell_ip; ?></td>
  182. <td><?php echo WEB_cell_type; ?></td>
  183. <?php
  184. if ($device['device_type'] <= 2) {
  185. print "<td>" . WEB_device_port_count . "</td>";
  186. } else {
  187. print "<td></td>";
  188. }
  189. print "</tr>";
  190. print "<tr>\n";
  191. print "<td class='data'><a href=/admin/users/edituser.php?id=" . $device['user_id'] . ">" . $user_info['login'] . "</a></td>\n";
  192. print "<td class='data'>";
  193. print_device_ip_select($db_link, 'f_ip', $device['ip'], $device['user_id']);
  194. print "</td>\n";
  195. print "<td class='data'>";
  196. print_devtype_select($db_link, 'f_devtype_id', $device['device_type']);
  197. print "</td>\n";
  198. if ($device['device_type'] <= 2) {
  199. print "<td class='data'><input type='text' name='f_port_count' value='" . $device['port_count'] . "' size=5></td>\n";
  200. } else {
  201. print "<td></td>";
  202. }
  203. print "</tr>\n";
  204. ?>
  205. </tr>
  206. <td colspan=2><?php echo WEB_cell_host_model; ?></td>
  207. <td><?php echo WEB_cell_host_firmware; ?></td>
  208. <td><?php echo WEB_cell_sn; ?></td>
  209. <?php
  210. //common information
  211. print "<tr>\n";
  212. print "<td class='data' colspan=2>";
  213. print_device_model_select($db_link, 'f_device_model_id', $device['device_model_id']);
  214. print "</td>\n";
  215. print "<td class='data' ><input type='text' name='f_firmware' value='" . $device['firmware'] . "'></td>\n";
  216. print "<td class='data' ><input type='text' name='f_SN' value='" . $device['SN'] . "'></td>\n";
  217. print "</tr>\n";
  218. print "<tr><td colspan=2>" . WEB_location_name . "</td><td colspan=2>" . WEB_cell_comment . "</td>";
  219. print "</tr><tr>";
  220. print "<td class='data'>";
  221. print_building_select($db_link, 'f_building_id', $device['building_id']);
  222. print "</td>\n";
  223. print "<td class='data' colspan=3><input type='text' size=50 name='f_comment' value='" . $device['comment'] . "'></td>\n";
  224. print "</tr>";
  225. //print gateway settings
  226. if ($device['device_type'] == 2) {
  227. print "<tr><td>"; print_url(WEB_device_access_control,"/admin/devices/edit_gw_instances.php?id=$id"); print "</td><td>" . WEB_device_dhcp_server . "</td><td>" . WEB_device_queues_enabled . "</td><td>" . WEB_device_connected_only . "</td></tr>";
  228. print "<tr>";
  229. print "<td class='data'>";
  230. print_qa_select('f_user_acl', $device['user_acl']);
  231. print "</td>\n";
  232. print "<td class='data'>";
  233. print_qa_select('f_dhcp', $device['dhcp']);
  234. print "</td>\n";
  235. print "<td class='data'>";
  236. print_qa_select('f_queue_enabled', $device['queue_enabled']);
  237. print "</td>\n";
  238. print "<td class='data'>";
  239. print_qa_select('f_connected_user_only', $device['connected_user_only']);
  240. print "</td>\n";
  241. print "</tr>\n";
  242. print "<tr><td colspan=2>";
  243. print_url(WEB_list_l3_interfaces, "/admin/devices/edit_l3int.php?id=$id");
  244. print "</td>";
  245. print "<td colspan=2>";
  246. print_url(WEB_list_gateway_subnets, "/admin/devices/edit_gw_subnets.php?id=$id");
  247. print "</td></tr>";
  248. print "<tr><td colspan=2 class='data'>";
  249. print get_l3_interfaces($db_link, $device['id']);
  250. print "</td>";
  251. print "<td colspan=2 class='data'>";
  252. print get_gw_subnets($db_link, $device['id']);
  253. print "</td></tr>";
  254. }
  255. //print router settings
  256. if ($device['device_type'] == 0) {
  257. print "<tr><td>" . WEB_device_dhcp_server . "</td><td></td><td></td><td></td></tr>";
  258. print "<tr>";
  259. print "<td class='data'>";
  260. print_qa_select('f_dhcp', $device['dhcp']);
  261. print "<td class='data' colspan=4>";
  262. print_url(WEB_list_l3_networks, "/admin/devices/edit_gw_subnets.php?id=$id");
  263. print "</tr>\n";
  264. }
  265. //for all active network devices
  266. if ($device['device_type'] <= 2) {
  267. //cli access settings
  268. print "<tr><td>" . WEB_cell_login . "</td><td>" . WEB_cell_password . "</td><td>" . WEB_cell_control_proto . "</td><td>" . WEB_cell_control_port . "</td></tr>";
  269. print "<tr>";
  270. print "<td class='data'><input type='text' name='f_login' value=" . $device['login'] . "></td>\n";
  271. print "<td class='data'><input type='text' name='f_password' value='********'></td>\n";
  272. print "<td class='data'>";
  273. print_control_proto_select('f_protocol', $device['protocol']);
  274. print "</td>\n";
  275. print "<td class='data'><input type='text' name='f_control_port' value=" . $device['control_port'] . "></td>\n";
  276. print "</tr>";
  277. //snmp settings & discovery & nagios
  278. print "<tr><td>" . WEB_network_discovery . "</td><td>" . WEB_nagios . "</td><td>" . WEB_device_save_netflow . "</td><td></td></tr>";
  279. print "<tr>";
  280. print "<td class='data'>";
  281. print_qa_select('f_discovery', $device['discovery']);
  282. print "</td>\n";
  283. print "<td class='data'>";
  284. print_qa_select('f_nagios', $device['nagios']);
  285. print "</td>\n";
  286. print "<td class='data'>";
  287. print_qa_select('f_save_netflow', $device['netflow_save']);
  288. print "</td>\n";
  289. print "<td class='data'></td></tr>";
  290. }
  291. if ($device['snmp_version'] == 3) {
  292. //snmp settings
  293. print "<tr><td>" . WEB_snmp_version . "</td><td>" . WEB_snmp_v3_auth_proto . "</td><td>" . WEB_snmp_v3_priv_proto . "</td><td></td></tr>";
  294. print "<tr><td class='data'>";
  295. print_snmp_select('f_snmp_version', $device['snmp_version']);
  296. print "</td>\n";
  297. print "<td class='data'>";
  298. print_snmp_auth_proto_select('f_snmp3_auth_proto', $device['snmp3_auth_proto']);
  299. print "</td>\n";
  300. print "<td class='data'>";
  301. print_snmp_priv_proto_select('f_snmp3_priv_proto', $device['snmp3_priv_proto']);
  302. print "</td>\n";
  303. print "<td class='data'></td>";
  304. print "</tr>";
  305. print "<tr><td>" . WEB_snmp_v3_user_ro . "</td><td>" . WEB_snmp_v3_ro_password . "</td><td>" . WEB_snmp_v3_user_rw . "</td><td>" . WEB_snmp_v3_rw_password . "</td><td></td>";
  306. print "</tr><tr>";
  307. print "<td class='data'><input type='text' name='f_snmp3_user_ro' value=" . $device['snmp3_user_ro'] . "></td>\n";
  308. print "<td class='data'><input type='text' name='f_snmp3_user_ro_password' minlength='8' value=" . $device['snmp3_user_ro_password'] . "></td>\n";
  309. print "<td class='data'><input type='text' name='f_snmp3_user_rw' value=" . $device['snmp3_user_rw'] . "></td>\n";
  310. print "<td class='data'><input type='text' name='f_snmp3_user_rw_password' minlength='8' value=" . $device['snmp3_user_rw_password'] . "></td>\n";
  311. print "</tr>\n";
  312. } else {
  313. print "<tr><td>" . WEB_snmp_version . "</td><td></td><td></td><td></td></tr>";
  314. print "<tr><td class='data'>";
  315. print_snmp_select('f_snmp_version', $device['snmp_version']);
  316. print "</td><td class='data' colspan=3></td>\n";
  317. print "</tr>";
  318. if ($device['snmp_version'] > 0) {
  319. print "<tr><td>" . WEB_snmp_community_ro . "</td><td>" . WEB_snmp_community_rw . "</td><td></td><td></td></tr>";
  320. print "<tr>\n";
  321. print "<td class='data'><input type='text' name='f_community' value=" . $device['community'] . "></td>\n";
  322. print "<td class='data'><input type='text' name='f_rw_community' value=" . $device['rw_community'] . "></td>\n";
  323. print "<td class='data' colspan=2></td>";
  324. print "</tr>";
  325. }
  326. }
  327. //save button
  328. if ($device['snmp_version'] > 0) {
  329. print "<tr><td colspan=2>" . $device['ip'] . "::" . get_device_model_name($db_link, $device['device_model_id']) . "</td>";
  330. print "<td><button name='mac_walk' onclick=\"window.open('mactable.php?id=" . $id . "')\">" . WEB_device_mac_table . "</button>";
  331. print "<button name='port_walk' onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">" . WEB_device_walk_port_list . "</button></td>";
  332. } else {
  333. print "<tr><td colspan=3>" . $device['ip'] . "::" . get_device_model_name($db_link, $device['device_model_id']) . "</td>";
  334. }
  335. print "<td align=right><input type='submit' id='editdevice' name='editdevice' value='" . WEB_btn_save . "'></td></tr>";
  336. print "</table>\n";
  337. ?>
  338. </form>
  339. <script>
  340. document.getElementById('f_devtype_id').addEventListener('change', function(event) {
  341. const buttonApply = document.getElementById('editdevice');
  342. buttonApply.click();
  343. });
  344. document.getElementById('f_snmp_version').addEventListener('change', function(event) {
  345. const buttonApply = document.getElementById('editdevice');
  346. buttonApply.click();
  347. });
  348. </script>
  349. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.simple.php"); ?>