コード例 #1
0
function mime_header_checks()
{
    $f = array();
    $main = new maincf_multi("master", "master");
    $enable_attachment_blocking_postfix = $main->GET("enable_attachment_blocking_postfix");
    if (!is_numeric($enable_attachment_blocking_postfix)) {
        $enable_attachment_blocking_postfix = 0;
    }
    $extmime = $main->mime_header_checks();
    $extmime = trim(str_replace("mime_header_checks =", "", $extmime));
    if ($enable_attachment_blocking_postfix == 1) {
        $sql = new mysql();
        $sql = "SELECT * FROM smtp_attachments_blocking WHERE ou='_Global' ORDER BY IncludeByName";
        writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
        $q = new mysql();
        writelogs("-> Qyery", __FUNCTION__, __FILE__, __LINE__);
        $results = $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            writelogs("Error mysql {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
            return null;
        }
        writelogs("-> loop", __FUNCTION__, __FILE__, __LINE__);
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            if ($ligne["IncludeByName"] == null) {
                continue;
            }
            $f[] = $ligne["IncludeByName"];
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " Blocking extensions trough postfix is disabled\n";
    }
    if (count($f) == 0) {
        echo "Starting......: " . date("H:i:s") . " No extensions blocked\n";
        if ($extmime != null) {
            postconf("mime_header_checks", $extmime);
        }
        postconf("mime_header_checks", null);
        return;
    }
    $strings = implode("|", $f);
    echo "Starting......: " . date("H:i:s") . " " . count($f) . " extensions blocked\n";
    $pattern[] = "/^\\s*Content-(Disposition|Type).*name\\s*=\\s*\"?(.+\\.({$strings}))\"?\\s*\$/\tREJECT file attachment types is not allowed. File \"\$2\" has the unacceptable extension \"\$3\"";
    $pattern[] = "";
    @file_put_contents("/etc/postfix/mime_header_checks", implode("\n", $pattern));
    if ($extmime != null) {
        $extmime = ",{$extmime}";
    }
    postconf("mime_header_checks", "regexp:/etc/postfix/mime_header_checks{$extmime}");
    echo "Starting......: " . date("H:i:s") . " mime_header_checks() done\n";
}