protected function checkIdPermission($ID)
 {
     # checks the requested id, its class should be accessible for the user, otherwise access will be denied.
     $class_id = db_templates("get_classid_of_item", $ID);
     $query = 'SELECT id_class
                 FROM ConfigClasses
                 WHERE nav_privs = "' . $this->group . '"
                     AND id_class = "' . $class_id . '"';
     $user_class_permissions = db_handler($query, "getOne", "Check if user has access to the class of the requested item");
     # set authorization
     # special behaviour for multiple ids (then its not allowed to set to true if already FALSE state was set)
     if (!empty($user_class_permissions) and $this->requested_id_authorized !== FALSE) {
         $this->requested_id_authorized = TRUE;
     } else {
         $this->requested_id_authorized = FALSE;
     }
 }
} else {
    $nav_links = "";
}
if ($_POST['old_nav_privs'] != $nav_privs or $_POST['old_group'] != $grouping or $class_id == "new") {
    $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
Example #3
0
function table_output($result, $item_class = '', $title = '', $level = 0)
{
    # template cache for detect previouse loaded template
    global $template_cache;
    # the local template cache is for detecting endless loops
    global $template_cache_local;
    # handling the local template cache
    #reseting it if level is 0
    if ($level == 0) {
        $template_cache_local = array();
    } elseif ($level == 20) {
        # this is a hardcoded loop stopper, should come into action, but prevents that the page will endless load
        # normaly there will never be templates on 20 level inherited
        return;
    }
    # output will catch the content until return
    $output = '';
    if (!empty($result)) {
        if (is_array($result) and !empty($result) and !empty($title)) {
            $output .= '<tr><td colspan=2><br>';
            if ($item_class == 'template_inheritance') {
                $output .= '<b>inherited from</b> ' . $title;
            } else {
                $output .= '<b>' . $title . '</b>';
            }
            $output .= '</td></tr>';
        }
        $last_fname = '';
        foreach ($result as $entry) {
            if (!empty($entry["config_class"]) and $entry["config_class"] == "service") {
                $host_query = 'SELECT attr_value AS hostname
                                      FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
                                      WHERE fk_item_linked2=ConfigValues.fk_id_item
                                          AND id_attr=ConfigValues.fk_id_attr
                                          AND naming_attr="yes"
                                          AND fk_id_class = id_class
                                          AND config_class="host"
                                          AND ItemLinks.fk_id_item=' . $entry["item_id"];
                $hostname = db_handler($host_query, "getOne", "Get linked hostnames (if service)");
            }
            if (!empty($entry["friendly_name"])) {
                $group_name = $entry["friendly_name"];
            }
            // group same attributes
            if (!empty($group_name) and $last_fname != $group_name) {
                $show_fname = $group_name;
                //$bgcolor = 'class="color_list2"';
            } else {
                $show_fname = '';
            }
            $output .= '<tr>';
            //$output .= '<td '.$bgcolor.'>'.$show_fname.'</td>';
            $output .= '<td class="color_list2">' . $show_fname . '</td>';
            # print template (and detect repetitive)
            if ($item_class == 'template_inheritance') {
                $template_status = apply_template($template_cache, $entry["item_id"]);
                $local_template_status = apply_template($template_cache_local, $entry["item_id"]);
                NConf_DEBUG::set($local_template_status, 'DEBUG', "local repetitive status");
                NConf_DEBUG::set($template_cache_local, 'DEBUG', "local template cache");
            } else {
                $template_status = FALSE;
                $local_template_status = FALSE;
            }
            if (!empty($entry["config_class"]) and $entry["config_class"] == "service" && $item_class != "host") {
                $output .= '<td class="color_list1 highlight">';
                $output .= '<a href="detail.php?id=' . $entry["item_id"] . '">';
                $output .= $hostname . ': ' . $entry["attr_value"];
                $output .= '</td>';
            } else {
                $level_label = '';
                for ($i = $level; $i > 1; $i--) {
                    $level_label .= '<div style="width: 9px; display: inline-block;"></div>';
                }
                if ($i == 1 and $level != 0) {
                    ## add a mark
                    $level_label .= '<span class="link_with_tag2"></span>';
                }
                # mark previously applied templates
                if ($template_status === "repetitive") {
                    # detect previously applied or template loop
                    if ($local_template_status === "repetitive") {
                        # endless loop
                        $repetitive_text = "(circular template chain detected)";
                        $class = "ui-state-error highlight";
                    } else {
                        $repetitive_text = "(previously applied)";
                        $class = "color_list1 highlight";
                    }
                    $output .= '<td class="' . $class . '">';
                    $output .= $level_label . '<a href="detail.php?id=' . $entry["item_id"] . '">';
                    $output .= $entry["attr_value"] . '</a>';
                    $output .= '<span id="' . $entry["item_id"] . '" class="previously_applied" style="float: right;"><i>' . $repetitive_text . '</i></span>';
                    $output .= '</td>';
                } else {
                    # set id for coming repetitive
                    if ($item_class == 'template_inheritance') {
                        $output .= '<td id="' . $entry["item_id"] . '_first" class="color_list1 highlight">';
                    } else {
                        $output .= '<td class="color_list1 highlight">';
                    }
                    if (!empty($entry["item_id"])) {
                        $output .= $level_label;
                        $output .= '<a href="detail.php?id=' . $entry["item_id"] . '">';
                        $output .= $entry["attr_value"] . '</a>';
                    } else {
                        $output .= $entry["attr_value"];
                    }
                    $output .= '</td>';
                }
            }
            $output .= '</tr>';
            if (!empty($group_name)) {
                $last_fname = $group_name;
                $show_fname = '';
                $bgcolor = '';
            }
            # lookup template himself
            if ($item_class == 'template_inheritance') {
                if ($local_template_status === "repetitive") {
                    NConf_DEBUG::set('', 'DEBUG', 'template is repetitive, stopping inheritance to prevent endless loop');
                } else {
                    $template_on_template = db_templates("template_inheritance_direct", $entry["item_id"]);
                    if (!empty($template_on_template)) {
                        //$output .= '<tr><td colspan=2><br><b>directly linked to service</b></td></tr>';
                        $output .= table_output($template_on_template, 'template_inheritance', '', ++$level);
                    }
                }
            }
        }
    }
    return $output;
}
Example #4
0
                // show password
                echo '<td class="color_list1 highlight">&nbsp;' . $password . '</td>';
            } else {
                // Link handling
                if (preg_match('/^http*/', $entry["attr_value"])) {
                    # Link
                    echo '<td class="color_list1 highlight">&nbsp;<a target="_blank"href="' . $entry["attr_value"] . '">' . $entry["attr_value"] . '</a></td>';
                } else {
                    # normal text
                    echo '<td class="color_list1 highlight" style="word-break:break-all;word-wrap:break-word">&nbsp;' . $entry["attr_value"] . '</td>';
                }
            }
            echo '</tr>';
        }
    }
} elseif ($_GET["type"] == "contacts") {
    # Titel
    echo '<tr>
            <td>
                <b>contacts</b>
            </td>
        </tr>
    ';
    $contacts = db_templates("get_linked_item_2", $_GET["id"], "members");
    foreach ($contacts as $contact) {
        echo '<tr>';
        echo '<td class="color_list1 highlight" style="word-break:break-all;word-wrap:break-word">&nbsp;' . $contact["attr_value"] . '</td>';
        echo '</tr>';
    }
}
echo '</table></div>';
Example #5
0
echo '<h2>&nbsp;Clone Service from host ' . $item_name . '</h2>';
echo '
  <br>
    <table>
    ';
