Пример #1
0
if ($unix->process_exists(@file_get_contents($pidfile))) {
    if ($GLOBALS["VERBOSE"]) {
        echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n";
    }
    writelogs(basename(__FILE__) . ":Already executed.. aborting the process", basename(__FILE__), __FILE__, __LINE__);
    die;
}
@file_put_contents($pidfile, getmypid());
$GLOBALS["nmblookup"] = $unix->find_program("nmblookup");
if ($argv[1] == "lookup") {
    echo "{$argv[2]}:" . nmblookup($argv[2], $argv[3]) . "\n";
    die;
}
if ($argv[1] == '--single-computer') {
    writelogs("update_computer({$argv[2]},{$argv[3]},{$argv[4]}) ", basename(__FILE__), __FILE__, __LINE__);
    update_computer($argv[2], $argv[3], $argv[4]);
    die;
}
if ($GLOBALS["VERBOSE"]) {
    echo " --> Argument={$argv[1]}\n";
    echo " --> Force={$GLOBALS["FORCE"]}\n";
}
$sock = new sockets();
$EnableDHCPServer = $sock->GET_INFO('EnableDHCPServer');
$ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases");
if ($ComputersAllowDHCPLeases == null) {
    $ComputersAllowDHCPLeases = 1;
}
if ($EnableDHCPServer == 0) {
    writelogs("EnableDHCPServer is disabled, aborting...", "MAIN", __FILE__, __LINE__);
    die;
Пример #2
0
function parseLeases()
{
    $BaseWorkDir = "/var/log/artica-postfix/DHCP-LEASES";
    @mkdir($BaseWorkDir, 0755, true);
    if (!($handle = opendir($BaseWorkDir))) {
        echo "Failed open {$BaseWorkDir}\n";
        return;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "{$BaseWorkDir}/{$filename}";
        $array = unserialize(@file_get_contents($targetFile));
        @unlink($targetFile);
        if (!is_array($array)) {
            continue;
        }
        $ip = $array["IP"];
        $mac = $array["MAC"];
        $hostname = $array["hostname"];
        if ($ip == null) {
            continue;
        }
        CreateComputerLogs($ip, $mac, $hostname);
        update_computer($ip, $mac, $hostname);
    }
}
Пример #3
0
function parseLeases()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".parseLeases.pid";
    $pidTime = "/etc/artica-postfix/pids/exec.dhcpd-leases.php.parseLeases.time";
    if ($unix->process_exists(@file_get_contents($pidfile, basename(__FILE__)))) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n";
        }
        die;
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $TimeFile = $unix->file_time_min($pidTime);
        if ($TimeFile < 5) {
            if ($GLOBALS["VERBOSE"]) {
                echo " {$TimeFile}Mn, require 5mn\n";
            }
            die;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $pid = dhcpd_pid();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> DHCPD service not running...\n";
        }
        return;
    }
    $ptime = $unix->PROCCESS_TIME_MIN($pid);
    if ($ptime < 2) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> DHCPD service running before 2mn...\n";
        }
        return;
    }
    $BaseWorkDir = "/var/log/artica-postfix/DHCP-LEASES";
    @mkdir($BaseWorkDir, 0755, true);
    if (!($handle = opendir($BaseWorkDir))) {
        echo "Failed open {$BaseWorkDir}\n";
        return;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "{$BaseWorkDir}/{$filename}";
        $TimeFile = $unix->file_time_min($targetFile);
        if ($TimeFile > 240) {
            @unlink($TimeFile);
            continue;
        }
        $array = unserialize(@file_get_contents($targetFile));
        @unlink($targetFile);
        if (!is_array($array)) {
            continue;
        }
        $ip = $array["IP"];
        $mac = $array["MAC"];
        $hostname = $array["hostname"];
        if ($ip == null) {
            continue;
        }
        CreateComputerLogs($ip, $mac, $hostname);
        update_computer($ip, $mac, $hostname);
    }
}