misp-dashboard/templates/geo.html

435 lines
18 KiB
HTML
Raw Normal View History

2017-10-25 16:22:14 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
2017-10-27 08:49:47 +02:00
<title>MISP live dashboard</title>
2017-10-25 16:22:14 +02:00
<!-- Bootstrap Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<!-- Custom Fonts -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css"
integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"
integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log=="
crossorigin=""></script>
</head>
<style>
.panel-body {
padding: 0px;
}
2017-10-26 16:59:02 +02:00
.panel {
margin-bottom: 10px;
}
2017-10-25 16:22:14 +02:00
.col-lg-6 {
padding-right: 5px;
padding-left: 5px;
}
.leftSepa {
border-left-color: rgb(221, 221, 221);
border-left-style: solid;
border-left-width: 2px;
padding-left: 8px;
}
.textTopHeader {
height: 50px;
text-align: center;
margin-left: 8px;
float: left;
padding-top: 9px;
2017-10-25 16:22:14 +02:00
}
.center {
display:block;
margin-left:auto;
margin-right:auto;
}
small {
font-size: 100%;
font-weight: bold;
}
</style>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0; padding-left: 15px;">
<div class="navbar-header">
2017-10-27 08:57:26 +02:00
<a class="navbar-brand" href="{{ url_for('geo') }}">MISP Geolocalisation</a>
<div id="ledsHolder" style="float: right; height: 50px;">
2017-10-26 09:22:03 +02:00
<div class='leftSepa textTopHeader'>
<strong>Zoom level:</strong>
<select id="zoom_selector">
<option value="18">18</option>
<option value="17">17</option>
<option value="15" selected>15</option>
<option value="13">13</option>
<option value="11">11</option>
<option value="9">9</option>
<option value="7">7</option>
2017-10-26 16:59:02 +02:00
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
2017-10-26 09:22:03 +02:00
</select>
</div>
<div class='leftSepa textTopHeader'>
<strong>Date: <input type="text" id="datepicker" size="30" style="margin-bottom: 5px;"></strong>
</div>
<div id="alertUpdate" class="textTopHeader alert alert-info" style="margin-left: 100px; Display: none;">Maps updated</div>
</div>
2017-10-25 16:22:14 +02:00
</div>
<!-- /.navbar-header -->
</nav>
<!-- Page Content -->
<div id="page-wrapper" style="margin: 0px; padding: 0px;">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div style="height: 10px;"></div>
<div class="col-lg-6">
<div class="col-lg-6">
<div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;">
2017-10-25 17:32:06 +02:00
<b id="topMap1Header">1. Top location</b>
2017-10-25 16:22:14 +02:00
</div>
<div id="panelbody" class="panel-body" style="">
<div id="topMap1" style="width:100%; height: calc(75vh / 3);"></div>
</div>
</div><!-- /.panel-body -->
<div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;">
2017-10-25 17:32:06 +02:00
<b id="topMap3Header">3. Top location</b>
2017-10-25 16:22:14 +02:00
</div>
<div id="panelbody" class="panel-body" style="">
<div id="topMap3" style="width:100%; height: calc(75vh / 3);"></div>
</div>
</div><!-- /.panel-body -->
<div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;">
2017-10-25 17:32:06 +02:00
<b id="topMap5Header">5. Top location</b>
2017-10-25 16:22:14 +02:00
</div>
<div id="panelbody" class="panel-body" style="">
<div id="topMap5" style="width:100%; height: calc(75vh / 3);"></div>
</div>
</div><!-- /.panel-body -->
</div><!-- /.col-lg-6-6 -->
<div class="col-lg-6">
<div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;">
2017-10-25 17:32:06 +02:00
<b id="topMap2Header">2. Top location</b>
2017-10-25 16:22:14 +02:00
</div>
<div id="panelbody" class="panel-body" style="">
<div id="topMap2" style="width:100%; height: calc(75vh / 3);"></div>
</div>
</div><!-- /.panel-body -->
<div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;">
2017-10-25 17:32:06 +02:00
<b id="topMap4Header">4. Top location</b>
2017-10-25 16:22:14 +02:00
</div>
<div id="panelbody" class="panel-body" style="">
<div id="topMap4" style="width:100%; height: calc(75vh / 3);"></div>
</div>
</div><!-- /.panel-body -->
<div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;">
2017-10-25 17:32:06 +02:00
<b id="topMap6Header">6. Top location</b>
2017-10-25 16:22:14 +02:00
</div>
<div id="panelbody" class="panel-body" style="">
<div id="topMap6" style="width:100%; height: calc(75vh / 3);"></div>
</div>
</div><!-- /.panel-body -->
</div><!-- /.col-lg-6-6 -->
</div><!-- /.col-lg-6 -->
<div class="col-lg-6">
<div class="panel panel-default" style="height: 100%;">
<div class="panel-heading bg-info" style="font-weight: bold;">
<b id="worldMapHeader">Hit map </b>
</div>
<div id="panelbody" class="panel-body" style="height: 100%;">
2017-10-26 16:59:02 +02:00
<div id="worldMap" style="width:100%; height: 30vh; position: relative;"></div>
2017-10-25 16:22:14 +02:00
</div>
<!-- /.panel-body -->
2017-10-26 16:59:02 +02:00
</div><!-- /.panel -->
2017-10-25 16:22:14 +02:00
2017-10-26 16:59:02 +02:00
<div class="panel panel-default" style="height: 100%;">
<div class="panel-heading bg-info" style="font-weight: bold; padding: 5px 10px;">
<b id="radiusHeader" style="font-size: 18px;">Geospatial information</b>
<strong class='leftSepa textTopHeader' style="float: none; padding: 11px;">Dates:
<input type="text" id="datepickerRadiusFrom" size="20" style="">
<input type="text" id="datepickerRadiusTo" size="20" style="">
</strong>
2017-10-26 17:13:11 +02:00
<button type="button" class="btn btn-default leftSepa" onclick="queryAndAddMarkers()">Query</button>
2017-10-26 16:59:02 +02:00
</div>
<div id="panelbody" class="panel-body" style="height: 100%;">
2017-10-26 17:13:11 +02:00
<div id="radiusMap" style="width:100%; height: 51vh; position: relative; z-index: 1;"></div>
2017-10-26 16:59:02 +02:00
</div>
<!-- /.panel-body -->
2017-10-25 16:22:14 +02:00
</div><!-- /.panel -->
2017-10-26 16:59:02 +02:00
2017-10-25 16:22:14 +02:00
</div><!-- /.col-lg-6 -->
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->
</div> <!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<!-- jQuery flot -->
<script src="{{ url_for('static', filename='js/jquery.flot.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.flot.pie.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.flot.resize.js') }}"></script>
<!-- Bootstrap Core JavaScript -->
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="text/css">
<link rel="stylesheet" href="{{ url_for('static', filename='css/jquery-jvectormap-2.0.3.css') }}" type="text/css" media="screen"/>
<script src="{{ url_for('static', filename='js/jquery-jvectormap-2.0.3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery-jvectormap-world-mill.js') }}"></script>
<link href="{{ url_for('static', filename='css/jquery-ui.min.css') }}" rel="stylesheet" type="text/css" />
<script src="{{ url_for('static', filename='js/jquery-ui.min.js') }}"></script>
2017-10-25 16:22:14 +02:00
<!-- Index -->
<script>
2017-10-25 17:45:00 +02:00
var regionhitsMax = 10;
var regionhits = {};
2017-10-25 16:22:14 +02:00
const OSMURL='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const OSMATTRIB='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
2017-10-26 09:22:03 +02:00
var ZOOMLEVEL = 15;
var updateFrequency = 1000*60*60*1 //1h
2017-10-25 16:22:14 +02:00
var allOpenStreetMap = {};
var savedMarker = {};
2017-10-26 16:59:02 +02:00
var savedMarkerRadius = [];
var datePickerWidget;
2017-10-26 16:59:02 +02:00
var datePickersRadiusWidget;
var radiusOpenStreetMap;
var circleRadius;
2017-10-25 16:22:14 +02:00
for(var i=1; i<7; i++) {
allOpenStreetMap[i] = L.map('topMap'+i).setView([0, 0], 0);
new L.TileLayer(OSMURL, {minZoom: 0, maxZoom: 18}).addTo(allOpenStreetMap[i]);
}
var vectorMapConfig = {
map: 'world_mill',
markers: [],
series: {
regions: [{
values: [],
min: 0,
max: 10,
2017-10-26 09:58:01 +02:00
scale: ['#003FBF','#0063BF','#0087BF','#00ACBF','#00BFAD','#00BF89','#00BF64','#00BF40','#00BF1C','#08BF00','#2CBF00','#51BF00','#75BF00','#99BF00','#BEBF00','#BF9B00','#BF7700','#BF5200','#BF2E00','#BF0900'],
2017-10-26 10:06:44 +02:00
normalizeFunction: 'linear',
2017-10-26 09:58:01 +02:00
legend: {
horizontal: true
}
2017-10-25 16:22:14 +02:00
}]
},
2017-10-25 17:45:00 +02:00
onRegionTipShow: function(e, el, code){
el.html(el.html()+' ('+regionhits[code]+')');
}
2017-10-25 16:22:14 +02:00
}
2017-10-25 17:32:06 +02:00
function updateTopMaps(dayNum) {
$.getJSON("{{ url_for('getTopCoord') }}?dayNum="+dayNum, function(list){
for(var i=0; i<6 && i<list.length; i++) {
// create marker + flyToIt
2017-10-25 17:32:06 +02:00
coordJson = JSON.parse(list[i][0]);
allOpenStreetMap[i+1].flyTo([coordJson.lat, coordJson.lon], ZOOMLEVEL);
// update marker
var markerToUpdate = savedMarker[i+1];
if (markerToUpdate != undefined) {
markerToUpdate.setLatLng({lat: coordJson.lat, lng: coordJson.lon});
markerToUpdate._popup._content = 'lat: '+coordJson.lat+', lon: '+coordJson.lon+' - '+list[i][1];
markerToUpdate.update();
} else { // create new marker
var marker = L.marker([coordJson.lat, coordJson.lon]).addTo(allOpenStreetMap[i+1]);
savedMarker[i+1] = marker;
2017-10-27 08:58:55 +02:00
marker.bindPopup('lat: '+coordJson.lat+', lon: '+coordJson.lon+' (<strong>'+list[i][1]+'</strong>)').openPopup();
}
2017-10-25 17:32:06 +02:00
}
});
}
2017-10-25 17:45:00 +02:00
function updateWorldMap(dayNum) {
2017-10-25 17:32:06 +02:00
$.getJSON("{{ url_for('getHitMap') }}?dayNum="+dayNum, function(list){
for(var i=0; i<list.length; i++) {
var rCode = list[i][0];
var rNum = list[i][1];
2017-10-25 17:45:00 +02:00
update_region(rCode, rNum);
2017-10-25 17:32:06 +02:00
}
});
}
2017-10-25 17:45:00 +02:00
function update_region(regionCode, num) {
regionhits[regionCode] = num;
// Force recomputation of min and max for correct color scaling
regionhitsMax = regionhitsMax >= regionhits[regionCode] ? regionhitsMax : regionhits[regionCode];
worldMapObj.series.regions[0].params.max = regionhitsMax;
2017-10-26 09:58:01 +02:00
worldMapObj.series.regions[0].legend.render();
2017-10-25 17:45:00 +02:00
// Update data
worldMapObj.series.regions[0].setValues(regionhits);
}
2017-10-26 16:59:02 +02:00
function updateRadius(e) {
var curObj = e.target;
var curCoord = curObj.getCenter();
var zoom = curObj.zoom;
var scale = getScale(radiusOpenStreetMap.getZoom());
circleRadius.setRadius(scale);
circleRadius.setLatLng(curCoord);
}
function getScale(zoom) {
return 64 * Math.pow(2, (18-zoom));
}
function queryAndAddMarkers() {
var radius_km = circleRadius.getRadius() / 1000;
var coord = circleRadius._latlng;
var dateStart = datePickersRadiusWidgetFrom.datepicker("getDate").getTime() / 1000;
var dateEnd = datePickersRadiusWidgetTo.datepicker("getDate").getTime() / 1000;
2017-10-26 17:17:58 +02:00
$.getJSON("{{ url_for('getCoordsByRadius') }}?dateStart="+dateStart+"&dateEnd="+dateEnd+"&centerLat="+coord.lat+"&centerLon="+coord.lng+"&radius="+radius_km, function(allList){
2017-10-26 17:57:31 +02:00
console.log(allList);
2017-10-26 16:59:02 +02:00
// remove old markers
for (var i in savedMarkerRadius) {
savedMarkerRadius[i].remove(); // remove marker
}
2017-10-26 17:17:58 +02:00
for (var listIndex in allList) {
2017-10-26 17:57:31 +02:00
var curMarker = allList[listIndex];
var dataText = "";
var coordJson = curMarker[1];
for (var dataI in curMarker[0]) {
var jsonData = JSON.parse(curMarker[0][dataI])
dataText += '<strong>'+jsonData.categ+': </strong> '+jsonData.value + "<br>"
2017-10-26 17:17:58 +02:00
}
2017-10-26 17:57:31 +02:00
var marker = L.marker([coordJson[1], coordJson[0]]).addTo(radiusOpenStreetMap);
savedMarkerRadius.push(marker);
marker.bindPopup(dataText, {autoClose:false}).openPopup();
2017-10-26 16:59:02 +02:00
}
});
}
function days_between(date1, date2) {
var ONEDAY = 60*60*24*1000;
var diff_ms = Math.abs(date1.getTime() - date2.getTime());
return Math.round(diff_ms/ONEDAY);
}
function updateAll() {
var currentDate = datePickerWidget.datepicker( "getDate" );
var now = new Date();
var numDay = days_between(now, currentDate);
updateTopMaps(numDay);
updateWorldMap(numDay);
}
2017-10-25 17:32:06 +02:00
$(document).ready(function () {
$('#worldMap').vectorMap(vectorMapConfig);
worldMapObj = $("#worldMap").vectorMap('get','mapObject');
/* Create the datepicker and button*/
var datePickerOptions = {
showOn: "button",
minDate: -31,
maxDate: 0,
buttonImage: "{{ url_for('static', filename='pics/calendar.gif') }}",
buttonImageOnly: true,
buttonText: "Select date",
showAnim: "slideDown",
onSelect: updateAll
};
2017-10-26 16:59:02 +02:00
var datePickerRadiusOptions = {
showOn: "button",
minDate: -31,
maxDate: 0,
buttonImage: "{{ url_for('static', filename='pics/calendar.gif') }}",
buttonImageOnly: true,
buttonText: "Select date",
showAnim: "slideDown",
};
datePickerWidget = $( "#datepicker" )
datePickerWidget.datepicker(datePickerOptions);
2017-10-26 09:22:03 +02:00
datePickerWidget.datepicker("setDate", new Date());
2017-10-26 16:59:02 +02:00
// radius
2017-10-27 08:30:04 +02:00
radiusOpenStreetMap = L.map('radiusMap').setView([30, 0], 2);
2017-10-26 17:13:11 +02:00
new L.TileLayer(OSMURL, {minZoom: 0, maxZoom: 18}).addTo(radiusOpenStreetMap);
2017-10-26 16:59:02 +02:00
datePickersRadiusWidgetFrom = $( "#datepickerRadiusFrom" )
datePickersRadiusWidgetFrom.datepicker(datePickerRadiusOptions);
datePickersRadiusWidgetFrom.datepicker("setDate", new Date());
datePickersRadiusWidgetTo = $( "#datepickerRadiusTo" )
datePickersRadiusWidgetTo.datepicker(datePickerRadiusOptions);
datePickersRadiusWidgetTo.datepicker("setDate", new Date());
circleRadius = L.circle(radiusOpenStreetMap.getCenter(), {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.4,
radius: getScale(radiusOpenStreetMap.getZoom())
}).addTo(radiusOpenStreetMap);
radiusOpenStreetMap.on('move', updateRadius);
2017-10-26 09:22:03 +02:00
$( "#zoom_selector" ).change(function() {
var sel = parseInt($( this ).val());
ZOOMLEVEL = sel;
updateAll();
});
2017-10-26 16:59:02 +02:00
updateAll();
setInterval(function(){
updateAll();
$("#alertUpdate").fadeIn(2200).fadeOut(2200);
}, updateFrequency);
2017-10-25 17:32:06 +02:00
});
2017-10-25 16:22:14 +02:00
</script>
</body>
</html>