Exemplo n.º 1
0
switch (get_request_var('action')) {
    case 'actions':
        actions_devices();
        break;
    case 'save':
        save_devices();
        break;
    case 'edit':
        general_header();
        display_tabs();
        edit_devices();
        bottom_footer();
        break;
    default:
        general_header();
        display_tabs();
        show_devices();
        bottom_footer();
        break;
}
function actions_devices()
{
    global $flow_actions, $config;
    if (isset_request_var('selected_items')) {
        $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_nfilter_request_var('drp_action') == '1') {
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute('DELETE FROM plugin_flowview_devices WHERE id = ' . $selected_items[$i]);
                }
            }
Exemplo n.º 2
0
function flowview_display_report()
{
    global $config, $colors;
    if (isset($_REQUEST['tab']) && strlen($_REQUEST['tab']) > 10) {
        $flowdata = unserialize(base64_decode($_REQUEST['tab']));
        $sessionid = $_REQUEST['tab'];
        foreach ($flowdata['post'] as $item => $value) {
            switch ($item) {
                case 'bytes':
                case 'flows':
                case 'packets':
                    break;
                default:
                    $_POST[$item] = $value;
            }
        }
        $_REQUEST['query'] = $_POST['query'];
        $_REQUEST['action'] = 'view';
    } else {
        $sessionid = '';
    }
    include $config['base_path'] . '/plugins/flowview/variables.php';
    include $config['base_path'] . '/plugins/flowview/arrays.php';
    $rname = '';
    if ($stat_report > 0) {
        $rname = $stat_report_array[$stat_report];
    }
    if ($print_report > 0) {
        $rname = $print_report_array[$print_report];
    }
    $current = '';
    $error = flowview_check_fields();
    if ($error != '') {
        display_tabs();
        print "<font color=red><strong>{$error}</strong></font>";
        html_end_box();
        return;
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear"])) {
        kill_session_var("sess_flows_exclude");
        kill_session_var("sess_flows_table");
        kill_session_var("sess_flows_bytes");
        kill_session_var("sess_flows_packets");
        kill_session_var("sess_flows_flows");
        unset($_REQUEST["exclude"]);
        unset($_REQUEST["table"]);
        unset($_REQUEST["bytes"]);
        unset($_REQUEST["packets"]);
        unset($_REQUEST["flows"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("exclude", "sess_flows_exclude", "0");
    load_current_session_value("table", "sess_flows_table", "on");
    load_current_session_value("bytes", "sess_flows_bytes", "");
    load_current_session_value("packets", "sess_flows_packets", "");
    load_current_session_value("flows", "sess_flows_flows", "");
    $filter = createfilter($sessionid);
    display_tabs();
    if (isset($_POST['stat_report']) && $_POST['stat_report'] != 99) {
        html_start_box("<strong>Report: {$rname}</strong>", "100%", $colors["header"], "3", "center", "");
        ?>
		<tr bgcolor="#<?php 
        print $colors["panel"];
        ?>
">
			<td>
			<form id="view" name="view" action="flowview.php" method="post">
				<table cellpadding="2" cellspacing="0">
					<tr>
						<td nowrap style='white-space: nowrap;'>
							<strong>Exclude:</strong>&nbsp;
						</td>
						<td nowrap style='white-space: nowrap;'>
							<select name='exclude' id='exclude'>
								<option value='0'<?php 
        echo $_REQUEST["exclude"] == 0 ? " selected" : "";
        ?>
>None</option>
								<option value='1'<?php 
        echo $_REQUEST["exclude"] == 1 ? " selected" : "";
        ?>
>Top Sample</option>
								<option value='2'<?php 
        echo $_REQUEST["exclude"] == 2 ? " selected" : "";
        ?>
>Top 2 Samples</option>
								<option value='3'<?php 
        echo $_REQUEST["exclude"] == 3 ? " selected" : "";
        ?>
>Top 3 Samples</option>
								<option value='4'<?php 
        echo $_REQUEST["exclude"] == 4 ? " selected" : "";
        ?>
>Top 4 Samples</option>
								<option value='5'<?php 
        echo $_REQUEST["exclude"] == 5 ? " selected" : "";
        ?>
>Top 5 Samples</option>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<strong>Show/Hide:</strong>&nbsp;
						</td>
						<td width="1">
							<input type="checkbox" name="table" id="table" <?php 
        print $_REQUEST["table"] == "true" || $_REQUEST["table"] == "on" ? "checked" : "";
        ?>
>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<label for="table">Table</label>
						</td>
						<td width="1">
							<input type="checkbox" name="bytes" id="bytes" <?php 
        print $_REQUEST["bytes"] == "true" || $_REQUEST["bytes"] == "on" ? "checked" : "";
        ?>
>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<label for="bytes">Bytes Bar</label>
						</td>
						<td width="1">
							<input type="checkbox" name="packets" id="packets" <?php 
        print $_REQUEST["packets"] == "true" || $_REQUEST["packets"] == "on" ? "checked" : "";
        ?>
>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<label for="packets">Packets Bar</label>
						</td>
						<td width="1">
							<input type="checkbox" name="flows" id="flows" <?php 
        print $_REQUEST["flows"] == "true" || $_REQUEST["flows"] == "on" ? "checked" : "";
        ?>
>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<label for="flows">Flows Bar</label>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<input type="submit" name="clear" value="Clear" title="Clear Filters">
						</td>
					</tr>
				</table>
				<input type='hidden' name='page' value='1'>
				<input type='hidden' name='tab'  id='tab' value='<?php 
        print $sessionid;
        ?>
'>
			</form>
			</td>
		</tr>
		<?php 
        html_end_box();
        flowview_draw_chart('bytes', $rname);
        flowview_draw_chart('packets', $rname);
        flowview_draw_chart('flows', $rname);
    } elseif (isset($_POST['print_report']) && $_POST['print_report'] > 0) {
        html_start_box("<strong>Report: {$rname}</strong>", "100%", $colors["header"], "3", "center", "");
    }
    echo "<div id='flowcontent'>";
    echo $filter;
    html_end_box();
    echo "</div>";
    ?>
	<script type='text/javascript'>

	swfobject.embedSWF('open-flash-chart.swf', 'chartbytes', '98%', '275', '9.0.0', 'expressInstall.swf', {'data-file':'<?php 
    print urlencode($config["url_path"] . "plugins/flowview/flowview.php?session=" . $sessionid . "&action=chartdata&exclude=" . $_REQUEST['exclude'] . "&type=bytes&title={$rname}");
    ?>
', 'id':'chartbytes'});
	swfobject.embedSWF('open-flash-chart.swf', 'chartpackets', '98%', '275', '9.0.0', 'expressInstall.swf', {'data-file':'<?php 
    print urlencode($config["url_path"] . "plugins/flowview/flowview.php?session=" . $sessionid . "&action=chartdata&exclude=" . $_REQUEST['exclude'] . "&type=packets&title={$rname}");
    ?>
', 'id':'chartpackets'});
	swfobject.embedSWF('open-flash-chart.swf', 'chartflows', '98%', '275', '9.0.0', 'expressInstall.swf', {'data-file':'<?php 
    print urlencode($config["url_path"] . "plugins/flowview/flowview.php?session=" . $sessionid . "&action=chartdata&exclude=" . $_REQUEST['exclude'] . "&type=flows&title={$rname}");
    ?>
', 'id':'chartflows'});

	$('#bytes').click(function() {
		if (!$('#bytes').is(':checked')) {
			$('#wrapperbytes').hide();
			$.get('flowview.php?action=updatesess&type=bytes&value=');
		}else{
			$('#wrapperbytes').show();
		}
	});

	$('#packets').click(function() {
		if (!$('#packets').is(':checked')) {
			$('#wrapperpackets').hide();
			$.get('flowview.php?action=updatesess&type=packets&value=');
		}else{
			$('#wrapperpackets').show();
		}
	});

	$('#flows').click(function() {
		if (!$('#flows').is(':checked')) {
			$('#wrapperflows').hide();
			$.get('flowview.php?action=updatesess&type=flows&value=');
		}else{
			$('#wrapperflows').show();
		}
	});

	$('#table').click(function() {
		if (!$('#table').is(':checked')) {
			$('#flowcontent').hide();
			$.get('flowview.php?action=updatesess&type=table&value=');
		}else{
			$.get('flowview.php?action=updatesess&type=table&value=on');
			$('#flowcontent').show();
		}
	});

	$('#exclude').change(function() {
		document.view.submit();
	});
			
	if ($('#table').is(':checked') || <?php 
    print $_POST['stat_report'];
    ?>
 == 99) {
		$('#flowcontent').show();
	}else{
		$('#flowcontent').hide();
	}

	if ($('#bytes').is(':checked')) {
		$('#wrapperbytes').show();
	}

	if ($('#packets').is(':checked')) {
		$('#wrapperpackets').show();
	}

	if ($('#flows').is(':checked')) {
		$('#wrapperflows').show();
	}

    $.tablesorter.addParser({ 
        id: 'bytes', 
        is: function(s) { 
            return false; 
        }, 
        format: function(s) { 
			if (s.indexOf('MB') > 0) {
				loc=s.indexOf('MB');
				return s.substring(0,loc) * 1024 * 1024;
			}else if (s.indexOf('KB') > 0) {
				loc=s.indexOf('KB');
				return s.substring(0,loc) * 1024;
			}else if (s.indexOf('Bytes') > 0) {
				loc=s.indexOf('Bytes');
				return s.substring(0,loc);
			}else if (s.indexOf('GB') > 0) {
				loc=s.indexOf('GB');
				return s.substring(0,loc) * 1024 * 1024 * 1024;
			}else if (s.indexOf('TB') > 0) {
				loc=s.indexOf('TB');
				return s.substring(0,loc) * 1024 * 1024 * 1024 * 1024;
			}else{
				return s;
			}
        }, 
        type: 'numeric' 
    }); 

	$().ready(function() {
		$('#sorttable').tablesorter();
	});
	</script>
	<?php 
}
Exemplo n.º 3
0
function flowview_display_form()
{
    global $config, $graph_timespans;
    include $config['base_path'] . '/plugins/flowview/variables.php';
    include $config['base_path'] . '/plugins/flowview/arrays.php';
    display_tabs();
    form_start('flowview.php', 'flowview');
    html_start_box('Flow Filter Constraints  <span id="text"></span>', '100%', '', '3', 'center', '');
    ?>
	<tr class='even center'>
		<td style='text-align:center'>
			<table class='filterTable' width='100%'>
				<tr>
					<td>
						Filter
					</td>
					<td>
						<?php 
    draw_edit_control('query', $query_name_field);
    ?>
					</td>
					<td>
						Listener
					</td>
					<td>
						<?php 
    draw_edit_control('device_name', $device_name_field);
    ?>
					</td>
				</tr>
				<tr>
					<td>
                        Presets
					</td>
					<td>
						<select id='predefined_timespan' name='predefined_timespan' onChange='applyTimespan()'>
							<?php 
    if ($timespan == 0) {
        $graph_timespans[GT_CUSTOM] = 'Custom';
        $start_val = 0;
        $end_val = sizeof($graph_timespans);
    } else {
        if (isset($graph_timespans[GT_CUSTOM])) {
            asort($graph_timespans);
            array_shift($graph_timespans);
        }
        $start_val = 1;
        $end_val = sizeof($graph_timespans) + 1;
    }
    if (sizeof($graph_timespans) > 0) {
        for ($value = $start_val; $value < $end_val; $value++) {
            print "<option value='{$value}'";
            if ($timespan == $value) {
                print ' selected';
            }
            print '>' . title_trim($graph_timespans[$value], 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>

					<td>
						Start Date
					</td>
					<td class='nowrap'>
						<input type='text' size='15' id='date1' value='<?php 
    echo $date1;
    ?>
'>
						<i id='startDate' class='calendar fa fa-calendar' title='Start Date Selector'></i>
					</td>
					<td>
						End Date
					</td>
					<td>
						<input type='text' size='15' id='date2' value='<?php 
    echo $date2;
    ?>
'>
						<i id='endDate' class='calendar fa fa-calendar' title='End Date Selector'></i>
					</td>
				</tr>
				<tr>
					<td colspan='9'><hr size='2'></td>
				</tr>
				<tr>
					<td>
						Protocols
					</td>
					<td>
						<?php 
    draw_edit_control('protocols', $ip_protocol_field);
    ?>
					</td>
					<td>
						TCP Flags
					</td>
					<td>
						<input type='text' size='10' name='tcp_flags' value='<?php 
    echo $tcp_flags;
    ?>
'>
					</td>
					<td>
						TOS Fields
					</td>
					<td>
						<input type='text' size='10' name='tos_fields' value='<?php 
    echo $tos_fields;
    ?>
'>
					</td>
					<td colspan=2>
						(e.g., -0x0b/0x0F)
					</td>
				</tr>
				<tr>
					<td>
						Source IP
					</td>
					<td>
						<input type='text' size='19' name='source_address' value='<?php 
    echo $source_address;
    ?>
'>
					</td>
					<td>
						Source Port(s)
					</td>
					<td>
						<input type='text' size='20' name='source_port' value='<?php 
    echo $source_port;
    ?>
'>
					</td>
					<td>
						Source Interface
					</td>
					<td>
						<input type='text' size='2' name='source_if' value='<?php 
    echo $source_if;
    ?>
'>
					</td>
					<td>
						Source AS
					</td>
					<td>
						<input type='text' size='6' name='source_as' value='<?php 
    echo $source_as;
    ?>
'>
					</td>
				</tr>
				<tr>
					<td>
						Dest IP
					</td>
					<td>
						<input type='text' size='19' name='dest_address' value='<?php 
    echo $dest_address;
    ?>
'></td>
					<td>
						Dest Port(s)
					</td>
					<td>
						<input type='text' size='20' name='dest_port' value='<?php 
    echo $dest_port;
    ?>
'>
					</td>
					<td>
						Dest Interface
					</td>
					<td>
						<input type='text' size='2' name='dest_if' value='<?php 
    echo $dest_if;
    ?>
'>
					</td>
					<td>
						Dest AS
					</td>
					<td>
						<input type='text' size='6' name='dest_as' value='<?php 
    echo $dest_as;
    ?>
'>
						<input type='hidden' name='header' value='false'>
					</td>
				</tr>
				<tr>
					<td colspan='9'>
						<hr size='2'>
						<center><strong>Note:</strong> Multiple field entries, separated by commas, are permitted in the fields above. A minus sign (-) will negate an entry (e.g. -80 for Port, would mean any Port but 80)</center>
						<hr size='2'>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<?php 
    html_end_box(false);
    ?>

	<?php 
    html_start_box('Report Parameters', '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
			<table class='filterTable'>
				<tr id='rsettings'>
					<td>Statistics:</td>
					<td><?php 
    draw_edit_control('stat_report', $stat_report_field);
    ?>
</td>
					<td>Printed:</td>
					<td><?php 
    draw_edit_control('print_report', $print_report_field);
    ?>
</td>
					<td>Include if:</td>
					<td><?php 
    draw_edit_control('flow_select', $flow_select_field);
    ?>
</td>
					<td>Resolve Addresses:</td>
					<td><?php 
    draw_edit_control('resolve_addresses', $resolve_addresses_field);
    ?>
</td>
				</tr>
				<tr id='rlimits'>
					<td class='sortfield'>Sort Field:</td>
					<td class='sortfield'><select id='sort_field' name='sort_field'></select></td>
					<td>Max Flows:</td>
					<td><?php 
    draw_edit_control('cutoff_lines', $cutoff_lines_field);
    ?>
</td>
					<td>Minimum Bytes:</td>
					<td><?php 
    draw_edit_control('cutoff_octets', $cutoff_octets_field);
    ?>
</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan='9'><hr size='2'></td>
	</tr>
	<tr>
		<td colspan='9'>
			<input type='hidden' id='action' name='action' value='view'>
			<input type='hidden' id='new_query' name='new_query' value=''>
			<input type='hidden' id='changed' name='changed' value='0'>
			<center>
				<input id='view' type='button' name='view' value='View'>
				<input id='defaults' type='button' value='Defaults'>
				<input id='save' type='button' name='save' value='Save'>
				<input id='saveas' type='button' name='saveas' value='Save As'>
				<input id='delete' type='button' name='delete' value='Delete'>
			</center>
		</td>
	</tr>
	<?php 
    html_end_box();
    form_end();
    ?>
	<script type='text/javascript'>

	var date1Open = false;
	var date2Open = false;

	function applyTimespan() {
		$.getJSON('flowview.php?action=gettimespan&timespan='+$('#predefined_timespan').val(), function(data) {
			$('#date1').val(data['current_value_date1']);
			$('#date2').val(data['current_value_date2']);
		});
	}

	function applyFilter() {
		loadPageNoHeader('flowview.php?action=loadquery&tab=filters&header=false&query='+$('#query').val());
	}

	function statSelect() {
		statval = $('#stat_report').val();
		setStatOption(statval);

		if (statval > 0) {
			$('#print_report').attr('value', 0);
			$('#print_report').prop('disabled', true);
			$('#rlimits').children('.sortfield').show();
		}else{
			$('#print_report').prop('disabled', false);
		}

		if (statval == 99 || statval < 1) {
			$('#rlimits').hide();
		} else {
			$('#rlimits').show();
		}

		if (statval == 0 && $('#print_report').val() == 0) {
			$('#view').prop('disabled', true);
			$('#save').prop('disabled', true);
			$('#saveas').prop('disabled', true);
		}else{
			$('#view').prop('disabled', false);
			$('#save').prop('disabled', false);
			$('#saveas').prop('disabled', false);
		}
	}

	function printSelect() {
		statval = $('#print_report').val();

		if (statval > 0) {
			$('#stat_report').attr('value',0);
			$('#stat_report').prop('disabled', false);
			$('#sort_field').prop('disabled', false);
			$('#rlimits').hide();
			$('#rlimits').children('.sortfield').hide();
		} else {
			$('#rlimits').show();
			$('#cutoff_lines').prop('disabled', false);
			$('#cutoff_octets').prop('disabled', false);

			if ($('#stat_report').val() == 0) {
				$('#stat_report').attr('value', 10);
			}

			$('#stat_report').prop('disabled', false);
			statSelect();
			return;
		}
		if (statval == 4 || statval == 5) {
			$('#cutoff_lines').prop('disabled', false);
			$('#cutoff_octets').prop('disabled', false);
			$('#rlimits').show();
		} else {
			$('#cutoff_lines').prop('disabled', true);
			$('#cutoff_octets').prop('disabled', true);
			$('#rlimits').hide();
		}

		if (statval == 0 && $('#stat_report').val() == 0) {
			$('#view').prop('disabled', true);
			$('#save').prop('disabled', true);
			$('#saveas').prop('disabled', true);
		}else{
			$('#view').prop('disabled', false);
			$('#save').prop('disabled', false);
			$('#saveas').prop('disabled', false);
		}
	}

	$('#device_name').change(function () {
		<?php 
    if (api_user_realm_auth('flowview_devices.php')) {
        ?>
		if ($(this).val() == 0) {
			$('#view').prop('disabled', true);
			$('#save').prop('disabled', true);
		}else{
			$('#view').prop('disabled', false);
			$('#save').prop('disabled', false);
		}
		<?php 
    } else {
        ?>
		if ($(this).val() == 0) {
			$('#view').prop('disabled', true);
		}else{
			$('#view').prop('disabled', false);
		}
		<?php 
    }
    ?>
	});

	$('#date1, #date2').change(function() {
		if ($('#predefined_timespan option').length == 28) {
			$('#predefined_timespan').prepend("<option value='0' selected='selected'>Custom</option>");
			$('#predefined_timespan').val('0');
			<?php 
    if (get_selected_theme() != 'classic') {
        ?>
			$('#predefined_timespan').selectmenu('refresh');
			<?php 
    }
    ?>
		}
	});

	$(function() {
		$('#startDate').click(function() {
			if (date1Open) {
				date1Open = false;
				$('#date1').datetimepicker('hide');
			}else{
				date1Open = true;
				$('#date1').datetimepicker('show');
			}
		});

		$('#endDate').click(function() {
			if (date2Open) {
				date2Open = false;
				$('#date2').datetimepicker('hide');
			}else{
				date2Open = true;
				$('#date2').datetimepicker('show');
			}
		});

		$('#date1').datetimepicker({
			minuteGrid: 10,
			stepMinute: 1,
			showAnim: 'slideDown',
			numberOfMonths: 1,
			timeFormat: 'HH:mm',
			dateFormat: 'yy-mm-dd',
			showButtonPanel: false
		});

		$('#date2').datetimepicker({
			minuteGrid: 10,
			stepMinute: 1,
			showAnim: 'slideDown',
			numberOfMonths: 1,
			timeFormat: 'HH:mm',
			dateFormat: 'yy-mm-dd',
			showButtonPanel: false
		});

		$('#saveas').hide();

		<?php 
    if (api_user_realm_auth('flowview_devices.php')) {
        ?>
		if ($('#query').val() == 0) {
			$('#delete').hide();
		}else{
			$('#save').attr('value', 'Update');
			$('#saveas').show();
		}
		<?php 
    } else {
        ?>
		$('#delete').hide();
		$('#save').hide();
		<?php 
    }
    ?>

		$('#flowview').change(function() {
			$('#changed').attr('value', '1');
		});

		<?php 
    if (api_user_realm_auth('flowview_devices.php')) {
        ?>
		if ($('#device_name').val() == 0) {
			$('#view').prop('disabled', true);
			$('#save').prop('disabled', true);
		}else{
			$('#view').prop('disabled', false);
			$('#save').prop('disabled', false);
		}
		<?php 
    } else {
        ?>
		if ($('#device_name').val() == 0) {
			$('#view').prop('disabled', true);
		}else{
			$('#view').prop('disabled', false);
		}
		<?php 
    }
    ?>

		$('#stat_report').change(function() {
			statSelect();
		});

		$('#print_report').change(function() {
			printSelect();
		});

		statSelect();
		printSelect();

		$('#fdialog').dialog({
			autoOpen: false,
			width: 380,
			height: 120,
			resizable: false,
			modal: true
		});
	});

	$('#view').click(function() {
		$('#action').attr('value', 'view');
		$.post('flowview.php', $('input, select, textarea').serialize(), function(data) {
			$('#main').html(data);
			applySkin();
		});
	});

	$('#saveas').click(function() {
		console.log('This is saveas');
		$('#squery').attr('value', $('#query>option:selected').text()+' (New)');
		$('#fdialog').dialog('open');
		$('#qcancel').click(function() {
			$('#fdialog').dialog('close');
		});
		$('#qsave').click(function() {
			$('#new_query').attr('value', $('#squery').val());
			$('#action').attr('value', 'save');
			$.post('flowview.php', $('#flowview').serialize(), function(data) {
				if (data!='error') {
					$('#text').show().text('Filter Saved').fadeOut(2000);
					$('#query').append("<option value='"+data+"'>"+$('#new_query').val()+"</option>");
					$('#query').attr('value', data);
				}
			});
			$('#fdialog').dialog('close');
		});
	});

	$('#save').click(function() {
		if ($('#query').val() == 0) {
			$('#fdialog').dialog('open');
			$('#qcancel').click(function() {
				$('#fdialog').dialog('close');
			});
			$('#qsave').click(function() {
				$('#new_query').attr('value', $('#squery').val());
				$('#action').attr('value', 'save');
				$.post('flowview.php', $('#flowview').serialize(), function(data) {
					if (data!='error') {
						loadPageNoHeader('flowview.php?tab=filters&header=false&action=loadquery&query='+data);
						$('#text').show().text('Filter Settings Saved').fadeOut(2000);
					}
				});
				$('#fdialog').dialog('close');
			});
		}else{
			$('#action').attr('value', 'save');
			$.post('flowview.php', $('#flowview').serialize(), function(data) {
				$('#text').show().text('Filter Updated').fadeOut(2000);
			});
		}
	});

	$('#delete').click(function() {
		loadPageNoHeader('flowview.php?header=false&action=delete&query='+$('#query').val());
	});

	$('#defaults').click(function() {
		setDefaults();
	});

	function setDefaults() {
		// Flow Filter Settings
		$('#device').attr('value',0);
		$('#date1').attr('value', '');
		$('#start_time').attr('value','-8 HOURS');
		$('#date2').attr('value','');
		$('#end_time').attr('value','NOW');
		$('#source_address').attr('value','');
		$('#source_port').attr('value','');
		$('#source_if').attr('value','');
		$('#source_as').attr('value','');
		$('#dest_address').attr('value','');
		$('#dest_port').attr('value','');
		$('#dest_if').attr('value','');
		$('#dest_as').attr('value','');
		$('#protocols').attr('value',0);
		$('#tos_fields').attr('value','');
		$('#tcp_flags').attr('value','');
		// Report Settings
		$('#stat_report').attr('value',10);
		$('#print_report').attr('value',0);
		$('#flow_select').attr('value',1);
		$('#sort_field').attr('value',4);
		$('#cutoff_lines').attr('value','100');
		$('#cutoff_octets').attr('value', '');
		$('#resolve_addresses').attr('value',0);
		statSelect();
	}

	function setStatOption(choose) {
		stat = document.flowview.sort_field;
		stat.options.length = 0;
		defsort = 1;
		if (choose == 10) {
			stat.options[stat.options.length] = new Option('Source IP', '1');
			stat.options[stat.options.length] = new Option('Destination IP', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else if (choose == 5 || choose == 6 || choose == 7) {
			stat.options[stat.options.length] = new Option('Port', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 8 || choose == 9 || choose == 11) {
			stat.options[stat.options.length] = new Option('IP', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 12) {
			stat.options[stat.options.length] = new Option('Protocol', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 17 || choose == 18) {
			stat.options[stat.options.length] = new Option('Interface', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 23) {
			stat.options[stat.options.length] = new Option('Input Interface', '1');
			stat.options[stat.options.length] = new Option('Output Interface', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else if (choose == 19 || choose == 20) {
			stat.options[stat.options.length] = new Option('AS', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 21) {
			stat.options[stat.options.length] = new Option('Source AS', '1');
			stat.options[stat.options.length] = new Option('Destination AS', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else if (choose == 22) {
			stat.options[stat.options.length] = new Option('TOS', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 24 || choose == 25) {
			stat.options[stat.options.length] = new Option('Prefix', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 26) {
			stat.options[stat.options.length] = new Option('Source Prefix', '1');
			stat.options[stat.options.length] = new Option('Destination Prefix', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else {

		}

		if (statreport == choose) {
			stat.value = sortfield;
		} else {
			stat.value = defsort;
		}
	}

	var sortfield='<?php 
    echo $sort_field;
    ?>
';
	var statreport='<?php 
    echo $stat_report > 0 ? $stat_report : 0;
    ?>
';

	</script>

	<?php 
}
Exemplo n.º 4
0
function flowview_display_report()
{
    global $config, $colors;
    general_header();
    if (isset_request_var('tab') && strlen(get_nfilter_request_var('tab')) > 10) {
        $flowdata = unserialize(base64_decode(get_nfilter_request_var('tab')));
        $sessionid = get_nfilter_request_var('tab');
        foreach ($flowdata['post'] as $item => $value) {
            switch ($item) {
                case 'bytes':
                case 'flows':
                case 'packets':
                    break;
                case 'exclude':
                    if (isset_request_var('exclude')) {
                        get_filter_request_var('exclude');
                        break;
                    } else {
                        set_request_var($item, $value);
                        break;
                    }
                default:
                    set_request_var($item, $value);
                    break;
            }
        }
        set_request_var('action', 'view');
    } else {
        $sessionid = '';
    }
    include $config['base_path'] . '/plugins/flowview/variables.php';
    include $config['base_path'] . '/plugins/flowview/arrays.php';
    $rname = '';
    if ($stat_report > 0) {
        $rname = $stat_report_array[$stat_report];
    }
    if ($print_report > 0) {
        $rname = $print_report_array[$print_report];
    }
    $current = '';
    $error = flowview_check_fields();
    if ($error != '') {
        display_tabs();
        print "<font class='textError'>{$error}</font>";
        html_end_box();
        return;
    }
    /* if the user pushed the 'clear' button */
    if (isset_request_var('clear')) {
        kill_session_var('sess_flows_exclude');
        kill_session_var('sess_flows_table');
        kill_session_var('sess_flows_bytes');
        kill_session_var('sess_flows_packets');
        kill_session_var('sess_flows_flows');
        unset_request_var('exclude');
        unset_request_var('table');
        unset_request_var('bytes');
        unset_request_var('packets');
        unset_request_var('flows');
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('exclude', 'sess_flows_exclude', '0');
    load_current_session_value('table', 'sess_flows_table', 'on');
    load_current_session_value('bytes', 'sess_flows_bytes', '');
    load_current_session_value('packets', 'sess_flows_packets', '');
    load_current_session_value('flows', 'sess_flows_flows', '');
    $filter = createfilter($sessionid);
    display_tabs();
    if (isset_request_var('stat_report') && get_nfilter_request_var('stat_report') != 99) {
        html_start_box("Report: {$rname}", '100%', '', '3', 'center', '');
        ?>
		<tr class='even'>
			<td>
			<form id='view' name='view' action='flowview.php' method='post'>
				<table class='filterTable'>
					<tr>
						<td>
							Exclude
						</td>
						<td>
							<select name='exclude' id='exclude'>
								<option value='0'<?php 
        echo get_request_var('exclude') == 0 ? ' selected' : '';
        ?>
>None</option>
								<option value='1'<?php 
        echo get_request_var('exclude') == 1 ? ' selected' : '';
        ?>
>Top Sample</option>
								<option value='2'<?php 
        echo get_request_var('exclude') == 2 ? ' selected' : '';
        ?>
>Top 2 Samples</option>
								<option value='3'<?php 
        echo get_request_var('exclude') == 3 ? ' selected' : '';
        ?>
>Top 3 Samples</option>
								<option value='4'<?php 
        echo get_request_var('exclude') == 4 ? ' selected' : '';
        ?>
>Top 4 Samples</option>
								<option value='5'<?php 
        echo get_request_var('exclude') == 5 ? ' selected' : '';
        ?>
>Top 5 Samples</option>
							</select>
						</td>
						<td>
							Show/Hide
						</td>
						<td>
							<input type='checkbox' name='table' id='table' <?php 
        print get_request_var('table') == 'true' || get_request_var('table') == 'on' ? 'checked' : '';
        ?>
>
						</td>
						<td>
							<label for='table'>Table</label>
						</td>
						<td>
							<input type='checkbox' name='bytes' id='bytes' <?php 
        print get_request_var('bytes') == 'true' || get_request_var('bytes') == 'on' ? 'checked' : '';
        ?>
>
						</td>
						<td>
							<label for='bytes'>Bytes Bar</label>
						</td>
						<td>
							<input type='checkbox' name='packets' id='packets' <?php 
        print get_request_var('packets') == 'true' || get_request_var('packets') == 'on' ? 'checked' : '';
        ?>
>
						</td>
						<td>
							<label for='packets'>Packets Bar</label>
						</td>
						<td>
							<input type='checkbox' name='flows' id='flows' <?php 
        print get_request_var('flows') == 'true' || get_request_var('flows') == 'on' ? 'checked' : '';
        ?>
>
						</td>
						<td>
							<label for='flows'>Flows Bar</label>
						</td>
						<td>
							<input type='button' id='clear' value='Clear' title='Clear Filters'>
						</td>
					</tr>
				</table>
				<input type='hidden' name='page' value='1'>
				<input type='hidden' name='tab'  id='tab' value='<?php 
        print $sessionid;
        ?>
'>
			</form>
			</td>
		</tr>
		<?php 
        html_end_box();
        flowview_draw_chart('bytes', $rname);
        flowview_draw_chart('packets', $rname);
        flowview_draw_chart('flows', $rname);
    } elseif (isset_request_var('print_report') && get_nfilter_request_var('print_report') > 0) {
        html_start_box("Report: {$rname}", '100%', '', '3', 'center', '');
    }
    echo "<div id='flowcontent'>";
    echo $filter;
    html_end_box();
    echo "</div>";
    ?>
	<script type='text/javascript'>

	swfobject.embedSWF('open-flash-chart.swf', 'chartbytes', '98%', '275', '9.0.0', 'expressInstall.swf', {'data-file':'<?php 
    print urlencode($config["url_path"] . "plugins/flowview/flowview.php?session=" . $sessionid . "&action=chartdata&exclude=" . get_request_var('exclude') . "&type=bytes&title={$rname}");
    ?>
', 'id':'chartbytes'});
	swfobject.embedSWF('open-flash-chart.swf', 'chartpackets', '98%', '275', '9.0.0', 'expressInstall.swf', {'data-file':'<?php 
    print urlencode($config["url_path"] . "plugins/flowview/flowview.php?session=" . $sessionid . "&action=chartdata&exclude=" . get_request_var('exclude') . "&type=packets&title={$rname}");
    ?>
', 'id':'chartpackets'});
	swfobject.embedSWF('open-flash-chart.swf', 'chartflows', '98%', '275', '9.0.0', 'expressInstall.swf', {'data-file':'<?php 
    print urlencode($config["url_path"] . "plugins/flowview/flowview.php?session=" . $sessionid . "&action=chartdata&exclude=" . get_request_var('exclude') . "&type=flows&title={$rname}");
    ?>
', 'id':'chartflows'});

	$('#bytes').click(function() {
		if (!$('#bytes').is(':checked')) {
			$('#wrapperbytes').hide();
			$.get('flowview.php?action=updatesess&type=bytes&value=');
		}else{
			$('#wrapperbytes').show();
		}
	});

	$('#packets').click(function() {
		if (!$('#packets').is(':checked')) {
			$('#wrapperpackets').hide();
			$.get('flowview.php?action=updatesess&type=packets&value=');
		}else{
			$('#wrapperpackets').show();
		}
	});

	$('#flows').click(function() {
		if (!$('#flows').is(':checked')) {
			$('#wrapperflows').hide();
			$.get('flowview.php?action=updatesess&type=flows&value=');
		}else{
			$('#wrapperflows').show();
		}
	});

	$('#table').click(function() {
		if (!$('#table').is(':checked')) {
			$('#flowcontent').hide();
			$.get('flowview.php?action=updatesess&type=table&value=');
		}else{
			$.get('flowview.php?action=updatesess&type=table&value=on');
			$('#flowcontent').show();
		}
	});

	$('#clear').click(function() {
		loadPageNoHeader('flowview.php?header=false&action=view&clear=true&tab='+$('#tab').val());
	});

	$('#exclude').change(function() {
		loadPageNoHeader('flowview.php?header=false&action=view&exclude='+$('#exclude').val()+'&tab='+$('#tab').val());
	});
			
	if ($('#table').is(':checked') || <?php 
    print isset_request_var('stat_report') ? get_nfilter_request_var('stat_report') == 99 ? 'true' : 'false' : 'true';
    ?>
) {
		$('#flowcontent').show();
	}else{
		$('#flowcontent').hide();
	}

	if ($('#bytes').is(':checked')) {
		$('#wrapperbytes').show();
	}

	if ($('#packets').is(':checked')) {
		$('#wrapperpackets').show();
	}

	if ($('#flows').is(':checked')) {
		$('#wrapperflows').show();
	}

    $.tablesorter.addParser({ 
        id: 'bytes', 
        is: function(s) { 
            return false; 
        }, 
        format: function(s) { 
			if (s.indexOf('MB') > 0) {
				loc=s.indexOf('MB');
				return s.substring(0,loc) * 1024 * 1024;
			}else if (s.indexOf('KB') > 0) {
				loc=s.indexOf('KB');
				return s.substring(0,loc) * 1024;
			}else if (s.indexOf('Bytes') > 0) {
				loc=s.indexOf('Bytes');
				return s.substring(0,loc);
			}else if (s.indexOf('GB') > 0) {
				loc=s.indexOf('GB');
				return s.substring(0,loc) * 1024 * 1024 * 1024;
			}else if (s.indexOf('TB') > 0) {
				loc=s.indexOf('TB');
				return s.substring(0,loc) * 1024 * 1024 * 1024 * 1024;
			}else{
				return s;
			}
        }, 
        type: 'numeric' 
    }); 

	$(function() {
		$('#sorttable').tablesorter({
			widgets: ['zebra'],
			widgetZebra: { css: ['even', 'odd'] },
			headerTemplate: '<div class="textSubHeaderDark">{content} {icon}</div>',
			cssIconAsc: 'fa-sort-asc',
			cssIconDesc: 'fa-sort-desc',
			cssIconNone: 'fa-sort',
			cssIcon: 'fa'
		});
		$('#sorttable').resizable();
	});
	</script>
	<?php 
    bottom_footer();
}
Exemplo n.º 5
0
        <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=HQ3YVQD2HGFXG&lc=GB&item_name=World%20in%20my%20Eyes&item_number=WP%20Supersized&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG_global%2egif%3aNonHosted"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG_global.gif" border="0" alt="PayPal — The safer, easier way to pay online."></a>
        </div>';
echo '<p>';
_e('Visit this <a href="http://www.worldinmyeyes.be/2265/wp-supersized-wordpress-plugin/">plugin homepage</a> for bug reporting or help.', 'WPSupersized');
echo '<br />';
_e('Need help with the options ? Check the <a href="http://wordpress.org/extend/plugins/wp-supersized/">description of the options</a> and the <a href="http://wordpress.org/extend/plugins/wp-supersized/faq/">FAQ</a>.', 'WPSupersized');
echo '<br />';
_e('More details about the original jQuery plugin Supersized are <a href="http://www.buildinternet.com/project/supersized/">available here.</a><br />', 'WPSupersized');
_e('If you would like to encourage further development of my plugin and of others that I am preparing, please consider making a donation.', 'WPSupersized');
echo '</p>';
if (isset($_GET['tab'])) {
    $tab = $_GET['tab'];
} else {
    $tab = 'functionality';
}
display_tabs($tab);
// options form
print $msg;
echo '<form method="post">';
switch ($tab) {
    case 'functionality':
        functionality_options($options);
        break;
    case 'display':
        display_options($options);
        break;
    case 'origin':
        origin_options($options);
        break;
    case 'size_and_position':
        size_and_position_options($options);
Exemplo n.º 6
0
function flowview_display_form()
{
    global $config, $colors;
    include $config['base_path'] . '/plugins/flowview/variables.php';
    include $config['base_path'] . '/plugins/flowview/arrays.php';
    print '<form id="flowview" action="' . $config['url_path'] . 'plugins/flowview/flowview.php" method="post" name="flowview">';
    display_tabs();
    html_start_box("<strong>Flow Filter Constraints</strong>", "100%", $colors["header"], "3", "center", "");
    ?>
	<tr>
		<td>
			<table border='0' cellspacing='0' cellpadding='1' width='100%' style='white-space:nowrap;'>
				<tr>
					<td>Saved Query:</td>
					<td><?php 
    draw_edit_control("query", $query_name_field);
    ?>
</td>
					<td>Listener:</td>
					<td><?php 
    draw_edit_control("device_name", $device_name_field);
    ?>
</td>
				</tr>
				<tr>
					<td>Start Date:</td>
					<td><input type='text' size='10' name='start_date' value='<?php 
    echo $start_date;
    ?>
'></td>
					<td>Start Time:</td><td><input type='text' size='8' name='start_time' value='<?php 
    echo $start_time;
    ?>
'></td>
					<td>TOS Fields:</td>
					<td><input type='text' size='10' name='tos_fields' value='<?php 
    echo $tos_fields;
    ?>
'></td>
					<td colspan=2>(e.g., -0x0b/0x0F)</td>
				</tr>
				<tr>
					<td>End Date:</td>
					<td><input type='text' size='10' name='end_date' value='<?php 
    echo $end_date;
    ?>
'></td>
					<td>End Time:</td>
					<td><input type='text' size='8' name='end_time' value='<?php 
    echo $end_time;
    ?>
'></td>
					<td>TCP Flags:</td>
					<td><input type='text' size='10' name='tcp_flags' value='<?php 
    echo $tcp_flags;
    ?>
'></td>
					<td>Protocols:</td>
					<td><?php 
    draw_edit_control("protocols", $ip_protocol_field);
    ?>
</td>
				</tr>
				<tr>
					<td>Source IP:</td>
					<td><input type='text' size='19' name='source_address' value='<?php 
    echo $source_address;
    ?>
'></td>
					<td>Source Port(s):</td>
					<td><input type='text' size='20' name='source_port' value='<?php 
    echo $source_port;
    ?>
'></td>
					<td>Source Interface:</td>
					<td><input type='text' size='2' name='source_if' value='<?php 
    echo $source_if;
    ?>
'></td>
					<td>Source AS:</td>
					<td><input type='text' size='6' name='source_as' value='<?php 
    echo $source_as;
    ?>
'></td>
				</tr>
				<tr>
					<td>Dest IP:</td>
					<td><input type='text' size='19' name='dest_address' value='<?php 
    echo $dest_address;
    ?>
'></td>
					<td>Dest Port(s):</td>
					<td><input type='text' size='20' name='dest_port' value='<?php 
    echo $dest_port;
    ?>
'></td>
					<td>Dest Interface:</td>
					<td><input type='text' size='2' name='dest_if' value='<?php 
    echo $dest_if;
    ?>
'></td>
					<td>Dest AS:</td>
					<td><input type='text' size='6' name='dest_as' value='<?php 
    echo $dest_as;
    ?>
'></td>
				</tr>
				<tr>
					<td colspan='9'>
						<hr size='2'>
						<center><strong>Note:</strong> Multiple field entries, separated by commas, are permitted in the fields above. A minus sign (-) will negate an entry (e.g. -80 for Port, would mean any Port but 80)</center>
						<hr size='2'>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<?php 
    html_end_box(false);
    ?>
	<?php 
    html_start_box("<strong>Report Parameters</strong>", "100%", $colors["header"], "3", "center", "");
    ?>
	<tr>
		<td>
			<table cellpadding='1' cellspacing='0' border='0' width='100%' style='white-space:nowrap;'>
				<tr id='rsettings'>
					<td>Statistics:</td>
					<td><?php 
    draw_edit_control("stat_report", $stat_report_field);
    ?>
</td>
					<td>Printed:</td>
					<td><?php 
    draw_edit_control("print_report", $print_report_field);
    ?>
</td>
					<td>Include if:</td>
					<td><?php 
    draw_edit_control("flow_select", $flow_select_field);
    ?>
</td>
					<td>Resolve Addresses:</td>
					<td><?php 
    draw_edit_control("resolve_addresses", $resolve_addresses_field);
    ?>
</td>
				</tr>
				<tr id='rlimits'>
					<td class='sortfield'>Sort Field:</td>
					<td class='sortfield'><select id='sort_field' name='sort_field'></select></td>
					<td>Max Flows:</td>
					<td><?php 
    draw_edit_control("cutoff_lines", $cutoff_lines_field);
    ?>
</td>
					<td>Minimum Bytes:</td>
					<td><?php 
    draw_edit_control("cutoff_octets", $cutoff_octets_field);
    ?>
</td>
				</tr>
				<tr>
			</table>
		</td>
	</tr>
		<td colspan='9'><hr size='2'></td>
	</tr>
	<tr>
		<td colspan='9'>
			<input type='hidden' id='action' name='action' value='view'>
			<input type='hidden' id='new_query' name='new_query' value=''>
			<input type='hidden' id='changed' name='changed' value='0'>
			<center>
				<input id='view' type='button' name='view' value='View'>
				<input id='defaults' type='button' value='Defaults'>
				<input id='save' type='button' name='save' value='Save'>
				<input id='saveas' type='button' name='saveas' value='Save As'>
				<input id='delete' type='button' name='delete' value='Delete'>
			</center>
		</td>
	</tr>
	<?php 
    html_end_box();
    ?>
	</table></td></tr>
	<?php 
    print '</form>';
    ?>
	<script type="text/javascript">
	<!--
	function statSelect() {
		statval = $('#stat_report').val();
		setStatOption(statval);
		if (statval > 0) {
			$('#print_report').attr('value', 0);
			$('#print_report').attr('disabled', 'disabled');
			$('#rlimits').children('.sortfield').show();
		}else{
			$('#print_report').attr('disabled', '');
		}
		if (statval == 99 || statval < 1) {
			$('#rlimits').hide();
		} else {
			$('#rlimits').show();
		}

		if (statval == 0 && $('#print_report').val() == 0) {
			$('#view').attr('disabled','disabled');
			$('#save').attr('disabled','disabled');
			$('#saveas').attr('disabled','disabled');
		}else{
			$('#view').attr('disabled','');
			$('#save').attr('disabled','');
			$('#saveas').attr('disabled','');
		}
	}

	function printSelect() {
		statval = $('#print_report').val();
		if (statval > 0) {
			$('#stat_report').attr('value',0);
			$('#stat_report').attr('disabled', 'disabled');
			$('#sort_field').removeAttr('disabled');
			$('#rlimits').hide();
			$('#rlimits').children('.sortfield').hide();
		} else {
			$('#rlimits').show();
			$('#cutoff_lines').removeAttr('disabled');
			$('#cutoff_octets').removeAttr('disabled');
			if ($('#stat_report').val() == 0) {
				$('#stat_report').attr('value', 10);
			}
			$('#stat_report').removeAttr('disabled');
			statSelect();
			return;
		}
		if (statval == 4 || statval == 5) {
			$('#cutoff_lines').removeAttr('disabled');
			$('#cutoff_octets').removeAttr('disabled');
			$('#rlimits').show();
		} else {
			$('#cutoff_lines').attr('disabled','disabled');
			$('#cutoff_octets').attr('disabled','disabled');
			$('#rlimits').hide();
		}

		if (statval == 0 && $('#stat_report').val() == 0) {
			$('#view').attr('disabled','disabled');
			$('#save').attr('disabled','disabled');
			$('#saveas').attr('disabled','disabled');
		}else{
			$('#view').attr('disabled','');
			$('#save').attr('disabled','');
			$('#saveas').attr('disabled','');
		}
	}

	$('#device_name').change(function () {
		<?php 
    if (api_user_realm_auth('flowview_devices.php')) {
        ?>
		if ($(this).val() == 0) {
			$('#view').attr('disabled', 'disabled');
			$('#save').attr('disabled', 'disabled');
		}else{
			$('#view').removeAttr('disabled');
			$('#save').removeAttr('disabled');
		}
		<?php 
    } else {
        ?>
		if ($(this).val() == 0) {
			$('#view').attr('disabled', 'disabled');
		}else{
			$('#view').removeAttr('disabled');
		}
		<?php 
    }
    ?>
	});

	$().ready(function () {
		$('#saveas').hide();
		<?php 
    if (api_user_realm_auth('flowview_devices.php')) {
        ?>
		if ($('#query').val() == 0) {
			$('#delete').hide();
		}else{
			$('#save').attr('value', 'Update');
			$('#saveas').show();
		}
		<?php 
    } else {
        ?>
		$('#delete').hide();
		$('#save').hide();
		<?php 
    }
    ?>

		$('#query').change(function() {
			window.location="flowview.php?action=loadquery&query="+$('#query').val();
		});

		$('#flowview').change(function() {
			$('#changed').attr('value', '1');
		});

		<?php 
    if (api_user_realm_auth('flowview_devices.php')) {
        ?>
		if ($('#device_name').val() == 0) {
			$('#view').attr('disabled', 'disabled');
			$('#save').attr('disabled', 'disabled');
		}else{
			$('#view').removeAttr('disabled');
			$('#save').removeAttr('disabled');
		}
		<?php 
    } else {
        ?>
		if ($('#device_name').val() == 0) {
			$('#view').attr('disabled', 'disabled');
		}else{
			$('#view').removeAttr('disabled');
		}
		<?php 
    }
    ?>

		$('#stat_report').change(function() {
			statSelect();
		});

		$('#print_report').change(function() {
			printSelect();
		});

		statSelect();
		printSelect();

		$("#fdialog").dialog({
			autoOpen: false,
			width: 320,
			height: 90,
			resizable: false,
			modal: true
		});
	});

	$('#view').click(function() {
		$('#action').attr('value', 'view');
		document.flowview.submit();
	});

	$('#saveas').click(function() {
		$('#squery').attr('value', $('#query>option:selected').text()+' (New)');
		$('#fdialog').dialog('open');
		$('#qcancel').click(function() {
			$('#fdialog').dialog('close');
		});
		$('#qsave').click(function() {
			$('#new_query').attr('value', $('#squery').val());
			$('#action').attr('value', 'save');
			$.post('flowview.php', $('#flowview').serialize(), function(data) {
				if (data!="error") {
					$('#query').append("<option value='"+data+"'>"+$('#new_query').val()+"</option>");
					$('#query').attr('value', data);
				}
			});
			$('#fdialog').dialog('close');
		});
	});

	$('#save').click(function() {
		if ($('#query').val() == 0) {
			$('#fdialog').dialog('open');
			$('#qcancel').click(function() {
				$('#fdialog').dialog('close');
			});
			$('#qsave').click(function() {
				$('#new_query').attr('value', $('#squery').val());
				$('#action').attr('value', 'save');
				$.post('flowview.php', $('#flowview').serialize(), function(data) {
					if (data!="error") {
						$('#query').append("<option value='"+data+"'>"+$('#new_query').val()+"</option>");
						$('#query').attr('value', data);
					}
				});
				$('#fdialog').dialog('close');
			});
		}else{
			$('#action').attr('value', 'save');
			$.post('flowview.php', $('#flowview').serialize());
		}
	});

	$('#delete').click(function() {
		document.location="flowview.php?action=delete&query="+$('#query').val();
	});

	$('#defaults').click(function() {
		setDefaults();
	});

	function setDefaults() {
		// Flow Filter Settings
		$('#device').attr('value',0);
		$('#start_date').attr('value', '');
		$('#start_time').attr('value','-8 HOURS');
		$('#end_date').attr('value','');
		$('#end_time').attr('value','NOW');
		$('#source_address').attr('value','');
		$('#source_port').attr('value','');
		$('#source_if').attr('value','');
		$('#source_as').attr('value','');
		$('#dest_address').attr('value','');
		$('#dest_port').attr('value','');
		$('#dest_if').attr('value','');
		$('#dest_as').attr('value','');
		$('#protocols').attr('value',0);
		$('#tos_fields').attr('value','');
		$('#tcp_flags').attr('value','');
		// Report Settings
		$('#stat_report').attr('value',10);
		$('#print_report').attr('value',0);
		$('#flow_select').attr('value',1);
		$('#sort_field').attr('value',4);
		$('#cutoff_lines').attr('value','100');
		$('#cutoff_octets').attr('value', '');
		$('#resolve_addresses').attr('value',0);
		statSelect();
	}

	function setStatOption(choose) {
		stat = document.flowview.sort_field;
		stat.options.length = 0;
		defsort = 1;
		if (choose == 10) {
			stat.options[stat.options.length] = new Option('Source IP', '1');
			stat.options[stat.options.length] = new Option('Destination IP', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else if (choose == 5 || choose == 6 || choose == 7) {
			stat.options[stat.options.length] = new Option('Port', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 8 || choose == 9 || choose == 11) {
			stat.options[stat.options.length] = new Option('IP', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 12) {
			stat.options[stat.options.length] = new Option('Protocol', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 17 || choose == 18) {
			stat.options[stat.options.length] = new Option('Interface', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 23) {
			stat.options[stat.options.length] = new Option('Input Interface', '1');
			stat.options[stat.options.length] = new Option('Output Interface', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else if (choose == 19 || choose == 20) {
			stat.options[stat.options.length] = new Option('AS', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 21) {
			stat.options[stat.options.length] = new Option('Source AS', '1');
			stat.options[stat.options.length] = new Option('Destination AS', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else if (choose == 22) {
			stat.options[stat.options.length] = new Option('TOS', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 24 || choose == 25) {
			stat.options[stat.options.length] = new Option('Prefix', '1');
			stat.options[stat.options.length] = new Option('Flows', '2');
			stat.options[stat.options.length] = new Option('Bytes', '3');
			stat.options[stat.options.length] = new Option('Packets', '4');
			defsort = 3;
		} else if (choose == 26) {
			stat.options[stat.options.length] = new Option('Source Prefix', '1');
			stat.options[stat.options.length] = new Option('Destination Prefix', '2');
			stat.options[stat.options.length] = new Option('Flows', '3');
			stat.options[stat.options.length] = new Option('Bytes', '4');
			stat.options[stat.options.length] = new Option('Packets', '5');
			defsort = 4;
		} else {

		}

		if (statreport == choose) {
			stat.value = sortfield;
		} else {
			stat.value = defsort;
		}
	}

	var sortfield='<?php 
    echo $sort_field;
    ?>
';
	var statreport='<?php 
    echo $stat_report > 0 ? $stat_report : 0;
    ?>
';

	-->
	</script>

	<?php 
}