Esempio n. 1
0
function MiltergreyList_inject($array)
{
    if (count($array) == 0) {
        events("MiltergreyList_inject():: Nothing to do...", __FILE__);
        return;
    }
    $q = new mysql_postfix_builder();
    events("MiltergreyList_inject():: Analyze " . count($array) . " rows", __FILE__);
    while (list($tablename, $sqls) = each($array)) {
        events("MiltergreyList_inject():: build-sql {$tablename} > " . count($array) . " rows", __FILE__);
        $q->milter_BuildHourTable($tablename);
        if (!$q->TABLE_EXISTS($tablename)) {
            events("MiltergreyList_inject():: {$tablename} no such table", __FILE__);
        }
        $prefix = "INSERT IGNORE INTO {$tablename} (`zmd5`,`ztime`,`zhour`,`mailfrom`,`instancename`,`mailto`,`domainfrom`,`domainto`,`senderhost`,`failed`) VALUES ";
        $q->QUERY_SQL($prefix . @implode(",", $sqls));
        if (!$q->ok) {
            events("MiltergreyList_inject():: {$q->mysql_error}", __FILE__);
        }
    }
    events("MiltergreyList_inject():: Finish...", __FILE__);
}
function list_table()
{
    $MyPage = CurrentPageName();
    $page = 1;
    $tpl = new templates();
    $table = date("Ymd") . "_dcnx";
    $q = new mysql_postfix_builder();
    if (!$q->TABLE_EXISTS($table)) {
        json_error_show("{$table} no such table");
    }
    $t = $_GET["t"];
    $database = null;
    $FORCE_FILTER = 1;
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("No item");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error}");
        }
        $total = $ligne["TCOUNT"];
        if ($total == 0) {
            json_error_show("No rows for {$searchstring}");
        }
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 1;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show("{$q->mysql_error}<hr>{$sql}<hr>");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("No data...", 1);
    }
    $today = date('Y-m-d');
    $style = "font-size:14px;";
    $unknown = $tpl->_ENGINE_parse_body("{unknown}");
    //Hour | cnx | hostname                                       | domain                    |
    while ($ligne = mysql_fetch_assoc($results)) {
        $md = md5(serialize($ligne));
        $cells = array();
        $cells[] = "<span style='font-size:14px;'>{$ligne["Hour"]}h</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["cnx"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["hostname"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["domain"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["ipaddr"]}</span>";
        $data['rows'][] = array('id' => $line["zmd5"], 'cell' => $cells);
    }
    echo json_encode($data);
}
function list_table()
{
    $Now = false;
    $MyPage = CurrentPageName();
    $page = 1;
    $tpl = new templates();
    if (!isset($_GET["failed"])) {
        $_GET["failed"] = null;
    }
    $table = "mgreyd_" . date("Ymd");
    $q = new mysql_postfix_builder();
    if (isset($_GET["hier"])) {
        $hier = strtotime($q->HIER() . " 00:00:00");
        $table = "mgreyd_" . date("Ymd", $hier);
    }
    if (isset($_GET["now"])) {
        $Now = true;
        $table = "MGREY_RTT";
    }
    if (!$q->TABLE_EXISTS($table)) {
        json_error_show("{$table} no such table");
    }
    $t = $_GET["t"];
    $database = null;
    $FORCE_FILTER = 1;
    if ($_GET["failed"] != null) {
        $FORCE_FILTER = "`failed`='{$_GET["failed"]}'";
    }
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("No item");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error}");
        }
        $total = $ligne["TCOUNT"];
        if ($total == 0) {
            json_error_show("No rows for {$searchstring}");
        }
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 1;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show("{$q->mysql_error}<hr>{$sql}<hr>");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("No data...", 1);
    }
    $today = date('Y-m-d');
    $style = "font-size:14px;";
    $color = "black";
    $unknown = $tpl->_ENGINE_parse_body("{unknown}");
    $arrayA["accept"] = $tpl->javascript_parse_text("{sent}");
    $arrayA["tempfail"] = $tpl->javascript_parse_text("{greylist}");
    $arrayA["reject"] = $tpl->javascript_parse_text("{blacklist}");
    //Hour | cnx | hostname                                       | domain                    |
    while ($ligne = mysql_fetch_assoc($results)) {
        $style = "background-color:#03BA2F;color:#FFFFFF;margin:-5px;padding:5px;font-weight:bold;text-transform:capitalize;font-size:14px;";
        $failed = $ligne["failed"];
        if ($failed == "tempfail") {
            $style = "background-color:#949494;color:#FFFFFF;margin:-5px;padding:5px;font-weight:bold;text-transform:capitalize;font-size:14px;";
        }
        if ($failed == "reject") {
            $style = "background-color:#DD1212;color:#FFFFFF;margin:-5px;padding:5px;font-weight:bold;text-transform:capitalize;font-size:14px;";
        }
        if ($Now) {
            $ligne["hits"] = 1;
        }
        $text_hour = "{$ligne["zhour"]}h";
        if ($Now) {
            $text_hour = date("H:i:s", strtotime($ligne["ztime"]));
        }
        $md = md5(serialize($ligne));
        $cells = array();
        $cells[] = "<span style='font-size:14px;'>{$text_hour}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["hits"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["senderhost"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["mailfrom"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["mailto"]}</span>";
        $cells[] = "<span style='font-size:14px;'><div style='{$style}'>{$arrayA[$failed]}</div></span>";
        $data['rows'][] = array('id' => $line["zmd5"], 'cell' => $cells);
    }
    echo json_encode($data);
}
function greylistm_items()
{
    $month = $_GET["month"];
    $t = $_GET["t"];
    if (!is_numeric($month)) {
        $month = date("Ym");
    }
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_postfix_builder();
    $ct = new user($_SESSION["uid"]);
    $mails = $ct->HASH_ALL_MAILS;
    while (list($index, $message) = each($mails)) {
        $q1[] = " (`mailto`='{$message}')";
    }
    $search = '%';
    $table = "mgreym_{$month}";
    $database = "artica_backup";
    $page = 1;
    $FORCE_FILTER = " AND (" . @implode("OR", $q1) . ")";
    if (!$q->TABLE_EXISTS($table)) {
        json_error_show("{$table}: No such table", 0, true);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $zmd5 = md5($ligne["filename"]);
        $color = "#D90505";
        $res = strtolower(trim($ligne["failed"]));
        if ($res == "accept") {
            $color = "#00922B";
        }
        $delete = imgsimple("delete-24.png", "", "DeleteFileNameHosting{$t}('{$ligne["filename"]}','{$zmd5}')");
        $ztime = strtotime($ligne["zday"] . " 00:00:00");
        $zday = $tpl->_ENGINE_parse_body(date("{l} d", $ztime));
        $ligne["failed"] = $tpl->_ENGINE_parse_body("{{$ligne["failed"]}}");
        $data['rows'][] = array('id' => "D{$zmd5}", 'cell' => array("<span style='font-size:14px;color:black'>{$zday}</a></span>", "<span style='font-size:14px;color:black'>{$ligne["hits"]}</a></span>", "<span style='font-size:14px;color:black'>{$urljs}{$ligne["mailfrom"]}</a></span>", "<span style='font-size:14px;color:{$color}'>{$urljs}{$ligne["failed"]}</a></span>"));
    }
    echo json_encode($data);
}