Пример #1
0
function getimagesize_remote($image_url)
{
    if (!($handle = @fopen($image_url, 'rb'))) {
        return 0;
    }
    $contents = '';
    $count = 0;
    if ($handle) {
        do {
            $count += 1;
            $data = fread($handle, 8192);
            if (strlen($data) == 0) {
                break;
            }
            $contents .= $data;
            // Workaround for more speed:
            //  For the size range usually the first bytes, it reads:
            //  therefore only max. the first ~ 40 bytes
            //
            // } while(true);
        } while ($count <= 5);
    } else {
        return 0;
    }
    fclose($handle);
    if (!($im = imagecreatefromstring($contents))) {
        return 0;
    }
    $gis[0] = Imagesx($im);
    $gis[1] = Imagesy($im);
    imagedestroy($im);
    // array member 3 is used below to keep with current getimagesize standards
    $gis[3] = "width={$gis[0]} height={$gis[1]}";
    return $gis;
}
Пример #2
0
function Layout() {

	global $link,$locsep,$resmsg;
	global $xm,$ym,$xo,$yo,$len,$geo,$ina,$flt,$lev,$ipi;
	global $mapbg,$rloc,$cloc,$bloc;

	$net       = array();

# Gather Device Info
	if($ina == "vlan"){
		$query	= GenQuery('vlans','g','device','device','',array('vlanid'),array('regexp'),array($flt));
		$res	= @DbQuery($query,$link);
		if($res){
			while( ($vl = @DbFetchRow($res)) ){
				$devs[] = preg_replace('/([\^\$+])/','\\\\\\\\$1',$vl[0]);		# \Q...\E Doesn't seem to work in MySQL?
			}
			@DbFreeResult($res);
		}else{
			echo @DbError($link);
		}
		if (! is_array ($devs) ){echo $resmsg;die;}
		$query	= GenQuery('devices','s','name,ip,location,icon','','',array('name'),array('regexp'),array(implode("|",$devs)));
	}elseif($ina == "network"){
		$query	= GenQuery('networks','g','device','device','',array('ip'),array('='),array($flt));
		$res	= @DbQuery($query,$link);
		if($res){
			while( ($net = @DbFetchRow($res)) ){
				$devs[] = preg_replace('/([\^\$\*\+])/','\\\\\\\\$1',$net[0]);
			}
			@DbFreeResult($res);
		}else{
			echo @DbError($link);
		}
		if (! is_array ($devs) ){echo $resmsg;die;}
		$query	= GenQuery('devices','s','name,ip,location,icon','','',array('name'),array('regexp'),array(implode("|",$devs)));
	}elseif($ina == "type"){
		$query	= GenQuery('devices','s','name,ip,location,icon','','',array('type'),array('regexp'),array($flt));
	}else{
		$query	= GenQuery('devices','s','name,ip,location,icon','','',array('location'),array('regexp'),array($flt));
	}
	$res	= @DbQuery($query,$link);
	if($res){
		while( ($d = @DbFetchRow($res)) ){
			$l = explode($locsep, $d[2]);
			if($lev == "c" or $lev == "C"){
				$locs[$l[0]][$l[1]]++;
			}elseif($lev == "b" or $lev == "B"){
				$locs[$l[0]][$l[1]][$l[2]]++;
			}else{
				$locs[$l[0]][$l[1]][$l[2]][$l[3]][] = $d[0];
			}
			$dev['ip'] [$d[0]] = long2ip($d[1]);
			$dev['ic'] [$d[0]] = $d[3];
			$dev['reg'][$d[0]] = $l[0];
			$dev['cty'][$d[0]] = $l[1];
			$dev['bld'][$d[0]] = $l[2];
			$dev['rom'][$d[0]] = $l[4];
		}
		@DbFreeResult($res);
	}else{
		echo @DbError($link);
	}
	if($ipi){
		$query	= GenQuery('networks');
		$res	= @DbQuery($query,$link);
		if($res){
			while( ($n = @DbFetchRow($res)) ){
				$net[$n[0]][$n[1]] .= " ". long2ip($n[2]);
			}
		}else{
			echo @DbError($link);
		}
		@DbFreeResult($res);
	}

# Gather Link Info
	$query	= GenQuery('links');
	$res	= @DbQuery($query,$link);
	if($res){
		while( ($l = @DbFetchRow($res)) ){
			if($dev[$l[1]]['ic'] and $dev[$l[3]]['ic']){					# both ends are ok, if an icon exists
				if($lev == "f"){
					if( isset($devlink[$l[3]][$l[1]]) ){				# opposite link doesn't exist?
						$devlink[$l[3]][$l[1]]['nbw'][$l[3]][$l[4]][$l[1]][$l[2]] = $l[5];
					}else{
						$devlink[$l[1]][$l[3]]['bw'][$l[1]][$l[2]][$l[3]][$l[4]] = $l[5];
					}
				}
				if($dev[$l[1]]['bld'] != $dev[$l[3]]['bld'])			{	# is it same bld?
					$nbldlink[$dev[$l[1]]['bld']] ++;
					$abldlink[$dev[$l[1]]['bld']][$dev[$l[3]]['bld']]++;		# needed for Arranging.
					if(isset($bldlink[$dev[$l[3]]['bld']][$dev[$l[1]]['bld']]) ){	# link defined already?
						$bldlink[$dev[$l[3]]['bld']][$dev[$l[1]]['bld']]['nbw'][$l[3]][$l[4]][$l[1]][$l[2]] = $l[5];
					}else{
						$bldlink[$dev[$l[1]]['bld']][$dev[$l[3]]['bld']]['bw'][$l[1]][$l[2]][$l[3]][$l[4]] = $l[5];
					}
				}
				if($dev[$l[1]]['cty'] != $dev[$l[3]]['cty']){				# is it same cty?
					$nctylink[$dev[$l[1]]['cty']]++;
					$actylink[$dev[$l[1]]['cty']][$dev[$l[3]]['cty']]++;		# needed for Arranging.
					if(isset($ctylink[$dev[$l[3]]['cty']][$dev[$l[1]]['cty']]) ){	# link defined already?
						$ctylink[$dev[$l[3]]['cty']][$dev[$l[1]]['cty']]['nbw'][$l[3]][$l[4]][$l[1]][$l[2]] = $l[5];
					}else{

						$ctylink[$dev[$l[1]]['cty']][$dev[$l[3]]['cty']]['bw'][$l[1]][$l[2]][$l[3]][$l[4]] = $l[5];
					}
				}
			}
		}
		@DbFreeResult($res);
	}else{
		echo @DbError($link);
	}

# Prepare geographic stuff
	$mapinfo   = "";
	$mapframes = "";
	$maplinks  = "";
	$mapitems  = "";

	if ($geo) {
		if(count($cdev) == 1){
			$rk   = array_keys($cdev);
			if(count($cdev[$rk[0]]) == 1){
				$ck = array_keys($cdev[$rk[0]]);
				$mapbg = TopoMap($rk[0],$ck[0]);
			}else{
				$mapbg = TopoMap($rk[0]);
			}
		}else{
			$mapbg = TopoMap();
		}
		$bg = Imagecreatefrompng("log/$mapbg");
		$xm = Imagesx($bg);
		$ym = Imagesy($bg);
		Imagedestroy($bg);

		$query	= GenQuery('locations');
		$res	= @DbQuery($query,$link);
		if($res){
			while( ($l = @DbFetchRow($res)) ){
				if($l[3]){
					if( $mapbg == TopoMap($l[1],$l[2]) ){
						$bloc[$l[3]] = $l[4];
						$bloc[$l[3]] = $l[5];
					}
				}elseif($l[2]){
					if($mapbg == TopoMap($l[1]) ){
						$cloc[$l[2]] = $l[4];
						$cloc[$l[2]] = $l[5];
					}
				}else{
					$rloc[$l[1]] = $l[4];
					$rloc[$l[1]] = $l[5];
				}
			}
			@DbFreeResult($res);
		}else{
			echo @DbError($link);
		}
		
	}
# Build Layout
	Drawlevel($locs,(intval($xm/2) + $xo), (intval($ym/2) + $yo),$len );
}
Пример #3
0
function Map()
{
    global $link, $lev, $fco, $xm, $ym, $xo, $yo, $csi, $bsi, $fsi, $cro, $bro, $cwt, $loi, $bwt, $dev, $ndev, $bdev, $cdev;
    global $devlink, $ctylink, $bldlink, $rdevlink, $rctylink, $rbldlink, $nctylink, $nbldlink, $imgmap;
    global $geo, $xbl, $ybl, $xct, $yct, $mapbg, $mapinfo, $mapframes, $maplinks, $mapitems, $locsep;
    $mapinfo = "";
    $mapframes = "";
    $maplinks = "";
    $mapitems = "";
    $ctyscalx = 1.3;
    $ctyscaly = 1;
    $nreg = count($rdev);
    $ncty = count($cdev);
    if ($nreg == 1) {
        $rk = array_keys($rdev);
        if ($ncty == 1) {
            $ctyscalx = 0;
            $ctyscaly = 0;
            $ck = array_keys($rdev[$rk[0]]);
            $mapbg = TopoMap($rk[0], $ck[0]);
        } else {
            $mapbg = TopoMap($rk[0]);
        }
    } else {
        $mapbg = TopoMap();
    }
    if ($geo) {
        $bg = Imagecreatefrompng("log/{$mapbg}");
        $xm = Imagesx($bg);
        $ym = Imagesy($bg);
        Imagedestroy($bg);
        $query = GenQuery('locations');
        $res = @DbQuery($query, $link);
        if ($res) {
            while ($l = @DbFetchRow($res)) {
                if ($l[3]) {
                    if ($mapbg == TopoMap($l[1], $l[2])) {
                        $xbl["{$l['1']}{$locsep}{$l['2']}"][$l[3]] = $l[4];
                        $ybl["{$l['1']}{$locsep}{$l['2']}"][$l[3]] = $l[5];
                    }
                } elseif ($l[2]) {
                    if ($mapbg == TopoMap($l[1])) {
                        $xct["{$l['1']}{$locsep}{$l['2']}"] = $l[4];
                        $yct["{$l['1']}{$locsep}{$l['2']}"] = $l[5];
                    }
                } else {
                    $xrg[$l[1]] = $l[4];
                    $yrg[$l[1]] = $l[5];
                }
            }
            @DbFreeResult($res);
        } else {
            echo @DbError($link);
        }
    }
    $ctynum = 0;
    ksort($cdev);
    foreach (Arrange($cdev, "c") as $cty) {
        $ctynum++;
        $nbld = count($ndev[$cty]);
        $ncl = $nctylink[$cty] ? $nctylink[$cty] : 1;
        $l = explode($locsep, $cty);
        if (!(isset($xct[$cty]) and isset($yct[$cty]))) {
            $phi = $cro * M_PI / 180 + 2 * $ctynum * M_PI / $ncty;
            $ctywght = pow($ncl, $cwt / 10);
            $xct[$cty] = intval(intval($xm / 2) + $xo + $csi * cos($phi) * $ctyscalx / $ctywght);
            $yct[$cty] = intval(intval($ym / 2) + $yo + $csi * sin($phi) * $ctyscaly / $ctywght);
        }
        if ($lev == "c" or $lev == "C") {
            $mapitems .= Drawitem($xct[$cty], $yct[$cty], $cdev[$cty], $l[1], $lev);
            $area = $xct[$cty] - 20 . "," . ($yct[$cty] - 20) . "," . ($xct[$cty] + 20) . "," . ($yct[$cty] + 20);
            $imgmap .= "<area href=?flt=" . rawurlencode($cty) . "&lev=b&loi=1&draw=1 coords=\"{$area}\" shape=rect title=\"Show {$nbld} buildings\">\n";
        } else {
            if ($nbld == 1) {
                $bldscalx = 0;
                $bldscaly = 0;
            } else {
                $bldscalx = 1.3;
                $bldscaly = 1;
                if ($loi) {
                    $mapinfo .= Drawitem($xct[$cty], $yct[$cty], '0', "{$l['1']} {$l['0']}", 'ci');
                }
            }
            $bldnum = 0;
            foreach (Arrange($ndev[$cty], "b") as $bld) {
                $bldnum++;
                $nbl = $nbldlink[$bld] ? $nbldlink[$bld] : 1;
                if (!(isset($xbl[$bld]) and isset($ybl[$bld]))) {
                    $eps = $bro * M_PI / 180 + 2 * $bldnum * M_PI / $nbld;
                    $bldwght = pow($nbl, $bwt / 10);
                    $xbl[$bld] = intval($xct[$cty] + $bsi * cos($eps) * $bldscalx / $bldwght);
                    $ybl[$bld] = intval($yct[$cty] + $bsi * sin($eps) * $bldscaly / $bldwght);
                }
                if ($lev == "b" or $lev == "B") {
                    $mapitems .= Drawitem($xbl[$bld], $ybl[$bld], $bdev[$cty][$bld], $bld, $lev);
                    $area = $xbl[$bld] - 20 . "," . ($ybl[$bld] - 20) . "," . ($xbl[$bld] + 20) . "," . ($ybl[$bld] + 20);
                    $imgmap .= "<area href=?flt=" . rawurlencode($bld) . "&lev=f&loi=1&ipi=1&draw=1 coords=\"{$area}\" shape=rect title=\"Show " . $bdev[$cty][$bld] . " devices\">\n";
                } else {
                    $cury = $rows = 0;
                    $cols = 1;
                    foreach (array_keys($ndev[$cty][$bld]) as $flr) {
                        # Determine building size
                        $cols = max(count($ndev[$cty][$bld][$flr]), $cols);
                        # find max cols
                        if ($cols > $fco) {
                            # Break row, if > Floor columns
                            $rrow = ceil($cols / $fco);
                            # How many rows result?
                            $rows += $rrow;
                            $cols = $fco;
                        } else {
                            $rows++;
                        }
                    }
                    $woff = intval($fsi * ($cols - 1) / 2);
                    $hoff = intval($fsi * ($rows - 1) / 2);
                    $mapframes .= Drawbox($xbl[$bld] - $woff - intval($fsi / 2) - 10, $ybl[$bld] - $hoff - intval($fsi / 2), $xbl[$bld] + $woff + intval($fsi / 2), $ybl[$bld] + $hoff + intval($fsi / 2), $bld);
                    uksort($ndev[$cty][$bld], "Floorsort");
                    foreach (array_keys($ndev[$cty][$bld]) as $flr) {
                        $mapitems .= Drawitem($xbl[$bld] - $woff - intval($fsi / 2), $ybl[$bld] - $hoff + $cury * $fsi, 0, $flr, 'fl');
                        usort($ndev[$cty][$bld][$flr], "Roomsort");
                        $curx = 0;
                        foreach ($ndev[$cty][$bld][$flr] as $dv) {
                            $xd[$dv] = $xbl[$bld] - $woff + $curx * $fsi;
                            $yd[$dv] = $ybl[$bld] - $hoff + $cury * $fsi;
                            $mapitems .= Drawitem($xd[$dv], $yd[$dv], '0', $dv, 'd');
                            $area = $xd[$dv] - 20 . "," . ($yd[$dv] - 20) . "," . ($xd[$dv] + 20) . "," . ($yd[$dv] + 20);
                            $imgmap .= "<area href=Devices-Status.php?dev=" . rawurlencode($dv) . " coords=\"{$area}\" shape=rect title=\"Show {$dv} Status\">\n";
                            $curx++;
                            if ($curx == $fco) {
                                $curx = 0;
                                $cury++;
                            }
                        }
                        $cury++;
                    }
                }
            }
        }
    }
    if ($lev == "c" or $lev == "C") {
        # Draw links after we set all coordinates
        foreach (array_keys($ctylink) as $ctyl) {
            foreach (array_keys($ctylink[$ctyl]) as $ctyn) {
                $mylink = Drawlink($xct[$ctyl], $yct[$ctyl], $xct[$ctyn], $yct[$ctyn], $ctylink[$ctyl][$ctyn]);
                $maplinks .= $mylink[0];
                $mapitems .= $mylink[1];
            }
        }
    } elseif ($lev == "b" or $lev == "B") {
        foreach (array_keys($bldlink) as $bldl) {
            foreach (array_keys($bldlink[$bldl]) as $bldn) {
                $mylink = Drawlink($xbl[$bldl], $ybl[$bldl], $xbl[$bldn], $ybl[$bldn], $bldlink[$bldl][$bldn]);
                $maplinks .= $mylink[0];
                $mapitems .= $mylink[1];
            }
        }
    } elseif ($lev == "f") {
        foreach (array_keys($devlink) as $devl) {
            foreach (array_keys($devlink[$devl]) as $devn) {
                $mylink = Drawlink($xd[$devl] - 8, $yd[$devl] - 4, $xd[$devn] - 8, $yd[$devn] - 4, $devlink[$devl][$devn]);
                $maplinks .= $mylink[0];
                $mapitems .= $mylink[1];
            }
        }
    }
}
Пример #4
0
 /**
  * Inserts the passed text in fontsize and color into the passed image
  *
  * @param resource $img
  * @param int $font
  * @param string $text
  * @param int $color
  */
 private function imageCenterString($img, $font, $text, $color)
 {
     if ($font < 0 || $font > 5) {
         $font = 0;
     }
     $num = array(array(4.6, 6), array(4.6, 6), array(5.6, 12), array(6.5, 12), array(7.6, 16), array(8.5, 16));
     $width = ceil(strlen($text) * $num[$font][0]);
     $x = imagesx($img) - $width - 8;
     $y = Imagesy($img) - ($num[$font][1] + 2);
     imagestring($img, $font, $x / 2, $y / 2, $text, $color);
 }
