Example #1
0
function DisplayDetails()
{
    global $self;
    global $DisplayOrder;
    global $TypeOrder;
    global $WinSizeLabels;
    global $RRDoffset;
    global $GMToffset;
    global $TZname;
    require_once 'av_init.php';
    $db_aux = new ossim_db();
    $conn_aux = $db_aux->connect();
    ?>
    <script language="Javascript" src="js/detail.js" type="text/javascript">
    </script>
<?php 
    $tright = UNIX2DISPLAY($_SESSION['tright']);
    $tleft = UNIX2DISPLAY($_SESSION['tleft']);
    $profile = $_SESSION['profile'];
    $profilegroup = $_SESSION['profilegroup'];
    $detail_opts = $_SESSION['detail_opts'];
    $is_shadow = ($_SESSION['profileinfo']['type'] & 4) > 0;
    print "<h3>Profile: " . Util::htmlentities($profile) . "</h3>\n";
    if ($detail_opts['channellist'] != '') {
        $_tmp = explode('!', $detail_opts['channellist']);
    } else {
        $_tmp = array();
    }
    if (count($_tmp) == 0) {
        $graph_channels = '@EMPTY';
    } else {
        $graph_channels = '';
        foreach ($_tmp as $_t) {
            $graph_channels .= $_t . ';' . Av_sensor::get_nfsen_channel_name($conn_aux, $_t) . ':';
        }
        $graph_channels = preg_replace('/:$/', '', $graph_channels);
    }
    ?>
	<table style='font-size:14px;font-weight:bold;width:100%' class='transparent'>
	<tr>
<?php 
    for ($i = 1; $i < count($DisplayOrder); $i++) {
        $label = $DisplayOrder[$i];
        if ($label == $detail_opts['proto']) {
            $label = 'any';
        }
        print "<td>";
        print $label;
        print "</td>\n";
    }
    print "<td style='font-size:14px;font-weight:bold'>" . gettext("Profile info:") . "</td>\n";
    // Empty right element
    print "</tr><tr>\n";
    for ($i = 1; $i < count($DisplayOrder); $i++) {
        $label = $DisplayOrder[$i];
        if ($label == $detail_opts['proto']) {
            $label = 'any';
        }
        print "<td>\n";
        if ($graph_channels != '@EMPTY') {
            $arg = implode(" ", array($graph_channels, $label, $detail_opts['type'], $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 288, 100, 1, $detail_opts['logscale'], $detail_opts['linegraph']));
            $arg = urlencode($arg);
        } else {
            $arg = '';
        }
        print "<a href='{$self}&proto={$label}'> " . "<img src=rrdgraph.php?cmd=get-detailsgraph&profile=" . Util::htmlentities($_SESSION['profileswitch']) . "&arg={$arg} border='0' width='165' height='81' alt='{$label}'></a>\n";
        print "</td>\n";
    }
    print "<td style='vertical-align: bottom;'>\n";
    $str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tstart']);
    $expire = $_SESSION['profileinfo']['expire'];
    if ($expire == 0) {
        $expire = 'never';
    } else {
        $d = (int) ($expire / 24);
        $h = $expire % 24;
        $d_ext = $d == 1 ? '' : 's';
        $h_ext = $h == 1 ? '' : 's';
        if ($d) {
            $expire = "{$d} day{$d_ext} {$h} hour{$h_ext}";
        } else {
            $expire = "{$h} hour{$h_ext}";
        }
    }
    $maxsize = ScaleBytes($_SESSION['profileinfo']['maxsize'], 1, 1024.0);
    if ($maxsize == 0) {
        $maxsize = 'unlimited';
    }
    print "<table style='font-size:12px;font-weight:bold;border:none;width:100%'>\n";
    switch ($_SESSION['profileinfo']['type'] & 3) {
        case 0:
            $type = 'live';
            break;
        case 1:
            $type = 'history';
            break;
        case 2:
            $type = 'continuous';
            break;
        default:
            $type = 'unknown';
    }
    $type .= $is_shadow ? '&nbsp;/&nbsp;shadow' : '';
    print "<tr><td>Type:</td><td>{$type}</td></tr>";
    print "<tr><td>Max:</td><td>" . Util::htmlentities($maxsize) . "</td></tr>";
    print "<tr><td>Exp:</td><td>{$expire}</td></tr>";
    print "<tr><td>Start:</td><td>{$str} {$TZname}</td></tr>\n";
    $str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tend']);
    print "<tr><td style='border:none'>End:</td><td style='border:none'>{$str} {$TZname}</td></tr>\n";
    print "</table>\n";
    print "</td>\n";
    if ($graph_channels != '@EMPTY') {
        $arg = implode(" ", array($graph_channels, $detail_opts['proto'], $detail_opts['type'], $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 576, 200, 0, $detail_opts['logscale'], $detail_opts['linegraph']));
        $arg = urlencode($arg);
    } else {
        $arg = '';
    }
    ?>
	</tr>
	<tr>
		<td colspan='4' align="center" valign="top" style='padding:0;'>
			<br>
			<img id='MainGraph' style='position:relative; top:0px; left:0px;' onclick="DragCursor.set(event);" src=rrdgraph.php?cmd=get-detailsgraph&profile=<?php 
    echo Util::htmlentities($_SESSION['profileswitch']);
    ?>
&arg=<?php 
    echo $arg;
    ?>
 border='0' alt='main-graph'>
			<img id="CursorDragHandle" style="position:absolute;display:none; " src="icons/cursor-line.png" alt="Line Cursor">
			<img id="StartDragHandle" 	style="position:absolute;display:none" src="icons/cursor-start.png" alt="Start Cursor">
			<div id="StartLine" style="position: absolute;display:none; width: 1px; height: 200px; background-color: black;"></div>
			<div id="SpanBox"  style="position:absolute;display:none; height: 200px; background-color: #B1FFA1; filter:alpha(opacity=40); opacity:.40;"></div>
			<div id="StopLine"  style="position: absolute;display:none; width: 1px; height: 200px; background-color: black;"></div>
			<img id="StopDragHandle"  	style="position:absolute;display:none" src="icons/cursor-stop.png" alt="Stop Cursor">
			<form style="display:inline;" name="slotselectform" id="slotselectform" action="<?php 
    echo $self;
    ?>
" method="POST">
				<input type="hidden" name="cursor_mode" id="cursor_mode" value="">
				<input type="hidden" name="tleft" id="tleft" value="">
				<input type="hidden" name="tright" id="tright" value="">
			</form>
		</td>
		<td style="vertical-align:bottom;padding:0;"> 
				<table style="margin-bottom:1pt;border:none;width:100%">
				<tr>
					<td><span style='font-size:14px;font-weight:bold;margin-bottom:1pt'>
							t<SUB><?php 
    echo _("start");
    ?>
</SUB>
						</span>
					</td>
					<td style="font-size:16px;color:#555555;">
						<!-- input type="text" name="box_tleft" id="box_tleft" value="" SIZE="16" MAXLENGTH="16" style='font-size:10px;' readonly -->
						<b id='box_tleft'>- <?php 
    echo _("update");
    ?>
 -</b>
					</td>
				</tr><tr>
					<td><span style='font-size:14px;font-weight:bold;margin-bottom:1pt'>
							t<SUB><?php 
    echo _("end");
    ?>
</SUB>
						</span>
					</td>
					<td style="font-size:16px;color:#555555;">
						<!-- input type="text" name="box_tright" id="box_tright" value="" SIZE="16" MAXLENGTH="16" style='font-size:10px;' readonly -->
						<b id='box_tright'>- <?php 
    echo _("update");
    ?>
 -</b>
					</td>
				</tr>
				</table>

		<table style='font-size:14px;font-weight:bold;border:none;width:100%'>
<?php 
    for ($i = 1; $i < count($TypeOrder); $i++) {
        $label = $TypeOrder[$i];
        if ($label == $detail_opts['type']) {
            $label = 'flows';
        }
        // Make first letter uppercase of label to print
        $printlabel = strtoupper($label[0]) . substr($label, 1);
        print "<tr><td>" . ($printlabel != "" ? gettext($printlabel) : "&nbsp;") . "</td></tr>\n";
        print "<tr><td style='border:none'>\n";
        if ($graph_channels != '@EMPTY') {
            $arg = implode(" ", array($graph_channels, $detail_opts['proto'], $label, $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 288, 100, 1, $detail_opts['logscale'], $detail_opts['linegraph']));
            $arg = urlencode($arg);
        } else {
            $arg = '';
        }
        print "<a href='{$self}&type={$label}'> " . "<img src=rrdgraph.php?cmd=get-detailsgraph&profile=" . Util::htmlentities($_SESSION['profileswitch']) . "&arg={$arg} border='0' width='165' height='81' alt='{$label}'></a>";
        print "</td></tr>\n";
    }
    ?>
		</table>
		</td>
	</tr>
	<tr>

	<td colspan='4' style="border:none">
		<table border="0" style='width:100%;margin:0pt;border:none'>
		<tr>
		<td style="border:none">
			<?php 
    echo _("Select");
    ?>
&nbsp;
			<select name="CursorMode" id="ModeSelector" onchange="SetCursorMode(<?php 
    echo Util::htmlentities($_SESSION['tstart']) . ", " . Util::htmlentities($_SESSION['tend']) . ", " . Util::htmlentities($_SESSION['profileinfo']['tstart']) . ", " . Util::htmlentities($_SESSION['tleft']) . ", " . Util::htmlentities($_SESSION['tright']) . ",576, {$RRDoffset}";
    ?>
)" size=1>
<?php 
    if ($detail_opts['cursor_mode'] == 1) {
        print "<option value='0'>" . _("Single Timeslot") . "\n";
        print "<option value='1' selected>" . _("Time Window") . "\n";
    } else {
        print "<option value='0' selected>" . _("Single Timeslot") . "\n";
        print "<option value='1'>" . _("Time Window") . "\n";
    }
    ?>
			</select>
		</td>

		<td style="text-align: right;border:none">
			<?php 
    echo _("Display");
    ?>
