hover info + clickk to reload + websocket reload + readme
This commit is contained in:
		
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							@@ -13,4 +13,16 @@ npm install
 | 
			
		||||
### Start Server
 | 
			
		||||
``` sh
 | 
			
		||||
npm start
 | 
			
		||||
```
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Usage
 | 
			
		||||
> :notebook: **Open in browser**: ```http://<ADRESS>:3100```
 | 
			
		||||
####Features 
 | 
			
		||||
* Automatic refresh on new Data
 | 
			
		||||
* Manual refresh on left-click
 | 
			
		||||
* Click on arc reveals whole "Ntopng Alert"
 | 
			
		||||
* Hover on arc reveals src/dest ip/hostname
 | 
			
		||||
#### Colors
 | 
			
		||||
* Orange arc is a bidirectional request (sender and receiver are swapped)
 | 
			
		||||
* Red side of arc is receiving
 | 
			
		||||
* Green side of arc is sending
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								app.js
									
									
									
									
									
								
							@@ -5,11 +5,16 @@ var cookieParser = require('cookie-parser');
 | 
			
		||||
var logger = require('morgan');
 | 
			
		||||
var cors = require('cors')
 | 
			
		||||
 | 
			
		||||
var indexRouter = require('./routes/index');
 | 
			
		||||
var usersRouter = require('./routes/users');
 | 
			
		||||
 | 
			
		||||
var app = express();
 | 
			
		||||
 | 
			
		||||
// var expressWs = require('express-ws')(app);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var indexRouter = require('./routes/index');
 | 
			
		||||
var usersRouter = require('./routes/users');
 | 
			
		||||
// view engine setup
 | 
			
		||||
app.set('views', path.join(__dirname, 'views'));
 | 
			
		||||
app.set('view engine', 'jade');
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
var alerts = [];
 | 
			
		||||
var alertDates = []
 | 
			
		||||
 | 
			
		||||
const {
 | 
			
		||||
    v4: uuidv4
 | 
			
		||||
} = require('uuid');
 | 
			
		||||
const {v4: uuidv4} = require('uuid');
 | 
			
		||||
