mirror of https://github.com/D4-project/d4-core
chg: [server + UI] change server_mode + display all registered sensors
parent
3ce8557cff
commit
0bd02f21d6
|
@ -3,3 +3,5 @@
|
||||||
use_default_save_directory = yes
|
use_default_save_directory = yes
|
||||||
save_directory = None
|
save_directory = None
|
||||||
|
|
||||||
|
[D4_Server]
|
||||||
|
server_mode = registration # registration or shared-secret
|
||||||
|
|
|
@ -25,7 +25,26 @@ def is_valid_uuid_v4(UUID):
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_sensor_metadata(sensor_uuid, first_seen=True, last_seen=True, mail=True, description=True):
|
def _get_sensor_type(sensor_uuid, first_seen=True, last_seen=True, time_format='default'):
|
||||||
|
uuid_type = []
|
||||||
|
uuid_all_type = r_serv_db.smembers('all_types_by_uuid:{}'.format(sensor_uuid))
|
||||||
|
for type in uuid_all_type:
|
||||||
|
type_meta = {}
|
||||||
|
type_meta['type'] = type
|
||||||
|
if first_seen:
|
||||||
|
type_meta['first_seen'] = r_serv_db.hget('metadata_type_by_uuid:{}:{}'.format(sensor_uuid, type), 'first_seen')
|
||||||
|
if last_seen:
|
||||||
|
type_meta['last_seen'] = r_serv_db.hget('metadata_type_by_uuid:{}:{}'.format(sensor_uuid, type), 'last_seen')
|
||||||
|
# time format
|
||||||
|
if time_format=='gmt':
|
||||||
|
if type_meta['first_seen']:
|
||||||
|
type_meta['first_seen'] = datetime.datetime.fromtimestamp(float(type_meta['first_seen'])).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
if type_meta['last_seen']:
|
||||||
|
type_meta['last_seen'] = datetime.datetime.fromtimestamp(float(type_meta['last_seen'])).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
uuid_type.append(type_meta)
|
||||||
|
return uuid_type
|
||||||
|
|
||||||
|
def _get_sensor_metadata(sensor_uuid, first_seen=True, last_seen=True, time_format='default', sensor_types=False, mail=True, description=True):
|
||||||
|
|
||||||
meta_sensor = {}
|
meta_sensor = {}
|
||||||
meta_sensor['uuid'] = sensor_uuid
|
meta_sensor['uuid'] = sensor_uuid
|
||||||
|
@ -33,6 +52,15 @@ def _get_sensor_metadata(sensor_uuid, first_seen=True, last_seen=True, mail=True
|
||||||
meta_sensor['first_seen'] = r_serv_db.hget('metadata_uuid:{}'.format(sensor_uuid), 'first_seen')
|
meta_sensor['first_seen'] = r_serv_db.hget('metadata_uuid:{}'.format(sensor_uuid), 'first_seen')
|
||||||
if last_seen:
|
if last_seen:
|
||||||
meta_sensor['last_seen'] = r_serv_db.hget('metadata_uuid:{}'.format(sensor_uuid), 'last_seen')
|
meta_sensor['last_seen'] = r_serv_db.hget('metadata_uuid:{}'.format(sensor_uuid), 'last_seen')
|
||||||
|
# time format
|
||||||
|
if time_format=='gmt':
|
||||||
|
if meta_sensor['first_seen']:
|
||||||
|
meta_sensor['first_seen'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(meta_sensor['first_seen'])))
|
||||||
|
if meta_sensor['last_seen']:
|
||||||
|
meta_sensor['last_seen'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(meta_sensor['last_seen'])))
|
||||||
|
|
||||||
|
if sensor_types:
|
||||||
|
meta_sensor['types'] = _get_sensor_type(sensor_uuid, first_seen=False, last_seen=False)
|
||||||
if description:
|
if description:
|
||||||
meta_sensor['description'] = r_serv_db.hget('metadata_uuid:{}'.format(sensor_uuid), 'description')
|
meta_sensor['description'] = r_serv_db.hget('metadata_uuid:{}'.format(sensor_uuid), 'description')
|
||||||
if mail:
|
if mail:
|
||||||
|
@ -77,6 +105,15 @@ def _register_sensor(sensor_uuid, secret_key, user_id=None, description=None):
|
||||||
def get_pending_sensor():
|
def get_pending_sensor():
|
||||||
return list(r_serv_db.smembers('sensor_pending_registration'))
|
return list(r_serv_db.smembers('sensor_pending_registration'))
|
||||||
|
|
||||||
|
def get_nb_pending_sensor():
|
||||||
|
return r_serv_db.scard('sensor_pending_registration')
|
||||||
|
|
||||||
|
def get_nb_registered_sensors():
|
||||||
|
return r_serv_db.scard('registered_uuid')
|
||||||
|
|
||||||
|
def get_registered_sensors():
|
||||||
|
return list(r_serv_db.smembers('registered_uuid'))
|
||||||
|
|
||||||
def approve_sensor(req_dict):
|
def approve_sensor(req_dict):
|
||||||
sensor_uuid = req_dict.get('uuid', None)
|
sensor_uuid = req_dict.get('uuid', None)
|
||||||
if not is_valid_uuid_v4(sensor_uuid):
|
if not is_valid_uuid_v4(sensor_uuid):
|
||||||
|
|
|
@ -12,6 +12,7 @@ import datetime
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import configparser
|
||||||
|
|
||||||
from twisted.internet import ssl, task, protocol, endpoints, defer
|
from twisted.internet import ssl, task, protocol, endpoints, defer
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
|
@ -27,7 +28,6 @@ accepted_type = [1, 2, 4, 8, 254]
|
||||||
accepted_extended_type = ['ja3-jl']
|
accepted_extended_type = ['ja3-jl']
|
||||||
|
|
||||||
all_server_modes = ('registration', 'shared-secret')
|
all_server_modes = ('registration', 'shared-secret')
|
||||||
server_mode = 'registration'
|
|
||||||
|
|
||||||
timeout_time = 30
|
timeout_time = 30
|
||||||
|
|
||||||
|
@ -584,6 +584,21 @@ if __name__ == "__main__":
|
||||||
logger.addHandler(handler_log)
|
logger.addHandler(handler_log)
|
||||||
logger.setLevel(args.verbose)
|
logger.setLevel(args.verbose)
|
||||||
|
|
||||||
|
|
||||||
|
# get file config
|
||||||
|
config_file_server = os.path.join(os.environ['D4_HOME'], 'configs/server.conf')
|
||||||
|
config_server = configparser.ConfigParser()
|
||||||
|
config_server.read(config_file_server)
|
||||||
|
|
||||||
|
# get server_mode
|
||||||
|
server_mode = config_server['D4_Server'].get('server_mode')
|
||||||
|
if server_mode not in all_server_modes:
|
||||||
|
print('Error: incorrect server_mode')
|
||||||
|
logger.critical('Error: incorrect server_mode')
|
||||||
|
sys.exit(1)
|
||||||
|
logger.info('Server mode: {}'.format(server_mode))
|
||||||
|
|
||||||
|
|
||||||
logger.info('Launching Server ...')
|
logger.info('Launching Server ...')
|
||||||
|
|
||||||
task.react(main)
|
task.react(main)
|
||||||
|
|
|
@ -38,6 +38,8 @@ baseUrl = ''
|
||||||
if baseUrl != '':
|
if baseUrl != '':
|
||||||
baseUrl = '/'+baseUrl
|
baseUrl = '/'+baseUrl
|
||||||
|
|
||||||
|
all_server_modes = ('registration', 'shared-secret')
|
||||||
|
|
||||||
host_redis_stream = os.getenv('D4_REDIS_STREAM_HOST', "localhost")
|
host_redis_stream = os.getenv('D4_REDIS_STREAM_HOST', "localhost")
|
||||||
port_redis_stream = int(os.getenv('D4_REDIS_STREAM_PORT', 6379))
|
port_redis_stream = int(os.getenv('D4_REDIS_STREAM_PORT', 6379))
|
||||||
|
|
||||||
|
@ -61,6 +63,10 @@ if use_default_save_directory:
|
||||||
else:
|
else:
|
||||||
data_directory = config_server['Save_Directories'].get('save_directory')
|
data_directory = config_server['Save_Directories'].get('save_directory')
|
||||||
|
|
||||||
|
server_mode = config_server['D4_Server'].get('server_mode')
|
||||||
|
if server_mode not in all_server_modes:
|
||||||
|
print('Error: incorrect server_mode')
|
||||||
|
|
||||||
redis_server_stream = redis.StrictRedis(
|
redis_server_stream = redis.StrictRedis(
|
||||||
host=host_redis_stream,
|
host=host_redis_stream,
|
||||||
port=port_redis_stream,
|
port=port_redis_stream,
|
||||||
|
@ -506,6 +512,9 @@ def show_active_uuid():
|
||||||
@login_required
|
@login_required
|
||||||
@login_user_basic
|
@login_user_basic
|
||||||
def server_management():
|
def server_management():
|
||||||
|
nb_sensors_registered = Sensor.get_nb_registered_sensors()
|
||||||
|
nb_sensors_pending = Sensor.get_nb_pending_sensor()
|
||||||
|
|
||||||
blacklisted_ip = request.args.get('blacklisted_ip')
|
blacklisted_ip = request.args.get('blacklisted_ip')
|
||||||
unblacklisted_ip = request.args.get('unblacklisted_ip')
|
unblacklisted_ip = request.args.get('unblacklisted_ip')
|
||||||
blacklisted_uuid = request.args.get('blacklisted_uuid')
|
blacklisted_uuid = request.args.get('blacklisted_uuid')
|
||||||
|
@ -570,6 +579,8 @@ def server_management():
|
||||||
list_accepted_extended_types.append({"name": extended_type, 'list_analyzer_uuid': list_analyzer_uuid})
|
list_accepted_extended_types.append({"name": extended_type, 'list_analyzer_uuid': list_analyzer_uuid})
|
||||||
|
|
||||||
return render_template("server_management.html", list_accepted_types=list_accepted_types, list_accepted_extended_types=list_accepted_extended_types,
|
return render_template("server_management.html", list_accepted_types=list_accepted_types, list_accepted_extended_types=list_accepted_extended_types,
|
||||||
|
server_mode=server_mode,
|
||||||
|
nb_sensors_registered=nb_sensors_registered, nb_sensors_pending=nb_sensors_pending,
|
||||||
default_analyzer_max_line_len=default_analyzer_max_line_len,
|
default_analyzer_max_line_len=default_analyzer_max_line_len,
|
||||||
blacklisted_ip=blacklisted_ip, unblacklisted_ip=unblacklisted_ip,
|
blacklisted_ip=blacklisted_ip, unblacklisted_ip=unblacklisted_ip,
|
||||||
blacklisted_uuid=blacklisted_uuid, unblacklisted_uuid=unblacklisted_uuid)
|
blacklisted_uuid=blacklisted_uuid, unblacklisted_uuid=unblacklisted_uuid)
|
||||||
|
@ -709,6 +720,15 @@ def blacklisted_uuid():
|
||||||
page=page, nb_page_max=nb_page_max,
|
page=page, nb_page_max=nb_page_max,
|
||||||
unblacklisted_uuid=unblacklisted_uuid, blacklisted_uuid=blacklisted_uuid)
|
unblacklisted_uuid=unblacklisted_uuid, blacklisted_uuid=blacklisted_uuid)
|
||||||
|
|
||||||
|
@app.route('/server/registered_sensor')
|
||||||
|
@login_required
|
||||||
|
@login_admin
|
||||||
|
def registered_sensor():
|
||||||
|
sensors = Sensor.get_registered_sensors()
|
||||||
|
all_sensors = []
|
||||||
|
for sensor_uuid in sensors:
|
||||||
|
all_sensors.append(Sensor._get_sensor_metadata(sensor_uuid, time_format='gmt', sensor_types=True))
|
||||||
|
return render_template("registered_sensors.html", all_sensors=all_sensors)
|
||||||
|
|
||||||
@app.route('/server/pending_sensor')
|
@app.route('/server/pending_sensor')
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>D4-Project</title>
|
||||||
|
<link rel="icon" href="{{ url_for('static', filename='img/d4-logo.png')}}">
|
||||||
|
<!-- Core CSS -->
|
||||||
|
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- JS -->
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.popover{
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
{% include 'navbar.html' %}
|
||||||
|
|
||||||
|
<div class="mx-2 py-3">
|
||||||
|
<table class="table table-striped table-bordered table-hover text-center" id="myTable_1">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="bg-info text-white">UUID</th>
|
||||||
|
<th class="bg-info text-white">first seen</th>
|
||||||
|
<th class="bg-info text-white">last seen</th>
|
||||||
|
<th class="bg-info text-white">types</th>
|
||||||
|
<th class="bg-secondary text-white">Status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for row_uuid in all_sensors %}
|
||||||
|
<tr data-trigger="hover" title="" data-content="test content" data-original-title="test title">
|
||||||
|
<td>
|
||||||
|
<a class="" href="{{ url_for('uuid_management') }}?uuid={{row_uuid['uuid']}}">
|
||||||
|
{{row_uuid['uuid']}}
|
||||||
|
</a>
|
||||||
|
{% if row_uuid['description'] %}
|
||||||
|
<div class="text-info"><small>{{row_uuid['description']}}</small></div>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if row_uuid['first_seen'] %}
|
||||||
|
{{row_uuid['first_seen']}}
|
||||||
|
{% else %}
|
||||||
|
{{'-'}}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if row_uuid['first_seen'] %}
|
||||||
|
{{row_uuid['first_seen']}}
|
||||||
|
{% else %}
|
||||||
|
{{'-'}}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{type_description}}
|
||||||
|
{% for uuid_type in row_uuid['types'] %}
|
||||||
|
<span class="badge badge-dark">
|
||||||
|
{{uuid_type['type']}}
|
||||||
|
</span>
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
{% if not row_uuid['Error'] %}
|
||||||
|
div class="text-success">
|
||||||
|
OK -
|
||||||
|
{% else %}
|
||||||
|
div class="text-danger">
|
||||||
|
<i class="fa fa-times-circle"></i> {{row_uuid['Error']}}
|
||||||
|
{% endif %}
|
||||||
|
{% if row_uuid['active_connection'] %}
|
||||||
|
<i class="fa fa-check-circle"></i> Connected
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{% include 'navfooter.html' %}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("#nav-sensor").addClass("active");
|
||||||
|
table = $('#myTable_1').DataTable(
|
||||||
|
{
|
||||||
|
"aLengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]],
|
||||||
|
"iDisplayLength": 10,
|
||||||
|
"order": [[ 0, "asc" ]]
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
|
@ -21,6 +21,24 @@
|
||||||
|
|
||||||
{% include 'navbar.html' %}
|
{% include 'navbar.html' %}
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
<div class="card border-secondary mt-3 text-center" style="max-width: 30rem;">
|
||||||
|
<div class="card-body text-dark">
|
||||||
|
<h5 class="card-title">D4 Server mode:
|
||||||
|
<span class="badge badge-dark">
|
||||||
|
{{server_mode}}
|
||||||
|
</span>
|
||||||
|
</h5>
|
||||||
|
<a href="{{ url_for('registered_sensor') }}">
|
||||||
|
<button type="button" class="btn btn-info">Registered Sensors <span class="badge badge-light">{{nb_sensors_registered}}</span></button>
|
||||||
|
</a>
|
||||||
|
<a href="{{ url_for('pending_sensors') }}">
|
||||||
|
<button type="button" class="btn btn-outline-secondary">Pending Sensors <span class="badge badge-danger">{{nb_sensors_pending}}</span></button>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="card-deck ml-0 mr-0">
|
<div class="card-deck ml-0 mr-0">
|
||||||
<div class="card text-center mt-3 ml-xl-4">
|
<div class="card text-center mt-3 ml-xl-4">
|
||||||
<div class="card-header bg-danger text-white">
|
<div class="card-header bg-danger text-white">
|
||||||
|
|
Loading…
Reference in New Issue