/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage functions
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
function get_entity_by_id_cache($type, $id)
{
    global $cache;
    if ($type !== 'port') {
        list($entity_table, $entity_id_field, $entity_name_field) = entity_type_translate($type);
    }
    if (is_array($cache[$type][$id])) {
        return $cache[$type][$id];
    } else {
        switch ($type) {
            case "port":
                $entity = get_port_by_id($id);
                break;
            default:
                $entity = dbFetchRow("SELECT * FROM `" . $entity_table . "` WHERE `" . $entity_id_field . "` = ?", array($id));
                if (function_exists('humanize_' . $type)) {
                    $do = 'humanize_' . $type;
                    $do($entity);
                }
                break;
        }
        if (is_array($entity)) {
            entity_rewrite($type, $entity);
            $cache[$type][$id] = $entity;
            return $entity;
        }
    }
    return FALSE;
}
function get_entity_by_id_cache($entity_type, $entity_id)
{
    global $cache;
    $translate = entity_type_translate_array($entity_type);
    if (is_array($cache[$entity_type][$entity_id])) {
        return $cache[$entity_type][$entity_id];
    } else {
        switch ($entity_type) {
            case "port":
                $entity = get_port_by_id($entity_id);
                break;
            default:
                $entity = dbFetchRow("SELECT * FROM `" . $translate['table'] . "` WHERE `" . $translate['id_field'] . "` = ?", array($entity_id));
                if (function_exists('humanize_' . $entity_type)) {
                    $do = 'humanize_' . $entity_type;
                    $do($entity);
                } elseif (isset($translate['humanize_function']) && function_exists('humanize_' . $translate['humanize_function'])) {
                    $do = 'humanize_' . $translate['humanize_function'];
                    $do($entity);
                }
                break;
        }
        if (is_array($entity)) {
            entity_rewrite($entity_type, $entity);
            $cache[$entity_type][$entity_id] = $entity;
            return $entity;
        }
    }
    return FALSE;
}
<?php

echo '<table class="table table-striped table-condensed">';
$i = "1";
echo '<thead><th>Local Port</th>
          <th>Remote Port</th>
          <th>Remote Device</th>
          <th>Protocol</th>
      </thead>';
