function getHashID($hash)
{
    global $avarice_admin_connection;
    $query = "SELECT hash_ID FROM inv__hash WHERE hash = '" . $hash . "'";
    $result = dbquery_func($avarice_admin_connection, $query);
    if (mysql_num_rows($result) != 1) {
        dbquery_func($avarice_admin_connection, "INSERT INTO inv__hash SET hash = '" . $hash . "'");
        $result = dbquery_func($avarice_admin_connection, $query);
    }
    return mysql_result($result, 0, 0);
}
Exemple #2
0
<?php

header("Content-Type: text/plain");
include_once "../../include/config.php";
include_once "inv_functions.php";
include_once "inv_config.php";
if (!empty($form_data['action'])) {
    $query = array();
    if ($form_data['action'] == "templatecheck") {
        $given_hash_id = getHashID($form_data['hash']);
        $query['query'] = "\r\n                       SELECT hash_ID\r\n                            , template\r\n                         FROM inv__config_templates\r\n                        WHERE inv__config_templates.os = ?\r\n                          AND inv__config_templates.release = ?\r\n                          AND inv__config_templates.version = ?";
        $query['params'] = array("sss", $form_data['os'], $form_data['release'], $form_data['version']);
        $result = dbquery_func($avarice_user_connection, $query);
        if ($given_hash_id != $result[0]['hash_ID']) {
            print $result[0]['template'];
        }
    } else {
        if ($form_data['action'] == "submit_results") {
            $query['query'] = "\r\n                       INSERT INTO inv__dataprocessing\r\n                                   (createdDate, assetName, data)\r\n                            VALUES (?, ?, ?);";
            $query['params'] = array("ssb", substr($form_data['filename'], 0, 4) . "-" . substr($form_data['filename'], 4, 2) . "-" . substr($form_data['filename'], 6, 2), substr($form_data['filename'], 8, -4), $form_data['xml_result']);
            dbquery_func($avarice_admin_connection, $query);
        }
    }
}
function ldap_to_db_data($table_array, $avarice_admin_connection)
{
    $func_start_time = microtime_float();
    foreach ($table_array as $objectClass => $details) {
        if (empty($objectClass)) {
            continue;
        }
        $column_list_result = dbquery_func($avarice_admin_connection, "SHOW COLUMNS FROM " . $avarice_admin_connection['db_name'] . "." . charreplace($objectClass));
        $column_list = array();
        while ($row = mysql_fetch_assoc($column_list_result)) {
            if (isset($first_field_row_done)) {
                $column_list[] = $row['Field'];
            } else {
                $first_field_row_done = "true";
            }
        }
        $insert_query = "INSERT INTO " . $avarice_admin_connection['db_name'] . "." . charreplace($objectClass) . " (";
        foreach ($column_list as $column) {
            if (!isset($first_insert_column)) {
                $first_insert_column = "true";
            } else {
                $insert_query .= ", ";
            }
            $insert_query .= $column;
        }
        unset($first_insert_column);
        $insert_query .= ") VALUES ";
        foreach ($details['data'] as $key => $data) {
            if (!isset($first_line_data_done)) {
                $first_line_data_done = "true";
            } else {
                $insert_query .= ", ";
            }
            $insert_query .= "(";
            foreach ($column_list as $column) {
                if (isset($first_data_done)) {
                    $insert_query .= ", ";
                } else {
                    $first_data_done = 1;
                }
                if (isset($data[$column])) {
                    $insert_query .= "\"" . addslashes($data[$column]) . "\"";
                } else {
                    $insert_query .= "\"\"";
                }
            }
            $insert_query .= ")";
            unset($first_data_done);
            if (strlen($insert_query) > 500000) {
                unset($first_line_data_done);
                $insert_query .= " ON DUPLICATE KEY UPDATE ";
                foreach ($column_list as $column) {
                    if (!isset($first_insert_column)) {
                        $first_insert_column = "true";
                    } else {
                        $insert_query .= ", ";
                    }
                    $insert_query .= $column . "=VALUES(" . $column . ")";
                }
                unset($first_insert_column);
                dbquery_func($avarice_admin_connection, $insert_query, "on");
                $insert_query = "INSERT INTO " . $avarice_admin_connection['db_name'] . "." . charreplace($objectClass) . " (";
                foreach ($column_list as $column) {
                    if (!isset($first_insert_column)) {
                        $first_insert_column = "true";
                    } else {
                        $insert_query .= ", ";
                    }
                    $insert_query .= $column;
                }
                unset($first_insert_column);
                $insert_query .= ") VALUES ";
                unset($first_line_data_done);
            }
        }
        unset($first_line_data_done);
        $insert_query .= " ON DUPLICATE KEY UPDATE ";
        foreach ($column_list as $column) {
            if (!isset($first_insert_column)) {
                $first_insert_column = "true";
            } else {
                $insert_query .= ", ";
            }
            $insert_query .= $column . "=VALUES(" . $column . ")";
        }
        unset($first_insert_column);
        dbquery_func($avarice_admin_connection, $insert_query, "on");
    }
    $func_end_time = microtime_float();
    $func_time_taken = $func_end_time - $func_start_time;
    return $func_time_taken;
}
<?php

include_once "../../include/config.php";
include_once "inv_functions.php";
include_once "inv_config.php";
$query = "\r\n          SELECT template\r\n            FROM inv__config_templates";
$result = dbquery_func($avarice_user_connection, $query);
$tables_expected = array();
while ($row = mysql_fetch_assoc($result)) {
    $template_xml = simplexml_load_string($row['template']);
    $tables_expected['asset'] = array("type" => "single", "columns" => array());
    foreach ($template_xml->asset->property as $property) {
        $tables_expected['asset']['columns'][] = (string) $property['name'];
    }
    foreach ($template_xml->asset->category as $category) {
        $tables_expected[(string) $category['name']] = array("type" => (string) $category['type'], "columns" => array());
        if ((string) $category['type'] == "single") {
            foreach ($category->property as $property) {
                if (!isset($property['type']) or (string) $property['type'] == "individual") {
                    $tables_expected[(string) $category['name']]['columns'][] = (string) $property['name'];
                } else {
                    if ((string) $property['type'] == "general") {
                        if (!in_array((string) $category['name'] . "_general", array_keys($tables_expected))) {
                            $tables_expected[(string) $category['name'] . "_general"] = array("type" => "general", "columns" => array());
                        }
                        $tables_expected[(string) $category['name'] . "_general"]['columns'][] = (string) $property['name'];
                    }
                }
            }
        } else {
            if ((string) $category['type'] == "multiple") {