:&nbsp;
			<form action="<?php 
    echo $self;
    ?>
" style="display:inline;" method="POST">
			<select name='wsize' onchange='this.form.submit();' size=1>
<?php 
    $size_label = 'unknown';
    for ($i = 0; $i < count($WinSizeLabels); $i++) {
        if ($i == $detail_opts['wsize']) {
            print "<option value='{$i}' selected>" . $WinSizeLabels[$i] . "\n";
            $size_label = $WinSizeLabels[$i];
        } else {
            print "<option value='{$i}'>" . $WinSizeLabels[$i] . "\n";
        }
    }
    $status = $detail_opts['cursor_mode'] == 0 && !$is_shadow ? '' : 'disabled';
    $peak_search_label = $status == '' ? _("Search Peak") : _("Peak search not available");
    ?>
			</select>
			<input class="small av_b_secondary" name="adjust" value=" << " type="submit" title="<?php 
    echo _("Back");
    ?>
 <?php 
    echo $size_label;
    ?>
">&nbsp;
			<input class="small av_b_secondary" name="adjust" value=" < " type="submit" title="<?php 
    echo _("Previous time slot");
    ?>
">&nbsp;
			<input class="small av_b_secondary" name="adjust" value=" | " type="submit" title="<?php 
    echo _("Center cursor");
    ?>
">&nbsp;
			<input class="small av_b_secondary" name="adjust" value=" ^ " type="submit" <?php 
    echo $status;
    ?>
 title="<?php 
    echo $peak_search_label;
    ?>
">&nbsp;
			<input class="small av_b_secondary" name="adjust" value=" > " type="submit" title="<?php 
    echo _("Next time slot");
    ?>
">&nbsp;
			<input class="small av_b_secondary" name="adjust" value=" >> " type="submit" title="<?php 
    echo _("Forward");
    ?>
 <?php 
    echo $size_label;
    ?>
">&nbsp;
			<input class="small av_b_secondary" name="adjust" value=" >| " type="submit" title="<?php 
    echo _("Goto last slot");
    ?>
">
			</form>
		</td>
		</tr>
		</table>
	</td> <td style="border:none">
		<form action="<?php 
    echo $self;
    ?>
