Esempio n. 1
0
function IP2C($string, $isCLI)
{
    include_once "config.php";
    include_once "functions.php";
    if ($isCLI == 'NO') {
        // Running from a browser
        $when = 'WHERE ' . hextostr($string) . ' AND ';
    } else {
        // Running from the command line
        if ($string == 0) {
            $when = "WHERE ";
        }
        if ($string == 1) {
            $startDate = gmdate("Y-m-d");
            $startTime = "00:00:00";
            $endDate = gmdate("Y-m-d", strtotime($startDate . "+1 day"));
            $endTime = "00:00:00";
            $when = "WHERE e.timestamp BETWEEN '{$startDate} {$startTime}' AND '{$endDate} {$endTime}' AND";
        }
        echo "Performing base queries (this can take a while)..\n\n";
    }
    function lookup($list)
    {
        while ($row = mysql_fetch_row($list)) {
            $ip = $row[0];
            $dot = long2ip((double) $ip);
            $ipLookup = mysql_query("SELECT registry, cc, c_long, type, date, status FROM ip2c WHERE\n                                     {$ip} >=start_ip AND {$ip} <= end_ip LIMIT 1");
            $result = mysql_fetch_array($ipLookup);
            if ($result) {
                $registry = $result[0];
                $cc = $result[1];
                $c_long = $result[2];
                $type = $result[3];
                $date = $result[4];
                $status = $result[5];
                mysql_query("REPLACE INTO mappings (registry,cc,c_long,type,ip,date,status)\n                             VALUES (\"{$registry}\",\"{$cc}\",\"{$c_long}\",\"{$type}\",\"{$ip}\",\"{$date}\",\"{$status}\")");
                echo "-- Mapped {$dot} ({$ip}) to {$cc} ({$c_long})\n";
            }
        }
    }
    // DB Connect
    $db = mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
    mysql_select_db($dbName, $db) or die(mysql_error());
    // Start timing
    $st = microtime(true);
    $sipList = mysql_query("SELECT DISTINCT(e.src_ip) FROM event AS e LEFT JOIN mappings AS m ON e.src_ip=m.ip\n                            WHERE (m.ip IS NULL OR m.cc = '01')");
    $dipList = mysql_query("SELECT DISTINCT(e.dst_ip) FROM event AS e LEFT JOIN mappings AS m ON e.dst_ip=m.ip\n                            WHERE (m.ip IS NULL OR m.cc = '01')");
    $sipCount = $dipCount = 0;
    if ($sipList) {
        $sipCount = mysql_num_rows($sipList);
        if ($sipCount > 0) {
            lookup($sipList);
        }
    }
    if ($dipList) {
        $dipCount = mysql_num_rows($dipList);
        if ($dipCount > 0) {
            lookup($dipList);
        }
    }
    $allRecs = mysql_query("SELECT COUNT(*) FROM mappings");
    $allCount = mysql_fetch_row($allRecs);
    // Stop Timing
    $et = microtime(true);
    $time = $et - $st;
    $rt = sprintf("%01.3f", $time);
    if ($isCLI == 'NO') {
        $html = "\r<table align=left>\n                 \r<tr><td align=left style=\"font-size: 10px;\"><b>&nbsp;-> Query Time: {$rt} seconds</b></td></tr>\n                 \r<tr><td align=left style=\"font-size: 10px;\"><b>&nbsp;-> Source Count: {$sipCount}</b></td></tr>\n                 \r<tr><td align=left style=\"font-size: 10px;\"><b>&nbsp;-> Destination Count: {$dipCount}</b></td>\n                 \r<tr><td align=left style=\"font-size: 10px;\"><b>&nbsp;-> Total Mapped: {$allCount['0']}</b></td></tr>\n                 \r</table>";
        return $html;
    }
    if ($isCLI == 'YES' && $string == 0) {
        echo "\n-> Query Time: {$rt} seconds\n              \r-> Source Count: {$sipCount}\n              \r-> Destination Count: {$dipCount}\n              \r-> Total Mapped: {$allCount['0']}\n\n";
    }
}
 private function decrypt($encrypted_password)
 {
     $encrypted_password = trim($encrypted_password);
     if (!strlen($encrypted_password)) {
         return '';
     }
     $decoded_password = hextostr($encrypted_password);
     $decrypted_password = '';
     $seed = 0x2a9a;
     for ($i = 0; $i < strlen($decoded_password); $i++) {
         $decrypted_password .= chr(ord($decoded_password[$i]) ^ $seed >> 8 & 0xff);
         $seed += ord($decoded_password[$i]);
         $seed = hexdec(gmp_strval(gmp_and(gmp_add(gmp_mul("{$seed}", "0x8141"), "0x3171"), "0xffff"), 16));
     }
     return $decrypted_password;
 }
