コード例 #1
0
function STATS_CNX_ACCEPT_parse($path)
{
    if ($GLOBALS["VERBOSE"]) {
        echo "Parsing {$path}\n";
    }
    $db_con = dba_open($path, "r", "db4");
    if (!$db_con) {
        echo "DB open {$path} failed\n";
        return false;
    }
    $fam = new familysite();
    $SQL1 = array();
    $mainkey = dba_firstkey($db_con);
    while ($mainkey != false) {
        $data = dba_fetch($mainkey, $db_con);
        $ARRAY = unserialize($data);
        if ($ARRAY["IPADDR"] == "127.0.0.1") {
            $mainkey = dba_nextkey($db_con);
            continue;
        }
        $zmd5 = md5($data);
        if ($ARRAY["HOSTNAME"] == null) {
            $ARRAY["HOSTNAME"] = $fam->GetComputerName($ARRAY["IPADDR"]);
        }
        $familysite = $fam->GetFamilySites($ARRAY["HOSTNAME"]);
        $SQL1[date("YmdH", $ARRAY["TIME"])][] = "('{$zmd5}','{$ARRAY["DATE"]}','{$ARRAY["HOSTNAME"]}','{$familysite}','{$ARRAY["IPADDR"]}')";
        if ($GLOBALS["VERBOSE"]) {
            echo "('{$zmd5}','{$ARRAY["DATE"]}','{$ARRAY["HOSTNAME"]}','{$familysite}','{$ARRAY["IPADDR"]}')\n";
        }
        $mainkey = dba_nextkey($db_con);
    }
    dba_close($db_con);
    if (count($SQL1) > 0) {
        $q = new mysql_postfix_builder();
        while (list($TIMESTAMP, $rows) = each($SQL1)) {
            $q->postfix_buildhour_connections($TIMESTAMP);
            $sql = "INSERT IGNORE INTO {$TIMESTAMP}_hcnx (`zmd5`,`zDate`,`hostname`,`domain`,`ipaddr`) VALUES " . @implode(",", $rows);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error;
                return false;
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Parsing {$path} END\n";
    }
    return true;
}