Beispiel #1
0
     } elseif (isset($data['ipNetToMediaPhysAddress'])) {
         $raw_mac = $data['ipNetToMediaPhysAddress'];
         list($if, $ip) = explode('.', $ip, 2);
         $ipv = 'ipv4';
     }
     $interface = get_port_by_index_cache($device['device_id'], $if);
     $port_id = $interface['port_id'];
     if (!empty($ip) && $ipv === 'ipv4' && $raw_mac != '0:0:0:0:0:0' && !isset($arp_table[$port_id][$ip])) {
         $mac = implode(array_map('zeropad', explode(':', $raw_mac)));
         $arp_table[$port_id][$ip] = $mac;
         $index = array_search($ip, $ipv4_addresses);
         if ($index !== false) {
             $old_mac = $existing_data[$index]['mac_address'];
             if ($mac != $old_mac && $mac != '') {
                 d_echo("Changed mac address for {$ip} from {$old_mac} to {$mac}\n");
                 log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($mac), $device, 'interface', $port_id);
                 dbUpdate(array('mac_address' => $mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', array($port_id, $ip, $context));
             }
             d_echo(null, '.');
         } elseif (isset($interface['port_id'])) {
             d_echo(null, '+');
             $insert_data[] = array('port_id' => $port_id, 'mac_address' => $mac, 'ipv4_address' => $ip, 'context_name' => $context);
         }
     }
 }
 // add new entries
 if (!empty($insert_data)) {
     dbBulkInsert($insert_data, 'ipv4_mac');
 }
 // remove stale entries
 foreach ($existing_data as $entry) {
        $mac = "{$m_a}:{$m_b}:{$m_c}:{$m_d}:{$m_e}:{$m_f}";
        $mac_table[$if][$mac]['ip'] = $ip;
        $mac_table[$if][$mac]['ciscomac'] = "{$m_a}{$m_b}.{$m_c}{$m_d}.{$m_e}{$m_f}";
        $clean_mac = $m_a . $m_b . $m_c . $m_d . $m_e . $m_f;
        $mac_table[$if][$mac]['cleanmac'] = $clean_mac;
        $port_id = $interface['port_id'];
        $mac_table[$port_id][$clean_mac] = 1;
        if (dbFetchCell("SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?", array($interface['port_id'], $ip))) {
            // Commented below, no longer needed but leaving for reference.
            //$sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
            $old_mac = dbFetchCell("SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?", array($ip, $interface['port_id']));
            if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
                if ($debug) {
                    echo "Changed mac address for {$ip} from {$old_mac} to {$clean_mac}\n";
                }
                log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . " -> " . mac_clean_to_readable($clean_mac), $device, "interface", $interface['port_id']);
            }
            dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip));
            echo ".";
        } else {
            echo "+";
            #echo("Add MAC $mac\n");
            dbInsert(array('port_id' => $interface['port_id'], 'mac_address' => $clean_mac, 'ipv4_address' => $ip), 'ipv4_mac');
        }
    }
}
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '" . $device['device_id'] . "'";
foreach (dbFetchRows($sql) as $entry) {
    $entry_mac = $entry['mac_address'];
    $entry_if = $entry['port_id'];
    if (!$mac_table[$entry_if][$entry_mac]) {
        } else {
            unset($as);
            unset($astext);
            unset($asn);
        }
        if ($vars['graph']) {
            $graph_type = "macaccounting_" . $vars['graph'];
        } else {
            $graph_type = "macaccounting_bits";
        }
        if ($vars['subview'] == "minigraphs") {
            if (!$asn) {
                $asn = "No Session";
            }
            echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 221px; max-width:221px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e5e5e5;'>\n      " . $addy['ipv4_address'] . " - " . $asn . "\n          <a href='#' onmouseover=\"return overlib('\\\n     <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\\'>" . $name . " - " . $addy['ipv4_address'] . " - " . $asn . "</div>\\\n     <img src=\\'graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n     ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >\n          <img src='graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=213&amp;height=45'></a>\n\n          <span style='font-size: 10px;'>" . $name . "</span>\n         </div>";
        } else {
            echo "<div style='background-color: {$row_colour}; padding: 0px;'>";
            echo "\n      <table>\n        <tr>\n          <td class=list-large width=200>" . mac_clean_to_readable($acc['mac']) . "</td>\n          <td class=list-large width=200>" . $addy['ipv4_address'] . "</td>\n          <td class=list-large width=500>" . $name . " " . $arp_name . "</td>\n          <td class=list-large width=100>" . formatRates($acc['cipMacHCSwitchedBytes_input_rate'] / 8) . "</td>\n          <td class=list-large width=100>" . formatRates($acc['cipMacHCSwitchedBytes_output_rate'] / 8) . "</td>\n        </tr>\n      </table>\n    ";
            $peer_info['astext'];
            $graph_array['type'] = $graph_type;
            $graph_array['id'] = $acc['ma_id'];
            $graph_array['height'] = "100";
            $graph_array['width'] = "216";
            $graph_array['to'] = $config['time']['now'];
            echo '<tr bgcolor="' . $bg_colour . '"' . ($bg_image ? ' background="' . $bg_image . '"' : '') . '"><td colspan="7">';
            include "includes/print-graphrow.inc.php";
            echo "</td></tr>";
            $i++;
        }
    }
}
         $graph_type = 'macaccounting_' . $vars['graph'];
     } else {
         $graph_type = 'macaccounting_bits';
     }
     if ($vars['subview'] == 'minigraphs') {
         if (!$asn) {
             $asn = 'No Session';
         }
         echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 221px; max-width:221px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e5e5e5;'>\n      " . $addy['ipv4_address'] . ' - ' . $asn . "\n          <a href='#' onmouseover=\"return overlib('\\\n     <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\\'>" . $name . ' - ' . $addy['ipv4_address'] . ' - ' . $asn . "</div>\\\n     <img src=\\'graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . '&amp;to=' . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n     ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >\n          <img src='graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . '&amp;to=' . $config['time']['now'] . "&amp;width=213&amp;height=45'></a>\n\n          <span style='font-size: 10px;'>" . $name . '</span>
      </div>';
     } else {
         echo "<div style='background-color: {$row_colour}; padding: 0px;'>";
         echo '
   <table>
     <tr>
       <td class=list-large width=200>' . mac_clean_to_readable($acc['mac']) . '</td>
       <td class=list-large width=200>' . $addy['ipv4_address'] . '</td>
       <td class=list-large width=500>' . $name . ' ' . $arp_name . '</td>
       <td class=list-large width=100>' . formatRates($acc['cipMacHCSwitchedBytes_input_rate'] / 8) . '</td>
       <td class=list-large width=100>' . formatRates($acc['cipMacHCSwitchedBytes_output_rate'] / 8) . '</td>
     </tr>
   </table>
 ';
         $peer_info['astext'];
         $graph_array['type'] = $graph_type;
         $graph_array['id'] = $acc['ma_id'];
         $graph_array['height'] = '100';
         $graph_array['width'] = '216';
         $graph_array['to'] = $config['time']['now'];
         echo '<tr bgcolor="' . $bg_colour . '"' . ($bg_image ? ' background="' . $bg_image . '"' : '') . '"><td colspan="7">';
         include 'includes/print-graphrow.inc.php';
        } else {
            unset($as);
            unset($astext);
            unset($asn);
        }
        if ($vars['graph']) {
            $vars['graph'] == "bits";
        }
        $graph_type = "macaccounting_" . $vars['graph'];
        if ($vars['subview'] == "minigraphs") {
            if (!$asn) {
                $asn = "No Session";
            }
            echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 221px; max-width:221px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e5e5e5;'>\n      " . $addy['ipv4_address'] . " - " . $asn . "\n          <a href='#' onmouseover=\"return overlib('\\\n     <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\\'>" . $name . " - " . $addy['ipv4_address'] . " - " . $asn . "</div>\\\n     <img src=\\'graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n     ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >\n          <img src='graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=213&amp;height=45'></a>\n\n          <span style='font-size: 10px;'>" . $name . "</span>\n         </div>";
        } else {
            echo "\n        <tr>\n          <td width=20></td>\n          <td width=200><bold>" . mac_clean_to_readable($acc['mac']) . "</bold></td>\n          <td width=200>" . implode($ips, "<br />") . "</td>\n          <td width=500>" . $name . " " . $arp_name . "</td>\n          <td width=100>" . formatRates($acc['bytes_input_rate'] / 8) . "</td>\n          <td width=100>" . formatRates($acc['bytes_output_rate'] / 8) . "</td>\n          <td width=100>" . format_number($acc['pkts_input_rate'] / 8) . "pps</td>\n          <td width=100>" . format_number($acc['pkts_output_rate'] / 8) . "pps</td>\n        </tr>\n    ";
            $peer_info['astext'];
            if ($vars['subview'] == "graphs") {
                $graph_array['type'] = $graph_type;
                $graph_array['id'] = $acc['ma_id'];
                $graph_array['height'] = "100";
                $graph_array['to'] = $config['time']['now'];
                echo '<tr><td colspan="8">';
                include "includes/print-graphrow.inc.php";
                echo "</td></tr>";
                $i++;
            }
        }
    }
    echo "</table>";
}