From 11c4ba69913b317f4b540a471c73346c5ae868dc Mon Sep 17 00:00:00 2001 From: Terrtia Date: Thu, 9 Jul 2020 17:50:43 +0200 Subject: [PATCH] chg: [username correlation + login redirection] add twitter username correlation + redirect to the requested page on login --- .../ail_json_importer/Ail_feeder_twitter.py | 5 ++++- bin/lib/Correlate_object.py | 13 +++++++----- bin/lib/Username.py | 21 +++++++++++++++++++ bin/lib/telegram.py | 8 ++----- bin/packages/Item.py | 10 ++++----- var/www/blueprints/correlation.py | 4 ++-- var/www/blueprints/root.py | 11 ++++++---- .../modules/hashDecoded/Flask_hashDecoded.py | 6 +++++- .../correlation/legend_graph_correlation.html | 11 +++++++++- var/www/templates/login.html | 1 + 10 files changed, 65 insertions(+), 25 deletions(-) create mode 100755 bin/lib/Username.py diff --git a/bin/import/ail_json_importer/Ail_feeder_twitter.py b/bin/import/ail_json_importer/Ail_feeder_twitter.py index ec9fb0a2..a622a800 100755 --- a/bin/import/ail_json_importer/Ail_feeder_twitter.py +++ b/bin/import/ail_json_importer/Ail_feeder_twitter.py @@ -14,6 +14,7 @@ import datetime sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib')) import item_basic +import Username sys.path.append(os.path.join(os.environ['AIL_BIN'], 'import', 'ail_json_importer')) from Default_json import Default_json @@ -34,11 +35,13 @@ class Ail_feeder_twitter(Default_json): item_id = str(self.json_item['meta']['twitter:tweet_id']) return os.path.join('twitter', item_date, item_id) + '.gz' - # # TODO: def process_json_meta(self, process, item_id): ''' Process JSON meta filed. ''' twitter_id = str(self.json_item['meta']['twitter:tweet_id']) item_basic.add_map_obj_id_item_id(twitter_id, item_id, 'twitter_id') + username = str(self.json_item['meta']['twitter:id']) + item_date = item_basic.get_item_date(item_id) + Username.save_item_correlation('twitter', username, item_id, item_date) return None diff --git a/bin/lib/Correlate_object.py b/bin/lib/Correlate_object.py index 90fcea3d..c0d959f5 100755 --- a/bin/lib/Correlate_object.py +++ b/bin/lib/Correlate_object.py @@ -13,7 +13,7 @@ import ConfigLoader import Decoded import Domain import Screenshot -import telegram +import Username sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages/')) import Pgp @@ -36,7 +36,7 @@ def is_valid_object_subtype(object_type, object_subtype): elif object_type == 'cryptocurrency': return Cryptocurrency.cryptocurrency.is_valid_obj_subtype(object_subtype) elif object_type == 'username': - return telegram.correlation.is_valid_obj_subtype(object_subtype) + return Username.correlation.is_valid_obj_subtype(object_subtype) elif object_subtype == None: return True else: @@ -69,7 +69,7 @@ def exist_object(object_type, correlation_id, type_id=None): # => work on object elif object_type == 'cryptocurrency': return Cryptocurrency.cryptocurrency.exist_correlation(type_id, correlation_id) elif object_type == 'username': - return telegram.correlation.exist_correlation(type_id, correlation_id) + return Username.correlation.exist_correlation(type_id, correlation_id) elif object_type == 'screenshot' or object_type == 'image': return Screenshot.exist_screenshot(correlation_id) else: @@ -88,7 +88,7 @@ def get_object_metadata(object_type, correlation_id, type_id=None): elif object_type == 'cryptocurrency': return Cryptocurrency.cryptocurrency.get_metadata(type_id, correlation_id) elif object_type == 'username': - return telegram.correlation.get_metadata(type_id, correlation_id) + return Username.correlation.get_metadata(type_id, correlation_id) elif object_type == 'screenshot' or object_type == 'image': return Screenshot.get_metadata(correlation_id) @@ -104,7 +104,7 @@ def get_object_correlation(object_type, value, correlation_names=None, correlati elif object_type == 'cryptocurrency': return Cryptocurrency.cryptocurrency.get_correlation_all_object(requested_correl_type, value, correlation_objects=correlation_objects) elif object_type == 'username': - return telegram.correlation.get_correlation_all_object(requested_correl_type, value, correlation_objects=correlation_objects) + return Username.correlation.get_correlation_all_object(requested_correl_type, value, correlation_objects=correlation_objects) elif object_type == 'screenshot' or object_type == 'image': return Screenshot.get_screenshot_correlated_object(value, correlation_objects=correlation_objects) return {} @@ -157,6 +157,9 @@ def get_correlation_node_icon(correlation_name, correlation_type=None, value=Non if correlation_type == 'telegram': icon_class = 'fab' icon_text = '\uf2c6' + elif correlation_type == 'twitter': + icon_class = 'fab' + icon_text = '\uf099' else: icon_text = '\uf007' diff --git a/bin/lib/Username.py b/bin/lib/Username.py new file mode 100755 index 00000000..0448a167 --- /dev/null +++ b/bin/lib/Username.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*-coding:UTF-8 -* + +import os +import sys +import redis + +sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/')) +import ConfigLoader + +sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages/')) +import Correlation + +config_loader = ConfigLoader.ConfigLoader() +r_serv_crawler = config_loader.get_redis_conn("ARDB_Onion") +config_loader = None + +correlation = Correlation.Correlation('username', ['telegram', 'twitter']) + +def save_item_correlation(subtype, username, item_id, item_date): + correlation.save_item_correlation(subtype, username, item_id, item_date) diff --git a/bin/lib/telegram.py b/bin/lib/telegram.py index 08eafeff..cfad88ed 100755 --- a/bin/lib/telegram.py +++ b/bin/lib/telegram.py @@ -5,20 +5,16 @@ import os import sys import redis -sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/')) -import Correlation - sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/')) import ConfigLoader +import Username config_loader = ConfigLoader.ConfigLoader() r_serv_crawler = config_loader.get_redis_conn("ARDB_Onion") config_loader = None -correlation = Correlation.Correlation('username', ['telegram']) - def save_item_correlation(username, item_id, item_date): - correlation.save_item_correlation('telegram', username, item_id, item_date) + Username.save_item_correlation('telegram', username, item_id, item_date) def save_telegram_invite_hash(invite_hash, item_id): r_serv_crawler.sadd('telegram:invite_code', '{};{}'.format(invite_hash, item_id)) diff --git a/bin/packages/Item.py b/bin/packages/Item.py index a551157f..d898d1e0 100755 --- a/bin/packages/Item.py +++ b/bin/packages/Item.py @@ -20,7 +20,7 @@ import ConfigLoader import Correlate_object import Decoded import Screenshot -import telegram +import Username from item_basic import * @@ -156,15 +156,15 @@ def get_item_pgp(item_id, currencies_type=None, get_nb=False): ''' return Pgp.pgp.get_item_correlation_dict(item_id, correlation_type=currencies_type, get_nb=get_nb) -def get_item_username(item_id, currencies_type=None, get_nb=False): +def get_item_username(item_id, sub_type=None, get_nb=False): ''' Return all pgp of a given item. :param item_id: item id - :param currencies_type: list of cryptocurrencies type - :type currencies_type: list, optional + :param sub_type: list of username type + :type sub_type: list, optional ''' - return telegram.correlation.get_item_correlation_dict(item_id, correlation_type=currencies_type, get_nb=get_nb) + return Username.correlation.get_item_correlation_dict(item_id, correlation_type=sub_type, get_nb=get_nb) def get_item_decoded(item_id): ''' diff --git a/var/www/blueprints/correlation.py b/var/www/blueprints/correlation.py index 359ac612..03c7ea5e 100644 --- a/var/www/blueprints/correlation.py +++ b/var/www/blueprints/correlation.py @@ -25,7 +25,7 @@ import Correlate_object import Domain import Screenshot import btc_ail -import telegram +import Username sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages')) import Cryptocurrency @@ -110,7 +110,7 @@ def get_card_metadata(object_type, correlation_id, type_id=None, expand_card=Fal card_dict["sparkline"] = Pgp.pgp.get_list_nb_previous_correlation_object(type_id, correlation_id, 6) card_dict["icon"] = Correlate_object.get_correlation_node_icon(object_type, type_id) elif object_type == 'username': - card_dict["sparkline"] = telegram.correlation.get_list_nb_previous_correlation_object(type_id, correlation_id, 6) + card_dict["sparkline"] = Username.correlation.get_list_nb_previous_correlation_object(type_id, correlation_id, 6) card_dict["icon"] = Correlate_object.get_correlation_node_icon(object_type, type_id) elif object_type == 'decoded': card_dict["sparkline"] = Decoded.get_list_nb_previous_hash(correlation_id, 6) diff --git a/var/www/blueprints/root.py b/var/www/blueprints/root.py index 83446dc6..2c69be46 100644 --- a/var/www/blueprints/root.py +++ b/var/www/blueprints/root.py @@ -54,7 +54,7 @@ def login(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') - #next_page = request.form.get('next_page') + next_page = request.form.get('next_page') if username is not None: user = User.get(username) @@ -74,7 +74,10 @@ def login(): if user.request_password_change(): return redirect(url_for('root.change_password')) else: - return redirect(url_for('dashboard.index')) + if next_page and next_page!='None': + return redirect(next_page) + else: + return redirect(url_for('dashboard.index')) # login failed else: # set brute force protection @@ -91,9 +94,9 @@ def login(): return 'please provide a valid username' else: - #next_page = request.args.get('next') + next_page = request.args.get('next') error = request.args.get('error') - return render_template("login.html" , error=error) + return render_template("login.html" , next_page=next_page, error=error) @root.route('/change_password', methods=['POST', 'GET']) @login_required diff --git a/var/www/modules/hashDecoded/Flask_hashDecoded.py b/var/www/modules/hashDecoded/Flask_hashDecoded.py index 0ad24fdf..4186e431 100644 --- a/var/www/modules/hashDecoded/Flask_hashDecoded.py +++ b/var/www/modules/hashDecoded/Flask_hashDecoded.py @@ -39,7 +39,7 @@ hashDecoded = Blueprint('hashDecoded', __name__, template_folder='templates') ## TODO: put me in option all_cryptocurrency = ['bitcoin', 'ethereum', 'bitcoin-cash', 'litecoin', 'monero', 'zcash', 'dash'] all_pgpdump = ['key', 'name', 'mail'] -all_username = ['telegram'] +all_username = ['telegram', 'twitter'] # ============ FUNCTIONS ============ @@ -128,6 +128,8 @@ def get_icon(correlation_type, type_id): elif correlation_type == 'username': if type_id == 'telegram': icon_text = 'fab fa-telegram-plane' + elif type_id == 'twitter': + icon_text = 'fab fa-twitter' return icon_text def get_icon_text(correlation_type, type_id): @@ -153,6 +155,8 @@ def get_icon_text(correlation_type, type_id): elif correlation_type == 'username': if type_id == 'telegram': icon_text = '\uf2c6' + elif type_id == 'twitter': + icon_text = '\uf099' return icon_text def get_all_types_id(correlation_type): diff --git a/var/www/templates/correlation/legend_graph_correlation.html b/var/www/templates/correlation/legend_graph_correlation.html index 15fee4d9..b8d095fa 100644 --- a/var/www/templates/correlation/legend_graph_correlation.html +++ b/var/www/templates/correlation/legend_graph_correlation.html @@ -152,7 +152,16 @@ telegram - +
+ + + + + + + twitter +
+ f099
diff --git a/var/www/templates/login.html b/var/www/templates/login.html index a0c01462..4b941520 100644 --- a/var/www/templates/login.html +++ b/var/www/templates/login.html @@ -73,6 +73,7 @@
{{error}}