<% extend ApplicationHelper %>

<% content_for :pdf_header do %>
	<br />
	<i><%= @start_time.strftime('%A, %B %d, %Y %I:%M %p') %> - <%= @end_time.strftime('%A, %B %d, %Y %I:%M %p') %></i>
<% end %>

<% content_for :footer do %>

	<script type="text/javascript">
		
	chart = new Highcharts.Chart({
	      chart: {
	         renderTo: 'events-graph',
	         defaultSeriesType: 'spline',
	         marginRight: 80,
					 marginLeft: 80,
					 marginTop: 50,
	         marginBottom: 50,
					 borderColor: 'transparent',
					 borderWidth: 0,
           backgroundColor: '#fff'
	      },
        credits: {
            enabled: false
        },
	      title: {
	         text: 'Event Count vs Time By Sensor',
	         x: -20 //center
	      },
				plotOptions: { series: { enableMouseTracking: false, shadow: false, animation: false } },
	      xAxis: {
					categories: [<%= @axis %>],
	        title: {
							margin: 10,
							<% if (@range == 'year' || @range == 'quarter') %>
								text: 'Month of Year'
							<% elsif (@range == 'month' || @range == 'last_month') %>
								text: 'Date of Month'
							<% elsif (@range == 'week' || @range == 'last_week') %>
								text: 'Date Of Week'
							<% else %>
								text: 'Hour of Day'
							<% end %>
	         }
	      },
	      yAxis: {
	         title: {
	            text: 'Event Count'
	         },
	         plotLines: [{
	            value: 0,
	            width: 1,
	            color: '#808080'
	         }]
	      },
	      tooltip: {
		       formatter: function() {
	                   return '<b>'+ this.series.name +'</b><br/>'+ this.y + ' Events';
	         }
        },
	      legend: {
	         layout: 'vertical',
	         align: 'right',
	         verticalAlign: 'top',
	         x: 0,
	         y: 0,
	         borderWidth: 0,
					 borderRadius: 0,
					 borderColor: '#ddd',
					 backgroundColor: '#fff'
	      },
	      series: <%= @sensor_metrics.to_json.html_safe %>
	   });
	
		chart2 = new Highcharts.Chart({
		      chart: {
		         renderTo: 'protocol-graph',
		         defaultSeriesType: 'spline',
		         marginRight: 80,
						 marginLeft: 80,
						 marginTop: 50,
		         marginBottom: 50,
						 borderColor: 'transparent',
						 borderWidth: 0,
             backgroundColor: '#fff'
          },
          credits: {
            enabled: false
          },
		      title: {
		         text: 'Protocol Count vs Time',
		         x: -20 //center
		      },
		      xAxis: {
						categories: [<%= @axis %>],
		        title: {
								margin: 10,
								<% if (@range == 'year' || @range == 'quarter') %>
									text: 'Month of Year'
								<% elsif (@range == 'month' || @range == 'last_month') %>
									text: 'Date of Month'
								<% elsif (@range == 'week' || @range == 'last_week') %>
									text: 'Date Of Week'
								<% else %>
									text: 'Hour of Day'
								<% end %>
		         }
		      },
					plotOptions: { series: { enableMouseTracking: false, shadow: false, animation: false } },
		      yAxis: {
		         title: {
		            text: 'Protocol Count'
		         },
		         plotLines: [{
		            value: 0,
		            width: 1,
		            color: '#808080'
		         }]
		      },
		      tooltip: {
		         formatter: function() {
		                   return '<b>'+ this.series.name +'</b><br/>'+ this.y + ' Events';
		         }
		      },
		      legend: {
		         layout: 'vertical',
		         align: 'right',
		         verticalAlign: 'top',
		         x: 0,
		         y: 0,
		         borderWidth: 0,
						 borderRadius: 0,
						 borderColor: '#ddd',
						 backgroundColor: '#fff'
		      },
		      series: [{
						name: 'TCP',
						data: [<%= @tcp.join(', ') %>]
					},{
						name: 'UDP',
						data: [<%= @udp.join(', ') %>]
					},{
						name: 'ICMP',
						data: [<%= @icmp.join(', ') %>]
					}]
		   });
		
			chart3 = new Highcharts.Chart({
			      chart: {
			         renderTo: 'severity-graph',
			         defaultSeriesType: 'spline',
			         marginRight: 80,
							 marginLeft: 80,
							 marginTop: 50,
			         marginBottom: 50,
							 borderColor: 'transparent',
							 borderWidth: 0,
               backgroundColor: '#fff'
            },
            credits: {
              enabled: false
            },
			      title: {
			         text: 'Severity Count vs Time',
			         x: -20 //center
			      },
						plotOptions: { series: { enableMouseTracking: false, shadow: false, animation: false } },
			      xAxis: {
							categories: [<%= @axis %>],
			        title: {
									margin: 10,
									<% if (@range == 'year' || @range == 'quarter') %>
										text: 'Month of Year'
									<% elsif (@range == 'month' || @range == 'last_month') %>
										text: 'Date of Month'
									<% elsif (@range == 'week' || @range == 'last_week') %>
										text: 'Date Of Week'
									<% else %>
										text: 'Hour of Day'
									<% end %>
			         }
			      },
			      yAxis: {
			         title: {
			            text: 'Severity Count'
			         },
			         plotLines: [{
			            value: 0,
			            width: 1,
			            color: '#808080'
			         }]
			      },
			      tooltip: {
			         formatter: function() {
			                   return '<b>'+ this.series.name +'</b><br/>'+ this.y + ' Events';
			         }
			      },
			      legend: {
			         layout: 'vertical',
			         align: 'right',
			         verticalAlign: 'top',
			         x: 0,
			         y: 0,
			         borderWidth: 0,
							 borderRadius: 0,
							 borderColor: '#ddd',
							 backgroundColor: '#fff'
			      },
            series: [{
              name: 'High Severity',
              color: sev1_bg_color,
              data: [<%= @high.join(', ') %>]
            },{
              name: 'Medium Severity',
              color: sev2_bg_color,
              data: [<%= @medium.join(', ') %>]
            },{
              name: 'Low Severity',
              color: sev3_bg_color,
              data: [<%= @low.join(', ') %>]
            }]
			   });
		
    $('#sev1-graph').sparkline([<%= @high.join(',') %>], { 
        barWidth: 6, height: 40, type: 'bar', barColor: sev1_bg_color 
     });
    
    $('#sev2-graph').sparkline([<%= @medium.join(',') %>], { 
      barWidth: 6, height: 40, type: 'bar', barColor: sev2_bg_color 
    });

    $('#sev3-graph').sparkline([<%= @low.join(',') %>], { 
      barWidth: 6, height: 40, type: 'bar', barColor: sev3_bg_color 
    });
		
	</script>

