diff --git a/bin/Tags.py b/bin/Tags.py index 3f0dc44f..88e0ef0e 100755 --- a/bin/Tags.py +++ b/bin/Tags.py @@ -41,6 +41,7 @@ if __name__ == '__main__': continue else: + print(message) tag, item_id = message.split(';') Tag.add_tag("item", tag, item_id) diff --git a/bin/lib/Correlate_object.py b/bin/lib/Correlate_object.py index 590698cd..1854902c 100755 --- a/bin/lib/Correlate_object.py +++ b/bin/lib/Correlate_object.py @@ -181,7 +181,10 @@ def get_item_url(correlation_name, value, correlation_type=None): elif correlation_name == 'domain': endpoint = 'crawler_splash.showDomain' url = url_for(endpoint, domain=value) - elif correlation_name == 'paste': + elif correlation_name == 'item': + endpoint = 'showsavedpastes.showsavedpaste' + url = url_for(endpoint, paste=value) + elif correlation_name == 'paste': ### # TODO: remove me endpoint = 'showsavedpastes.showsavedpaste' url = url_for(endpoint, paste=value) return url diff --git a/bin/packages/Tag.py b/bin/packages/Tag.py index 2b131b75..6b95da7e 100755 --- a/bin/packages/Tag.py +++ b/bin/packages/Tag.py @@ -6,6 +6,7 @@ import sys import redis import datetime +sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages/')) import Date import Item @@ -156,7 +157,7 @@ def get_modal_add_tags(item_id, object_type='item'): Modal: add tags to domain or Paste ''' return {"active_taxonomies": get_active_taxonomies(), "active_galaxies": get_active_galaxies(), - "object_id": item_id, "object_type": tag_type} + "object_id": item_id, "object_type": object_type} ######## NEW VERSION ######## def get_tag_first_seen(tag, r_int=False): @@ -204,7 +205,7 @@ def is_obj_tagged(object_id, tag): :return: is object tagged :rtype: boolean ''' - return r_serv_tags.sismember('tag:{}'.format(object_id), tag) + return r_serv_metadata.sismember('tag:{}'.format(object_id), tag) def get_all_tags(): return list(r_serv_tags.smembers('list_tags')) @@ -333,16 +334,20 @@ def api_add_obj_tags(tags=[], galaxy_tags=[], object_id=None, object_type="item" return ({'status': 'error', 'reason': 'object_id id not found'}, 404) if not tags and not galaxy_tags: return ({'status': 'error', 'reason': 'Tags or Galaxy not specified'}, 400) - if object_type not in ('paste', 'domain'): # # TODO: put me in another file + if object_type not in ('item', 'domain'): # # TODO: put me in another file return ({'status': 'error', 'reason': 'Incorrect object_type'}, 400) - res = add_obj_tags(object_id, object_type, tags=[], galaxy_tags=[]) + # remove empty tags + tags = list(filter(bool, tags)) + galaxy_tags = list(filter(bool, galaxy_tags)) + + res = add_obj_tags(object_id, object_type, tags=tags, galaxy_tags=galaxy_tags) if res: return res res_dict['tags'] = tags + galaxy_tags - res_dict['id'] = item_id - res_dict['type'] = item_type + res_dict['id'] = object_id + res_dict['type'] = object_type return (res_dict, 200) def add_obj_tag(object_type, object_id, tag, obj_date=None): @@ -403,7 +408,7 @@ def api_delete_obj_tags(tags=[], object_id=None, object_type="item"): if not tags: return ({'status': 'error', 'reason': 'No Tag(s) specified'}, 400) - res = delete_obj_tags(object_id, object_type, tags=[]) + res = delete_obj_tags(object_id, object_type, tags=tags) if res: return res diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 728222ca..201c080d 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -39,6 +39,8 @@ import Flask_config from blueprints.root import root from blueprints.crawler_splash import crawler_splash from blueprints.correlation import correlation +from blueprints.tags_ui import tags_ui + Flask_dir = os.environ['AIL_FLASK'] @@ -85,6 +87,7 @@ app.config['MAX_CONTENT_LENGTH'] = 900 * 1024 * 1024 app.register_blueprint(root, url_prefix=baseUrl) app.register_blueprint(crawler_splash, url_prefix=baseUrl) app.register_blueprint(correlation, url_prefix=baseUrl) +app.register_blueprint(tags_ui, url_prefix=baseUrl) # ========= =========# # ========= session ======== diff --git a/var/www/blueprints/tags.py b/var/www/blueprints/tags_ui.py similarity index 88% rename from var/www/blueprints/tags.py rename to var/www/blueprints/tags_ui.py index 9f38e860..05d9313b 100644 --- a/var/www/blueprints/tags.py +++ b/var/www/blueprints/tags_ui.py @@ -25,7 +25,7 @@ import Date import Tag sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib')) -import Domain +import Correlate_object r_cache = Flask_config.r_cache r_serv_db = Flask_config.r_serv_db @@ -33,7 +33,7 @@ r_serv_tags = Flask_config.r_serv_tags bootstrap_label = Flask_config.bootstrap_label # ============ BLUEPRINT ============ -tags_ui = Blueprint('tags', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/tags')) +tags_ui = Blueprint('tags_ui', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/tags')) # ============ VARIABLES ============ @@ -82,15 +82,8 @@ def add_tags(): # error if res[1] != 200: return str(res[0]) - # success - - # # TODO: use object FUNCTIONS - - if object_type=='domain': - return redirect(url_for('crawler_splash.showDomain', domain=object_id)) - else: - return redirect(url_for('showsavedpastes.showsavedpaste', paste=object_id)) + return redirect(Correlate_object.get_item_url(object_type, object_id)) diff --git a/var/www/modules/Tags/Flask_Tags.py b/var/www/modules/Tags/Flask_Tags.py index d9060912..f2bb6101 100644 --- a/var/www/modules/Tags/Flask_Tags.py +++ b/var/www/modules/Tags/Flask_Tags.py @@ -375,7 +375,7 @@ def remove_tag(): path = request.args.get('paste') tag = request.args.get('tag') - res = Tag.api_delete_obj_tags(tags=tag, object_id=path, object_type="item") + res = Tag.api_delete_obj_tags(tags=[tag], object_id=path, object_type="item") if res[1] != 200: return str(res[0]) return redirect(url_for('showsavedpastes.showsavedpaste', paste=path)) @@ -390,11 +390,11 @@ def confirm_tag(): tag = request.args.get('tag') if(tag[9:28] == 'automatic-detection'): - Tag.api_delete_obj_tags(tags=tag, object_id=path, object_type="item") + Tag.api_delete_obj_tags(tags=[tag], object_id=path, object_type="item") tag = tag.replace('automatic-detection','analyst-detection', 1) #add analyst tag - Tag.add_item_tag(tag, path) + Tag.add_tag('item', tag, path) return redirect(url_for('showsavedpastes.showsavedpaste', paste=path)) diff --git a/var/www/modules/showpaste/templates/show_saved_paste.html b/var/www/modules/showpaste/templates/show_saved_paste.html index 7b2b265b..b2c0a8bf 100644 --- a/var/www/modules/showpaste/templates/show_saved_paste.html +++ b/var/www/modules/showpaste/templates/show_saved_paste.html @@ -570,7 +570,7 @@ var tags = ltags.getValue() var tagsgalaxy = ltagsgalaxies.getValue() var path = '{{ request.args.get('paste') }}' - window.location.replace("{{ url_for('Tags.addTags') }}?tags=" + tags + "&tagsgalaxies=" + tagsgalaxy + "&path=" + path); + window.location.replace("{{ url_for('tags_ui.add_tags') }}?tags=" + tags + "&tagsgalaxies=" + tagsgalaxy + "&object_id=" + path + "&object_type=item"); } diff --git a/var/www/templates/modals/add_tags.html b/var/www/templates/modals/add_tags.html index e2a4f7a0..2f06811b 100644 --- a/var/www/templates/modals/add_tags.html +++ b/var/www/templates/modals/add_tags.html @@ -126,6 +126,6 @@ jQuery("#all-tags-galaxies").click(function(e){ function addTags() { var tags = ltags.getValue() var tagsgalaxy = ltagsgalaxies.getValue() - window.location.replace("{{ url_for('tags_ui.add_item_tags') }}?tags=" + tags + "&tagsgalaxies=" + tagsgalaxy + "&object_id={{ modal_add_tags['object_id'] }}&object_type={{ modal_add_tags['object_type'] }}"); + window.location.replace("{{ url_for('tags_ui.add_tags') }}?tags=" + tags + "&tagsgalaxies=" + tagsgalaxy + "&object_id={{ modal_add_tags['object_id'] }}&object_type={{ modal_add_tags['object_type'] }}"); }