mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 00:28:22 +00:00
chg: [Tag core] objects tagging, Part 2/2
TODO: UI tags domain + screenshot + object rename paste=>item
This commit is contained in:
parent
b557b7fed8
commit
85d5770e80
8 changed files with 28 additions and 23 deletions
|
@ -41,6 +41,7 @@ if __name__ == '__main__':
|
|||
continue
|
||||
|
||||
else:
|
||||
print(message)
|
||||
tag, item_id = message.split(';')
|
||||
|
||||
Tag.add_tag("item", tag, item_id)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 ========
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
||||
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -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'] }}");
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue