Skip to content

Commit

Permalink
chg: [tags] search ocrs and images by tags + fix ocr, filter invalid …
Browse files Browse the repository at this point in the history
…image
  • Loading branch information
Terrtia committed Apr 26, 2024
1 parent 2b23d99 commit 31b519c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bin/modules/OcrExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def compute(self, message):
languages = get_model_languages(image)
languages = Ocrs.sanityze_ocr_languages(languages, ocr_languages=self.ocr_languages)
print(image.id, languages)
texts = Ocrs.extract_text(path, languages)
try:
texts = Ocrs.extract_text(path, languages)
except ValueError as e:
self.logger.warning(e)
self.obj.add_tag('infoleak:confirmed="false-positive"')
texts = None
if texts:
print('create')
ocr = Ocrs.create(image.id, texts)
Expand Down
18 changes: 18 additions & 0 deletions var/www/blueprints/tags_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ def tags_search_messages():
dict_tagged['date'] = Date.sanitise_date_range('', '', separator='-')
return render_template("tags/search_obj_by_tags.html", bootstrap_label=bootstrap_label, dict_tagged=dict_tagged)

@tags_ui.route('/tag/search/image')
@login_required
@login_read_only
def tags_search_images():
object_type = 'image'
dict_tagged = {"object_type": object_type, "object_name": object_type.title() + "s"}
dict_tagged['date'] = Date.sanitise_date_range('', '', separator='-')
return render_template("tags/search_obj_by_tags.html", bootstrap_label=bootstrap_label, dict_tagged=dict_tagged)

@tags_ui.route('/tag/search/ocr')
@login_required
@login_read_only
def tags_search_ocrs():
object_type = 'ocr'
dict_tagged = {"object_type": object_type, "object_name": object_type.title() + "s"}
dict_tagged['date'] = Date.sanitise_date_range('', '', separator='-')
return render_template("tags/search_obj_by_tags.html", bootstrap_label=bootstrap_label, dict_tagged=dict_tagged)

@tags_ui.route('/tag/search/domain')
@login_required
@login_read_only
Expand Down
12 changes: 12 additions & 0 deletions var/www/templates/tags/menu_sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ <h5 class="d-flex text-muted w-100" id="nav_tags_search">
Search Messages by Tags
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('tags_ui.tags_search_images') }}" id="nav_tags_search_image">
<i class="fas fa-image"></i>
Search Images by Tags
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('tags_ui.tags_search_ocrs') }}" id="nav_tags_search_message">
<i class="fas fa-expand"></i>
Search Ocrs by Tags
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('tags_ui.tags_search_domains') }}" id="nav_tags_search_domain">
<i class="fab fa-html5"></i>
Expand Down
22 changes: 21 additions & 1 deletion var/www/templates/tags/search_obj_by_tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,27 @@
</div>
</td>
</tr>
{% endfor %}
{% endfor %}
{%elif dict_tagged["object_type"]=="screenshot"%}

{%elif dict_tagged["object_type"]=="image" or dict_tagged["object_type"]=="ocr"%}
{% for dict_obj in dict_tagged["tagged_obj"] %}
<tr>
<td class="pb-0">
<a target="_blank" href="{{ url_for('correlation.show_correlation') }}?type={{dict_tagged['object_type']}}&id={{dict_obj['id']}}" class="text-secondary">
<div style="line-height:0.9;">{{ dict_obj['id'] }}</div>
</a>
<div class="mb-2">
{% for tag in dict_obj['tags'] %}
<a href="{{ url_for('tags_ui.get_obj_by_tags') }}?object_type={{dict_tagged['object_type']}}&ltags={{ tag }}">
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
</a>
{% endfor %}
</div>
</td>
</tr>
{% endfor %}

{%elif dict_tagged["object_type"]=="message"%}
{% for dict_obj in dict_tagged["tagged_obj"] %}
<tr>
Expand Down

0 comments on commit 31b519c

Please sign in to comment.