diff --git a/bin/lib/Domain.py b/bin/lib/Domain.py index 8c1c8b40..aa1b51cf 100755 --- a/bin/lib/Domain.py +++ b/bin/lib/Domain.py @@ -48,20 +48,29 @@ def get_db_keys_domain_up(domain_type, date_type): # sanitise domain_type def get_list_db_keys_domain_up(domain_type, l_dates, date_type): l_keys_name = [] - key_name = get_db_keys_domain_up(domain_type, date_type) - if key_name: - for str_date in l_dates: - l_keys_name.append(key_name.format(str_date)) + if domain_type=='all': + domains_types = get_all_domains_type() + else: + domains_types = [domain_type] + + for dom_type in domains_types: + key_name = get_db_keys_domain_up(dom_type, date_type) + if key_name: + for str_date in l_dates: + l_keys_name.append(key_name.format(str_date)) return l_keys_name ######## UTIL ######## def sanitize_domain_type(domain_type): - if domain_type in ['onion', 'regular']: + if domain_type in get_all_domains_type(): return domain_type else: return 'regular' ######## DOMAINS ######## +def get_all_domains_type(): + return ['onion', 'regular'] + def get_all_domains_up(domain_type, r_list=True): ''' Get all domain up (at least one time) @@ -116,7 +125,7 @@ def get_domains_up_by_daterange(date_from, date_to, domain_type): ''' Get all domain up (at least one time) by daterange - :param domain_type: date YYYYMMDD + :param domain_type: domain_type :type domain_type: str :return: list of domain @@ -184,14 +193,35 @@ def domains_up_by_page(domain_type, nb_obj=28, page=1): ''' domains = sorted(get_all_domains_up(domain_type, r_list=False)) domains = paginate_iterator(domains, nb_obj=nb_obj, page=page) - - # # TODO: get tags + root_screenshot + metadata - l_domains = [] - for domain in domains['list_elem']: - l_domains.append(get_domain_metadata(domain, domain_type, first_seen=True, last_ckeck=True, status=True, ports=True, tags=True, screenshot=True)) - domains['list_elem'] = l_domains + domains['list_elem'] = create_domains_metadata_list(domains['list_elem'], domain_type) return domains +def get_domains_up_by_filers(domain_type, date_from=None, date_to=None, tags=[], nb_obj=28, page=1): + if not tags: + if not date_from and not date_to: + return domains_up_by_page(domain_type, nb_obj=nb_obj, page=page) + else: + domains = sorted(get_domains_up_by_daterange(date_from, date_to, domain_type)) + domains = paginate_iterator(domains, nb_obj=nb_obj, page=page) + domains['list_elem'] = create_domains_metadata_list(domains['list_elem'], domain_type) + domains['domain_type'] = domain_type + domains['date_from'] = date_from + domains['date_to'] = date_to + return domains + else: + return None + +def create_domains_metadata_list(list_domains, domain_type): + l_domains = [] + for domain in list_domains: + if domain_type=='all': + dom_type = get_domain_type(domain) + else: + dom_type = domain_type + l_domains.append(get_domain_metadata(domain, dom_type, first_seen=True, last_ckeck=True, status=True, + ports=True, tags=True, screenshot=True, tags_safe=True)) + return l_domains + ######## DOMAIN ######## def get_domain_type(domain): @@ -439,7 +469,7 @@ def get_domain_random_screenshot(domain): ''' return Screenshot.get_randon_domain_screenshot(domain) -def get_domain_metadata(domain, domain_type, first_seen=True, last_ckeck=True, status=True, ports=True, tags=False, screenshot=False): +def get_domain_metadata(domain, domain_type, first_seen=True, last_ckeck=True, status=True, ports=True, tags=False, tags_safe=False, screenshot=False): ''' Get Domain basic metadata @@ -471,6 +501,11 @@ def get_domain_metadata(domain, domain_type, first_seen=True, last_ckeck=True, s dict_metadata['ports'] = get_domain_all_ports(domain, domain_type) if tags: dict_metadata['tags'] = get_domain_tags(domain) + if tags_safe: + if tags: + dict_metadata['is_tags_safe'] = Tag.is_tags_safe(dict_metadata['tags']) + else: + dict_metadata['is_tags_safe'] = Tag.is_tags_safe(get_domain_tags(domain)) if screenshot: dict_metadata['screenshot'] = get_domain_random_screenshot(domain) return dict_metadata diff --git a/var/www/blueprints/crawler_splash.py b/var/www/blueprints/crawler_splash.py index 1cedd8e6..ee2e68ba 100644 --- a/var/www/blueprints/crawler_splash.py +++ b/var/www/blueprints/crawler_splash.py @@ -80,28 +80,79 @@ def showDomain(): return render_template("showDomain.html", dict_domain=dict_domain, bootstrap_label=bootstrap_label, modal_add_tags=Tag.get_modal_add_tags(dict_domain['domain'], object_type="domain")) -@crawler_splash.route('/domains/explorer/onion', methods=['GET', 'POST']) +@crawler_splash.route('/domains/explorer/domain_type_post', methods=['POST']) @login_required @login_read_only -def domains_explorer_onion(): +def domains_explorer_post_filter(): + domain_onion = request.form.get('domain_onion_switch') + domain_regular = request.form.get('domain_regular_switch') + date_from = request.form.get('date_from') + date_to = request.form.get('date_to') + + if date_from and date_to: + date_from = date_from.replace('-', '') + date_to = date_to.replace('-', '') + else: + date_from = None + date_to = None + + if domain_onion and domain_regular: + if date_from and date_to: + return redirect(url_for('crawler_splash.domains_explorer_all', date_from=date_from, date_to=date_to)) + else: + return redirect(url_for('crawler_splash.domains_explorer_all')) + elif domain_regular: + if date_from and date_to: + return redirect(url_for('crawler_splash.domains_explorer_web', date_from=date_from, date_to=date_to)) + else: + return redirect(url_for('crawler_splash.domains_explorer_web')) + else: + if date_from and date_to: + return redirect(url_for('crawler_splash.domains_explorer_onion', date_from=date_from, date_to=date_to)) + else: + return redirect(url_for('crawler_splash.domains_explorer_onion')) + +@crawler_splash.route('/domains/explorer/all', methods=['GET']) +@login_required +@login_read_only +def domains_explorer_all(): page = request.args.get('page') + date_from = request.args.get('date_from') + date_to = request.args.get('date_to') try: page = int(page) except: page = 1 - dict_data = Domain.domains_up_by_page('onion', page=page) + dict_data = Domain.get_domains_up_by_filers('all', page=page, date_from=date_from, date_to=date_to) + return render_template("domain_explorer.html", dict_data=dict_data, bootstrap_label=bootstrap_label, domain_type='all') + +@crawler_splash.route('/domains/explorer/onion', methods=['GET']) +@login_required +@login_read_only +def domains_explorer_onion(): + page = request.args.get('page') + date_from = request.args.get('date_from') + date_to = request.args.get('date_to') + try: + page = int(page) + except: + page = 1 + + dict_data = Domain.get_domains_up_by_filers('onion', page=page, date_from=date_from, date_to=date_to) return render_template("domain_explorer.html", dict_data=dict_data, bootstrap_label=bootstrap_label, domain_type='onion') -@crawler_splash.route('/domains/explorer/web', methods=['GET', 'POST']) +@crawler_splash.route('/domains/explorer/web', methods=['GET']) @login_required @login_read_only def domains_explorer_web(): page = request.args.get('page') + date_from = request.args.get('date_from') + date_to = request.args.get('date_to') try: page = int(page) except: page = 1 dict_data = Domain.domains_up_by_page('regular', page=page) - return render_template("domain_explorer.html", dict_data=dict_data, bootstrap_label=bootstrap_label, domain_type='onion') + return render_template("domain_explorer.html", dict_data=dict_data, bootstrap_label=bootstrap_label, domain_type='regular') diff --git a/var/www/templates/crawler/crawler_splash/domain_explorer.html b/var/www/templates/crawler/crawler_splash/domain_explorer.html index e80bdb7f..007da8f0 100644 --- a/var/www/templates/crawler/crawler_splash/domain_explorer.html +++ b/var/www/templates/crawler/crawler_splash/domain_explorer.html @@ -6,10 +6,13 @@ + + + + + +
+ + {% include 'nav_bar.html' %} + +
+
+ First seen: {{dict_domain["first_seen"]}}
+ Last_seen: {{dict_domain["first_seen"]}}
+ Ports: {{dict_domain["ports"]}}
+
+