Esempio n. 3
0
    $swImage1UpdateTime = str_ireplace(' ', '', $swImage1UpdateTime);
    $swImage1UpdateTime = str_ireplace(chr(10), '', $swImage1UpdateTime);
    $swImage1UpdateTime = str_ireplace(chr(13), '', $swImage1UpdateTime);
    $swImage1UpdateTime = hextostr($swImage1UpdateTime);
    $swImage2UpdateTime = str_ireplace(' ', '', $swImage2UpdateTime);
    $swImage2UpdateTime = str_ireplace(chr(10), '', $swImage2UpdateTime);
    $swImage2UpdateTime = str_ireplace(chr(13), '', $swImage2UpdateTime);
    $swImage2UpdateTime = hextostr($swImage2UpdateTime);
}
// Это чит для прошивок вроде 2.10B02, которые произвольно выдают версию то в string то в hex формате.
if (stripos($sysFirmvare, '.') == false) {
    $sysFirmvare = str_ireplace('"', '', $sysFirmvare);
    $sysFirmvare = str_ireplace(' ', '', $sysFirmvare);
    $sysFirmvare = str_ireplace(chr(10), '', $sysFirmvare);
    $sysFirmvare = str_ireplace(chr(13), '', $sysFirmvare);
    $sysFirmvare = hextostr($sysFirmvare);
}
//Подготовка информации о прошивке к выводу на экран
$swImage1Version = str_ireplace('"', '', $swImage1Version);
$swImage2Version = str_ireplace('"', '', $swImage2Version);
$swImage1SendUser = str_ireplace('"', '', $swImage1SendUser);
$swImage2SendUser = str_ireplace('"', '', $swImage2SendUser);
//Для моделей 3028 и ей подобных
if ($ModelType == 'DES-3028' || $ModelType == 'DES-3028G' || $ModelType == 'DES-3028P' || $ModelType == 'DES-3200-28' || $ModelType == 'DGS-3100-24TG') {
    if ($swImage1Version != "") {
        $swFirm1Info = str_ireplace('"', '', $swImage1Version) . " (" . $swImage1UpdateTime . ")";
    } else {
        $swFirm1Info = "not installed";
    }
    if ($swImage2Version != "") {
        $swFirm2Info = str_ireplace('"', '', $swImage2Version) . " (" . $swImage2UpdateTime . ")";
Esempio n. 4
0
function times()
{
    global $offset, $when, $sensors;
    $filter = hextostr($_REQUEST['filter']);
    if ($filter != 'empty') {
        $filter = str_replace('&lt;', '<', $filter);
        $filter = str_replace('&gt;', '>', $filter);
        $filter = "AND " . $filter;
        $qp2 = "WHERE {$when}\n      {$sensors}\n      {$filter}";
    } else {
        $qp2 = "WHERE {$when}\n      {$sensors}";
    }
    $query = "SELECT\n    SUBSTRING(CONVERT_TZ(timestamp,'+00:00','{$offset}'),12,5) AS time,\n      COUNT(signature) AS count \n      FROM event\n      LEFT JOIN mappings AS msrc ON event.src_ip = msrc.ip\n      LEFT JOIN mappings AS mdst ON event.dst_ip = mdst.ip\n      {$qp2}\n      GROUP BY time \n      ORDER BY timestamp";
    $result = mysql_query($query);
    $rows = array();
    $r = $m = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $rows[] = $row;
        $cnts[] = $row['count'];
        $r++;
    }
    if ($r > 0) {
        $m = max($cnts);
    }
    $theJSON = json_encode(array("rows" => $rows, "r" => $r, "m" => $m));
    echo $theJSON;
}
Esempio n. 5
0
if ($ModelType == 'DES-3526') {
    $nocomboports = 2;
} else {
    $nocomboports = 0;
}
if ($ModelType == 'DES-3028' || $ModelType == 'DES-3028G' || $ModelType == 'DES-3028P' || $ModelType == 'DES-3200-28') {
    // Описание портов
    $portDescription = @snmpwalk($ip, $rcomm, ".1.3.6.1.4.1.171.11." . $p_oid[$ModelType] . ".2.2.2.1.6", $timeout, $retries);
    for ($pi = 1; $pi < $portscount[$ModelType] + 1; $pi++) {
        $portDescription[$pi - 1] = str_ireplace(' ', '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace('"', '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace('00', '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace(chr(10), '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace(chr(9), '', $portDescription[$pi - 1]);
        if ($ModelType != 'DES-3200-28') {
            $portDescription[$pi - 1] = hextostr($portDescription[$pi - 1]);
        }
    }
}
if ($ModelType == 'DES-3526' || $ModelType == 'DES-3026' || $ModelType == 'DGS-3100-24TG') {
    // Описание портов
    $portDescription = @snmpwalk($ip, $rcomm, ".1.3.6.1.2.1.31.1.1.1.18", $timeout, $retries);
}
for ($pi = 1; $pi < $portscount[$ModelType] + 1 - $nocomboports; $pi++) {
    $kport = $pi;
    if (strlen($kport) == 1) {
        $kport = "0" . $kport;
    }
    if ($portscount[$ModelType] == 30) {
        if ($kport == 26) {
            $kport = "25(F)";