function addAlert(first_seen, srv_city_name, ip_version, action, pool_id, srv_continent_name, score, entity_val, vlan_id, cli2srv_bytes, cli_country_name, entity_id, srv_asn, l7_proto, is_cli_attacker, srv_name, srv_ip, proto, json, srv_country_name, community_id, alert_id, is_srv_attacker, srv_blacklisted, alerts_map, srv_os, cli_localhost, cli_asn, srv2cli_packets, cli2srv_packets, tstamp, cli_name, cli_continent_name, srv2cli_bytes, l7_cat, ifid, observation_point_id, srv_localhost, cli_port, cli_blacklisted, dns_last_query, is_flow_alert, srv_port, l7_master_proto, is_cli_victim, cli_ip, cli_city_name, cli_os, is_srv_victim){
 | 
			
		||||
// function addAlert(srv_name, srv_ip, srv_port, json, cli_ip, cli_port){
 | 
			
		||||
    var data = {
 | 
			
		||||
@@ -57,11 +56,44 @@ function addAlert(first_seen, srv_city_name, ip_version, action, pool_id, srv_co
 | 
			
		||||
        cli_city_name:cli_city_name,
 | 
			
		||||
        cli_os:cli_os,
 | 
			
		||||
        is_srv_victim:is_srv_victim
 | 
			
		||||
      }
 | 
			
		||||
      if(!alerts.some(x => x.cli_ip === data.cli_ip && x.srv_ip === data.srv_ip)) {
 | 
			
		||||
          alerts.push(data);
 | 
			
		||||
          return data.uid
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(!alerts.some(x => x.cli_ip === data.cli_ip && x.srv_ip === data.srv_ip)) {
 | 
			
		||||
        const date = new Date();
 | 
			
		||||
        const nowminutes = date.getMinutes();
 | 
			
		||||
        if(alertDates.some(x => x.minute === nowminutes)){
 | 
			
		||||
            const dataIndex = alertDates.findIndex(ad => ad.minute === nowminutes);
 | 
			
		||||
            alertDates[dataIndex].uids.push(data.uid);
 | 
			
		||||
        }else{
 | 
			
		||||
            var alertMinute = {
 | 
			
		||||
                uids: [data.uid],
 | 
			
		||||
                date: date,
 | 
			
		||||
                minute: nowminutes
 | 
			
		||||
            }
 | 
			
		||||
            alertDates.push(alertMinute)
 | 
			
		||||
        }
 | 
			
		||||
        alerts.push(data);
 | 
			
		||||
        return data.uid
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delAlerts(uids){
 | 
			
		||||
    uids.forEach(uid => delAlert(uid))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delAlert(uid){
 | 
			
		||||
    console.log(uid)
 | 
			
		||||
    alerts = alerts.filter(a => a.uid !== uid)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delAlertDate(date){
 | 
			
		||||
    console.log(date)
 | 
			
		||||
    alertDates = alertDates.filter(ad => ad.date !== date )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getAlertDates(){
 | 
			
		||||
    return alertDates;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getAlerts(){
 | 
			
		||||
@@ -69,11 +101,14 @@ function getAlerts(){
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getAlert(uid){
 | 
			
		||||
    return alerts.filter(i => i.uid === uid);
 | 
			
		||||
    return alerts.filter(i => i.uid === uid)[0];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    getAlerts,
 | 
			
		||||
    getAlert,
 | 
			
		||||
    addAlert
 | 
			
		||||
    addAlert,
 | 
			
		||||
    getAlertDates,
 | 
			
		||||
    delAlertDate,
 | 
			
		||||
    delAlerts
 | 
			
		||||
};
 | 
			
		||||
@@ -27,25 +27,35 @@ var settings = {
 | 
			
		||||
        },
 | 
			
		||||
        arc: {
 | 
			
		||||
            default: 1.1
 | 
			
		||||
        },
 | 
			
		||||
        globe: {
 | 
			
		||||
            arcDashLength: 0.4,
 | 
			
		||||
            arcAltitudeAutoScale: 0.4,
 | 
			
		||||
            arcDashGap: 0.1,
 | 
			
		||||
            arcDashInitialGap: 0.1,
 | 
			
		||||
            arcDashAnimateTime: 7000,
 | 
			
		||||
            arcStroke: 0.5,
 | 
			
		||||
            labelSize: 0,
 | 
			
		||||
            labelDotRadius: 0.4,
 | 
			
		||||
            labelResolution: 2
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    timer:{
 | 
			
		||||
        del: 30
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var geoip = require('fast-geoip');
 | 
			
		||||
 | 
			
		||||
async function addArc(src, dest, uid){
 | 
			
		||||
    const arcName = src + " -> " + dest;
 | 
			
		||||
async function addArc(src, dest, uid, src_name, dest_name){
 | 
			
		||||
    const arcName = src_name + " -> " + dest_name;
 | 
			
		||||
    var geoSrc = undefined;
 | 
			
		||||
    var startLat = undefined;
 | 
			
		||||
    var startLng = undefined;
 | 
			
		||||
    var geoDest = undefined;
 | 
			
		||||
    var endLat = undefined;
 | 
			
		||||
    var endLng = undefined;
 | 
			
		||||
    if(data.arc.some(x => x.name === arcName)) {
 | 
			
		||||
        console.log("is scho da")
 | 
			
		||||
    }else{
 | 
			
		||||
        console.log(src.includes("192.168.1.") || src.includes("127.0.0.1"))
 | 
			
		||||
        console.log(dest.includes("192.168.1.") || dest.includes("127.0.0.1"))
 | 
			
		||||
    if(!data.arc.some(x => x.src === src && x.dest === dest)) {
 | 
			
		||||
        if (src.includes("192.168.1.") || src.includes("127.0.0.1")) {
 | 
			
		||||
            startLat = round(settings.location.home.lat, settings.location.precision)
 | 
			
		||||
            startLng = round(settings.location.home.lng, settings.location.precision)
 | 
			
		||||
@@ -70,6 +80,7 @@ async function addArc(src, dest, uid){
 | 
			
		||||
                endLng = round(settings.location.home.lng, settings.location.precision)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        var txrx = [{src: src, dest: dest, src_name: src_name, dest_name: dest_name}];
 | 
			
		||||
        var dat = {
 | 
			
		||||
            uid: uid,
 | 
			
		||||
            name: arcName,
 | 
			
		||||
@@ -78,12 +89,14 @@ async function addArc(src, dest, uid){
 | 
			
		||||
            endLat: endLat,
 | 
			
		||||
            endLng: endLng,
 | 
			
		||||
            color: settings.colors.arc.default,
 | 
			
		||||
            stroke: settings.sizes.arc.default
 | 
			
		||||
            stroke: settings.sizes.arc.default,
 | 
			
		||||
            src: src,
 | 
			
		||||
            dest: dest,
 | 
			
		||||
            src_name: src_name,
 | 
			
		||||
            dest_name: dest_name,
 | 
			
		||||
            txrx: txrx
 | 
			
		||||
        }
 | 
			
		||||
        console.log(arcName)
 | 
			
		||||
        if(data.arc.some(x => x.startLat === startLat && x.startLng === startLng && x.endLat === endLat && x.endLng === endLng)){
 | 
			
		||||
            console.log("is scho da 2")
 | 
			
		||||
        }else {
 | 
			
		||||
        if(!data.arc.some(x => x.startLat === startLat && x.startLng === startLng && x.endLat === endLat && x.endLng === endLng)){
 | 
			
		||||
            const newUid = addLoc(arcName, startLat, startLng, uid)
 | 
			
		||||
            dat.uid = newUid;
 | 
			
		||||
            if (!data.arc.some(x => x.startLat === startLat && x.startLng === startLng && x.endLat === endLat && x.endLng === endLng)) {
 | 
			
		||||
@@ -93,18 +106,18 @@ async function addArc(src, dest, uid){
 | 
			
		||||
                } else {
 | 
			
		||||
                    const dataIndex = data.arc.findIndex(x => x.startLat === endLat && x.startLng === endLng && x.endLat === startLat && x.endLng === startLng);
 | 
			
		||||
                    data.arc[dataIndex].color = settings.colors.arc.dualsender;
 | 
			
		||||
                    data.arc[dataIndex].txrx.push({src: dat.src, dest: dat.dest, src_name: dat.src_name, dest_name: dat.dest_name})
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                const dataIndex = data.arc.findIndex(x => x.startLat === startLat && x.startLng === startLng && x.endLat === endLat && x.endLng === endLng);
 | 
			
		||||
                const arcuid = data.arc[dataIndex].uid;
 | 
			
		||||
                var loc = getLoc(arcuid)
 | 
			
		||||
                loc.color = settings.colors.loc.dualsender;
 | 
			
		||||
                loc.txrx.push({src: dat.src, dest: dat.dest, src_name: dat.src_name, dest_name: dat.dest_name})
 | 
			
		||||
                editLoc(loc);
 | 
			
		||||
                console.log("selbe richtiung schon da")
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    console.log("NACH IS SCHO DA")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function round(value, precision) {
 | 
			
		||||
@@ -112,14 +125,16 @@ function round(value, precision) {
 | 
			
		||||
    return Math.round(value * multiplier) / multiplier;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function addLoc(name, lat, lng, uid){
 | 
			
		||||
function addLoc(name, lat, lng, uid, src, dest, src_name, dest_name){
 | 
			
		||||
    var txrx = [{src: src, dest: dest, src_name: src_name, dest_name: dest_name}]
 | 
			
		||||
    var dat = {
 | 
			
		||||
        uid: uid,
 | 
			
		||||
        name: name,
 | 
			
		||||
        lat: lat,
 | 
			
		||||
        lng: lng,
 | 
			
		||||
        size: settings.sizes.loc.default,
 | 
			
		||||
        color: settings.colors.loc.default
 | 
			
		||||
        color: settings.colors.loc.default,
 | 
			
		||||
        txrx: txrx
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    if(!data.loc.some(x => x.lat === lat && x.lng === lng)) {
 | 
			
		||||
@@ -127,7 +142,7 @@ function addLoc(name, lat, lng, uid){
 | 
			
		||||
        return dat.uid
 | 
			
		||||
    }else{
 | 
			
		||||
        const dataIndex = data.loc.findIndex(obj => obj.lat === lat && obj.lng === lng);
 | 
			
		||||
        data.loc[dataIndex].name = data.loc[dataIndex].name + "<br>\n" + name;
 | 
			
		||||
        data.loc[dataIndex].name = data.loc[dataIndex].name + "\n" + name;
 | 
			
		||||
        return data.loc[dataIndex].uid
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -145,10 +160,13 @@ function getData(){
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getDisplayData(){
 | 
			
		||||
    return {
 | 
			
		||||
        arc: filterUid(data.arc),
 | 
			
		||||
        loc: filterUid(data.loc)
 | 
			
		||||
    }
 | 
			
		||||
    var ret = data;
 | 
			
		||||
    ret.settings = settings
 | 
			
		||||
    return ret
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getSettigns(){
 | 
			
		||||
    return settings;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function filterUid(tofilter){
 | 
			
		||||
@@ -177,7 +195,26 @@ function editLoc(loc){
 | 
			
		||||
    data.loc[dataIndex] = loc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delUids(uids){
 | 
			
		||||
    uids.forEach(uid => delUid(uid))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delUid(uid){
 | 
			
		||||
    console.log("delglobe")
 | 
			
		||||
    console.log(uid)
 | 
			
		||||
    delArc(uid);
 | 
			
		||||
    delLoc(uid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delLoc(uid){
 | 
			
		||||
    data.loc = data.loc.filter(loc => loc.uid !== uid)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function delArc(uid){
 | 
			
		||||
    data.arc = data.arc.filter(arc => arc.uid !== uid)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    addArc, addLoc, getLocData, getArcColor, getData, getArcData, getLocColor, getDisplayData
 | 
			
		||||
    addArc, addLoc, getLocData, getArcColor, getData, getArcData, getLocColor, getDisplayData, delUids, getSettigns
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										52
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										52
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -16,6 +16,7 @@
 | 
			
		||||
        "http-errors": "~1.6.3",
 | 
			
		||||
        "jade": "~1.11.0",
 | 
			
		||||
        "morgan": "~1.9.1",
 | 
			
		||||
        "node-cron": "^3.0.0",
 | 
			
		||||
        "uuid": "^8.3.2"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
@@ -585,6 +586,25 @@
 | 
			
		||||
        "mkdirp": "bin/cmd.js"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/moment": {
 | 
			
		||||
      "version": "2.29.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
 | 
			
		||||
      "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==",
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": "*"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/moment-timezone": {
 | 
			
		||||
      "version": "0.5.34",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.34.tgz",
 | 
			
		||||
      "integrity": "sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "moment": ">= 2.9.0"
 | 
			
		||||
      },
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": "*"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/morgan": {
 | 
			
		||||
      "version": "1.9.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
 | 
			
		||||
@@ -613,6 +633,17 @@
 | 
			
		||||
        "node": ">= 0.6"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/node-cron": {
 | 
			
		||||
      "version": "3.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-DDwIvvuCwrNiaU7HEivFDULcaQualDv7KoNlB/UU1wPW0n1tDEmBJKhEIE6DlF2FuoOHcNbLJ8ITL2Iv/3AWmA==",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "moment-timezone": "^0.5.31"
 | 
			
		||||
      },
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": ">=6.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/object-assign": {
 | 
			
		||||
      "version": "4.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
 | 
			
		||||
@@ -1429,6 +1460,19 @@
 | 
			
		||||
        "minimist": "^1.2.5"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "moment": {
 | 
			
		||||
      "version": "2.29.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
 | 
			
		||||
      "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
 | 
			
		||||
    },
 | 
			
		||||
    "moment-timezone": {
 | 
			
		||||
      "version": "0.5.34",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.34.tgz",
 | 
			
		||||
      "integrity": "sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==",
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "moment": ">= 2.9.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "morgan": {
 | 
			
		||||
      "version": "1.9.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
 | 
			
		||||
@@ -1451,6 +1495,14 @@
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
 | 
			
		||||
      "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
 | 
			
		||||
    },
 | 
			
		||||
    "node-cron": {
 | 
			
		||||
      "version": "3.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-DDwIvvuCwrNiaU7HEivFDULcaQualDv7KoNlB/UU1wPW0n1tDEmBJKhEIE6DlF2FuoOHcNbLJ8ITL2Iv/3AWmA==",
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "moment-timezone": "^0.5.31"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "object-assign": {
 | 
			
		||||
      "version": "4.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@
 | 
			
		||||
    "http-errors": "~1.6.3",
 | 
			
		||||
    "jade": "~1.11.0",
 | 
			
		||||
    "morgan": "~1.9.1",
 | 
			
		||||
    "node-cron": "^3.0.0",
 | 
			
		||||
    "uuid": "^8.3.2"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										61686
									
								
								public/babel.js
									
									
									
									
									
								
							
							
						
						
									
										61686
									
								
								public/babel.js
									
									
									
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										25
									
								
								public/babel.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								public/babel.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -1,60 +1,163 @@
 | 
			
		||||
<head>
 | 
			
		||||
  <style> body { margin: 0; } </style>
 | 
			
		||||
    <style> body {
 | 
			
		||||
        margin: 0;
 | 
			
		||||
    } </style>
 | 
			
		||||
 | 
			
		||||
  <script src="/react.production.min.js"></script>
 | 
			
		||||
<!--  <script src="//unpkg.com/react/umd/react.production.min.js"></script>-->
 | 
			
		||||
  <script src="/react-dom.production.min.js"></script>
 | 
			
		||||
<!--  <script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>-->
 | 
			
		||||
<!--  <script src="//unpkg.com/babel-standalone"></script>-->
 | 
			
		||||
  <script src="/babel.js"></script>
 | 
			
		||||
    <script src="/react.production.min.js"></script>
 | 
			
		||||
    <!--  <script src="//unpkg.com/react/umd/react.production.min.js"></script>-->
 | 
			
		||||
    <script src="/react-dom.production.min.js"></script>
 | 
			
		||||
    <!--  <script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>-->
 | 
			
		||||
    <!--  <script src="//unpkg.com/babel-standalone"></script>-->
 | 
			
		||||
    <script src="/babel.min.js"></script>
 | 
			
		||||
 | 
			
		||||
    <script src="/react-globe.js"></script>
 | 
			
		||||
    <!--  <script src="//unpkg.com/react-globe.gl"></script>-->
 | 
			
		||||
    <!--  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
 | 
			
		||||
    <script src="/axios.min.js"></script>
 | 
			
		||||
 | 
			
		||||
  <script src="/react-globe.js"></script>
 | 
			
		||||
<!--  <script src="//unpkg.com/react-globe.gl"></script>-->
 | 
			
		||||
<!--  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
 | 
			
		||||
  <script src="/axios.min.js"></script>
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
<div id="globeViz"></div>
 | 
			
		||||
 | 
			
		||||
<script type="text/jsx">
 | 
			
		||||
  // Gen random data
 | 
			
		||||
  var data = {};
 | 
			
		||||
  axios.get("http://localhost:3100/alerts").then(res => {
 | 
			
		||||
    data = res.data;
 | 
			
		||||
    console.log(data)
 | 
			
		||||
    ReactDOM.render(
 | 
			
		||||
    <Globe
 | 
			
		||||
      globeImageUrl="/images/earth-night.jpg"
 | 
			
		||||
      backgroundImageUrl="/images/night-sky.png"
 | 
			
		||||
      // edges
 | 
			
		||||
      arcsData={data.arc}
 | 
			
		||||
      arcColor={(d) => [d.color[0], d.color[1]]}
 | 
			
		||||
      arcDashLength={(d) => d.stroke - 0.1 + 0.3}
 | 
			
		||||
      // arcDashLength={(d) => d.stroke - 0.1}
 | 
			
		||||
      arcAltitudeAutoScale={0.5}
 | 
			
		||||
      arcDashGap={(d) => 0.1 + (1 - (d.stroke - 0.1))}
 | 
			
		||||
      arcDashAnimateTime={(d) => (1.1 - d.stroke) * 5000 + 2000}
 | 
			
		||||
      arcStroke={0.4}
 | 
			
		||||
      //arcCircularResolution={64}
 | 
			
		||||
      // arcLabel={() => "test"}
 | 
			
		||||
      // labels
 | 
			
		||||
      labelsData={data.loc}
 | 
			
		||||
      labelLat={(d) => d.lat}
 | 
			
		||||
      labelLng={(d) => d.lng}
 | 
			
		||||
      labelText={(d) => d.name}
 | 
			
		||||
      // labelSize={(d) => 0.5 + d.size}
 | 
			
		||||
      labelSize={0}
 | 
			
		||||
      labelDotRadius={0.4}
 | 
			
		||||
      // labelDotRadius={(d) => 0.5 + d.size}
 | 
			
		||||
      labelColor={(d) => d.color}
 | 
			
		||||
      labelResolution={2}
 | 
			
		||||
      enablePointerInteraction={true}
 | 
			
		||||
      />,
 | 
			
		||||
    document.getElementById('globeViz')
 | 
			
		||||
  );
 | 
			
		||||
  }).catch(err => alert(err)) 
 | 
			
		||||
    function generateHoverText(txrx) {
 | 
			
		||||
        var text = ""
 | 
			
		||||
        txrx.forEach(i => {
 | 
			
		||||
            text += i.src_name + " (" + i.src + ") -> " + i.dest_name + " (" + i.dest + ")<br>"
 | 
			
		||||
        })
 | 
			
		||||
        return text;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function generateClickText(item) {
 | 
			
		||||
        return "uid: " + item.uid + " \nfirst_seen: " +
 | 
			
		||||
            item.first_seen + " \nsrv_city_name: " +
 | 
			
		||||
            item.srv_city_name + " \nip_version: " +
 | 
			
		||||
            item.ip_version + " \naction: " +
 | 
			
		||||
            item.action + " \npool_id: " +
 | 
			
		||||
            item.pool_id + " \nsrv_continent_name: " +
 | 
			
		||||
            item.srv_continent_name + " \nscore: " +
 | 
			
		||||
            item.score + " \nentity_val: " +
 | 
			
		||||
            item.entity_val + " \nvlan_id: " +
 | 
			
		||||
            item.vlan_id + " \ncli2srv_bytes: " +
 | 
			
		||||
            item.cli2srv_bytes + " \ncli_country_name: " +
 | 
			
		||||
            item.cli_country_name + " \nentity_id: " +
 | 
			
		||||
            item.entity_id + " \nsrv_asn: " +
 | 
			
		||||
            item.srv_asn + " \nl7_proto: " +
 | 
			
		||||
            item.l7_proto + " \nis_cli_attacker: " +
 | 
			
		||||
            item.is_cli_attacker + " \nsrv_name: " +
 | 
			
		||||
            item.srv_name + " \nsrv_ip: " +
 | 
			
		||||
            item.srv_ip + " \nproto: " +
 | 
			
		||||
            item.proto + " \njson: " +
 | 
			
		||||
            item.json + " \nsrv_country_name: " +
 | 
			
		||||
            item.srv_country_name + " \ncommunity_id: " +
 | 
			
		||||
            item.community_id + " \nalert_id: " +
 | 
			
		||||
            item.alert_id + " \nis_srv_attacker: " +
 | 
			
		||||
            item.is_srv_attacker + " \nsrv_blacklisted: " +
 | 
			
		||||
            item.srv_blacklisted + " \nalerts_map: " +
 | 
			
		||||
            item.alerts_map + " \nsrv_os: " +
 | 
			
		||||
            item.srv_os + " \ncli_localhost: " +
 | 
			
		||||
            item.cli_localhost + " \ncli_asn: " +
 | 
			
		||||
            item.cli_asn + " \nsrv2cli_packets: " +
 | 
			
		||||
            item.srv2cli_packets + " \ncli2srv_packets: " +
 | 
			
		||||
            item.cli2srv_packets + " \ntstamp: " +
 | 
			
		||||
            item.tstamp + " \ncli_name: " +
 | 
			
		||||
            item.cli_name + " \ncli_continent_name: " +
 | 
			
		||||
            item.cli_continent_name + " \nsrv2cli_bytes: " +
 | 
			
		||||
            item.srv2cli_bytes + " \nl7_cat: " +
 | 
			
		||||
            item.l7_cat + " \nproto: " +
 | 
			
		||||
            item.proto + " \nifid: " +
 | 
			
		||||
            item.ifid + " \nobservation_point_id: " +
 | 
			
		||||
            item.observation_point_id + " \nsrv_localhost: " +
 | 
			
		||||
            item.srv_localhost + " \ncli_port: " +
 | 
			
		||||
            item.cli_port + " \ncli_blacklisted: " +
 | 
			
		||||
            item.cli_blacklisted + " \nis_flow_alert: " +
 | 
			
		||||
            item.is_flow_alert + " \nsrv_port: " +
 | 
			
		||||
            item.srv_port + " \nl7_master_proto: " +
 | 
			
		||||
            item.l7_master_proto + " \nis_cli_victim: " +
 | 
			
		||||
            item.is_cli_victim + " \ncli_ip: " +
 | 
			
		||||
            item.cli_ip + " \ncli_city_name: " +
 | 
			
		||||
            item.cli_city_name + " \ncli_os: " +
 | 
			
		||||
            item.cli_os + " \nis_srv_vic " + item.is_srv_vic
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function componentDidMount() {
 | 
			
		||||
        var data = {};
 | 
			
		||||
        if ("WebSocket" in window) {
 | 
			
		||||
            console.log("WebSocket is supported by your Browser!");
 | 
			
		||||
            const ws = new WebSocket('ws://localhost:8999');
 | 
			
		||||
            ws.onopen = function () {
 | 
			
		||||
                // Web Socket is connected, send data using send()
 | 
			
		||||
                console.log("Message is sent...");
 | 
			
		||||
            };
 | 
			
		||||
            ws.onmessage = function (evt) {
 | 
			
		||||
                var received_msg = evt.data;
 | 
			
		||||
                console.log("Message is received...");
 | 
			
		||||
                componentDidMount()
 | 
			
		||||
            };
 | 
			
		||||
            ws.onclose = function () {
 | 
			
		||||
                // websocket is closed.
 | 
			
		||||
                console.log("Connection is closed...");
 | 
			
		||||
            };
 | 
			
		||||
        }else {
 | 
			
		||||
            // The browser doesn't support WebSocket
 | 
			
		||||
            alert("WebSocket NOT supported by your Browser! A left click on the globe will refresh the data");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        axios.get("http://localhost:3100/display").then(res => {
 | 
			
		||||
            data = res.data;
 | 
			
		||||
            console.log(data)
 | 
			
		||||
            ReactDOM.render(
 | 
			
		||||
                <Globe
 | 
			
		||||
                    onGlobeClick={() => {
 | 
			
		||||
                        axios.get("http://localhost:3100/display").then(res => {
 | 
			
		||||
                            data = res.data;
 | 
			
		||||
                            componentDidMount()
 | 
			
		||||
                        });
 | 
			
		||||
                    }}
 | 
			
		||||
                    globeImageUrl="/images/earth-night.jpg"
 | 
			
		||||
                    backgroundImageUrl="/images/night-sky.png"
 | 
			
		||||
                    backgroundColor={"#000011"}
 | 
			
		||||
                        // edges
 | 
			
		||||
                    arcsData={data.arc}
 | 
			
		||||
                    arcColor={(d) => [d.color[0], d.color[1]]}
 | 
			
		||||
                    arcDashLength={data.settings.sizes.globe.arcDashLength}
 | 
			
		||||
                    arcAltitudeAutoScale={data.settings.sizes.globe.arcAltitudeAutoScale}
 | 
			
		||||
                    arcDashGap={data.settings.sizes.globe.arcDashGap}
 | 
			
		||||
                    arcDashInitialGap={data.settings.sizes.globe.arcDashInitialGap}
 | 
			
		||||
                    arcDashAnimateTime={data.settings.sizes.globe.arcDashAnimateTime}
 | 
			
		||||
                    arcStroke={data.settings.sizes.globe.arcStroke}
 | 
			
		||||
                    arcLabel={(d) => generateHoverText(d.txrx)}
 | 
			
		||||
                    onArcClick={function (d) {
 | 
			
		||||
                        axios.get("http://localhost:3100/alert/" + d.uid).then(res => {
 | 
			
		||||
                            const resdata = res.data;
 | 
			
		||||
                            alert(generateClickText(resdata))
 | 
			
		||||
                        })
 | 
			
		||||
                    }}
 | 
			
		||||
                        //arcCircularResolution={64}
 | 
			
		||||
                        // arcLabel={() => "test"}
 | 
			
		||||
                        // labels
 | 
			
		||||
                    labelsData={data.loc}
 | 
			
		||||
                    labelLat={(d) => d.lat}
 | 
			
		||||
                    labelLng={(d) => d.lng}
 | 
			
		||||
                    labelText={(d) => d.name}
 | 
			
		||||
                        // labelSize={(d) => 0.5 + d.size}
 | 
			
		||||
                    labelSize={0}
 | 
			
		||||
                    labelDotRadius={0.4}
 | 
			
		||||
                        // labelDotRadius={(d) => 0.5 + d.size}
 | 
			
		||||
                    labelColor={(d) => d.color}
 | 
			
		||||
                    labelResolution={2}
 | 
			
		||||
                    enablePointerInteraction={true}
 | 
			
		||||
                />,
 | 
			
		||||
                document.getElementById('globeViz')
 | 
			
		||||
            );
 | 
			
		||||
        }).catch(err => alert(err))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    componentDidMount()
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
</script>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</body>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
body {
 | 
			
		||||
  padding: 50px;
 | 
			
		||||
  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
a {
 | 
			
		||||
  color: #00B7FF;
 | 
			
		||||
}
 | 
			
		||||
@@ -2,27 +2,84 @@ var express = require('express');
 | 
			
		||||
var router = express.Router();
 | 
			
		||||
var alerts = require('../model/alerts.js');
 | 
			
		||||
var globe = require('../model/globedata.js');
 | 
			
		||||
var cron = require('node-cron')
 | 
			
		||||
const path = require('path');
 | 
			
		||||
var WebSocket = require('ws')
 | 
			
		||||
var http = require('http')
 | 
			
		||||
 | 
			
		||||
/* GET home page. */
 | 
			
		||||
router.get('/alerts', function(req, res, next) {
 | 
			
		||||
router.get('/display', function(req, res, next) {
 | 
			
		||||
  res.setHeader("Content-Type", "application/json");
 | 
			
		||||
 | 
			
		||||
  res.json(globe.getData());
 | 
			
		||||
  res.json(globe.getDisplayData());
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.get('/', function(req, res, next) {
 | 
			
		||||
  res.sendFile(path.join(__dirname, '../public/globe.html'));
 | 
			
		||||
});
 | 
			
		||||
const server = http.createServer(router);
 | 
			
		||||
//initialize the WebSocket server instance
 | 
			
		||||
const wss = new WebSocket.Server({ server });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
wss.on('connection', (ws) => {
 | 
			
		||||
 | 
			
		||||
  //connection is up, let's add a simple simple event
 | 
			
		||||
  ws.on('message', (message) => {
 | 
			
		||||
 | 
			
		||||
    //log the received message and send it back to the client
 | 
			
		||||
    console.log('received: %s', message);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
wss.broadcast = function broadcast(msg) {
 | 
			
		||||
  console.log(msg);
 | 
			
		||||
  wss.clients.forEach(function each(client) {
 | 
			
		||||
    client.send(msg);
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
//start our server
 | 
			
		||||
server.listen(process.env.PORT || 8999, () => {
 | 
			
		||||
  console.log(`Server started on port ${server.address().port} :)`);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.get('/alert/:uid', function(req, res, next) {
 | 
			
		||||
  const uid = req.params.uid
 | 
			
		||||
  res.setHeader("Content-Type", "application/json");
 | 
			
		||||
  res.json(alerts.getAlert(uid));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.get('/alerts/dates', function(req, res, next) {
 | 
			
		||||
  res.json(alerts.getAlertDates());
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var task = cron.schedule('* * * * *', () =>  {
 | 
			
		||||
  const TEN_MINUTES = globe.getSettigns().timer.del*60*1000;
 | 
			
		||||
  const date = new Date();
 | 
			
		||||
  alerts.getAlertDates().forEach(ad => {
 | 
			
		||||
    var duration = Date.now() - ad.date.getTime();
 | 
			
		||||
    if (duration > TEN_MINUTES) {
 | 
			
		||||
      const todel = ad.uids;
 | 
			
		||||
      console.log(todel)
 | 
			
		||||
      delTimer(todel, ad.date)
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function delTimer(todel, date){
 | 
			
		||||
  globe.delUids(todel)
 | 
			
		||||
  alerts.delAlerts(todel)
 | 
			
		||||
  alerts.delAlertDate(date)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
router.post('/ws', async function(req, res, next) {
 | 
			
		||||
  for (const item of req.body.alerts) {
 | 
			
		||||
    var log =  {
 | 
			
		||||
      src: item.srv_ip,
 | 
			
		||||
      dest: item.cli_ip,
 | 
			
		||||
    }
 | 
			
		||||
    console.log(log)
 | 
			
		||||
    const uid = alerts.addAlert(item.first_seen, item.srv_city_name, item.ip_version, item.action, item.pool_id, item.srv_continent_name, item.score, item.entity_val, item.vlan_id, item.cli2srv_bytes, item.cli_country_name, item.entity_id, item.srv_asn, item.l7_proto, item.is_cli_attacker, item.srv_name, item.srv_ip, item.proto, item.json, item.srv_country_name, item.community_id, item.alert_id, item.is_srv_attacker, item.srv_blacklisted, item.alerts_map, item.srv_os, item.cli_localhost, item.cli_asn, item.srv2cli_packets, item.cli2srv_packets, item.tstamp, item.cli_name, item.cli_continent_name, item.srv2cli_bytes, item.l7_cat, item.ifid, item.observation_point_id, item.srv_localhost, item.cli_port, item.cli_blacklisted, item.dns_last_query, item.is_flow_alert, item.srv_port, item.l7_master_proto, item.is_cli_victim, item.cli_ip, item.cli_city_name, item.cli_os, item.is_srv_victim);
 | 
			
		||||
    const src = item.srv_ip;
 | 
			
		||||
    const dest = item.cli_ip;
 | 
			
		||||
    if (typeof src !== 'undefined' || typeof dest !== 'undefined')
 | 
			
		||||
      await globe.addArc(src, dest, uid)
 | 
			
		||||
      await globe.addArc(src, dest, uid, item.srv_name, item.cli_name)
 | 
			
		||||
  }
 | 
			
		||||
  wss.broadcast("new data is da")
 | 
			
		||||
  res.sendStatus(200);
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user