" method="POST">
			<table style="border:none;width:100%">
			<tr>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="logscale" value="0"
					<?php 
    if ($detail_opts['logscale'] == 0) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Lin Scale");
    ?>
				</td>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="linegraph" value="0"
					<?php 
    if ($detail_opts['linegraph'] == 0) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Stacked Graph");
    ?>
				</td>
			</tr>
			<tr>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="logscale" value="1"
					<?php 
    if ($detail_opts['logscale'] == 1) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Log Scale");
    ?>
				</td>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="linegraph" value="1"
					<?php 
    if ($detail_opts['linegraph'] == 1) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Line Graph");
    ?>
				</td>
			</tr>
			</table>

		</form>
	</td>
	</tr><tr>
		<td colspan='4' style="border:none"></td>
		<td style="border:none"></td>
	</tr>
	</table>
<?php 
    if ($_SESSION['tleft'] == $_SESSION['tright']) {
        $tslot = "timeslot " . strftime("%b %d %Y - %H:%M", $_SESSION['tleft']);
    } else {
        $tslot = "timeslot " . strftime("%b %d %Y - %H:%M", $_SESSION['tleft']) . " - " . strftime("%b %d %Y - %H:%M", $_SESSION['tright']);
    }
    $num_channels = count(array_keys($_SESSION['profileinfo']['channel']));
    $proto_index = 1;
    foreach ($DisplayOrder as $p) {
        if ($detail_opts['proto'] == $p) {
            break;
        }
        $proto_index++;
    }
    $statpref = explode(':', $detail_opts['statpref']);
    $max_colspan = 0;
    for ($i = 0; $i < count($statpref); $i++) {
        $pref = $statpref[$i];
        if ($pref == 0) {
            $arrow_style[] = '';
            $arrow_style[] = 'style="display:none;"';
            $colspan[] = 5;
            $max_colspan += 5;
        } else {
            $arrow_style[] = 'style="display:none;"';
            $arrow_style[] = '';
            $statpref[$i] = $proto_index;
            $colspan[] = 1;
            $max_colspan += 1;
        }
    }
    $_i = 0;
    if ($detail_opts['statvisible'] == 1) {
        $stattable_style = '';
        $down_arrow_style = '';
        $right_arrow_style = 'style="display:none"';
    } else {
        $stattable_style = 'display:none;';
        $down_arrow_style = 'style="display:none"';
        $right_arrow_style = '';
    }
    ?>
	<br><br><b>
	<table style="width:100%" cellspacing='0' cellpadding='0'>
        <tr>
            <th class='thold'>
            	<a href="#null" onClick="ShowHideStat();" 
            		title="<?php 
    echo _("Hide Statistic");
    ?>
" ><IMG SRC="icons/arrow.yellow.down.png" name="flows" id="stat_arrow_down" border="0"
            		<?php 
    echo $down_arrow_style;
    ?>
 align="left" alt="<?php 
    echo _("Hide stat table");
    ?>
"></a>
            	<a href="#null" onClick="ShowHideStat();" 
            		title="<?php 
    echo _("Show Statistic");
    ?>
" ><IMG SRC="icons/arrow.yellow.right.png" name="flows" id="stat_arrow_right" border="0"
            		<?php 
    echo $right_arrow_style;
    ?>
 align="left" alt="<?php 
    echo _("Show stat table");
    ?>
"></a>
            	Statistics <?php 
    echo $tslot;
    ?>
</b>
            </th>
        </tr>
	</table>
	<form action="<?php 
    echo $self;
    ?>
" method="POST" id="statsform">
	<input type="hidden" name="srctrigger" value="src">
	<table id="stattable" style='font-size:14px;font-weight:bold;<?php 
    echo $stattable_style;
    ?>
;border:none;width:100%' cellspacing='0' cellpadding='3'>
		<tr align='center'>
			<th class='theader' colspan="2"><?php 
    echo _("Channel");
    ?>
</th>
			<th class='theader' id="label0" colspan='<?php 
    echo $colspan[0];
    ?>
'>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 0, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Collapse");
    ?>
" ><IMG SRC="icons/arrow.blue.down.png" name="flows" id="arrow0_down" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 0, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Expand");
    ?>
" ><IMG SRC="icons/arrow.blue.right.png" name="flows" id="arrow0_right" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a><?php 
    echo _("Flows");
    ?>
			</th>
			<th class='theader' id="label1" colspan='<?php 
    echo $colspan[1];
    ?>
'>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 1, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Collapse");
    ?>
" ><IMG SRC="icons/arrow.blue.down.png" name="flows" id="arrow1_down" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 1, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Expand");
    ?>
" ><IMG SRC="icons/arrow.blue.right.png" name="flows" id="arrow1_right" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a><?php 
    echo _("Packets");
    ?>
			</th>
			<th class='theader' id="label2" colspan='<?php 
    echo $colspan[2];
    ?>
'>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 2, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Collapse");
    ?>
" ><IMG SRC="icons/arrow.blue.down.png" name="flows" id="arrow2_down" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 2, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Expand");
    ?>
" ><IMG SRC="icons/arrow.blue.right.png" name="flows" id="arrow2_right" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a><?php 
    echo _("Traffic");
    ?>
			</th>
		</tr>
		<tr>
		<td colspan="2">&nbsp;</td>
