" . $hash_type_names{$parsed_hash["type"]} . ") "; }else{ $prepend = ""; } switch ($parsed_hash["type"]) { case 'graph_template': return $prepend . db_fetch_cell("select name from graph_templates where hash='" . $parsed_hash["hash"] . "'"); case 'data_template': return $prepend . db_fetch_cell("select name from data_template where hash='" . $parsed_hash["hash"] . "'"); case 'data_template_item': return $prepend . db_fetch_cell("select data_source_name from data_template_rrd where hash='" . $parsed_hash["hash"] . "'"); case 'host_template': return $prepend . db_fetch_cell("select name from host_template where hash='" . $parsed_hash["hash"] . "'"); case 'data_input_method': return $prepend . db_fetch_cell("select name from data_input where hash='" . $parsed_hash["hash"] . "'"); case 'data_input_field': return $prepend . db_fetch_cell("select name from data_input_fields where hash='" . $parsed_hash["hash"] . "'"); case 'data_query': return $prepend . db_fetch_cell("select name from snmp_query where hash='" . $parsed_hash["hash"] . "'"); case 'gprint_preset': return $prepend . db_fetch_cell("select name from graph_templates_gprint where hash='" . $parsed_hash["hash"] . "'"); case 'cdef': return $prepend . db_fetch_cell("select name from cdef where hash='" . $parsed_hash["hash"] . "'"); case 'round_robin_archive': return $prepend . db_fetch_cell("select name from rra where hash='" . $parsed_hash["hash"] . "'"); } } function resolve_hash_to_id($hash, &$hash_cache_array) { /* parse information from the hash */ $parsed_hash = parse_xml_hash($hash); /* invalid/wrong hash */ if ($parsed_hash == false) { return false; } if (isset($hash_cache_array{$parsed_hash["type"]}{$parsed_hash["hash"]})) { $_SESSION["import_debug_info"]["dep"][$hash] = "met"; return $hash_cache_array{$parsed_hash["type"]}{$parsed_hash["hash"]}; }else{ $_SESSION["import_debug_info"]["dep"][$hash] = "unmet"; return 0; } } function parse_xml_hash($hash) { if (ereg("hash_([a-f0-9]{2})([a-f0-9]{4})([a-f0-9]{32})", $hash, $matches)) { $parsed_hash["type"] = check_hash_type($matches[1]); $parsed_hash["version"] = strval(check_hash_version($matches[2])); $parsed_hash["hash"] = $matches[3]; /* an error has occured */ if (($parsed_hash["type"] == false) || ($parsed_hash["version"] == false)) { return false; } }else{ return false; } return $parsed_hash; } function check_hash_type($hash_type) { global $hash_type_codes; /* lets not mess up the pointer for other people */ $local_hash_type_codes = $hash_type_codes; reset($local_hash_type_codes); while (list($type, $code) = each($local_hash_type_codes)) { if ($code == $hash_type) { $current_type = $type; } } if (!isset($current_type)) { // error: cannot find type return false; } return $current_type; } function check_hash_version($hash_version) { global $hash_version_codes, $config; $i = 0; reset($hash_version_codes); while (list($version, $code) = each($hash_version_codes)) { if ($version == $config["cacti_version"]) { $current_version_index = $i; } if ($code == $hash_version) { $hash_version_index = $i; $current_version = $version; } $i++; } if (!isset($current_version_index)) { // error: current cacti version does not exist! return false; }elseif (!isset($hash_version_index)) { // error: hash version does not exist! return false; }elseif ($hash_version_index > $current_version_index) { // error: hash made with a newer version of cacti return false; } return $current_version; } ?>