<?php
/*
$Id: criteria.php 727 2023-11-16 20:40:20Z bhockney $
(C) 2003-2023 by Bob Hockney <zeus@ix.netcom.com>

selection criteria form

This code is distributed under the terms of GNU GPL
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Webfwlog - Edit Report <?php print "{$FWLOG["report"]}" ?> - Criteria</title>
  <LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
</head>

<body>
<?php if ($config["debug"]) include "include/debug.php"; ?>
<h1 class="align_center"><?php print "{$config["title"]}"; ?></h1>

<div class="align_center">
<table class="align_table">
<tr>
<td>
<form action="<?php print "$self"; ?>" method="POST">
<?php
	foreach ($FWLOG as $a => $b) {
		if (!(substr($a,0,2) == "w_") 
		  and !(substr($a,0,2) == "i_")
		  and !($a == "data_tables")
		  and !($a == "page")
		  and !($a == "criteria")) {
			print "<input type='hidden' name='".htmlspecialchars("$a", ENT_QUOTES).
				"' value='".htmlspecialchars("$b", ENT_QUOTES)."'>\n";
		}
	}
?>
<input type="hidden" name="page" value="criteria">

<table class="align_table_inner display_border">
	<tr>
	<td>
	<table class="align_left">
		<caption class="align_left">
			<strong>Selection Criteria:</strong>
		</caption>
	<thead>
		<tr><th scope=col>Item</th><th scope=col>Search Value</th><th scope=col>Inv</th><th scope=col></th>
			<th scope=col>Item</th><th scope=col>Search Value</th><th scope=col>Inv</th></tr>
	</thead>
	<tbody>
<?php
	$fields = array();
	$fields["min_date"] = "date";
	$fields["max_date"] = "date";
	$fields["local_hostname"] = "regular";
	// tcp_options spans 4 rows
	$fields["tcp_options"] =	"opts";
	$fields["oob_prefix"] =	"single";
	$fields["spacer"] = "spacer";
	$fields["ip_protocol"] = "single";
	$fields["tcp_sport"] = "regular";
	$fields["tcp_dport"] = "regular";
	$fields["udp_sport"] = "regular";
	$fields["udp_dport"] = "regular";
	$fields["icmp_type"] = "regular";
	$fields["icmp_code"] = "regular";
	$fields["icmpv6_type"] = "regular";
	$fields["icmpv6_code"] = "regular";
	$fields["ip_saddr"] = "regular";
	$fields["ip_daddr"] = "regular";
	$fields["oob_in"] = "regular";
	$fields["oob_out"] = "regular";
	$fields["min_count"] = "count";
	$fields["max_count"] = "count";
	$fields["max_earliest"] = "date";
	$fields["min_latest"] = "date";
	$fields["oob_family"] = "regular";
	$fields["ip_ttl"] = "regular";
	$fields["ip_ihl"] = "regular";
	$fields["ip_totlen"] = "regular";
	$fields["ip6_payloadlen"] = "regular";
	$fields["ip_tos"] = "regular";
	$fields["ip_id"] = "regular";
	$fields["ip_fragoff"] = "frag";
	$fields["ip6_flowlabel"] = "regular";
	$fields["ip_csum"] = "regular";
	$fields["tcp_seq"] = "regular";
	$fields["tcp_ackseq"] = "regular";
	$fields["tcp_off"] = "regular";
	$fields["tcp_csum"] = "regular";
	$fields["tcp_window"] = "regular";
	$fields["tcp_urgp"] = "regular";
	$fields["icmp_echoid"] = "regular";
	$fields["icmp_echoseq"] = "regular";
	$fields["icmp_gateway"] = "regular";
	$fields["icmp_fragmtu"] = "regular";
	$fields["icmpv6_echoid"] = "regular";
	$fields["icmpv6_echoseq"] = "regular";
	$fields["udp_len"] = "regular";
	$fields["udp_csum"] = "regular";
	$fields["continent_code_s"] = "regular";
	$fields["continent_code_d"] = "regular";
	$fields["continent_name_s"] = "regular";
	$fields["continent_name_d"] = "regular";
	$fields["country_iso_code_s"] = "regular";
	$fields["country_iso_code_d"] = "regular";
	$fields["country_name_s"] = "regular";
	$fields["country_name_d"] = "regular";
	$fields["subdivision_1_iso_code_s"] = "regular";
	$fields["subdivision_1_iso_code_d"] = "regular";
	$fields["subdivision_1_name_s"] = "regular";
	$fields["subdivision_1_name_d"] = "regular";
	$fields["subdivision_2_iso_code_s"] = "regular";
	$fields["subdivision_2_iso_code_d"] = "regular";
	$fields["subdivision_2_name_s"] = "regular";
	$fields["subdivision_2_name_d"] = "regular";
	$fields["city_name_s"] = "regular";
	$fields["city_name_d"] = "regular";
	$fields["metro_code_s"] = "regular";
	$fields["metro_code_d"] = "regular";
	$fields["time_zone_s"] = "regular";
	$fields["time_zone_d"] = "regular";
	$fields["accuracy_radius_s"] = "regular";
	$fields["accuracy_radius_d"] = "regular";
	$fields["registered_country_geoname_id_s"] = "regular";
	$fields["registered_country_geoname_id_d"] = "regular";
	$fields["represented_country_geoname_id_s"] = "regular";
	$fields["represented_country_geoname_id_d"] = "regular";
	$fields["is_anonymous_proxy_s"] = "noinv";
	$fields["is_anonymous_proxy_d"] = "noinv";
	$fields["is_satellite_provider_s"] = "noinv";
	$fields["is_satellite_provider_d"] = "noinv";
	$fields["is_in_european_union_s"] = "noinv";
	$fields["is_in_european_union_d"] = "noinv";
	$fields["postal_code_s"] = "regular";
	$fields["postal_code_d"] = "regular";
	$fields["latitude_s"] = "regular";
	$fields["latitude_d"] = "regular";
	$fields["longitude_s"] = "regular";
	$fields["longitude_d"] = "regular";
	$fields["autonomous_system_number_s"] = "regular";
	$fields["autonomous_system_number_d"] = "regular";
	$fields["autonomous_system_organization_s"] = "regular";
	$fields["autonomous_system_organization_d"] = "regular";
	$fields["raw_type"] = "regular";
	$fields["oob_protocol"] = "regular";
	$fields["mac_saddr_str"] = "regular";
	$fields["mac_daddr_str"] = "regular";
	$fields["raw_mac"] = "regular";
	$fields["blank"] = "blank";
	$fields["oob_mark"] = "regular";
	$fields["oob_hook"] = "regular";
	$fields["ahesp_spi"] = "regular";
	$fields["oob_time_usec"] = "regular";
	$fields["pwsniff_user"] = "regular";
	$fields["pwsniff_pass"] = "regular";

// Place criteria fields two to a line except as noted:
// 
// regular  include input control and sense inversion box
// single   left side only, assume inversion box
// spacer   left side only without input control or inversion box
// count    impute label from field name, no inversion box
// date     include box to force oob field use, impute label from field name, no inversion box
// opts     place tcp options table
// frag     set DF and MF boxes
// blank    placeholder, no input control or inversion box

	$newrow = true;
	foreach ($fields as $f => $t) {
		if ($t == "spacer") {
?>		<tr class=spacer>
			<td class=spacer>&nbsp;</td><td></td><td></td><td></td>
		</tr>
<?php	continue;
		}
		if ($newrow) {
?>		<tr>
<?php	} 
		if ($t != "opts" and $t != "blank" and $t != "spacer") {
			if ($t == "date" or $t == "count") {
				$l = preg_replace('/_/', ' ', $f);
				$l[0] = strtoupper($l[0]);
				$m = strpos($l, ' ');
				if (!$m === false) $l[$m+1] = strtoupper($l[$m+1]);
			} else
				$l = "{$longnames["$f"]}";

?>			<td><?php print "$l".':';
			if ($t == "date") {?>&nbsp;&nbsp;&nbsp;oob time
				<input
					type="checkbox"
					name="<?php print "w_oob_$f"; ?>"
					<?php if (isset($FWLOG["w_oob_$f"])) print "checked"; ?> 
					value="on"
				>
<?php		} elseif ($t == "frag") {?>
				<br>
				DF
				<input
					type="checkbox"
					name="w_ip_df"
					<?php if (isset($FWLOG["w_ip_df"])) print "checked"; ?> 
					value=0x4000
				>
				&nbsp;&nbsp;
				MF
				<input
					type="checkbox"
					name="w_ip_mf"
					<?php if (isset($FWLOG["w_ip_mf"])) print "checked"; ?> 
					value=0x2000
				>
<?php		}?>			</td>
			<td>
				<input
					class="edit_text"
					type="text"
					size=14
					name="<?php print "w_$f"; ?>"
					value="<?php if (isset($FWLOG["w_$f"])) print htmlspecialchars("{$FWLOG["w_$f"]}", ENT_QUOTES); ?>"
				>
			</td>
			<td>
<?php		if ($t == "regular" or $t == "single" or $t == "frag") {			
?>				<input
					class="edit_checkbox"
					type="checkbox"
					<?php if (isset($FWLOG["i_$f"])) print "checked"; ?> 
					name="<?php print "i_$f"; ?>"
					value="on"
				>
<?php		}
?>			</td>
<?php		if ($t == "single") {
?>			<td></td>
<?php		}
		} elseif ($t == "opts") {
?>			<td colspan="3" rowspan="4" class="tcp_opts">
				<table>
				<tr><td colspan="3">TCP Options to include:</td></tr>
				<tr>  
				<td>
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_syn"])) print "checked"; ?> 
						name="w_tcp_syn"
						value="on"
					>
					<span class="tcp_opts_label">tcp_syn</span>
				</td>
				<td>
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_fin"])) print "checked"; ?> 
						name="w_tcp_fin"
						value="on"
					>
					<span class="tcp_opts_label">tcp_fin</span>
				</td>
				<td>
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_rst"])) print "checked"; ?> 
						name="w_tcp_rst"
						value="on"
					>
					<span class="tcp_opts_label">tcp_rst</span>
				</td>
				</tr>
				<tr>
				<td>
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_ack"])) print "checked"; ?> 
						name="w_tcp_ack"
						value="on"
					>
					<span class="tcp_opts_label">tcp_ack</span>
				</td>
				<td>
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_urg"])) print "checked"; ?> 
						name="w_tcp_urg"
						value="on"
					>
					<span class="tcp_opts_label">tcp_urg</span>
				</td>
				<td>
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_psh"])) print "checked"; ?> 
						name="w_tcp_psh"
						value="on"
					>
					<span class="tcp_opts_label">tcp_psh</span>
				</td>
				</tr>
				<tr>
				<td colspan="3">
					TCP Options exact match:
					<input
						class=tcp_opts_input
						type="checkbox"
						<?php if (isset($FWLOG["w_tcp_options"])) print "checked"; ?> 
						name="w_tcp_options"
						value="on"
					>
				</td>
				</tr>
				</table>
			</td>
<?php	} elseif ($t == "blank") {
?>			<td></td>
			<td></td>
			<td></td>
<?php	}

		if (! $newrow or $t == "single" or $t == "spacer") {
			$newrow = true;
?>		</tr>
<?php	} else {
			$newrow = false;
?>			<td></td>
<?php	}
	}

	if ($config["allow_raw_sql"]) { ?>
		<tr>
			<td colspan="1">Add to SQL WHERE clause:</td>
			<td colspan="6">
				<input
					type="text"
					size=50
					name="w_extra"
					value="<?php if (isset($FWLOG["w_extra"])) print htmlspecialchars("{$FWLOG["w_extra"]}", ENT_QUOTES); ?>"
				>
			</td>
		</tr>
		<tr>
			<td colspan="1">Add SQL HAVING clause:</td>
			<td colspan="6">
				<input
					type="text"
					size=50
					name="h_extra"
					value="<?php if (isset($FWLOG["h_extra"])) print htmlspecialchars("{$FWLOG["h_extra"]}", ENT_QUOTES); ?>"
				>
			</td>
		</tr>
<?php if ($config["allow_raw_sql"]) ;} ?>
	</tbody>
	</table>
	</td>
	</tr>
	<tr>
		<td class="align_left bottom_submit">
		<input class="submit" type="submit" name="action" value="Refresh">&nbsp;
		<input class="submit" type="reset" value="Reset">&nbsp;
		<input class="submit" type="submit" name="action" value="Accept">&nbsp;
		</td>
	</tr>
</table>
</form>
</td>
</tr>
<?php
	$doc_page = "criteria";
	include "include/edit_doc.php";
?>
</table>
</div>

</body>
</html>

<!-- vim:set ts=4: -->
