1
0

editdevice.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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"])) { $new['ip'] = $_POST["f_ip"]; }
  41. $cur_device = get_record_sql($db_link,"SELECT * FROM devices WHERE id=".$id);
  42. //main device info
  43. if (!empty($new['ip'])) { $cur_auth = get_record_sql($db_link,"SELECT * FROM User_auth WHERE deleted=0 AND ip='".$new['ip']."'"); }
  44. if (isset($_POST["f_device_model_id"])) {
  45. $new['device_model_id'] = $_POST["f_device_model_id"]*1;
  46. $new['vendor_id'] = get_device_model_vendor($db_link,$new['device_model_id']);
  47. }
  48. if (isset($_POST["f_port_count"])) { $new['port_count'] = $sw_ports; }
  49. if (isset($_POST["f_devtype_id"])) { $new['device_type'] = $_POST["f_devtype_id"]*1; }
  50. if (isset($_POST["f_comment"])) { $new['comment'] = $_POST["f_comment"]; }
  51. if (isset($_POST["f_SN"])) { $new['SN'] = $_POST["f_SN"]; }
  52. if (isset($_POST["f_firmware"])) { $new['firmware'] = $_POST["f_firmware"]; }
  53. //snmp
  54. if (isset($_POST["f_snmp_version"])) { $new['snmp_version'] = $_POST["f_snmp_version"] * 1; }
  55. if (isset($_POST["f_community"])) { $new['community'] = substr($_POST["f_community"], 0, 50); }
  56. if (isset($_POST["f_rw_community"])) { $new['rw_community'] = substr($_POST["f_rw_community"], 0, 50); }
  57. if (isset($_POST["f_snmp3_user_rw"])) { $new['snmp3_user_rw'] = substr($_POST["f_snmp3_user_rw"], 0, 20); }
  58. if (isset($_POST["f_snmp3_user_ro"])) { $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20); }
  59. if (isset($_POST["f_snmp3_user_rw_password"])) { $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20); }
  60. if (isset($_POST["f_snmp3_user_ro_password"])) { $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20); }
  61. //acl & configuration options
  62. if (isset($_POST["f_queue_enabled"])) { $new['queue_enabled'] = $_POST["f_queue_enabled"] * 1; }
  63. if (isset($_POST["f_connected_user_only"])) { $new['connected_user_only'] = $_POST["f_connected_user_only"] * 1; }
  64. if (isset($_POST["f_dhcp"])) { $new['dhcp'] = $_POST["f_dhcp"] * 1; }
  65. if (isset($_POST["f_user_acl"])) { $new['user_acl'] = $_POST["f_user_acl"] * 1; }
  66. if ($new['device_type'] == 0 ) {
  67. $new['queue_enabled'] = 0;
  68. $new['connected_user_only'] = 1;
  69. $new['user_acl'] = 1;
  70. }
  71. //interfaces
  72. if (isset($_POST["f_wan"])) { $new['wan_int'] = $_POST["f_wan"]; }
  73. if (isset($_POST["f_lan"])) { $new['lan_int'] = $_POST["f_lan"]; }
  74. //location
  75. if (isset($_POST["f_building_id"])) { $new['building_id'] = $_POST["f_building_id"] * 1; }
  76. //access
  77. if (isset($_POST["f_login"])) { $new['login'] = $_POST["f_login"]; }
  78. if (!empty($_POST["f_password"])) {
  79. if (!preg_match('/^\*+$/', $_POST["f_password"])) {
  80. $new['password'] = crypt_string($_POST["f_password"]);
  81. }
  82. }
  83. if (isset($_POST["f_protocol"])) { $new['protocol'] = $_POST["f_protocol"]*1; }
  84. if (isset($_POST["f_control_port"])) { $new['control_port'] = $_POST["f_control_port"]*1; }
  85. if (isset($_POST["f_save_netflow"])) { $new['netflow_save'] = $_POST["f_save_netflow"]*1; }
  86. //discovery
  87. if (isset($_POST["f_discovery"])) { $new['discovery'] = $_POST["f_discovery"]; }
  88. //nagios
  89. if (isset($_POST["f_nagios"])) {
  90. $new['nagios'] = $_POST["f_nagios"] * 1;
  91. if ($new['nagios'] ==0) { $new['nagios_status']='UP'; }
  92. } else {
  93. if (!empty($cur_auth)) {
  94. $new['nagios']=0;
  95. $new['nagios_status']=$cur_auth['nagios_status'];
  96. }
  97. }
  98. update_record($db_link, "devices", "id='$id'", $new);
  99. header("Location: " . $_SERVER["REQUEST_URI"]);
  100. exit;
  101. }
  102. $device=get_record($db_link,'devices',"id=".$id);
  103. $user_info = get_record_sql($db_link,"SELECT * FROM User_list WHERE id=".$device['user_id']);
  104. unset($_POST);
  105. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  106. print_device_submenu($page_url);
  107. print_editdevice_submenu($page_url,$id,$device['device_type'],$user_info['login']);
  108. ?>
  109. <div id="contsubmenu">
  110. <?php
  111. if (!empty($_GET['status'])) {
  112. if ($_GET['status'] ==='locked') { print '<div id="msg">' . WEB_device_locked . '</div>'; }
  113. }
  114. ?>
  115. <form name="def" action="editdevice.php?id=<?php echo $id; ?>" method="post">
  116. <table class="data">
  117. <tr>
  118. <td><?php echo WEB_cell_name; ?></td>
  119. <td><?php echo WEB_cell_ip; ?></td>
  120. <td><?php echo WEB_cell_type; ?></td>
  121. <?php
  122. if ($device['device_type']<=2) { print "<td>".WEB_device_port_count."</td>"; } else { print "<td></td>"; }
  123. print "</tr>";
  124. print "<tr>\n";
  125. print "<td class='data'><a href=/admin/users/edituser.php?id=".$device['user_id'].">".$user_info['login']."</a></td>\n";
  126. print "<td class='data'>"; print_device_ip_select($db_link,'f_ip',$device['ip'],$device['user_id']); print "</td>\n";
  127. print "<td class='data'>"; print_devtype_select($db_link,'f_devtype_id',$device['device_type']); print "</td>\n";
  128. if ($device['device_type']<=2) { print "<td class='data'><input type='text' name='f_port_count' value='".$device['port_count']."' size=5></td>\n"; } else { print "<td></td>"; }
  129. print "</tr>\n";
  130. ?>
  131. </tr>
  132. <td colspan=2><?php echo WEB_cell_host_model; ?></td>
  133. <td><?php echo WEB_cell_host_firmware; ?></td>
  134. <td><?php echo WEB_cell_sn; ?></td>
  135. <?php
  136. //common information
  137. print "<tr>\n";
  138. print "<td class='data' colspan=2>"; print_device_model_select($db_link,'f_device_model_id',$device['device_model_id']); print "</td>\n";
  139. print "<td class='data' ><input type='text' name='f_firmware' value='".$device['firmware']."'></td>\n";
  140. print "<td class='data' ><input type='text' name='f_SN' value='".$device['SN']."'></td>\n";
  141. print "</tr>\n";
  142. print "<tr><td colspan=2>".WEB_location_name."</td><td colspan=2>".WEB_cell_comment."</td>";
  143. print "</tr><tr>";
  144. print "<td class='data'>"; print_building_select($db_link, 'f_building_id', $device['building_id']); print "</td>\n";
  145. print "<td class='data' colspan=3><input type='text' size=50 name='f_comment' value='".$device['comment']."'></td>\n";
  146. print "</tr>";
  147. //print gateway settings
  148. if ($device['device_type']==2) {
  149. print "<tr><td>".WEB_device_access_control."</td><td>".WEB_device_dhcp_server."</td><td>".WEB_device_queues_enabled."</td><td>".WEB_device_connected_only."</td></tr>";
  150. print "<tr>";
  151. print "<td class='data'>"; print_qa_select('f_user_acl', $device['user_acl']); print "</td>\n";
  152. print "<td class='data'>"; print_qa_select('f_dhcp', $device['dhcp']); print "</td>\n";
  153. print "<td class='data'>"; print_qa_select('f_queue_enabled', $device['queue_enabled']); print "</td>\n";
  154. print "<td class='data'>"; print_qa_select('f_connected_user_only', $device['connected_user_only']); print "</td>\n";
  155. print "</tr>\n";
  156. print "<tr><td colspan=2>"; print_url(WEB_list_l3_interfaces,"/admin/devices/edit_l3int.php?id=$id"); print "</td>";
  157. print "<td colspan=2>"; print_url(WEB_list_gateway_subnets,"/admin/devices/edit_gw_subnets.php?id=$id"); print "</td></tr>";
  158. print "<tr><td colspan=2 class='data'>"; print get_l3_interfaces($db_link,$device['id']); print "</td>";
  159. print "<td colspan=2 class='data'>"; print get_gw_subnets($db_link,$device['id']); print "</td></tr>";
  160. }
  161. //print router settings
  162. if ($device['device_type']==0) {
  163. print "<tr><td>".WEB_device_dhcp_server."</td><td></td><td></td><td></td></tr>";
  164. print "<tr>";
  165. print "<td class='data'>"; print_qa_select('f_dhcp', $device['dhcp']);
  166. print "<td class='data' colspan=4>"; print_url(WEB_list_l3_networks,"/admin/devices/edit_gw_subnets.php?id=$id");
  167. print "</tr>\n";
  168. }
  169. //for all active network devices
  170. if ($device['device_type']<=2) {
  171. //cli access settings
  172. 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>";
  173. print "<tr>";
  174. print "<td class='data'><input type='text' name='f_login' value=".$device['login']."></td>\n";
  175. print "<td class='data'><input type='text' name='f_password' value='********'></td>\n";
  176. print "<td class='data'>"; print_control_proto_select('f_protocol', $device['protocol']); print "</td>\n";
  177. print "<td class='data'><input type='text' name='f_control_port' value=".$device['control_port']."></td>\n";
  178. print "</tr>";
  179. //snmp settings & discovery & nagios
  180. print "<tr><td>".WEB_snmp_version."</td><td>".WEB_network_discovery."</td><td>".WEB_nagios."</td><td>".WEB_device_save_netflow."</td></tr>";
  181. print "<tr><td class='data'>"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
  182. print "<td class='data'>"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
  183. print "<td class='data'>"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
  184. print "<td class='data'>"; print_qa_select('f_save_netflow', $device['netflow_save']); print "</td>\n";
  185. print "</tr>";
  186. if ($device['snmp_version'] ==3) {
  187. print "<tr><td>".WEB_snmp_v3_user_ro."</td><td>".WEB_snmp_v3_user_rw."</td><td>".WEB_snmp_v3_ro_password."</td><td>".WEB_snmp_v3_rw_password."</td><td></td>";
  188. print "</tr><tr>";
  189. print "<td class='data'><input type='text' name='f_snmp3_user_ro' value=".$device['snmp3_user_ro']."></td>\n";
  190. print "<td class='data'><input type='text' name='f_snmp3_user_rw' value=".$device['snmp3_user_rw']."></td>\n";
  191. print "<td class='data'><input type='text' name='f_snmp3_user_ro_password' value=".$device['snmp3_user_ro_password']."></td>\n";
  192. print "<td class='data'><input type='text' name='f_snmp3_user_rw_password' value=".$device['snmp3_user_rw_password']."></td>\n";
  193. print "</tr>\n";
  194. }
  195. print "<tr><td>".WEB_snmp_community_ro."</td><td>".WEB_snmp_community_rw."</td><td></td><td></td></tr>";
  196. print "<tr>\n";
  197. print "<td class='data'><input type='text' name='f_community' value=".$device['community']."></td>\n";
  198. print "<td class='data'><input type='text' name='f_rw_community' value=".$device['rw_community']."></td>\n";
  199. print "<td><button name='mac_walk' onclick=\"window.open('mactable.php?id=" . $id . "')\">".WEB_device_mac_table."</button>";
  200. print "<button name='port_walk' onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">".WEB_device_walk_port_list."</button></td>";
  201. print "<td></td>";
  202. print "</tr>";
  203. }
  204. //only snmp for other devices
  205. if ($device['device_type']>2) {
  206. print "<tr><td>".WEB_snmp_version."</td><td>".WEB_snmp_community_ro."</td><td>".WEB_snmp_community_rw."</td><td></td></tr>";
  207. print "<tr><td class='data'>"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
  208. print "<td class='data'><input type='text' name='f_community' value=".$device['community']."></td>\n";
  209. print "<td class='data'><input type='text' name='f_rw_community' value=".$device['rw_community']."></td>\n";
  210. print "<td></td></tr>";
  211. if ($device['snmp_version'] ==3) {
  212. print "<tr><td>".WEB_snmp_v3_user_ro."</td><td>".WEB_snmp_v3_user_rw."</td><td>".WEB_snmp_v3_ro_password."</td><td>".WEB_snmp_v3_rw_password."</td><td></td>";
  213. print "</tr><tr>";
  214. print "<td class='data'><input type='text' name='f_snmp3_user_ro' value=".$device['snmp3_user_ro']."></td>\n";
  215. print "<td class='data'><input type='text' name='f_snmp3_user_rw' value=".$device['snmp3_user_rw']."></td>\n";
  216. print "<td class='data'><input type='text' name='f_snmp3_user_ro_password' value=".$device['snmp3_user_ro_password']."></td>\n";
  217. print "<td class='data'><input type='text' name='f_snmp3_user_rw_password' value=".$device['snmp3_user_rw_password']."></td>\n";
  218. print "<td></td></tr>\n";
  219. }
  220. }
  221. //save button
  222. print "<tr><td colspan=3>".$device['ip']."::". get_device_model_name($db_link,$device['device_model_id'])."</td><td align=right><input type='submit' name='editdevice' value='".WEB_btn_save."'></td></tr>";
  223. print "</table>\n";
  224. ?>
  225. </form>
  226. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php"); ?>