<?php 
    for ($i = 0; $i < 3; $i++) {
        $col = 1;
        foreach (array(gettext("all:"), 'tcp:', 'udp:', 'icmp:', gettext("other:")) as $_type) {
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td id='id.0.{$i}.{$col}' {$_style}>{$_type}</td>";
            $col++;
        }
    }
    print "</tr>\n";
    // for simplified testing
    foreach (explode('!', $detail_opts['channellist']) as $channel) {
        $_SelectedChannels[$channel] = 1;
    }
    foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
        $flows_sum[$_type] = 0;
        $packets_sum[$_type] = 0;
        $bits_sum[$_type] = 0;
    }
    $row = 1;
    $rateval = 1;
    foreach ($_SESSION['profileinfo']['channel'] as $channel) {
        $ch_name = $channel['name'];
        $ch_id = $channel['id'];
        if (Session::am_i_admin()) {
            $del_incon = "<img src='/ossim/vulnmeter/images/delete.gif' align='sub' onclick='remove_source(\"{$ch_id}\")' style='cursor:pointer;' border='0'>";
        } else {
            $del_incon = '';
        }
        print "<tr>\n";
        # channel exists in profile
        $statinfo = ReadStat($profile, $profilegroup, $ch_id);
        $rateval = 1;
        if ($detail_opts['ratescale'] == 1) {
            $rateval = $_SESSION['tright'] - $_SESSION['tleft'] + 300;
        }
        $bgcolour = "bgcolor='" . Util::htmlentities($channel['colour']) . "'";
        print "<td {$bgcolour} style='width:10px'></td>\n";
        if (array_key_exists($ch_id, $_SelectedChannels)) {
            print "<td align=left><input type='checkbox' name='" . Util::htmlentities($ch_id) . "' value='" . Util::htmlentities($ch_id) . "' onClick='this.form.submit();' checked>{$ch_name} {$del_incon}</td>\n";
            $cellcolour = "bgcolor='#f2f2f2'";
        } else {
            print "<td align=left><input type='checkbox' name='" . Util::htmlentities($ch_id) . "' value='" . Util::htmlentities($ch_id) . "' onClick='this.form.submit();'>{$ch_name} {$del_incon}</td>\n";
            $cellcolour = '';
        }
        # print flows
        $i = 0;
        $col = 1;
        $mark_char = ($_SESSION['profileinfo']['type'] & 4) > 0 ? 'S' : 'x';
        foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
            if ($statinfo) {
                $_val = ScaleValue($statinfo['flows' . $_type], $rateval);
                $flows_sum[$_type] += $statinfo['flows' . $_type];
            } else {
                $_val = $mark_char;
            }
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
            $col++;
        }
        # print packets
        $i = 1;
        $col = 1;
        foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
            if ($statinfo) {
                $_val = ScaleValue($statinfo['packets' . $_type], $rateval);
                $packets_sum[$_type] += $statinfo['packets' . $_type];
            } else {
                $_val = $mark_char;
            }
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
            $col++;
        }
        # prints bits
        $i = 2;
        $col = 1;
        foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
            if ($statinfo) {
                $_val = ScaleBytes($statinfo['traffic' . $_type], $rateval, 1000.0);
                $bits_sum[$_type] += $statinfo['traffic' . $_type];
            } else {
                $_val = $mark_char;
            }
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
            $col++;
        }
        print "</tr>\n";
        $row++;
    }
    ?>
		
	<tr bgcolor='#dee7ec'>
	<td colspan="2">&nbsp;</td>
<?php 
    # reprint the header as a footer
    for ($i = 0; $i < 3; $i++) {
        $col = 1;
        foreach (array('all:', 'tcp:', 'udp:', 'icmp:', 'other:') as $_type) {
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td id='id.{$row}.{$i}.{$col}' {$_style}>{$_type}</td>";
            $col++;
        }
    }
    print "</tr>\n";
    $row++;
    ?>
	<tr>
	<td colspan="2">TOTAL</td>
<?php 
    # print flows
    $i = 0;
    $col = 1;
    $mark_char = ($_SESSION['profileinfo']['type'] & 4) > 0 ? 'S' : 'x';
    foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
        $_val = ScaleValue($flows_sum[$_type], $rateval);
        if ($statpref[$i] == 0) {
            $_style = '';
        } else {
            if ($statpref[$i] == $col) {
                $_style = '';
            } else {
                $_style = 'style="display:none;"';
            }
        }
        print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
        $col++;
    }
    # print packets
    $i = 1;
    $col = 1;
    foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
        $_val = ScaleValue($packets_sum[$_type], $rateval);
        if ($statpref[$i] == 0) {
            $_style = '';
        } else {
            if ($statpref[$i] == $col) {
                $_style = '';
            } else {
                $_style = 'style="display:none;"';
            }
        }
        print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
        $col++;
    }
    # prints bits
    $i = 2;
    $col = 1;
    foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
        $_val = ScaleBytes($bits_sum[$_type], $rateval, 1000.0);
        if ($statpref[$i] == 0) {
            $_style = '';
        } else {
            if ($statpref[$i] == $col) {
                $_style = '';
            } else {
                $_style = 'style="display:none;"';
            }
        }
        print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
        $col++;
    }
    print "</tr>\n";
    $row++;
    ?>

		<tr><td colspan="2">
		<INPUT class="small av_b_secondary" TYPE="submit" NAME="MultipleSources" Value="<?php 
    echo _("All");
    ?>
">
		<INPUT class="small av_b_secondary" TYPE="submit" NAME="MultipleSources" Value="<?php 
    echo _("None");
    ?>
">
		</td>
		<td colspan='15' style='text-align: left;'>
		<?php 
    echo _("Display");
    ?>
:
		<input type="radio" onClick='this.form.submit();' name="ratescale" value="0"
		<?php 
    if ($detail_opts['ratescale'] == 0) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Sum");
    ?>
		<input type="radio" onClick='this.form.submit();' name="ratescale" value="1"
		<?php 
    if ($detail_opts['ratescale'] == 1) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Rate");
    ?>
 &nbsp;
