Beispiel #1
0
} elseif ($_GET['t'] == 'tmp') {
    $tit = 'Temperature';
    $rrd = "{$rrdpath}/" . rawurlencode($_GET['dv']) . "/system.rrd";
    if (!file_exists("{$rrd}")) {
        $debug = "RRD {$rrd} not found!";
    }
    $drawin .= "DEF:temp={$rrd}:temp:AVERAGE AREA:temp#7788bb  ";
    $drawin .= "CDEF:temp2=temp,1.3,/ AREA:temp2#8899cc ";
    $drawin .= "CDEF:temp3=temp,1.8,/ AREA:temp3#99aadd ";
    $drawin .= "CDEF:temp4=temp,3,/ AREA:temp4#aabbee ";
    $drawin .= "LINE2:temp#224488:\"Degrees Celsius\" ";
    if ($fahrtmp) {
        $drawin .= "CDEF:far=temp,1.8,*,32,+ LINE2:far#006699:\"Degrees Fahrenheit\" ";
    }
} else {
    foreach ($_GET['if'] as $i) {
        $rrd[$i] = "{$rrdpath}/" . rawurlencode($_GET['dv']) . "/" . rawurlencode($i) . ".rrd";
        if (!file_exists($rrd[$i])) {
            $debug .= "RRD {$rrd[$i]} not found!\n";
        }
    }
    list($drawin, $drawout, $tit) = GraphTraffic($rrd, $_GET['t']);
}
$opts = GraphOpts($_GET['s'], $_GET['dur'], $tit, 0);
if ($debug) {
    echo "<b>{$debug}</b>";
    echo "<pre>{$rrdcmd} graph - -a PNG {$opts}\n\t{$drawin}\n\t{$drawout}</pre>";
} else {
    header("Content-type: image/png");
    passthru("{$rrdcmd} graph - -a PNG {$opts} {$drawin} {$drawout}");
}
function Drawlink($x1,$y1,$x2,$y2,$prop) {

	$ida = 0;
	$oda = 0;

	$ltxt = "";
	$itxt = "";

	$slabel  = array();
	$elabel = array();
	
        global $fmt,$link,$lev,$lis,$ifi,$ipi,$lwt,$lix,$liy,$net;
	global $trfw,$trfa,$rrdstep,$rrdpath,$rrdcmd;

        if($x1 == $x2){
                $lix[$x1]+= 2;
                $x1 += $lix[$x1];
                $x2 = $x1;
        }
        if($y1 == $y2){
                $liy[$y1]+= 2;
                $y1 += $liy[$y1];
                $y2 = $y1;
        }

	foreach(array_keys($prop['bw']) as $dv){
		foreach(array_keys($prop['bw'][$dv]) as $if){
			if( preg_match("/[tsm]/",$lis) ){
				$rrd = "$rrdpath/" . rawurlencode($dv) . "/" . rawurlencode($if) . ".rrd";
				if (file_exists($rrd)){
					$rrdif["$dv-$if"] = $rrd;
				}else{
					echo "RRD:$rrd not found!\n";
				}
			}elseif($lis == 'r'){
				$iquery	= GenQuery('interfaces','s','dinoct,doutoct','','',array('device','ifname'),array('=','='),array($dv,$if),array('AND') );
				$ires	= @DbQuery($iquery,$link);
				$nres	= @DbNumRows($ires);
				if ($nres == 1) {
					$trf  = @DbFetchRow($ires);
					$ida += $trf[0];
					$oda += $trf[1];
				}
				@DbFreeResult($ires);
			}
			foreach(array_keys($prop['bw'][$dv][$if]) as $ndv){
				foreach(array_keys($prop['bw'][$dv][$if][$ndv]) as $nif){
					if($lis == 'e'){
						$iquery	= GenQuery('interfaces','s','dinerr,douterr','','',array('device','ifname'),array('=','='),array($dv,$if),array('AND') );
						$ires	= @DbQuery($iquery,$link);
						$nres	= @DbNumRows($ires);
						if ($nres == 1) {
							$err  = @DbFetchRow($ires);
							$ida += $err[0];
							$oda += $err[1];
						}
						$iquery	= GenQuery('interfaces','s','dinerr,douterr','','',array('device','ifname'),array('=','='),array($ndv,$nif),array('AND') );
						$ires	= @DbQuery($iquery,$link);
						$nres	= @DbNumRows($ires);
						if ($nres == 1) {
							$err  = @DbFetchRow($ires);
							$oda += $err[0];
							$ida += $err[1];
						}
						@DbFreeResult($ires);
					}
					if($ipi){
						if($net[$dv][$if])  {$ia = $net[$dv][$if];}
						if($net[$ndv][$nif]){$nia= $net[$ndv][$nif];}
					}
					if($ifi){
						if($lev == "f"){
							$in = $if;
							$nin= $nif;
						}else{
							$in = "$dv $if";
							$nin= "$ndv $nif";
						}
					}
					if ($ifi or $ipi){
						array_push($slabel,"$in $ia");
						array_push($elabel,"$nin $nia");
					}
					$bw  += $prop['bw'][$dv][$if][$ndv][$nif];
					$nbw += $prop['nbw'][$dv][$if][$ndv][$nif];
				}
			}
		}
	}
	$xl   = intval($x1  + $x2) / 2;
	$yl   = intval($y1  + $y2) / 2;
	$xi1  = intval($x1+($x2-$x1)/(1 + $lwt/10));
	$xi2  = intval($x2+($x1-$x2)/(1 + $lwt/10));
	$yi1  = intval($y1+($y2-$y1)/(1 + $lwt/10));
	$yi2  = intval($y2+($y1-$y2)/(1 + $lwt/10));
	$bwtxt= ZFix($bw) . "/" . ZFix($nbw);

	if($lis == 'r'){
		if($bw and $nbw){
			$ri = round($ida*800/$bw/$rrdstep);
			$ro = round($oda*800/$nbw/$rrdstep);
			if ($ri > intval($trfa + (100 - $trfa)/2) ){
				$lico = "red";
			}elseif ($ri > $trfa){
				$lico = "orange";
			}elseif ($ri > intval($trfw + $trfw/2) ){
				$lico = "purple";
			}elseif ($ri > $trfw){
				$lico = "blue";
			}else{
				$lico = "limegreen";
			}
			if ($ro > intval($trfa + (100 - $trfa)/2) ){
				$loco = "red";
			}elseif ($ro > $trfa){
				$loco = "orange";
			}elseif ($ro > intval($trfw + $trfw/2) ){
				$loco = "purple";
			}elseif ($ro > $trfw){
				$loco = "blue";
			}else{
				$loco = "limegreen";
			}
		}else{
			$lico = "gray";
			$loco = "gray";
			$ri   = "-";
			$ro   = "-";
		}
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$xl\" y2=\"$yl\" stroke=\"$lico\" stroke-width=\"4\"/>\n";
			$ltxt .= "	<line x1=\"$xl\" y1=\"$yl\" x2=\"$x2\" y2=\"$y2\" stroke=\"$loco\" stroke-width=\"4\"/>\n";
			$ltxt .= "	<text x=\"$xi2\" y=\"".($yi2-8)."\">${ri}%</text>\n";
			$ltxt .= "	<text x=\"$xi2\" y=\"".($yi1-8)."\">${ro}%</text>\n";
		}else{
			$ltxt .= "Imagesetthickness(\$image,4);\n";
			$ltxt .= "Imageline(\$image,$x1,$y1,$xl,$yl,\$$lico);\n";
			$ltxt .= "Imageline(\$image,$xl,$yl,$x2,$y2,\$$loco);\n";
			$ltxt .= "Imagesetthickness(\$image, 1);\n";
			$itxt .= "ImageString(\$image, 1,$xi2,".($yi2-8).",\"${ri}%\", \$black);\n";
			$itxt .= "ImageString(\$image, 1,$xi1,".($yi1-8).",\"${ro}%\", \$black);\n";
		}
	}elseif($lis == 'e'){
		if ($ida > $rrdstep ){
			$lico = "red";
		}elseif ($ida > intval($rrdstep/60) ){
			$lico = "orange";
		}elseif ($ida > 1){
			$lico = "blue";
		}else{
			$lico = "limegreen";
		}
		if ($oda > $rrdstep ){
			$loco = "red";
		}elseif ($oda > intval($rrdstep/60) ){
			$loco = "orange";
		}elseif ($oda > 1){
			$loco = "blue";
		}else{
			$loco = "limegreen";
		}
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$xl\" y2=\"$yl\" stroke=\"$lico\" stroke-width=\"4\"/>\n";
			$ltxt .= "	<line x1=\"$xl\" y1=\"$yl\" x2=\"$x2\" y2=\"$y2\" stroke=\"$loco\" stroke-width=\"4\"/>\n";
			$ltxt .= "	<text x=\"$xi2\" y=\"".($yi2-8)."\">$ida</text>\n";
			$ltxt .= "	<text x=\"$xi2\" y=\"".($yi1-8)."\">$oda</text>\n";
		}else{
			$ltxt .= "Imagesetthickness(\$image,4);\n";
			$ltxt .= "Imageline(\$image,$x1,$y1,$xl,$yl,\$$lico);\n";
			$ltxt .= "Imageline(\$image,$xl,$yl,$x2,$y2,\$$loco);\n";
			$ltxt .= "Imagesetthickness(\$image, 1);\n";
			$itxt .= "ImageString(\$image, 1,$xi2,".($yi2-8).",\"$ida\", \$black);\n";
			$itxt .= "ImageString(\$image, 1,$xi1,".($yi1-8).",\"$oda\", \$black);\n";
		}
	}elseif($bw == 11000000 or $bw == 54000000){
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" stroke=\"cornflowerblue\" stroke-dasharray=\"3,3\"/>\n";
		}else{
			$ltxt .= "imagesetstyle(\$image,array(\$navy,\$blue,\$cornflowerblue,\$wte,\$wte) );\n";
			$ltxt .= "Imageline(\$image,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED);\n";
		}
	}elseif($bw < 10000000){
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" stroke=\"limegreen\" />\n";
		}else{
			$ltxt .= "Imageline(\$image,$x1,$y1,$x2,$y2,\$limegreen);\n";
		}
	}elseif($bw < 100000000){
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" stroke=\"blue\" />\n";
		}else{
			$ltxt .= "Imageline(\$image,$x1,$y1,$x2,$y2,\$blue);\n";
		}
	}elseif($bw < 1000000000){
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" stroke=\"purple\" />\n";
		}else{
			$ltxt .= "Imageline(\$image,$x1,$y1,$x2,$y2,\$purple);\n";
		}
	}elseif($bw == 1000000000){
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" stroke=\"orange\" />\n";
		}else{
			$ltxt .= "Imageline(\$image,$x1,$y1,$x2,$y2,\$orange);\n";
		}
	}else{
		$lt = ($bw/1000000000 < 10)?($bw/1000000000):10;
		if($fmt == "svg"){
			$ltxt .= "	<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" stroke=\"red\" stroke-width=\"$lt\"/>\n";
		}else{
			$ltxt .= "imagesetthickness(\$image,$lt);\n";
			$ltxt .= "Imageline(\$image,$x1,$y1,$x2,$y2,\$red);\n";
			$ltxt .= "Imagesetthickness(\$image, 1);\n";
		}
	}

	if($lis	and is_array($rrdif) ){
		$opts = GraphOpts($lis,0,'Link Traffic',$bw);
		list($drawin,$drawout,$tit) = GraphTraffic($rrdif,'trf');
		exec("$rrdcmd graph log/$xl$yl.png -a PNG $opts $drawin $drawout");
		if($lis == "t"){
			if($fmt == "svg"){
				$itxt .= "	<text x=\"".($xl-16)."\" y=\"".($yl-18)."\" fill=\"green\">$bwtxt</text>\n";
			}else{
				$itxt .= "ImageString(\$image, 1,".($xl-16).", ".($yl-18).", \"$bwtxt\", \$green);\n";
			}
		}
		if($fmt == "svg"){
				$itxt .= "	<text x=\"".($xl-16)."\" y=\"".($yl-18)."\" fill=\"green\">no RRDs in SVG!</text>\n";
		}else{
			$ltxt .= "\$icon = Imagecreatefrompng(\"$xl$yl.png\");\n";
			$ltxt .= "\$w = Imagesx(\$icon);\n";
			$ltxt .= "\$h = Imagesy(\$icon);\n";
			$ltxt .= "Imagecopy(\$image, \$icon,$xl-\$w/2,$yl-\$h/2,0,0,\$w,\$h);\n";
			$ltxt .= "Imagedestroy(\$icon);\n";
			$ltxt .= "unlink(\"$xl$yl.png\");\n";
		}
	}elseif( preg_match("/[rw]/",$lis) ){
		if($fmt == "svg"){
			$itxt .= "	<text x=\"".($xl-16)."\" y=\"$yl\" fill=\"green\">$bwtxt</text>\n";
		}else{
			$itxt .= "ImageString(\$image, 1, ".($xl-16).",$yl, \"$bwtxt\", \$green);\n";
		}
	}
	$yof = 0;
	foreach ($slabel as $i){
		$i = preg_replace('/[$&]/','.', $i);
		if($fmt == "svg"){
			$itxt .= "	<text x=\"$xi2\" y=\"".($yi2+$yof)."\" fill=\"green\">$i</text>\n";
		}else{
			$itxt .= "ImageString(\$image, 1, $xi2, ".($yi2+$yof).", \"$i\", \$green);\n";
		}
		$yof += 8;
	}
	$yof = 0;
	foreach ($elabel as $i){
		if($fmt == "svg"){
			$itxt .= "	<text x=\"$xi1\" y=\"".($yi1+$yof)."\" fill=\"green\">".Safelabel($i)."</text>\n";
		}else{
			$itxt .= "ImageString(\$image, 1, $xi1, ".($yi1+$yof).", \"".Safelabel($i)."\", \$green);\n";
		}
		$yof += 8;
	}
	return array($ltxt,$itxt);
}
function Drawlink($x1, $y1, $x2, $y2, $prop)
{
    $slab = array();
    $elab = array();
    global $maplinks, $lev, $gra, $ifi, $ipi, $lwt, $lix, $liy, $net, $rrdstep, $rrdpath, $rrdcmd;
    if ($x1 == $x2) {
        $lix[$x1] += 2;
        $x1 += $lix[$x1];
        $x2 = $x1;
    }
    if ($y1 == $y2) {
        $liy[$y1] += 2;
        $y1 += $liy[$y1];
        $y2 = $y1;
    }
    foreach (array_keys($prop['bw']) as $dv) {
        foreach (array_keys($prop['bw'][$dv]) as $if) {
            if ($gra) {
                $rrd = "{$rrdpath}/" . rawurlencode($dv) . "/" . rawurlencode($if) . ".rrd";
                if (file_exists($rrd)) {
                    $rrdif["{$dv}-{$if}"] = $rrd;
                } else {
                    echo "RRD:{$rrd} not found!\n";
                }
            }
            foreach (array_keys($prop['bw'][$dv][$if]) as $ndv) {
                foreach (array_keys($prop['bw'][$dv][$if][$ndv]) as $nif) {
                    if ($ipi) {
                        if ($net[$dv][$if]) {
                            $ia = $net[$dv][$if];
                        }
                        if ($net[$ndv][$nif]) {
                            $nia = $net[$ndv][$nif];
                        }
                    }
                    if ($ifi) {
                        if ($lev == "f") {
                            $in = $if;
                            $nin = $nif;
                        } else {
                            $in = "{$dv} {$if}";
                            $nin = "{$ndv} {$nif}";
                        }
                    }
                    if ($ifi or $ipi) {
                        array_push($slab, "{$in} {$ia}");
                        array_push($elab, "{$nin} {$nia}");
                    }
                    $bw += $prop['bw'][$dv][$if][$ndv][$nif];
                    $nbw += $prop['nbw'][$dv][$if][$ndv][$nif];
                }
            }
        }
    }
    if ($bw == 11000000 or $bw == 54000000) {
        #$maplinks[] = "Imageline(\$image,$x1,$y1,$x2,$y2,\$org);";
        $maplinks[] = "imagesetstyle(\$image,array(\$bl2,\$bl2,\$wte,\$wte) );";
        $maplinks[] = "Imageline(\$image,{$x1},{$y1},{$x2},{$y2},IMG_COLOR_STYLED);";
    } elseif ($bw < 10000000) {
        $maplinks[] = "Imageline(\$image,{$x1},{$y1},{$x2},{$y2},\$grn);";
    } elseif ($bw < 100000000) {
        $maplinks[] = "Imageline(\$image,{$x1},{$y1},{$x2},{$y2},\$bl2);";
    } elseif ($bw < 1000000000) {
        $maplinks[] = "Imageline(\$image,{$x1},{$y1},{$x2},{$y2},\$bl3);";
    } elseif ($bw == 1000000000) {
        $maplinks[] = "Imageline(\$image,{$x1},{$y1},{$x2},{$y2},\$red);";
    } else {
        $maplinks[] = "imagesetthickness(\$image," . $bw / 1000000000 . ");";
        $maplinks[] = "Imageline(\$image,{$x1},{$y1},{$x2},{$y2},\$re2);";
        $maplinks[] = "Imagesetthickness(\$image, 1);";
    }
    $xl = intval($x1 + $x2) / 2;
    $yl = intval($y1 + $y2) / 2;
    $clab = ZFix($bw) . "/" . ZFix($nbw);
    if ($gra and is_array($rrdif)) {
        $opts = GraphOpts($gra, 0, 'Link Traffic');
        list($drawin, $drawout, $tit) = GraphTraffic($rrdif, 'trf');
        exec("{$rrdcmd} graph log/{$xl}{$yl}.png -a PNG {$opts} {$drawin} {$drawout}");
        if ($gra == "t") {
            $maplinks[] = "ImageString(\$image, 1,{$xl}-16,{$yl}-18,\"{$clab}\", \$grn);";
        }
        $maplinks[] = "\$icon = Imagecreatefrompng(\"{$xl}{$yl}.png\");";
        $maplinks[] = "\$w = Imagesx(\$icon);";
        $maplinks[] = "\$h = Imagesy(\$icon);";
        $maplinks[] = "Imagecopy(\$image, \$icon,{$xl}-\$w/2,{$yl}-\$h/2,0,0,\$w,\$h);";
        $maplinks[] = "Imagedestroy(\$icon);";
        $maplinks[] = "unlink(\"{$xl}{$yl}.png\");";
    } else {
        $maplinks[] = "ImageString(\$image, 1,{$xl}-16,{$yl},\"{$clab}\", \$grn);";
    }
    $xi1 = intval($x1 + ($x2 - $x1) / (1 + $lwt / 10));
    $xi2 = intval($x2 + ($x1 - $x2) / (1 + $lwt / 10));
    $yi1 = intval($y1 + ($y2 - $y1) / (1 + $lwt / 10));
    $yi2 = intval($y2 + ($y1 - $y2) / (1 + $lwt / 10));
    $yof = 0;
    foreach ($slab as $i) {
        $maplinks[] = "ImageString(\$image, 1,{$xi2},{$yi2}+{$yof},\"{$i}\", \$gr2);";
        $yof += 8;
    }
    $yof = 0;
    foreach ($elab as $i) {
        $maplinks[] = "ImageString(\$image, 1,{$xi1},{$yi1}+{$yof},\"{$i}\", \$gr2);";
        $yof += 8;
    }
}
Beispiel #4
0
function DrawLink($x1, $y1, $x2, $y2, $opt)
{
    global $fmt, $lev, $lix, $liy, $lis, $lit, $lil, $lal, $ipi, $ifi, $ifa, $pos, $xm, $ym, $debug;
    global $dev, $maplinks, $mapitems, $errlbl, $trflbl, $rrdcmd, $rrdstep, $nedipath, $liy;
    $liy["{$x1},{$y1},{$y2}"] = $liy["{$x1},{$y1},{$y2}"] ? 0 : 9;
    # offset coherent if/ip info on start of links from a node where link end is same y
    $liy["{$x2},{$y2},{$y1}"] = $liy["{$x2},{$y2},{$y1}"] ? 0 : 9;
    # offset coherent if/ip info on end of links from a node where link end is same y
    if ($x1 == $x2) {
        # offset coherent, horizontal links...
        $lix[$x1] += 2;
        $x1 += $lix[$x1];
        $x2 = $x1;
    } elseif ($y1 == $y2) {
        # offset coherent, verical links...
        $liy[$y1] += 2;
        $y1 += $liy[$y1];
        $y2 = $y1;
    }
    $xlm = intval($x1 + $x2) / 2;
    # middle of link
    $ylm = intval($y1 + $y2) / 2;
    $dctr1 = sqrt(pow($x1 - $xm / 2, 2) + pow($y2 - $ym / 2, 2));
    # Pythagoras tells distance to map center of either possible arc centerpoint
    $dctr2 = sqrt(pow($x2 - $xm / 2, 2) + pow($y1 - $ym / 2, 2));
    if ($dctr1 < $dctr2) {
        $xctr = $x1;
        $yctr = $y2;
        $xedg = $xr2 = $x2;
        $xr1 = $xedg - intval(($xedg - $xctr) / 8);
        $yedg = $yr1 = $y1;
        $yr2 = $yedg - intval(($yedg - $yctr) / 8);
    } else {
        $xctr = $x2;
        $yctr = $y1;
        $xedg = $xr1 = $x1;
        $xr2 = $xedg - intval(($xedg - $xctr) / 8);
        $yedg = $yr2 = $y2;
        $yr1 = $yedg - intval(($yedg - $yctr) / 8);
    }
    #$maplinks .= "ImageString(\$image, 3, $xctr,$yctr,\"C\", \$blue);\n";
    #$maplinks .= "ImageString(\$image, 3, $xedg,$yedg,\"E\", \$blue);\n";
    $futl = round($opt['ftr'] * 800 / $opt['fbw'] / $rrdstep, 1);
    list($t, $cf) = LinkStyle($opt['fbw'], $futl);
    if (is_numeric($opt['rbw']) and $opt['rbw'] > 0) {
        $rutl = round($opt['rtr'] * 800 / $opt['rbw'] / $rrdstep, 1);
        list($tr, $cr) = LinkStyle($opt['rbw'], $rutl);
    } else {
        $rutl = round($opt['rtr'] * 800 / $opt['fbw'] / $rrdstep, 1);
        list($tr, $cr) = LinkStyle($opt['fbw'], $rutl);
    }
    #$maplinks .= "ImageString(\$image, 3, $x1,$y1,\"Start\", \$blue);\n";
    $maplinks .= "\$stylarr = array(\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\n\t\t\t\t\t\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf}, \n\t\t\t\t\t\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf}, \n\t\t\t\t\t\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf},\${$cf}, \n\t\t\t\t\t\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\n\t\t\t\t\t\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\n\t\t\t\t\t\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\n\t\t\t\t\t\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr},\${$cr});\n";
    $maplinks .= "imagesetstyle(\$image,\$stylarr);\n";
    $lsty = 'IMG_COLOR_STYLED';
    #$maplinks .= "\$bru = imagecreatefrompng('../img/netr.png');\n";
    #$maplinks .= "imagesetbrush(\$image, \$bru);\n";
    #$lsty = 'IMG_COLOR_BRUSHED';
    if ($lis == "a1" or $x2 == $x1 and $y2 == $y1) {
        if ($x2 == $x1 and $y2 == $y1) {
            $y1 += 1;
            $w = 100;
            $h = 50;
            $s = 0;
            $e = 360;
            $xctr += 50;
            $xlm = $xctr + 50;
            $ylm = $y1;
        } else {
            $w = 2 * abs($x2 - $x1);
            $h = 2 * abs($y2 - $y1);
            $l = sqrt($w * $h) / 10;
            if ($xctr > $xedg) {
                # Left half
                if ($yctr > $yedg) {
                    # Upper Quadrant
                    $s = 180;
                    $e = 270;
                    $ylm -= $l;
                } else {
                    $s = 90;
                    $e = 180;
                    $ylm += $l;
                }
                $xlm -= $l;
            } else {
                if ($yctr > $yedg) {
                    $s = 270;
                    $e = 0;
                    $ylm -= $l;
                } else {
                    $s = 0;
                    $e = 90;
                    $ylm += $l;
                }
                $xlm += $l;
            }
        }
        if ($fmt == "svg") {
            $maplinks .= "<path d=\"M {$x1} {$y1} A {$w} {$h} 0 0 1 {$x2} {$y2}\" stroke=\"{$cf}\" stroke-width=\"{$t}\" fill = \"none\"/>\n";
        } else {
            $maplinks .= "imagesetthickness(\$image,{$t});\n";
            $maplinks .= "imagearc(\$image, {$xctr}, {$yctr}, {$w}, {$h}, {$s}, {$e}, {$lsty});\n";
        }
    } elseif ($lis == "a2" or $lis == "a3") {
        $xlm = $xedg;
        $ylm = $yedg;
        if ($fmt == "svg") {
            $maplinks .= "<line x1=\"{$x1}\" y1=\"{$y1}\" x2=\"{$xlm}\" y2=\"{$ylm}\" stroke=\"{$cf}\" stroke-width=\"{$t}\"/>\n";
            $maplinks .= "<line x1=\"{$xlm}\" y1=\"{$ylm}\" x2=\"{$x2}\" y2=\"{$y2}\" stroke=\"{$cf}\" stroke-width=\"{$t}\"/>\n";
        } elseif ($lis == "a3") {
            $maplinks .= "imagesetthickness(\$image,{$t});\n";
            $maplinks .= "imageline(\$image,{$x1},{$y1},{$xr1},{$yr1},{$lsty});\n";
            $maplinks .= "imageline(\$image,{$xr2},{$yr2},{$x2},{$y2},{$lsty});\n";
            $maplinks .= "imageline(\$image,{$xr1},{$yr1},{$xr2},{$yr2},{$lsty});\n";
        } else {
            $maplinks .= "imagesetthickness(\$image,{$t});\n";
            $maplinks .= "imageline(\$image,{$x1},{$y1},{$xlm},{$ylm},{$lsty});\n";
            $maplinks .= "imageline(\$image,{$xlm},{$ylm},{$x2},{$y2},{$lsty});\n";
        }
    } elseif ($lis == "a4") {
        $xlm = $xedg - intval(($xedg - $xctr) / 5);
        $ylm = $yedg - intval(($yedg - $yctr) / 5);
        if ($fmt == "svg") {
            $maplinks .= "<line x1=\"{$x1}\" y1=\"{$y1}\" x2=\"{$xlm}\" y2=\"{$ylm}\" stroke=\"{$cf}\" stroke-width=\"{$t}\"/>\n";
            $maplinks .= "<line x1=\"{$xlm}\" y1=\"{$ylm}\" x2=\"{$x2}\" y2=\"{$y2}\" stroke=\"{$cf}\" stroke-width=\"{$t}\"/>\n";
        } else {
            $maplinks .= "imagesetthickness(\$image,{$t});\n";
            $maplinks .= "imageline(\$image,{$x1},{$y1},{$xlm},{$ylm},{$lsty});\n";
            $maplinks .= "imageline(\$image,{$xlm},{$ylm},{$x2},{$y2},{$lsty});\n";
        }
    } else {
        if ($fmt == "svg") {
            $maplinks .= "<line x1=\"{$x1}\" y1=\"{$y1}\" x2=\"{$x2}\" y2=\"{$y2}\" stroke=\"{$cf}\" stroke-width=\"{$t}\"/>\n";
        } else {
            $maplinks .= "imagesetthickness(\$image,{$t});\n";
            $maplinks .= "imageline(\$image,{$x1},{$y1},{$x2},{$y2},{$lsty});\n";
        }
    }
    $xlm = $xlm + $lil / 10 * intval($xm / ($xlm - $xm / 2.1));
    # move info on a ray from the center
    $ylm = $ylm + $lil / 10 * intval($ym / ($ylm - $ym / 2.1));
    # .1 to avoid div 0
    if (is_array($opt['fif'])) {
        $yof = 2 + $liy["{$x1},{$y1},{$y2}"];
        foreach ($opt['fif'] as $fi) {
            $f = explode(';;', $fi);
            $ifal = ($ifa and $dev[$f[0]]['ifal'][$f[1]]) ? " " . $dev[$f[0]]['ifal'][$f[1]] : "";
            if (preg_match('/^[febd]/', $lit) and $rrdcmd) {
                $rrd = "{$nedipath}/rrd/" . rawurlencode($f[0]) . "/" . rawurlencode($f[1]) . ".rrd";
                if (file_exists($rrd)) {
                    $rrdif["{$f['0']}-{$f['1']}"] = $rrd;
                } elseif ($debug) {
                    echo "<div class=\"textpad alrm\">FRRD:{$rrd} not found!</div>\n";
                }
            }
            if ($lev > 3) {
                $ifl = ($ifi and $f[1] != '-') ? $f[1] : '';
            } else {
                $ifl = $ifi ? "{$f['0']} {$f['1']}" : "";
            }
            $ipl = $ipi ? $dev[$f[0]]['ifip'][$f[1]] : "";
            $alpha = atan2($ylm - $y1, $xlm - $x1);
            $mapitems .= DrawLabel($x1 + cos($alpha) * $lal, $y1 + sin($alpha) * $lal + $yof, Safelabel("{$ifl}{$ipl}{$ifal}"), 1, "gray");
            $yof += 9;
        }
    }
    if (is_array($opt['rif'])) {
        $yof = 2 + $liy["{$x2},{$y2},{$y1}"];
        foreach ($opt['rif'] as $ri) {
            $r = explode(';;', $ri);
            $ifal = ($ifa and $dev[$r[0]]['ifal'][$r[1]]) ? " " . $dev[$r[0]]['ifal'][$r[1]] : "";
            if ($lev > 3) {
                $ifl = ($ifi and $r[1] != '-') ? $r[1] : '';
            } else {
                $ifl = $ifi ? "{$r['0']} {$r['1']}" : "";
            }
            $ipl = $ipi ? $dev[$r[0]]['ifip'][$r[1]] : "";
            $alpha = atan2($ylm - $y2, $xlm - $x2);
            $mapitems .= DrawLabel($x2 + cos($alpha) * $lal, $y2 + sin($alpha) * $lal + $yof, Safelabel("{$ifl}{$ipl}{$ifal}"), 1, "gray");
            $yof += 9;
        }
    }
    if ($lit == 'w') {
        $mapitems .= DrawLabel($xlm, $ylm - 8, DecFix($opt['fbw']) . "/" . DecFix($opt['rbw']), 1, "green");
    } elseif ($lit == 't') {
        foreach ($opt['fty'] as $t => $c) {
            $ftyp .= $c > 1 ? "{$c}x {$t} " : "{$t} ";
        }
        foreach ($opt['rty'] as $t => $c) {
            $rtyp .= $c > 1 ? "{$c}x {$t} " : "{$t} ";
        }
        $mapitems .= DrawLabel($xlm, $ylm - 8, $ftyp, 1, "blue");
        $mapitems .= DrawLabel($xlm, $ylm - 16, $rtyp, 1, "blue");
    } elseif ($lit == 'l' and $pos != "d") {
        $mapitems .= DrawLabel($xlm, $ylm - 8, "{$futl}%/{$rutl}%", 3, "black");
    } elseif (is_array($rrdif)) {
        if (preg_match('/^f/', $lit)) {
            $opts = GraphOpts(substr($lit, 1), 0, 0, $trflbl, $opt['fbw']);
            list($draw, $tit) = GraphTraffic($rrdif, 'trf');
            $mapitems .= DrawLabel($xlm, $ylm - 25, DecFix($opt['fbw']) . "/" . DecFix($opt['rbw']), 1, "green");
        } elseif (preg_match('/^e/', $lit)) {
            $opts = GraphOpts(substr($lit, 1), 0, 0, $errlbl, 1);
            list($draw, $tit) = GraphTraffic($rrdif, 'err');
        } elseif (preg_match('/^d/', $lit)) {
            $opts = GraphOpts(substr($lit, 1), 0, 0, "Discards", 0);
            list($draw, $tit) = GraphTraffic($rrdif, 'dsc');
        } else {
            $opts = GraphOpts(substr($lit, 1), 0, 0, "Broadcasts", 0);
            list($draw, $tit) = GraphTraffic($rrdif, 'brc');
        }
        exec("{$rrdcmd} graph map/{$xlm}{$ylm}.png -a PNG {$opts} {$draw}");
        if ($fmt == "json") {
        } elseif ($fmt == "svg") {
            $mapitems .= "\t<text x=\"{$xlm}\" y=\"{$ylm}\" fill=\"gray\">no RRDs in SVG!</text>\n";
        } else {
            $mapitems .= "\$icon = Imagecreatefrompng(\"{$xlm}{$ylm}.png\");\n";
            $mapitems .= "\$w = Imagesx(\$icon);\n";
            $mapitems .= "\$h = Imagesy(\$icon);\n";
            $mapitems .= "Imagecopy(\$image, \$icon,{$xlm}-\$w/2,{$ylm}-\$h/2,0,0,\$w,\$h);\n";
            $mapitems .= "Imagedestroy(\$icon);\n";
            $mapitems .= "unlink(\"{$xlm}{$ylm}.png\");\n";
        }
    }
}
Beispiel #5
0
    $draw .= "DEF:monsl={$rrd}:monsl:AVERAGE STACK:monsl#ccaa00:\"Slow\" ";
    $draw .= "DEF:monal={$rrd}:monal:AVERAGE STACK:monal#884400:\"Down\\l\" ";
} elseif ($typ == 'msg') {
    $rrd = "{$nedipath}/rrd/top.rrd";
    if ($safe) {
        $debug = file_exists("{$rrd}") ? "" : "RRD {$rrd} not found!";
    }
    $tit = "{$msglbl} / " . round($rrdstep / 60) . "m";
    $draw .= "DEF:msg50={$rrd}:msg50:AVERAGE AREA:msg50#44cc44:\"" . substr($mlvl[50], 0, 4) . "\" ";
    $draw .= "DEF:msg100={$rrd}:msg100:AVERAGE STACK:msg100#4444cc:\"" . substr($mlvl[100], 0, 4) . "\" ";
    $draw .= "DEF:msg150={$rrd}:msg150:AVERAGE STACK:msg150#cccc44:\"" . substr($mlvl[150], 0, 4) . "\" ";
    $draw .= "DEF:msg200={$rrd}:msg200:AVERAGE STACK:msg200#cc8844:\"" . substr($mlvl[200], 0, 4) . "\" ";
    $draw .= "DEF:msg250={$rrd}:msg250:AVERAGE STACK:msg250#cc4444:\"" . substr($mlvl[250], 0, 4) . "\\l\" ";
} elseif ($typ == 'trf' or $typ == 'err' or $typ == 'brc' or $typ == 'dsc' or $typ == 'sta') {
    foreach ($_GET['if'] as $i) {
        $rrd[$i] = "{$nedipath}/rrd/" . rawurlencode($_GET['dv']) . "/" . rawurlencode($i) . ".rrd";
        # rawurlencode for valid filenames!
        if ($safe) {
            $debug = file_exists("{$rrd[$i]}") ? "" : "RRD {$rrd[$i]} not found!";
        }
    }
    list($draw, $tit) = GraphTraffic($rrd, $typ);
}
$opts = GraphOpts($gsz, $sta, $end, $tit, $opt);
if ($debug) {
    echo "<b>{$debug}</b>";
    echo "<pre>{$rrdcmd} graph - -a PNG {$opts}\n\t{$draw}</pre>";
} else {
    header("Content-type: image/png");
    passthru("{$rrdcmd} graph - -a PNG {$opts} {$draw}");
}