diff --git a/client/d4.c b/client/d4.c index 9d8cdd5..ab39c59 100644 --- a/client/d4.c +++ b/client/d4.c @@ -10,7 +10,7 @@ #include #include -#include +#include "others/uuid/uuid.h" #include "d4.h" // @@ -80,14 +80,14 @@ void d4_update_uuid(d4_t* d4) int d4_check_config(d4_t* d4) { // TODO implement other sources, file, fifo, unix_socket ... - if (strlen(d4->conf[SOURCE]) > strlen(STDIN)) { + if (strlen(d4->conf[SOURCE]) >= strlen(STDIN)) { if (!strncmp(d4->conf[SOURCE],STDIN, strlen(STDIN))) { d4->source.fd = STDIN_FILENO; } } //TODO implement other destinations file, fifo unix_socket ... - if (strlen(d4->conf[DESTINATION]) > strlen(STDOUT)) { + if (strlen(d4->conf[DESTINATION]) >= strlen(STDOUT)) { if (!strncmp(d4->conf[DESTINATION],STDOUT, strlen(STDOUT))) { d4->destination.fd = STDOUT_FILENO; } @@ -121,6 +121,7 @@ int d4_load_config(d4_t* d4) if (fd > 0) { //FIXME error handling read(fd, d4->conf[i], SZCONFVALUE); + close(fd); } else { d4->errno_copy = errno; INSERT_ERROR("Failed to load %s", d4params[i]); @@ -190,7 +191,7 @@ void d4_transfert(d4_t* d4) hmac = calloc(1,SZHMAC); hmaczero = calloc(1,SZHMAC); //TODO error handling -> insert error message - if ((buf == NULL) && (hmac == NULL)) + if ((buf == NULL) && (hmac == NULL) && (hmaczero == NULL)) return; d4_prepare_header(d4); diff --git a/client/others/uuid/randutils.c b/client/others/uuid/randutils.c index 1b4e5ff..5944c58 100644 --- a/client/others/uuid/randutils.c +++ b/client/others/uuid/randutils.c @@ -14,7 +14,6 @@ #include #include #include -#include #include //#include "c.h" @@ -118,7 +117,7 @@ void random_get_bytes(void *buf, size_t nbytes) int x; errno = 0; - x = getrandom(cp, n, GRND_NONBLOCK); + x = getentropy(cp, n); if (x > 0) { /* success */ n -= x; cp += x; diff --git a/server/.gitignore b/server/.gitignore index e334829..832729a 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -2,3 +2,5 @@ *.csr *.pem *.key +data/ +logs/ diff --git a/server/server.py b/server/server.py index 941fc44..bbf7fd3 100755 --- a/server/server.py +++ b/server/server.py @@ -229,11 +229,14 @@ class Echo(Protocol, TimeoutMixin): if redis_server_stream.xlen('stream:{}:{}'.format(data_header['type'], self.session_uuid)) < self.stream_max_size: redis_server_stream.xadd('stream:{}:{}'.format(data_header['type'], self.session_uuid), {'message': data[header_size:], 'uuid': data_header['uuid_header'], 'timestamp': data_header['timestamp'], 'version': data_header['version']}) + + # daily stats redis_server_metadata.zincrby('stat_uuid_ip:{}:{}'.format(date, data_header['uuid_header']), 1, ip) redis_server_metadata.zincrby('stat_ip_uuid:{}:{}'.format(date, ip), 1, data_header['uuid_header']) - redis_server_metadata.zincrby('daily_uuid:{}'.format(date), 1, data_header['uuid_header']) redis_server_metadata.zincrby('daily_ip:{}'.format(date), 1, ip) + redis_server_metadata.zincrby('daily_type:{}'.format(date), 1, data_header['type']) + redis_server_metadata.zincrby('stat_type_uuid:{}:{}'.format(date, data_header['type']), 1, data_header['uuid_header']) # if not redis_server_metadata.hexists('metadata_uuid:{}'.format(data_header['uuid_header']), 'first_seen'): diff --git a/server/web/Flask_server.py b/server/web/Flask_server.py new file mode 100755 index 0000000..f000f4d --- /dev/null +++ b/server/web/Flask_server.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# -*-coding:UTF-8 -* + +import os +import sys +import time +import redis +import flask +import datetime + +from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for + +baseUrl = '' +if baseUrl != '': + baseUrl = '/'+baseUrl + +host_redis_metadata = "localhost" +port_redis_metadata= 6380 + +redis_server_metadata = redis.StrictRedis( + host=host_redis_metadata, + port=port_redis_metadata, + db=0, + decode_responses=True) + +app = Flask(__name__, static_url_path=baseUrl+'/static/') +app.config['MAX_CONTENT_LENGTH'] = 900 * 1024 * 1024 + +# ========== ROUTES ============ +@app.route('/') +def index(): + return render_template("index.html") + +@app.route('/_json_daily_uuid_stats') +def _json_daily_uuid_stats(): + date = datetime.datetime.now().strftime("%Y%m%d") + daily_uuid = redis_server_metadata.zrange('daily_uuid:{}'.format(date), 0, -1, withscores=True) + + data_daily_uuid = [] + for result in daily_uuid: + data_daily_uuid.append({"key": result[0], "value": int(result[1])}) + + return jsonify(data_daily_uuid) + +if __name__ == "__main__": + app.run(host='0.0.0.0', port=7000, threaded=True) diff --git a/server/web/static/img/d4-logo.png b/server/web/static/img/d4-logo.png new file mode 100644 index 0000000..63fe5a0 Binary files /dev/null and b/server/web/static/img/d4-logo.png differ diff --git a/server/web/templates/index.html b/server/web/templates/index.html new file mode 100644 index 0000000..951f5f1 --- /dev/null +++ b/server/web/templates/index.html @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + diff --git a/server/web/update_web.sh b/server/web/update_web.sh new file mode 100755 index 0000000..1262161 --- /dev/null +++ b/server/web/update_web.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +BOOTSTRAP_VERSION='4.2.1' +FONT_AWESOME_VERSION='4.7.0' +D3_JS_VERSION='4.13.0' + +if [ ! -d static/css ]; then + mkdir static/css +fi +if [ ! -d static/js ]; then + mkdir static/js +fi + +rm -rf temp +mkdir temp + +wget https://github.com/twbs/bootstrap/releases/download/v${BOOTSTRAP_VERSION}/bootstrap-${BOOTSTRAP_VERSION}-dist.zip -O temp/bootstrap${BOOTSTRAP_VERSION}.zip + +#wget https://github.com/FortAwesome/Font-Awesome/archive/v${FONT_AWESOME_VERSION}.zip -O temp/FONT_AWESOME_${FONT_AWESOME_VERSION}.zip +wget https://github.com/d3/d3/releases/download/v${D3_JS_VERSION}/d3.zip -O temp/d3_${D3_JS_VERSION}.zip + +# dateRangePicker +#wget https://github.com/moment/moment/archive/2.22.2.zip -O temp/moment_2.22.2.zip +#wget https://github.com/longbill/jquery-date-range-picker/archive/v0.18.0.zip -O temp/daterangepicker_v0.18.0.zip + + +unzip temp/bootstrap${BOOTSTRAP_VERSION}.zip -d temp/ +#unzip temp/FONT_AWESOME_${FONT_AWESOME_VERSION}.zip -d temp/ +unzip temp/d3_${D3_JS_VERSION}.zip -d temp/ + +#unzip temp/moment_2.22.2.zip -d temp/ +#unzip temp/daterangepicker_v0.18.0.zip -d temp/ + +mv temp/bootstrap-${BOOTSTRAP_VERSION}-dist/js/bootstrap.min.js ./static/js/ +mv temp/bootstrap-${BOOTSTRAP_VERSION}-dist/css/bootstrap.min.css ./static/css/ +mv temp/bootstrap-${BOOTSTRAP_VERSION}-dist/css/bootstrap.min.css.map ./static/css/ + + +#mv temp/Font-Awesome-${FONT_AWESOME_VERSION} temp/font-awesome + +#rm -rf ./static/fonts/ ./static/font-awesome/ +#mv temp/font-awesome/ ./static/ + +#mv temp/jquery-date-range-picker-0.18.0/dist/daterangepicker.min.css ./static/css/ + +mv temp/d3.min.js ./static/js/ +#mv temp/moment-2.22.2/min/moment.min.js ./static/js/ +#mv temp/jquery-date-range-picker-0.18.0/dist/jquery.daterangepicker.min.js ./static/js/ + +rm -rf temp + +JQVERSION="3.3.1" +wget http://code.jquery.com/jquery-${JQVERSION}.min.js -O ./static/js/jquery.js + +#Ressources for dataTable +wget https://cdn.datatables.net/v/bs4/dt-1.10.18/datatables.min.css -O ./static/css/dataTables.bootstrap.css +wget https://cdn.datatables.net/v/bs4/dt-1.10.18/datatables.min.js -O ./static/js/dataTables.bootstrap.js + +rm -rf temp