editdevice.php 17 KB

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