Changeset 16


Ignore:
Timestamp:
Jan 17, 2008, 7:13:44 PM (16 years ago)
Author:
george
Message:

Opraveno: Zobrazování topologie počítačů.

Location:
www
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • www/error.php

    r4 r16  
    1 <?
     1<?php
    22
    33// Obsluha chyb v1.1.1 //
    4 
     4include_once('config.php');
    55$Error_Email = $Config['Web']['AdminEmail'];                                            // Adresa, kam budou chyby odesílány
    66$Error_Subject = $Config['Web']['Title'].' - Chybové hlášení';          // Název zpráv o chybách
  • www/is/topologie-img.php

    r4 r16  
    1313  global $debug, $bbound;
    1414 
    15   if ($i=@$vfirst[$id])
     15  if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0;
     16  if($i = $vfirst[$id])
    1617  {
    17     if ($debug==2) echo @$id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n";
    18     if ((@$vlast[$id]>0)&&(@$vleft[$id]>@$vleft[$vlast[$id]]))
     18    //if ($debug==2) echo $id.':'.@$i.','.@$vpred[$i].'-'.@$vleft[@$vpred[$i]]."\n";
     19    if (($vlast[$id] > 0) && ($vleft[$id] > $vleft[$vlast[$id]]))
    1920    {
    2021      $diff=$vleft[$id]-$vleft[$vlast[$id]];
    2122      $i=$vfirst[$id];
    22       if ($vleft[$id]>=@$tbound[$level])
    23       {
    24         $tbound[$level]=$vleft[$id]+2;
    25         if ($vleft[$id]>$width) $width=$vleft[$id];
     23      if ($vleft[$id] >= $tbound[$level])
     24      {
     25        $tbound[$level] = $vleft[$id] + 2;
     26        if ($vleft[$id] > $width) $width = $vleft[$id];
    2627      }
    2728    } else {
     
    3637      $vleft[$i]+=$diff;
    3738      $limit = balance($i,$level+1, $vlast,$vleft,$vpred, $vfirst,$vnext,$tbound, $width, $limit) + 2;
    38       $i=@$vnext[$i];
     39      if(!array_key_exists($i, $vnext)) $vnext[$i] = 0;
     40      $i = $vnext[$i];
    3941    }
    4042  }
     
    6365  $height = 0;                                   // Hloubka stromu
    6466
    65   $parent[$level]=0;                             // Rodič dané úrovně
    66   $position[$level]=0;                           // Aktuální pozice prvku na dané úrovni
    67   $count[$level]=0;                              // Počet prvků na dané úrovni
    68  
     67  $parent[$level] = 0;                             // Rodič dané úrovně
     68  $position[$level] = 0;                           // Aktuální pozice prvku na dané úrovni
     69  $count[$level] = 0;                              // Počet prvků na dané úrovni
     70 
     71  $maxindex = 0;
     72  $tbound[$level] = 0;
     73  $tranger[$level] = 0;
     74   
    6975  // --- Hlavní cyklus ---------------------------------------------------------
    7076  do
     
    7278  // --- Proveď databázový dotaz -----------------------------------------------
    7379    $query = 'SELECT * FROM hosts WHERE used=1 AND ';
    74     if ($level==0)
     80    if ($level == 0)
    7581    {
    7682      $query .= 'name = "'.$TopHostName.'" ORDER BY id';
     
    8187    if ($mode) $query.=' DESC';
    8288    $query .= ' LIMIT '.$position[$level].',1';
     89    //echo($query.'<br>');
    8390    $DbResult = $Database->query($query);
    8491    $item = $DbResult->fetch_array();
    85     if ($item) {
     92    //print_r($item);
     93    if($item)
     94    {
    8695  // --- Zpracování položky z DB -----------------------------------------------
    8796      if($position[$level] > 0)
    8897      {
    89         $vnext[$curr]=$item['id']; // Neprvní položka, nastav předchozí
     98        $vnext[$curr] = $item['id']; // Neprvní položka, nastav předchozí
    9099      }
    91100      $curr = $item['id'];
    92       if ($curr > @$maxindex) $maxindex=$curr;
     101      if ($curr > $maxindex) $maxindex = $curr;
    93102      if ($position[$level] == 0) $vfirst[$parent[$level]]=$curr; // První položka, nastav první
    94       $vlast[$parent[$level]]=$curr;
     103      $vlast[$parent[$level]] = $curr;
    95104      $vtop[$curr] = $level;
    96       $vleft[$curr] = @$tbound[$level];
    97       $vpred[$curr] = @$tranger[$level];
     105      if(!array_key_exists($level, $tbound)) $tbound[$level] = 0;
     106      $vleft[$curr] = $tbound[$level];
     107      if(!array_key_exists($level, $tranger)) $tranger[$level] = 0;
     108      $vpred[$curr] = $tranger[$level];
    98109      $tranger[$level] = $curr;
    99110      if (($debug == 3) && ($level == 8)) echo $curr.',';
     
    104115      $childcnt = $DbResult->fetch_array();
    105116      if ($childcnt[0] > 0)
    106       {                      // Uzelový vrchol
    107         if(@$tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = @$tbound[$level + 1];
     117      {   
     118        // Uzelový vrchol
     119        if(array_key_exists($level + 1, $tbound))                 
     120          if($tbound[$level + 1] > $vleft[$curr]) $vleft[$curr] = $tbound[$level + 1];
    108121      }
    109122      $tbound[$level] = $vleft[$curr] + 2;
     
    114127        if ($level > $height) $height = $level;
    115128        $parent[$level] = $curr;
    116         $position[$level]=0;
     129        $position[$level] = 0;
    117130        $count[$level] = 0;
    118131      } else $index++;                            // Listový vrchol
    119     } else {
     132    } else
     133    {
    120134  // --- Zarovnávání prvků kvůli vzhledu
    121       if (@$vleft[$vfirst[$parent[$level]]]>@$vleft[$parent[$level]]) {
     135      if(!array_key_exists($vfirst[$parent[$level]], $vleft)) $vleft[$vfirst[$parent[$level]]] = 0;
     136      if(!array_key_exists($parent[$level], $vleft)) $vleft[$parent[$level]] = 0;
     137      if ($vleft[$vfirst[$parent[$level]]] > $vleft[$parent[$level]])
     138      {
    122139        $vleft[$parent[$level]] = $vleft[$vfirst[$parent[$level]]];
    123140        if ($vleft[$parent[$level]]+2>$tbound[$level-1]) $tbound[$level-1] = $vleft[$parent[$level]]+2;
    124141      }
    125       balance(@$parent[$level],$level, $vlast,$vleft,$vpred,$vfirst,$vnext,$tbound, $width, 0);
    126       if (@$position[$level]==1) {
    127         $vleft[$vfirst[$parent[$level]]]=@$vleft[$parent[$level]];
     142      balance($parent[$level],$level, $vlast,$vleft,$vpred,$vfirst,$vnext,$tbound, $width, 0);
     143      if ($position[$level]==1)
     144      {
     145        $vleft[$vfirst[$parent[$level]]] = $vleft[$parent[$level]];
    128146      }
    129147      $level--;
    130       $curr=@$vlast[$parent[$level]];
    131       if (@$tbound[$level]>@$tbound[$level+1]) $tbound[$level+1]=$tbound[$level];
     148      if(!array_key_exists($level, $parent)) $parent[$level] = 0;
     149      if(!array_key_exists($parent[$level], $vlast)) $vlast[$parent[$level]] = 0;
     150      $curr = $vlast[$parent[$level]];
     151     
     152      if(!array_key_exists($level, $tbound)) $tbound[$level] = 0;
     153      if(!array_key_exists($level + 1, $tbound)) $tbound[$level + 1] = 0;
     154      if($tbound[$level] > $tbound[$level + 1]) $tbound[$level + 1] = $tbound[$level];
    132155    }
    133156  } while($level >= 0);
    134   $data = compact('tbound','count','tbound','vfirst','vlast','vtop','vleft','height','width','index','maxindex');
    135   return $data;
     157  $data = compact('tbound', 'count', 'tbound', 'vfirst', 'vlast', 'vtop', 'vleft', 'height', 'width', 'index', 'maxindex');
     158  return($data);
    136159};
    137160
     
    140163// exit();
    141164$data = gentree(1);
    142 $datawidth = @$data['width'];
    143 for ($i=0; $i<=$maxindex; $i++) $vleft[$i]=.2+(@$vleft[$i]+($datawidth-@$data['vleft'][$i]))/2;
    144 
    145 $spacex=32;
    146 $spacey=68;
    147 $halfx=$spacex/2;
    148 $halfy=$spacey/2;
     165$datawidth = $data['width'];
     166for($i=0; $i <= $maxindex; $i++)
     167{
     168  if(!array_key_exists($i, $vleft)) $vleft[$i] = 0;
     169  if(!array_key_exists($i, $data['vleft'])) $data['vleft'][$i] = 0;
     170  $vleft[$i] = .2 + ($vleft[$i] + ($datawidth - $data['vleft'][$i])) / 2;
     171}
     172
     173$spacex = 32;
     174$spacey = 68;
     175$halfx = $spacex / 2;
     176$halfy = $spacey / 2;
    149177// === Načtení pomocných obrázků ===============================================
    150 $im_comp = @imagecreatefrompng('images/comp.png');
    151 $im_dev = @imagecreatefrompng('images/device.png');
     178$im_comp = imagecreatefrompng('images/comp.png');
     179$im_dev = imagecreatefrompng('images/device.png');
    152180// === Generování obrázku ======================================================
    153 $im = @imagecreate(($width+1.6)*$spacex, ($height+1)*$spacey);
     181$im = imagecreate(($width + 1.6) * $spacex, ($height + 1) * $spacey);
    154182$background_color = imagecolorallocate($im, 255, 255, 255);
    155 $black = imagecolorallocate($im, 0,0,0);
    156 $red = imagecolorallocate($im, 255,0,0);
    157 $green = imagecolorallocate($im, 0,128,0);
    158 $blue = imagecolorallocate($im, 100,100,255);
    159 $gray = imagecolorallocate($im, 160,160,160);
    160 
    161 function xpos($id) {
     183$black = imagecolorallocate($im, 0, 0, 0);
     184$red = imagecolorallocate($im, 255, 0, 0);
     185$green = imagecolorallocate($im, 0, 128, 0);
     186$blue = imagecolorallocate($im, 100, 100, 255);
     187$gray = imagecolorallocate($im, 160, 160, 160);
     188
     189function xpos($id)
     190{
    162191  global $vleft, $spacex;
    163   return @$vleft[$id]*$spacex;
     192  return($vleft[$id] * $spacex);
    164193}
    165194
    166195$DbResult = $Database->query("SELECT * FROM hosts WHERE used=1");
    167 while ($item = $DbResult->fetch_array())
     196while($item = $DbResult->fetch_array())
    168197{
    169198  $id = $item['id'];
    170   if ((@$vtop[$id]>0)||($item['name']==$TopHostName))
     199  if(!array_key_exists($id, $vtop)) $vtop[$id] = 0;
     200  if(($vtop[$id] > 0) || ($item['name'] == $TopHostName))
    171201  {
    172     if ($vtop[$id]>0) imageline($im,xpos($id)+$halfx,@$vtop[$id]*$spacey,xpos($id)+$halfx,@$vtop[$id]*$spacey+8,$black);
    173     if (@$vfirst[$id]>0) {
    174       imageline($im,xpos($vfirst[$id])+$halfx,$vtop[$id]*$spacey+$spacey,xpos($vlast[$id])+$halfx,$vtop[$id]*$spacey+$spacey,$black);
    175       imageline($im,xpos($id)+$halfx,($vtop[$id]+1)*$spacey-10,xpos($id)+$halfx,($vtop[$id]+1)*$spacey,$black);
    176     }
    177     $ip=explode('.',$item['IP']);
    178     if (@$ip[3]<100) { $image=$im_comp; } else $image=$im_dev; 
     202    if($vtop[$id] > 0) imageline($im, xpos($id) + $halfx, $vtop[$id] * $spacey, xpos($id) + $halfx, $vtop[$id] * $spacey + 8, $black);
     203    if(!array_key_exists($id, $vfirst)) $vfirst[$id] = 0;
     204    if($vfirst[$id] > 0)
     205    {
     206      imageline($im, xpos($vfirst[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, xpos($vlast[$id]) + $halfx, $vtop[$id] * $spacey + $spacey, $black);
     207      imageline($im, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey - 10, xpos($id) + $halfx, ($vtop[$id] + 1) * $spacey, $black);
     208    }
     209    $ip = explode('.',$item['IP']);
     210    if(!array_key_exists(3, $ip)) $ip[3] = '';
     211    if($ip[3] < 100)
     212    {
     213      $image = $im_comp;
     214    } else $image = $im_dev; 
    179215    if(($ip[0] != 192) and ($ip[0] != 168))
    180216    {
     
    185221      $color = $gray;
    186222      $image = $im_dev;
    187     } else {
    188       if ((($ip[0] != 192) and ($ip[0] != 168)) or ($ip[3]>=100) or ($ip[3]==1))
     223    } else
     224    {
     225      if((($ip[0] != 192) and ($ip[0] != 168)) or ($ip[3] >= 100) or ($ip[3] == 1))
    189226      {
    190227        if($item['online'] == 1) { $color = $green; } else $color = $red;
    191       } else {
     228      } else
     229      {
    192230        if($item['online'] == 1) { $color = $green; } else $color = $black;
    193231      }
     
    204242
    205243// === Sestavení výsledného souboru ============================================
    206 if(!($debug>1))
     244if(!($debug > 1))
    207245{
    208246  header("Content-type: image/png");
Note: See TracChangeset for help on using the changeset viewer.