Skip to content

Commit 2a45cfd

Browse files
committed
chg: [retro hunt + update] add ocr retro hunt + new update
1 parent 7e27089 commit 2a45cfd

File tree

6 files changed

+142
-1
lines changed

6 files changed

+142
-1
lines changed

bin/lib/ail_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_objects_tracked():
9393
return ['barcode', 'decoded', 'item', 'pgp', 'message', 'ocr', 'qrcode', 'title']
9494

9595
def get_objects_retro_hunted():
96-
return ['decoded', 'item', 'message']
96+
return ['decoded', 'item', 'message', 'ocr']
9797

9898
def get_all_objects_with_subtypes_tuple():
9999
str_objs = []

bin/lib/chats_viewer.py

+20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lib.objects import Messages
2626
from lib.objects.BarCodes import Barcode
2727
from lib.objects.QrCodes import Qrcode
28+
from lib.objects.Ocrs import Ocr
2829
from lib.objects import UsersAccount
2930
from lib.objects import Usernames
3031
from lib import Language
@@ -421,6 +422,25 @@ def get_nb_messages_iterator(filters={}):
421422
nb_messages += chat.get_nb_messages()
422423
return nb_messages
423424

425+
426+
def get_ocrs_iterator(filters={}):
427+
for instance_uuid in get_chat_service_instances():
428+
for chat_id in ChatServiceInstance(instance_uuid).get_chats():
429+
chat = Chats.Chat(chat_id, instance_uuid)
430+
print(chat.get_correlation('ocr'))
431+
for ocr in chat.get_correlation('ocr').get('ocr', []):
432+
_, ocr_id = ocr.split(':', 1)
433+
yield Ocr(ocr_id)
434+
435+
def get_nb_ors_iterator(filters={}):
436+
nb = 0
437+
for instance_uuid in get_chat_service_instances():
438+
for chat_id in ChatServiceInstance(instance_uuid).get_chats():
439+
chat = Chats.Chat(chat_id, instance_uuid)
440+
nb += chat.get_nb_correlation('ocr')
441+
return nb
442+
443+
424444
def get_chat_object_messages_meta(c_messages):
425445
temp_chats = {}
426446
for date in c_messages:

bin/lib/objects/ail_objects.py

+4
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ def obj_iterator(obj_type, filters):
371371
return Pgps.get_all_pgps_objects(filters=filters)
372372
elif obj_type == 'message':
373373
return chats_viewer.get_messages_iterator(filters=filters)
374+
elif obj_type == 'ocr':
375+
return chats_viewer.get_ocrs_iterator(filters=filters)
374376
elif obj_type == 'title':
375377
return Titles.Titles().get_iterator()
376378

@@ -390,6 +392,8 @@ def card_obj_iterator(obj_type, filters):
390392
return Pgps.nb_all_pgps_objects(filters=filters)
391393
elif obj_type == 'message':
392394
return chats_viewer.get_nb_messages_iterator(filters=filters)
395+
elif obj_type == 'ocr':
396+
return chats_viewer.get_nb_ors_iterator(filters=filters)
393397

