function reload()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    build();
    $recursor_pid = pdns_recursor_pid();
    $pdns_pid = PID_NUM();
    $pdns_control = $unix->find_program('pdns_control');
    $rec_control = $unix->find_program('rec_control');
    shell_exec("{$pdns_control} --config-dir=/etc/powerdns reload >/dev/null 2>&1");
    shell_exec("{$rec_control} --config-dir=/etc/powerdns --socket-dir=/var/run/pdns reload >/dev/null 2>&1");
}
Exemple #2
0
function start_recursor()
{
    $sock = new sockets();
    $unix = new unix();
    $DisablePowerDnsManagement = $sock->GET_INFO("DisablePowerDnsManagement");
    $PowerDNSRecursorQuerLocalAddr = $sock->GET_INFO("PowerDNSRecursorQuerLocalAddr");
    $EnablePDNS = $sock->GET_INFO("EnablePDNS");
    if (!is_numeric($DisablePowerDnsManagement)) {
        $DisablePowerDnsManagement = 0;
    }
    $EnableChilli = 0;
    $chilli = $unix->find_program("chilli");
    if (is_file($chilli)) {
        $EnableChilli = $sock->GET_INFO("EnableChilli");
        if (!is_numeric($EnableChilli)) {
            $EnableChilli = 0;
        }
    }
    if ($EnableChilli == 1) {
        echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor HotSpot is enabled...\n";
        stop_recursor();
        return;
    }
    if ($PowerDNSRecursorQuerLocalAddr == null) {
        $net = new networking();
        $net->ifconfig("eth0");
        if ($net->tcp_addr != null) {
            if ($net->tcp_addr != "0.0.0.0") {
                $PowerDNSRecursorQuerLocalAddr = $net->tcp_addr;
            }
        }
    }
    if (!is_numeric($EnablePDNS)) {
        $EnablePDNS = 0;
    }
    $nohup = $unix->find_program("nohup");
    $recursorbin = $unix->find_program("pdns_recursor");
    if (!is_file($recursorbin)) {
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor Not installed, aborting task\n";
    }
    $pid = pdns_recursor_pid();
    if ($unix->process_exists($pid)) {
        $pidtime = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor Already running PID {$pid} since {$pidtime}mn\n";
        return;
    }
    if ($DisablePowerDnsManagement == 1) {
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor DisablePowerDnsManagement={$DisablePowerDnsManagement}, aborting task\n";
        return;
    }
    if ($EnablePDNS == 0) {
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor service is disabled, aborting task\n";
        stop_recursor();
        return;
    }
    $trace = null;
    $quiet = "yes";
    $PowerDNSLogLevel = $sock->GET_INFO("PowerDNSLogLevel");
    $PowerDNSLogsQueries = $sock->GET_INFO("PowerDNSLogsQueries");
    if (!is_numeric($PowerDNSLogLevel)) {
        $PowerDNSLogLevel = 1;
    }
    $query_local_address = " --query-local-address={$PowerDNSRecursorQuerLocalAddr}";
    if ($PowerDNSLogLevel > 8) {
        $trace = ' --trace';
    }
    if ($PowerDNSLogsQueries == 1) {
        $quiet = 'no';
    }
    echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor Network card to send queries {$PowerDNSRecursorQuerLocalAddr}\n";
    echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor Log level [{$PowerDNSLogLevel}]\n";
    echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor Verify MySQL DB...\n";
    checkMysql();
    @mkdir("/var/run/pdns", 0755, true);
    $cmdline = "{$nohup} {$recursorbin} --daemon --export-etc-hosts --socket-dir=/var/run/pdns --quiet={$quiet} --config-dir=/etc/powerdns{$trace} {$query_local_address} >/dev/null 2>&1 &";
    shell_exec($cmdline);
    sleep(1);
    $pid = pdns_recursor_pid();
    if (!$unix->process_exists($pid)) {
        for ($i = 0; $i < 5; $i++) {
            echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor waiting " . ($i + 1) . "/5\n";
            $pid = pdns_recursor_pid();
            if ($unix->process_exists($pid)) {
                break;
            }
        }
    }
    $pid = pdns_recursor_pid();
    if (!$unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor failed\n";
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor \"{$cmdline}\"\n";
    } else {
        echo "Starting......: " . date("H:i:s") . " PowerDNS Recursor success PID {$pid}\n";
    }
}