コード例 #1
0
function send_mobile_mail_AU($mail_to_name, $mail_to, $mail_title, $mail_body, $mail_from, $mail_from_name)
{
    $mailbody = Arrange($mail_body);
    $mailtitle = iconv("SHIFT-JIS", "iso-2022-jp", $mail_title);
    $mailtitle = mb_encode_mimeheader($mailtitle, "SJIS");
    $mailheaders = "From: " . $mail_from;
    $bodytext = iconv("shift-jis", "iso-2022-jp", stripslashes($mail_body));
    if (mail($mail_to, $mailtitle, $bodytext, $mailheaders)) {
        return 1;
    } else {
        return 0;
    }
}
コード例 #2
0
function Drawlevel($locs,$xs,$ys,$l) {

	global $link,$locsep,$resmsg;
	global $lev,$loi,$liwgt;
	global $mapbg,$mapinfo,$mapframes,$maplinks,$mapitems,$imgmap;

	$nloc   = count($locs);
	if($nloc == 1){
		$scalx = 0;
		$scaly = 0;
	}else{
		$scalx = 1.3;
		$scaly = 1;
	}
	$locnum = 0;
	foreach(Arrange($locs) as $loc){
		$locnum++;
		if( 1 ){
			$phi  = $cro * M_PI/180 + 2 * $locnum * M_PI / $nloc;
			$locw = pow($ncl,$liwgt/10);
			$x = intval($xs + $l * cos($phi) * $scalx / $locw);
			$y = intval($ys + $l * sin($phi) * $scaly / $locw);
		}
		if( is_array($locs[$loc]) ){
			if ($loi and count($locs[$loc]) > 1){$mapinfo .= Drawitem($x,$y,'0',"$loc",'ci');}
			Drawlevel($locs[$loc],$x,$y,($l/2));
		}else{
			$mapitems .= Drawitem($x,$y,$locs[$loc],$loc,$lev);
			$area = ($x-20) .",". ($y-20) .",". ($x+20) .",". ($y+20);
			$imgmap .= "<area href=?flt=". rawurlencode("$loc$locsep") ."&lev=".Childlev($lev)."&loi=1&draw=1 coords=\"$area\" shape=rect title=\"Show\">\n";
		}
	}
}
コード例 #3
0
ファイル: libmap.php プロジェクト: pl0o0f/nedi-puppet
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]);
                }
            }
        }
    }
}
コード例 #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];
            }
        }
    }
}
コード例 #5
0
function Map()
{
    global $lev, $fco, $xm, $ym, $xo, $yo, $csi, $bsi, $fsi, $cro, $bro, $cwt, $loi, $bwt, $dev, $ndev, $bdev, $fdev;
    global $devlink, $ctylink, $bldlink, $rdevlink, $rctylink, $rbldlink, $nctylink, $nbldlink, $imgmap;
    $ncty = count($ndev);
    if ($ncty == 1) {
        $ctyscalx = 0;
        $ctyscaly = 0;
    } else {
        $ctyscalx = 1.3;
        $ctyscaly = 1;
    }
    $ctynum = 0;
    $bldnum = 0;
    foreach (Arrange($ndev, "c") as $cty) {
        $phi = $cro * M_PI / 180 + 2 * $ctynum * M_PI / $ncty;
        $ctynum++;
        $ncl = $nctylink[$cty] ? $nctylink[$cty] : 1;
        $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);
        $nbld = count($ndev[$cty]);
        if ($lev == "c") {
            Drawitem($xct[$cty], $yct[$cty], $nbld, $cty, $lev);
            $area = $xct[$cty] - 20 . "," . ($yct[$cty] - 20) . "," . ($xct[$cty] + 20) . "," . ($yct[$cty] + 20);
            $imgmap .= "<area href=?flt=" . urlencode($cty) . "&lev=b&loi=1&draw=1 coords=\"{$area}\" shape=rect title=\"Show {$nbld} buildings\">\n";
        } else {
            if ($nbld != 1) {
                $bldscalx = 1.3;
                $bldscaly = 1;
                if ($loi and $cty != "-") {
                    Drawitem($xct[$cty], $yct[$cty], '0', $cty, 'ci');
                }
            }
            foreach (Arrange($ndev[$cty], "b") as $bld) {
                $eps = $bro * M_PI / 180 + 2 * $bldnum * M_PI / $nbld;
                $bldnum++;
                $nbl = $nbldlink[$bld] ? $nbldlink[$bld] : 1;
                $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") {
                    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=" . urlencode($bld) . "&lev=f&loi=1&ipi=1&draw=1 coords=\"{$area}\" shape=rect title=\"Show " . $bdev[$cty][$bld] . " devices\">\n";
                } else {
                    $cury = $nflr = $mdfl = 0;
                    $nflr = count($ndev[$cty][$bld]);
                    $mdfl = max(array_values($fdev[$cty][$bld]));
                    foreach (array_keys($fdev[$cty][$bld]) as $flr) {
                        if ($fdev[$cty][$bld][$flr] > $fco) {
                            $afl = intval($fdev[$cty][$bld][$flr] / $fco);
                            $rem = bcmod($fdev[$cty][$bld][$flr], $fco);
                            if ($rem) {
                                $nflr = $nflr + $afl;
                            } else {
                                $nflr = $nflr + $afl - 1;
                            }
                            $mdfl = $fco;
                        }
                    }
                    $xb1 = intval($xbl[$bld] - $fsi / 2 * $mdfl - 50);
                    $yb1 = intval($ybl[$bld] - $fsi / 2 * $nflr + $fsi - 50);
                    $xb2 = intval($xbl[$bld] + $fsi / 2 * $mdfl - $fsi + 50);
                    $yb2 = intval($ybl[$bld] + $fsi / 2 * $nflr + 40);
                    Drawbox($xb1, $yb1, $xb2, $yb2, $bld);
                    uksort($ndev[$cty][$bld], "floorsort");
                    foreach (array_keys($ndev[$cty][$bld]) as $flr) {
                        $cury++;
                        $curx = 0;
                        usort($ndev[$cty][$bld][$flr], "Roomsort");
                        $xf = $xbl[$bld] - intval($fsi * $mdfl / 2 + 40);
                        $yf = $ybl[$bld] + intval($fsi * ($cury - $nflr / 2));
                        Drawitem($xf, $yf, 0, $flr, "fl");
                        foreach ($ndev[$cty][$bld][$flr] as $dv) {
                            if ($curx == $fco) {
                                $curx = 0;
                                $cury++;
                            }
                            $xd[$dv] = $xbl[$bld] + intval($fsi * ($curx - $mdfl / 2));
                            $yd[$dv] = $ybl[$bld] + intval($fsi * ($cury - $nflr / 2));
                            Drawitem($xd[$dv], $yd[$dv], '0', $dv, $lev);
                            $area = $xd[$dv] - 20 . "," . ($yd[$dv] - 20) . "," . ($xd[$dv] + 20) . "," . ($yd[$dv] + 20);
                            $imgmap .= "<area href=Devices-Status.php?dev=" . urlencode($dv) . " coords=\"{$area}\" shape=rect title=\"Show {$dv} Status\">\n";
                            $curx++;
                        }
                    }
                }
            }
        }
    }
    if ($lev == "c") {
        foreach (array_keys($ctylink) as $ctyl) {
            foreach (array_keys($ctylink[$ctyl]) as $ctyn) {
                Drawlink($xct[$ctyl], $yct[$ctyl], $xct[$ctyn], $yct[$ctyn], $ctylink[$ctyl][$ctyn]);
            }
        }
    } elseif ($lev == "b") {
        foreach (array_keys($bldlink) as $bldl) {
            foreach (array_keys($bldlink[$bldl]) as $bldn) {
                Drawlink($xbl[$bldl], $ybl[$bldl], $xbl[$bldn], $ybl[$bldn], $bldlink[$bldl][$bldn]);
            }
        }
    } elseif ($lev == "f") {
        foreach (array_keys($devlink) as $devl) {
            foreach (array_keys($devlink[$devl]) as $devn) {
                Drawlink($xd[$devl] - 8, $yd[$devl] - 4, $xd[$devn] - 8, $yd[$devn] - 4, $devlink[$devl][$devn]);
            }
        }
    }
}