예제 #1
0
function Save()
{
    $q = new mysql_meta();
    if (!$q->FIELD_EXISTS("metahosts", "cloneFrom")) {
        $q->QUERY_SQL("ALTER TABLE `metahosts` ADD `cloneFrom` VARCHAR(90),ADD INDEX ( `cloneFrom` )");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
            return;
        }
    }
    $q->QUERY_SQL("UPDATE metahosts SET cloneFrom='{$_POST["cloneFrom"]}' WHERE uuid='{$_POST["uuid"]}'");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("artica.php?meta-metaclient-clonesource=yes&uuid={$_POST["uuid"]}");
}
function __network_hosts($uuid, $filepath)
{
    $ARRAY = unserialize(@file_get_contents($filepath));
    $f = array();
    $prefix = "INSERT IGNORE INTO networks_hosts (MAC,IPADDR,IPINT,uuid,hostname,username,OSNAME) VALUES ";
    if (count($ARRAY) == 0) {
        @unlink($filepath);
        return;
    }
    while (list($MAC, $subarray) = each($ARRAY)) {
        while (list($a, $b) = each($subarray)) {
            $subarray[$a] = mysql_escape_string2($b);
        }
        $f[] = "('{$MAC}','{$subarray["IPADDR"]}','{$subarray["IPINT"]}','{$uuid}','{$subarray["hostname"]}',\n\t\t'{$subarray["username"]}','{$subarray["OSNAME"]}')";
    }
    if (count($f) == 0) {
        @unlink($filepath);
        return;
    }
    $q = new mysql_meta();
    $q->CheckTables();
    if (!$q->FIELD_EXISTS("networks_hosts", "OSNAME")) {
        $q->QUERY_SQL("ALTER TABLE `networks_hosts` ADD `OSNAME` varchar(255)");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
    $q->QUERY_SQL($prefix . @implode(",", $f));
    if ($q->ok) {
        @unlink($filepath);
        return;
    }
}