echo define_colgroup();
?>
      <tr><td class="middle"><br>services to clone
          </td>
          <td colspan=3>
            <?php 
echo '<input id="host_ID" type="hidden" name="source_host_id" value="' . $host_id . '">';
?>
            <select multiple name="all_services[]" id="services_fromBox">
            <?php 
$services = db_templates("get_services_from_host_id", $host_id);
foreach ($services as $service_id => $service_name) {
    echo '<option value="' . $service_id . '">' . $service_name . '</option>';
}
?>
            </select>

            <select multiple name="destination_service_ids[]" id="services_toBox">
            </select>

            <script type="text/javascript">
            createMovableOptions("services_fromBox","services_toBox",500,145,'Available services','Selected services',"livesearch");
            </script>

            <!-- needed for IE7, otherwise the select will be cut on the bottom -->
            <br>
Example #6
0
 }
 ////
 // Link contactgroups of service with same as his host
 // Link service with same contactgroups as host
 $query = 'SELECT fk_item_linked2
             FROM ItemLinks,ConfigAttrs 
             WHERE id_attr=fk_id_attr
             AND attr_name="contact_groups"
             AND fk_id_item="' . $host_ID . '"
          ';
 $result = db_handler($query, "result", "Link service with same contactgroups as host (select)");
 if ($result) {
     if (mysql_num_rows($result) > 0) {
         while ($contactgroup_ID = mysql_fetch_row($result)) {
             // get contact_groups attr id
             $contact_groups_id = db_templates("get_attr_id", "service", "contact_groups");
             //remove from attrs_visible_yes
             unset($attrs_visible_yes[$contact_groups_id]);
             $query = 'INSERT INTO ItemLinks (fk_id_item,fk_item_linked2,fk_id_attr) 
                         VALUES ( ' . $new_service_ID . '
                                 ,' . $contactgroup_ID[0] . '
                                 ,' . $contact_groups_id . '
                                )
                      ';
             $status = db_handler($query, "insert", "Link service with same contactgroups as host (insert)");
             if ($status) {
                 history_add("assigned", $contact_groups_id, $contactgroup_ID[0], $new_service_ID, "resolve_assignment");
             }
         }
         // END while
     }
     message($debug, 'Successfully linked service ' . $new_service_id . ' to host ' . $new_host_id);
 } else {
     message($error, 'Error linking service ' . $new_service_id . ' to host ' . $new_host_id . ' ' . $query);
 }
 # clone basic data of original service onto new service
 $query = 'INSERT INTO ConfigValues (fk_id_attr,attr_value,fk_id_item)
             SELECT id_attr,attr_value,' . $new_service_id . ' FROM ConfigAttrs,ConfigValues,ConfigItems
                 WHERE id_attr=fk_id_attr
                     AND id_item=fk_id_item
                     AND id_item=' . $service_tpl["fk_id_item"] . '
                 ORDER BY ordering';
 $result = db_handler($query, "insert", "clone basic data of original service onto new service");
 if ($result) {
     # service added
     $service_name = db_templates("naming_attr", $service_tpl["fk_id_item"]);
     $service_name_attr_id = db_templates("get_attr_id", "service", "service_description");
     # created entry
     history_add("created", "service", $service_name, $new_service_id);
     history_add("added", $service_name_attr_id, $service_name, $new_service_id);
     history_add("added", "service", $new_service_id, $new_host_id, "resolve_assignment");
     # HISTORY add :basic data
     $query = 'SELECT id_attr,attr_value FROM ConfigAttrs,ConfigValues,ConfigItems
                     WHERE id_attr=fk_id_attr
                         AND id_item=fk_id_item
                         AND id_item=' . $service_tpl["fk_id_item"] . '
                         AND naming_attr = "no"
                     ORDER BY ordering';
     $basic_entries = db_handler($query, "array", "for history: get basic data");
     foreach ($basic_entries as $entry) {
         history_add("added", $entry["id_attr"], $entry["attr_value"], $new_service_id);
     }
Example #8
0
     $result = db_handler($get_srv_query, "result", "get services linked to host");
     # prepare services
     $services = array();
     while ($entry = mysql_fetch_assoc($result)) {
         $services[] = array("id" => $entry["item_id"], "name" => $entry["attr_value"], "type" => "service");
     }
 }
 # Lookup class and name of item
 $item_class = db_templates("class_name", $id);
 $item_name = db_templates("naming_attr", $id);
 # on service items we want to group it by their associated hostname
 if ($item_class == "service") {
     # service deletions
     # get host name of service
     $hostID = db_templates("hostID_of_service", $id);
     $hostname = db_templates("naming_attr", $hostID);
     # create hostname entrie
     if (!isset($entries[$hostname])) {
         $entries[$hostname] = array("id" => $hostID, "name" => $hostname, "title" => "", "status" => "open");
     }
     # add the service to the host branch
     $services = array("id" => $id, "name" => $item_name, "type" => "service");
     $entries[$hostname]["childs"][] = $services;
 } else {
     # any other deletion:
     if (!empty($services)) {
         # for host trees with services (class = host)
         $entries[] = array("id" => $id, "name" => $item_name, "title" => $item_class . ": ", "status" => "open", "childs" => $services);
     } else {
         # for single (any other) classes
         $entries[] = array("id" => $id, "name" => $item_name, "title" => $item_class . ": ", "type" => $item_class);
Example #9
0
    </style>
    ';
    echo '
    <!-- Load nconf js functions -->
    <script src="include/js/nconf.js" type="text/javascript"></script>
    ';
    echo '<link rel="stylesheet" type="text/css" href="design_templates/' . TEMPLATE_DIR . '/main.css">';
    echo '<div style="text-align: left; margin: 10px; margin-right: auto;">';
    ###
    # Content of nagiosview
    ###
    echo '<div class="dependency_info color_list2">';
    echo '<h2 class="color_list3">Show host parent / child relationships</h2>';
    echo VERSION_STRING . '&nbsp;&nbsp;&nbsp;<a target="_new" href="http://www.nconf.org">www.nconf.org</a>';
    echo '</div>';
    $hostname = db_templates("get_value", $id, "host_name");
    echo '<div style="margin-top:20px; margin-bottom:20px;"><h2>parent / child relationships for host \'' . $hostname . '\'</h2></div>';
    # Show the tree
    if (!empty($id)) {
        generate_tree($id, $xmode);
    }
    echo '</div>';
} else {
    # Normal NConf view
    require_once 'include/head.php';
    // Form action and url handling
    $request_url = set_page();
    /*
        # Get config classes
        #$query = 'SELECT config_class FROM ConfigClasses ORDER BY config_class';
        #$classes = db_handler($query, "array", "Get classes");
Example #10
0
                ConfigValues.fk_id_item AS id,
                attr_value AS entryname,
                (SELECT attr_value
                    FROM ConfigValues,ConfigAttrs
                    WHERE id_attr=fk_id_attr
                        AND attr_name="service_enabled"
                        AND fk_id_item=id) AS service_enabled
                FROM ConfigValues, ConfigAttrs, ConfigClasses, ItemLinks
                WHERE id_attr = ConfigValues.fk_id_attr
                AND naming_attr = "yes"
                AND id_class = fk_id_class
                AND config_class = "advanced-service"
                AND ConfigValues.fk_id_item = ItemLinks.fk_id_item
                AND fk_item_linked2 = ' . $host_id . '
                ORDER BY entryname
             ';
$old_linked_data[$attribute_id] = db_handler($query, "array_direct", "Get advanced-service of host with its service_enabled status");
NConf_DEBUG::set($advanced_services, 'DEBUG', "send items");
$class_id = db_templates("get_id_of_class", "advanced-service");
$name = db_templates("naming_attr", $id);
# history entry status for "edited"
$edited = FALSE;
$handle_action = 'modify';
$items2write = $advanced_services;
# special case for advanced_services !
# items_write2db will look for $advanced_services and use the "bidirection/child" feature, to swap the data
require_once 'include/items_write2db.php';
// needs $items2write
if (!NConf_DEBUG::status('ERROR')) {
    echo '<div id="modify_success">' . $edited . '</div>';
}
Example #11
0
# 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";
               }
               */
            # Destination site should alway be detail.php
            $dest_url = "detail.php";
Example #12
0
        # feedback for clone2hosts
        if ($_POST["action"] == "clone2hosts") {
            $host_name = db_templates("get_value", $destination_host_id, "host_name");
            $host_link = '<a href="modify_item_service.php?id=' . $destination_host_id . '"><span class="link_with_tag">' . $host_name . '</span></a>';
            NConf_DEBUG::set("<i>" . $new_service_name . "</i>", 'INFO', $host_link);
            if (NConf_DEBUG::status('ERROR')) {
                $service_link = '<a href="detail.php?id=' . $new_service_id . '" target="_blank" class="link_with_tag">' . $new_service_name . '</a>';
                NConf_DEBUG::set($service_link, 'ERROR', "failed with service");
            }
        }
    }
    if ($_POST["action"] == "cloneONhost") {
        // give new ID back
        echo '<div id="clone_success">' . $new_service_id . '</div>';
    }
}
# output for clone2hosts
if ($_POST["action"] == "clone2hosts") {
    $source_service_name = db_templates("get_value", $_POST["service_id"], "service_description");
    if (NConf_DEBUG::status('ERROR')) {
        # error
        $feedback = "Failed, see debug for details.";
        echo '<div id="clone_error">' . $feedback;
        echo NConf_DEBUG::show_debug('INFO', TRUE);
        echo '</div>';
    } else {
        $feedback .= 'Successfully cloned to the following hosts:</b><br>';
        $feedback .= NConf_DEBUG::show_debug('INFO', TRUE);
        echo '<div id="clone_success" class="feedback">' . $feedback . '</div>';
    }
}
Example #13
0
                "aoColumns": [
                    null, null, null, null, null, { "bVisible": false }
                    ],
                "fnInitComplete": function() {
                    $('#history_processing').addClass('ui-widget-header');
                    $("#loading").hide();
                    $("#hidden_history").show();
                }
            });


        });
    </script>
    <?php 
    $item_class = db_templates("class_name", $_GET["id"]);
    $item_name = db_templates("naming_attr", $_GET["id"]);
    # Set time seperation (empty row after time-change)
    $time_seperation = TRUE;
    $show_item_links = FALSE;
    # Set title
    $title = 'History of ' . $item_class . ': ' . $item_name;
    if (!empty($_SESSION["go_back_page"])) {
        $detail_navigation = '<a class="button_back jQ_tooltip" title="back" href="' . $_SESSION["go_back_page"] . '"></a>';
    }
    # Expand the titel with filter
    if (!empty($_GET["filter"])) {
        $title .= '<br>--> filtered for <i>' . $_GET["filter"] . '</i>';
    }
} else {
    ?>
    <script type="text/javascript">
Example #14
0
echo '<thead class="ui-state-default">';
echo '<tr>';
if ($class == "service" or $class == "hostgroup_service") {
    echo '<th></th>';
}
echo '<th>' . FRIENDLY_NAME_SERVICES . '</td>';
if ($class == "service") {
    echo '<th colspan="3" class="center">' . FRIENDLY_NAME_ACTIONS . '</td>';
} elseif ($class == "hostgroup_service") {
    echo '<th>' . FRIENDLY_NAME_HOSTGROUP . '</td>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody class="ui-widget-content">';
if ($class == "hostgroup_service") {
    $services = db_templates("hostgroup_services", $host_ID);
} else {
    $query = 'SELECT
                ConfigValues.fk_id_item AS id,
                attr_value AS entryname,
                (SELECT attr_value
                    FROM ConfigValues,ConfigAttrs
                    WHERE id_attr=fk_id_attr
                        AND attr_name="service_enabled"
                        AND fk_id_item=id) AS service_enabled
                FROM ConfigValues, ConfigAttrs, ConfigClasses, ItemLinks
                WHERE id_attr = ConfigValues.fk_id_attr
                AND naming_attr = "yes"
                AND id_class = fk_id_class
                AND config_class = "' . $class . '"
                AND ConfigValues.fk_id_item = ItemLinks.fk_id_item
 # history entry "edited"
 if ($edited) {
     history_add("edited", $config_class, $_POST[$id_naming_attr], $id);
 }
 // this info has a newline (<br>) because other messages are in front
 if (!NConf_DEBUG::status("ERROR")) {
     NConf_DEBUG::set('<br>Successfully modified <b>' . escape_string($_POST[$id_naming_attr]) . '</b>', 'INFO');
 }
 // show infos
 echo NConf_DEBUG::show_debug('INFO', TRUE);
 echo '<br>';
 // inheritance from host to services
 if ($config_class == "host") {
     $name = db_templates("naming_attr", $id);
     # Vererben ?
     $vererben2_result = db_templates("vererben", $id);
     while ($row = mysql_fetch_assoc($vererben2_result)) {
         $vererben2[$row["item_id"]] = $row["attr_name"];
     }
     # Ask for make the changes also to the linked services
     if (!empty($vererben1) and !empty($vererben2) and $vererben1 !== $vererben2) {
         # get preview of possible attributes for inheritance from host to its services
         # user can choose which attributes should inherit (apply) or not
         $preview[$name] = inheritance_HostToService($id, "preview");
         # print in info box
         if (!empty($preview)) {
             echo '<form name="vererben" action="' . $_SERVER["PHP_SELF"] . '" method="post">';
             $update_button = '<input name="HIDDEN_config_class" type="hidden" value="' . $config_class . '">';
             $update_button .= '<input name="HIDDEN_modify_id" type="hidden" value="' . $_POST["HIDDEN_modify_id"] . '">';
             $update_button .= '<br><div id=buttons>';
             $update_button .= '<input type="Submit" value="yes" name="vererben" align="middle">';
 # 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)
                 VALUES
                 (NULL, "' . $class_id . '" )
                 ';
     if (DB_NO_WRITES != 1) {
         $insert = db_handler($query, "insert", "Insert");
         if (!$insert) {
             message($error, 'Error while adding entry to ConfigItems:' . $query);
         }
     }
     if ($insert) {
         # Get ID of insert:
         $id = mysql_insert_id();
         # add item CREATED to history
Example #17
0
         continue;
     } else {
         $insert_attr_value = encrypt_password($attr["value"]);
     }
 } else {
     // modify text/select
     $insert_attr_value = escape_string($attr["value"]);
 }
 # only multimodify:
 if ($handle_action == "multimodify") {
     # check for service name (dublicates are not allowed, so generate an name which is not already used in this host)
     if (isset($items2write[$id_naming_attr]) and $config_class == "service") {
         # check the service name, it should not be the same as the source service
         # get all service names of destination server
         $host_ID = db_templates("hostID_of_service", $id);
         $existing_service_names = db_templates("get_services_from_host_id", $host_ID);
         # when service name does not exist, we can add service with its name
         # otherwise we have to create an other name:
         $new_service_name = $insert_attr_value;
         if (in_array($new_service_name, $existing_service_names)) {
             $service_name_changed = TRUE;
             # create a service name with "_" and a number, until we found a service name which is not used
             $new_service_name = $insert_attr_value . '_';
             $i = 1;
             do {
                 $i++;
                 $try_service_name = $new_service_name . $i;
             } while (in_array($try_service_name, $existing_service_names));
             # found a services name, which does not exist
             $new_service_name = $try_service_name;
         }
Example #18
0
function inheritance_HostToService($host_id, $mode = '')
{
    //NConf_DEBUG::open_group('inheritance for host_id: "'.$host_id.'"', 1);
    # Handling inheritance to services
    # check for host data
    if ($mode == 'apply_inheritance') {
        if (empty($_POST["apply_inheritance"][$host_id])) {
            // continue if service is empty
            NConf_DEBUG::set("not applying for host: " . $host_id, 'DEBUG', 'Inheritance filter');
            return;
        }
    }
    # These services will be modified
    $services = db_templates("get_services_from_host_id", $host_id);
    # array of inherited attributes
    $change_attrs = array("check_period" => "check period", "notification_period" => "notification period", "contact_groups" => "contact groups");
    $class_id = db_templates("get_id_of_class", "service");
    # array for preview functionality
    $preview_array = array();
    # make a diff with each service to detect which items must be linked and which must be removed
    foreach ($services as $service_id => $service_name) {
        NConf_DEBUG::open_group('inheritance for service: "' . $service_name . '"', 1);
        # initial value for history entry "edited"
        $edited = FALSE;
        $preview_array[$service_name] = array();
        if ($mode == 'apply_inheritance') {
            if (empty($_POST["apply_inheritance"][$host_id][$service_id])) {
                // continue if service is empty
                NConf_DEBUG::set("not applying for service: " . $service_name, 'DEBUG', 'Inheritance filter');
                continue;
            }
        }
        foreach ($change_attrs as $change_attr => $change_attr_friendly_name) {
            NConf_DEBUG::open_group("attribute: " . $change_attr_friendly_name, 2);
            if ($mode == 'apply_inheritance' and empty($_POST["apply_inheritance"][$host_id][$service_id][$change_attr])) {
                // continue if service is empty
                NConf_DEBUG::set("not applying for attribute: " . $change_attr_friendly_name, 'DEBUG', 'Inheritance filter');
                continue;
            }
            NConf_DEBUG::open_group("lookup values", 3);
            $attr_id = db_templates("get_attr_id", "service", $change_attr);
            # get current host data
            $new_items = db_templates("get_linked_item", $host_id, $change_attr, '', 'array_2fieldsTOassoc');
            # get current service data
            $current_items = db_templates("get_linked_item", $service_id, $change_attr, '', 'array_2fieldsTOassoc');
            # diff to get items to add
            $diff_array = array_diff($new_items, $current_items);
            # diff to get items to remove
            $diff_array2 = array_diff($current_items, $new_items);
            /* debugging:
               echo "<pre>";
               var_dump($diff_array);
               var_dump($diff_array2);
               echo "</pre>";
               */
            if ($mode == "preview") {
                $preview_array[$service_id]["service_name"] = $service_name;
                $preview_array[$service_id]["attrs"][$attr_id] = array("attr_name" => $change_attr, "attr_friendly_name" => $change_attr_friendly_name, "current" => $current_items, "new" => $new_items, "differs" => !empty($diff_array) or !empty($diff_array2));
                //                $preview_array[$service_id]["attrs"][$attr_id]["differs"] = (!empty($diff_array) OR !empty($diff_array2) );
            } else {
                # make changes in the DB
                // until now, there are no such special attributes:
                //$lac_OR_bidirectional = check_link_as_child_or_bidirectional($change_attr, $class_id);
                // perhaps later there must also be this logic.
                # remove items
                if (!empty($diff_array2)) {
                    NConf_DEBUG::open_group("remove items");
                    foreach ($diff_array2 as $attr_removed_name => $attr_removed_id) {
                        $query = 'DELETE FROM ItemLinks
                                    WHERE fk_id_item=' . $service_id . '
                                        AND fk_id_attr = "' . $attr_id . '"
                                        AND fk_item_linked2 = "' . $attr_removed_id . '"
                                 ';
                        db_handler($query, "delete", 'delete linked item "' . $attr_removed_name . '"');
                        history_add("unassigned", $change_attr_friendly_name, $attr_removed_name, $service_id);
                        $edited = TRUE;
                    }
                }
                # add items
                if (!empty($diff_array)) {
                    NConf_DEBUG::open_group("add items");
                    foreach ($diff_array as $attr_add_name => $attr_add_id) {
                        $query = 'INSERT INTO ItemLinks (fk_id_item,fk_item_linked2,fk_id_attr)
                                    VALUES (' . $service_id . ',' . $attr_add_id . ', ' . $attr_id . ')';
                        db_handler($query, "insert", 'insert linked item "' . $attr_add_name . '"');
                        history_add("assigned", $change_attr_friendly_name, $attr_add_name, $service_id);
                        $edited = TRUE;
                    }
                }
            }
        }
        NConf_DEBUG::close_group(2);
        //NConf_DEBUG::open_group('history "edited" entry', 1);
        # history entry "edited"
        if ($mode == "preview") {
            # clean service if nothing will change
            if (empty($preview_array[$service_name])) {
                unset($preview_array[$service_name]);
            }
        } elseif ($edited) {
            history_add("edited", "service", $service_name, $service_id);
        }
    }
    if ($mode == "preview") {
        # print preview
        # create a table with checkboxes for applying inheritance
        $preview = NConf_HTML::table_begin('class="ui-nconf-table ui-widget ui-widget-content ui-nconf-max-width"', array('', 50, 120, 100, 100));
        $preview .= '<thead class="ui-widget-header">
                      <tr>
                        <th>service</th>
                        <th name="checkbox_toggle_all" class="center pointer">update</th>
                        <th>attribute</th>
                        <th>service value</th>
                        <th>host value</th>
                      </tr>
                     </thead>';
        $bg_class = "even";
        foreach ($preview_array as $service_id => $service) {
            $i = 0;
            $service_name = $service["service_name"];
            # handle background for each service
            if ($bg_class == "odd") {
                $bg_class = "even";
            } else {
                $bg_class = "odd";
            }
            foreach ($service["attrs"] as $attribute_id => $values) {
                $i++;
                $preview .= '<tr class="' . $bg_class . '">';
                if ($i == 1) {
                    $preview .= '<td rowspan="' . count($service["attrs"]) . '" class="align_top">' . NConf_HTML::title($service_name) . '</td>';
                }
                # check box for applying
                $preview .= '<td class="center">';
                if ($values["differs"]) {
                    $preview .= '<input type="checkbox" class="pointer" name="apply_inheritance[' . $host_id . '][' . $service_id . '][' . $values["attr_name"] . ']" value="' . $attribute_id . '" checked=checked>';
                }
                $preview .= '</td>';
                $preview .= '<td>' . $values["attr_friendly_name"] . '</td>';
                # current values
                $preview .= '<td name="checkbox_toggle"';
                // color red
                if ($values["differs"]) {
                    $preview .= ' class="red"';
                }
                $preview .= '>';
                # generate value list
                $current_values = array_flip($values["current"]);
                $preview .= implode(", ", $current_values);
                $preview .= "</td>";
                # new values
                $preview .= '<td name="checkbox_toggle"';
                // color green
                if ($values["differs"]) {
                    $preview .= ' class="bold"';
                }
                $preview .= '>';
                # generate value list
                $new_values = array_flip($values["new"]);
                $preview .= implode(", ", $new_values);
                $preview .= "</td>";
                $preview .= "</tr>";
            }
        }
        $preview .= NConf_HTML::table_end();
        return $preview;
    } elseif (!NConf_DEBUG::status('ERROR') and $mode != "preview") {
        NConf_DEBUG::set('', 'INFO', 'Successfully updated all linked services.');
    }
    return;
}
                attr_value AS service_name,
                ( SELECT attr_value
                    FROM ConfigValues, ConfigAttrs
                    WHERE ConfigValues.fk_id_attr = ConfigAttrs.id_attr
                    AND attr_name = "service_description"
                    AND ConfigValues.fk_id_item = id_item ) AS service_description
                FROM ConfigItems,ConfigValues,ConfigAttrs,ConfigClasses
                WHERE id_item=fk_id_item
                    AND id_attr=fk_id_attr
                    AND naming_attr="yes"
                    AND ConfigItems.fk_id_class=id_class
                    AND config_class="advanced-service"
                ORDER BY service_name ASC';
$service_names = db_handler($query, "array", "get all advanced services");
$output .= '<br><select id="fromBox_advanced_services" name="from_advanced_services[]" style="' . CSS_SELECT_MULTI . '" multiple >';
$services = db_templates("get_services_from_host_id", $host_ID, "advanced-service");
foreach ($service_names as $advanced_service) {
    // Title attribute is needed for later name conflict checks(over jQuery)
    // First set the title attribute to the service name
    $advanced_service["title"] = $advanced_service["service_name"];
    // compare service_name with service_description
    if (!empty($advanced_service["service_description"]) and $advanced_service["service_name"] != $advanced_service["service_description"]) {
        // display the description in brackets behind the service name
        $advanced_service["service_name"] = $advanced_service["service_name"] . ' (' . $advanced_service["service_description"] . ')';
        // Override service title with service description, which is needed for later conflict checks
        $advanced_service["title"] = $advanced_service["service_description"];
    }
    // move already selected items
    if (array_key_exists($advanced_service["id_item"], $services)) {
        $selected_items[] = $advanced_service;
        continue;