Пример #5
0
function Map()
{
    global $debug, $link, $locsep, $vallbl, $sholbl, $sumlbl, $imas, $fmt, $lit, $fsz, $pos;
    global $xm, $ym, $xo, $yo, $rot, $cro, $bro, $len, $lsf, $mde, $in, $op, $st, $co, $lev, $loo, $loa, $loi, $ipi, $ifa;
    global $mapbg, $mapitems, $maplinks, $mapinfo, $imgmap, $reg, $cty, $bld, $flr, $dev, $nod, $nlnk, $jnod, $cud;
    $rlnk = array();
    $clnk = array();
    $blnk = array();
    $dlnk = array();
    $acol = '';
    $join = '';
    if ($pos == 'a') {
        $acol = ',status';
        $join .= 'LEFT JOIN monitoring USING (device) ';
    }
    if (in_array('vlanid', $in) or in_array('vlanname', $in)) {
        $join .= 'LEFT JOIN vlans USING (device) ';
    }
    if (in_array('mac', $in) or in_array('nodip', $in) or in_array('name', $in) or in_array('oui', $in)) {
        $join .= 'LEFT JOIN nodes USING (device) ';
    }
    if (in_array('ifip', $in) or in_array('vrfname', $in)) {
        $join .= 'LEFT JOIN networks USING (device) ';
    }
    if (in_array('neighbor', $in)) {
        $join .= 'LEFT JOIN links USING (device) ';
    }
    $query .= GenQuery('devices', 's', "distinct device,devip,type,location,contact,devmode,icon,cpu,temp,devopts,size,stack{$acol},snmpversion", '', '', $in, $op, $st, $co, $join);
    # Postgres requires ordercolumn (snmpversion)!
    if ($lev < 5) {
        if (strpos($query, 'WHERE')) {
            $query .= ' AND snmpversion != 0';
        } else {
            $query .= ' WHERE snmpversion != 0';
        }
    }
    $query .= ' order by snmpversion desc';
    $res = DbQuery($query, $link);
    if ($res) {
        while ($d = DbFetchRow($res)) {
            $l = explode($locsep, $d[3]);
            $reg[$l[0]]['ndv']++;
            $cty[$l[0]][$l[1]]['ndv']++;
            $dev[$d[0]]['reg'] = $l[0];
            if ($d[6] and $ipi) {
                # Get IP info for interfaces on snmpdevs
                $nquery = GenQuery('networks', 's', 'ifname,ifip,ifip6,vrfname', '', '', array('device'), array('='), array($d[0]));
                $nres = DbQuery($nquery, $link);
                if ($nres) {
                    while ($n = DbFetchRow($nres)) {
                        if ($n[1]) {
                            $dev[$d[0]]['ifip'][$n[0]] .= " " . long2ip($n[1]) . ($n[3] ? " ({$n['3']})" : "");
                        } else {
                            $dev[$d[0]]['ifip'][$n[0]] .= " " . DbIPv6($n[2]) . ($n[3] ? " ({$n['3']})" : "");
                        }
                    }
                } else {
                    echo DbError($nlink);
                }
                DbFreeResult($nres);
            }
            if ($d[6] and ($ifa or $lit == 'l')) {
                # Get IF alias TODO use iftype to determine links?
                $nquery = GenQuery('interfaces', 's', 'ifname,ifidx,iftype,alias,dinoct,doutoct', '', '', array('device'), array('='), array($d[0]));
                $nres = DbQuery($nquery, $link);
                if ($nres) {
                    while ($n = DbFetchRow($nres)) {
                        $dev[$d[0]]['ifty'][$n[0]] = $n[1];
                        $dev[$d[0]]['ifix'][$n[0]] = $n[2];
                        $dev[$d[0]]['ifal'][$n[0]] = $n[3];
                        $dev[$d[0]]['ifin'][$n[0]] = $n[4];
                        $dev[$d[0]]['ifout'][$n[0]] = $n[5];
                    }
                } else {
                    echo DbError($nlink);
                }
                DbFreeResult($nres);
            }
            if ($lev > 1) {
                $dev[$d[0]]['cty'] = $l[1];
            }
            if ($lev > 2) {
                $bld[$l[0]][$l[1]][$l[2]]['ndv']++;
                $dev[$d[0]]['bld'] = $l[2];
            }
            if ($lev > 3) {
                if ($mde == "r") {
                    $flr[$l[0]][$l[1]][$l[2]][$d[0]]['ndv']++;
                } else {
                    $flr[$l[0]][$l[1]][$l[2]][$l[3]][] = $d[0];
                }
                $dev[$d[0]]['ip'] = long2ip($d[1]);
                $dev[$d[0]]['rom'] = $l[4];
                $dev[$d[0]]['rak'] = $l[5] ? $l[5] : "";
                $dev[$d[0]]['typ'] = $d[2];
                $dev[$d[0]]['con'] = $d[4];
                $dev[$d[0]]['mod'] = Devmode($d[5]);
                $dev[$d[0]]['ico'] = $d[6];
                if (substr($d[9], 1, 1) == "C") {
                    $dev[$d[0]]['cpu'] = $d[7];
                } else {
                    $dev[$d[0]]['cpu'] = "-";
                }
                $dev[$d[0]]['tmp'] = $d[8];
                if ($d[8] != 0) {
                    $dev[$d[0]]['tlb'] = $_SESSION['far'] ? intval($dev[$d[0]]['tmp'] * 1.8 + 32) . "F" : $dev[$d[0]]['tmp'] . "C";
                } else {
                    $dev[$d[0]]['tlb'] = "-";
                }
                $dev[$d[0]]['stk'] = $d[11] > 1 ? $d[11] : 1;
                $dev[$d[0]]['siz'] = $d[10] * $dev[$d[0]]['stk'];
                if ($pos == 'a') {
                    $dev[$d[0]]['sta'] = $d[12];
                }
            }
        }
        DbFreeResult($res);
    } else {
        echo DbError($link);
    }
    # Precalculate Links
    foreach (array_keys($dev) as $d) {
        # Devs sorted by snmpversion creates links with stats first!
        $lquery = GenQuery('links', 's', '*', '', '', array('device'), array('='), array($d));
        $lres = DbQuery($lquery, $link);
        while ($k = DbFetchRow($lres)) {
            if (isset($dev[$k[3]]['reg'])) {
                # Only use, if we have complete devs
                $rlquery = GenQuery('links', 's', '*', '', '', array('device', 'neighbor'), array('=', '='), array($k[3], $k[1]), array('AND'));
                $rlres = DbQuery($rlquery, $link);
                $rlnum = DbNumRows($rlres);
                if ($debug) {
                    echo "<div class=\"textpad good\">LINK:{$k['1']} to {$k['3']} with BW of {$k['5']}</div>\n";
                }
                if (array_key_exists("{$k['3']};;{$k['1']}", $dlnk)) {
                    $dlnk["{$k['3']};;{$k['1']}"]['rbw'] += $k[5];
                    $dlnk["{$k['3']};;{$k['1']}"]['rtr'] += $dev[$k[3]]['ifin'][$k[4]];
                    $dlnk["{$k['3']};;{$k['1']}"]['rif'][] = "{$k['1']};;{$k['2']}";
                    $dlnk["{$k['3']};;{$k['1']}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                } elseif (isset($dev[$k[3]]['ico'])) {
                    if (!$rlnum) {
                        if ($debug) {
                            echo "<div class=\"textpad alrm\">LNK: Fixing missing link from {$k['3']} to {$k['1']}</div>\n";
                        }
                        $dlnk["{$k['1']};;{$k['3']}"]['rbw'] += $k[5];
                        $dlnk["{$k['1']};;{$k['3']}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                        $dlnk["{$k['1']};;{$k['3']}"]['rif'][] = "{$k['3']};;{$k['4']}";
                        $dlnk["{$k['1']};;{$k['3']}"]['fty']["{$k['6']}:" . date('j.M', $k[10])]++;
                    }
                    $dlnk["{$k['1']};;{$k['3']}"]['fbw'] += $k[5];
                    $dlnk["{$k['1']};;{$k['3']}"]['ftr'] += $dev[$k[1]]['ifout'][$k[2]];
                    $dlnk["{$k['1']};;{$k['3']}"]['fif'][] = "{$k['1']};;{$k['2']}";
                    $dlnk["{$k['1']};;{$k['3']}"]['fty']["{$k['6']}:" . date('j.M', $k[10])]++;
                }
                $ra = $dev[$k[1]]['reg'];
                $rb = $dev[$k[3]]['reg'];
                $ca = $dev[$k[1]]['cty'];
                $cb = $dev[$k[3]]['cty'];
                $ba = $dev[$k[1]]['bld'];
                $bb = $dev[$k[3]]['bld'];
                if ($mde != "f" and $ra != $rb) {
                    $reg[$ra]['nlk']++;
                    $reg[$ra]['alk'][$rb]++;
                    # Needed for arranging
                    if (array_key_exists("{$rb};;{$ra}", $rlnk)) {
                        # Reverse link exists?
                        $rlnk["{$rb};;{$ra}"]['rbw'] += $k[5];
                        $rlnk["{$rb};;{$ra}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                        $rlnk["{$rb};;{$ra}"]['rif'][] = "{$k['1']};;{$k['2']}";
                        $rlnk["{$rb};;{$ra}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                    } else {
                        if (!$rlnum) {
                            $reg[$rb]['nlk']++;
                            $reg[$rb]['alk'][$rb]++;
                            $rlnk["{$ra};;{$rb}"]['rbw'] += $k[5];
                            $rlnk["{$ra};;{$rb}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                            $rlnk["{$ra};;{$rb}"]['rif'][] = "{$k['3']};;{$k['4']}";
                            $rlnk["{$ra};;{$rb}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                        }
                        $rlnk["{$ra};;{$rb}"]['fbw'] += $k[5];
                        $rlnk["{$ra};;{$rb}"]['ftr'] += $dev[$k[1]]['ifout'][$k[2]];
                        $rlnk["{$ra};;{$rb}"]['fif'][] = "{$k['1']};;{$k['2']}";
                        $rlnk["{$ra};;{$rb}"]['fty']["{$k['6']}:" . date('j.M', $k[10])]++;
                    }
                }
                if ($mde != "f" and $lev > 1) {
                    if ("{$ra};;{$ca}" != "{$rb};;{$cb}") {
                        $cty[$ra][$ca]['nlk']++;
                        if ($ra == $rb) {
                            $cty[$ra][$ca]['alk'][$cb]++;
                        }
                        #TODO test whether this improves arranging!
                        if (array_key_exists("{$rb};;{$cb};;{$ra};;{$ca}", $clnk)) {
                            $clnk["{$rb};;{$cb};;{$ra};;{$ca}"]['rbw'] += $k[5];
                            $clnk["{$rb};;{$cb};;{$ra};;{$ca}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                            $clnk["{$rb};;{$cb};;{$ra};;{$ca}"]['rif'][] = "{$k['1']};;{$k['2']}";
                            $clnk["{$rb};;{$cb};;{$ra};;{$ca}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                        } else {
                            if (!$rlnum) {
                                $cty[$rb][$cb]['nlk']++;
                                if ($ra == $rb) {
                                    $cty[$rb][$cb]['alk'][$ca]++;
                                }
                                $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['rbw'] += $k[5];
                                $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                                $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['rif'][] = "{$k['3']};;{$k['4']}";
                                $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                            }
                            $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['fbw'] += $k[5];
                            $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['ftr'] += $dev[$k[1]]['ifout'][$k[2]];
                            $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['fif'][] = "{$k['1']};;{$k['2']}";
                            $clnk["{$ra};;{$ca};;{$rb};;{$cb}"]['fty']["{$k['6']}:" . date('j.M', $k[10])]++;
                        }
                    }
                }
                if ($mde != "f" and $lev > 2) {
                    if ("{$ra};;{$ca};;{$ba}" != "{$rb};;{$cb};;{$bb}") {
                        $bld[$ra][$ca][$ba]['nlk']++;
                        if ("{$ra};;{$ca}" == "{$rb};;{$cb}") {
                            $bld[$ra][$ca][$ba]['alk'][$bb]++;
                        }
                        if (array_key_exists("{$rb};;{$cb};;{$bb};;{$ra};;{$ca};;{$ba}", $blnk)) {
                            $blnk["{$rb};;{$cb};;{$bb};;{$ra};;{$ca};;{$ba}"]['rbw'] += $k[5];
                            $blnk["{$rb};;{$cb};;{$bb};;{$ra};;{$ca};;{$ba}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                            $blnk["{$rb};;{$cb};;{$bb};;{$ra};;{$ca};;{$ba}"]['rif'][] = "{$k['1']};;{$k['2']}";
                            $blnk["{$rb};;{$cb};;{$bb};;{$ra};;{$ca};;{$ba}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                        } else {
                            if (!$rlnum) {
                                $bld[$rb][$cb][$bb]['nlk']++;
                                if ("{$ra};;{$ca}" == "{$rb};;{$cb}") {
                                    $bld[$rb][$cb][$bb]['alk'][$ba]++;
                                }
                                $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['rbw'] += $k[5];
                                $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['rtr'] += $dev[$k[1]]['ifin'][$k[2]];
                                $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['rif'][] = "{$k['3']};;{$k['4']}";
                                $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['rty']["{$k['6']}:" . date('j.M', $k[10])]++;
                            }
                            $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['fbw'] += $k[5];
                            $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['ftr'] += $dev[$k[1]]['ifout'][$k[2]];
                            $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['fif'][] = "{$k['1']};;{$k['2']}";
                            $blnk["{$ra};;{$ca};;{$ba};;{$rb};;{$cb};;{$bb}"]['fty']["{$k['6']}:" . date('j.M', $k[10])]++;
                        }
                    }
                }
                if ($lev > 3) {
                    $dev[$k[1]]['nlk']++;
                    # Count devlinks for flatmode
                    $dev[$k[1]]['alk'][$k[3]]++;
                    # Needed for arranging
                    #if ($mde == "r") {# TODO find arrange method for building rings (only links within bld matter!)
                    #	$flr[$l[0]][$l[1]][$l[2]][$k[1]]['alk'][$k[3]]++;
                    #}
                    if (!$rlnum) {
                        $dev[$k[3]]['nlk']++;
                        $dev[$k[3]]['alk'][$k[1]]++;
                    }
                }
            }
        }
        DbFreeResult($lres);
    }
    $rk = array_keys($reg);
    $nr = count($rk);
    # Draw Layout
    $cud = 0;
    if ($mde == "f") {
        $fstnod = 1;
        $nd = count(array_keys($dev));
        foreach (Arrange($dev) as $dv) {
            $jdev[$dv] = $cud;
            list($dev[$dv]['x'], $dev[$dv]['y']) = CircleCoords(intval($xm / 2 + $xo), intval($ym / 2 - $yo), $cud, $nd, $dev[$dv]['nlk'], $len, $rot);
            $mapitems .= DrawItem($dev[$dv]['x'], $dev[$dv]['y'], '0', $dv, 'd');
            if ($lev == 6) {
                DrawNodes($dv);
            }
            $imgmap .= "<area href=\"Devices-Status.php?dev=" . urlencode($dv) . "\" coords=\"" . ($dev[$dv]['x'] - $imas) . "," . ($dev[$dv]['y'] - $imas) . "," . ($dev[$dv]['x'] + $imas) . "," . ($dev[$dv]['y'] + $imas) . "\" shape=\"rect\" title=\"{$dv} " . $dev[$dv]['ip'] . " CPU:" . $dev[$dv]['cpu'] . "% Temp:" . $dev[$dv]['tlb'] . "\">\n";
            if ($loi) {
                $mapinfo .= DrawLabel($dev[$dv]['x'], $dev[$dv]['y'] - 40, Safelabel($dev[$dv]['cty'] . " " . $dev[$dv]['bld']), 1, "cornflowerblue");
            } elseif ($debug) {
                $mapinfo .= DrawLabel($dev[$dv]['x'], $dev[$dv]['y'] - 40, "Pos{$cud}", 1, "cornflowerblue");
            }
            $cud++;
        }
    } else {
        if ($mde == "g") {
            # Prepare geographic stuff
            if (count($rk) == 1) {
                $ck = array_keys($cty[$rk[0]]);
                if (count($ck) == 1) {
                    $mapbg = TopoMap($rk[0], $ck[0]);
                } else {
                    $mapbg = TopoMap($rk[0]);
                }
            } else {
                $mapbg = TopoMap();
            }
            $bg = Imagecreatefromjpeg("../topo/{$mapbg}");
            $xm = Imagesx($bg);
            $ym = Imagesy($bg);
            Imagedestroy($bg);
        }
        $cur = 0;
        $toc = 0;
        $tob = 0;
        foreach (Arrange($reg) as $r) {
            if ($mde == "g") {
                list($reg[$r]['x'], $reg[$r]['y'], $reg[$r]['cmt']) = DbCoords($r);
            }
            if (!$reg[$r]['x']) {
                list($reg[$r]['x'], $reg[$r]['y']) = CircleCoords(intval($xm / 2 + $xo), intval($ym / 2 - $yo), $cur, $nr, $reg[$r]['nlk'], $len, $rot);
            }
            if ($lev == 1) {
                $jreg[$r] = $cur;
                $mapitems .= DrawItem($reg[$r]['x'], $reg[$r]['y'], $reg[$r]['ndv'], $r, 1);
                $imgmap .= "<area href=\"?lev=2&mde={$mde}&fmt=png&loo={$loo}&loa={$loa}&st[]=" . urlencode(TopoLoc($r)) . "\" coords=\"" . ($reg[$r]['x'] - $imas) . "," . ($reg[$r]['y'] - $imas) . "," . ($reg[$r]['x'] + $imas) . "," . ($reg[$r]['y'] + $imas) . "\" shape=\"rect\" title=\"{$sholbl}\">\n";
            } else {
                if ($loi) {
                    if (count($cty[$r]) > 1) {
                        $mapinfo .= DrawItem($reg[$r]['x'], $reg[$r]['y'], '0', $r . " " . $reg[$r]['cmt'], 'ri');
                    } else {
                        $mapinfo .= DrawLabel($reg[$r]['x'], $reg[$r]['y'] - 42, Safelabel($r), 1, "cornflowerblue");
                    }
                }
                $cuc = 0;
                $nc = count(array_keys($cty[$r]));
                foreach (Arrange($cty[$r]) as $c) {
                    if ($mde == "g") {
                        list($cty[$r][$c]['x'], $cty[$r][$c]['y'], $cty[$r][$c]['cmt']) = DbCoords($r, $c);
                    }
                    if (!$cty[$r][$c]['x']) {
                        list($cty[$r][$c]['x'], $cty[$r][$c]['y']) = CircleCoords($reg[$r]['x'], $reg[$r]['y'], $cuc, $nc, $cty[$r][$c]['nlk'], $len * 10 / $lsf, $cro);
                    }
                    if ($lev == 2) {
                        $jcty["{$r};;{$c}"] = $toc;
                        $mapitems .= DrawItem($cty[$r][$c]['x'], $cty[$r][$c]['y'], $cty[$r][$c]['ndv'], $c, 2);
                        $imgmap .= "<area href=\"?lev=3&mde={$mde}&fmt=png&loo={$loo}&loa={$loa}&st[]=" . urlencode(TopoLoc($r, $c)) . "\" coords=\"" . ($cty[$r][$c]['x'] - $imas) . "," . ($cty[$r][$c]['y'] - $imas) . "," . ($cty[$r][$c]['x'] + $imas) . "," . ($cty[$r][$c]['y'] + $imas) . "\" shape=\"rect\" title=\"{$sholbl}\">\n";
                    } else {
                        if ($loi) {
                            if (count($bld[$r][$c]) > 1) {
                                $mapinfo .= DrawItem($cty[$r][$c]['x'], $cty[$r][$c]['y'], '0', $c . " " . $cty[$r][$c]['cmt'], 'ci');
                            } else {
                                $mapinfo .= DrawLabel($cty[$r][$c]['x'], $cty[$r][$c]['y'] - 30, Safelabel($c), 1, "cornflowerblue");
                            }
                        }
                        $cub = 0;
                        $nb = count(array_keys($bld[$r][$c]));
                        foreach (Arrange($bld[$r][$c]) as $b) {
                            if ($mde == "g") {
                                list($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y'], $bld[$r][$c][$b]['cmt']) = DbCoords($r, $c, $b);
                            }
                            if (!$bld[$r][$c][$b]['x']) {
                                list($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y']) = CircleCoords($cty[$r][$c]['x'], $cty[$r][$c]['y'], $cub, $nb, $bld[$r][$c][$b]['nlk'] * ($mde == "b" ? $cb % 2 + 0.3 : 1), $len / pow($lsf / 10, 2), $bro);
                            }
                            if ($lev == 3) {
                                $jbld["{$r};;{$c};;{$b}"] = $tob;
                                $mapitems .= DrawItem($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y'], $bld[$r][$c][$b]['ndv'], $b, 3);
                                $imgmap .= "<area href=\"?lev=4&mde={$mde}&fmt=png&loo={$loo}&loa={$loa}&st[]=" . urlencode(TopoLoc($r, $c, $b)) . "\" coords=\"" . ($bld[$r][$c][$b]['x'] - $imas) . "," . ($bld[$r][$c][$b]['y'] - $imas) . "," . ($bld[$r][$c][$b]['x'] + $imas) . "," . ($bld[$r][$c][$b]['y'] + $imas) . "\" shape=\"rect\" title=\"{$sholbl}\">\n";
                            } elseif ($mde == "b" or $mde == "g") {
                                DrawBuilding($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y'], $r, $c, $b);
                            } else {
                                if ($loi) {
                                    if (count($flr[$r][$c][$b]) > 1) {
                                        $mapinfo .= DrawItem($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y'], '0', $b . " " . $bld[$r][$c][$b]['cmt'], 'bi');
                                    } else {
                                        $mapinfo .= DrawLabel($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y'] - 38, Safelabel($b), 1, "cornflowerblue");
                                    }
                                }
                                $cd = 0;
                                $nd = count(array_keys($flr[$r][$c][$b]));
                                foreach (Arrange($flr[$r][$c][$b]) as $d) {
                                    $jdev[$d] = $cud;
                                    list($dev[$d]['x'], $dev[$d]['y']) = CircleCoords($bld[$r][$c][$b]['x'], $bld[$r][$c][$b]['y'], $cd, $nd, $dev[$d]['nlk'], $fsz, 0, 0);
                                    $mapitems .= DrawItem($dev[$d]['x'], $dev[$d]['y'], '0', $d, 'd');
                                    $imgmap .= "<area href=\"Devices-Status.php?dev=" . urlencode($d) . "\" coords=\"" . ($dev[$d]['x'] - $imas) . "," . ($dev[$d]['y'] - $imas) . "," . ($dev[$d]['x'] + $imas) . "," . ($dev[$d]['y'] + $imas) . "\" shape=\"rect\" title=\"{$dv} " . $dev[$d]['ip'] . " CPU:" . $dev[$d]['cpu'] . "%  T:" . $dev[$d]['tmp'] . "C\">\n";
                                    if ($lev == 6) {
                                        DrawNodes($d);
                                    }
                                    $cd++;
                                    $cud++;
                                }
                            }
                            $cub++;
                            $tob++;
                        }
                    }
                    $cuc++;
                    $toc++;
                }
            }
            $cur++;
        }
    }
    # Draw Links
    if ($lev == 1) {
        $rlkeys = array_keys($rlnk);
        foreach ($rlkeys as $li) {
            $l = explode(';;', $li);
            if ($fmt == "json") {
                $ls = intval(sqrt($rlnk[$li]['fbw'] / 100000000 / $lsf) + 1);
                $maplinks .= "    {\"source\":" . $jreg[$l[0]] . ",\"target\":" . $jreg[$l[1]] . ",\"value\":{$ls}},\n";
            } else {
                DrawLink($reg[$l[0]]['x'], $reg[$l[0]]['y'], $reg[$l[1]]['x'], $reg[$l[1]]['y'], $rlnk[$li]);
            }
        }
    } elseif ($lev == 2) {
        foreach (array_keys($clnk) as $li) {
            $l = explode(';;', $li);
            if ($fmt == "json") {
                $ls = intval(sqrt($clnk[$li]['fbw'] / 100000000 / $lsf) + 1);
                $maplinks .= "    {\"source\":" . $jcty["{$l['0']};;{$l['1']}"] . ",\"target\":" . $jcty["{$l['2']};;{$l['3']}"] . ",\"value\":{$ls}},\n";
            } else {
                DrawLink($cty[$l[0]][$l[1]]['x'], $cty[$l[0]][$l[1]]['y'], $cty[$l[2]][$l[3]]['x'], $cty[$l[2]][$l[3]]['y'], $clnk[$li]);
            }
        }
    } elseif ($lev == 3) {
        foreach (array_keys($blnk) as $li) {
            $l = explode(';;', $li);
            if ($fmt == "json") {
                $ls = intval(sqrt($blnk[$li]['fbw'] / 100000000 / $lsf) + 1);
                $maplinks .= "    {\"source\":" . $jbld["{$l['0']};;{$l['1']};;{$l['2']}"] . ",\"target\":" . $jbld["{$l['3']};;{$l['4']};;{$l['5']}"] . ",\"value\":{$ls}},\n";
            } else {
                DrawLink($bld[$l[0]][$l[1]][$l[2]]['x'], $bld[$l[0]][$l[1]][$l[2]]['y'], $bld[$l[3]][$l[4]][$l[5]]['x'], $bld[$l[3]][$l[4]][$l[5]]['y'], $blnk[$li]);
            }
        }
    } elseif ($lev > 3) {
        foreach (array_keys($dlnk) as $li) {
            $l = explode(';;', $li);
            if ($fmt == "json") {
                $ls = intval(sqrt($dlnk[$li]['fbw'] / 100000000 / $lsf) + 1);
                $ls = $ls ? $ls : 1;
                $maplinks .= "    {\"source\":" . $jdev[$l[0]] . ",\"target\":" . $jdev[$l[1]] . ",\"value\":{$ls}},\n";
            } else {
                DrawLink($dev[$l[0]]['x'], $dev[$l[0]]['y'], $dev[$l[1]]['x'], $dev[$l[1]]['y'], $dlnk[$li]);
            }
        }
        if ($lev == 6) {
            foreach (array_keys($nlnk) as $li) {
                $l = explode(';;', $li);
                if ($fmt == "json") {
                    $ls = intval(sqrt($nlnk[$li]['fbw'] / 100000000 / $lsf) + 1);
                    $ls = $ls ? $ls : 1;
                    $maplinks .= "    {\"source\":" . $jdev[$l[0]] . ",\"target\":" . $jnod["{$l['0']};;{$l['1']}"] . ",\"value\":{$ls}},\n";
                } else {
                    DrawLink($dev[$l[0]]['x'], $dev[$l[0]]['y'], $nod[$l[1]]['x'], $nod[$l[1]]['y'], $nlnk[$li]);
                }
            }
        }
    }
}
Пример #6
0
function txtonimg($src, $str, $color, $x, $y)
{
    $font = 'ANGSAZ.TTF';
    $string = $str;
    // String
    $filename = basename($src);
    $ext = getExtension($filename);
    if (strtolower($ext) == "gif") {
        $im = imagecreatefromgif($src);
    } elseif (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg") {
        $im = imagecreatefromjpeg($src);
    } elseif (strtolower($ext) == "png") {
        $im = imagecreatefrompng($src);
    }
    // Path Images
    $color = ImageColorAllocate($im, 255, 255, 255);
    // Text Color
    $pxX = (Imagesx($im) - 4 * strlen($string)) / 2;
    // X
    $pxY = Imagesy($im) - 10;
    // Y
    ImagettfText($im, 20, 0, $pxX, $pxY, $color, $font, $string);
    if (strtolower($ext) == "gif") {
        imagegif($src);
    } elseif (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg") {
        imagejpeg($src);
    } elseif (strtolower($ext) == "png") {
        imagepng($src);
    }
    ImageDestroy($im);
}