<?php
/*
Fruity - A Nagios Configuration Tool
Copyright (C) 2005 Groundwork Open Source Solutions

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
Fruity Index Page, Displays Menu, and Statistics
*/
include_once('includes/config.inc');


if(isset($_POST['request'])) {
	if(count($_POST['cgi_config'])) {
		foreach($_POST['cgi_config'] as $key=>$value) {
			$_SESSION['tempData']['cgi_config'][$key] = $value;
		}
	}
	if($_POST['request'] == 'update') {
		$fruity->update_cgi_conf($_SESSION['tempData']['cgi_config']);
		unset($_SESSION['tempData']);
		$status_msg = "Updated CGI Configuration.";
	}
}

// Get Existing CGI Configuration
$fruity->get_cgi_conf($_SESSION['tempData']['cgi_config']);
	
// Let's make the status map layout select list
$statusmap_layout_list[] = array("values" => "0", "text" => "User-Defined Coordinates");
$statusmap_layout_list[] = array("values" => "1", "text" => "Depth Layers");
$statusmap_layout_list[] = array("values" => "2", "text" => "Collapsed Tree");
$statusmap_layout_list[] = array("values" => "3", "text" => "Balanced Tree");
$statusmap_layout_list[] = array("values" => "4", "text" => "Circular");
$statusmap_layout_list[] = array("values" => "5", "text" => "Circular (Marked Up)");
$statusmap_layout_list[] = array("values" => "6", "text" => "Circular (Marked Down)");

// Let's make the status wrl layout select list
$statuswrl_layout_list[] = array("values" => "0", "text" => "User-Defined Coordinates");
$statuswrl_layout_list[] = array("values" => "1", "text" => "Depth Layers");
$statuswrl_layout_list[] = array("values" => "2", "text" => "Collapsed Tree");
$statuswrl_layout_list[] = array("values" => "3", "text" => "Balanced Tree");
$statuswrl_layout_list[] = array("values" => "4", "text" => "Circular");


if(!isset($_GET['section']))
	$_GET['section'] = 'paths';


