Changeset 738 for trunk/Modules/NetworkTopology
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- Location:
- trunk/Modules/NetworkTopology
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkTopology/NetworkTopology.php
r586 r738 7 7 var $ParentClass = 'PagePortal'; 8 8 var $TopHostName = 'NIX-ROUTER'; 9 9 10 10 function Show() 11 11 { 12 12 if(count($this->System->PathItems) > 1) 13 { 13 { 14 14 if($this->System->PathItems[1] == 'topologie.png') return($this->ShowImage()); 15 15 else return(PAGE_NOT_FOUND); 16 16 17 17 } else return($this->ShowOverview()); 18 18 } 19 19 20 20 function ShowImage() 21 21 { … … 31 31 $width = $item[0]; 32 32 $height = $item[1]; 33 33 34 34 $spacex = 32; 35 35 $spacey = 68; 36 36 $halfx = $spacex / 2; 37 37 $halfy = $spacey / 2; 38 // Načtení pomocných obrázků 38 // Načtení pomocných obrázků 39 39 $im_comp = imagecreatefrompng(dirname(__FILE__).'/images/comp.png'); 40 40 $im_dev = imagecreatefrompng(dirname(__FILE__).'/images/device.png'); … … 47 47 $blue = imagecolorallocate($im, 100, 100, 255); 48 48 $gray = imagecolorallocate($im, 160, 160, 160); 49 49 50 50 //$DbResult = $Database->query("SELECT * FROM hosts, NetworkTopology WHERE host = id AND used=1"); 51 51 $DbResult = $this->Database->query('SELECT NetworkTopology.*, NetworkTopology.Host AS Id, '. … … 98 98 } 99 99 } 100 100 101 101 // === Sestavení výsledného souboru ============================================ 102 102 if($debug == 0) 103 103 { 104 104 Header("Content-type: image/png"); 105 Header("Cache-Control: no-cache"); 105 Header("Cache-Control: no-cache"); // Dynamický graf, nekešovat 106 106 imagepng($im); 107 107 imagedestroy($im); … … 111 111 return(''); 112 112 } 113 113 114 114 function ShowOverview() 115 115 { … … 142 142 $this->Dependencies = array('Network'); 143 143 } 144 144 145 145 function DoInstall() 146 146 { 147 147 } 148 148 149 149 function DoUnInstall() 150 150 { -
trunk/Modules/NetworkTopology/topologie-img.php
r548 r738 9 9 10 10 // === Zpětné vyvážení stromu do hloubky ======================================= 11 function balance($id, $level, &$vlast, &$vleft, &$vpred, &$vfirst, &$vnext, &$tbound, &$width, $limit) 11 function balance($id, $level, &$vlast, &$vleft, &$vpred, &$vfirst, &$vnext, &$tbound, &$width, $limit) 12 12 { 13 13 global $debug, $bbound; 14 14 15 15 if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0; 16 if($i = $vfirst[$id]) 16 if($i = $vfirst[$id]) 17 17 { 18 18 //if ($debug==2) echo $id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n"; 19 if (($vlast[$id] > 0) && ($vleft[$id] > $vleft[$vlast[$id]])) 19 if (($vlast[$id] > 0) && ($vleft[$id] > $vleft[$vlast[$id]])) 20 20 { 21 21 $diff=$vleft[$id]-$vleft[$vlast[$id]]; 22 22 $i=$vfirst[$id]; 23 if ($vleft[$id] >= $tbound[$level]) 23 if ($vleft[$id] >= $tbound[$level]) 24 24 { 25 25 $tbound[$level] = $vleft[$id] + 2; … … 28 28 } else { 29 29 $diff=0; 30 if ($vpred[$i]&&($vleft[$i]<=$vleft[$vpred[$i]])) 30 if ($vpred[$i]&&($vleft[$i]<=$vleft[$vpred[$i]])) 31 31 { 32 32 $diff=$vleft[$i]-$vleft[$vpred[$i]]+2; 33 33 } else $i = 0; 34 34 } 35 while ($i>0) 35 while ($i>0) 36 36 { 37 37 $vleft[$i]+=$diff; … … 45 45 // === Generování rovinné stromové struktury =================================== 46 46 function gentree($mode) // depth-first algorithm 47 { 47 { 48 48 global $debug, $TopHostName, $Database; 49 49 50 50 // --- Inicializace ---------------------------------------------------------- 51 51 $tbound = array(); // Hranice pozic jednotlivých úrovní … … 58 58 $vtop = array(); // Pozice prvku shora 59 59 $vpred = array(); // Vedlejsi prvek na řádku 60 60 61 61 $index = 0; // Index aktuálního prvku 62 62 $curr = 0; // Aktuální prvek … … 68 68 $position[$level] = 0; // Aktuální pozice prvku na dané úrovni 69 69 $count[$level] = 0; // Počet prvků na dané úrovni 70 70 71 71 $maxindex = 0; 72 72 $tbound[$level] = 0; 73 73 $tranger[$level] = 0; 74 74 75 75 // --- Hlavní cyklus --------------------------------------------------------- 76 do 76 do 77 77 { 78 78 // --- Proveď databázový dotaz ----------------------------------------------- 79 79 $query = 'SELECT * FROM hosts WHERE used=1 AND '; 80 if ($level == 0) 81 { 82 $query .= 'name = "'.$TopHostName.'" ORDER BY id'; 83 } else 80 if ($level == 0) 81 { 82 $query .= 'name = "'.$TopHostName.'" ORDER BY id'; 83 } else 84 84 { 85 85 $query .= ' parent = '.$parent[$level].' ORDER BY id'; … … 91 91 $item = $DbResult->fetch_array(); 92 92 //print_r($item); 93 if($item) 93 if($item) 94 94 { 95 95 // --- Zpracování položky z DB ----------------------------------------------- 96 if($position[$level] > 0) 96 if($position[$level] > 0) 97 97 { 98 98 $vnext[$curr] = $item['id']; // Neprvní položka, nastav předchozí … … 114 114 $DbResult = $Database->query('SELECT COUNT(*) FROM hosts WHERE used=1 AND parent = '.$curr); 115 115 $childcnt = $DbResult->fetch_array(); 116 if ($childcnt[0] > 0) 117 { 116 if ($childcnt[0] > 0) 117 { 118 118 // Uzelový vrchol 119 if(array_key_exists($level + 1, $tbound)) 119 if(array_key_exists($level + 1, $tbound)) 120 120 if($tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = $tbound[$level + 1]; 121 121 } 122 122 $tbound[$level] = $vleft[$curr] + 2; 123 123 if ($vleft[$curr] > $width) $width = $vleft[$curr]; 124 if ($childcnt[0] > 0) 124 if ($childcnt[0] > 0) 125 125 { 126 126 $level++; … … 130 130 $count[$level] = 0; 131 131 } else $index++; // Listový vrchol 132 } else 132 } else 133 133 { 134 134 // --- Zarovnávání prvků kvůli vzhledu 135 135 if(!array_key_exists($vfirst[$parent[$level]], $vleft)) $vleft[$vfirst[$parent[$level]]] = 0; 136 136 if(!array_key_exists($parent[$level], $vleft)) $vleft[$parent[$level]] = 0; 137 if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]]) 137 if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]]) 138 138 { 139 139 $vleft[$parent[$level]] = $vleft[$vfirst[$parent[$level]]]; … … 141 141 } 142 142 balance($parent[$level],$level, $vlast,$vleft,$vpred,$vfirst,$vnext,$tbound, $width, 0); 143 if ($position[$level]==1) 143 if ($position[$level]==1) 144 144 { 145 145 $vleft[$vfirst[$parent[$level]]] = $vleft[$parent[$level]]; … … 149 149 if(!array_key_exists($parent[$level], $vlast)) $vlast[$parent[$level]] = 0; 150 150 $curr = $vlast[$parent[$level]]; 151 151 152 152 if(!array_key_exists($level, $tbound)) $tbound[$level] = 0; 153 153 if(!array_key_exists($level + 1, $tbound)) $tbound[$level + 1] = 0; … … 165 165 $datawidth = $data['width']; 166 166 for($i = 0; $i <= $maxindex; $i++) 167 { 167 { 168 168 if(!array_key_exists($i, $vleft)) $vleft[$i] = 0; 169 169 if(!array_key_exists($i, $data['vleft'])) $data['vleft'][$i] = 0; … … 179 179 $IconList = array(); 180 180 $DbResult = $Database->query('SELECT * FROM HostType'); 181 while($HostType = $DbResult->fetch_assoc()) 181 while($HostType = $DbResult->fetch_assoc()) 182 182 $IconList[$HostType['Id']] = imagecreatefrompng('images/'.$HostType['IconName'].'.png'); 183 183 … … 191 191 $gray = imagecolorallocate($im, 160, 160, 160); 192 192 193 function xpos($id) 193 function xpos($id) 194 194 { 195 195 global $vleft, $spacex; … … 198 198 199 199 $DbResult = $Database->query('SELECT * FROM hosts JOIN HostType ON HostType.Id = hosts.type WHERE hosts.used=1'); 200 while($item = $DbResult->fetch_array()) 200 while($item = $DbResult->fetch_array()) 201 201 { 202 202 $id = $item['id']; 203 203 if(!array_key_exists($id, $vtop)) $vtop[$id] = 0; 204 if(($vtop[$id] > 0) || ($item['name'] == $TopHostName)) 204 if(($vtop[$id] > 0) || ($item['name'] == $TopHostName)) 205 205 { 206 206 if($vtop[$id] > 0) imageline($im, xpos($id) + $halfx, $vtop[$id] * $spacey, xpos($id) + $halfx, $vtop[$id] * $spacey + 8, $black); 207 207 if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0; 208 if($vfirst[$id] > 0) 208 if($vfirst[$id] > 0) 209 209 { 210 210 imageline($im, xpos($vfirst[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, xpos($vlast[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, $black); 211 211 imageline($im, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey - 10, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey, $black); 212 212 } 213 213 214 214 $image = $IconList[$item['type']]; 215 215 if($item['IP'] == '') … … 228 228 imagecopy($im, $image, xpos($id) + $halfx - 15, $vtop[$id] * $spacey + 12, 0, 0, 30, 30); 229 229 // imagerectangle($im,xpos($id)+$halfx-6,$vtop[$id]*$spacey+16,xpos($id)+$halfx+6,$vtop[$id]*$spacey+28,$color); 230 if($debug) 230 if($debug) 231 231 { 232 232 imagestring($im, 2, xpos($id) + ($spacex - strlen($item['id']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), $item['id'], $color); 233 } else 233 } else 234 234 imagestring($im, 2, xpos($id) + ($spacex - strlen($item['name']) * imagefontwidth(2)) / 2, $vtop[$id] * $spacey + 31 + imagefontheight(2), strtoupper($item['name']), $color); 235 235 } -
trunk/Modules/NetworkTopology/topologie2.php
r577 r738 38 38 } 39 39 40 $this->Tree = $Hosts[$this->TopHostId]; 40 $this->Tree = $Hosts[$this->TopHostId]; 41 41 } 42 42 43 43 function CalculateDimension(&$Host) 44 44 { … … 66 66 67 67 function MoveNode(&$Host, $Displacement) 68 { 68 { 69 69 $Host['displacement'] = $Host['displacement'] + $Displacement; 70 70 foreach($Host['subitems'] as $Index => $SubHost) … … 92 92 $II = 0; 93 93 while($RightHost['parent_node']['subitems'][$II]['id'] != $RightHost['id']) $II++; 94 while($II < count($RightHost['parent_node']['subitems'])) 94 while($II < count($RightHost['parent_node']['subitems'])) 95 95 { 96 96 $this->MoveNode($RightHost['parent_node']['subitems'][$II], $Level[$I]['displacement'] - $Level[$I + 1]['displacement']); … … 100 100 } 101 101 } 102 102 103 103 function BuildLevels(&$Host) 104 104 { … … 116 116 { 117 117 $HostPos = array('x' => -$this->RelPos['min'] + $SubHost['displacement'], 'y' => $SubHost['level'] * $this->HostHeight); 118 imageline($this->Image, $ParentHostPos['x'], $ParentHostPos['y'], $ParentHostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $this->LineColor); 119 imageline($this->Image, $ParentHostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $HostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $this->LineColor); 120 imageline($this->Image, $HostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $HostPos['x'], $HostPos['y'], $this->LineColor); 118 imageline($this->Image, $ParentHostPos['x'], $ParentHostPos['y'], $ParentHostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $this->LineColor); 119 imageline($this->Image, $ParentHostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $HostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $this->LineColor); 120 imageline($this->Image, $HostPos['x'], $ParentHostPos['y'] + $this->HostHeight * 0.5, $HostPos['x'], $HostPos['y'], $this->LineColor); 121 121 $this->DrawNode(&$Host['subitems'][$Index]); 122 122 imagecopy($this->Image, $this->ImageComputer, $HostPos['x'] - imagesx($this->ImageComputer) * 0.5, $HostPos['y'] - imagesy($this->ImageComputer) * 0.5, 0, 0, 30, 30);
Note:
See TracChangeset
for help on using the changeset viewer.