<% end %>

<div class='table-holder'>
	<h2>Sensors</h2>
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<th>Name</th>
			<th>Event Count</th>
		</tr>
		<% @sensor_metrics.sort{|a,b| -1*(a[1]<=>b[1]) }.each do |hash| %>
		<tr>
			<td><%= hash[:name] %></td>
			<td style='width:100px'><%= hash[:data].sum %></td>
		</tr>
		<% end %>
	</table>
	
	<div id='events-graph' style='' class='dashboard-graph'></div>
	
</div>

<div class='table-holder'>
	<h2>Severities</h2>
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<th>High Severity (<%= @high.sum %>)</th>
			<th>Medium Severity (<%= @medium.sum %>)</th>
			<th>Low Severity (<%= @low.sum %>)</th>
			<th>Total</th>
		</tr>
		<tr>
			<td style='width:200px'><div id="sev1-graph" style='float:left;'></div></td>
			<td style='width:200px'><div id="sev2-graph" style='float:left;'></div></td>
			<td style='width:200px'><div id="sev3-graph" style='float:left;'></div></td>
			<td style='width:100px'><%= @event_count %></td>
		</tr>
	</table>
	
	<div id='severity-graph' style='' class='dashboard-graph'></div>
	
</div>

<div class='table-holder'>
	<h2>Protocols</h2>
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<th>TCP Count</th>
			<th>UDP Count</th>
			<th>ICMP Count</th>
			<th>Total</th>
		</tr>
		<tr>
			<td style='width:200px'><%= @tcp.sum %></div></td>
			<td style='width:200px'><%= @udp.sum %></td>
			<td style='width:200px'><%= @icmp.sum %></td>
			<td style='width:100px'><%= @event_count %></td>
		</tr>
	</table>
	
	<div id='protocol-graph' style='' class='dashboard-graph'></div>
	
</div>

<div class='table-holder'>
	<h2>Top 15 Signatures</h2>
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<th>Signature Name</th>
			<th>Percentage</th>
			<th>Event Count</th>
		</tr>
		<% sig_total = @signature_metrics.sort{|a,b| -1*(a[1]<=>b[1]) }.map(&:last).sum %>
		<% @signature_metrics.sort{|a,b| -1*(a[1]<=>b[1]) }.each do |name, count| %>
			<tr>
				<td><%= truncate(name.to_s, :length => 65) %></td>
				<td style='width:100px'><%= percentage_for(count, sig_total) %>%</td>
				<td style='width:100px'><%= count %></td>
			</tr>
		<% end %>
	</table>
</div>

<div class='table-holder'>
	<h2>Top 10 Source Addresses</h2>
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<th>Source IP Address</th>
			<th>Percentage</th>
			<th>Event Count</th>
		</tr>

		<% source_total = @src_metrics.map(&:last).sum %>
		<% src_count = 0 %>
		<% @src_metrics.sort{|a,b| -1*(a[1]<=>b[1]) }.each do |name, count| %>
		
		<% break if src_count >= 10 %>
			<tr>
				<td><%= name %></td>
				<td style='width:100px'><%= percentage_for(count, source_total) %>%</td>
				<td style='width:100px'><%= count %></td>
			</tr>
			
			<% src_count += 1 %>
			
		<% end %>

	</table>
</div>

<div class='table-holder'>
	<h2>Top 10 Destination Addresses</h2>
	<table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<th>Destination IP Address</th>
			<th>Percentage</th>
			<th>Event Count</th>
		</tr>

		<% destination_total = @dst_metrics.map(&:last).sum %>
		<% dst_count = 0 %>
		<% @dst_metrics.sort{|a,b| -1*(a[1]<=>b[1]) }.each do |name, count| %>
		<% break if dst_count >= 10 %>
		
			<tr>
				<td><%= name %></td>
				<td style='width:100px'><%= percentage_for(count, destination_total) %>%</td>
				<td style='width:100px'><%= count %></td>
			</tr>
			
			<% dst_count += 1 %>
			
		<% end %>

	</table>
</div>
