Ejemplo n.º 1
0
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
    global $config;
    if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
        $dst_host = $hostname . '.' . $config['mydomain'];
    } else {
        $dst_host = $hostname;
    }
    d_echo("discovering {$dst_host}\n");
    $ip = gethostbyname($dst_host);
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
        // $ip isn't a valid IP so it must be a name.
        if ($ip == $dst_host) {
            d_echo("name lookup of {$dst_host} failed\n");
            log_event("{$method} discovery of " . $dst_host . " failed - Check name lookup", $device['device_id'], 'discovery');
            return false;
        }
    } elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) {
        // gethostbyname returned a valid $ip, was $dst_host an IP?
        if ($config['discovery_by_ip'] === false) {
            d_echo('Discovery by IP disabled, skipping ' . $dst_host);
            log_event("{$method} discovery of " . $dst_host . " failed - Discovery by IP disabled", $device['device_id'], 'discovery');
            return false;
        }
    }
    d_echo("ip lookup result: {$ip}\n");
    $dst_host = rtrim($dst_host, '.');
    // remove trailing dot
    if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
        d_echo("{$ip} in an excluded network - skipping\n");
        return false;
    }
    if (match_network($config['nets'], $ip)) {
        try {
            $remote_device_id = addHost($dst_host, '', '161', 'udp', $config['distributed_poller_group']);
            $remote_device = device_by_id_cache($remote_device_id, 1);
            echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
            discover_device($remote_device);
            device_by_id_cache($remote_device_id, 1);
            if ($remote_device_id && is_array($device) && !empty($method)) {
                $extra_log = '';
                $int = ifNameDescr($interface);
                if (is_array($int)) {
                    $extra_log = ' (port ' . $int['label'] . ') ';
                }
                log_event('Device ' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'discovery');
            } else {
                log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - Check ping and SNMP access", $device['device_id'], 'discovery');
            }
            return $remote_device_id;
        } catch (HostExistsException $e) {
            // already have this device
        } catch (Exception $e) {
            log_event("{$method} discovery of " . $dst_host . " ({$ip}) failed - " . $e->getMessage());
        }
    } else {
        d_echo("{$ip} not in a matched network - skipping\n");
    }
    //end if
}
Ejemplo n.º 2
0
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
    global $config, $debug;
    if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
        $dst_host = $hostname . '.' . $config['mydomain'];
    } else {
        $dst_host = $hostname;
    }
    if ($debug) {
        echo "discovering {$dst_host}\n";
    }
    $ip = gethostbyname($dst_host);
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
        // $ip isn't a valid IP so it must be a name.
        if ($ip == $dst_host) {
            if ($debug) {
                echo "name lookup of {$dst_host} failed\n";
            }
            return false;
        }
    }
    if ($debug) {
        echo "ip lookup result: {$ip}\n";
    }
    $dst_host = rtrim($dst_host, '.');
    // remove trailing dot
    if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
        if ($debug) {
            echo "{$ip} in an excluded network - skipping\n";
        }
        return false;
    }
    if (match_network($config['nets'], $ip)) {
        $remote_device_id = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']);
        if ($remote_device_id) {
            $remote_device = device_by_id_cache($remote_device_id, 1);
            echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
            discover_device($remote_device);
            device_by_id_cache($remote_device_id, 1);
            if ($remote_device_id && is_array($device) && !empty($method)) {
                $extra_log = '';
                $int = ifNameDescr($interface);
                if (is_array($int)) {
                    $extra_log = ' (port ' . $int['label'] . ') ';
                }
                log_event('Device $' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'system');
            } else {
                log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - check ping and SNMP access", $device['device_id'], 'system');
            }
            return $remote_device_id;
        }
    } else {
        if ($debug) {
            echo "{$ip} not in a matched network - skipping\n";
        }
    }
    //end if
}
Ejemplo n.º 3
0
    generate_front_box('device-down', generate_device_link($device, shorthost($device['hostname'])) . '<br />
    <span class=list-device-down>Device Down</span> <br />
    <span class=body-date-1>' . truncate($device['location'], 20) . '</span>');
    ++$count_boxes;
}
if (is_admin() === true || is_read() === true) {
    $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT " . $config['front_page_down_box_limit'];
} else {
    $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND  I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1'  LIMIT " . $config['front_page_down_box_limit'];
}
// These things need to become more generic, and more manageable across different frontpages... rewrite inc :>
// Port down boxes
if ($config['warn']['ifdown']) {
    foreach (dbFetchRows($sql) as $interface) {
        if (!$interface['deleted']) {
            $interface = ifNameDescr($interface);
            generate_front_box('alert alert-danger', generate_device_link($interface, shorthost($interface['hostname'])) . "<br />\n        <span class=\"interface-updown\">Port Down</span><br />\n<!--      <img src='graph.php?type=bits&amp;if=" . $interface['port_id'] . '&amp;from=' . $config['time']['day'] . '&amp;to=' . $config['time']['now'] . "&amp;width=100&amp;height=32' /> -->\n        " . generate_port_link($interface, truncate(makeshortif($interface['label']), 13, '')) . ' <br />
        ' . ($interface['ifAlias'] ? '<span class="body-date-1">' . truncate($interface['ifAlias'], 20, '') . '</span>' : ''));
            ++$count_boxes;
        }
    }
}
/*
    FIXME service permissions? seem nonexisting now.. */
// Service down boxes
if (is_admin() === true || is_read() === true) {
    $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '2' LIMIT " . $config['front_page_down_box_limit'];
    $param[] = '';
} else {
    $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '2' LIMIT " . $config['front_page_down_box_limit'];
    $param[] = $_SESSION['user_id'];
Ejemplo n.º 4
0
function generate_ap_link($args, $text = null, $type = null)
{
    global $config;
    $args = ifNameDescr($args);
    if (!$text) {
        $text = fixIfName($args['label']);
    }
    if ($type) {
        $args['graph_type'] = $type;
    }
    if (!isset($args['graph_type'])) {
        $args['graph_type'] = 'port_bits';
    }
    if (!isset($args['hostname'])) {
        $args = array_merge($args, device_by_id_cache($args['device_id']));
    }
    $content = '<div class=list-large>' . $args['text'] . ' - ' . fixifName($args['label']) . '</div>';
    if ($args['ifAlias']) {
        $content .= $args['ifAlias'] . '<br />';
    }
    $content .= "<div style=\\'width: 850px\\'>";
    $graph_array = array();
    $graph_array['type'] = $args['graph_type'];
    $graph_array['legend'] = 'yes';
    $graph_array['height'] = '100';
    $graph_array['width'] = '340';
    $graph_array['to'] = $config['time']['now'];
    $graph_array['from'] = $config['time']['day'];
    $graph_array['id'] = $args['accesspoint_id'];
    $content .= generate_graph_tag($graph_array);
    $graph_array['from'] = $config['time']['week'];
    $content .= generate_graph_tag($graph_array);
    $graph_array['from'] = $config['time']['month'];
    $content .= generate_graph_tag($graph_array);
    $graph_array['from'] = $config['time']['year'];
    $content .= generate_graph_tag($graph_array);
    $content .= '</div>';
    $url = generate_ap_url($args);
    if (port_permitted($args['interface_id'], $args['device_id'])) {
        return overlib_link($url, $text, $content, null);
    } else {
        return fixifName($text);
    }
}
Ejemplo n.º 5
0
                echo " <b style='color: #a10000;'>v6</b>";
            }
            if ($int_links_v4[$int_link]) {
                echo " <b style='color: #00a100'>v4</b>";
            }
            $br = "<br />";
        }
    }
    #     unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
}
if ($port_details && $config['enable_port_relationship'] === TRUE) {
    foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", array($port['port_id'])) as $pseudowire) {
        #`port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`
        $pw_peer_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($pseudowire['peer_device_id']));
        $pw_peer_int = dbFetchRow("SELECT * FROM `ports` AS I, pseudowires AS P WHERE I.device_id = ? AND P.cpwVcID = ? AND P.port_id = I.port_id", array($pseudowire['peer_device_id'], $pseudowire['cpwVcID']));
        $pw_peer_int = ifNameDescr($pw_peer_int);
        echo "{$br}<img src='images/16/arrow_switch.png' align=absmiddle><b> " . generate_port_link($pw_peer_int, makeshortif($pw_peer_int['label'])) . " on " . generate_device_link($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . "</b>";
        $br = "<br />";
    }
    foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) {
        echo "{$br}<img src='images/16/brick_link.png' align=absmiddle> <strong>" . generate_port_link($member) . " (PAgP)</strong>";
        $br = "<br />";
    }
    if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) {
        $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id']));
        echo "{$br}<img src='images/16/bricks.png' align=absmiddle> <strong>" . generate_port_link($parent) . " (PAgP)</strong>";
        $br = "<br />";
    }
    foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $higher_if) {
        if ($higher_if['port_id_high']) {
            $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']);
Ejemplo n.º 6
0
    $link_out_used = $items['local_ifoutoctets_rate'] * 8 / $items['local_ifspeed'] * 100;
    if ($link_in_used > $link_out_used) {
        $link_used = $link_in_used;
    } else {
        $link_used = $link_out_used;
    }
    $link_used = round($link_used, -1);
    if ($link_used > 100) {
        $link_used = 100;
    }
    $link_color = $config['network_map_legend'][$link_used];
    $id1 = $items['local_port_id'] . ':' . $items['remote_port_id'];
    $id2 = $items['remote_port_id'] . ':' . $items['local_port_id'];
    if (!in_array($id1, $tmp_link_ids) || !in_array($id2, $tmp_link_ids)) {
        $local_port = ifNameDescr($local_port);
        $remote_port = ifNameDescr($remote_port);
        $tmp_links[] = array('from' => $items['local_device_id'], 'to' => $items['remote_device_id'], 'label' => shorten_interface_type($local_port['ifName']) . ' > ' . shorten_interface_type($remote_port['ifName']), 'title' => generate_port_link($local_port, "<img src='graph.php?type=port_bits&amp;id=" . $items['local_port_id'] . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;width=100&amp;height=20&amp;legend=no&amp;bg=" . str_replace("#", "", $row_colour) . "'>\n", '', 0, 1), 'width' => $width, 'color' => $link_color);
    }
    array_push($tmp_link_ids, $id1);
    array_push($tmp_link_ids, $id2);
}
$node_devices = $tmp_devices;
$nodes = json_encode($node_devices);
$edges = json_encode($tmp_links);
if (count($node_devices) > 1 && count($tmp_links) > 0) {
    ?>
 
<div id="visualization"></div>
<script src="js/vis.min.js"></script>
<script type="text/javascript">
var height = $(window).height() - 100;
Ejemplo n.º 7
0
 } elseif ($link['ifSpeed'] >= "10000000") {
     $info = "style=\"setlinewidth(1)\"";
 } else {
     $info = "style=\"setlinewidth(1)\"";
 }
 $src = $device['hostname'];
 if ($remote_interface_id) {
     $dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '{$remote_interface_id}'  AND D.device_id = I.device_id"), 0);
     $dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '{$remote_interface_id}'  AND D.device_id = I.device_id"), 0);
 } else {
     $dst_host = $link['remote_hostname'];
     $dst = $link['remote_hostname'];
 }
 $sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['local_interface_id'])), $device);
 if ($remote_interface_id) {
     $dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['remote_interface_id'])));
 } else {
     $dif['label'] = $link['remote_port'];
     $dif['interface_id'] = $link['remote_hostname'] . $link['remote_port'];
 }
 $map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"/device/" . $device['device_id'] . "/interface/{$local_interface_id}/\"]\n";
 if (!$ifdone[$src][$sif['interface_id']]) {
     $map .= "\"{$src}\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n";
     $ifdone[$src][$sif['interface_id']] = 1;
 }
 $map .= "\"{$dst}\" [URL=\"/device/{$dst_host}/map/\" fontsize=20 shape=box3d]\n";
 if ($dst_host == $device['device_id']) {
     $map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"/device/{$dst_host}/interface/{$remote_interface_id}/\"]\n";
 } else {
     $map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"/device/{$dst_host}/interface/{$remote_interface_id}/\"]\n";
 }