394398
def get_ui_obj_tag_table_keys(obj_type): # TODO REMOVE ME
395399
"""

update/v6.0.1/Update.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
# -*-coding:UTF-8 -*
3+
4+
import os
5+
import sys
6+
7+
sys.path.append(os.environ['AIL_HOME'])
8+
##################################
9+
# Import Project packages
10+
##################################
11+
from update.bin.ail_updater import AIL_Updater
12+
from lib import ail_users
13+
from lib import crawlers
14+
from lib import Investigations
15+
from lib import Tracker
16+
17+
def _fix_user_lowercase():
18+
r_tracking = Investigations.r_tracking
19+
r_tracker = Tracker.r_tracker
20+
r_crawler = crawlers.r_crawler
21+
22+
for user_id in ail_users.get_users():
23+
l_user_id = user_id.lower()
24+
if user_id != l_user_id:
25+
print(f'Updating {user_id} ...')
26+
ail_users.kill_session_user(user_id)
27+
28+
# Investigations
29+
for investigation_uuid in Investigations.get_user_all_investigations(user_id):
30+
r_tracking.srem(f'investigations:user:{user_id}', investigation_uuid)
31+
r_tracking.sadd(f'investigations:user:{l_user_id}', investigation_uuid)
32+
r_tracking.hset(f'investigations:data:{investigation_uuid}', 'creator_user', l_user_id)
33+
34+
# Trackers
35+
for tracker_uuid in Tracker.get_user_trackers(user_id):
36+
tracker = Tracker.Tracker(tracker_uuid)
37+
tracker_type = tracker.get_type()
38+
39+
r_tracker.rename(f'user:tracker:{user_id}:{tracker_type}', f'user:tracker:{l_user_id}:{tracker_type}')
40+
r_tracker.rename(f'user:tracker:{user_id}', f'user:tracker:{l_user_id}')
41+
42+
# creator
43+
r_tracker.hset(f'tracker:{tracker_uuid}', 'user_id', l_user_id)
44+
45+
try:
46+
r_tracker.rename(f'trackers:user:{user_id}', f'trackers:user:{l_user_id}')
47+
except Exception:
48+
pass
49+
50+
# Cookiejar
51+
for cookiejar_uuid in crawlers.get_cookiejars_user(user_id):
52+
cookiejar = crawlers.Cookiejar(cookiejar_uuid)
53+
# creator
54+
cookiejar._set_user(l_user_id)
55+
56+
try:
57+
r_crawler.rename(f'cookiejars:user:{user_id}', f'cookiejars:user:{l_user_id}')
58+
except Exception:
59+
pass
60+
61+
# ail_user
62+
ail_users._fix_user_lowercase(user_id)
63+
64+
65+
class Updater(AIL_Updater):
66+
"""default Updater."""
67+
68+
def __init__(self, version):
69+
super(Updater, self).__init__(version)
70+
71+
72+
if __name__ == '__main__':
73+
_fix_user_lowercase()
74+
# updater = Updater('v6.0.1')
75+
# updater.run_update()

update/v6.0.1/Update.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
[ -z "$AIL_HOME" ] && echo "Needs the env var AIL_HOME. Run the script from the virtual environment." && exit 1;
4+
[ -z "$AIL_REDIS" ] && echo "Needs the env var AIL_REDIS. Run the script from the virtual environment." && exit 1;
5+
[ -z "$AIL_BIN" ] && echo "Needs the env var AIL_ARDB. Run the script from the virtual environment." && exit 1;
6+
[ -z "$AIL_FLASK" ] && echo "Needs the env var AIL_FLASK. Run the script from the virtual environment." && exit 1;
7+
8+
export PATH=$AIL_HOME:$PATH
9+
export PATH=$AIL_REDIS:$PATH
10+
export PATH=$AIL_BIN:$PATH
11+
export PATH=$AIL_FLASK:$PATH
12+
13+
GREEN="\\033[1;32m"
14+
DEFAULT="\\033[0;39m"
15+
16+
echo -e $GREEN"Shutting down AIL ..."$DEFAULT
17+
bash ${AIL_BIN}/LAUNCH.sh -ks
18+
wait
19+
20+
echo -e $GREEN"Updating UI resources..."$DEFAULT
21+
bash ${AIL_BIN}/LAUNCH.sh -ut
22+
wait
23+
24+
echo -e $GREEN"Updating python requirement..."$DEFAULT
25+
pip install -U flask-sock
26+
27+
# SUBMODULES #
28+
git submodule update
29+
30+
echo ""
31+
echo -e $GREEN"Updating AIL VERSION ..."$DEFAULT
32+
echo ""
33+
python ${AIL_HOME}/update/v6.0/Update.py
34+
wait
35+
echo ""
36+
echo ""
37+
38+
exit 0

var/www/templates/hunter/add_retro_hunt_task.html

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ <h5 class="card-title">Create a new Retro Hunt task</h5>
8282
<input class="custom-control-input" type="checkbox" name="message_obj" id="message_obj" checked="">
8383
<label class="custom-control-label" for="message_obj"><i class="fas fa-comment-dots"></i>&nbsp;Messages</label>
8484
</div>
85+
<div class="custom-control custom-switch mt-1">
86+
<input class="custom-control-input" type="checkbox" name="ocr_obj" id="ocr_obj" checked="">
87+
<label class="custom-control-label" for="ocr_obj"><i class="fas fa-expand"></i>&nbsp;Ocrs</label>
88+
</div>
8589
{# <div class="custom-control custom-switch mt-1">#}
8690
{# <input class="custom-control-input" type="checkbox" name="domain_obj" id="domain_obj" checked="">#}
8791
{# <label class="custom-control-label" for="domain_obj"><i class="fas fa-spider"></i>&nbsp;Domain</label>#}

0 commit comments

Comments
 (0)