Esempio n. 1
0
function iprulesDNS()
{
    $unix = new unix();
    $IPCHAIN = "dnsfilter";
    $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($unix->process_exists(@file_get_contents($pidfile), basename(__FILE__))) {
        echo "Starting......: " . date("H:i:s") . " iptables configurator already executed PID " . @file_get_contents($pidfile) . "\n";
        die;
    }
    $pid = getmypid();
    file_put_contents($pidfile, $pid);
    $sock = new sockets();
    $EnableIptablesDNS = $sock->GET_INFO("EnableIptablesDNS");
    if (!is_numeric($EnableIptablesDNS)) {
        $EnableIptablesDNS = 1;
    }
    if ($EnableIptablesDNS == 0) {
        $ip = new iptables_exec();
        if ($ip->is_chain_exists($IPCHAIN)) {
            shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}");
            shell_exec("{$GLOBALS["iptables"]} -X {$IPCHAIN}");
        }
        return;
    }
    $tmpfile = $unix->FILE_TEMP();
    $curl = new ccurl("https://raw.github.com/smurfmonitor/dns-iptables-rules/master/domain-blacklist.txt");
    $curl->NoHTTP_POST = true;
    if ($curl->GetFile($tmpfile)) {
        $size = @filesize($tmpfile);
        if ($size < 100) {
            $tmpfile = "/usr/share/artica-postfix/bin/install/iptables_defaults.txt";
        }
    }
    $ip = new iptables_exec();
    if (!$ip->is_chain_exists($IPCHAIN)) {
        echo "Adding chain {$IPCHAIN}\n";
        shell_exec("{$GLOBALS["iptables"]} -N {$IPCHAIN}");
        shell_exec("{$GLOBALS["iptables"]} -I INPUT -p udp --dport 53 -j {$IPCHAIN}");
    } else {
        echo "chain {$IPCHAIN} exists...\n";
    }
    shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}");
    shell_exec("{$GLOBALS["iptables"]} -A {$IPCHAIN} -j RETURN");
    $f = explode("\n", @file_get_contents($tmpfile));
    while (list($num, $ligne) = each($f)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        $ligne = str_replace("INPUT", $IPCHAIN, $ligne);
        $ligne = str_replace("iptables", $GLOBALS["iptables"], $ligne);
        $results = array();
        exec($ligne, $results);
        echo "{$ligne}\n";
        while (list($a, $b) = each($results)) {
            echo "{$b}\n";
        }
    }
}
function StartBubble()
{
    $q = new mysql();
    if (!$q->test_mysql_connection()) {
        echo "Starting......: " . date("H:i:s") . " Postfix Bubble Mysql is not ready aborting...\n";
        return;
    }
    $ip = new iptables_exec();
    $ip->buildrules();
}