Skip to content

Commit

Permalink
chg: [api] add domain lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Oct 3, 2024
1 parent f93d82e commit 483d49f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions bin/lib/crawlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from lib import ail_orgs
from lib.ConfigLoader import ConfigLoader
from lib.objects.Domains import Domain
from lib.objects.Titles import Title
from lib.objects import HHHashs
from lib.objects.Items import Item

Expand All @@ -55,6 +56,34 @@

faup = Faup()

# # # # # # # #
# #
# DOMAINS #
# #
# # # # # # # #

# is safe ???
# TODO FILTER URL ???

def api_get_domain_lookup_meta(domain):
dom = Domain(domain)
if not dom.exists():
return {'error': 'domain not found', 'domain': domain}, 404
meta = dom.get_meta(options={'languages'})
meta['first_seen'] = meta['first_seen'].replace('/', '-')
meta['last_seen'] = meta['last_check'].replace('/', '-')
meta['languages'] = list(meta['languages'])
del meta['domain']
del meta['last_check']
del meta['type']
del meta['status']
meta['titles'] = []
for h in dom.get_correlation('title').get('title', []):
t = Title(h[1:])
meta['titles'].append(t.get_content())
return meta


# # # # # # # #
# #
# COMMON #
Expand Down
2 changes: 1 addition & 1 deletion bin/lib/objects/Domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_meta_keys(self):

# options: set of optional meta fields
def get_meta(self, options=set()):
meta = {'type': self.domain_type,
meta = {'type': self.domain_type, # TODO RENAME ME -> Fix template
'id': self.id,
'domain': self.id, # TODO Remove me -> Fix templates
'first_seen': self.get_first_seen(),
Expand Down
9 changes: 9 additions & 0 deletions var/www/blueprints/api_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ def objects_chat_thread_messages():
r = chats_viewer.api_thread_messages(obj_subtype, obj_id)
return create_json_response(r[0], r[1])

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # DOMAINS # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

@api_rest.route("api/v1/domain/lookup/<domain>", methods=['GET'])
@token_required('user')
def api_domain_lookup(domain):
return create_json_response(crawlers.api_get_domain_lookup_meta(domain), 200)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # TITLES # # # # # # # # # # # # # # # # # # # TODO TO REVIEW
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down

0 comments on commit 483d49f

Please sign in to comment.