print_header("CGI Configuration File Editor");
?>
&nbsp;<a class="sublink" href="<?=$path_config['doc_root'];?>cgi.php?section=paths">Paths</a> | <a class="sublink" href="<?=$path_config['doc_root'];?>cgi.php?section=authentication">Authentication</a> | <a class="sublink" href="<?=$path_config['doc_root'];?>cgi.php?section=status">Status</a> | <a class="sublink" href="<?=$path_config['doc_root'];?>cgi.php?section=sounds">Sounds</a> | <a class="sublink" href="<?=$path_config['doc_root'];?>cgi.php?section=other">Other</a><br />
<br />
<?php
	if(isset($status_msg)) {
		?>
		<div align="center" class="statusmsg"><?=$status_msg;?></div><br />
		<?php
	}
	?>
	<br />
	<?php
	if($_GET['section'] == 'paths') {
		print_window_header("Paths", "100%", "center");
		?>
		<form name="cgi_path_config" method="post" action="<?=$path_config['doc_root'];?>cgi.php?section=paths">
		<input type="hidden" name="request" value="update" />
		<b>Physical HTML Path:</b><br />
		<input type="text" size="80" name="cgi_config[physical_html_path]" VALUE="<?=$_SESSION['tempData']['cgi_config']['physical_html_path'];?>"><br />
		<?=$fruity->element_desc("physical_html_path", "nagios_cgi_desc"); ?><br />
		<br />
		<b>URL HTML Path:</b><br />
		<input type="text" size="80" name="cgi_config[url_html_path]" VALUE="<?=$_SESSION['tempData']['cgi_config']['url_html_path'];?>"><br />
		<?=$fruity->element_desc("url_html_path", "nagios_cgi_desc"); ?><br />
		<br />
		<br />
		<input type="submit" value="Update Path Configuration" />
		<?php
	}
	else if($_GET['section'] == 'authentication') {
		print_window_header("Authentication", "100%", "center");
		?>
		<form name="cgi_authentication_config" method="post" action="<?=$path_config['doc_root'];?>cgi.php?section=authentication">
		<input type="hidden" name="request" value="update" />
		<b>Use Authentication:</b> <?php print_select("cgi_config[use_authentication]", $enable_list, "values", "text", $_SESSION['tempData']['cgi_config']['use_authentication']);?><br />
		<?=$fruity->element_desc("use_authentication", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Default Username:</b> <input type="text" name="cgi_config[default_user_name]" VALUE="<?=$_SESSION['tempData']['cgi_config']['default_user_name'];?>"><br />
		<?=$fruity->element_desc("default_user_name", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for System Information:</b> <input type="text" name="cgi_config[authorized_for_system_information]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_system_information'];?>"><br />
		<?=$fruity->element_desc("authorized_for_system_information", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for System Commands:</b> <input type="text" name="cgi_config[authorized_for_system_commands]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_system_commands'];?>"><br />
		<?=$fruity->element_desc("authorized_for_system_commands", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for Configuration Information:</b> <input type="text" name="cgi_config[authorized_for_configuration_information]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_configuration_information'];?>"><br />
		<?=$fruity->element_desc("authorized_for_configuration_information", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for All Hosts:</b> <input type="text" name="cgi_config[authorized_for_all_hosts]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_all_hosts'];?>"><br />
		<?=$fruity->element_desc("authorized_for_all_hosts", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for All Host Commands:</b> <input type="text" name="cgi_config[authorized_for_all_host_commands]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_all_host_commands'];?>"><br />
		<?=$fruity->element_desc("authorized_for_all_host_commands", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for All Services:</b> <input type="text" name="cgi_config[authorized_for_all_services]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_all_services'];?>"><br />
		<?=$fruity->element_desc("authorized_for_all_services", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Authorized for All Service Commands:</b> <input type="text" name="cgi_config[authorized_for_all_service_commands]" VALUE="<?=$_SESSION['tempData']['cgi_config']['authorized_for_all_service_commands'];?>"><br />
		<?=$fruity->element_desc("authorized_for_all_service_commands", "nagios_cgi_desc"); ?><br />
		<br />
		<br />
		<input type="submit" value="Update Authentication Configuration" />
		<?php
	}
	else if($_GET['section'] == 'status') {
		print_window_header("Status Parameters", "100%", "center");
		?>
		<form name="cgi_authentication_config" method="post" action="<?=$path_config['doc_root'];?>cgi.php?section=status">
		<input type="hidden" name="request" value="update" />
		<b>Statusmap Background Image:</b> <input type="text" name="cgi_config[statusmap_background_image]" VALUE="<?=$_SESSION['tempData']['cgi_config']['statusmap_background_image'];?>"><br />
		<?=$fruity->element_desc("statusmap_background_image", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Default Statusmap Layout</b> <?php print_select("cgi_config[default_statusmap_layout]", $statusmap_layout_list, "values", "text", $_SESSION['tempData']['cgi_config']['default_statusmap_layout']);?><br />
		<?=$fruity->element_desc("default_statusmap_layout", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Statuswrl Include:</b> <input type="text" name="cgi_config[statuswrl_include]" VALUE="<?=$_SESSION['tempData']['cgi_config']['statuswrl_include'];?>"><br />
		<?=$fruity->element_desc("statuswrl_include", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Default Statuswrl Layout</b> <?php print_select("cgi_config[default_statuswrl_layout]", $statuswrl_layout_list, "values", "text", $_SESSION['tempData']['cgi_config']['default_statuswrl_layout']);?><br />
		<?=$fruity->element_desc("default_statuswrl_layout", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Refresh Rate:</b> <input type="text" name="cgi_config[refresh_rate]" VALUE="<?=$_SESSION['tempData']['cgi_config']['refresh_rate'];?>"><br />
		<?=$fruity->element_desc("refresh_rate", "nagios_cgi_desc"); ?><br />
		<br />		
		<br />
		<input type="submit" value="Update Status Configuration" />
		<?php
	}
	else if($_GET['section'] == 'sounds') {
		print_window_header("Status Parameters", "100%", "center");
		?>
		<form name="cgi_authentication_config" method="post" action="<?=$path_config['doc_root'];?>cgi.php?section=sounds">
		<input type="hidden" name="request" value="update" />
		<b>Host Unreachable Sound:</b> <input type="text" name="cgi_config[host_unreachable_sound]" VALUE="<?=$_SESSION['tempData']['cgi_config']['host_unreachable_sound'];?>"><br />
		<?=$fruity->element_desc("host_unreachable_sound", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Host Down Sound:</b> <input type="text" name="cgi_config[host_down_sound]" VALUE="<?=$_SESSION['tempData']['cgi_config']['host_down_sound'];?>"><br />
		<?=$fruity->element_desc("host_down_sound", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Service Critical Sound:</b> <input type="text" name="cgi_config[service_critical_sound]" VALUE="<?=$_SESSION['tempData']['cgi_config']['service_critical_sound'];?>"><br />
		<?=$fruity->element_desc("service_critical_sound", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Service Warning Sound:</b> <input type="text" name="cgi_config[service_warning_sound]" VALUE="<?=$_SESSION['tempData']['cgi_config']['service_warning_sound'];?>"><br />
		<?=$fruity->element_desc("service_warning_sound", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Service Unknown Sound:</b> <input type="text" name="cgi_config[service_unknown_sound]" VALUE="<?=$_SESSION['tempData']['cgi_config']['service_unknown_sound'];?>"><br />
		<?=$fruity->element_desc("service_unknown_sound", "nagios_cgi_desc"); ?><br />
		<br />
		<br />
		<input type="submit" value="Update Sound Configuration" />
		<?php
	}
	else if($_GET['section'] == 'other') {
		print_window_header("Other", "100%", "center");
		?>
		<form name="cgi_authentication_config" method="post" action="<?=$path_config['doc_root'];?>cgi.php?section=other">
		<input type="hidden" name="request" value="update" />
		<b>Nagios Check Command:</b><br />
		<input type="text" size="80" name="cgi_config[nagios_check_command]" VALUE="<?=$_SESSION['tempData']['cgi_config']['nagios_check_command'];?>"><br />
		<?=$fruity->element_desc("nagios_check_command", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Context Sensitive Help:</b> <?php print_select("cgi_config[show_context_help]", $enable_list, "values", "text", $_SESSION['tempData']['cgi_config']['show_context_help']);?><br />
		<?=$fruity->element_desc("show_context_help", "nagios_cgi_desc"); ?><br />
		<br />
		<b>Ping Syntax:</b><br />
		<input type="text" size="80" name="cgi_config[ping_syntax]" VALUE="<?=$_SESSION['tempData']['cgi_config']['ping_syntax'];?>"><br />
		<?=$fruity->element_desc("ping_syntax", "nagios_cgi_desc"); ?><br />
		<br />
		<br />
		<input type="submit" value="Update Other Configuration" />
		<?php
	}		
	print_window_footer();

print_footer();
?>