2020-10-13 16:02:30 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
'''
|
|
|
|
Blueprint Flask: crawler splash endpoints: dashboard, onion crawler ...
|
|
|
|
'''
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
|
|
|
|
from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response, abort, send_file
|
|
|
|
from flask_login import login_required, current_user
|
|
|
|
|
|
|
|
# Import Role_Manager
|
|
|
|
from Role_Manager import login_admin, login_analyst, login_read_only
|
|
|
|
|
2022-07-13 15:10:27 +02:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from lib import item_basic
|
|
|
|
from lib.objects.Items import Item
|
|
|
|
from export import Export
|
|
|
|
from packages import Tag
|
2020-10-13 16:02:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
# ============ BLUEPRINT ============
|
|
|
|
objects_item = Blueprint('objects_item', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/objects/item'))
|
|
|
|
|
|
|
|
# ============ VARIABLES ============
|
|
|
|
bootstrap_label = ['primary', 'success', 'danger', 'warning', 'info']
|
|
|
|
|
|
|
|
|
|
|
|
# ============ FUNCTIONS ============
|
|
|
|
|
|
|
|
|
|
|
|
# ============= ROUTES ==============
|
|
|
|
@objects_item.route("/object/item") #completely shows the paste in a new tab
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def showItem(): # # TODO: support post
|
|
|
|
item_id = request.args.get('id')
|
2022-07-13 15:10:27 +02:00
|
|
|
if not item_id or not item_basic.exist_item(item_id):
|
2020-10-13 16:02:30 +02:00
|
|
|
abort(404)
|
|
|
|
|
2022-07-13 15:10:27 +02:00
|
|
|
item = Item(item_id)
|
|
|
|
meta = item.get_meta(options=set(['content', 'crawler', 'duplicates', 'lines', 'size']))
|
2020-10-13 16:02:30 +02:00
|
|
|
|
2022-07-13 15:10:27 +02:00
|
|
|
meta['name'] = meta['id'].replace('/', ' / ')
|
|
|
|
meta['father'] = item_basic.get_item_parent(item_id)
|
2020-10-13 16:02:30 +02:00
|
|
|
## EXPORT SECTION
|
|
|
|
# # TODO: ADD in Export SECTION
|
2022-07-13 15:10:27 +02:00
|
|
|
meta['hive_case'] = Export.get_item_hive_cases(item_id)
|
2020-10-13 16:02:30 +02:00
|
|
|
|
|
|
|
return render_template("show_item.html", bootstrap_label=bootstrap_label,
|
2022-07-13 15:10:27 +02:00
|
|
|
modal_add_tags=Tag.get_modal_add_tags(meta['id'], object_type='item'),
|
2020-10-13 16:02:30 +02:00
|
|
|
is_hive_connected=Export.get_item_hive_cases(item_id),
|
2022-07-13 15:10:27 +02:00
|
|
|
meta=meta)
|
2020-10-13 16:02:30 +02:00
|
|
|
|
|
|
|
# kvrocks data
|
|
|
|
|
|
|
|
# # TODO: dynamic load:
|
|
|
|
## duplicates
|
|
|
|
## correlations
|
|
|
|
|
|
|
|
## Dynamic Path FIX
|
|
|
|
|
|
|
|
@objects_item.route("/object/item/html2text")
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def html2text(): # # TODO: support post
|
|
|
|
item_id = request.args.get('id')
|
2022-07-13 15:10:27 +02:00
|
|
|
if not item_id or not item_basic.exist_item(item_id):
|
2020-10-13 16:02:30 +02:00
|
|
|
abort(404)
|
2022-07-13 15:10:27 +02:00
|
|
|
item = Item(item_id)
|
|
|
|
return item.get_html2text_content()
|
2020-10-13 16:02:30 +02:00
|
|
|
|
|
|
|
@objects_item.route("/object/item/raw_content")
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def item_raw_content(): # # TODO: support post
|
|
|
|
item_id = request.args.get('id')
|
2022-07-13 15:10:27 +02:00
|
|
|
if not item_id or not item_basic.exist_item(item_id):
|
2020-10-13 16:02:30 +02:00
|
|
|
abort(404)
|
2022-07-13 15:10:27 +02:00
|
|
|
item = Item(item_id)
|
|
|
|
return Response(item.get_content(), mimetype='text/plain')
|
2020-10-13 16:02:30 +02:00
|
|
|
|
|
|
|
@objects_item.route("/object/item/download")
|
|
|
|
@login_required
|
|
|
|
@login_read_only
|
|
|
|
def item_download(): # # TODO: support post
|
|
|
|
item_id = request.args.get('id')
|
2022-07-13 15:10:27 +02:00
|
|
|
if not item_id or not item_basic.exist_item(item_id):
|
2020-10-13 16:02:30 +02:00
|
|
|
abort(404)
|
2022-07-13 15:10:27 +02:00
|
|
|
item = Item(item_id)
|
|
|
|
return send_file(item.get_raw_content(), attachment_filename=item_id, as_attachment=True)
|