foreach (dbFetchRows("SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id", array($device['device_id'])) as $neighbour) {
    if ($bg_colour == $list_colour_b) {
        $bg_colour = $list_colour_a;
    } else {
        $bg_colour = $list_colour_b;
    }
    echo '<tr bgcolor="' . $bg_colour . '">';
    echo '<td><span style="font-weight: bold;">' . generate_port_link($neighbour) . '</span><br />' . $neighbour['ifAlias'] . '</td>';
    if (is_numeric($neighbour['remote_port_id']) && $neighbour['remote_port_id']) {
        $remote_port = get_port_by_id($neighbour['remote_port_id']);
        $remote_device = device_by_id_cache($remote_port['device_id']);
        echo "<td>" . generate_port_link($remote_port) . "<br />" . $remote_port['ifAlias'] . "</td>";
        echo "<td>" . generate_device_link($remote_device) . "<br />" . $remote_device['hardware'] . "</td>";
    } else {
        echo "<td>" . $neighbour['remote_port'] . "</td>";
        echo "<td>" . $neighbour['remote_hostname'] . "\n          <br />" . $neighbour['remote_platform'] . "</td>";
    }
    echo "<td>" . strtoupper($neighbour['protocol']) . "</td>";
    echo "</tr>";
    $i++;
}
echo "</table>";
             // Hola, port really found
             $options['entPhysicalIndex_measured'] = $ifIndex;
             $options['measured_class'] = 'port';
             $options['measured_entity'] = $port['port_id'];
             print_debug("Port is found: ifIndex = {$ifIndex}, port_id = " . $port['port_id']);
         }
     }
     break;
     // Exit while
 } else {
     if ($device['os'] == 'arista_eos' && $sensor_port['entPhysicalClass'] == 'container' && strlen($sensor_port['entPhysicalAlias'])) {
         // Arista not have entAliasMappingIdentifier, but used entPhysicalAlias as ifDescr
         $port_id = get_port_id_by_ifDescr($device['device_id'], $sensor_port['entPhysicalAlias']);
         if (is_numeric($port_id)) {
             // Hola, port really found
             $port = get_port_by_id($port_id);
             $ifIndex = $port['ifIndex'];
             $options['entPhysicalIndex_measured'] = $ifIndex;
             $options['measured_class'] = 'port';
             $options['measured_entity'] = $port_id;
             print_debug("Port is found: ifIndex = {$ifIndex}, port_id = " . $port_id);
             break;
             // Exit while
         }
         $sensor_index = $sensor_port['entPhysicalContainedIn'];
         // Next ifIndex
     } else {
         if ($sensor_index == $sensor_port['entPhysicalContainedIn']) {
             break;
             // Break if current index same as next to avoid loop
         } else {
            }
            ?>

          </select>
          <button class="btn pull-right" type="submit" name="提交" value="添加"><i class="oicon-plus-circle"></i> 添加</button>
        </form>
      </div>
    </div>
    <div class="col-md-4">
      <div class="well">
        <h2>端口权限</h2>

<?php 
            if (count($user_permissions['port'])) {
                foreach (array_keys($user_permissions['port']) as $entity_id) {
                    $port = get_port_by_id($entity_id);
                    $device = device_by_id_cache($port['device_id']);
                    $emptyCheck = true;
                    $count++;
                    $devicebtn = '<button class="btn"><i class="oicon-servers"></i> ' . generate_device_link($device) . '</button>';
                    if (empty($port['ifAlias'])) {
                        $portalias = "";
                    } else {
                        $portalias = " - " . $port['ifAlias'] . "";
                    }
                    $portbtn = '<button class="btn">' . generate_port_link($port, '<i class="oicon-network-ethernet"></i> ' . rewrite_ifname($port['label']) . $portalias) . '</button>';
                    $del_url = generate_url(array('page' => 'edituser', 'action' => 'perm_del', 'user_id' => $vars['user_id'], 'entity_type' => 'port', 'entity_id' => $entity_id));
                    echo '            <div class="btn-group" style="margin: 5px;">';
                    echo '              <button class="btn btn-danger" style="color: #fff;" onclick="location.href=\'' . $del_url . '\';"><i class="icon-minus-sign icon-white"></i> 删除</button>';
                    echo '              ' . $devicebtn;
                    echo '              ' . $portbtn;
Beispiel #6
0
 *   This file is included with Observium. It was originally part of m0n0wall <http://www.m0n0.ch/wall/>
 *
 * @package    observium
 * @subpackage graphing
 * @author     T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**>
 * @copyright  2004-2006 T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**>
 * @license    BSD
 *
 */
include_once "../includes/sql-config.inc.php";
include $config['html_dir'] . "/includes/functions.inc.php";
include $config['html_dir'] . "/includes/authenticate.inc.php";
// Push $_GET into $vars to be compatible with web interface naming
$vars = get_vars('GET');
if (is_numeric($vars['id']) && ($config['allow_unauth_graphs'] || port_permitted($vars['id']))) {
    $port = get_port_by_id($vars['id']);
    $device = device_by_id_cache($port['device_id']);
    $title = generate_device_link($device);
    $title .= " :: Port  " . generate_port_link($port);
    $auth = TRUE;
} else {
    echo "Unauthenticated";
    die;
}
header("Content-type: image/svg+xml");
/********** HTTP GET Based Conf ***********/
$ifnum = $port['ifIndex'];
// BSD / SNMP interface name / number
$ifname = escape_html($port['port_label']);
//Interface name that will be showed on top right of graph
$hostname = short_hostname($device['hostname']);
<?php

$res = "";
$count = 0;
$speed = 0;
$port_ids = dbFetchRows("SELECT `port_id` FROM `bill_ports` WHERE bill_id = ?", array($bill_id));
foreach ($port_ids as $port_entry) {
    $port = get_port_by_id($port_entry['port_id']);
    $device = device_by_id_cache($port['device_id']);
    $emptyCheck = true;
    $count++;
    $speed += $port['ifSpeed'];
    /// FIXME - clean this up, it's horrible.
    $devicebtn = '<button class="btn"><i class="oicon-servers"></i> ' . generate_device_link($device) . '</button>';
    if (empty($port['ifAlias'])) {
        $portalias = "";
    } else {
        $portalias = " - " . $port['ifAlias'] . "";
    }
    $portbtn = '<button class="btn">' . generate_port_link($port, '<i class="oicon-network-ethernet"></i> ' . $port['label'] . $portalias) . '</button>';
    #  $portbtn = str_replace("interface-upup", "btn btn-mini", generate_port_link($port, "<i class='icon-random'></i> ".$port['label'].$portalias));
    #  $portbtn = str_replace("interface-updown", "btn btn-mini btn-danger", $portbtn);
    #  $portbtn = str_replace("interface-downdown", "btn btn-mini btn-danger", $portbtn);
    #  $portbtn = str_replace("interface-admindown", "btn btn-mini btn-warning disabled", $portbtn);
    #  $res    .= "          <div class=\"btn-toolbar\">\n";
    $res .= "            <div class=\"btn-group\">\n";
    $res .= "              " . $devicebtn . "\n";
    $res .= "              " . $portbtn . "\n";
    $res .= "            </div><br />\n";
    #  $res    .= "          </div>\n";
}
 if ($debug) {
     echo "<pre>";
     print_vars($ma);
     echo "</pre>";
 }
 if (is_array($ma)) {
     if ($auth || port_permitted($ma['port_id'])) {
         $rrd_filename = $config['rrd_dir'] . "/" . $ma['hostname'] . "/" . safename("mac_acc-" . $ma['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd");
         if ($debug) {
             echo $rrd_filename;
         }
         if (is_file($rrd_filename)) {
             if ($debug) {
                 echo "exists";
             }
             $port = get_port_by_id($ma['port_id']);
             $device = device_by_id_cache($port['device_id']);
             $title = generate_device_link($device);
             $title .= " :: Port  " . generate_port_link($port);
             $title .= " :: Mac Accounting";
             $title .= " :: " . formatMac($ma['mac']);
             $auth = TRUE;
         } else {
             #     graph_error("file not found");
         }
     } else {
         #    graph_error("unauthenticated");
     }
 } else {
     #   graph_error("entry not found");
 }
Beispiel #9
0
 *
 */
$config['install_dir'] = "../..";
require_once $config['install_dir'] . "/includes/sql-config.inc.php";
include $config['html_dir'] . "/includes/functions.inc.php";
include $config['html_dir'] . "/includes/authenticate.inc.php";
if (!$_SESSION['authenticated']) {
    print_error('Session expired, please log in again!');
    exit;
}
$vars = get_vars();
$vars['page'] = "popup";
switch ($vars['entity_type']) {
    case "port":
        if (is_numeric($vars['entity_id']) && port_permitted($vars['entity_id'])) {
            $port = get_port_by_id($vars['entity_id']);
            echo generate_port_popup($port);
        } else {
            print_warning("You are not permitted to view this port.");
        }
        exit;
        break;
    case "device":
        if (is_numeric($vars['entity_id']) && device_permitted($vars['entity_id'])) {
            $device = device_by_id_cache($vars['entity_id']);
            echo generate_device_popup($device, $vars, $start, $end);
        } else {
            print_warning("You are not permitted to view this device.");
        }
        exit;
        break;
} elseif ($stat == "bits") {
    $units = 'bps';
    $unit = 'B';
    $multiplier = '8';
    $colours_in = 'greens';
    $colours_out = 'blues';
    if ($sort == "in") {
        $sort = "bytes_input_rate";
    } elseif ($sort == "out") {
        $sort = "bytes_output_rate";
    } else {
        $sort = "bps";
    }
}
$mas = dbFetchRows("SELECT *, (bytes_input_rate + bytes_output_rate) AS bps,\n        (pkts_input_rate + pkts_output_rate) AS pps\n        FROM `mac_accounting`\n        LEFT JOIN  `mac_accounting-state` ON  `mac_accounting`.ma_id =  `mac_accounting-state`.ma_id\n        WHERE `mac_accounting`.port_id = ?\n        ORDER BY {$sort} DESC LIMIT 0," . $topn, array($port));
$port = get_port_by_id($port);
$device = device_by_id_cache($port['device_id']);
$pluses = "";
$iter = '0';
$rrd_options .= " COMMENT:'                                     In\\: Current     Maximum      Total      Out\\: Current     Maximum     Total\\\\n'";
foreach ($mas as $ma) {
    $this_rrd = get_rrd_path($device, "mac_acc-" . $port['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd");
    if (is_file($this_rrd)) {
        $mac = format_mac($ma['mac']);
        $name = $mac;
        $addy = dbFetchRow("SELECT * FROM ipv4_mac where mac_address = ? AND port_id = ?", array($ma['mac'], $ma['port_id']));
        if ($addy) {
            $name = $addy['ipv4_address'] . " (" . $mac . ")";
            $peer = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D\n              WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($addy['ipv4_address']));
            if ($peer) {
                $name = $peer['hostname'] . " " . short_ifname($port['ifDescr'], NULL, FALSE) . " (" . $mac . ")";
Beispiel #11
0
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
// Ports
// Print table of EIGRP interfaces from eigrp_ports.
echo '<table class="table table-hover table-striped-two table-bordered table-condensed table-rounded">';
echo '<thead>';
echo '<tr><th></th><th></th><th>Port</th><th>AS</th><th>Peers</th><th>Mean SRTT</th><th>Auth</th></tr>';
echo '</thead>';
echo '<tbody>';
foreach (dbFetchRows("SELECT * FROM `eigrp_ports` WHERE `device_id` = ?", array($device['device_id'])) as $eigrp_port) {
    $port = get_port_by_id($eigrp_port['port_id']);
    echo '<tr class="' . $port['row_class'] . '" onclick="location.href=\'' . generate_port_url($port) . '/\'" style="cursor: pointer;">

          <td style="width: 1px; background-color: ' . $port['table_tab_colour'] . '; margin: 0px; padding: 0px"></td>
          <td style="width: 1px;"></td>
          <td><span class="entity-title">' . generate_port_link($port) . '</span><br />
                                 ' . $port['ifAlias'] . '</td>
          <td>' . $eigrp_port['eigrp_as'] . '</td>
          <td>' . $eigrp_port['eigrp_peer_count'] . '</td>
          <td>' . $eigrp_port['eigrp_MeanSrtt'] . '</td>
          <td>' . $eigrp_port['eigrp_authmode'] . '</td>
        </tr>
        <tr>
          <td colspan=7>';
    $graph_array['to'] = $config['time']['now'];
    $graph_array['id'] = $eigrp_port['eigrp_port_id'];
Beispiel #12
0
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
echo "Mac Accounting: ";
// FIXME -- we're walking, so we can discover here too.
#dbQuery("TRUNCATE TABLE `mac_accounting`");
#dbQuery("TRUNCATE TABLE `mac_accounting-state`");
// Cache DB entries
echo "Caching DB...";
$sql = "SELECT *, `mac_accounting`.`ma_id` as `ma_id`";
$sql .= " FROM  `mac_accounting`";
$sql .= " LEFT JOIN  `mac_accounting-state` ON  `mac_accounting`.ma_id =  `mac_accounting-state`.ma_id";
$sql .= " WHERE `device_id` = ?";
$arg = array($device['device_id']);
foreach (dbFetchRows($sql, $arg) as $acc) {
    $port = get_port_by_id($acc['port_id']);
    $acc['ifIndex'] = $port['ifIndex'];
    unset($port);
    $ma_db_array[$acc['ifIndex'] . '-' . $acc['vlan_id'] . '-' . $acc['mac']] = $acc;
}
if ($debug) {
    print_vars($ma_db_array);
}
echo count($ma_db_array) . " entries. ";
if (is_device_mib($device, 'JUNIPER-MAC-MIB')) {
    $datas = snmp_walk($device, "JUNIPER-MAC-MIB::jnxMacStatsEntry", "-OUqsX", "JUNIPER-MAC-MIB", mib_dirs("juniper"));
    foreach (explode("\n", $datas) as $data) {
        list($oid, $ifIndex, $vlan, $mac, $value) = parse_oid2($data);
        list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac);
        $ah_a = zeropad($a_a);
        $ah_b = zeropad($a_b);
Beispiel #13
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage graphs
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
if (is_numeric($vars['id'])) {
    $data = dbFetchRow("SELECT * FROM `eigrp_ports` WHERE `eigrp_port_id` = ?", array($vars['id']));
    if (is_numeric($data['device_id']) && ($auth || device_permitted($data['device_id']))) {
        $device = device_by_id_cache($data['device_id']);
        $port = get_port_by_id($data['port_id']);
        $rrd_filename = get_rrd_path($device, "eigrp_port-" . $data['eigrp_vpn'] . "-" . $data['eigrp_as'] . "-" . $port['ifIndex'] . ".rrd");
        $title = generate_device_link($device);
        $title .= " :: EIGRP :: Port :: " . htmlentities($port['label']);
        $auth = TRUE;
    }
}
// EOF
Beispiel #14
0
function get_entity_by_id_cache($entity_type, $entity_id)
{
    global $cache;
    $translate = entity_type_translate_array($entity_type);
    if (is_array($cache[$entity_type][$entity_id])) {
        return $cache[$entity_type][$entity_id];
    } else {
        switch ($entity_type) {
            case "bill":
                if (function_exists('get_bill_by_id')) {
                    $entity = get_bill_by_id($entity_id);
                }
                break;
            case "port":
                $entity = get_port_by_id($entity_id);
                break;
            default:
                $sql = 'SELECT * FROM `' . $translate['table'] . '`';
                if (isset($translate['state_table'])) {
                    $sql .= ' LEFT JOIN `' . $translate['state_table'] . '` USING (`' . $translate['id_field'] . '`)';
                }
                $sql .= ' WHERE `' . $translate['table'] . '`.`' . $translate['id_field'] . '` = ?';
                $entity = dbFetchRow($sql, array($entity_id));
                if (function_exists('humanize_' . $entity_type)) {
                    $do = 'humanize_' . $entity_type;
                    $do($entity);
                } else {
                    if (isset($translate['humanize_function']) && function_exists($translate['humanize_function'])) {
                        $do = $translate['humanize_function'];
                        $do($entity);
                    }
                }
                break;
        }
        if (is_array($entity)) {
            entity_rewrite($entity_type, $entity);
            $cache[$entity_type][$entity_id] = $entity;
            return $entity;
        }
    }
    return FALSE;
}
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config;
    global $cache;
    $param = array();
    if ($_SESSION['userlevel'] >= 5) {
        $query_perms = '';
        $query_user = '';
    } else {
        $query_perms = 'LEFT JOIN devices_perms AS P ON D.device_id = P.device_id ';
        $query_user = '******';
        $param[] = $_SESSION['user_id'];
    }
    // Don't show ignored and disabled devices
    $query_device = ' AND D.ignore = 0 ';
    if (!$config['web_show_disabled']) {
        $query_device .= 'AND D.disabled = 0 ';
    }
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= $query_perms;
        $query .= 'WHERE D.status = 0' . $query_device . $query_user;
        $query .= 'ORDER BY D.hostname ASC';
        $entries = dbFetchRows($query, $param);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, shorthost($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= $query_perms;
            $query .= 'WHERE D.status = 1 AND D.uptime > 0 AND D.uptime < ' . $config['uptime_warning'] . $query_device . $query_user;
            $query .= 'ORDER BY D.hostname ASC';
            $entries = dbFetchRows($query, $param);
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, shorthost($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['links']) {
        // warning about deprecated option: $config['warn']['ifdown']
        if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) {
            echo '
  <div class="alert">
     <button type="button" class="close" data-dismiss="alert">&times;</button>
     <p><i class="oicon-bell"></i> <strong>Config option obsolete</strong></p>
     <p>Please note that config option <strong>$config[\'warn\'][\'ifdown\']</strong> is now obsolete.<br />Use options: <strong>$config[\'frontpage\'][\'device_status\'][\'ports\']</strong> and <strong>$config[\'frontpage\'][\'device_status\'][\'errors\']</strong></p>
     <p>To remove this message, delete <strong>$config[\'warn\'][\'ifdown\']</strong> from configuration file.</p>
  </div>';
        }
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['links'] && !$status['ports']) {
            $query .= 'INNER JOIN links as L ON I.port_id = L.local_port_id ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.device_id = D.device_id ';
        $query .= $query_perms;
        $query .= "WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = 0 AND I.deleted = 0 ";
        if ($status['links'] && !$status['ports']) {
            $query .= ' AND L.active = 1 ';
        }
        $query .= $query_device . $query_user;
        $query .= ' AND I.ifLastChange >= DATE_SUB(NOW(), INTERVAL 24 HOUR) ';
        $query .= 'ORDER BY I.ifLastChange DESC, D.hostname ASC, I.ifDescr * 1 ASC ';
        $entries = dbFetchRows($query, $param);
        //$count = count($entries);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > 200) {
                // Limit to 200 ports on overview page
                $string .= '  <tr><td></td><td><span class="badge badge-info">Port</span></td>';
                $string .= '<td><span class="label label-important">Port Down</span></td>';
                $string .= '<td colspan=3>Too many ports down. See <strong><a href="' . generate_url(array('page' => 'ports'), array('state' => 'down')) . '">All DOWN ports</a></strong>.</td></tr>' . PHP_EOL;
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, shorthost($port['hostname'])), 'entity_link' => generate_port_link($port, truncate(makeshortif($port['label']), 13, '')), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
            // We don't do anything with this here at the moment. There is no comment on it, what is it for?
            // if ($status['links'] && !$status['ports']) { $string .= ' ('.strtoupper($port['protocol']).': ' .$port['remote_hostname'].' / ' .$port['remote_port'] .')'; }
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports_errored'] as $port_id) {
            $port = get_port_by_id($port_id);
            if (port_permitted($port)) {
                $device = device_by_id_cache($port['device_id']);
                humanize_port($port);
                if ($port['ifInErrors_delta']) {
                    $port['string'] .= 'Rx: ' . $port['ifInErrors_delta'];
                }
                if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                    $port['string'] .= ', ';
                }
                if ($port['ifOutErrors_delta']) {
                    $port['string'] .= 'Tx: ' . $port['ifOutErrors_delta'];
                }
                $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, shorthost($device['hostname'])), 'entity_link' => generate_port_link($port, truncate(makeshortif($port['label']), 13, '')), 'time' => $port['string'], 'location' => $device['location']);
            }
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id ';
        $query .= $query_perms;
        $query .= "WHERE S.service_status = 'down' AND S.service_ignore = 0" . $query_device . $query_user;
        $query .= 'ORDER BY D.hostname ASC';
        $entries = dbFetchRows($query, $param);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, shorthost($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            // Description for BGP states
            $bgpstates = 'IDLE - Router is searching routing table to see whether a route exists to reach the neighbor. &#xA;';
            $bgpstates .= 'CONNECT - Router found a route to the neighbor and has completed the three-way TCP handshake. &#xA;';
            $bgpstates .= 'OPEN SENT - Open message sent, with parameters for the BGP session. &#xA;';
            $bgpstates .= 'OPEN CONFIRM - Router received agreement on the parameters for establishing session. &#xA;';
            $bgpstates .= 'ACTIVE - Router did not receive agreement on parameters of establishment. &#xA;';
            //$bgpstates .= 'ESTABLISHED - Peering is established; routing begins.';
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'LEFT JOIN bgpPeers AS B ON B.device_id = D.device_id ';
            $query .= $query_perms;
            $query .= "WHERE (bgpPeerAdminStatus = 'start' OR bgpPeerAdminStatus = 'running') AND bgpPeerState != 'established' " . $query_device . $query_user;
            $query .= 'ORDER BY D.hostname ASC';
            $entries = dbFetchRows($query, $param);
            foreach ($entries as $peer) {
                $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr'];
                if (strstr($peer['bgpPeerRemoteAddr'], ':')) {
                    $peer['wide'] = TRUE;
                }
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, shorthost($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'shorter'), 'location' => $device['location']);
            }
        }
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    // Final print all statuses
    return $boxes;
}
Beispiel #16
0
 * @author     T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**>
 * @copyright  2004-2006 T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**>
 * @license    BSD
 *
 */
include_once "../includes/defaults.inc.php";
include_once "../config.php";
include_once "../includes/definitions.inc.php";
include_once "../includes/common.inc.php";
include_once "../includes/dbFacile.php";
include_once "../includes/rewrites.inc.php";
include_once "includes/functions.inc.php";
include_once "includes/authenticate.inc.php";
include_once "../includes/snmp.inc.php";
if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) {
    $port = get_port_by_id($_GET['id']);
    $device = device_by_id_cache($port['device_id']);
    $title = generate_device_link($device);
    $title .= " :: Port  " . generate_port_link($port);
    $auth = TRUE;
} else {
    echo "Unauthenticad";
    die;
}
header("Content-type: image/svg+xml");
/********** HTTP GET Based Conf ***********/
$ifnum = @$port['ifIndex'];
// BSD / SNMP interface name / number
$ifname = htmlentities(@$port['ifDescr']);
//Interface name that will be showed on top right of graph
$hostname = short_hostname($device['hostname']);
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config, $cache;
    $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1)));
    $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1)));
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['links']) {
        // warning about deprecated option: $config['warn']['ifdown']
        if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) {
            print_warning("<strong>Config option obsolete</strong>\n                    Please note that config option <strong>\$config['warn']['ifdown']</strong> is now obsolete.\n                    Use options: <strong>\$config['frontpage']['device_status']['ports']</strong> and <strong>\$config['frontpage']['device_status']['errors']</strong>\n                    To remove this message, delete <strong>\$config['warn']['ifdown']</strong> from configuration file.");
        }
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['links'] && !$status['ports']) {
            $query .= 'INNER JOIN `links` as L ON I.`port_id` = L.`local_port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up' ";
        if ($status['links'] && !$status['ports']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'LEFT JOIN `bgpPeers` AS B ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr'];
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}
Beispiel #18
0
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config, $cache;
    $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1)));
    $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1)));
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D', 'hide_ignored' => TRUE));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I', 'hide_ignored' => TRUE));
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            // Since reboot event more complicated than just device uptime less than some time
            //$query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`last_rebooted` > ?';
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query, array($config['time']['now'] - $config['uptime_warning'] - 10));
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['neighbours']) {
        $status['neighbours'] = $status['neighbours'] && !$status['ports'];
        // Disable 'neighbours' if 'ports' already enabled
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['neighbours']) {
            $query .= 'INNER JOIN `neighbours` as L ON I.`port_id` = L.`port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE D.`status` = 1 AND D.ignore = 0 AND I.ignore = 0 AND I.deleted = 0 AND I.`ifAdminStatus` = 'up' AND (I.`ifOperStatus` = 'lowerLayerDown' OR I.`ifOperStatus` = 'down') ";
        if ($status['neighbours']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        if ($status['neighbours']) {
            $query .= 'GROUP BY L.`port_id` ';
        }
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            if (in_array($port_id, $cache['ports']['ignored'])) {
                continue;
            }
            // Skip ignored ports
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.`device_id` = D.`device_id` ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `bgpPeers` AS B ';
            $query .= 'LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE D.`status` = 1 AND (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                humanize_bgp($peer);
                $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}