From 70c268d20ed466c415a1bd1ba1fade74675567a9 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 6 Nov 2017 18:40:44 +0100 Subject: [PATCH] Added support of org logo --- contributor_helper.py | 18 ++++++++++++++++-- static/js/contrib.js | 15 +++++++++++++-- zmq_subscriber.py | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/contributor_helper.py b/contributor_helper.py index da532ac..ae429af 100644 --- a/contributor_helper.py +++ b/contributor_helper.py @@ -9,6 +9,7 @@ class Contributor_helper: self.serv_redis_db = serv_redis_db self.cfg = cfg + self.misp_web_url = cfg.get('RedisGlobal', 'misp_web_url') self.MAX_NUMBER_OF_LAST_CONTRIBUTOR = cfg.getint('CONTRIB', 'max_number_of_last_contributor') self.categories_in_datatable = json.loads(cfg.get('CONTRIB', 'categories_in_datatable')) self.default_pnts_per_contribution = json.loads(cfg.get('CONTRIB', 'default_pnts_per_contribution')) @@ -50,7 +51,7 @@ class Contributor_helper: return self.getTrueRank(ptns) def getOrgLogoFromRedis(self, org): - return 'logo_'+org + return "{}/img/orgs/{}.png".format(self.misp_web_url, org) def getLastContributorsFromRedis(self): date = datetime.datetime.now() @@ -203,6 +204,12 @@ class Contributor_helper: def TEST_getTopContributorFromRedis(self, date): data2 = [ + { + 'rank': random.randint(1,self.levelMax), + 'logo_path': self.getOrgLogoFromRedis('MISP'), + 'org': 'MISP', + 'pnts': random.randint(1,2**self.levelMax) + }, { 'rank': random.randint(1,self.levelMax), 'logo_path': 'logo1', @@ -239,6 +246,13 @@ class Contributor_helper: def TEST_getLastContributorsFromRedis(self): import time data2 = [ + { + 'rank': random.randint(1,self.levelMax), + 'logo_path': self.getOrgLogoFromRedis('MISP'), + 'org': 'MISP', + 'pnts': random.randint(1,2**self.levelMax), + 'epoch': time.time() - random.randint(0, 10000) + }, { 'rank': random.randint(1,self.levelMax), 'logo_path': 'logo1', @@ -278,5 +292,5 @@ class Contributor_helper: return data2*2 def TEST_getAllOrgFromRedis(self): - data2 = ['CIRCL', 'CASES', 'SMILE' ,'ORG4' ,'ORG5', 'SUPER HYPER LONG ORGINZATION NAME', 'Org3'] + data2 = ['CIRCL', 'CASES', 'SMILE' ,'ORG4' ,'ORG5', 'SUPER HYPER LONG ORGINZATION NAME', 'Org3', 'MISP'] return data2 diff --git a/static/js/contrib.js b/static/js/contrib.js index 22f4c8f..b6de8f4 100644 --- a/static/js/contrib.js +++ b/static/js/contrib.js @@ -117,6 +117,17 @@ function getRankIcon(rank, size, header) { } return img.outerHTML; } + +function createImg(source) { + var obj = document.createElement('object'); + obj.height = 26; + obj.width = 26; + obj.style.margin = 'auto'; + obj.data = source; + obj.type = "image/jpg" + return obj.outerHTML; +} + function generateRankingSheet(rank, rankDec, stepPnt, pnt, Rpnt) { var Cpnt = pnt - stepPnt; var Tpnt = Cpnt + Rpnt; @@ -210,7 +221,7 @@ function addToTableFromJson(datatable, url) { var to_add = [ row.pnts, getRankIcon(row.rank), - row.logo_path, + createImg(row.logo_path), row.org ]; datatable.row.add(to_add); @@ -234,7 +245,7 @@ function addLastContributor(datatable, data, update) { var to_add = [ data.pnts, getRankIcon(data.rank), - data.logo_path, + createImg(data.logo_path), data.org, data.epoch ]; diff --git a/zmq_subscriber.py b/zmq_subscriber.py index 6848ef0..1421ca6 100755 --- a/zmq_subscriber.py +++ b/zmq_subscriber.py @@ -18,7 +18,7 @@ configfile = os.path.join(os.environ['DASH_CONFIG'], 'config.cfg') cfg = configparser.ConfigParser() cfg.read(configfile) -ZMQ_URL = cfg.get('RedisLog', 'zmq_url') +ZMQ_URL = cfg.get('RedisGlobal', 'zmq_url') CHANNEL = cfg.get('RedisLog', 'channel') CHANNEL_LASTCONTRIB = cfg.get('RedisLog', 'channelLastContributor') CHANNELDISP = cfg.get('RedisMap', 'channelDisp')