<?php 
    if (!$statinfo) {
        print "x: " . _("No Data available");
    }
    ?>
		</td></tr>
	</table>
	</form>

	<style type="text/css">
		#av_msg_container {
			width: 60% !important;
		}
		
		.flowlist .tr_flow_data{
    		font-family: Courier, "Courier New", monospace !important;
        }
		
	</style>
    <script language="Javascript" type="text/javascript">

    function remove_source(id)
    {
    	if( confirm("<?php 
    echo Util::js_entities(_('This Netflow source is going to be deleted. This action cannot be undone. Are you soure?'));
    ?>
") )
    	{
	    	$.ajax({
				data:  {"action": 1, "data": {"sensor": id}},
				type: "POST",
				url: "nfsen_ajax.php", 
				dataType: "json",
				beforeSend: function () 
				{
					window.scrollTo(0, 0);

					var layer = "<div id='loading_container' style='width:100%;height:100%;position:absolute;top:0px;left:0px;'></div>";
	            	$('body').append(layer);
	            	
					show_loading_box('loading_container', '<?php 
    echo Util::js_entities(_("Deleting Netflow source..."));
    ?>
', '');
				},
				success: function(data)
				{ 
					hide_loading_box();
					$('#loading_container').remove();
					if(data.error)
					{
						notify(data.msg, 'nf_error');
					} 
					else
					{
						notify(data.msg, 'nf_success');
						setTimeout("document.location.reload();", 1500);
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) 
				{
					hide_loading_box();
					$('#loading_container').remove();
					
					notify(textStatus, 'nf_error');
				}
			});
    	}
    }

	window.onload=function() {
		SetCookieValue("statvisible", <?php 
    echo $detail_opts['statvisible'] ? 1 : 0;
    ?>
);
		var curdate = new Date();
		GMToffset  = <?php 
    echo $GMToffset;
    ?>
 + curdate.getTimezoneOffset() * 60;
		CursorMode = <?php 
    echo intval($detail_opts['cursor_mode']);
    ?>
;
		if ( CursorMode == 0 )
			SlotSelectInit(<?php 
    echo preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tstart'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tend'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['profileinfo']['tstart'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tleft'])) . ",576, {$RRDoffset}";
    ?>
);
		else
			WSelectInit(<?php 
    echo preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tstart'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tend'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['profileinfo']['tstart'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tleft'])) . ", " . preg_replace('/[,\\)]/', '', Util::htmlentities($_SESSION['tright'])) . ",576, {$RRDoffset}";
    ?>
);
<?php 
    if (array_key_exists('anchor', $_SESSION)) {
        print "location.hash='" . Util::htmlentities($_SESSION['anchor']) . "';";
        unset($_SESSION['anchor']);
    }
    ?>
	}


    </script>

<?php 
    $db_aux->close($conn_aux);
}
Example #2
0
function DisplayDetails()
{
    global $self;
    global $DisplayOrder;
    global $TypeOrder;
    global $WinSizeLabels;
    global $RRDoffset;
    global $GMToffset;
    global $TZname;
    require_once 'classes/Session.inc';
    require_once 'classes/Sensor.inc';
    require_once 'ossim_db.inc';
    $db_aux = new ossim_db();
    $conn_aux = $db_aux->connect();
    $sensors_list = Sensor::get_list($conn_aux);
    $db_aux->close($conn_aux);
    ?>
    <script language="Javascript" src="js/detail.js" type="text/javascript">
    </script>
<?php 
    $tright = UNIX2DISPLAY($_SESSION['tright']);
    $tleft = UNIX2DISPLAY($_SESSION['tleft']);
    $profile = $_SESSION['profile'];
    $profilegroup = $_SESSION['profilegroup'];
    $detail_opts = $_SESSION['detail_opts'];
    $channels = array_keys($_SESSION['profileinfo']['channel']);
    $is_shadow = ($_SESSION['profileinfo']['type'] & 4) > 0;
    print "<h3>" . _("Profile") . ": <font size='+1'>{$profile}</font></h3>\n";
    $_tmp = explode('!', $detail_opts['channellist']);
    $graph_channels = count($_tmp) == 0 ? '@EMPTY' : implode(":", $_tmp);
    ?>
	<table style='font-size:14px;font-weight:bold;width:100%'>
	<tr>
<?php 
    for ($i = 1; $i < count($DisplayOrder); $i++) {
        $label = $DisplayOrder[$i];
        if ($label == $detail_opts['proto']) {
            $label = 'any';
        }
        print "<td>";
        print $label;
        print "</td>\n";
    }
    print "<td style='font-size:14px;font-weight:bold'>" . gettext("Profile info:") . "</td>\n";
    // Empty right element
    print "</tr><tr>\n";
    for ($i = 1; $i < count($DisplayOrder); $i++) {
        $label = $DisplayOrder[$i];
        if ($label == $detail_opts['proto']) {
            $label = 'any';
        }
        print "<td>\n";
        $arg = implode(" ", array($graph_channels, $label, $detail_opts['type'], $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 288, 100, 1, $detail_opts['logscale'], $detail_opts['linegraph']));
        $arg = urlencode($arg);
        print "<a href='{$self}?proto={$label}'> " . "<img src=rrdgraph.php?cmd=get-detailsgraph&profile=" . $_SESSION['profileswitch'] . "&arg={$arg} border='0' width='165' height='81' alt='{$label}'></a>\n";
        print "</td>\n";
    }
    print "<td style='vertical-align: bottom;'>\n";
    $str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tstart']);
    $expire = $_SESSION['profileinfo']['expire'];
    if ($expire == 0) {
        $expire = 'never';
    } else {
        $d = (int) ($expire / 24);
        $h = $expire % 24;
        $d_ext = $d == 1 ? '' : 's';
        $h_ext = $h == 1 ? '' : 's';
        if ($d) {
            $expire = "{$d} day{$d_ext} {$h} hour{$h_ext}";
        } else {
            $expire = "{$h} hour{$h_ext}";
        }
    }
    $maxsize = ScaleBytes($_SESSION['profileinfo']['maxsize'], 1, 1024.0);
    if ($maxsize == 0) {
        $maxsize = 'unlimited';
    }
    print "<table style='font-size:12px;font-weight:bold;border:none;width:100%'>\n";
    switch ($_SESSION['profileinfo']['type'] & 3) {
        case 0:
            $type = 'live';
            break;
        case 1:
            $type = 'history';
            break;
        case 2:
            $type = 'continuous';
            break;
        default:
            $type = 'unknown';
    }
    $type .= $is_shadow ? '&nbsp;/&nbsp;shadow' : '';
    print "<tr><td>" . _("Type") . ":</td><td>{$type}</td></tr>";
    print "<tr><td>" . _("Max") . ":</td><td>{$maxsize}</td></tr>";
    print "<tr><td>" . _("Exp") . ":</td><td>{$expire}</td></tr>";
    print "<tr><td>" . _("Start") . ":</td><td>{$str} {$TZname}</td></tr>\n";
    $str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tend']);
    print "<tr><td style='border:none'>" . _("End") . ":</td><td style='border:none'>{$str} {$TZname}</td></tr>\n";
    print "</table>\n";
    print "</td>\n";
    $arg = implode(" ", array($graph_channels, $detail_opts['proto'], $detail_opts['type'], $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 576, 200, 0, $detail_opts['logscale'], $detail_opts['linegraph']));
    $arg = urlencode($arg);
    ?>
	</tr>
	<tr>
		<td colspan='4' align="left"   valign="top">
			<img id='MainGraph' style='position:relative; top:0px; left:0px;' onclick="DragCursor.set(event);" src=rrdgraph.php?cmd=get-detailsgraph&profile=<?php 
    echo $_SESSION['profileswitch'];
    ?>
&arg=<?php 
    echo $arg;
    ?>
 border='0' alt='<?php 
    echo _("main-graph");
    ?>
'>
			<img id="CursorDragHandle" style="position:absolute;display:none; " src="icons/cursor-line.png" alt="<?php 
    echo _("Line Cursor");
    ?>
">
			<img id="StartDragHandle" 	style="position:absolute;display:none" src="icons/cursor-start.png" alt="<?php 
    echo _("Start Cursor");
    ?>
">
			<div id="StartLine" style="position: absolute;display:none; width: 1px; height: 200px; background-color: black;"></div>
			<div id="SpanBox"  style="position:absolute;display:none; height: 200px; background-color: #B1FFA1; filter:alpha(opacity=40); opacity:.40;"></div>
			<div id="StopLine"  style="position: absolute;display:none; width: 1px; height: 200px; background-color: black;"></div>
			<img id="StopDragHandle"  	style="position:absolute;display:none" src="icons/cursor-stop.png" alt="<?php 
    echo _("Stop Cursor");
    ?>
">
			<form style="display:inline;" name="slotselectform" id="slotselectform" action="<?php 
    echo $self;
    ?>
" method="POST">
				<input type="hidden" name="cursor_mode" id="cursor_mode" value="">
				<input type="hidden" name="tleft" id="tleft" value="">
				<input type="hidden" name="tright" id="tright" value="">
			</form>
		</td>
		<td style="vertical-align: bottom;"> 
				<table style="margin-bottom:1pt;border:none;width:100%">
				<tr>
					<td><span style='font-size:14px;font-weight:bold;margin-bottom:1pt'>
							t<SUB><?php 
    echo _("start");
    ?>
</SUB>
						</span>
					</td>
					<td style="font-size:16px;color:#555555;">
						<!-- input type="text" name="box_tleft" id="box_tleft" value="" SIZE="16" MAXLENGTH="16" style='font-size:10px;' readonly -->
						<b id='box_tleft'>- <?php 
    echo _("update");
    ?>
 -</b>
					</td>
				</tr><tr>
					<td><span style='font-size:14px;font-weight:bold;margin-bottom:1pt'>
							t<SUB><?php 
    echo _("end");
    ?>
</SUB>
						</span>
					</td>
					<td style="font-size:16px;color:#555555;">
						<!-- input type="text" name="box_tright" id="box_tright" value="" SIZE="16" MAXLENGTH="16" style='font-size:10px;' readonly -->
						<b id='box_tright'>- <?php 
    echo _("update");
    ?>
 -</b>
					</td>
				</tr>
				</table>

		<table style='font-size:14px;font-weight:bold;border:none;width:100%'>
<?php 
    for ($i = 1; $i < count($TypeOrder); $i++) {
        $label = $TypeOrder[$i];
        if ($label == $detail_opts['type']) {
            $label = 'flows';
        }
        // Make first letter uppercase of label to print
        $printlabel = strtoupper($label[0]) . substr($label, 1);
        print "<tr><td>" . gettext($printlabel) . "</td></tr>\n";
        print "<tr><td style='border:none'>\n";
        $arg = implode(" ", array($graph_channels, $detail_opts['proto'], $label, $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 288, 100, 1, $detail_opts['logscale'], $detail_opts['linegraph']));
        $arg = urlencode($arg);
        print "<a href='{$self}?type={$label}'> " . "<img src=rrdgraph.php?cmd=get-detailsgraph&profile=" . $_SESSION['profileswitch'] . "&arg={$arg} border='0' width='165' height='81' alt='{$label}'></a>";
        print "</td></tr>\n";
    }
    ?>
		</table>
		</td>
	</tr>
	<tr>

	<td colspan='4' style="border:none">
		<table border="0" style='width: 100%;margin:0pt;;border:none;width:100%'>
		<tr>
		<td style="border:none">
			<?php 
    echo _("Select");
    ?>
&nbsp;
			<select name="CursorMode" id="ModeSelector" onchange="SetCursorMode(<?php 
    echo $_SESSION['tstart'] . ", " . $_SESSION['tend'] . ", " . $_SESSION['profileinfo']['tstart'] . ", " . $_SESSION['tleft'] . ", " . $_SESSION['tright'] . ",576, {$RRDoffset}";
    ?>
)" size=1>
<?php 
    if ($detail_opts['cursor_mode'] == 1) {
        print "<option value='0'>" . _("Single Timeslot") . "\n";
        print "<option value='1' selected>" . _("Time Window") . "\n";
    } else {
        print "<option value='0' selected>" . _("Single Timeslot") . "\n";
        print "<option value='1'>" . _("Time Window") . "\n";
    }
    ?>
			</select>
		</td>

		<td style="text-align: right;border:none">
			<?php 
    echo _("Display");
    ?>
:&nbsp;
			<form action="<?php 
    echo $self;
    ?>
" style="display:inline;" method="POST">
			<select name='wsize' onchange='this.form.submit();' size=1>
<?php 
    $size_label = 'unknown';
    for ($i = 0; $i < count($WinSizeLabels); $i++) {
        if ($i == $detail_opts['wsize']) {
            print "<option value='{$i}' selected>" . $WinSizeLabels[$i] . "\n";
            $size_label = $WinSizeLabels[$i];
        } else {
            print "<option value='{$i}'>" . $WinSizeLabels[$i] . "\n";
        }
    }
    $status = $detail_opts['cursor_mode'] == 0 && !$is_shadow ? '' : 'disabled';
    $peak_search_label = $status == '' ? _("Search Peak") : _("Peak search not available");
    ?>
			</select>
			<input class="lbutton" name="adjust" value=" << " type="submit" title="<?php 
    echo _("Back");
    ?>
 <?php 
    echo $size_label;
    ?>
">&nbsp;
			<input class="lbutton" name="adjust" value=" < " type="submit" title="<?php 
    echo _("Previous time slot");
    ?>
">&nbsp;
			<input class="lbutton" name="adjust" value=" | " type="submit" title="<?php 
    echo _("Center cursor");
    ?>
">&nbsp;
			<input class="lbutton" name="adjust" value=" ^ " type="submit" <?php 
    echo $status;
    ?>
 title="<?php 
    echo $peak_search_label;
    ?>
">&nbsp;
			<input class="lbutton" name="adjust" value=" > " type="submit" title="<?php 
    echo _("Next time slot");
    ?>
">&nbsp;
			<input class="lbutton" name="adjust" value=" >> " type="submit" title="<?php 
    echo _("Forward");
    ?>
 <?php 
    echo $size_label;
    ?>
">&nbsp;
			<input class="lbutton" name="adjust" value=" >| " type="submit" title="<?php 
    echo _("Goto last slot");
    ?>
">
			</form>
		</td>
		</tr>
		</table>
	</td> <td style="border:none">
		<form action="<?php 
    echo $self;
    ?>
" method="POST">
			<table style="border:none;width:100%">
			<tr>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="logscale" value="0"
					<?php 
    if ($detail_opts['logscale'] == 0) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Lin Scale");
    ?>
				</td>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="linegraph" value="0"
					<?php 
    if ($detail_opts['linegraph'] == 0) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Stacked Graph");
    ?>
				</td>
			</tr>
			<tr>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="logscale" value="1"
					<?php 
    if ($detail_opts['logscale'] == 1) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Log Scale");
    ?>
				</td>
				<td style="border:none">
					<input type="radio" onClick='this.form.submit();' name="linegraph" value="1"
					<?php 
    if ($detail_opts['linegraph'] == 1) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Line Graph");
    ?>
				</td>
			</tr>
			</table>

		</form>
	</td>
	</tr><tr>
		<td colspan='4'></td>
		<td></td>
	</tr>
	</table>
<?php 
    if ($_SESSION['tleft'] == $_SESSION['tright']) {
        $tslot = "timeslot " . strftime("%b %d %Y - %H:%M", $_SESSION['tleft']);
    } else {
        $tslot = "timeslot " . strftime("%b %d %Y - %H:%M", $_SESSION['tleft']) . " - " . strftime("%b %d %Y - %H:%M", $_SESSION['tright']);
    }
    $num_channels = count(array_keys($_SESSION['profileinfo']['channel']));
    $proto_index = 1;
    foreach ($DisplayOrder as $p) {
        if ($detail_opts['proto'] == $p) {
            break;
        }
        $proto_index++;
    }
    $statpref = explode(':', $detail_opts['statpref']);
    $max_colspan = 0;
    for ($i = 0; $i < count($statpref); $i++) {
        $pref = $statpref[$i];
        if ($pref == 0) {
            $arrow_style[] = '';
            $arrow_style[] = 'style="display:none;"';
            $colspan[] = 5;
            $max_colspan += 5;
        } else {
            $arrow_style[] = 'style="display:none;"';
            $arrow_style[] = '';
            $statpref[$i] = $proto_index;
            $colspan[] = 1;
            $max_colspan += 1;
        }
    }
    $_i = 0;
    if ($detail_opts['statvisible'] == 1) {
        $stattable_style = '';
        $down_arrow_style = '';
        $right_arrow_style = 'style="display:none"';
    } else {
        $stattable_style = 'display:none;';
        $down_arrow_style = 'style="display:none"';
        $right_arrow_style = '';
    }
    ?>
	<br><br><b>
	<a href="#null" onClick="ShowHideStat();" 
		title="<?php 
    echo _("Hide Statistic");
    ?>
" ><IMG SRC="icons/arrow.yellow.down.png" name="flows" id="stat_arrow_down" border="0"
		<?php 
    echo $down_arrow_style;
    ?>
 align="left" alt="<?php 
    echo _("Hide stat table");
    ?>
"></a>
	<a href="#null" onClick="ShowHideStat();" 
		title="<?php 
    echo _("Show Statistic");
    ?>
" ><IMG SRC="icons/arrow.yellow.right.png" name="flows" id="stat_arrow_right" border="0"
		<?php 
    echo $right_arrow_style;
    ?>
 align="left" alt="<?php 
    echo _("Show stat table");
    ?>
"></a>
	Statistics <?php 
    echo $tslot;
    ?>
</b>
	<form action="<?php 
    echo $self;
    ?>
" method="POST" id="statsform">
	<input type="hidden" name="srctrigger" value="src">
	<table id="stattable" style='font-size:14px;font-weight:bold;<?php 
    echo $stattable_style;
    ?>
;border:none;width:100%'>
		<tr align='center'>
			<td class='theader' colspan="2"><?php 
    echo _("Channel");
    ?>
:</td>
			<td class='theader' id="label0" colspan='<?php 
    echo $colspan[0];
    ?>
'>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 0, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Collapse");
    ?>
" ><IMG SRC="icons/arrow.blue.down.png" name="flows" id="arrow0_down" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 0, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Expand");
    ?>
" ><IMG SRC="icons/arrow.blue.right.png" name="flows" id="arrow0_right" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a><?php 
    echo _("Flows");
    ?>
:
			</td>
			<td class='theader' id="label1" colspan='<?php 
    echo $colspan[1];
    ?>
'>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 1, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Collapse");
    ?>
" ><IMG SRC="icons/arrow.blue.down.png" name="flows" id="arrow1_down" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 1, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Expand");
    ?>
" ><IMG SRC="icons/arrow.blue.right.png" name="flows" id="arrow1_right" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a><?php 
    echo _("Packets");
    ?>
:
			</td>
			<td class='theader' id="label2" colspan='<?php 
    echo $colspan[2];
    ?>
'>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 2, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Collapse");
    ?>
" ><IMG SRC="icons/arrow.blue.down.png" name="flows" id="arrow2_down" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a>
				<a href="#null" onClick="CollapseExpandStat(<?php 
    echo $num_channels;
    ?>
, 2, <?php 
    echo $proto_index;
    ?>
);" 
					title="<?php 
    echo _("Expand");
    ?>
" ><IMG SRC="icons/arrow.blue.right.png" name="flows" id="arrow2_right" border="0"
					<?php 
    echo $arrow_style[$_i++];
    ?>
 align="left" alt="<?php 
    echo _("collapse");
    ?>
"></a><?php 
    echo _("Traffic");
    ?>
:
			</td>
		</tr>
		<tr>
		<th colspan="2">&nbsp;</td>
<?php 
    for ($i = 0; $i < 3; $i++) {
        $col = 1;
        foreach (array(gettext("all:"), 'tcp:', 'udp:', 'icmp:', gettext("other:")) as $_type) {
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<th id='id.0.{$i}.{$col}' {$_style}>{$_type}</td>";
            $col++;
        }
    }
    print "</tr>\n";
    // for simplified testing
    foreach (explode('!', $detail_opts['channellist']) as $channel) {
        $_SelectedChannels[$channel] = 1;
    }
    $row = 1;
    foreach (array_keys($_SESSION['profileinfo']['channel']) as $channel) {
        $has_perm = 0;
        foreach ($sensors_list as $s) {
            if ($channel == $s->get_name()) {
                $has_perm = 1;
            }
        }
        if (Session::am_i_admin()) {
            $has_perm = 1;
        }
        print "<tr>\n";
        # channel exists in profile
        $statinfo = ReadStat($profile, $profilegroup, $channel);
        $rateval = 1;
        if ($detail_opts['ratescale'] == 1) {
            $rateval = $_SESSION['tright'] - $_SESSION['tleft'] + 300;
        }
        $bgcolour = "bgcolor='" . $_SESSION['profileinfo']['channel'][$channel]['colour'] . "'";
        print "<td {$bgcolour} style='width:10px'></td>\n";
        if (!$has_perm) {
            print "<td align=left><input type='checkbox' name='{$channel}' value='{$channel}' onClick='this.form.submit();' disabled><font style='color:gray'>{$channel}</font> &nbsp</td>\n";
            $cellcolour = '';
        } elseif (array_key_exists($channel, $_SelectedChannels)) {
            print "<td align=left><input type='checkbox' name='{$channel}' value='{$channel}' onClick='this.form.submit();' checked>{$channel} &nbsp</td>\n";
            $cellcolour = "bgcolor='#f2f2f2'";
        } else {
            print "<td align=left><input type='checkbox' name='{$channel}' value='{$channel}' onClick='this.form.submit();'>{$channel} &nbsp</td>\n";
            $cellcolour = '';
        }
        # print flows
        $i = 0;
        $col = 1;
        $mark_char = ($_SESSION['profileinfo']['type'] & 4) > 0 ? 'S' : 'x';
        foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
            if ($statinfo) {
                $_val = ScaleValue($statinfo['flows' . $_type], $rateval);
            } else {
                $_val = $mark_char;
            }
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
            $col++;
        }
        # print packets
        $i = 1;
        $col = 1;
        foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
            if ($statinfo) {
                $_val = ScaleValue($statinfo['packets' . $_type], $rateval);
            } else {
                $_val = $mark_char;
            }
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
            $col++;
        }
        # prints bits
        $i = 2;
        $col = 1;
        foreach (array('', '_tcp', '_udp', '_icmp', '_other') as $_type) {
            if ($statinfo) {
                $_val = ScaleBytes($statinfo['traffic' . $_type], $rateval, 1000.0);
            } else {
                $_val = $mark_char;
            }
            if ($statpref[$i] == 0) {
                $_style = '';
            } else {
                if ($statpref[$i] == $col) {
                    $_style = '';
                } else {
                    $_style = 'style="display:none;"';
                }
            }
            print "<td {$cellcolour} id='id.{$row}.{$i}.{$col}' {$_style} align=right>{$_val}&nbsp;</td>";
            $col++;
        }
        print "</tr>\n";
        $row++;
    }
    ?>
		
		<tr><td colspan="2">
		<INPUT class="lbutton" TYPE="submit" NAME="MultipleSources" Value="<?php 
    echo _("All");
    ?>