Ejemplo n.º 8
0
function generateiflink($interface, $text = 0, $type = NULL)
{
    global $twoday;
    global $now;
    global $config;
    global $day;
    global $month;
    $interface = ifNameDescr($interface);
    if (!$text) {
        $text = fixIfName($interface['label']);
    }
    if (isset($type)) {
        $interface['graph_type'] = $type;
    } else {
        $interface['graph_type'] = 'port_bits';
    }
    if (!isset($interface['hostname'])) {
        $interface = array_merge($interface, device_by_id_cache($interface['device_id']));
    }
    $class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
    $graph_url = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&amp;from={$day}&amp;to={$now}&amp;width=400&amp;height=100&amp;type=" . $interface['graph_type'];
    $graph_url_month = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&amp;from={$month}&amp;to={$now}&amp;width=400&amp;height=100&amp;type=" . $interface['graph_type'];
    $device_id = getifhost($interface['interface_id']);
    $url = $config['base_url'] . "/device/{$device_id}/interface/" . $interface['interface_id'] . "/";
    $contents = "<div class=list-large>" . $interface['hostname'] . " - " . fixifName($interface['label']) . "</div>";
    if ($interface['ifAlias']) {
        $contents .= htmlentities($interface['ifAlias'] . "<br />");
    }
    $contents .= "<img src=\\'{$graph_url}\\'><br /><img src=\\'{$graph_url_month}\\'>";
    $link = overlib_link($url, $text, $contents, $class);
    return $link;
}
Ejemplo n.º 9
0
     $src = md5($src);
 }
 if ($remote_port_id) {
     $dst = dbFetchCell("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.port_id = ? AND D.device_id = I.device_id", array($remote_port_id));
     $dst_host = dbFetchCell("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.port_id = ?  AND D.device_id = I.device_id", array($remote_port_id));
 } else {
     unset($dst_host);
     $dst = $link['remote_hostname'];
 }
 if ($anon) {
     $dst = md5($dst);
     $src = md5($src);
 }
 $sif = ifNameDescr(dbFetchRow("SELECT * FROM ports WHERE `port_id` = ?", array($link['local_port_id'])), $device);
 if ($remote_port_id) {
     $dif = ifNameDescr(dbFetchRow("SELECT * FROM ports WHERE `port_id` = ?", array($link['remote_port_id'])));
 } else {
     $dif['label'] = $link['remote_port'];
     $dif['port_id'] = $link['remote_hostname'] . '/' . $link['remote_port'];
 }
 if ($where == "") {
     if (!$ifdone[$dst][$dif['port_id']] && !$ifdone[$src][$sif['port_id']]) {
         $map .= "\"{$src}\" -> \"" . $dst . "\" [weight=500000, arrowsize=0, len=0];\n";
     }
     $ifdone[$src][$sif['port_id']] = 1;
 } else {
     $map .= "\"" . $sif['port_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/device=" . $device['device_id'] . "/tab=port/port={$local_port_id}/\"]\n";
     if (!$ifdone[$src][$sif['port_id']]) {
         $map .= "\"{$src}\" -> \"" . $sif['port_id'] . "\" [weight=500000, arrowsize=0, len=0];\n";
         $ifdone[$src][$sif['port_id']] = 1;
     }
Ejemplo n.º 10
0
    echo '<tr>
          <td colspan="4">';
    echo overlib_link($link, $graph, $overlib_content, null);
    echo '  </td>
        </tr>';
    echo '
    <tr>
      <td><img src="images/16/connect.png" align="absmiddle"> ' . $ports['total'] . '</td>
      <td><img src="images/16/if-connect.png" align="absmiddle"> ' . $ports['up'] . '</td>
      <td><img src="images/16/if-disconnect.png" align="absmiddle"> ' . $ports['down'] . '</td>
      <td><img src="images/16/if-disable.png" align="absmiddle"> ' . $ports['disabled'] . '</td>
    </tr>';
    echo '<tr>
          <td colspan="4">';
    $ifsep = '';
    foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) {
        $data = ifNameDescr($data);
        $data = array_merge($data, $device);
        echo "{$ifsep}" . generate_port_link($data, makeshortif(strtolower($data['label'])));
        $ifsep = ', ';
    }
    unset($ifsep);
    echo '  </td>';
    echo '</tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
}
//end if