Exemplo n.º 1
0
} elseif ($do == 'Delete' and $id) {
    $query = GenQuery('locations', 'd', '', '', '', array('id'), array('='), array($id));
    if (!@DbQuery($query, $link)) {
        echo "<h4>" . DbError($link) . "</h4>";
    } else {
        echo "<h3>Location {$reg} {$cty} {$bld} {$delokmsg}</h3>";
    }
}
if ($bld) {
    $query = GenQuery('locations', 's', 'id,x,y,comment', '', '', array('region', 'city', 'building'), array('=', '=', '='), array($reg, $cty, $bld), array('AND', 'AND'));
    $mapbg = TopoMap($reg, $cty);
    $nam = $bld;
    $com = "Building with " . $lopt[$reg][$cty][$bld] . " devices on {$now}";
} elseif ($cty) {
    $query = GenQuery('locations', 's', 'id,x,y,comment', '', '', array('region', 'city', 'building'), array('=', '=', '='), array($reg, $cty, ''), array('AND', 'AND'));
    $mapbg = TopoMap($reg);
    $nam = $cty;
    $com = "City with " . count(array_keys($lopt[$reg][$cty])) . " buildings on {$now}";
} elseif ($reg) {
    $query = GenQuery('locations', 's', 'id,x,y,comment', '', '', array('region', 'city', 'building'), array('=', '=', '='), array($reg, '', ''), array('AND', 'AND'));
    $nam = $reg;
    $com = "Region with " . count(array_keys($lopt[$reg])) . " cities on {$now}";
} else {
    $query = "";
}
if ($query) {
    $res = @DbQuery($query, $link);
    $nloc = @DbNumRows($res);
    if ($nloc == 1) {
        list($id, $x, $y, $com) = @DbFetchRow($res);
        $loco = 1;
Exemplo n.º 2
0
function TopoMap($reg = "", $cty = "")
{
    if ($reg) {
        if ($cty) {
            if (file_exists("log/map-{$reg}-{$cty}.png")) {
                return "map-{$reg}-{$cty}.png";
            } else {
                return TopoMap($reg);
            }
        } else {
            if (file_exists("log/map-{$reg}.png")) {
                return "map-{$reg}.png";
            }
        }
    }
    return "map-top.png";
}
Exemplo n.º 3
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 );
}
Exemplo n.º 4
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];
            }
        }
    }
}
Exemplo n.º 5
0
function DbCoords($r = '', $c = '', $b = '')
{
    global $mapbg, $link;
    $query = GenQuery('locations', 's', 'x,y,locdesc', '', '', array('region', 'city', 'building'), array('=', '=', '='), array($r, $c, $b), array('AND', 'AND'));
    $res = DbQuery($query, $link);
    $nloc = DbNumRows($res);
    if (!$c) {
        $r = "";
    } elseif (!$b) {
        $c = "";
    }
    # Clear those for Topomap()
    if ($nloc == 1 and $mapbg == TopoMap($r, $c)) {
        return DbFetchRow($res);
    }
}
Exemplo n.º 6
0
	$ico = 'img/cityg.png';
	$res = DbQuery( GenQuery('locations','s','id,x,y,ns,ew,locdesc','','',array('region','city','building'),array('=','=','='),array($reg,$cty,''),array('AND','AND') ),$link);
	if ( DbNumRows($res) == 1){
		$locex = 1;
		list($id,$x,$y,$ns,$ew,$com) = DbFetchRow($res);
		$geost = ($dem)?"$com, $geost":$nam;
	}else{
		$locex = 0;
		$geost = ($dem)?"$cty, $geost":$nam;
		$com = "$place[c], ".count(array_keys($lopt[$reg][$cty]))." buildings ($now)";
	}
}
if($bld){
	$z   = "16";
	$nam = "$bld $cty, $reg";
	if(!$map) $bgm = TopoMap($reg,$cty);
	$ico = preg_match("/$redbuild/",$bld)?'img/bldsr.png':'img/blds.png';
	$res = DbQuery( GenQuery('locations','s','id,x,y,ns,ew,locdesc','','',array('region','city','building'),array('=','=','='),array($reg,$cty,$bld),array('AND','AND') ),$link);
	if ( DbNumRows($res) == 1){
		$locex = 1;
		list($id,$x,$y,$ns,$ew,$com) = DbFetchRow($res);
		$geost = ($dem)?"$com $geost":$nam;
	}else{
		$locex = 0;
		$geost = ($dem)?"$bld $geost":$nam;
		$com = "$place[b], ".$lopt[$reg][$cty][$bld] ." devices ($now)";
	}
}
DbFreeResult($res);
$ns /= 10000000;
$ew /= 10000000;
Exemplo n.º 7
0
function TopoMap($reg = "", $cty = "")
{
    global $sub, $debug;
    $cp = '';
    $rp = '';
    $p = $sub ? "../topo" : "topo";
    if ($reg) {
        if ($cty) {
            $cp = preg_replace('/\\W/', '', $reg) . '/' . preg_replace('/\\W/', '', $cty);
            if (file_exists("{$p}/{$cp}/background.jpg")) {
                $mapbg = "{$cp}/background.jpg";
            } else {
                $mapbg = TopoMap($reg);
            }
        } else {
            $rp = preg_replace('/\\W/', '', $reg);
            if (file_exists("{$p}/{$rp}/background.jpg")) {
                $mapbg = "{$rp}/background.jpg";
            }
        }
    }
    if (!$mapbg) {
        $mapbg = "background.jpg";
    }
    if ($debug) {
        echo "<div class=\"textpad imga\">Mapbg:Sub={$sub} Path={$p} {$rp} {$cp} BG={$mapbg}</div>\n";
    }
    return $mapbg;
}