= get_version_index("0.8.5"))) { /* treat the 'color' field differently */ $color_id = db_fetch_cell("select id from colors where hex='" . $item_array[$field_name] . "'"); if (empty($color_id)) { db_execute("insert into colors (hex) values ('" . $item_array[$field_name] . "')"); $color_id = db_fetch_insert_id(); } $save[$field_name] = $color_id; }else{ $save[$field_name] = addslashes($item_array[$field_name]); } } } $graph_template_item_id = sql_save($save, "graph_templates_item"); $hash_cache["graph_template_item"]{$parsed_hash["hash"]} = $graph_template_item_id; } } /* import into: graph_template_input */ if (is_array($xml_array["inputs"])) { while (list($item_hash, $item_array) = each($xml_array["inputs"])) { /* parse information from the hash */ $parsed_hash = parse_xml_hash($item_hash); /* invalid/wrong hash */ if ($parsed_hash == false) { return false; } unset($save); $_graph_template_input_id = db_fetch_cell("select id from graph_template_input where hash='" . $parsed_hash["hash"] . "' and graph_template_id=$graph_template_id"); $save["id"] = (empty($_graph_template_input_id) ? "0" : $_graph_template_input_id); $save["hash"] = $parsed_hash["hash"]; $save["graph_template_id"] = $graph_template_id; reset($fields_graph_template_input_edit); while (list($field_name, $field_array) = each($fields_graph_template_input_edit)) { /* make sure this field exists in the xml array first */ if (isset($item_array[$field_name])) { $save[$field_name] = addslashes($item_array[$field_name]); } } $graph_template_input_id = sql_save($save, "graph_template_input"); $hash_cache["graph_template_input"]{$parsed_hash["hash"]} = $graph_template_input_id; /* import into: graph_template_input_defs */ $hash_items = explode("|", $item_array["items"]); if (!empty($hash_items[0])) { for ($i=0; $i "sequence", "type" => "type", "value" => "value" ); /* import into: cdef */ $_cdef_id = db_fetch_cell("select id from cdef where hash='$hash'"); $save["id"] = (empty($_cdef_id) ? "0" : $_cdef_id); $save["hash"] = $hash; reset($fields_cdef_edit); while (list($field_name, $field_array) = each($fields_cdef_edit)) { /* make sure this field exists in the xml array first */ if (isset($xml_array[$field_name])) { $save[$field_name] = addslashes($xml_array[$field_name]); } } $cdef_id = sql_save($save, "cdef"); $hash_cache["cdef"][$hash] = $cdef_id; /* import into: cdef_items */ if (is_array($xml_array["items"])) { while (list($item_hash, $item_array) = each($xml_array["items"])) { /* parse information from the hash */ $parsed_hash = parse_xml_hash($item_hash); /* invalid/wrong hash */ if ($parsed_hash == false) { return false; } unset($save); $_cdef_item_id = db_fetch_cell("select id from cdef_items where hash='" . $parsed_hash["hash"] . "' and cdef_id=$cdef_id"); $save["id"] = (empty($_cdef_item_id) ? "0" : $_cdef_item_id); $save["hash"] = $parsed_hash["hash"]; $save["cdef_id"] = $cdef_id; reset($fields_cdef_item_edit); while (list($field_name, $field_array) = each($fields_cdef_item_edit)) { /* make sure this field exists in the xml array first */ if (isset($item_array[$field_name])) { $save[$field_name] = addslashes($item_array[$field_name]); } } $cdef_item_id = sql_save($save, "cdef_items"); $hash_cache["cdef_item"]{$parsed_hash["hash"]} = $cdef_item_id; } } /* status information that will be presented to the user */ $_SESSION["import_debug_info"]["type"] = (empty($_cdef_id) ? "new" : "update"); $_SESSION["import_debug_info"]["title"] = $xml_array["name"]; $_SESSION["import_debug_info"]["result"] = (empty($cdef_id) ? "fail" : "success"); return $hash_cache; } function &xml_to_data_input_method($hash, &$xml_array, &$hash_cache) { global $fields_data_input_edit, $fields_data_input_field_edit, $fields_data_input_field_edit_1; /* aggregate field arrays */ $fields_data_input_field_edit += $fields_data_input_field_edit_1; /* import into: data_input */ $_data_input_id = db_fetch_cell("select id from data_input where hash='$hash'"); $save["id"] = (empty($_data_input_id) ? "0" : $_data_input_id); $save["hash"] = $hash; reset($fields_data_input_edit); while (list($field_name, $field_array) = each($fields_data_input_edit)) { /* make sure this field exists in the xml array first */ if (isset($xml_array[$field_name])) { $save[$field_name] = addslashes(xml_character_decode($xml_array[$field_name])); } } $data_input_id = sql_save($save, "data_input"); $hash_cache["data_input_method"][$hash] = $data_input_id; /* import into: data_input_fields */ if (is_array($xml_array["fields"])) { while (list($item_hash, $item_array) = each($xml_array["fields"])) { /* parse information from the hash */ $parsed_hash = parse_xml_hash($item_hash); /* invalid/wrong hash */ if ($parsed_hash == false) { return false; } unset($save); $_data_input_field_id = db_fetch_cell("select id from data_input_fields where hash='" . $parsed_hash["hash"] . "' and data_input_id=$data_input_id"); $save["id"] = (empty($_data_input_field_id) ? "0" : $_data_input_field_id); $save["hash"] = $parsed_hash["hash"]; $save["data_input_id"] = $data_input_id; reset($fields_data_input_field_edit); while (list($field_name, $field_array) = each($fields_data_input_field_edit)) { /* make sure this field exists in the xml array first */ if (isset($item_array[$field_name])) { $save[$field_name] = addslashes($item_array[$field_name]); } } $data_input_field_id = sql_save($save, "data_input_fields"); $hash_cache["data_input_field"]{$parsed_hash["hash"]} = $data_input_field_id; } } /* update field use counter cache if possible */ if ((isset($xml_array["input_string"])) && (!empty($data_input_id))) { generate_data_input_field_sequences($xml_array["input_string"], $data_input_id, "in"); } /* status information that will be presented to the user */ $_SESSION["import_debug_info"]["type"] = (empty($_data_input_id) ? "new" : "update"); $_SESSION["import_debug_info"]["title"] = $xml_array["name"]; $_SESSION["import_debug_info"]["result"] = (empty($data_input_id) ? "fail" : "success"); return $hash_cache; } function hash_to_friendly_name($hash, $display_type_name) { global $hash_type_names; /* parse information from the hash */ $parsed_hash = parse_xml_hash($hash); /* invalid/wrong hash */ if ($parsed_hash == false) { return false; } if ($display_type_name == true) { $prepend = "(" . $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)) { raise_message(18); /* 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)) { raise_message(15); /* error: current cacti version does not exist! */ return false; }elseif (!isset($hash_version_index)) { raise_message(16); /* error: hash version does not exist! */ return false; }elseif ($hash_version_index > $current_version_index) { raise_message(17); /* error: hash made with a newer version of cacti */ return false; } return $current_version; } function get_version_index($string_version) { global $hash_version_codes; $i = 0; reset($hash_version_codes); while (list($version, $code) = each($hash_version_codes)) { if ($string_version == $version) { return $i; } $i++; } return -1; } function xml_character_decode($text) { $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); return strtr($text, $trans_tbl); } ?>