message($debug, 'Setting after delete page to : ' . $_SERVER["HTTP_REFERER"]); } else { # check mandatory input # It divers for ADD or MODIFY ! if ($attr_id == "new") { $title = "Add attribute"; # mandatory for ADD $mandatory_fields = array("attr_name" => "attribute name", 'friendly_name' => "friendly name", 'datatype' => "attribute datatype", 'mandatory' => "mandatory", 'visible' => "visible", 'conf' => "write to conf", 'fk_id_class' => "attribute class", 'naming_attr' => "is naming attribute"); } else { $title = "Modify attribute"; # mandatory for modify $mandatory_fields = array("attr_name" => "attribute name", 'friendly_name' => "friendly name", 'mandatory' => "mandatory", 'visible' => "visible", 'conf' => "write to conf"); } echo NConf_HTML::title($title); # Check mandatory fields $write2db = check_mandatory($mandatory_fields, $_POST); } # special links # they should not both be yes (already checked, not possible with javascript) if (isset($_POST['link_as_child'])) { $link_as_child = $_POST['link_as_child']; } else { $link_as_child = 'no'; } if (isset($_POST['link_bidirectional'])) { $link_bidirectional = $_POST['link_bidirectional']; } else { $link_bidirectional = 'no'; } /* Is now allowed: if ( $link_as_child == "yes" && $link_bidirectional == "yes" ){
NConf_DEBUG::set('For its details click the link below or go back:', 'ERROR'); $list_items = ''; while ($entry = mysql_fetch_assoc($result)) { $list_items .= '<li><a href="detail.php?id=' . $entry["fk_id_item"] . '">' . $entry["attr_value"] . '</a></li>'; } $list = '<ul>' . $list_items . '</ul>'; NConf_DEBUG::set($list, 'ERROR'); # When user clicks on a listed item, and goes to delete it, the redirect must know where to go after delete, this would be the add page: $_SESSION["after_delete_page"] = $_SERVER["HTTP_REFERER"]; message($debug, 'Setting after delete page to : ' . $_SERVER["HTTP_REFERER"]); $write2db = "no"; } else { #entry not existing # Check mandatory fields $m_array = db_templates("mandatory", $config_class); $write2db = check_mandatory($m_array, $_POST); # check oncall groups when class is host, service or advanced-service if ($config_class == "host" or $config_class == "service" or $config_class == "advanced-service") { #if failed do not allow write2db if (oncall_check() == FALSE) { $write2db = 'no'; } } if ($write2db == "yes") { ################ #### write to db ################ # get class id $class_id = db_templates("get_id_of_class", $config_class); $query = 'INSERT INTO ConfigItems (id_item, fk_id_class)
<?php require_once 'include/head.php'; # Check mandatory fields $mandatory = array("item" => "Missing GET-parameter \"item\" (item class)", "id_str" => "Missing GET-parameter \"id_str\" (item name)"); $mandatory_check = check_mandatory($mandatory, $_GET); if ($mandatory_check == "yes") { # Get naming attr of class $naming_attr = db_templates("get_naming_attr_from_class", $_GET["item"]); if (!$naming_attr) { message($error, 'Could not find class "' . $_GET["item"] . '".'); } else { # Lookup ID of item if (!empty($_GET["id_str"])) { # services need other lookup if ($_GET["item"] == "service") { $id = db_templates("get_id_of_hostname_service", $naming_attr, $_GET["id_str"]); } else { $id = db_templates("get_id_of_item", $naming_attr, $_GET["id_str"]); } } if (!$id) { message($error, 'Could not find any ' . $_GET["item"] . ' item named "' . $_GET["id_str"] . '".'); } else { /* handle of other destination pages is disabled for security reason # handle dest_url if ( !empty($_GET["dest_url"]) ){ $dest_url = $_GET["dest_url"]; }else{ $dest_url = "detail.php"; }
$query = "SELECT MAX(ordering)+1 FROM ConfigClasses WHERE grouping = '{$grouping}' AND nav_privs = '{$nav_privs}'"; $ordering = db_handler($query, "getOne", "Get MAX ordering of coresponding group"); if ($ordering == NULL) { $ordering = 0; } } // if class type select is disabled, no value will come, so get the one which is already set. // this happens only on modifying if (isset($_POST['class_type'])) { $class_type = $_POST['class_type']; } else { $class_type = db_templates("lookup_ConfigClasses", "class_type", $class_id); } # Check mandatory fields $mandatory = array("config_class" => "Class name", "friendly_name" => "Friendly Name"); $write2db = check_mandatory($mandatory, $_POST); if ($write2db == "yes") { if ($class_id == "new") { $title = "Add class"; // Generate navigation link string $nav_links = 'Show::overview.php?class=' . $config_class . ';;Add::handle_item.php?item=' . $config_class; // Make insert (adding class) $query = "INSERT INTO ConfigClasses (config_class, friendly_name, nav_visible, grouping, nav_links, nav_privs, class_type, ordering, out_file, nagios_object)\n VALUES ('{$config_class}', '{$friendly_name}', '{$nav_visible}', '{$grouping}', '{$nav_links}', '{$nav_privs}', '{$class_type}', '{$ordering}', '{$out_file}', '{$nagios_object}')"; $action = "created"; } else { $title = "Modify class"; // UPDATE ConfigAttrs $action = "modified"; $query = "UPDATE ConfigClasses\n SET\n config_class = '{$config_class}',\n friendly_name = '{$friendly_name}',\n nav_visible = '{$nav_visible}',\n grouping = '{$grouping}',\n nav_links = '{$nav_links}',\n nav_privs = '{$nav_privs}',\n class_type = '{$class_type}',\n ordering = '{$ordering}',\n out_file = '{$out_file}',\n nagios_object = '{$nagios_object}'\n WHERE\n id_class = {$class_id}\n "; } $result = db_handler($query, "result", "{$action} Entry");
# check oncall groups when try modifying it and class is host, service or advanced-service # but not if the replace mode is "add" if (isset($_POST["multimodify"]) and ($config_class == "host" or $config_class == "service" or $config_class == "advanced-service") and !(!empty($_POST["replace_mode"]) and $_POST["replace_mode"] == "add")) { # get id of contact_group attr $contact_group_id = db_templates("get_attr_id", $config_class, "contact_groups"); if (isset($_POST[$contact_group_id])) { # if failed do not allow write2db $oncall_check = oncall_check(); } } # Check mandatory fields while ($attr = each($_POST)) { if (is_int($attr["key"])) { # Check mandatory fields $m_array = db_templates("mandatory", $config_class, $attr["key"]); if (check_mandatory($m_array, $_POST) == "no") { $write2db = "no"; } } } # Give error message if oncall or mandatory check fails if (isset($oncall_check) and $oncall_check === FALSE or isset($write2db) and $write2db == "no") { $content = NConf_HTML::show_error(); $content .= "<br><br>"; $content .= NConf_HTML::back_button($_SESSION["go_back_page"]); echo NConf_HTML::limit_space($content); // Cache $_SESSION["cache"]["use_cache"] = TRUE; foreach ($_POST as $key => $value) { $_SESSION["cache"]["handle"][$key] = $value; }