UI attunement - Possibility to adjust with of panels in config, immediatly change text. Bit of zmq refacto

pull/18/head
Sami Mokaddem 2017-10-25 12:12:14 +02:00
parent 6425fc711e
commit 6c7916b5be
6 changed files with 30 additions and 28 deletions

View File

@ -6,6 +6,8 @@ rotation_wait_time = 30
max_img_rotation = 10
hours_spanned = 48
zoomlevel = 15
# [1->12]
size_dashboard_left_width = 5
size_openStreet_pannel_perc = 55
size_world_pannel_perc = 35
@ -26,3 +28,4 @@ port=6250
db=1
channelProc=CoordToProcess
channelDisp=PicToDisplay
pathMaxMindDB=/home/sami/Downloads/GeoLite2-City_20171003/GeoLite2-City.mmdb

View File

@ -97,6 +97,7 @@ def index():
]
return render_template('index.html',
pannelSize=pannelSize,
size_dashboard_width=[cfg.getint('Dashboard' ,'size_dashboard_left_width'), 12-cfg.getint('Dashboard', 'size_dashboard_left_width')],
graph_log_refresh_rate=cfg.getint('Dashboard' ,'graph_log_refresh_rate'),
char_separator=cfg.get('Log', 'char_separator'),
rotation_wait_time=cfg.getint('Dashboard' ,'rotation_wait_time'),

View File

@ -240,18 +240,10 @@ function updateLogTable(feedName, log, zmqName) {
createRow(tableBody, log);
// Remove old row
var logSel = document.getElementById("log_select");
//get height of pannel, find max num of item
var maxNumLogItem = document.getElementById('divLogTable').clientHeight/37;
maxNumLogItem -= 2; //take heading/padding/... into account
if (maxNumLogItem - parseInt(maxNumLogItem) < 0.5) { //beautifier
maxNumLogItem -= 1;
}
if (tableBody.rows.length > maxNumLogItem) {
while (tableBody.rows.length >= maxNumLogItem){
tableBody.deleteRow(0);
}
while ($("#table_log").height() >= $("#panelLogTable").height()-26){ //26 for margin
tableBody.deleteRow(0);
}
} else if (feedName == "Keepalive") {
// do nothing
} else {

View File

@ -90,7 +90,7 @@ class MapEventManager {
myOpenStreetMap.flyTo([mapEvent.coord.lat, mapEvent.coord.lon], ZOOMLEVEL);
mapEvent.marker.bindPopup(mapEvent.textMarker).openPopup();
$("#textMap1").fadeOut(400, function(){ $(this).text(mapEvent.text); }).fadeIn(400);
$("#textMap1").text(mapEvent.text);
if(ROTATIONWAITTIME != 0) {
this._timeoutRotate = setTimeout(function(){ mapEventManager.rotateMap(); }, ROTATIONWAITTIME);
}

View File

@ -123,7 +123,7 @@ small {
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="col-lg-5">
<div class="col-lg-{{ size_dashboard_width[0] }}">
<div id="panelOpenMap" class="panel panel-default" style="margin-top: 15px; height: {{ pannelSize[0] }}vh;">
<div class="panel-heading bg-info" style="font-weight: bold;">
@ -168,7 +168,7 @@ small {
</div>
<!-- /.col-lg-6 -->
<!-- /.col-lg-6 -->
<div class="col-lg-7">
<div class="col-lg-{{ size_dashboard_width[1] }}">
<div class="panel panel-default" style="margin-top: 15px; height: {{ pannelSize[2] }}vh;">
<div id="panelbody" class="panel-body" style="height: 100%;">
@ -179,7 +179,7 @@ small {
</div>
<!-- /.panel -->
<div class="panel panel-default" style="height: {{ pannelSize[3] }}vh;">
<div id="panelLogTable" class="panel panel-default" style="height: {{ pannelSize[3] }}vh;">
<div class="panel-heading">
<i class="fa fa-tasks fa-fw"></i> Logs
<div class="pull-right">
@ -188,7 +188,7 @@ small {
<input id="checkbox_log_critical" type="checkbox" value="critical" checked="true"> CRITICAL
</div>
</div>
<div id="divLogTable" class="panel-body" style="height: 98%;">
<div id="divLogTable" class="panel-body" style="height: 98%; padding: 0px;">
<div class="row" style="height: 100%;">
<div class="col-lg-12" style="height: 100%;">
<table class="table table-bordered table-hover table-striped" id="table_log">

View File

@ -15,13 +15,11 @@ configfile = os.path.join(os.environ['VIRTUAL_ENV'], '../config.cfg')
cfg = configparser.ConfigParser()
cfg.read(configfile)
zmq_url = cfg.get('RedisLog', 'zmq_url')
channel = cfg.get('RedisLog', 'channel')
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect(zmq_url)
socket.setsockopt_string(zmq.SUBSCRIBE, '')
channelDisp = cfg.get('RedisMap', 'channelDisp')
ZMQ_URL = cfg.get('RedisLog', 'zmq_url')
CHANNEL = cfg.get('RedisLog', 'channel')
CHANNELDISP = cfg.get('RedisMap', 'channelDisp')
CHANNEL_PROC = cfg.get('RedisMap', 'channelProc')
PATH_TO_DB = cfg.get('RedisMap', 'pathMaxMindDB')
redis_server = redis.StrictRedis(
host=cfg.get('RedisLog', 'host'),
@ -31,14 +29,13 @@ serv_coord = redis.StrictRedis(
host=cfg.get('RedisMap', 'host'),
port=cfg.getint('RedisMap', 'port'),
db=cfg.getint('RedisMap', 'db'))
path_to_db = "/home/sami/Downloads/GeoLite2-City_20171003/GeoLite2-City.mmdb"
reader = geoip2.database.Reader(path_to_db)
channel_proc = "CoordToProcess"
reader = geoip2.database.Reader(PATH_TO_DB)
def publish_log(zmq_name, name, content):
to_send = { 'name': name, 'log': json.dumps(content), 'zmqName': zmq_name }
redis_server.publish(channel, json.dumps(to_send))
redis_server.publish(CHANNEL, json.dumps(to_send))
def ip_to_coord(ip):
@ -70,7 +67,7 @@ def getCoordAndPublish(zmq_name, supposed_ip, categ):
"cityName": rep['full_rep'].city.name,
"regionCode": rep['full_rep'].country.iso_code,
}
serv_coord.publish(channelDisp, json.dumps(to_send))
serv_coord.publish(CHANNELDISP, json.dumps(to_send))
except ValueError:
print("can't resolve ip")
@ -94,6 +91,8 @@ def handler_event(zmq_name, jsonevent):
#redirect to handler_attribute
if 'Attribute' in jsonevent:
attributes = jsonevent['Attribute']
print("+--------- EVENTS -----------+")
print(attributes)
if attributes is list:
for attr in attributes:
handler_attribute(zmq_name, attr)
@ -102,6 +101,7 @@ def handler_event(zmq_name, jsonevent):
def handler_attribute(zmq_name, jsonattr):
print("+--------- ATTRIBUTE -----------+")
jsonattr = jsonattr['Attribute']
print(jsonattr)
to_push = []
@ -128,6 +128,11 @@ def process_log(zmq_name, event):
def main(zmqName):
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect(ZMQ_URL)
socket.setsockopt_string(zmq.SUBSCRIBE, '')
while True:
content = socket.recv()
content.replace(b'\n', b'') # remove \n...
@ -150,6 +155,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description='A zmq subscriber. It subscribe to a ZNQ then redispatch it to the misp-dashboard')
parser.add_argument('-n', '--name', required=False, dest='zmqname', help='The ZMQ feed name', default="Misp Standard ZMQ")
parser.add_argument('-u', '--url', required=False, dest='zmqurl', help='The URL to connect to', default=ZMQ_URL)
args = parser.parse_args()
main(args.zmqname)