">
		<INPUT class="lbutton" TYPE="submit" NAME="MultipleSources" Value="<?php 
    echo _("None");
    ?>
">
		</td>
		<td colspan='15' style='text-align: left;'>
		<?php 
    echo _("Display");
    ?>
:
		<input type="radio" onClick='this.form.submit();' name="ratescale" value="0"
		<?php 
    if ($detail_opts['ratescale'] == 0) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Sum");
    ?>
		<input type="radio" onClick='this.form.submit();' name="ratescale" value="1"
		<?php 
    if ($detail_opts['ratescale'] == 1) {
        print "checked";
    }
    ?>
 ><?php 
    echo _("Rate");
    ?>
 &nbsp;
<?php 
    if (!$statinfo) {
        print "x: " . _("No Data available");
    }
    ?>
		</td></tr>
	</table>
	</form>

    <script language="Javascript" type="text/javascript">
	window.onload=function() {
		SetCookieValue("statvisible", <?php 
    echo $detail_opts['statvisible'] ? 1 : 0;
    ?>
);
		var curdate = new Date();
		GMToffset  = <?php 
    echo $GMToffset;
    ?>
 + curdate.getTimezoneOffset() * 60;
		CursorMode = <?php 
    echo $detail_opts['cursor_mode'];
    ?>
;
		if ( CursorMode == 0 )
			SlotSelectInit(<?php 
    echo $_SESSION['tstart'] . ", " . $_SESSION['tend'] . ", " . $_SESSION['profileinfo']['tstart'] . ", " . $_SESSION['tleft'] . ",576, {$RRDoffset}";
    ?>
);
		else
			WSelectInit(<?php 
    echo $_SESSION['tstart'] . ", " . $_SESSION['tend'] . ", " . $_SESSION['profileinfo']['tstart'] . ", " . $_SESSION['tleft'] . ", " . $_SESSION['tright'] . ",576, {$RRDoffset}";
    ?>
);
<?php 
    if (array_key_exists('anchor', $_SESSION)) {
        print "location.hash='" . $_SESSION['anchor'] . "';";
        unset($_SESSION['anchor']);
    }
    ?>
	}
    </script>

<?php 
}