"; print "

$message

"; print "
"; } break; case 'error': print ""; print ""; print "

Error: $message


"; break; } } } } session_unregister("sess_messages"); } function array_rekey($array, $key, $key_value) { if (sizeof($array) > 0) { foreach ($array as $item) { $item_key = $item[$key]; $ret_array[$item_key] = $item[$key_value]; } } return $ret_array; } function LogData($string) { global $config,$colors,$paths; /* fill in the current date for printing in the log */ $date = date("m/d/Y g:i A"); /* echo the data to the log (append) */ exec("echo '$date - $string' >> $paths[log]"); } function get_full_script_path($local_data_id) { global $paths; $data_source = db_fetch_row("select data_template_data.id, data_template_data.data_input_id, data_input.type_id, data_input.input_string from data_template_data,data_input where data_template_data.data_input_id=data_input.id and data_template_data.local_data_id=$local_data_id"); if ($data_source["type_id"] > 1) { return 0; } $data = db_fetch_assoc("select data_input_fields.data_name, data_input_data.value from data_input_fields left join data_input_data on data_input_fields.id=data_input_data.data_input_field_id where data_input_fields.data_input_id=" . $data_source["data_input_id"] . " and data_input_data.data_template_data_id=" . $data_source["id"] . " and data_input_fields.input_output='in'"); $full_path = $data_source["input_string"]; if (sizeof($data) > 0) { foreach ($data as $item) { $full_path = str_replace("<" . $item["data_name"] . ">", $item["value"], $full_path); } } $full_path = str_replace("", $paths["cacti"], $full_path); $full_path = str_replace("", read_config_option("path_snmpget"), $full_path); $full_path = str_replace("", read_config_option("path_php_binary"), $full_path); return $full_path; } function get_data_source_name($data_template_rrd_id) { if (empty($data_template_rrd_id)) { return ""; } $data_source = db_fetch_row("select data_template_rrd.data_source_name, data_template_data.name from data_template_rrd,data_template_data where data_template_rrd.local_data_id=data_template_data.local_data_id and data_template_rrd.id=$data_template_rrd_id"); /* use the cacti ds name by default or the user defined one, if entered */ if (empty($data_source["data_source_name"])) { /* limit input to 19 characters */ $data_source_name = clean_up_name($data_source["name"]); $data_source_name = substr(strtolower($data_source_name),0,(19-strlen($data_template_rrd_id))) . $data_template_rrd_id; return $data_source_name; }else{ return $data_source["data_source_name"]; } } function get_data_source_path($local_data_id, $expand_paths) { global $paths; if (empty($local_data_id)) { return ""; } $data_source = db_fetch_row("select name,data_source_path from data_template_data where local_data_id=$local_data_id"); if (sizeof($data_source) > 0) { if (empty($data_source["data_source_path"])) { /* no custom path was specified */ $data_source_path = generate_data_source_path($local_data_id); }else{ if (!strstr($data_source["data_source_path"], "/")) { $data_source_path = "/" . $data_source["data_source_path"]; }else{ $data_source_path = $data_source["data_source_path"]; } } /* whether to show the "actual" path or the variable name (for edit boxes) */ if ($expand_paths == true) { $data_source_path = str_replace("", $paths["rra"], $data_source_path); } return $data_source_path; } } function stri_replace($find, $replace, $string) { $parts = explode(strtolower($find), strtolower($string)); $pos = 0; foreach ($parts as $key=>$part) { $parts[$key] = substr($string, $pos, strlen($part)); $pos += strlen($part) + strlen($find); } return (join($replace, $parts)); } function clean_up_name($string) { $string = preg_replace("/[\s\.]+/", "_", $string); $string = preg_replace("/[*\/\*&%\"\',]/", "", $string); return $string; } function subsitute_host_data($string, $l_escape_string, $r_escape_string, $host_id) { $host = db_fetch_row("select description,hostname,management_ip,snmp_community,snmp_version,snmp_username,snmp_password from host where id=$host_id"); $string = str_replace($l_escape_string . "host_hostname" . $r_escape_string, $host["hostname"], $string); $string = str_replace($l_escape_string . "host_description" . $r_escape_string, $host["description"], $string); $string = str_replace($l_escape_string . "host_management_ip" . $r_escape_string, $host["management_ip"], $string); $string = str_replace($l_escape_string . "host_snmp_community" . $r_escape_string, $host["snmp_community"], $string); $string = str_replace($l_escape_string . "host_snmp_version" . $r_escape_string, $host["snmp_version"], $string); $string = str_replace($l_escape_string . "host_snmp_username" . $r_escape_string, $host["snmp_username"], $string); $string = str_replace($l_escape_string . "host_snmp_password" . $r_escape_string, $host["snmp_password"], $string); return $string; } function subsitute_snmp_query_data($string, $l_escape_string, $r_escape_string, $host_id, $snmp_query_id, $snmp_index) { $snmp_cache_data = db_fetch_assoc("select field_name,field_value from host_snmp_cache where host_id=$host_id and snmp_query_id=$snmp_query_id and snmp_index=$snmp_index"); if (sizeof($snmp_cache_data) > 0) { foreach ($snmp_cache_data as $data) { $string = stri_replace($l_escape_string . "squery_" . $data["field_name"] . $r_escape_string, $data["field_value"], $string); } } return $string; } function generate_data_source_path($local_data_id) { $data_source_name = db_fetch_cell("select name from data_template_data where local_data_id=$local_data_id"); $new_path = "/" . substr(strtolower(clean_up_name($data_source_name)), 0, 15) . "_" . $local_data_id . ".rrd"; db_execute("update data_template_data set data_source_path='$new_path' where local_data_id=$local_data_id"); return $new_path; } function generate_graph_def_name($graph_item_id) { $lookup_table = array("a","b","c","d","e","f","g","h","i","j"); $result = ""; for($i=0; $i 0) { return $data3[$field]; } $i++; } } return $start_seq; } function get_last_item($tblname, $field, $startid, $lmt_query) { $data1 = db_fetch_row("select min($field) mymin from $tblname where $lmt_query"); $end_seq = $data1["mymin"]; $data2 = db_fetch_row("select $field from $tblname where id=$startid"); $start_seq = $data2[$field]; $i = $start_seq; if ($end_seq != $start_seq) { while ($i > $end_seq) { $data3 = db_fetch_row("select $field from $tblname where $field=$i-1 and $lmt_query"); if (sizeof($data3) > 0 && $data3[$field] != 0) { return $data3[$field]; } $i--; } } return $start_seq; } function get_sequence($id, $field, $table_name, $group_query) { if (empty($id)) { $data = db_fetch_row("select max($field)+1 as seq from $table_name where $group_query"); if ($data["seq"] == "") { return 1; }else{ return $data["seq"]; } }else{ $data = db_fetch_row("select $field from $table_name where id=$id"); return $data[$field]; } } function move_item_down($table_name, $current_id, $group_query) { $next_item = get_next_item($table_name, "sequence", $current_id, $group_query); $id = db_fetch_cell("select id from $table_name where sequence=$next_item and $group_query"); $sequence = db_fetch_cell("select sequence from $table_name where id=$current_id"); db_execute("update $table_name set sequence=$next_item where id=$current_id"); db_execute("update $table_name set sequence=$sequence where id=$id"); } function move_item_up($table_name, $current_id, $group_query) { $last_item = get_last_item($table_name, "sequence", $current_id, $group_query); $id = db_fetch_cell("select id from $table_name where sequence=$last_item and $group_query"); $sequence = db_fetch_cell("select sequence from $table_name where id=$current_id"); db_execute("update $table_name set sequence=$last_item where id=$current_id"); db_execute("update $table_name set sequence=$sequence where id=$id"); } function exec_into_array($command_line) { exec($command_line,$out,$err); $command_array = array(); for($i=0; list($key, $value) = each($out); $i++) { $command_array[$i] = $value; } return $command_array; } function convert_mac_address($mac_address) { return strtolower(str_replace(" ", ":", $mac_address)); } function hex2bin($data) { $len = strlen($data); for($i=0;$i<$len;$i+=2) { $newdata .= pack("C",hexdec(substr($data,$i,2))); } return $newdata; } ?>