function XDUMP_RULES($MAIN)
{
    $proxyname = $GLOBALS["MYHOSTNAME"];
    $prefix = "INSERT INTO suricata_sig (signature,description,enabled) VALUES ";
    while (list($signature, $explain) = each($MAIN)) {
        $explain = pg_escape_string2($explain);
        if ($GLOBALS["VERBOSE"]) {
            events("Dump signature: {$signature} = {$explain}");
        }
        if (strlen($explain) > 128) {
            $explain = substr($explain, 0, 128);
        }
        $f[] = "('{$signature}',E'{$explain}',1)";
    }
    if (count($f) > 0) {
        xPGQUERY_SQL($prefix . @implode(",", $f) . " ON CONFLICT DO NOTHING");
    }
}
Beispiel #2
0
function parse_rulesToPostGres()
{
    if (!is_file("/etc/suricata/rules/sid-msg.map")) {
        return;
    }
    $prefix = "INSERT INTO suricata_sig (signature,description,enabled) VALUES ";
    $f = explode("\n", @file_get_contents("/etc/suricata/rules/sid-msg.map"));
    $I = array();
    while (list($num, $val) = each($f)) {
        $tr = explode("||", $val);
        $sig = intval(trim($tr[0]));
        if ($sig == 0) {
            echo "SIG  === 0 / {$val}\n";
            continue;
        }
        $explain = trim(pg_escape_string2($tr[1]));
        if ($explain == null) {
            continue;
        }
        if (strlen($explain) > 128) {
            $explain = substr($explain, 0, 128);
        }
        $I[] = "('{$sig}',E'{$explain}',1)";
    }
    if (count($I) == 0) {
        return;
    }
    $sql = $prefix . @implode(",", $I) . " ON CONFLICT DO NOTHING";
    $postgres = new postgres_sql();
    $postgres->QUERY_SQL($sql);
    if (!$postgres->ok) {
        echo $postgres->mysql_error . "\n";
    }
}