mirror of https://github.com/D4-project/d4-core
chg: [server UI v0.1] use json type
parent
3aadf48eb1
commit
451bea651a
server/web
|
@ -5,6 +5,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
import redis
|
import redis
|
||||||
import flask
|
import flask
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -21,15 +22,7 @@ port_redis_stream = 6379
|
||||||
|
|
||||||
default_max_entries_by_stream = 10000
|
default_max_entries_by_stream = 10000
|
||||||
|
|
||||||
json_type_description = {
|
json_type_description_path = os.path.join(os.environ['D4_HOME'], 'web/static/json/type.json')
|
||||||
"1": "pcap (libpcap 2.4)",
|
|
||||||
"2": "meta header (JSON)",
|
|
||||||
"3": "generic log line",
|
|
||||||
"4": "dnscap output",
|
|
||||||
"5": "pcapng (diagnostic)",
|
|
||||||
"6": "generic NDJSON or JSON Lines",
|
|
||||||
"7": "generic YAF (Yet Another Flowmeter)",
|
|
||||||
}
|
|
||||||
|
|
||||||
redis_server_stream = redis.StrictRedis(
|
redis_server_stream = redis.StrictRedis(
|
||||||
host=host_redis_stream,
|
host=host_redis_stream,
|
||||||
|
@ -75,6 +68,11 @@ def get_server_management_input_handler_value(value):
|
||||||
value=0
|
value=0
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def get_json_type_description():
|
||||||
|
with open(json_type_description_path, 'r') as f:
|
||||||
|
json_type_description = json.loads(f.read())
|
||||||
|
return json_type_description
|
||||||
|
|
||||||
# ========== ROUTES ============
|
# ========== ROUTES ============
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
@ -139,9 +137,11 @@ def server_management():
|
||||||
blacklisted_uuid = get_server_management_input_handler_value(blacklisted_uuid)
|
blacklisted_uuid = get_server_management_input_handler_value(blacklisted_uuid)
|
||||||
unblacklisted_uuid = get_server_management_input_handler_value(unblacklisted_uuid)
|
unblacklisted_uuid = get_server_management_input_handler_value(unblacklisted_uuid)
|
||||||
|
|
||||||
|
json_type_description = get_json_type_description()
|
||||||
|
|
||||||
list_accepted_types = []
|
list_accepted_types = []
|
||||||
for type in redis_server_metadata.smembers('server:accepted_type'):
|
for type in redis_server_metadata.smembers('server:accepted_type'):
|
||||||
list_accepted_types.append({"id": int(type), "description": json_type_description[type]})
|
list_accepted_types.append({"id": int(type), "description": json_type_description[int(type)]['description']})
|
||||||
|
|
||||||
return render_template("server_management.html", list_accepted_types=list_accepted_types,
|
return render_template("server_management.html", list_accepted_types=list_accepted_types,
|
||||||
blacklisted_ip=blacklisted_ip, unblacklisted_ip=unblacklisted_ip,
|
blacklisted_ip=blacklisted_ip, unblacklisted_ip=unblacklisted_ip,
|
||||||
|
@ -297,7 +297,8 @@ def unblacklist_ip_by_uuid():
|
||||||
def add_accepted_type():
|
def add_accepted_type():
|
||||||
type = request.args.get('type')
|
type = request.args.get('type')
|
||||||
user = request.args.get('redirect')
|
user = request.args.get('redirect')
|
||||||
if json_type_description[type]:
|
json_type_description = get_json_type_description()
|
||||||
|
if json_type_description[int(type)]:
|
||||||
redis_server_metadata.sadd('server:accepted_type', type)
|
redis_server_metadata.sadd('server:accepted_type', type)
|
||||||
if user:
|
if user:
|
||||||
return redirect(url_for('server_management'))
|
return redirect(url_for('server_management'))
|
||||||
|
@ -308,7 +309,8 @@ def add_accepted_type():
|
||||||
def remove_accepted_type():
|
def remove_accepted_type():
|
||||||
type = request.args.get('type')
|
type = request.args.get('type')
|
||||||
user = request.args.get('redirect')
|
user = request.args.get('redirect')
|
||||||
if json_type_description[type]:
|
json_type_description = get_json_type_description()
|
||||||
|
if json_type_description[int(type)]:
|
||||||
redis_server_metadata.srem('server:accepted_type', type)
|
redis_server_metadata.srem('server:accepted_type', type)
|
||||||
if user:
|
if user:
|
||||||
return redirect(url_for('server_management'))
|
return redirect(url_for('server_management'))
|
||||||
|
|
|
@ -12,6 +12,9 @@ fi
|
||||||
if [ ! -d static/js ]; then
|
if [ ! -d static/js ]; then
|
||||||
mkdir static/js
|
mkdir static/js
|
||||||
fi
|
fi
|
||||||
|
if [ ! -d static/json ]; then
|
||||||
|
mkdir static/json
|
||||||
|
fi
|
||||||
|
|
||||||
rm -rf temp
|
rm -rf temp
|
||||||
mkdir temp
|
mkdir temp
|
||||||
|
@ -59,4 +62,7 @@ wget https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap4.min.css -O ./s
|
||||||
wget https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap4.min.js -O ./static/js/dataTables.bootstrap.min.js
|
wget https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap4.min.js -O ./static/js/dataTables.bootstrap.min.js
|
||||||
wget https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js -O ./static/js/jquery.dataTables.min.js
|
wget https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js -O ./static/js/jquery.dataTables.min.js
|
||||||
|
|
||||||
|
#Update json
|
||||||
|
wget https://raw.githubusercontent.com/D4-project/architecture/master/format/type.json -O ./static/json/type.json
|
||||||
|
|
||||||
rm -rf temp
|
rm -rf temp
|
||||||
|
|
Loading…
Reference in New Issue