예제 #1
0
function EnablePolicyd()
{
    RemovePolicydWeight();
    $sock = new sockets();
    $users = new usersMenus();
    $POLICYD_WEIGHT_PORT = trim($users->POLICYD_WEIGHT_PORT);
    if ($POLICYD_WEIGHT_PORT == null) {
        $POLICYD_WEIGHT_PORT = 12525;
    }
    $TrustMyNetwork = $sock->GET_INFO("TrustMyNetwork");
    if (!is_numeric($TrustMyNetwork)) {
        $TrustMyNetwork = 1;
    }
    events("Enabling policyd-weight on port {$POLICYD_WEIGHT_PORT}");
    $datas = exec('postconf -h smtpd_recipient_restrictions');
    if ($datas == null) {
        events("Warning postconf return null string...");
    } else {
        $tbl = explode(",", $datas);
        events("EnablePolicyd():: " . count($tbl) . " lines");
        while (list($num, $ligne) = each($tbl)) {
            if (trim($ligne) == null) {
                continue;
            }
            $ARRAY[trim($ligne)] = true;
        }
    }
    reset($tbl);
    if ($TrustMyNetwork == 1) {
        array_unshift($tbl, "permit_mynetworks", "permit_sasl_authenticated", "reject_unauth_destination");
    } else {
        array_unshift($tbl, "permit_sasl_authenticated", "reject_unauth_destination");
    }
    while (list($num, $ligne) = each($tbl)) {
        if (trim($ligne) == null) {
            continue;
        }
        $ARRAY2[trim($ligne)] = true;
    }
    unset($tbl);
    while (list($num, $ligne) = each($ARRAY2)) {
        if (trim($num) == null) {
            continue;
        }
        $tbl[] = $num;
    }
    $tbl[] = "check_client_access hash:/etc/postfix/wbl_connections";
    $tbl[] = "check_recipient_access hash:/etc/postfix/wbl_connections";
    $tbl[] = "check_policy_service inet:127.0.0.1:{$POLICYD_WEIGHT_PORT}";
    $finalstring = implode(",", $tbl);
    $cmd = "postconf -e \"smtpd_recipient_restrictions = {$finalstring}\"";
    events($cmd);
    system($cmd);
    if (!is_file("/etc/postfix/whitelist_connections")) {
        exec("/bin/touch /etc/postfix/whitelist_connections");
    }
    // REJECT OR OK
    $q = new mysql();
    $sql = "SELECT * FROM postfix_whitelist_con";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "{$q->mysql_error}\n";
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $finalwhitelist[] = $ligne["ipaddr"] . "\tOK";
        if (strpos($ligne["hostname"], "*") == 0) {
            $finalwhitelist[] = $ligne["hostname"] . "\tOK";
        }
    }
    if (is_array($finalwhitelist)) {
        $conf = implode("\n", $finalwhitelist);
    }
    events("saving " . strlen($conf) . " bytes length in /etc/postfix/wbl_connections");
    @file_put_contents("/etc/postfix/wbl_connections", $conf);
    system("postmap hash:/etc/postfix/wbl_connections");
    events("adding policyd-weight done...");
}
예제 #2
0
function EnablePolicyd()
{
    RemovePolicydWeight();
    $users = new usersMenus();
    $POLICYD_WEIGHT_PORT = trim($users->POLICYD_WEIGHT_PORT);
    if ($POLICYD_WEIGHT_PORT == null) {
        $POLICYD_WEIGHT_PORT = 12525;
    }
    events("Enabling policyd-weight on port {$POLICYD_WEIGHT_PORT}");
    $datas = exec('postconf -h smtpd_recipient_restrictions');
    if ($datas == null) {
        events("Warning postconf return null string...");
    } else {
        $tbl = explode(",", $datas);
        events("EnablePolicyd():: " . count($tbl) . " lines");
        while (list($num, $ligne) = each($tbl)) {
            if (trim($ligne) == null) {
                continue;
            }
            $ARRAY[trim($ligne)] = true;
        }
    }
    reset($tbl);
    array_unshift($tbl, "permit_mynetworks", "permit_sasl_authenticated", "reject_unauth_destination");
    while (list($num, $ligne) = each($tbl)) {
        if (trim($ligne) == null) {
            continue;
        }
        $ARRAY2[trim($ligne)] = true;
    }
    unset($tbl);
    while (list($num, $ligne) = each($ARRAY2)) {
        if (trim($num) == null) {
            continue;
        }
        $tbl[] = $num;
    }
    $tbl[] = "check_client_access hash:/etc/postfix/wbl_connections";
    $tbl[] = "check_recipient_access hash:/etc/postfix/wbl_connections";
    $tbl[] = "check_policy_service inet:127.0.0.1:{$POLICYD_WEIGHT_PORT}";
    $finalstring = implode(",", $tbl);
    $cmd = "postconf -e \"smtpd_recipient_restrictions = {$finalstring}\"";
    events($cmd);
    system($cmd);
    if (!is_file("/etc/postfix/whitelist_connections")) {
        exec("/bin/touch /etc/postfix/whitelist_connections");
    }
    // REJECT OR OK
    $sock = new sockets();
    $datas = $sock->GET_INFO('PostfixAutoBlockWhiteList');
    $tpl = explode("\n", $datas);
    if (is_array($tpl)) {
        while (list($num, $ligne) = each($tpl)) {
            if ($ligne == null) {
                continue;
            }
            $array[$ligne] = $ligne;
        }
    }
    if (is_array($array)) {
        while (list($num, $ligne) = each($array)) {
            $finalwhitelist[] = $ligne . "\tOK";
        }
    }
    if (is_array($finalwhitelist)) {
        $conf = implode("\n", $finalwhitelist);
    }
    events("saving " . strlen($conf) . " bytes length in /etc/postfix/wbl_connections");
    @file_put_contents("/etc/postfix/wbl_connections", $conf);
    system("postmap hash:/etc/postfix/wbl_connections");
    events("adding policyd-weight done...");
}