Sfoglia il codice sorgente

add simple device structure

rajven 4 anni fa
parent
commit
0023813e44
4 ha cambiato i file con 41 aggiunte e 106 eliminazioni
  1. 39 103
      html/admin/devices/index-tree.php
  2. BIN
      html/img/switch.png
  3. 2 1
      html/inc/common.php
  4. 0 2
      html/inc/header.php

+ 39 - 103
html/admin/devices/index-tree.php

@@ -1,119 +1,55 @@
 <?php
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/devtypesfilter.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/buildingfilter.php");
-$default_sort='device_name';
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
-
-if (isset($_POST["create"])) {
-    $fname = $_POST["newswitches"];
-    if ($fname) {
-        global $snmp_default_version;
-        global $snmp_default_community;
-        $new['device_name'] = $fname;
-        $new['community'] = $snmp_default_community;
-        $new['snmp_version'] = $snmp_default_version;
-        $new_id=insert_record($db_link, "devices", $new);
-        LOG_INFO($db_link, "Created new device device_name=$fname");
-        unset($_POST);
-        header("location: editdevice.php?id=$new_id");
-    }
-}
-
-if (isset($_POST["remove"])) {
-    $fid = $_POST["fid"];
-    foreach ($fid as $key => $val) {
-        if ($val) {
-            LOG_INFO($db_link, "Delete device id: $val");
-            unbind_ports($db_link, $val);
-            delete_record($db_link, "connections", "device_id=$val");
-            delete_record($db_link, "device_ports", "device_id=$val");
-            $new['deleted'] = 1;
-            update_record($db_link, "devices", "id='$val'", $new);
-        }
-    }
-    header("Location: " . $_SERVER["REQUEST_URI"]);
-}
 unset($_POST);
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
 print_device_submenu($page_url);
-
-$sort_sql=" ORDER BY device_name";
-if (!empty($sort_field) and !empty($order)) { $sort_sql = " ORDER BY $sort_field $order"; }
-
 ?>
 <div id="cont">
 <br>
-<form name="def" action="index.php" method="post">
-<table class="data">
-<tr class="info" align="center">
-<td class="info" colspan=3 > Тип оборудования: </td>
-<td class="info" colspan=2 > <?php  print_devtypes_select($db_link, "devtypes", $f_devtype_id); ?>
-<td class="info" >Показать оборудование из</td>
-<td class="info" > <?php  print_building_select($db_link, "building_id", $f_building_id); ?></td>
-<td class="info" colspan=3> <input type="submit" name="apply" value="Apply"></td>
-</tr>
-<tr align="center">
-<td><input type="checkbox" onClick="checkAll(this.checked);"></td>
-<td><b><a href=index.php?sort=id&order=<?php print $new_order; ?>>id</a></b></td>
-<td><b><a href=index.php?sort=device_type&order=<?php print $new_order; ?>>Тип</a></b></td>
-<td><b><a href=index.php?sort=device_name&order=<?php print $new_order; ?>>Название</a></b></td>
-<td><b><a href=index.php?sort=ip&order=<?php print $new_order; ?>>IP</a></b></td>
-<td><b><a href=index.php?sort=device_model_id&order=<?php print $new_order; ?>>Модель</a></b></td>
-<td><b><a href=index.php?sort=building_id&order=<?php print $new_order; ?>>Расположен</a></b></td>
-<td><b>Портов</b></td>
-<td><b>Nagios</b></td>
-<td><b>Discavery</b></td>
-</tr>
-<?
-$filter = '';
-if ($f_building_id > 0) { $filter .= ' and building_id=' . $f_building_id; }
-if ($f_devtype_id > 0) { $filter .= ' and device_type=' . $f_devtype_id; }
+<?php
+
+function print_child($device_id,$hash) 
+{
+foreach ($hash as $device) {
+    if (!isset($device['parent_id'])) { continue; }
+    if ($device['parent_id'] !== $device_id) { continue; }
+    print '<ul><li class="jstree-node" id="'.$device['id'].'">';
+//    print $device['parent_port'].'->'.$device['uplink'].'&nbsp';
+    print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']);
+    print_child($device['id'],$hash);
+    print '</li></ul>';
+    }
+}
 
 $dSQL = 'SELECT * FROM devices WHERE deleted=0 '.$filter.' '.$sort_sql;
 $switches = get_records_sql($db_link,$dSQL);
