2019-10-30 16:12:04 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
'''
|
|
|
|
Blueprint Flask: crawler splash endpoints: dashboard, onion crawler ...
|
|
|
|
'''
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2019-10-31 16:14:23 +00:00
|
|
|
import json
|
|
|
|
import random
|
2019-10-30 16:12:04 +00:00
|
|
|
|
|
|
|
from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for, Response
|
|
|
|
from flask_login import login_required, current_user, login_user, logout_user
|
|
|
|
|
|
|
|
sys.path.append('modules')
|
|
|
|
import Flask_config
|
|
|
|
|
|
|
|
# Import Role_Manager
|
|
|
|
from Role_Manager import create_user_db, check_password_strength, check_user_role_integrity
|
2019-11-20 15:15:08 +00:00
|
|
|
from Role_Manager import login_admin, login_analyst, login_read_only
|
2019-10-30 16:12:04 +00:00
|
|
|
|
2019-11-05 08:49:51 +00:00
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages'))
|
2019-11-19 13:03:23 +00:00
|
|
|
import Tag
|
2019-11-05 08:49:51 +00:00
|
|
|
|
2019-10-30 16:12:04 +00:00
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib'))
|
|
|
|
import Domain
|
|
|
|
|
|
|
|
r_cache = Flask_config.r_cache
|
|
|
|
r_serv_db = Flask_config.r_serv_db
|
|
|
|
r_serv_tags = Flask_config.r_serv_tags
|
|
|
|
bootstrap_label = Flask_config.bootstrap_label
|
|
|
|
|
|
|
|
# ============ BLUEPRINT ============
|
|
|
|
crawler_splash = Blueprint('crawler_splash', __name__, template_folder=os.path.join(os.environ['AIL_FLASK'], 'templates/crawler/crawler_splash'))
|
|
|
|
|
|
|
|
# ============ VARIABLES ============
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============ FUNCTIONS ============
|
2019-10-31 16:14:23 +00:00
|
|
|
def api_validator(api_response):
|
|
|
|
if api_response:
|
|
|
|
return Response(json.dumps(api_response[0], indent=2, sort_keys=True), mimetype='application/json'), api_response[1]
|
2019-10-30 16:12:04 +00:00
|
|
|
|
|
|
|
# ============= ROUTES ==============
|
2019-11-05 08:49:51 +00:00
|
|
|
# add route : /crawlers/show_domain
|
2020-01-13 13:24:35 +00:00
|
|
|
@crawler_splash.route('/crawlers/showDomain', methods=['GET', 'POST'])
|
2019-11-08 08:25:09 +00:00
|
|
|
@login_required
|
2019-11-20 15:15:08 +00:00
|
|
|
@login_read_only
|
2019-10-30 16:12:04 +00:00
|
|
|
def showDomain():
|
2020-01-13 13:24:35 +00:00
|
|
|
if request.method == 'POST':
|
|
|
|
domain_name = request.form.get('in_show_domain')
|
|
|
|
epoch = None
|
|
|
|
port = None
|
|
|
|
else:
|
|
|
|
domain_name = request.args.get('domain')
|
|
|
|
epoch = request.args.get('epoch')
|
|
|
|
port = request.args.get('port')
|
2019-10-30 16:12:04 +00:00
|
|
|
|
2019-10-31 16:14:23 +00:00
|
|
|
res = api_validator(Domain.api_verify_if_domain_exist(domain_name))
|
|
|
|
if res:
|
|
|
|
return res
|
|
|
|
|
|
|
|
domain = Domain.Domain(domain_name, port=port)
|
2019-10-30 16:12:04 +00:00
|
|
|
|
|
|
|
dict_domain = domain.get_domain_metadata()
|
|
|
|
dict_domain['domain'] = domain_name
|
2019-12-16 14:55:50 +00:00
|
|
|
if domain.domain_was_up():
|
2019-10-31 16:14:23 +00:00
|
|
|
dict_domain = {**dict_domain, **domain.get_domain_correlation()}
|
2019-11-19 13:30:12 +00:00
|
|
|
dict_domain['correlation_nb'] = Domain.get_domain_total_nb_correlation(dict_domain)
|
2019-11-08 08:25:09 +00:00
|
|
|
dict_domain['origin_item'] = domain.get_domain_last_origin()
|
2019-10-31 16:14:23 +00:00
|
|
|
dict_domain['tags'] = domain.get_domain_tags()
|
2019-11-19 13:03:23 +00:00
|
|
|
dict_domain['tags_safe'] = Tag.is_tags_safe(dict_domain['tags'])
|
2019-10-31 16:14:23 +00:00
|
|
|
dict_domain['history'] = domain.get_domain_history_with_status()
|
|
|
|
dict_domain['crawler_history'] = domain.get_domain_items_crawled(items_link=True, epoch=epoch, item_screenshot=True, item_tag=True) # # TODO: handle multiple port
|
2019-12-16 14:55:50 +00:00
|
|
|
if dict_domain['crawler_history']['items']:
|
|
|
|
dict_domain['crawler_history']['random_item'] = random.choice(dict_domain['crawler_history']['items'])
|
2019-10-31 16:14:23 +00:00
|
|
|
|
2019-11-05 08:49:51 +00:00
|
|
|
return render_template("showDomain.html", dict_domain=dict_domain, bootstrap_label=bootstrap_label,
|
2020-01-06 16:07:52 +00:00
|
|
|
modal_add_tags=Tag.get_modal_add_tags(dict_domain['domain'], object_type="domain"))
|