2022-09-01 14:04:00 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2023-04-04 10:25:01 +02:00
|
|
|
from uuid import uuid4
|
2022-09-01 14:04:00 +02:00
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from lib.ConfigLoader import ConfigLoader
|
|
|
|
|
|
|
|
config_loader = ConfigLoader()
|
2023-01-16 16:27:49 +01:00
|
|
|
r_serv_db = config_loader.get_db_conn("Kvrocks_DB")
|
2022-09-01 14:04:00 +02:00
|
|
|
config_loader = None
|
|
|
|
|
2023-01-16 16:27:49 +01:00
|
|
|
AIL_OBJECTS = sorted({'cve', 'cryptocurrency', 'decoded', 'domain', 'item', 'pgp', 'screenshot', 'username'})
|
2022-11-22 10:47:15 +01:00
|
|
|
|
2022-09-01 14:04:00 +02:00
|
|
|
def get_ail_uuid():
|
2023-01-16 16:27:49 +01:00
|
|
|
return r_serv_db.get('ail:uuid')
|
2022-09-01 14:04:00 +02:00
|
|
|
|
2023-04-04 10:25:01 +02:00
|
|
|
def generate_uuid():
|
|
|
|
return str(uuid4())
|
|
|
|
|
2022-09-01 14:04:00 +02:00
|
|
|
#### AIL OBJECTS ####
|
|
|
|
|
|
|
|
def get_all_objects():
|
2022-11-22 10:47:15 +01:00
|
|
|
return AIL_OBJECTS
|
2022-09-01 14:04:00 +02:00
|
|
|
|
2023-02-28 11:01:27 +01:00
|
|
|
def get_objects_with_subtypes():
|
|
|
|
return ['cryptocurrency', 'pgp', 'username']
|
|
|
|
|
2022-09-01 14:04:00 +02:00
|
|
|
def get_object_all_subtypes(obj_type):
|
|
|
|
if obj_type == 'cryptocurrency':
|
|
|
|
return ['bitcoin', 'bitcoin-cash', 'dash', 'ethereum', 'litecoin', 'monero', 'zcash']
|
|
|
|
if obj_type == 'pgp':
|
|
|
|
return ['key', 'mail', 'name']
|
|
|
|
if obj_type == 'username':
|
|
|
|
return ['telegram', 'twitter', 'jabber']
|
|
|
|
|
2023-01-16 16:27:49 +01:00
|
|
|
def get_all_objects_with_subtypes_tuple():
|
|
|
|
str_objs = []
|
|
|
|
for obj_type in get_all_objects():
|
|
|
|
subtypes = get_object_all_subtypes(obj_type)
|
|
|
|
if subtypes:
|
|
|
|
for subtype in subtypes:
|
|
|
|
str_objs.append((obj_type, subtype))
|
|
|
|
else:
|
|
|
|
str_objs.append((obj_type, ''))
|
|
|
|
return str_objs
|
|
|
|
|
2022-09-01 14:04:00 +02:00
|
|
|
##-- AIL OBJECTS --##
|
2022-11-28 15:01:40 +01:00
|
|
|
|
|
|
|
def paginate_iterator(iter_elems, nb_obj=50, page=1):
|
2023-01-16 16:27:49 +01:00
|
|
|
dict_page = {'nb_all_elem': len(iter_elems)}
|
2022-11-28 15:01:40 +01:00
|
|
|
nb_pages = dict_page['nb_all_elem'] / nb_obj
|
|
|
|
if not nb_pages.is_integer():
|
|
|
|
nb_pages = int(nb_pages)+1
|
|
|
|
else:
|
|
|
|
nb_pages = int(nb_pages)
|
|
|
|
if page > nb_pages:
|
|
|
|
page = nb_pages
|
|
|
|
|
|
|
|
# multiple pages
|
|
|
|
if nb_pages > 1:
|
|
|
|
dict_page['list_elem'] = []
|
|
|
|
start = nb_obj*(page - 1)
|
|
|
|
stop = (nb_obj*page) - 1
|
|
|
|
current_index = 0
|
|
|
|
for elem in iter_elems:
|
|
|
|
if current_index > stop:
|
|
|
|
break
|
|
|
|
if start <= current_index <= stop:
|
|
|
|
dict_page['list_elem'].append(elem)
|
|
|
|
current_index += 1
|
|
|
|
stop += 1
|
|
|
|
if stop > dict_page['nb_all_elem']:
|
|
|
|
stop = dict_page['nb_all_elem']
|
|
|
|
|
|
|
|
else:
|
|
|
|
start = 0
|
|
|
|
stop = dict_page['nb_all_elem']
|
|
|
|
dict_page['list_elem'] = list(iter_elems)
|
|
|
|
dict_page['page'] = page
|
|
|
|
dict_page['nb_pages'] = nb_pages
|
|
|
|
# UI
|
|
|
|
dict_page['nb_first_elem'] = start+1
|
|
|
|
dict_page['nb_last_elem'] = stop
|
|
|
|
return dict_page
|