예제 #1
0
function update_computer($ip, $mac, $name)
{
    $sock = new sockets();
    $ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases");
    if ($ComputersAllowDHCPLeases == null) {
        $ComputersAllowDHCPLeases = 1;
    }
    if ($ComputersAllowDHCPLeases == 0) {
        localsyslog("`ComputersAllowDHCPLeases` Aborting updating the LDAP database");
        return;
    }
    $mac = trim($mac);
    $name = trim(strtolower($name));
    $ip = trim($ip);
    if ($ip == null) {
        return;
    }
    if ($mac == null) {
        return;
    }
    if ($name == null) {
        return;
    }
    $mac = strtolower(str_replace("-", ":", $mac));
    $ipClass = new IP();
    if ($ipClass->isIPAddress($name)) {
        localsyslog("`{$name}` is a TCP IP address, aborting updating the LDAP database");
        return;
    }
    $ip = nmblookup($name, $ip);
    $dhcp = new dhcpd();
    $GLOBALS["domain"] = $dhcp->ddns_domainname;
    $comp = new computers();
    $uid = $comp->ComputerIDFromMAC($mac);
    if (strpos($name, ".") > 0) {
        $NAMETR = explode(".", $name);
        $name = $NAMETR[0];
        unset($NAMETR[0]);
        $GLOBALS["domain"] = @implode(".", $NAMETR);
    }
    if ($ipClass->isIPAddress($uid)) {
        $comp = new computers($uid);
        localsyslog("Removing computer ({$uid}) {$mac}");
        $comp->DeleteComputer();
        $uid = null;
        $uid = $comp->ComputerIDFromMAC($mac);
    }
    localsyslog("{$mac} -> uid:`{$uid}`");
    if ($uid == null) {
        $add = true;
        $uid = "{$name}\$";
        $comp = new computers();
        $comp->ComputerRealName = $name;
        $comp->ComputerMacAddress = $mac;
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->uid = $uid;
        $ComputerRealName = $name;
        localsyslog("Create new computer {$name[$ip]} ({$uid}) {$mac} in domain {$comp->DnsZoneName}");
        $comp->Add();
    } else {
        $comp = new computers($uid);
        if (strpos($comp->ComputerRealName, ".") > 0) {
            $NAMETR = explode(".", $name);
            $comp->ComputerRealName = $NAMETR[0];
        }
        if ($comp->ComputerRealName == null) {
            $comp->ComputerRealName = $name;
        }
        if ($ipClass->isIPAddress($comp->ComputerRealName)) {
            $comp->ComputerRealName = $name;
        }
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        localsyslog("Update computer {$comp->ComputerRealName}[{$ip}] ({$uid}) {$mac} in domain {$comp->DnsZoneName}");
        $comp->Edit();
    }
    $dns = new pdns($GLOBALS["domain"]);
    $dns->EditIPName(strtolower($name), $ip, 'A', $mac);
}
예제 #2
0
function COMPUTER_SAVE_INFOS()
{
    $tpl = new templates();
    if (preg_match("#newcomputer#", $_GET["uid"])) {
        echo $tpl->_ENGINE_parse_body('ERROR:{give_computer_name}');
        exit;
    }
    if ($_GET["add_computer_form"]) {
        if ($_GET["ComputerMacAddress"] != null) {
            $comp = new computers();
            $uidfound = $comp->ComputerIDFromMAC($_GET["ComputerMacAddress"]);
            if (trim($uidfound) != null) {
                if ($uidfound != $_GET["uid"] . '$') {
                    echo $tpl->javascript_parse_text("{this_mac_address_is_already_used_by}:{$uidfound}");
                    return;
                }
            }
        }
    }
    $_GET["uid"] = str_replace("%24", "\$", $_GET["uid"]);
    $_GET["uid"] = str_replace("\$\$", "\$", $_GET["uid"]);
    $computer = new computers($_GET["userid"]);
    $fIP = explode(".", $_GET["ComputerIP"]);
    while (list($index, $val) = each($fIP)) {
        $fIP[$index] = intval($val);
    }
    $_GET["ComputerIP"] = @implode(".", $fIP);
    $computer->uid = $_GET["uid"] . '$';
    $computer->ComputerMacAddress = $_GET["ComputerMacAddress"];
    $computer->ComputerIP = $_GET["ComputerIP"];
    if (isset($_GET["DnsZoneName"])) {
        $computer->DnsZoneName = $_GET["DnsZoneName"];
    }
    if (isset($_GET["ComputerCPU"])) {
        $computer->ComputerCPU = $_GET["ComputerCPU"];
    }
    if (isset($_GET["DnsType"])) {
        $computer->DnsType = $_GET["DnsType"];
    }
    if (isset($_GET["DnsMXLength"])) {
        $computer->DnsMXLength = $_GET["DnsMXLength"];
    }
    if (isset($_GET["ComputerCPU"])) {
        $computer->ComputerCPU = $_GET["ComputerCPU"];
    }
    if (isset($_GET["ComputerOS"])) {
        $computer->ComputerOS = $_GET["ComputerOS"];
    }
    if (isset($_GET["ComputerMachineType"])) {
        $computer->ComputerMachineType = $_GET["ComputerMachineType"];
    }
    if ($_GET["userid"] == "newcomputer\$") {
        if (!$computer->Add()) {
            echo "ERROR:{$computer->ldap_error}";
            exit;
        } else {
            writelogs("Success updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
            if (isset($_GET["gpid"])) {
                writelogs("adding computer to group {$_GET["gpid"]}", __FUNCTION__, __FILE__, __LINE__);
                $group = new groups($_GET["gpid"]);
                $group->AddUsertoThisGroup($computer->uid);
                exit;
            }
            exit;
        }
    }
    if (!$computer->Edit()) {
        writelogs("!!FAILED updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
        echo $computer->ldap_error;
    } else {
        writelogs("Success updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
    }
}
예제 #3
0
function update_computer($ip, $mac, $name)
{
    $sock = new sockets();
    $ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases");
    if ($ComputersAllowDHCPLeases == null) {
        $ComputersAllowDHCPLeases = 1;
    }
    if ($ComputersAllowDHCPLeases == 0) {
        writelogs("ComputersAllowDHCPLeases is disabled, aborting...", "update_computer", __FILE__, __LINE__);
        die;
    }
    $mac = trim($mac);
    $name = trim(strtolower($name));
    $ip = trim($ip);
    if ($ip == null) {
        return;
    }
    if ($mac == null) {
        return;
    }
    if ($name == null) {
        return;
    }
    $ip = nmblookup($name, $ip);
    $unix = new unix();
    $unix->add_EtcHosts($name, $ip);
    $dhcp = new dhcpd();
    $GLOBALS["domain"] = $dhcp->ddns_domainname;
    $comp = new computers();
    $uid = $comp->ComputerIDFromMAC($mac);
    if ($uid == null) {
        $add = true;
        $uid = "{$name}\$";
        $comp = new computers();
        $comp->ComputerRealName = $name;
        $comp->ComputerMacAddress = $mac;
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->uid = $uid;
        $ComputerRealName = $HOST;
        $comp->Add();
    } else {
        $comp = new computers($uid);
        if ($comp->ComputerRealName == null) {
            $ComputerRealName = $name;
        }
        if (preg_match("#[0-9]+\\.[0-9]+\\.#", $comp->ComputerRealName)) {
            $comp->ComputerRealName = $name;
        }
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->Edit();
    }
    $dns = new pdns($GLOBALS["domain"]);
    $dns->EditIPName(strtolower($name), $ip, 'A', $mac);
}
예제 #4
0
function ImportDatas($datas)
{
    $import = unserialize(base64_decode($datas));
    $hash = $import["COMPUTERS"];
    for ($i = 0; $i < $hash["count"]; $i++) {
        $comp = new computers();
        $uidorg = $hash[$i]["uid"][0];
        $dnszonename = $hash[$i]["dnszonename"][0];
        $dnstype = $hash[$i]["dnstype"][0];
        $computermachinetype = $hash[$i]["computermachinetype"][0];
        $computerip = $hash[$i]["computerip"][0];
        $computermacaddress = $hash[$i]["computermacaddress"][0];
        $ComputerRealName = $hash[$i][strtolower("ComputerRealName")][0];
        if ($ComputerRealName == null) {
            $ComputerRealName = str_replace('$', '', $uidorg);
        }
        writelogs("Importing computer: {$uid} {$computerip} {$computermacaddress}", __FUNCTION__, __FILE__, __LINE__);
        $uid = $comp->ComputerIDFromMAC($computermacaddress);
        if ($uid == null) {
            $uid = $uidorg;
            $comp = new computers();
            $comp->ComputerRealName = $ComputerRealName;
            $comp->ComputerMacAddress = $computermacaddress;
            $comp->ComputerIP = $computerip;
            $comp->DnsZoneName = $dnszonename;
            $comp->ComputerMachineType = $computermachinetype;
            $comp->uid = $uid;
            $comp->Add();
        } else {
            $comp = new computers($uid);
            $comp->ComputerIP = $computerip;
            $comp->DnsZoneName = $dnszonename;
            $comp->ComputerMachineType = $computermachinetype;
            $comp->Edit();
        }
        $dns = new pdns($dnszonename);
        $dns->EditIPName(strtolower($ComputerRealName), $computerip, $dnstype, $computermacaddress);
    }
}
예제 #5
0
function COMPUTER_SAVE_INFOS()
{
    $tpl = new templates();
    if (preg_match("#newcomputer#", $_GET["uid"])) {
        echo $tpl->_ENGINE_parse_body('ERROR:{give_computer_name}');
        exit;
    }
    $computer = new computers($_GET["userid"]);
    $computer->uid = $_GET["uid"] . '$';
    $computer->ComputerMacAddress = $_GET["ComputerMacAddress"];
    $computer->ComputerIP = $_GET["ComputerIP"];
    $computer->DnsZoneName = $_GET["DnsZoneName"];
    $computer->ComputerCPU = $_GET["ComputerCPU"];
    $computer->DnsType = $_GET["DnsType"];
    $computer->DnsMXLength = $_GET["DnsMXLength"];
    $computer->dhcpfixed = $_GET["dhcpfixed"];
    $computer->VolatileIPAddress = $_GET["VolatileIPAddress"];
    if ($_GET["userid"] == "newcomputer\$") {
        if (!$computer->Add()) {
            echo "ERROR:{$computer->ldap_error}";
            exit;
        } else {
            writelogs("Success updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
            echo html_entity_decode($tpl->_ENGINE_parse_body('{success}'));
            if (isset($_GET["gpid"])) {
                writelogs("adding computer to group {$_GET["gpid"]}", __FUNCTION__, __FILE__, __LINE__);
                $group = new groups($_GET["gpid"]);
                $group->AddUsertoThisGroup($computer->uid);
                exit;
            }
            exit;
        }
    }
    if (!$computer->Edit()) {
        echo $computer->ldap_error;
    } else {
        writelogs("Success updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
        echo html_entity_decode($tpl->_ENGINE_parse_body('{success}'));
    }
}
예제 #6
0
function update_computer($ip, $mac, $name)
{
    $mac = trim($mac);
    $name = trim(strtolower($name));
    $ip = trim($ip);
    if ($ip == null) {
        return;
    }
    if ($mac == null) {
        return;
    }
    if ($name == null) {
        return;
    }
    $ip = nmblookup($name, $ip);
    $unix = new unix();
    $unix->add_EtcHosts($name, $ip);
    $dhcp = new dhcpd();
    $GLOBALS["domain"] = $dhcp->ddns_domainname;
    $comp = new computers();
    $uid = $comp->ComputerIDFromMAC($mac);
    if ($uid == null) {
        $add = true;
        $uid = "{$name}\$";
        $comp = new computers();
        $comp->ComputerRealName = $name;
        $comp->ComputerMacAddress = $mac;
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->uid = $uid;
        $ComputerRealName = $HOST;
        $comp->Add();
    } else {
        $comp = new computers($uid);
        if ($comp->ComputerRealName == null) {
            $ComputerRealName = $name;
        }
        if (preg_match("#[0-9]+\\.[0-9]+\\.#", $comp->ComputerRealName)) {
            $comp->ComputerRealName = $name;
        }
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->Edit();
    }
    $dns = new pdns($GLOBALS["domain"]);
    $dns->EditIPName(strtolower($name), $ip, 'A', $mac);
}
예제 #7
0
function COMPUTER_SAVE_INFOS()
{
    $tpl = new templates();
    if (preg_match("#newcomputer#", $_GET["uid"])) {
        echo $tpl->_ENGINE_parse_body('ERROR:{give_computer_name}');
        exit;
    }
    if ($_GET["add_computer_form"]) {
        if ($_GET["ComputerMacAddress"] != null) {
            $comp = new computers();
            $uidfound = $comp->ComputerIDFromMAC($_GET["ComputerMacAddress"]);
            if (trim($uidfound) != null) {
                if ($uidfound != $_GET["uid"] . '$') {
                    echo $tpl->javascript_parse_text("{this_mac_address_is_already_used_by}:{$uidfound}");
                    return;
                }
            }
        }
    }
    $computer = new computers($_GET["userid"]);
    $computer->uid = $_GET["uid"] . '$';
    $computer->ComputerMacAddress = $_GET["ComputerMacAddress"];
    $computer->ComputerIP = $_GET["ComputerIP"];
    $computer->DnsZoneName = $_GET["DnsZoneName"];
    $computer->ComputerCPU = $_GET["ComputerCPU"];
    $computer->DnsType = $_GET["DnsType"];
    $computer->DnsMXLength = $_GET["DnsMXLength"];
    $computer->dhcpfixed = $_GET["dhcpfixed"];
    $computer->VolatileIPAddress = $_GET["VolatileIPAddress"];
    if ($_GET["userid"] == "newcomputer\$") {
        if (!$computer->Add()) {
            echo "ERROR:{$computer->ldap_error}";
            exit;
        } else {
            writelogs("Success updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
            if (isset($_GET["gpid"])) {
                writelogs("adding computer to group {$_GET["gpid"]}", __FUNCTION__, __FILE__, __LINE__);
                $group = new groups($_GET["gpid"]);
                $group->AddUsertoThisGroup($computer->uid);
                exit;
            }
            exit;
        }
    }
    if (!$computer->Edit()) {
        echo $computer->ldap_error;
    } else {
        writelogs("Success updating/adding {$computer->uid}", __FUNCTION__, __FILE__, __LINE__);
    }
}
예제 #8
0
function parsefile($filename, $uid)
{
    $datas = file_get_contents($filename);
    $tbl = explode("\n", $datas);
    if (!is_array($tbl)) {
        return null;
    }
    while (list($num, $ligne) = each($tbl)) {
        if (preg_match("#([0-9]+).+?open\\s+(.+)#", $ligne, $re)) {
            $array[] = $re[1] . ":" . $re[2];
            continue;
        }
        if (preg_match("#^Running:(.+)#", $ligne, $re)) {
            $ComputerRunning = $re[1];
            continue;
        }
        if (preg_match("#^OS details:(.+)#", $ligne, $re)) {
            $ComputerOS = $re[1];
            continue;
        }
        if (preg_match("#^MAC Address:(.+).+?\\((.+?)\\)#", $ligne, $re)) {
            $ComputerMacAddress = $re[1];
            $ComputerMachineType = $re[2];
            continue;
        }
        if (preg_match("#^MAC Address:(.+)#", $ligne, $re)) {
            $ComputerMacAddress = $re[1];
            continue;
        }
    }
    if ($ComputerMacAddress != null) {
        $computer = new computers();
        $cpid = $computer->ComputerIDFromMAC($ComputerMacAddress);
    }
    if ($cpid == null) {
        $cpid = $uid;
    }
    echo "Save infos for {$cpid}\n";
    echo "ComputerMacAddress: {$ComputerMacAddress}\n";
    echo "ComputerOS: {$ComputerOS}\n";
    $computer = new computers($cpid . "\$");
    if ($ComputerMacAddress != null) {
        $computer->ComputerMacAddress = $ComputerMacAddress;
    }
    if ($ComputerOS != null) {
        $computer->ComputerOS = $ComputerOS;
    }
    if ($ComputerRunning != null) {
        $computer->ComputerRunning = $ComputerRunning;
    }
    if ($ComputerMachineType != null) {
        $computer->ComputerMachineType = $ComputerMachineType;
    }
    if (is_array($array)) {
        $computer->ComputerOpenPorts = implode("\n", $array);
    }
    $computer->Edit();
    echo $datas;
}
예제 #9
0
function receive_noop_connection()
{
    $datas = base64_decode($_GET["noop"]);
    // 00-0C-29-09-BB-77|192.168.1.248|GRAPHICS|Windows XP SP3|Windows XP|SP3|=Intel;Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz;2400;MMX|C:;34949382144
    $datas = explode("|", $datas);
    @file_put_contents("/tmp/datas.txt", implode("\n", $datas));
    while (list($num, $ligne) = each($datas)) {
        writelogs("=>{$num}): {$ligne}", __FUNCTION__, __FILE__, __LINE__);
    }
    $MAC = $datas[0];
    $MAC = str_replace("-", ":", $MAC);
    $LOCAL_IP = $datas[1];
    $COMPUTER_NAME = $datas[2];
    $OS_VER = $datas[3];
    $CPUAR = explode(";", $datas[6]);
    $CPU_INFO = $CPUAR[1];
    $CPU_INFO = str_replace("  ", " ", $CPU_INFO);
    $domain = strtolower($datas[9]);
    $uptime = strtolower($datas[13]);
    if (!preg_match("#(.+?)\\.(.+)#", $domain)) {
        $domain = null;
    }
    $computer = new computers();
    $uid = $computer->ComputerIDFromMAC($MAC);
    writelogs("[{$uid}] ({$COMPUTER_NAME}):: mac={$MAC}, ip={$LOCAL_IP}, system {$OS_VER} ({$CPU_INFO}) uptime={$uptime}", __FUNCTION__, __LINE__);
    if ($uid == null) {
        $computer->uid = "{$COMPUTER_NAME}\$";
        $computer->ComputerMacAddress = $MAC;
        $computer->ComputerIP = $LOCAL_IP;
        if ($domain != null) {
            $computer->DnsZoneName = $domain;
        }
        $computer->ComputerRealName = $COMPUTER_NAME;
        $computer->ComputerCPU = $CPU_INFO;
        $computer->ComputerOS = $OS_VER;
        if ($uptime != null) {
            $computer->ComputerUpTime = $uptime;
        }
        $computer->Add();
    } else {
        $computer = new computers($uid);
        $computer->ComputerIP = $LOCAL_IP;
        $computer->ComputerRealName = $COMPUTER_NAME;
        $computer->ComputerCPU = $CPU_INFO;
        $computer->ComputerOS = $OS_VER;
        $computer->ComputerMacAddress = $MAC;
        if ($domain != null) {
            $computer->DnsZoneName = $domain;
        }
        if ($uptime != null) {
            $computer->ComputerUpTime = $uptime;
        }
        $computer->Edit();
    }
    $MAC = str_replace("-", ':', $MAC);
    $sql = "INSERT INTO computers_events (MAC,zDate,events_type,events) VALUES('{$MAC}',NOW(),'communication','{success_artica_agent_updateinfo}')";
    $q = new mysql();
    $q->QUERY_SQL($sql, 'artica_backup');
    $sql = "SELECT * FROM computers_tasks WHERE MAC='{$MAC}' AND task_enabled=1 ORDER BY ID DESC";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        echo "<task>{$ligne["ID"]}</task><task_type>{$ligne["task_type"]}</task_type><schedule>{$ligne["schedule"]}</schedule><path>{$ligne["path"]}</path>\n";
    }
    $sql = "SELECT * FROM computers_orders WHERE MAC='{$MAC}' ORDER BY ID DESC";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ligne["parameters"] = base64_encode($ligne["parameters"]);
        echo "<order>{$ligne["ID"]}</order><task_type>{$ligne["task_type"]}</task_type><parameters>{$ligne["parameters"]}</parameters><taskid>{$ligne["taskid"]}</taskid>\n";
    }
}
예제 #10
0
function host_edit()
{
    $_POST["edit-mac"] = str_replace("-", ":", $_POST["edit-mac"]);
    $mac = trim(strtolower($_POST["edit-mac"]));
    if (!IsPhysicalAddress($mac)) {
        echo "host_edit():: {$mac}!! pattern failed\n";
        return;
    }
    $q = new mysql();
    $tpl = new templates();
    if (!$q->FIELD_EXISTS('dhcpd_fixed', "domain-name-servers-2", 'artica_backup')) {
        $sql = "ALTER TABLE `dhcpd_fixed` ADD `domain-name-servers-2` VARCHAR( 90 )";
        $q->QUERY_SQL($sql, "artica_backup");
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT mac FROM dhcpd_fixed WHERE `mac`='{$_POST["edit-mac"]}'", "artica_backup"));
    if (trim($ligne["mac"]) == null) {
        $_POST["new-mac"] = $mac;
        host_new();
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM dhcpd_fixed WHERE `ipaddr`='{$_POST["ipaddr"]}'", "artica_backup"));
    if (trim($ligne["mac"]) != null) {
        if ($ligne["mac"] != $_POST["edit-mac"]) {
            echo $tpl->javascript_parse_text("host_edit({$_POST["edit-mac"]}):: {ipaddr}:{$_POST["ipaddr"]} {already_exists}: [{$ligne["mac"]}]");
            return;
        }
    }
    $sql = "UPDATE dhcpd_fixed SET \n\t\thostname='{$_POST["hostname"]}',\n\t\tipaddr='{$_POST["ipaddr"]}' ,\n\t\t`routers`='{$_POST["routers"]}',\n\t\t`domain-name-servers`='{$_POST["domain-name-servers"]}',\n\t\t`domain-name-servers-2`='{$_POST["domain-name-servers2"]}',\n\t\t`domain`='{$_POST["domain"]}'\n\t\tWHERE mac='{$_POST["edit-mac"]}'";
    $q = new mysql();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $cp = new computers();
    $uid = $cp->ComputerIDFromMAC($_POST["edit-mac"]);
    if ($uid != null) {
        $cp = new computers($uid);
        $cp->ComputerIP = $_POST["ipaddr"];
        $cp->ComputerRealName = $_POST["hostname"];
        $cp->DnsZoneName = $_POST["domain"];
        $cp->ComputerMacAddress = $_POST["edit-mac"];
        $cp->Edit();
    }
    if (!isset($GLOBALS["APPLY_DHCP"])) {
        $GLOBALS["APPLY_DHCP"] = true;
        $sock = new sockets();
        $sock->getFrameWork("cmd.php?apply-dhcpd=yes");
    }
}
예제 #11
0
function parsefile($filename, $uid, $perc = 0)
{
    if ($perc == 0) {
        $perc = 10;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . "] Parsing file {$filename}\n";
    }
    $datas = file_get_contents($filename);
    $tbl = explode("\n", $datas);
    if (!is_array($tbl)) {
        return null;
    }
    $ComputerMacAddress = null;
    $ComputerRunning = null;
    $ComputerMachineType = null;
    $ComputerOS = null;
    $cpid = null;
    while (list($num, $ligne) = each($tbl)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (preg_match("#([0-9]+).+?open\\s+(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] PORT: {$re[1]} -> {$re[2]} ///////////////////\n";
            }
            $PORTS[$re[1]] = $re[2];
            continue;
        }
        if (preg_match("#^Running:(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] Running: {$re[1]}\n";
            }
            $ComputerRunning = $re[1];
            continue;
        }
        if (preg_match("#^OS details:(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] OS details: {$re[1]}\n";
            }
            $ComputerOS = $re[1];
            continue;
        }
        if (preg_match("#^MAC Address:(.+).+?\\((.+?)\\)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] MAC Address: {$re[1]}\n";
            }
            $ComputerMacAddress = trim(strtolower($re[1]));
            $ComputerMachineType = $re[2];
            continue;
        }
        if (preg_match("#([0-9]+).+?open\\s+(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] PORT: {$re[1]} -> {$re[2]} ///////////////////\n";
            }
            $PORTS[$re[1]] = $re[2];
            continue;
        }
        if (preg_match("#^MAC Address:(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] MAC Address: {$re[1]}\n";
            }
            $ComputerMacAddress = trim(strtolower($re[1]));
            continue;
        }
        if (preg_match("#^MAC Address:\\s+(.+?)\\s+#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] MAC Address: {$re[1]}\n";
            }
            $ComputerMacAddress = $re[1];
            continue;
        }
        if (preg_match("#^Aggressive OS guesses:\\s+(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __LINE__ . "] ******* Aggressive OS guesses: {$re[1]}\n";
            }
            $OSD = explode("-", $re[1]);
            while (list($num, $xline) = each($OSD)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo __LINE__ . "] {$xline}\n";
                }
                if (preg_match("#Apple iOS#", $xline)) {
                    $ComputerOS = "Apple Mac OS";
                    break;
                }
                if (preg_match("#Apple iPhone#", $xline)) {
                    $ComputerOS = "Apple iPhone";
                    break;
                }
                if (preg_match("#Apple Mac OS#", $xline)) {
                    $ComputerOS = "Apple Mac OS";
                    break;
                }
            }
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo __LINE__ . "] \"{$ligne}\" Not parsed...\n";
        }
    }
    if ($ComputerMacAddress != null) {
        $computer = new computers();
        $cpid = $computer->ComputerIDFromMAC($ComputerMacAddress);
        build_progress("Analyze {$ComputerMacAddress} ", $perc + 5);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo " xxxxxxxxxxxx  " . count($PORTS) . " ports xxxxxxxxxxxx\n";
    }
    if (count($PORTS) > 0) {
        AddPorts($PORTS, $ComputerMacAddress);
    }
    if ($cpid == null) {
        $cpid = $uid;
    }
    echo "Save infos for {$cpid} (" . __LINE__ . ")\n";
    echo "ComputerMacAddress: {$ComputerMacAddress} (" . __LINE__ . ")\n";
    echo "ComputerOS: {$ComputerOS} (" . __LINE__ . ")\n";
    build_progress("Adding {$cpid}\$ ", $perc + 5);
    $computer = new computers($cpid . "\$");
    if ($ComputerMacAddress != null) {
        $computer->ComputerMacAddress = $ComputerMacAddress;
    }
    if ($ComputerOS != null) {
        $computer->ComputerOS = $ComputerOS;
    }
    if ($ComputerRunning != null) {
        $computer->ComputerRunning = $ComputerRunning;
    }
    if ($ComputerMachineType != null) {
        $computer->ComputerMachineType = $ComputerMachineType;
    }
    if (is_array($array)) {
        $computer->ComputerOpenPorts = base64_encode(serialize($array));
    }
    echo "Update it has {$cpid} with MAC {$ComputerMacAddress} (" . __LINE__ . ")\n";
    if (!$computer->Edit(basename(__FILE__))) {
        echo "Failed to save infos for {$cpid} (" . __LINE__ . ")\n";
    }
    build_progress("Done...", $perc + 5);
    echo $datas;
}