function form_input_validate($field_value, $field_name, $regexp_match, $allow_empty, $custom_message = 0) { if (($allow_empty == true) && ($field_value == "")) { if ($custom_message == 3) { return $field_value; }else{ return true; } } /* php 4.2+ complains about empty regexps */ if (empty($regexp_match)) { $regexp_match = ".*"; } if ((!ereg($regexp_match, $field_value) || (($allow_empty == false) && ($field_value == "")))) { if ($custom_message == 3) { return $field_value; }else{ log_save("Field validation error occured for field '$field_name' value '$field_value' pattern '$regexp_match' allow empty '" . ($allow_empty == false ? "no" : "yes") . "' in ". __FUNCTION__ . "()", SEV_NOTICE); return false; } }else{ if ($custom_message == 3) { return $field_value; }else{ return true; } } }
function api_poller_get($poller_id) { /* sanity check for $poller_id */ if ((!is_numeric($poller_id)) || (empty($poller_id))) { log_save("Invalid input '$poller_id' for 'poller_id' in " . __FUNCTION__ . "()", SEV_ERROR); return false; } return db_fetch_row("select * from poller where poller_id = " . sql_sanitize($poller_id)); }
function db_order_direction_validate($direction, $log_errors = true) { if (($direction == "asc") || ($direction == "desc")) { return true; }else{ if ($log_errors == true) { log_save("Invalid order direction '$direction' in " . log_get_last_function() . "()", SEV_WARNING); } return false; } }
/** * 日志保存 * @static * @access public * @param integer $type 日志记录方式 * @param string $destination 写入目标 * @param string $extra 额外参数 * @return void */ static function save($type = '', $destination = '', $extra = '') { if (empty(self::$log)) { return; } //[cluster] 保存日志 $now = date(self::$format); log_save(self::$log, $now . ' ' . get_client_ip() . ' ' . $_SERVER['REQUEST_URI']); // 保存后清空日志缓存 self::$log = array(); //clearstatcache(); }
function api_graph_template_get($graph_template_id) { /* sanity checks */ validate_id_die($graph_template_id, "graph_template_id"); $graph_template = db_fetch_row("select * from graph_template where id = " . sql_sanitize($graph_template_id)); if (sizeof($graph_template) == 0) { log_save("Invalid graph template [ID#$graph_template_id] specified in api_graph_template_get()", SEV_ERROR); return false; }else{ return $graph_template; } }
/** * Retreive an event and all associated parameters * * Given an event id, return all name => value pairs containing all the data for an event * * @param int $event_id Event ID * @return array event parameters */ function event_get ($event_id) { /* sanity check for $event_id */ if ((!is_numeric($event_id)) || (empty($event_id))) { log_save("Invalid input '$event_id' for 'event_id' in " . __FUNCTION__ . "()", SEV_ERROR); return false; } $event = db_fetch_row("select * from event_queue_control where id = " . sql_sanitize($event_id)); $params = db_fetch_assoc("select * from event_queue_param where control_id = " . sql_sanitize($event_id)); foreach($params as $param) { $event[$param['name']] = $param['value']; } return $event; }
function change_password() { global $colors; $change_result = 1; $user_realms = api_user_realms_list($_SESSION["sess_user_id"]); /* check if authorized */ if ($user_realms["18"]["value"] == "1") { /* check passwords */ if ((!empty($_POST["password_old"])) && (!empty($_POST["password_new"])) && (!empty($_POST["password_new_confirm"]))) { if ($_POST["password_new"] != $_POST["password_new_confirm"]) { /* New passwords do not match */ raise_message(4); }else{ $change_result = api_user_changepassword($_SESSION["sess_user_id"],$_POST["password_new"],$_POST["password_old"]); if ($change_result == "0") { /* Password changed successfully */ raise_message(11); /* Log password change */ $username = db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]); log_save(_("CHANGEPASSWORD: Password change successful"), SEV_INFO, FACIL_AUTH); }elseif ($change_result == "2") { /* Authentication failure for old password */ raise_message(8); log_save(_("CHANGEPASSWORD: Authenication failure on old password"), SEV_WARNING, FACIL_AUTH); }else{ /* General error changing password */ raise_message(9); log_save(_("CHANGEPASSWORD: General Error unable to change password"), SEV_ERROR, FACIL_AUTH); } } }else{ /* error empty fields */ raise_message(10); } } require_once(CACTI_BASE_PATH . "/include/top_header.php"); if ($user_realms["18"]["value"] != "1") { /* Access Denied */ display_custom_error_message("Access Denied."); } require_once(CACTI_BASE_PATH . "/include/bottom_footer.php"); }
function api_package_metadata_save($package_metadata_id, &$_fields_package_metadata) { require_once(CACTI_BASE_PATH . "/lib/package/package_info.php"); /* sanity checks */ validate_id_die($package_metadata_id, "package_metadata_id", true); /* sanity check for $package_id */ if ((empty($package_metadata_id)) && (empty($_fields_package_metadata["package_id"]))) { log_save("Required package_id when package_metadata_id = 0", SEV_ERROR); return false; } else if ((isset($_fields_package_metadata["package_id"])) && (!is_numeric($_fields_package_metadata["package_id"]))) { return false; } /* field: id */ $_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $package_metadata_id); /* field: package_id */ if (!empty($_fields_package_metadata["package_id"])) { $_fields["package_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_package_metadata["package_id"]); } /* convert the input array into something that is compatible with db_replace() */ $_fields += sql_get_database_field_array($_fields_package_metadata, api_package_metadata_form_list()); /* check for an empty field list */ if (sizeof($_fields) == 1) { return true; } if (db_replace("package_metadata", $_fields, array("id"))) { if (empty($package_metadata_id)) { return db_fetch_insert_id(); }else{ return $package_metadata_id; } }else{ return false; } }
function api_script_field_save($script_field_id, $_fields_script_field) { require_once(CACTI_BASE_PATH . "/lib/script/script_info.php"); /* sanity checks */ validate_id_die($script_field_id, "script_field_id", true); /* make sure that there is at least one field to save */ if (sizeof($_fields_script_field) == 0) { return false; } /* sanity check for $script_id */ if ((empty($script_field_id)) && (empty($_fields_script_field["data_input_id"]))) { log_save("Required script_id when script_field_id = 0", SEV_ERROR); return false; } else if ((isset($_fields_script_field["data_input_id"])) && (!db_integer_validate($_fields_script_field["data_input_id"]))) { return false; } /* field: id */ $_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $script_field_id); /* field: graph_tree_id */ if (isset($_fields_script_field["data_input_id"])) { $_fields["data_input_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_script_field["data_input_id"]); } /* convert the input array into something that is compatible with db_replace() */ $_fields += sql_get_database_field_array($_fields_script_field, api_script_field_form_list()); if (db_replace("data_input_fields", $_fields, array("id"))) { if (empty($script_field_id)) { $script_field_id = db_fetch_insert_id(); } return $script_field_id; }else{ return false; } }
function form_save() { if ($_POST["action_post"] == "graph_edit") { /* fetch some cache variables */ if (empty($_POST["id"])) { $_graph_template_id = 0; } else { $_graph_template_id = db_fetch_cell("select graph_template_id from graph where id=" . $_POST["id"]); } /* cache all post field values */ init_post_field_cache(); $form_graph_fields = array(); $form_graph_item_fields = array(); /* parse out form values that we care about */ reset($_POST); while (list($name, $value) = each($_POST)) { if (substr($name, 0, 2) == "g|") { $matches = explode("|", $name); $form_graph_fields[$matches[1]] = $value; } else { if (substr($name, 0, 4) == "gip|") { $matches = explode("|", $name); $form_graph_item_fields[$matches[2]] = $value; } } } /* make a list of fields to save */ while (list($_field_name, $_field_value) = each($form_graph_fields)) { /* make sure that we know about this field */ if (isset($fields_graph[$_field_name])) { $save_graph[$_field_name] = $_field_value; } } /* add any unchecked checkbox fields */ $form_graph_fields += field_register_html_checkboxes(api_graph_form_list(), "g||field|"); $form_graph_fields["host_id"] = $_POST["host_id"]; $form_graph_fields["graph_template_id"] = $_POST["graph_template_id"]; /* step #2: field validation */ $suggested_value_fields = array(); /* placeholder */ field_register_error(api_graph_fields_validate($form_graph_fields, $suggested_value_fields, "g||field|", "")); /* step #3: field save */ if (is_error_message()) { log_save("User input validation error for graph [ID#" . $_POST["id"] . "]", SEV_DEBUG); } else { /* save graph data */ if (!api_graph_save($_POST["id"], $form_graph_fields)) { log_save("Save error for graph [ID#" . $_POST["id"] . "]", SEV_ERROR); } /* save graph item data for templated graphs */ if (!empty($_graph_template_id)) { if (sizeof($form_graph_item_fields) > 0) { foreach ($form_graph_item_fields as $graph_template_item_input_id => $value) { if (!api_graph_template_item_input_propagate($graph_template_item_input_id, $value)) { log_save("Save error when propagating graph item input [ID#{$graph_template_item_input_id}] to graph [ID#" . $_POST["id"] . "]", SEV_ERROR); } } } } } if (is_error_message() || $_POST["graph_template_id"] != $_graph_template_id) { header("Location: graphs.php?action=edit&id=" . $_POST["id"] . (!isset($_POST["host_id"]) ? "" : "&host_id=" . $_POST["host_id"]) . (!isset($_POST["graph_template_id"]) ? "" : "&graph_template_id=" . $_POST["graph_template_id"])); } else { header("Location: graphs.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "search") { $get_string = ""; if ($_POST["box-1-search_device"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_device=" . urlencode($_POST["box-1-search_device"]); } if (trim($_POST["box-1-search_filter"]) != "") { $get_string .= ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } header("Location: graphs.php{$get_string}"); } else { if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $graph_id) { api_graph_remove($graph_id); } } else { if ($_POST["box-1-action-area-type"] == "duplicate") { // not yet coded } else { if ($_POST["box-1-action-area-type"] == "change_graph_template") { // note yet coded } else { if ($_POST["box-1-action-area-type"] == "change_host") { foreach ($selected_rows as $graph_id) { api_graph_host_update($graph_id, $_POST["box-1-change_device"]); } } else { if ($_POST["box-1-action-area-type"] == "convert_graph_template") { // note yet coded } else { if ($_POST["box-1-action-area-type"] == "place_tree") { // note yet coded } } } } } } } header("Location: graphs.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "graph_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: graphs.php{$get_string}"); } } } }
function sql_get_quoted_string($field_type, $field_value) { if ($field_type == DB_TYPE_STRING) { return "'" . sql_sanitize($field_value) . "'"; }else if ($field_type == DB_TYPE_INTEGER){ if (is_numeric($field_value)) { return $field_value; }else{ log_message("Invalid numeric column value '" . $field_value . "' in " . __FUNCTION__ . "()", LOG_LEVEL_WARNING, "lib-db"); die("Invalid numeric column value '" . $field_value . "' in " . __FUNCTION__ . "()"); } }else if ($field_type == DB_TYPE_INTEGER) { if (db_integer_validate($field_value, true, true)) { return $field_value; }else{ log_message("Invalid numeric column value '" . $field_value . "' in " . __FUNCTION__ . "()", LOG_LEVEL_WARNING, "lib-db"); die("Invalid numeric column value '" . $field_value . "' in " . __FUNCTION__ . "()"); } }else if ($field_type == DB_TYPE_NULL) { return "NULL"; }else if ($field_type == DB_TYPE_BLOB) { // i think the addslashes() may cause problems for non-mysql dbs, but it wasn't working for me otherwise return "'" . addslashes($field_value) . "'"; }else if ($field_type == DB_TYPE_HTML_CHECKBOX) { if ($field_value == "on") { return 1; }else if ($field_value == "") { return 0; }else if ($field_value == "0") { return 0; }else if ($field_value == "1") { return 1; }else{ return 0; } }else if ($field_type == DB_TYPE_FUNC_NOW) { return "NOW()"; }else if ($field_type == DB_TYPE_FUNC_MD5) { return "'" . md5($field_value) . "'"; }else{ log_save("Invalid column type '" . $field_type . "' value '" . $field_value . "' in " . __FUNCTION__ . "()", SEV_WARNING); } }
function update_host_status($poller_id, $status, $host_id, &$hosts, &$ping, $ping_availability, $print_data_to_stdout) { $issue_log_message = false; $ping_failure_count = read_config_option("ping_failure_count"); $ping_recovery_count = read_config_option("ping_recovery_count"); if ($status == HOST_DOWN) { /* update total polls, failed polls and availability */ $hosts[$host_id]["failed_polls"]++; $hosts[$host_id]["total_polls"]++; $hosts[$host_id]["availability"] = 100 * ($hosts[$host_id]["total_polls"] - $hosts[$host_id]["failed_polls"]) / $hosts[$host_id]["total_polls"]; /* determine the error message to display */ if ($ping_availability == AVAIL_SNMP_AND_PING) { if ($hosts[$host_id]["snmp_community"] == "") { $hosts[$host_id]["status_last_error"] = $ping->ping_response; }else { $hosts[$host_id]["status_last_error"] = $ping->snmp_response . ", " . $ping->ping_response; } }elseif ($ping_availability == AVAIL_SNMP) { if ($hosts[$host_id]["snmp_community"] == "") { $hosts[$host_id]["status_last_error"] = _("Device does not require SNMP"); }else { $hosts[$host_id]["status_last_error"] = $ping->snmp_response; } }elseif ($ping_availability == AVAIL_NONE) { $hosts[$host_id]["status_last_error"] = _("Availability disabled for host"); }else { $hosts[$host_id]["status_last_error"] = $ping->ping_response; } /* determine if to send an alert and update remainder of statistics */ if ($hosts[$host_id]["status"] == HOST_UP) { /* increment the event failure count */ $hosts[$host_id]["status_event_count"]++; /* if it's time to issue an error message, indicate so */ if ($hosts[$host_id]["status_event_count"] >= $ping_failure_count) { /* host is now down, flag it that way */ $hosts[$host_id]["status"] = HOST_DOWN; $issue_log_message = true; /* update the failure date only if the failure count is 1 */ if ($ping_failure_count == 1) { $hosts[$host_id]["status_fail_date"] = date("Y-m-d h:i:s"); } /* host is down, but not ready to issue log message */ } else { /* host down for the first time, set event date */ if ($hosts[$host_id]["status_event_count"] == 1) { $hosts[$host_id]["status_fail_date"] = date("Y-m-d h:i:s"); } } /* host is recovering, put back in failed state */ } elseif ($hosts[$host_id]["status"] == HOST_RECOVERING) { $hosts[$host_id]["status_event_count"] = 1; $hosts[$host_id]["status"] = HOST_DOWN; /* host was unknown and now is down */ } elseif ($hosts[$host_id]["status"] == HOST_UNKNOWN) { $hosts[$host_id]["status"] = HOST_DOWN; $hosts[$host_id]["status_event_count"] = 0; } else { $hosts[$host_id]["status_event_count"]++; } /* host is up!! */ } else { /* update total polls and availability */ $hosts[$host_id]["total_polls"]++; $hosts[$host_id]["availability"] = 100 * ($hosts[$host_id]["total_polls"] - $hosts[$host_id]["failed_polls"]) / $hosts[$host_id]["total_polls"]; /* determine the ping statistic to set and do so */ if ($ping_availability == AVAIL_SNMP_AND_PING) { if ($hosts[$host_id]["snmp_community"] == "") { $ping_time = $ping->ping_status; }else { /* calculate the average of the two times */ $ping_time = ($ping->snmp_status + $ping->ping_status) / 2; } }elseif ($ping_availability == AVAIL_SNMP) { if ($hosts[$host_id]["snmp_community"] == "") { $ping_time = 0.000; }else { $ping_time = $ping->snmp_status; } }elseif ($ping_availability == AVAIL_NONE) { $ping_time = 0.000; }else { $ping_time = $ping->ping_status; } /* update times as required */ $hosts[$host_id]["cur_time"] = $ping_time; /* maximum time */ if ($ping_time > $hosts[$host_id]["max_time"]) $hosts[$host_id]["max_time"] = $ping_time; /* minimum time */ if ($ping_time < $hosts[$host_id]["min_time"]) $hosts[$host_id]["min_time"] = $ping_time; /* average time */ $hosts[$host_id]["avg_time"] = (($hosts[$host_id]["total_polls"]-1-$hosts[$host_id]["failed_polls"]) * $hosts[$host_id]["avg_time"] + $ping_time) / ($hosts[$host_id]["total_polls"]-$hosts[$host_id]["failed_polls"]); /* the host was down, now it's recovering */ if (($hosts[$host_id]["status"] == HOST_DOWN) || ($hosts[$host_id]["status"] == HOST_RECOVERING )) { /* just up, change to recovering */ if ($hosts[$host_id]["status"] == HOST_DOWN) { $hosts[$host_id]["status"] = HOST_RECOVERING; $hosts[$host_id]["status_event_count"] = 1; } else { $hosts[$host_id]["status_event_count"]++; } /* if it's time to issue a recovery message, indicate so */ if ($hosts[$host_id]["status_event_count"] >= $ping_recovery_count) { /* host is up, flag it that way */ $hosts[$host_id]["status"] = HOST_UP; $issue_log_message = true; /* update the recovery date only if the recovery count is 1 */ if ($ping_recovery_count == 1) { $hosts[$host_id]["status_rec_date"] = date("Y-m-d h:i:s"); } /* reset the event counter */ $hosts[$host_id]["status_event_count"] = 0; /* host is recovering, but not ready to issue log message */ } else { /* host recovering for the first time, set event date */ if ($hosts[$host_id]["status_event_count"] == 1) { $hosts[$host_id]["status_rec_date"] = date("Y-m-d h:i:s"); } } } else { /* host was unknown and now is up */ $hosts[$host_id]["status"] = HOST_UP; $hosts[$host_id]["status_event_count"] = 0; } } /* if the user wants a flood of information then flood them */ if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) { if (($hosts[$host_id]["status"] == HOST_UP) || ($hosts[$host_id]["status"] == HOST_RECOVERING)) { /* log ping result if we are to use a ping for reachability testing */ if ($ping_availability == AVAIL_SNMP_AND_PING) { log_save(_("PING: ") . $ping->ping_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); log_save(_("SNMP: ") . $ping->snmp_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } elseif ($ping_availability == AVAIL_SNMP) { if ($hosts[$host_id]["snmp_community"] == "") { log_save(_("SNMP: Device does not require SNMP"), SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); }else{ log_save(_("SNMP: ") . $ping->snmp_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } } elseif ($ping_availability == AVAIL_NONE) { log_save(_("AVAIL: Availability checking disabled for host"), SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } else { log_save(_("PING: ") . $ping->ping_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } } else { if ($ping_availability == AVAIL_SNMP_AND_PING) { log_save(_("PING: ") . $ping->ping_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); log_save(_("SNMP: ") . $ping->snmp_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } elseif ($ping_availability == AVAIL_SNMP) { log_save(_("SNMP: ") . $ping->snmp_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } elseif ($ping_availability == AVAIL_NONE) { log_save(_("AVAIL: Availability cheking disabled for host"), SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } else { log_save(_("PING: ") . $ping->ping_response, SEV_INFO, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } } } /* if there is supposed to be an event generated, do it */ if ($issue_log_message) { if ($hosts[$host_id]["status"] == HOST_DOWN) { log_save(_("DEVICE EVENT: Device is DOWN Message: ") . $hosts[$host_id]["status_last_error"], SEV_ERROR, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } else { log_save(_("DEVICE EVENT: Device Returned from DOWN State"), SEV_NOTICE, FACIL_POLLER, "", $poller_id, $host_id, $print_data_to_stdout); } } db_execute("update host set status = '" . $hosts[$host_id]["status"] . "', status_event_count = '" . $hosts[$host_id]["status_event_count"] . "', status_fail_date = '" . $hosts[$host_id]["status_fail_date"] . "', status_rec_date = '" . $hosts[$host_id]["status_rec_date"] . "', status_last_error = '" . $hosts[$host_id]["status_last_error"] . "', min_time = '" . $hosts[$host_id]["min_time"] . "', max_time = '" . $hosts[$host_id]["max_time"] . "', cur_time = '" . $hosts[$host_id]["cur_time"] . "', avg_time = '" . $hosts[$host_id]["avg_time"] . "', total_polls = '" . $hosts[$host_id]["total_polls"] . "', failed_polls = '" . $hosts[$host_id]["failed_polls"] . "', availability = '" . $hosts[$host_id]["availability"] . "' where hostname = '" . $hosts[$host_id]["hostname"] . "'"); }
function api_graph_template_item_save($graph_template_item_id, $_fields_graph_item) { require_once(CACTI_BASE_PATH . "/lib/sys/sequence.php"); require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); /* sanity checks */ validate_id_die($graph_template_item_id, "graph_template_item_id", true); /* make sure that there is at least one field to save */ if (sizeof($_fields_graph_item) == 0) { return false; } /* sanity check for $graph_template_id */ if ((empty($graph_template_item_id)) && (empty($_fields_graph_item["graph_template_id"]))) { log_save("Required graph_template_id when graph_template_item_id = 0", SEV_ERROR); return false; } else if ((isset($_fields_graph_item["graph_template_id"])) && (!db_integer_validate($_fields_graph_item["graph_template_id"]))) { return false; } /* field: id */ $_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_template_item_id); /* field: graph_template_id */ if (!empty($_fields_graph_item["graph_template_id"])) { $_fields["graph_template_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_item["graph_template_id"]); } /* field: sequence */ if (empty($graph_template_item_id)) { $_fields["sequence"] = array("type" => DB_TYPE_INTEGER, "value" => seq_get_current($graph_template_item_id, "sequence", "graph_template_item", "graph_template_id = " . sql_sanitize($_fields_graph_item["graph_template_id"]))); } /* convert the input array into something that is compatible with db_replace() */ $_fields += sql_get_database_field_array($_fields_graph_item, api_graph_template_item_form_list()); if (db_replace("graph_template_item", $_fields, array("id"))) { if (empty($graph_template_item_id)) { $graph_template_item_id = db_fetch_insert_id(); } return $graph_template_item_id; }else{ return false; } }
function api_data_template_item_get($data_template_item_id) { /* sanity check for $data_template_item_id */ if ((!is_numeric($data_template_item_id)) || (empty($data_template_item_id))) { return false; } $data_template_item = db_fetch_row("select * from data_template_item where id = " . sql_sanitize($data_template_item_id)); if (sizeof($data_template_item) == 0) { log_save("Invalid data template item [ID#$data_template_item_id] specified in api_data_template_item_get()", SEV_ERROR); return false; }else{ return $data_template_item; } }
function api_graph_tree_item_save($graph_tree_item_id, &$_fields_graph_tree_item) { require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php"); require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php"); require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php"); /* sanity checks */ validate_id_die($graph_tree_item_id, "graph_tree_item_id", true); /* sanity check for $graph_tree_id */ if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["graph_tree_id"]))) { log_save("Required graph_tree_id when graph_tree_item_id = 0", SEV_ERROR); return false; }else if ((isset($_fields_graph_tree_item["graph_tree_id"])) && (!db_integer_validate($_fields_graph_tree_item["graph_tree_id"]))) { return false; } /* sanity check for $item_type */ if ((!isset($_fields_graph_tree_item["item_type"])) || (!db_integer_validate($_fields_graph_tree_item["item_type"]))) { log_save("Missing required item_type", SEV_ERROR); return false; } /* sanity check for $item_value */ if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["item_value"]))) { log_save("Required item_value when graph_tree_item_id = 0", SEV_ERROR); return false; }else if ((isset($_fields_graph_tree_item["item_value"])) && ( (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) || ($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HOST)) && (!db_integer_validate($_fields_graph_tree_item["item_value"])) )) { return false; } /* sanity check for $parent_item_id */ if ((!isset($_fields_graph_tree_item["parent_item_id"])) || (!db_integer_validate($_fields_graph_tree_item["parent_item_id"], true))) { log_save("Missing required parent_item_id", SEV_ERROR); return false; } /* field: id */ $_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item_id); /* field: graph_tree_id */ if (isset($_fields_graph_tree_item["graph_tree_id"])) { $_fields["graph_tree_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["graph_tree_id"]); } /* get a copy of the parent tree item id */ if ($_fields_graph_tree_item["parent_item_id"] == "0") { $parent_order_key = ""; $parent_sort_type = TREE_ORDERING_NONE; }else{ $parent_graph_tree_item = api_graph_tree_item_get($_fields_graph_tree_item["parent_item_id"]); $parent_order_key = $parent_graph_tree_item["order_key"]; $parent_sort_type = $parent_graph_tree_item["sort_children_type"]; } /* generate a new order key if this is a new graph tree item */ if (empty($graph_tree_item_id)) { $_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => api_graph_tree_item_available_order_key_get($_fields_graph_tree_item["graph_tree_id"], $parent_order_key)); }else{ $graph_tree_item = api_graph_tree_item_get($graph_tree_item_id); $_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => $graph_tree_item["order_key"]); } /* if this item is a graph, make sure it is not being added to the same branch twice */ $search_key = substr($parent_order_key, 0, (api_graph_tree_item_depth_get($parent_order_key) * CHARS_PER_TIER)); if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where item_value = " . $_fields_graph_tree_item["item_value"] . " and item_type = " . TREE_ITEM_TYPE_GRAPH . " and graph_tree_id = " . $_fields_graph_tree_item["graph_tree_id"] . " and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) { return true; } /* convert the input array into something that is compatible with db_replace() */ $_fields += sql_get_database_field_array($_fields_graph_tree_item, api_graph_tree_item_form_list()); /* check for an empty field list */ if (sizeof($_fields) == 1) { return true; } if (db_replace("graph_tree_items", $_fields, array("id"))) { if (empty($graph_tree_item_id)) { $graph_tree_item_id = db_fetch_insert_id(); } /* re-parent the branch if the parent item has changed */ if ($_fields_graph_tree_item["parent_item_id"] != api_graph_tree_item_parent_get_bykey($_fields["order_key"]["value"], $_fields_graph_tree_item["graph_tree_id"])) { api_graph_tree_item_reparent($graph_tree_item_id, $_fields_graph_tree_item["parent_item_id"]); } $parent_tree = api_graph_tree_get($_fields_graph_tree_item["graph_tree_id"]); /* tree item ordering */ if ($parent_tree["sort_type"] == TREE_ORDERING_NONE) { /* resort our parent */ if ($parent_sort_type != TREE_ORDERING_NONE) { echo $parent_sort_type; api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_sort_type); } /* if this is a header, sort direct children */ if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && ($parent_sort_type != TREE_ORDERING_NONE)) { api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item_id, $parent_sort_type); } /* tree ordering */ }else{ /* potential speed savings for large trees */ if (api_graph_tree_item_depth_get($_fields["order_key"]["value"]) == 1) { api_graph_tree_item_sort(SORT_TYPE_TREE, $_fields_graph_tree_item["graph_tree_id"], $parent_tree["sort_type"]); }else{ api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_tree["sort_type"]); } } /* if the user checked the 'Propagate Changes' box */ if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && (isset($_fields_graph_tree_item["sort_children_type"])) && (!empty($_fields_graph_tree_item["propagate_changes"]))) { $graph_tree_items = api_graph_tree_item_list($_fields_graph_tree_item["graph_tree_id"], array("item_type" => TREE_ITEM_TYPE_HEADER), $graph_tree_item_id, false, false); if (is_array($graph_tree_items) > 0) { foreach ($graph_tree_items as $graph_tree_item) { db_update("graph_tree_items", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item["id"]), "sort_children_type" => array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["sort_children_type"]) ), array("id")); if ($_fields_graph_tree_item["sort_children_type"] != TREE_ORDERING_NONE) { api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item["id"], $_fields_graph_tree_item["sort_children_type"]); } } } } return $graph_tree_item_id; }else{ return false; } }
/** * Truncates the cacti system log * * Truncates the cacti system log and logs that it occured * * @return bool true */ function log_clear () { db_execute("TRUNCATE TABLE log"); db_execute("REPLACE INTO settings (name,value) VALUES('log_status','active')"); log_save("Log truncated", SEV_NOTICE, FACIL_WEBUI); return true; }
function form_post() { if ($_POST["action_post"] == "device_edit") { /* the "Add" assigned package button was pressed */ if (isset($_POST["assoc_package_add_y"])) { api_device_package_add($_POST["id"], $_POST["assoc_package_id"]); header("Location: devices.php?action=edit&id=" . $_POST["id"]); exit; } /* cache all post field values */ init_post_field_cache(); /* field validation */ $form_device["id"] = $_POST["id"]; $form_device["description"] = $_POST["description"]; $form_device["hostname"] = $_POST["hostname"]; $form_device["host_template_id"] = $_POST["host_template_id"]; $form_device["poller_id"] = $_POST["poller_id"]; $form_device["disabled"] = html_boolean(isset($_POST["disabled"]) ? $_POST["disabled"] : ""); $form_device["snmp_version"] = $_POST["snmp_version"]; $form_device["snmp_community"] = $_POST["snmp_community"]; $form_device["snmp_port"] = $_POST["snmp_port"]; $form_device["snmp_timeout"] = $_POST["snmp_timeout"]; $form_device["snmpv3_auth_username"] = $_POST["snmpv3_auth_username"]; $form_device["snmpv3_auth_password"] = $_POST["snmpv3_auth_password"]; $form_device["snmpv3_auth_protocol"] = $_POST["snmpv3_auth_protocol"]; $form_device["snmpv3_priv_passphrase"] = $_POST["snmpv3_priv_passphrase"]; $form_device["snmpv3_priv_protocol"] = $_POST["snmpv3_priv_protocol"]; field_register_error(api_device_field_validate($form_device, "|field|")); /* field save */ $device_id = false; if (is_error_message()) { log_save("User input validation error for device [ID#" . $_POST["id"] . "]", SEV_DEBUG); } else { $device_id = api_device_save($_POST["id"], $form_device); if ($device_id === false) { log_save("Save error for device [ID#" . $_POST["id"] . "]", SEV_ERROR); } } if ($device_id === false || empty($_POST["id"])) { header("Location: devices.php?action=edit" . (empty($_POST["id"]) ? "" : "&id=" . $_POST["id"])); } else { header("Location: devices.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "search") { $get_string = ""; if ($_POST["box-1-search_device_template"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_device_template=" . urlencode($_POST["box-1-search_device_template"]); } if ($_POST["box-1-search_status"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_status=" . urlencode($_POST["box-1-search_status"]); } if (trim($_POST["box-1-search_filter"]) != "") { $get_string .= ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } header("Location: devices.php{$get_string}"); exit; } else { if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $host_id) { api_device_remove($host_id, $_POST["box-1-remove_type"] == "2" ? true : false); } } else { if ($_POST["box-1-action-area-type"] == "enable") { foreach ($selected_rows as $host_id) { api_device_enable($host_id); } } else { if ($_POST["box-1-action-area-type"] == "disable") { foreach ($selected_rows as $host_id) { api_device_disable($host_id); } } else { if ($_POST["box-1-action-area-type"] == "clear_stats") { foreach ($selected_rows as $host_id) { api_device_statistics_clear($host_id); } } else { if ($_POST["box-1-action-area-type"] == "change_snmp_opts") { // not yet implemented } else { if ($_POST["box-1-action-area-type"] == "change_avail_opts") { // not yet implemented } else { if ($_POST["box-1-action-area-type"] == "change_poller") { // not yet implemented } } } } } } } } header("Location: devices.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "device_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: devices.php{$get_string}"); } } } }
function api_device_data_query_get($device_id, $data_query_id) { /* sanity check for $data_query_id */ if ((!is_numeric($data_query_id)) || (empty($data_query_id))) { log_save("Invalid input '$data_query_id' for 'data_query_id' in " . __FUNCTION__ . "()", SEV_ERROR); return false; } /* sanity check for $device_id */ if ((!is_numeric($device_id)) || (empty($device_id))) { log_save("Invalid input '$device_id' for 'host_id' in " . __FUNCTION__ . "()", SEV_ERROR); return false; } return db_fetch_row("select * from host_data_query where host_id = " . sql_sanitize($device_id) . " and data_query_id = " . sql_sanitize($data_query_id)); }
function form_save() { if ($_POST["action_post"] == "package_new") { header("Location: packages.php?action=edit"); }else if ($_POST["action_post"] == "package_edit") { /* the "Add" associated graph template button was pressed */ if (isset($_POST["assoc_graph_template_add_y"])) { api_package_package_template_add($_POST["package_id"], $_POST["assoc_graph_template_id"]); header("Location: packages.php?action=edit&id=" . $_POST["package_id"]); exit; } /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_package["id"] = $_POST["package_id"]; $form_package["name"] = $_POST["name"]; $form_package["description"] = $_POST["description"]; $form_package["description_install"] = $_POST["description_install"]; $form_package["category"] = ($_POST["category"] == "new" ? $_POST["category_txt"] : api_data_preset_package_category_get($_POST["category_drp"])); $form_package["subcategory"] = ($_POST["subcategory"] == "new" ? $_POST["subcategory_txt"] : api_data_preset_package_subcategory_get($_POST["subcategory_drp"])); $form_package["vendor"] = ($_POST["vendor"] == "new" ? $_POST["vendor_txt"] : api_data_preset_package_vendor_get($_POST["vendor_drp"])); $form_package["model"] = $_POST["model"]; /* the author field values may either come from the form or from the database */ if ($_POST["author_type"] == "new") { $form_package["author_name"] = $_POST["author_name"]; $form_package["author_email"] = $_POST["author_email"]; $form_package["author_user_repository"] = $_POST["author_user_repository"]; $form_package["author_user_forum"] = $_POST["author_user_forum"]; }else if ($_POST["author_type"] == "existing") { $package_author = api_package_author_get($_POST["author_type_drp"]); $form_package["author_name"] = $package_author["name"]; $form_package["author_email"] = $package_author["email"]; $form_package["author_user_repository"] = $package_author["user_repository"]; $form_package["author_user_forum"] = $package_author["user_forum"]; } field_register_error(api_package_field_validate($form_package, "|field|")); /* the custom category textbox goes by a different name on the form */ if (field_error_isset("category")) { field_register_error("category_txt"); } /* the custom subcategory textbox goes by a different name on the form */ if (field_error_isset("subcategory")) { field_register_error("subcategory_txt"); } /* step #3: field save */ $package_id = false; if (is_error_message()) { log_save("User input validation error for package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG); }else{ $package_id = api_package_save($_POST["package_id"], $form_package); if ($package_id === false) { log_save("Save error for package [ID#" . $_POST["package_id"] . "]", SEV_ERROR); } } if (($package_id === false) || (empty($_POST["package_id"]))) { header("Location: packages.php?action=edit" . (empty($_POST["package_id"]) ? "" : "&id=" . $_POST["package_id"])); }else{ header("Location: packages.php"); } }else if ($_POST["action_post"] == "package_edit_metadata") { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_package_metadata["id"] = $_POST["package_metadata_id"]; $form_package_metadata["package_id"] = $_POST["package_id"]; $form_package_metadata["type"] = $_POST["type"]; $form_package_metadata["name"] = $_POST["name"]; $form_package_metadata["description"] = $_POST["description"]; if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCREENSHOT) { /* make sure there is a valid file that was uploaded via an HTTP POST */ if ((isset($_FILES["payload_upl"])) && (is_uploaded_file($_FILES["payload_upl"]["tmp_name"]))) { $fp = fopen($_FILES["payload_upl"]["tmp_name"], "r"); $raw_data = fread($fp, $_FILES["payload_upl"]["size"]); fclose($fp); $form_package_metadata["mime_type"] = $_FILES["payload_upl"]["type"]; $form_package_metadata["payload"] = $raw_data; } }else if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCRIPT) { $form_package_metadata["description_install"] = $_POST["description_install"]; $form_package_metadata["required"] = html_boolean(isset($_POST["required"]) ? $_POST["required"] : ""); $form_package_metadata["mime_type"] = "text/plain"; $form_package_metadata["payload"] = $_POST["payload_txt"]; } field_register_error(api_package_field_validate($form_package_metadata, "|field|")); /* step #3: field save */ $package_metadata_id = false; if (is_error_message()) { log_save("User input validation error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG); }else{ $package_metadata_id = api_package_metadata_save($_POST["package_metadata_id"], $form_package_metadata); if ($package_metadata_id === false) { log_save("Save error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_ERROR); } } if ($package_metadata_id === false) { header("Location: packages.php?action=edit_metadata&package_id=" . $_POST["package_id"] . (empty($_POST["package_metadata_id"]) ? "" : "&id=" . $_POST["package_metadata_id"])); }else{ /* the cache will not be purged in time unless to do it here */ kill_post_field_cache(); header("Location: packages.php?action=edit&id=" . $_POST["package_id"]); } }else if ($_POST["action_post"] == "package_import") { /* first, see if there is any XML in the textbox */ if (trim($_POST["import_package_text"] != "")) { $xml_data = $_POST["import_package_text"]; /* next, check if the user uploaded a file */ }else if ((isset($_FILES["import_package_file"])) && (is_uploaded_file($_FILES["import_package_file"]["tmp_name"]))) { $fp = fopen($_FILES["import_package_file"]["tmp_name"], "r"); $xml_data = fread($fp, $_FILES["import_package_file"]["size"]); fclose($fp); } package_import($xml_data); } }
if (strpos($result,"\n") != 0) { fputs(STDOUT, $result); fflush(STDOUT); } else { fputs(STDOUT, $result . "\n"); fflush(STDOUT); } log_save(_("SERVER: ") . $in_string . _(" output ") . $result, SEV_DEBUG, FACIL_SCPTSVR, "", $poller_id); } else { log_save(_("Function does not exist"), SEV_WARNING, FACIL_SCPTSVR, "", $poller_id); fputs(STDOUT, _("WARNING: Function does not exist") . "\n"); } }elseif ($in_string == "quit") { fputs(STDOUT, _("PHP Script Server Shutdown request received, exiting") . "\n"); log_save(_("PHP Script Server Shutdown request received, exiting"), SEV_DEBUG, FACIL_SCPTSVR, "", $poller_id); break; }else { log_save(_("Problems with input, command ingnored"), SEV_WARNING, FACIL_SCPTSVR, "", $poller_id); fputs(STDOUT, _("ERROR: Problems with input") . "\n"); } }else { log_save(_("Input Expected, Script Server Terminating"), SEV_ERROR, FACIL_SCPTSVR, "", $poller_id); fputs(STDOUT, _("ERROR: Input Expected, Script Server Terminating") . "\n"); /* parent abended, let's show the parent as done */ db_execute("insert into poller_time (poller_id, start_time, end_time) values (0, NOW(), NOW())"); exit (-1); } } ?>
if (api_user_expire_info($_SESSION["sess_user_id"]) == "0") { $_SESSION["sess_change_password"] = true; if (read_config_option("auth_method") == 1 || $current_user["realm"] == "0" && read_config_option("auth_method") == "3") { log_save(_("AUTH: User password expired, password change forced"), SEV_NOTICE, FACIL_AUTH); header("Location: auth_changepassword.php?ref=" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php")); exit; } } /* Check permissions to use this realm against database */ $realm_id = 0; if (isset($user_auth_realm_filenames[basename($_SERVER["PHP_SELF"])])) { $realm_id = $user_auth_realm_filenames[basename($_SERVER["PHP_SELF"])]; } $user_realms = api_user_realms_list($_SESSION["sess_user_id"]); if ($user_realms[$realm_id]["value"] != "1") { log_save(_("AUTH: User access denied to realm ") . $user_auth_realms[$realm_id], SEV_WARNING, FACIL_AUTH); ?> <html> <head> <link rel='shortcut icon' href='<?php print html_get_theme_images_path("favicon.ico"); ?> ' type='image/x-icon'> <link href='<?php print html_get_theme_images_path("favicon.ico"); ?> ' rel='image/x-icon'> <title><?php echo _("Cacti"); ?> </title>
function form_save() { if (isset($_POST["save_data_query_x"])) { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_data_query["id"] = $_POST["data_query_id"]; $form_data_query["input_type"] = $_POST["input_type"]; $form_data_query["name"] = $_POST["name"]; $form_data_query["index_order_type"] = $_POST["index_order_type"]; $form_data_query["index_title_format"] = $_POST["index_title_format"]; /* these fields are only displayed when editing a data query field */ if (!empty($_POST["data_query_id"])) { $form_data_query["index_order"] = $_POST["index_order"]; $form_data_query["index_field_id"] = $_POST["index_field_id"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { $form_data_query["snmp_oid_num_rows"] = $_POST["snmp_oid_num_rows"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY || $form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { $form_data_query["script_path"] = $_POST["script_path"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { $form_data_query["script_server_function"] = $_POST["script_server_function"]; } field_register_error(validate_data_query_fields($form_data_query, "|field|")); /* step #3: field save */ $data_query_id = false; if (is_error_message()) { log_save("User input validation error for data query [ID#" . $_POST["data_query_id"] . "]", SEV_DEBUG); } else { $data_query_id = api_data_query_save($_POST["data_query_id"], $form_data_query); if ($data_query_id === false) { log_save("Save error for data query [ID#" . $_POST["data_query_id"] . "]", SEV_ERROR); } } if ($data_query_id === false) { header("Location: data_queries.php?action=edit" . (empty($_POST["data_query_id"]) ? "" : "&id=" . $_POST["data_query_id"])); } else { if (empty($_POST["data_query_id"])) { header("Location: data_queries.php?action=edit&id={$data_query_id}"); } else { header("Location: data_queries.php"); } } } else { if (isset($_POST["save_data_query_field_x"])) { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_data_query["id"] = $_POST["data_query_field_id"]; $form_data_query["data_query_id"] = $_POST["data_query_id"]; $form_data_query["type"] = $_POST["field_type"]; $form_data_query["name"] = $_POST["name"]; $form_data_query["name_desc"] = $_POST["name_desc"]; $form_data_query["source"] = $_POST["source"]; /* determine the correct values for the method type/value fields */ if (isset($_POST["method_group"])) { /* value */ if ($_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_VALUE) { $form_data_query["method_type"] = $_POST["method_type_v"]; if ($_POST["method_type_v"] == DATA_QUERY_FIELD_METHOD_VALUE_PARSE) { $form_data_query["method_value"] = $_POST["method_value_v_parse"]; } /* snmp oid */ } else { if ($_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID) { $form_data_query["method_type"] = $_POST["method_type_s"]; if ($_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) { $form_data_query["method_value"] = $_POST["method_value_s_octet"]; } else { if ($_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_PARSE) { $form_data_query["method_value"] = $_POST["method_value_s_parse"]; } } } } } field_register_error(validate_data_query_field_fields($form_data_query, "|field|")); /* since the 'method_value' field name is abstracted above, we need to pass any input field errors * on to the correct form field */ if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_VALUE && $_POST["method_type_v"] == DATA_QUERY_FIELD_METHOD_VALUE_PARSE) { $_SESSION["sess_error_fields"]["method_value_v_parse"] = 1; } else { if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID && $_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) { $_SESSION["sess_error_fields"]["method_value_s_octet"] = 1; } else { if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID && $_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_PARSE) { $_SESSION["sess_error_fields"]["method_value_s_parse"] = 1; } } } /* step #3: field save */ $data_query_field_id = false; if (is_error_message()) { log_save("User input validation error for data query field [ID#" . $_POST["data_query_field_id"] . "], data query [ID#" . $_POST["data_query_id"] . "]", SEV_DEBUG); } else { $data_query_field_id = api_data_query_field_save($_POST["data_query_field_id"], $form_data_query); if ($data_query_field_id === false) { log_save("Save error for data query field [ID#" . $_POST["data_query_field_id"] . "], data query [ID#" . $_POST["data_query_id"] . "]", SEV_ERROR); } } if ($data_query_field_id === false) { header("Location: data_queries.php?action=field_edit" . (empty($_POST["data_query_field_id"]) ? "" : "&id=" . $_POST["data_query_field_id"]) . "&data_query_id=" . $_POST["data_query_id"]); } else { header("Location: data_queries.php?action=edit&id=" . $_POST["data_query_id"]); } } else { if (isset($_POST["box-1-action-area-button"])) { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $data_query_id) { api_data_query_remove($data_query_id); } } header("Location: data_queries.php"); } } } }
function rrdtool_function_tune($rrd_tune_array) { require(CACTI_BASE_PATH . "/include/global_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php"); $data_source_name = get_data_source_item_name($rrd_tune_array["data_source_id"]); $data_source_type = $data_source_types{$rrd_tune_array["data-source-type"]}; $data_source_path = api_data_source_path_get($rrd_tune_array["data_source_id"], true); if ($rrd_tune_array["heartbeat"] != "") { $rrd_tune .= " --heartbeat $data_source_name:" . $rrd_tune_array["heartbeat"]; } if ($rrd_tune_array["minimum"] != "") { $rrd_tune .= " --minimum $data_source_name:" . $rrd_tune_array["minimum"]; } if ($rrd_tune_array["maximum"] != "") { $rrd_tune .= " --maximum $data_source_name:" . $rrd_tune_array["maximum"]; } if ($rrd_tune_array["data-source-type"] != "") { $rrd_tune .= " --data-source-type $data_source_name:" . $data_source_type; } if ($rrd_tune_array["data-source-rename"] != "") { $rrd_tune .= " --data-source-rename $data_source_name:" . $rrd_tune_array["data-source-rename"]; } if ($rrd_tune != "") { if (file_exists($data_source_path) == true) { $fp = popen(read_config_option("path_rrdtool") . " tune $data_source_path $rrd_tune", "r"); pclose($fp); log_save("RRD_TUNE: " . addslashes(read_config_option("path_rrdtool")) . " tune $data_source_path $rrd_tune", SEV_DEBUG, FACIL_POLLER); } } }
function db_replace($table_name, $fields, $keys = "") { global $cnn_id, $last_insert_id; /* default primary key */ if (!is_array($keys)) { $keys = array("id"); } /* generate a WHERE statement that reflects the list of keys */ $sql_key_where = ""; for ($i=0; $i<sizeof($keys); $i++) { $sql_key_where .= ($i == 0 ? "WHERE " : " AND ") . $keys[$i] . " = " . sql_get_quoted_string($fields{$keys[$i]}["type"], $fields{$keys[$i]}["value"]); } /* no rows exist at this key; generate an INSERT statement */ if (db_fetch_cell("SELECT count(*) FROM $table_name $sql_key_where") == 0) { $sql_field_names = ""; $sql_field_values = ""; $i = 0; if (sizeof($fields) > 0) { foreach ($fields as $db_field_name => $db_field_array) { if ($i == 0) { $sql_field_names = "("; $sql_field_values = "("; } $sql_field_names .= $db_field_name . ($i == (sizeof($fields) - 1) ? "" : ","); $sql_field_values .= sql_get_quoted_string($db_field_array["type"], $db_field_array["value"]) . ($i == (sizeof($fields) - 1) ? "" : ","); if ($i == (sizeof($fields) - 1)) { $sql_field_names .= ")"; $sql_field_values .= ")"; } $i++; } } $sql = "INSERT INTO $table_name $sql_field_names VALUES $sql_field_values"; /* more than one row exists at this key; generate an UPDATE statement */ }else{ $sql_set_fields = ""; $i = 0; if (sizeof($fields) > 0) { foreach ($fields as $db_field_name => $db_field_array) { /* do not include the key fields in the SET string */ if (!in_array($db_field_name, $keys)) { $sql_set_fields .= $db_field_name . " = " . sql_get_quoted_string($db_field_array["type"], $db_field_array["value"]) . (($i == (sizeof($fields) - sizeof($keys) - 1)) ? "" : ","); $i++; } } } /* if there are not any fields to update, log a warning */ if ($sql_set_fields == "") { log_save("Invalid empty update field list for table '$table_name' in " . __FUNCTION__ . "()", SEV_WARNING); return false; } $sql = "UPDATE $table_name SET $sql_set_fields $sql_key_where"; } /* execute the sql statement and return the result */ if (db_execute($sql)) { /* cache the inserted id for later use */ $_last_insert_id = $cnn_id->Insert_ID(); if (!empty($_last_insert_id)) { $last_insert_id = $_last_insert_id; } return true; }else{ return false; } }
function host_new_graphs_save() { $validation_array = array(); $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"])); $map_id_to_index_array = unserialize(stripslashes($_POST["map_id_to_index_array"])); /* form an array that contains all of the data on the previous form */ while (list($var, $val) = each($_POST)) { if (preg_match("/^g_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["graph_template"][$matches[3]] = $val; } $validation_array["graph_template"][$matches[3]][$var] = $val; } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: graph_template_input_id, 4: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["graph_template_item"][$matches[2]][$matches[3]] = $val; } $validation_array["graph_template_item"][$matches[4]][$var] = $val; } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["data_template"][$matches[3]][$matches[4]] = $val; } $validation_array["data_template"][$matches[4]][$var] = $val; } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_input_field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["custom_data"][$matches[3]][$matches[4]] = $val; } $validation_array["custom_data"][$matches[4]][$var] = $val; } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_template_item_id, 5: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["data_template_item"][$matches[3]][$matches[4]][$matches[5]] = $val; } $validation_array["data_template_item"][$matches[5]][$var] = $val; } } /* first pass: form validation */ while (list($type, $type_array) = each($validation_array)) { while (list($field_name, $field_array) = each($type_array)) { while (list($form_field_name, $value) = each($field_array)) { $_v_arr = array($field_name => $value); if ($type == "data_template") { $_sv_arr = array(); field_register_error(api_data_source_fields_validate($_v_arr, $_sv_arr, $form_field_name, "")); } else { if ($type == "custom_data") { field_register_error(api_data_source_input_fields_validate($_v_arr, $form_field_name)); } else { if ($type == "data_template_item") { $_v_arr["id"] = 0; field_register_error(api_data_source_item_fields_validate($_v_arr, $form_field_name)); } else { if ($type == "graph_template") { $_sv_arr = array(); field_register_error(api_graph_fields_validate($_v_arr, $_sv_arr, $form_field_name, "")); } else { if ($type == "graph_template_item") { field_register_error(api_graph_item_fields_validate($_v_arr, $form_field_name)); } } } } } } } } /* form validation failed: redirect back */ if (is_error_message()) { /* cache all post field values */ init_post_field_cache(); host_new_graphs($selected_graphs_array, $map_id_to_index_array); /* form validation passed: save the data on the form */ } else { debug_log_clear("new_graphs"); foreach ($selected_graphs_array as $uniq_id => $skel) { if (isset($skel["custom_data"]["all_dq"])) { $is_data_query_graph = true; $data_query_id = isset($skel["custom_data"]["all_dq"]["data_query_id"]) ? $skel["custom_data"]["all_dq"]["data_query_id"] : 0; /* decode the data query index into its literal form */ $data_query_index = decode_data_query_index(isset($skel["custom_data"]["all_dq"]["data_query_index"]) ? $skel["custom_data"]["all_dq"]["data_query_index"] : 0, get_data_query_indexes($data_query_id, $_POST["host_id"])); } else { $is_data_query_graph = false; $data_query_id = 0; $data_query_index = ""; } $create_info = generate_complete_graph($skel["graph_template_id"], $_POST["host_id"], $data_query_id, $data_query_index); /* set the appropriate 'custom_data' keys */ if ($is_data_query_graph == true) { /* pick the data query field name to index on */ $data_query_field_name = get_best_data_query_index_type($_POST["host_id"], $data_query_id); /* get a list of all data templates associated with this graph template that are of type DATA_INPUT_TYPE_DATA_QUERY */ $dq_data_templates = get_data_templates_from_graph_template($skel["graph_template_id"], DATA_INPUT_TYPE_DATA_QUERY); if (sizeof($dq_data_templates) > 0) { foreach ($dq_data_templates as $data_template) { $skel["custom_data"][$data_template["id"]]["data_query_id"] = $data_query_id; $skel["custom_data"][$data_template["id"]]["data_query_index"] = $data_query_index; $skel["custom_data"][$data_template["id"]]["data_query_field_name"] = $data_query_field_name; $skel["custom_data"][$data_template["id"]]["data_query_field_value"] = get_data_query_row_value($data_query_id, $_POST["host_id"], $data_query_field_name, $data_query_index); } } } /* update user specified data: data source-specific fields */ foreach (array_keys($create_info["data_source"]) as $data_template_id) { if (isset($skel["data_template"][$data_template_id])) { if (!api_data_source_save($create_info["data_source"][$data_template_id], $skel["data_template"][$data_template_id])) { log_save("Problems updating new data source [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } if (isset($skel["data_template_item"][$data_template_id])) { foreach ($skel["data_template_item"][$data_template_id] as $data_source_item_id => $data_template_item_array) { if (!api_data_source_item_save($data_source_item_id, $data_template_item_array)) { log_save("Problems updating new data source [item] [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } } if (isset($skel["custom_data"][$data_template_id])) { if (!api_data_source_fields_save($create_info["data_source"][$data_template_id], $skel["custom_data"][$data_template_id])) { log_save("Problems updating new data source (fields) [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } /* update the title cache */ api_data_source_title_cache_update($create_info["data_source"][$data_template_id]); /* update poller cache */ update_poller_cache($create_info["data_source"][$data_template_id]); } /* update user specified data: graph-specific fields */ foreach (array_keys($create_info["graph"]) as $graph_template_id) { if (isset($skel["graph_template"][$graph_template_id])) { if (!api_graph_save($create_info["graph"][$graph_template_id], $skel["graph_template"][$graph_template_id])) { log_save("Problems updating new graph [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR); } } if (isset($skel["graph_template_item"][$graph_template_id])) { foreach ($skel["graph_template_item"][$graph_template_id] as $graph_template_item_input_id => $value) { if (!api_graph_template_item_input_propagate($graph_template_item_input_id, $value)) { log_save("Problems updating new graph [item] [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR); } } } /* update the title cache */ api_graph_title_cache_update($create_info["graph"][$graph_template_id]); } debug_log_insert("new_graphs", _("Created graph: ") . api_graph_title_get($create_info["graph"][$skel["graph_template_id"]])); } /* lastly push host-specific information to our data sources */ //push_out_host($_POST["host_id"], 0); } }
function api_user_ldap_search_dn($username,$ldap_dn = "",$ldap_host = "",$ldap_port = "",$ldap_port_ssl = "",$ldap_version = "",$ldap_encryption = "",$ldap_referrals = "", $ldap_mode = "",$ldap_search_base = "", $ldap_search_filter = "",$ldap_specific_dn = "",$ldap_specific_password = "") { $output = array(); /* validation */ if (empty($username)) { $output["dn"] = ""; $output["error_num"] = "1"; $output["error_text"] = _("No username defined"); log_save(_("LDAP_SEARCH: No username defined"), SEV_DEBUG, FACIL_AUTH); return $output; } /* strip bad chars from username - prevent altering filter from username */ $username = str_replace("&", "", $username); $username = str_replace("|", "", $username); $username = str_replace("(", "", $username); $username = str_replace(")", "", $username); $username = str_replace("*", "", $username); $username = str_replace(">", "", $username); $username = str_replace("<", "", $username); $username = str_replace("!", "", $username); $username = str_replace("=", "", $username); /* get LDAP parameters */ if (empty($ldap_dn)) { $ldap_dn = read_config_option("ldap_dn"); } $ldap_dn = str_replace("<username>",$username,$ldap_dn); if (empty($ldap_host)) { $ldap_host = read_config_option("ldap_server"); } if (empty($ldap_port)) { $ldap_port = read_config_option("ldap_port"); } if (empty($ldap_port_ssl)) { $ldap_port_ssl = read_config_option("ldap_port_ssl"); } if (empty($ldap_version)) { $ldap_version = read_config_option("ldap_version"); } if (empty($ldap_encryption)) { $ldap_encryption = read_config_option("ldap_encryption"); } if (empty($ldap_referrals)) { $ldap_referrals = read_config_option("ldap_referrals"); } if (empty($ldap_mode)) { $ldap_mode = read_config_option("ldap_mode"); } if ($ldap_encryption == "1") { $ldap_host = "ldaps://" . $ldap_host; $ldap_port = $ldap_port_ssl; }else{ $ldap_host = "ldap://" . $ldap_host; } if ($ldap_mode == "0") { /* Just bind mode, make dn and return */ $output["dn"] = $ldap_dn; $output["error_num"] = "0"; $output["error_text"] = _("User found"); return $output; }elseif ($ldap_mode == "2") { /* specific */ if (empty($ldap_specific_dn)) { $ldap_specific_dn = read_config_option("ldap_specific_dn"); } if (empty($ldap_specific_password)) { $ldap_specific_password = read_config_option("ldap_specific_password"); } log_save(sprintf(_("LDAP_SEARCH: Using DN '%s' and password '%s' for binding"), $ldap_specific_dn, $ldap_specific_password), SEV_DEBUG, FACIL_AUTH); }elseif ($ldap_mode == "1"){ /* assume anonymous */ $ldap_specific_dn = ""; $ldap_specific_password = ""; log_save(_("LDAP_SEARCH: Using anonymous for binding"), SEV_DEBUG, FACIL_AUTH); } if (empty($ldap_search_base)) { $ldap_search_base = read_config_option("ldap_search_base"); } if (empty($ldap_search_filter)) { $ldap_search_filter = read_config_option("ldap_search_filter"); } $ldap_search_filter = str_replace("<username>",$username,$ldap_search_filter); log_save(sprintf(_("LDAP_SEARCH: Search filter '%s'"), $ldap_search_filter), SEV_DEBUG, FACIL_AUTH); /* Searching mode */ /* Setup connection to LDAP server */ log_save(sprintf(_("LDAP: Setting up connection to %s:%s"), $ldap_host, $ldap_port), SEV_DEBUG, FACIL_AUTH); $ldap_conn = @ldap_connect($ldap_host,$ldap_port); if ($ldap_conn) { /* Set protocol version */ log_save(sprintf(_("LDAP_SEARCH: Setting protocol version to %s"), $ldap_version), SEV_DEBUG, FACIL_AUTH); if (!@ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $ldap_version)) { /* protocol error */ $output["dn"] = ""; $output["error_num"] = "4"; $output["error_text"] = _("Protocol error, unable to set version"); log_save(sprintf(_("LDAP_SEARCH: %s"), $output["error_text"]), SEV_ERROR, FACIL_AUTH); @ldap_close($ldap_conn); return $output; } /* set referrals */ if ($ldap_referrals == "0") { log_save(_("LDAP_SEARCH: Setting referral option to ") . $ldap_referrals, SEV_DEBUG, FACIL_AUTH); if (!@ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0)) { /* referrals set error */ $output["dn"] = ""; $output["error_num"] = "13"; $output["error_text"] = _("Unable to set referrals option"); log_save(_("LDAP_SEARCH: ") . $output["error_text"], SEV_ERROR, FACIL_AUTH); @ldap_close($ldap_conn); return $output; } } /* start TLS if requested */ if ($ldap_encryption == "2") { log_save(_("LDAP_SEARCH: Starting TLS encryption"), SEV_DEBUG, FACIL_AUTH); if (!@ldap_start_tls($ldap_conn)) { /* TLS startup error */ $output["dn"] = ""; $output["error_num"] = "5"; $output["error_text"] = _("Protocol error, unable to start TLS communications"); log_save(_("LDAP_SEARCH: ") . $output["error_text"], SEV_ERROR, FACIL_AUTH); @ldap_close($ldap_conn); return $output; } } /* bind to the directory */ log_save(_("LDAP_SEARCH: Binding to LDAP server"), SEV_DEBUG, FACIL_AUTH); if (@ldap_bind($ldap_conn,$ldap_specific_dn,$ldap_specific_password)) { /* Search */ $ldap_results = ldap_search($ldap_conn, $ldap_search_base, $ldap_search_filter, array("dn")); if ($ldap_results) { $ldap_entries = ldap_get_entries($ldap_conn, $ldap_results); if ($ldap_entries["count"] == "1") { /* single response return user dn */ $output["dn"] = $ldap_entries["0"]["dn"]; $output["error_num"] = "0"; $output["error_text"] = _("User found"); log_save(sprintf(_("LDAP_SEARCH: User found, DN '%s'"), $output["dn"]), SEV_DEBUG, FACIL_AUTH); }elseif ($ldap_entries["count"] > 1) { /* more than 1 result */ $output["dn"] = ""; $output["error_num"] = "13"; $output["error_text"] = _("More than one matching user found"); }else{ /* no search results */ $output["dn"] = ""; $output["error_num"] = "3"; $output["error_text"] = _("Unable to find users DN"); } }else{ /* no search results, user not found*/ $output["dn"] = ""; $output["error_num"] = "3"; $output["error_text"] = _("Unable to find users DN"); } }else{ /* unable to bind */ $ldap_error = ldap_errno($ldap_conn); if ($ldap_error == 0x03) { /* protocol error */ $output["dn"] = ""; $output["error_num"] = "6"; $output["error_text"] = _("Protocol error"); }elseif ($ldap_error == 0x31) { /* invalid credentials */ $output["dn"] = ""; $output["error_num"] = "7"; $output["error_text"] = _("Invalid credentials"); }elseif ($ldap_error == 0x32) { /* insuffient access */ $output["dn"] = ""; $output["error_num"] = "8"; $output["error_text"] = _("Insuffient access"); }elseif ($ldap_error == 0x51) { /* unable to connect to server */ $output["dn"] = ""; $output["error_num"] = "9"; $output["error_text"] = _("Unable to connect to server"); }elseif ($ldap_error == 0x55) { /* timeout */ $output["dn"] = ""; $output["error_num"] = "10"; $output["error_text"] = _("Timeout"); }else{ /* general bind error */ $output["dn"] = ""; $output["error_num"] = "11"; $output["error_text"] = sprintf(_("General bind error, LDAP result: %s"), ldap_error($ldap_conn)); } } }else{ /* unable to setup connection */ $output["dn"] = ""; $output["error_num"] = "2"; $output["error_text"] = _("Unable to create LDAP connection object"); } @ldap_close($ldap_conn); if ($output["error_num"] > 0) { log_save(_("LDAP_SEARCH: ") . $output["error_text"], SEV_ERROR, FACIL_AUTH); } return $output; }
function generate_complete_graph($graph_template_id, $host_id = 0, $data_query_id = 0, $data_query_index = "") { require_once(CACTI_BASE_PATH . "/lib/graph/graph_update.php"); require_once(CACTI_BASE_PATH . "/lib/data_template/data_template_push.php"); require_once(CACTI_BASE_PATH . "/lib/data_template/data_template_info.php"); /* sanity check for $graph_template_id */ if ((!is_numeric($graph_template_id)) || (empty($graph_template_id))) { return false; } /* sanity check for $host_id */ if (!is_numeric($host_id)) { return false; } $data_templates = get_data_templates_from_graph_template($graph_template_id); /* decide which data sources we will need to create */ $create_data_templates_list = array(); if (sizeof($data_templates) > 0) { foreach ($data_templates as $item) { if (($item["data_input_type"] == DATA_INPUT_TYPE_DATA_QUERY) && (isset($form_data_input_fields["data_query_id"]))) { if (db_fetch_cell("select value from data_template_field where data_template_id = " . $item["id"] . " and name = 'data_query_id'") == $form_data_input_fields["data_query_id"]) { $create_data_templates_list[] = $item["id"]; } }else{ $create_data_templates_list[] = $item["id"]; } } } /* no data templates have been marked for creation */ if (sizeof($create_data_templates_list) == 0) { return false; } $dti_to_dsi = array(); foreach ($create_data_templates_list as $data_template_id) { $data_source_id = copy_data_template_to_data_source($data_template_id, $host_id, $data_query_id, $data_query_index); if ($data_source_id === false) { log_save("Error generating data source from data template [ID#$data_template_id]", SEV_ERROR); }else{ $dti_to_dsi[$data_template_id] = $data_source_id; } } /* create the actual graph from the chosen graph template */ $graph_id = copy_graph_template_to_graph($graph_template_id, $host_id, $data_query_id, $data_query_index); if ($graph_id === false) { log_save("Error generating graph from graph template [ID#$graph_template_id]", SEV_ERROR); }else{ /* fetch a list graph template items and their associated data template items */ $data_template_items = get_data_template_items_from_graph_template($graph_template_id); if (sizeof($data_template_items) > 0) { foreach ($data_template_items as $item) { /* write out the graph->data source item mapping here. note, that we are only able to use 'sequence' * as a primary key here because the graph was just created above and therefore must be accurate */ db_update("graph_item", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => db_fetch_cell("select id from graph_item where graph_id = " . sql_sanitize($graph_id) . " and graph_template_item_id = " . sql_sanitize($item["graph_template_item_id"]))), "data_source_item_id" => array("type" => DB_TYPE_INTEGER, "value" => db_fetch_cell("select id from data_source_item where data_source_name = '" . sql_sanitize($item["data_source_name"]) . "' and data_source_id = " . sql_sanitize($dti_to_dsi{$item["data_template_id"]}))) ), array("id")); } } /* make sure the graph title is up to date */ api_graph_title_cache_update($graph_id); return array("graph" => array($graph_template_id => $graph_id), "data_source" => $dti_to_dsi); } return false; }
default: $url_location = "index.php"; } log_save(_("LOGIN: URL: ") . $url_location, SEV_DEBUG, FACIL_AUTH); header("Location: " . $url_location); exit; } } else { if (!$guest_user && $user_auth) { /* No guest account defined */ auth_display_custom_error_message(_("Access Denied, please contact you Cacti Administrator.")); log_save(_("LOGIN: Access Denied, No guest enabled or template user to copy"), SEV_CRITICAL, FACIL_AUTH); exit; } else { /* BAD username/password builtin and LDAP */ log_save(sprintf(_("LOGIN: Invalid username '%s' and password"), $username), SEV_WARNING, 0, 0, 0, false, FACIL_AUTH); } } } /* auth_display_custom_error_message - displays a custom error message to the browser that looks like the pre-defined error messages @arg $message - the actual text of the error message to display */ function auth_display_custom_error_message($message) { /* kill the session */ setcookie(session_name(), "", time() - 3600, "/"); /* print error */ print "<html>\n<head>\n"; print " <title>" . _("Cacti") . "</title>\n"; print " <link href=\"" . html_get_theme_css() . "\" rel=\"stylesheet\">"; print "</head>\n";
ini_set('max_execution_time', '0'); $no_http_headers = true; require dirname(__FILE__) . '/include/global.php'; $event_manager_interval = read_config_option('event_manager_interval'); log_save('Event Manager Starting', SEV_INFO, FACIL_POLLER, '', 0, 0, 0, true); $counter = time() - $event_manager_interval; while (true) { /* We want to have the event manager process every XX seconds, so sleep until its processing time */ while ($counter > time() - $event_manager_interval) { Sleep(1); } /* Start our timer now, so it includes the actual processing time in the processing interval */ $counter = time(); /* Set the status to show which events are being processed */ $status_id = event_save_status(); /* Get all events so we can begin processing */ $events = event_list(array('status' => $status_id)); /* Loop through each event for processing */ foreach ($events as $event) { log_save('Processing Event ' . $event['id'], SEV_INFO, FACIL_POLLER, '', 0, 0, 0, true); event_process($event['id']); } /* Remove all events that were set to be processed */ event_deleted_processed($status_id); if (date('s', time()) < $event_manager_interval) { unset($_SESSION['sess_config_array']['event_manager_interval']); $event_manager_interval = read_config_option('event_manager_interval'); } } log_save('Event Manager exitting', SEV_INFO, FACIL_POLLER, '', 0, 0, 0, true);
/** * Truncates the cacti system log * * Truncates the cacti system log and logs that it occured * * @return bool true */ function log_clear () { db_execute("TRUNCATE TABLE log"); db_execute("REPLACE INTO settings (name,value) VALUES('log_status','active')"); log_save("Log truncated", CACTI_LOG_SEV_NOTICE, CACTI_LOG_FAC_INTERFACE); return true; }