+$dev_hash = NULL;
 foreach ($switches as $row) {
-    print "<tr align=center>\n";
-    $cl = "data";
-    if (isset($row['nagios_status'])) {
-        $cl = 'shutdown';
-        if ($row['nagios_status'] == 'UP') { $cl = 'up'; }
-        }
-    print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
-    print "<td class=\"$cl\"><input type=hidden name=\"id\" value=".$row['id'].">".$row['id']."</td>\n";
-    print "<td class=\"$cl\">".get_devtype_name($db_link,$row['device_type'])."</td>\n";
-    print "<td class=\"$cl\" align=left><a href=editdevice.php?id=".$row['id'].">" . $row['device_name'] . "</a></td>\n";
-    if (isset($row['user_id']) and $row['user_id']>0) {
-        print "<td class=\"$cl\"><a href=/admin/users/edituser.php?id=".$row['user_id'].">".$row['ip']."</a></td>\n";
-        } else {
-        print "<td class=\"$cl\">".$row['ip']."</td>\n";
-        }
-    print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . get_device_model($db_link,$row['device_model_id']) . "</td>\n";
-    print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']) . "(" . $row['comment'] . ")</td>\n";
-    print "<td class=\"$cl\">".$row['port_count']."</td>\n";
-    print "<td class=\"$cl\">" . get_qa($row['nagios']) . "</td>\n";
-    print "<td class=\"$cl\">" . get_qa($row['discovery']) . "</td>\n";
+$dev_id=$row['id'];
+$dev_hash[$dev_id]['id']=$dev_id;
+$dev_hash[$dev_id]['name']=$row['device_name'];
+$pSQL = 'SELECT * FROM device_ports WHERE uplink = 1 and device_id='.$dev_id;
+$uplink = get_record_sql($db_link,$pSQL);
+if (empty($uplink)) { continue; }
+if (empty($uplink['target_port_id'])) { continue; }
+$dev_hash[$dev_id]['uplink']=$uplink['port_name'];
+$parentSQL='SELECT * FROM device_ports WHERE device_ports.id='.$uplink['target_port_id'];
+$parent=get_record_sql($db_link,$parentSQL);
+$dev_hash[$dev_id]['parent_id']=$parent['device_id'];
+$dev_hash[$dev_id]['parent_port']=$parent['port_name'];
 }
-?>
-</table>
-<table class="data">
-<tr align=left>
-<td>Название <input type=text name=newswitches value="Unknown"></td>
-<td><input type="submit" name="create" value="Добавить"></td>
-<td align="right"><input type="submit" name="remove" value="Удалить"></td>
-</tr>
-</table>
-</form>
-<table class="data">
-<tr>
-<td>Device status</td>
-</tr>
-<tr>
-<td class="shutdown">Down</td>
-<td class="up">Online</td>
-<tr>
-</table>
-<?
+
+print '<div id="html1">';
+foreach ($dev_hash as $device) {
+if (isset($device['parent_id'])) { continue; }
+print '<ul><li>';
+print_url($device['name'],'/admin/devices/editdevice.php?id='.$device['id']);
+print_child($device['id'],$dev_hash);
+print '</li>';
+print '</ul>';
+}
+print '</div>';
+
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
 ?>

BIN
html/img/switch.png


+ 2 - 1
html/inc/common.php

@@ -552,6 +552,7 @@ print "<div id='submenu'>\n";
 print_submenu_url('Активное сетевое оборудование','/admin/devices/index.php',$current_page,0);
 print_submenu_url('Пассивное оборудование','/admin/devices/index-passive.php',$current_page,0);
 print_submenu_url('Расположение','/admin/devices/building.php',$current_page,0);
+print_submenu_url('Структура','/admin/devices/index-tree.php',$current_page,0);
 print_submenu_url('Удалённые','/admin/devices/deleted.php',$current_page,0);
 print_submenu_url('Модели устройств','/admin/devices/devmodels.php',$current_page,0);
 print_submenu_url('Vendors','/admin/devices/devvendors.php',$current_page,0);
@@ -952,7 +953,7 @@ function print_device_port_select($db, $field_name, $device_id, $target_id)
     if (! isset($device_id)) {
         $device_id = 0;
     }
-    $d_sql = "SELECT D.device_name, DP.port, DP.device_id, DP.id, DP.ifName FROM devices AS D, device_ports AS DP WHERE D.deleted=0 and D.id = DP.device_id AND (DP.device_id<>$device_id or DP.id=$target_id) and (DP.id not in (select target_port_id FROM device_ports WHERE target_port_id>0 and target_port_id<>$target_id)) order by D.device_name,DP.port";
+    $d_sql = "SELECT D.device_name, DP.port, DP.device_id, DP.id, DP.ifName FROM devices AS D, device_ports AS DP WHERE D.deleted=0 and D.id = DP.device_id AND (DP.device_id<>$device_id or DP.id=$target_id) and (DP.id not in (select target_port_id FROM device_ports WHERE target_port_id>0 and target_port_id<>$target_id)) ORDER BY D.device_name,DP.port";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item('Empty',0,$target_id);
     while (list ($f_name, $f_port, $f_device_id, $f_target_id, $f_ifname) = mysqli_fetch_array($t_device)) {

+ 0 - 2
html/inc/header.php

@@ -6,8 +6,6 @@
 <script src="/js/jq/jquery.min.js"></script>
 <link href="/js/select2/css/select2.min.css" rel="stylesheet"/>
 <script src="/js/select2/js/select2.min.js"></script>
-<link rel="stylesheet" href="/js/jstree/themes/default/style.min.css" />
-<script src="/js/jstree/jstree.min.js"></script>
 <meta http-equiv="content-type" content="application/xhtml+xml" />
 <meta charset="UTF-8" />