public function command($host_info) { $CONF_DEPLOY_URL = $host_info["host"]; $CONF_DEPLOY_USER = !empty($host_info["user"]) ? $host_info["user"] : ''; $CONF_DEPLOY_PWD = !empty($host_info["password"]) ? $host_info["password"] : ''; $REMOTE_EXECUTE = !empty($host_info["remote_execute"]) ? $host_info["remote_execute"] : ''; $REMOTE_ACTION = !empty($host_info["remote_action"]) ? $host_info["remote_action"] : ''; $post_data = array(); $post_data['file'] = '@' . $host_info["source_file"]; $post_data['remote_execute'] = $REMOTE_EXECUTE; $post_data['remote_action'] = $REMOTE_ACTION; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $CONF_DEPLOY_URL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (!empty($CONF_DEPLOY_USER) and !empty($CONF_DEPLOY_PWD)) { curl_setopt($ch, CURLOPT_USERPWD, $CONF_DEPLOY_USER . ":" . $CONF_DEPLOY_PWD); } $postResult = curl_exec($ch); if ($postResult === false) { $curl_error = 'Curl-Error: ' . curl_error($ch); if (!curl_errno($ch)) { $info = curl_getinfo($ch); $curl_error .= "<br>" . $info["http_code"]; } } curl_close($ch); if ($postResult == "OK") { return TRUE; } else { if (!empty($postResult)) { NConf_HTML::set_info(NConf_HTML::table_row_check('', 'FAILED', $postResult), 'add'); } if (!empty($curl_error)) { NConf_HTML::set_info(NConf_HTML::table_row_check('', 'FAILED', $curl_error), 'add'); } return FALSE; } }
public function run_deployment() { if (!ALLOW_DEPLOYMENT) { echo NConf_HTML::limit_space(NConf_HTML::show_error('ERROR', 'Deployment functionality is currently disabled.')); } elseif (ALLOW_DEPLOYMENT && (!ALLOW_DIRECT_DEPLOYMENT && empty($_POST["status"]))) { echo NConf_HTML::limit_space(NConf_HTML::show_error('ERROR', 'Please first run the "Generate Nagios config".')); } elseif (ALLOW_DEPLOYMENT && ALLOW_DIRECT_DEPLOYMENT || ALLOW_DEPLOYMENT && (!ALLOW_DIRECT_DEPLOYMENT && (!empty($_POST["status"]) && $_POST["status"] == "OK"))) { echo NConf_HTML::table_begin('class="table_checks"', array(170, 50, '')); // DEPLOY // First do the local module $local_module = $this->modules["local"]; if ($local_module->configured()) { NConf_DEBUG::set('', 'DEBUG', 'Deploying ' . $local_module->name); echo NConf_HTML::table_row_text(NConf_HTML::title($local_module->name, '', 'class="content_header"')); NConf_DEBUG::set($local_module->destinations, 'DEBUG', $local_module->name); $local_module->deploy(); echo NConf_HTML::table_row_text(NConf_HTML::line(), '', 'colspan=3'); } // Then do all other modules if they are configured foreach ($this->modules as $module) { // Dont do the "local" module // Check also if module is configured if ($module->name == "local" or !$module->configured()) { continue; } NConf_DEBUG::set('', 'DEBUG', 'Deploying ' . $module->name); echo NConf_HTML::table_row_text(NConf_HTML::title($module->name, '', 'class="content_header"')); NConf_DEBUG::set($module->destinations, 'DEBUG', $module->name); // run the deploy $module->deploy(); echo NConf_HTML::table_row_text(NConf_HTML::line(), '', 'colspan=3'); } echo NConf_HTML::table_end(); } else { echo NConf_HTML::text('Deployment is enabled, but your configuration seems to have errors.', TRUE, 'div', 'class="attention"'); } }
//set_page(); # Get ID if (!empty($_REQUEST["id"])) { $id = $_REQUEST["id"]; } else { NConf_DEBUG::set("No id", 'ERROR'); } #determine if class or attribute if (!empty($_REQUEST["type"])) { $type = $_REQUEST["type"]; } else { NConf_DEBUG::set("This type does not exist", 'ERROR'); } // end / exit page if error if (NConf_DEBUG::status('ERROR')) { echo NConf_HTML::exit_error(); } if ($type == "class") { ######################################## ## configure user friendly names here ## ######################################## $user_friendly_names = array("id_attr" => "Attribute ID", "id_class" => "Class ID", "attr_name" => "Nagios-specific attribute name", "config_class" => "Nagios-specific class name", "friendly_name" => "Friendly name (shown in GUI)", "description" => "description, example or help-text", "datatype" => "Data type", "max_length" => "max. text-field length (chars)", "poss_values" => "Possible values", "predef_value" => "Predefined value", "mandatory" => "Is attribute mandatory", "ordering" => "Ordering position", "nav_visible" => "Is Class visible in Navigation", "visible" => "Is attribute visible", "write_to_conf" => "write attribute to configuration", "naming_attr" => "naming attribute", "link_as_child" => "link selected item(s) as children", "fk_show_class_items" => "items of class to be assigned", "fk_id_class" => "attribute belongs to class", "grouping" => "Navigation Group", "nav_links" => "Configure Links", "nav_privs" => "Viewable by", "out_file" => "generated filename", "nagios_object" => "Nagios object definition"); ######################################## ######################################## $HTTP_referer = 'show_class.php'; #query $query = 'SELECT * FROM ConfigClasses WHERE id_class = ' . $id; } elseif ($type == "attr") { ######################################## ## configure user friendly names here ## ########################################
} } } # get also the debug informations if ($debug == 'yes' and $json == 'no') { $title = 'Load file "' . $file_path . '" @ ' . date("H:i:s"); // set ERROR if (NConf_DEBUG::status('ERROR')) { echo '<div id="ajax_error">'; echo NConf_DEBUG::show_debug('ERROR', TRUE); echo '</div>'; } // set DEBUG if (NConf_DEBUG::status('DEBUG')) { echo '<div id="ajax_debug">'; echo NConf_HTML::swap_content(NConf_DEBUG::show_debug('DEBUG', TRUE), $title, FALSE, FALSE, 'color_list3'); echo '</div>'; } if (!empty($ajax) and $ajax == 'yes') { ?> <!-- jQuery part --> <script type="text/javascript"> $(document).ready(function(){ // fetch ERROR part and give to footer and display it $("#jquery_error").append( $("#ajax_error") ); $("#ajax_error").parent("#jquery_error").show("blind"); // fetch DEBUG part and give to footer (will be displayed if debug is enabled) $("#ajax_debug").prependTo( $("#jquery_console") ); $("#jquery_console_parent").fadeIn("slow"); });
}); </script> <?php echo NConf_HTML::ui_box_header("Configuration Deployment"); echo NConf_HTML::ui_box_content(); echo '<div style="height: 20px;"> <div id="loading"> <img src="img/working_small.gif"> in progress... </div> </div>'; // Load deployment class and create object require_once "class.deployment.php"; require_once "class.deployment.modules.php"; // Load the NConf Deployment class // It loads all the modules and handles the deployment basic stuff $deployment = new NConf_Deployment(); // Loads the configuration of the user // nconf/conf/deployment.ini $deployment->import_config(); if (NConf_DEBUG::status('ERROR')) { // Show error if set echo NConf_HTML::limit_space(NConf_HTML::show_error()); } else { // Start deploying the files $deployment->run_deployment(); } echo '</div>';
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; }
} else { $table .= '<tr class="color_list2 highlight ' . $additional_class . '">'; } $table .= '<td>' . $ICON_datatype . '</td>'; $table .= '<td>' . $pre . '<a href="detail_admin_items.php?type=attr&class=' . $class . '&id=' . $entry["id_attr"] . '">' . $entry["attr_name"] . '</a>' . $fin . '</td>'; $table .= '<td>' . $pre . $entry["friendly_name"] . $fin . '</td>'; $table .= '<td>' . $pre . $entry["datatype"] . $fin . '</td>'; $table .= '<td align="center"><div align=center>' . $ICON_mandatory . '</div></td>'; // Ordering is good for debbuging //$table .= '<td>'.$pre.$entry["ordering"].$fin.'</td>'; $table .= '<td class="center">' . $pre; $table .= '<a href="show_attr.php?class=' . $class . '&id=' . $entry["id_attr"] . '&do=up">' . ICON_UP_BOX_BLUE . '</a>'; $table .= ' '; $table .= '<a href="show_attr.php?class=' . $class . '&id=' . $entry["id_attr"] . '&do=down">' . ICON_DOWN_BOX_BLUE . '</a>'; $table .= $fin . '</td>'; $table .= '</td>'; $table .= '<td align="center"><div align=center>' . $naming_attr_cell . '</div></td>'; $table .= '<td style="text-align:center"><a href="modify_attr.php?id=' . $entry["id_attr"] . '">' . ICON_EDIT . '</a></td>'; $table .= '<td style="text-align:center"><a href="delete_attr.php?id=' . $entry["id_attr"] . '">' . ICON_DELETE . '</a></td>'; $table .= "</tr>\n"; $count++; } // Warn if there is no naming attribute if ($naming_attr_count == 0) { message($info, TXT_NAMING_ATTR_MISSED); } } $table .= '</tbody>'; echo NConf_HTML::ui_table($table, 'ui-nconf-max-width'); mysql_close($dbh); require_once 'include/foot.php';
public function command($host_infos) { // check source $status = ''; if (!file_exists($host_infos["source_file"])) { NConf_HTML::set_info(NConf_HTML::table_row_check('source_file', 'FAILED', 'Source file does not exist (' . $host_infos["source_file"] . ')'), 'add'); $status = FALSE; } if (substr($host_infos["target_file"], -1) == "/" or is_dir($host_infos["source_file"])) { // force target directory if source is directory $dirname = dirname($host_infos["target_file"] . '/.'); } else { // get dirname $dirname = dirname($host_infos["target_file"]); } // check target directory if (!file_exists($dirname)) { if (!is_dir($dirname)) { $structure = $dirname; // create directory $status = mkdir($structure, 0775, true); NConf_HTML::set_info(NConf_HTML::table_row_check('PHP mkdir:', $status, 'Create target directory (' . $dirname . ')'), 'add'); } // check target again if (!is_dir($dirname)) { NConf_HTML::set_info(NConf_HTML::table_row_check('target_file', 'FAILED', 'Target directory does not exist, or permissions denied (' . $dirname . ')'), 'add'); $status = FALSE; } } // break, if status already is FALSE if ($status === FALSE) { return $status; } // check action if (empty($host_infos["action"])) { NConf_HTML::set_info(NConf_HTML::table_row_check('action', 'FAILED', 'action is not defined, read documentation for details.'), 'add'); } elseif ($host_infos["action"] == "extract") { #$target_file_tgz = $dirname.'/'.basename($host_infos["source_file"]); #$target_file_tar = $dirname.'/'.basename($host_infos["source_file"], ".tgz").'.tar'; $target_file_tgz = $host_infos["target_file"] . basename($host_infos["source_file"]); $target_file_tar = $host_infos["target_file"] . basename($host_infos["source_file"], ".tgz") . '.tar'; // copy $status = copy($host_infos["source_file"], $target_file_tgz); NConf_HTML::set_info(NConf_HTML::table_row_check('PHP copy:', $status, 'temporary copy(' . $host_infos["source_file"] . ', ' . $target_file_tgz . ')'), 'add'); // gunzip $status = $this->system_call($this->gunzip . ' ' . $target_file_tgz); // tar $tar_command = $this->tar; if (!empty($host_infos["options"])) { $tar_command .= ' ' . $host_infos["options"]; } else { $tar_command .= ' -xf'; } $tar_command .= ' ' . $target_file_tar; $tar_command .= ' -C ' . $host_infos["target_file"]; $status = $this->system_call($tar_command); // remove gunzip'ed file // no "$status =" because it doesn't matter when this fails $status_unlink = unlink($target_file_tar); NConf_HTML::set_info(NConf_HTML::table_row_check('PHP unlink:', $status_unlink, ' remove temporary file(' . $target_file_tar . ')'), 'add'); } elseif ($host_infos["action"] == "copy") { if (!empty($host_infos["source_file"]) && !empty($host_infos["target_file"])) { if (is_dir($host_infos["source_file"])) { // handle/copy directories $status = $this->recursive_copy($host_infos["source_file"], $host_infos["target_file"]); NConf_HTML::set_info(NConf_HTML::table_row_check('PHP copy:', $status, 'recursive copy(' . $host_infos["source_file"] . ', ' . $host_infos["target_file"] . ')'), 'add'); } else { // copy single file if (!copy($host_infos["source_file"], $host_infos["target_file"])) { $status = FALSE; } else { $status = TRUE; } NConf_HTML::set_info(NConf_HTML::table_row_check('PHP copy:', $status, 'copy(' . $host_infos["source_file"] . ', ' . $host_infos["target_file"] . ')'), 'add'); } } else { return FALSE; } } elseif ($host_infos["action"] == "move") { if (!empty($host_infos["source_file"]) && !empty($host_infos["target_file"])) { // rename file or directory $status = rename($host_infos["source_file"], $host_infos["target_file"]); NConf_HTML::set_info(NConf_HTML::table_row_check('PHP rename:', $status, 'rename(' . $host_infos["source_file"] . ', ' . $host_infos["target_file"] . ')'), 'add'); } else { return FALSE; } } // reload nagios/icinga ? if ($status && !empty($host_infos["reload_command"])) { if (is_array($host_infos["reload_command"])) { // predefine status to unknown $status = "UNKNOWN"; foreach ($host_infos["reload_command"] as $command) { $command_status = $this->system_call($command); if (!$command_status) { // command failed $status = FALSE; } elseif ($command_status) { // only make true if status was not already false (previouse command failed) if ($status != FALSE) { $status = TRUE; } } } } else { $status = $this->system_call($host_infos["reload_command"]); } } return $status; }
protected function system_call($command_list, $success_output = FALSE) { $output = array(); # if command is an array of commands if (is_array($command_list)) { $command = ''; $count = 0; foreach ($command_list as $command_part) { if ($count > 0) { $command .= " && "; } $command .= escapeshellcmd($command_part); $count++; } NConf_DEBUG::set($command, 'DEBUG', "finished command"); } else { // escape for security reason $command = escapeshellcmd($command_list); } // execute $status = exec($command, $output, $retval); if ($retval == 0) { // success NConf_HTML::set_info(NConf_HTML::table_row_check('system call', 'OK', $command), 'add'); NConf_HTML::set_info(NConf_HTML::table_row_check('', '', $output), 'add'); if ($success_output) { return $output; } else { return TRUE; } } else { // failed // add some informations NConf_HTML::set_info(NConf_HTML::table_row_check('system call', 'FAILED', $command), 'add'); // no other way worked to get the error message: if (empty($output)) { $out = shell_exec("{$command} 2> " . NCONFDIR . "/temp/output"); // file to array $output = $out ? $out : file(NCONFDIR . "/temp/output"); } NConf_HTML::set_info(NConf_HTML::table_row_check('', '', $output), 'add'); NConf_DEBUG::set($output, 'DEBUG', $command); return FALSE; } }
echo '<br>'; echo '<div>'; echo '<button id="clone" class="ui-buttonset">clone services</button>'; /* echo '<a id="clone" href="#"> clone services </a>';*/ if (!empty($_SESSION["go_back_page"])) { $link = $_SESSION["go_back_page"]; } else { $link = "index.php"; } echo '<a id="continue" href="' . $link . '">continue</a>'; echo '<br><br>'; echo '<div id="clone_error" style="display: none;">'; echo NConf_HTML::show_error('Error:', '<span id="clone_error_content"></span>'); echo '</div>'; echo '<div id="feedback" style="display: none;">'; echo '<div style="width: 300px">'; echo '<h2>Progress:</h2>'; echo '<div> <div id="progressbar"></div> </div>'; echo '<div style="float: left">0%</div>'; echo '<div style="float: right">100%</div>'; echo '</div>'; echo '<div style="clear: both;"></div>'; echo '<br><h2 class="ui-nconf-header ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix">Feedback:</h2>'; echo '<div id="clone_feedback" class="ui-nconf-content ui-widget-content ui-corner-bottom" style="display: none;"></div>'; echo '</div>'; echo '
// set list color if ($row_warn == 1) { $box_content .= '<tr class="color_warning highlight">'; } elseif ((1 & $count) == 1) { $box_content .= '<tr class="odd highlight ' . $additional_class . '">'; } else { $box_content .= '<tr class="even highlight ' . $additional_class . '">'; } $detail_link = '<a href="detail_admin_items.php?type=class&id=' . $entry["id_class"] . '">' . $entry["config_class"] . '</a>'; $detail_link_friendly_name = '<a href="detail_admin_items.php?type=class&id=' . $entry["id_class"] . '">' . $entry["friendly_name"] . '</a>'; $box_content .= '<td class="">'; $box_content .= $detail_link; $box_content .= '</td>'; $box_content .= '<td>' . $detail_link_friendly_name . '</td>'; $box_content .= '<td class="center">' . $ICON_mandatory . '</td>'; $box_content .= '<td class="center">' . '<a href="show_class.php?id=' . $entry["id_class"] . '&do=up">' . ICON_UP_BOX_BLUE . '</a></td>'; $box_content .= '<td class="center">' . '<a href="show_class.php?id=' . $entry["id_class"] . '&do=down">' . ICON_DOWN_BOX_BLUE . '</a>' . '</td>'; $box_content .= '<td class="center"><a href="modify_class.php?id=' . $entry["id_class"] . '">' . ICON_EDIT . '</a></td>'; $box_content .= '<td class="center"><a href="delete_class.php?id=' . $entry["id_class"] . '">' . ICON_DELETE . '</a></td>'; $box_content .= "</tr>\n"; $count++; } // show content box echo NConf_HTML::ui_box_content(NConf_HTML::ui_table($box_content)); } echo '<br>'; } // End of nav_tree echo '</div>'; mysql_close($dbh); require_once 'include/foot.php';
public function setURL($URL, $REGEX_OPEN_END = TRUE, $GROUPS = array(), $REQUEST = array()) { # do not check if already allowed if ($this->url_check_status == TRUE) { return; } # check URL for passed attributes (should only be the scriptname) # the navigation links will need this handler # search for query part in URL # TODO: check if ampersand can be optimized on xmode views: # Array( # [class] => contact # [amp;xmode] => pikett # ) # perhaps using $_SERVER['QUERY_STRING'] ? if (strpos($URL, "?") !== FALSE) { $url_parsed = parse_url($URL); $this->debug .= NConf_HTML::swap_content($url_parsed, "ACL - Found query in URL : Parsing URL", FALSE, TRUE); # get request items parse_str($url_parsed["query"], $REQUEST); $this->debug .= NConf_HTML::swap_content($REQUEST, "ACL - fetched query and converted to REQUEST array", FALSE, TRUE); # override URL with correct scriptname $URL = $url_parsed["path"]; } # check group permission if (empty($GROUPS) or in_array($this->group, $GROUPS)) { if ($REGEX_OPEN_END) { if (!preg_match('/^' . preg_quote($URL) . '\\w*/', $this->current_script)) { return; } } else { if (!preg_match('/^' . preg_quote($URL) . '$/', $this->current_script)) { return; } } $this->debug .= NConf_HTML::text("URL matched: {$URL}", TRUE); # check for request limitations if (!empty($REQUEST)) { # check if needed request items match $diff = array_diff($REQUEST, $_REQUEST); if (!empty($diff)) { # for debugging these could be grouped together $this->debug .= NConf_HTML::swap_content($REQUEST, "REQUEST items do not match", FALSE, TRUE); return; } else { $this->debug .= NConf_HTML::swap_content($REQUEST, "REQUEST items matched", FALSE, TRUE); } //NConf_DEBUG::set($REQUEST, 'DEBUG', "REQUEST matched"); } # all checks passed, URL is fine $this->url_check_status = TRUE; return; } }
$class = $_GET["class"]; }elseif ( !empty($_POST["class"]) ) { $class = $_POST["class"]; }else{ $class = $classes[0]; } } */ ### # Info/Warning in the top right corner ### echo '<h2 style="margin-right:4px">Show host parent / child relationships</h2>'; echo ' <div class="editor_info">'; $content = 'This view allows you to graphically browse your host\'s parent / child relationships.'; echo NConf_HTML::show_highlight('Info', $content); echo '</div>'; echo '<form name="editor" action="dependency.php" method="post"> <fieldset class="inline ui-widget-content"> <legend>choose a host</legend> <table>'; ### # List class and items ### /* echo '<tr>'; echo '<td>Class</td>'; echo '</tr>'; echo '<tr><td><select name="class" style="width:192px" onchange="document.editor.id.value=\'\'; document.editor.submit()">'; //echo '<option value="">'.SELECT_EMPTY_FIELD.'</option>'; foreach($classes as $class_item){
### echo '<h2>Edit static config files</h2>'; echo '<div class="editor_info">'; if (NConf_DEBUG::status('ERROR')) { $title = 'WARNING'; $content = NConf_DEBUG::show_debug('ERROR', TRUE); $content .= '<br>The webserver user must have write permissions for your config directory, <br>otherwise NConf cannot save your changes.'; echo NConf_HTML::show_error($title, $content); } elseif (NConf_DEBUG::status('INFO') and !empty($saved)) { $title = 'Successfully saved file'; $content = ICON_TRUE . NConf_DEBUG::show_debug('INFO', TRUE); echo NConf_HTML::show_highlight($title, $content); } else { $title = 'Info'; $content = 'This mask allows administrators to modify static Nagios configuration files.'; echo NConf_HTML::show_highlight($title, $content); } echo '</div>'; echo '<form name="editor" action="' . $request_url . '" method="post"> <fieldset class="inline"> <legend>choose a file</legend> <table> <colgroup> <col width="70"> <col> </colgroup> '; ### # List directories and files for editing ###
$update_button .= '<input type="Submit" value="yes" name="vererben" align="middle">'; $update_button .= ' <input type=button name="no" onClick="window.location.href=\'' . $_SESSION["go_back_page_ok"] . '\'" value="no">'; $update_button .= '</div>'; echo NConf_HTML::limit_space(NConf_HTML::show_highlight('Attention', TXT_UPDATE_SERVICES . '<br>' . $update_button)); echo "<br>"; # show inheritance tables echo '<div style="float: left; margin-right: 5px;">'; echo NConf_HTML::title('Show detailed inheritance information'); echo '</div>'; echo '<div name="help_inheritance"></div>'; echo '<div style="clear: both"></div>'; echo '<div id="page_content"></div>'; $inheritance_details = ''; foreach ($preview as $server_name => $service_table) { $title = '<span class="ui-icon ui-icon-triangle-1-e"></span><a href="#">' . $server_name . '</a>'; $inheritance_details .= NConf_HTML::title($title, 3, 'class="accordion_title ui-accordion-header ui-helper-reset ui-state-default"'); $inheritance_details .= '<div class="accordion_content" style="display:none;">' . $service_table . '</div>'; } # print tables echo '<div class="ui-accordion ui-widget ui-helper-reset ui-accordion-icons">'; echo $inheritance_details; echo '</div>'; echo '</form>'; } } # Finish button if no action was failed and ask_vererben is not true if (!$ask_vererben and empty($info_summary["failed"]) and (!empty($info_summary["ignored"]) or !empty($info_summary["ok"]))) { // Finish button echo '<br><br>'; echo '<button onClick="window.location.href=\'' . $_SESSION["go_back_page_ok"] . '\'">Finish</button>'; }
echo NConf_HTML::title("Info:", 2); echo NConf_DEBUG::show_debug("INFO"); echo NConf_HTML::line(); } // Display jQuery/ajax errors echo '<div id="jquery_error" class="ui-state-error" style="display: none">'; echo '<span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"> </span>'; echo NConf_HTML::title("Error:", 2); echo '</div>'; if (NConf_DEBUG::status("ERROR")) { echo NConf_HTML::title("Error:", 2); echo '<font color="red">'; echo NConf_DEBUG::show_debug("ERROR"); echo '</font>'; echo NConf_HTML::line(); } if (DEBUG_MODE == 1) { echo '<div id="jquery_console_parent" style="padding: 0; display: none">'; echo NConf_HTML::swap_content('<div id="jquery_console"></div>', "<b>jQuery debugging</b>", FALSE, FALSE); echo '</div>'; NConf_DEBUG::display(); } ?> </div> </div> <!-- END OF DIV "footer" --> </body> </html>
if (constant("VERSION_NOT_FINAL_WARNING") !== '') { echo "<br>"; echo NConf_HTML::limit_space(NConf_HTML::show_error('Attention', VERSION_NOT_FINAL_WARNING)); } # new nconf version info if (defined('CHECK_UPDATE') and CHECK_UPDATE == 1 and $_SESSION["group"] == "admin") { echo '<script src="include/js/jquery_plugins/jquery.nconf_check_update.js" type="text/javascript"></script>'; echo js_prepare(' $(document).ready(function(){ $.nconf_check_update("' . VERSION_NUMBER . '"); }); '); # html container echo "<br>"; echo '<div id="check_update" style="display:none">'; echo NConf_HTML::limit_space(NConf_HTML::show_highlight('<span id="check_update_title"></span>', '<div id="check_update_content"></div>')); echo '</div>'; } echo "<br>" . DISCLAIMER_STRING . "<br><br>"; echo POWERED_BY_LOGOS; } else { # This will be displayed on the login screen echo "<br><br>" . POWERED_BY_LOGOS; } ?> </td> </tr> </table> </td> </tr> </table>
# Try to logon user to ldap $ldap_user_dn = str_replace(USER_REPLACEMENT, $user_loginname, BASE_DN); NConf_DEBUG::set($ldap_user_dn, 'DEBUG', 'ldap user dn'); $user_pwd = $_POST["password"]; $ldap_response = @ldap_bind($ldapconnection, $ldap_user_dn, $user_pwd); if ($ldap_response and $user_loginname and $user_pwd) { NConf_DEBUG::set("success", 'DEBUG', 'ldap bind'); # If user login was successfull, look for group # admins are in group : ADMIN_GROUP # normal nconf user are in group : USER_GROUP # all other do not have access # AdminUsers $sr = ldap_search($ldapconnection, GROUP_DN, ADMIN_GROUP); $results = ldap_get_entries($ldapconnection, $sr); # debug $debug_entry = NConf_HTML::swap_content($results, "<b>LDAP</b> ldap_get_entries:", FALSE, FALSE); message($debug, $debug_entry); $Admin_user_array = $results[0]["memberuid"]; # remove field count unset($Admin_user_array["count"]); # BasicUsers $sr = ldap_search($ldapconnection, GROUP_DN, USER_GROUP); $results = ldap_get_entries($ldapconnection, $sr); $Basic_user_array = $results[0]["memberuid"]; # remove field count unset($Basic_user_array["count"]); # Users Infos $justthese = array("cn"); //$justthese = array("cn", "description", "uid"); $sr = ldap_read($ldapconnection, $ldap_user_dn, "(objectclass=*)", $justthese); $results = ldap_get_entries($ldapconnection, $sr);
} } } } # close template inheritance $output .= '</table>'; $output .= '</div>'; # template cache debug NConf_DEBUG::set($template_cache, 'DEBUG', "template cache"); NConf_DEBUG::close_group(); #print the template inheritace box echo NConf_HTML::ui_box_header('Template inheritance'); if (count($template_cache) == 0) { $output = 'no templates inherited'; } echo NConf_HTML::ui_box_content($output); } echo '</div>'; /* commented out because we do not want to group the different link types we want all linked items in one group if we want to change that, we have to get all normal types, and then group the child or bidirectionals as follows: # get entries linked as child $result = db_templates("linked_as_child", $_GET["id"], "link_as_child"); table_output($result, $item_class, "Child items linked"); # get bidirectional entries $result = db_templates("linked_as_child", $_GET["id"], "link_bidirectional"); table_output($result, $item_class, "Bidirectional items"); */ function table_output($result, $item_class = '', $title = '', $level = 0) {
if ($deployment_info) { $content = 'The generated configuration has been written to the "nconf/output/" directory.<br> To set up more sophisticated deployment functionality, please edit your "config/deployment.ini" file accordingly.<br> For a complete list of available deployment options, refer to the online documentation on <a href="http://www.nconf.org" target="_blank">www.nconf.org</a>.'; system("bash /var/www/nconf/ADD-ONS/deploy_local.sh"); echo NConf_HTML::limit_space(NConf_HTML::show_highlight('Note', $content)); } else { // Show deployment button echo "<form method=\"POST\" action=\"call_file.php?module_file=deployment/main.php\" id=buttons>"; echo '<input type=hidden name=status value="' . $status . '">'; echo '<br><input type="submit" name="submit" value="Deploy" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">'; echo "</form><br>"; } } else { // Simply show success message echo "<b>Changes updated successfully.</b><br><br>"; } } else { history_add("general", "config", "generate failed with syntax errors"); // Remove generated config - syntax check has failed if (DEBUG_MODE == 1) { // Move generated config to "output" dir, but tag it as FAILED system("mv " . NCONFDIR . "/temp/NagiosConfig.tgz " . NCONFDIR . "/output/NagiosConfig_FAILED.tgz." . time()); } // Remove generated config system("rm -rf " . NCONFDIR . "/temp/*"); $content = "Deployment not possible due to errors in configuration."; echo NConf_HTML::limit_space(NConf_HTML::show_error('Error', $content)); } mysql_close($dbh);
$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); } } } //foreach # service deletion: sort the array on hostnames ksort($entries); # Modify text on top tree element (root) when deleting services if ($item_class == "service") { $items = "services"; } else { $items = "items"; } $tree_view = array("root" => array("id" => "root", "status" => 'open', "name" => "The following {$items} will be deleted", "type" => "parent", "childs" => $entries)); # display tree echo '<br><div>'; displayTree_list($tree_view); echo '</div>'; } else { NConf_DEBUG::set("No item to delete", "ERROR"); } if (NConf_DEBUG::status('ERROR')) { echo NConf_HTML::limit_space(NConf_HTML::show_error()); echo "<br><br>"; echo NConf_HTML::back_button($_SESSION["go_back_page"]); } mysql_close($dbh); require_once 'include/foot.php';
public static function show_error($title = "Error:", $content = '') { $output = ''; $output .= '<div class="ui-state-error ui-corner-all fg-error">'; $output .= '<span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"> </span>'; $output .= NConf_HTML::title($title, 2); if (!empty($content)) { $output .= $content; } else { $output .= NConf_DEBUG::show_debug('ERROR', TRUE); } $output .= '</div>'; return $output; }
<br>any asscociated data will be lost! <br><br>Are you <b>ABSOLUTELY SURE</b> you want to proceed? <br><br>List of attributes defined for this class:<br>(items using these attributes are not listed here explicitly) <br> '; $content .= '<ul>'; foreach ($attr as $item) { $content .= '<li>' . $item["attr_name"] . '</li>'; } $content .= '</ul>'; } else { $content = 'No attributes defined for this class.<br>You may safely delete the "<b>' . $class_name . '</b>" class.'; } // Buttons $content_button = ' <form name="delete_class" action="delete_class.php" method="post"> <input type="hidden" name="id" value="' . $_GET["id"] . '"> <input type="hidden" name="class_name" value="' . $class_name . '"> <input type="hidden" name="delete" value="yes"> '; if (!empty($_GET["from"])) { $content_button .= '<input type="hidden" name="from" value="' . $_GET["from"] . '">'; } $content_button .= '<br><div id=buttons>'; $content_button .= '<input type="Submit" value="Delete" name="submit" align="middle"> '; $content_button .= '<input type=button onClick="window.location.href=\'' . $_SESSION["go_back_page"] . '\'" value="Back">'; $content_button .= '</form>'; echo NConf_HTML::limit_space(NConf_HTML::show_highlight('WARNING', $content . $content_button)); } mysql_close($dbh); require_once 'include/foot.php';
# get host name of service $hostID = db_templates("hostID_of_service", $item_ID); $hostname = db_templates("naming_attr", $hostID); $name = $hostname . ":" . $name; } if (!empty($name) or $name === "0") { $content .= "<li>{$name}</li>"; } } $content .= '</ul>'; echo '<br>'; echo '<div id="info_box">'; $title = 'Old value will be overwritten for the following item(s):'; echo NConf_HTML::limit_space(NConf_HTML::show_highlight($title, $content)); echo '</div>'; } echo '</form>'; } if (NConf_DEBUG::status('ERROR')) { echo NConf_HTML::show_error(); } // Run the Autocomplete function if (isset($prepare_status) and $prepare_status == 1) { # only run if prepare was ok js_Autocomplete_run('email', 'emaillist'); js_Autocomplete_run('pager', 'pagerlist'); } # close content box echo '</div>'; mysql_close($dbh); require_once 'include/foot.php';
public static function show_debug($LEVEL = '', $IN_CONTENT = FALSE, $BACK_BUTTON = FALSE) { if (self::status($LEVEL)) { $output = ''; $after_titel = TRUE; $group_open = FALSE; $group_level = 0; foreach (self::$debug as $entry) { if (empty($LEVEL) || $LEVEL == $entry["LEVEL"]) { //if ( !empty($entry["GROUP"]) ){ if (is_int($entry["GROUP"]) and $entry["GROUP"] > 0) { # Handle groups if ($entry["GROUP"] == $group_level and $group_open) { $output .= '</fieldset><fieldset'; } elseif ($entry["GROUP"] == $group_level and !$group_open) { $output .= '<fieldset'; } elseif ($entry["GROUP"] > $group_level) { $output .= '<fieldset'; $group_level++; $group_open = TRUE; } elseif ($entry["GROUP"] < $group_level) { for ($level = $group_level; $level >= $entry["GROUP"]; $level--) { $output .= '</fieldset>'; } $output .= '<fieldset'; $group_level = $entry["GROUP"]; } # define the background if ((1 & $entry["GROUP"]) == 1) { $bgcolor = "even"; } else { $bgcolor = "odd"; } $output .= ' class="' . $bgcolor . '">'; // put title in FIELDSET - LEGEND if (!empty($entry["TITLE"])) { $output .= '<legend><b>' . $entry["TITLE"] . '</b></legend>'; } } elseif ($entry["GROUP"] === FALSE) { for ($level = $group_level; $level > 0; $level--) { $output .= '</fieldset>'; } $group_open = FALSE; } elseif (is_int($entry["GROUP"]) and $entry["GROUP"] < 0) { for ($level = (int) -$group_level; $level <= $entry["GROUP"]; $level++) { $output .= '</fieldset>'; } $group_open = FALSE; } elseif (is_array($entry["MESSAGE"])) { if ($after_titel) { $output .= NConf_HTML::swap_content($entry["MESSAGE"], $entry["TITLE"]); } else { $output .= NConf_HTML::swap_content($entry["MESSAGE"], $entry["TITLE"], FALSE, FALSE); } } else { if ($IN_CONTENT) { if (!empty($entry["TITLE"])) { if (!empty($entry["MESSAGE"])) { if ($after_titel) { $output .= NConf_HTML::text('<b>' . $entry["TITLE"] . '</b>: ' . $entry["MESSAGE"], FALSE); } else { $output .= NConf_HTML::text('<b>' . $entry["TITLE"] . '</b>: ' . $entry["MESSAGE"]); } // info about new line for next message $after_titel = FALSE; } else { $output .= NConf_HTML::title($entry["TITLE"]); // info about new line for next message $after_titel = TRUE; } } else { if ($after_titel) { $output .= NConf_HTML::text($entry["MESSAGE"], FALSE); $after_titel = FALSE; } else { $output .= NConf_HTML::text($entry["MESSAGE"]); } } } else { if (!empty($entry["TITLE"])) { $output .= NConf_HTML::text('<b>' . $entry["TITLE"] . '</b>: ' . $entry["MESSAGE"]); } else { // mostly for fieldset not making a first line //if ($after_titel){ // $output .= NConf_HTML::text($entry["MESSAGE"], FALSE); // $after_titel = FALSE; //}else{ $output .= NConf_HTML::text($entry["MESSAGE"]); //} } } } } } # print back button if wanted if ($BACK_BUTTON) { $output .= '<br><br>'; $output .= '<div id=buttons>'; $output .= '<input type=button onClick="window.location.href=\'' . $BACK_BUTTON . '\'" value="Back">'; $output .= '</div>'; } return $output; } else { return ''; } }
### require_once NCONFDIR . '/include/access_rules.php'; # Show page or EXIT the script ? (based on above auth-checks) if ($NConf_PERMISSIONS->checkPageAccess() === TRUE and $NConf_PERMISSIONS->checkIdAuthorization() !== FALSE) { NConf_DEBUG::set("Access granted", 'DEBUG', "ACL"); # go ahead in file } elseif (!isset($_SESSION["group"]) and empty($_GET["goto"])) { # not logged in # Go to login page, and redirect it to called page $url = 'index.php?goto=' . urlencode($_SERVER['REQUEST_URI']); # Redirect to login page with url as goto echo '<meta http-equiv="refresh" content="0; url=' . $url . '">'; message($info, '<b>redirecting to:</b> <a href="' . $url . '"> [ this page ] </a>'); require_once NCONFDIR . '/include/foot.php'; exit; } elseif (!isset($_SESSION["group"]) and !empty($_GET["goto"])) { # do nothing, login page will be displayed message($debug, "display login page"); } else { $message = $NConf_PERMISSIONS->message; NConf_DEBUG::set($message, 'INFO'); NConf_DEBUG::set("Access denied", 'DEBUG', "ACL"); //echo $message; echo NConf_HTML::limit_space(NConf_HTML::show_error('Error', $message)); require_once NCONFDIR . '/include/foot.php'; # EXIT because of no access exit; } # close header-part in DEBUG section $debug_entry = NConf_HTML::line() . NConf_HTML::text("Page specific debugging:", FALSE, 'b'); NConf_DEBUG::set($debug_entry);