Skip to content

Commit

Permalink
chg: Normalize more HTML blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jan 20, 2025
1 parent 67ffb4f commit 0009bbe
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
91 changes: 45 additions & 46 deletions website/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2017,20 +2017,44 @@ def add_context(tree_uuid: str, node_uuid: str) -> WerkzeugResponse | None:


def __prepare_node_view(capture_uuid: str, nodes: list[tuple[str, str]], from_popup: bool=False) -> str:
to_return = f'The capture contains this value in {len(nodes)} nodes, click below to see them on the tree:'
to_return += '<ul>'
to_return = f'The capture contains this value in <b>{len(nodes)}</b> nodes.'
to_return += f"""<br>
<p class="d-inline-flex gap-1">
<button class="btn btn-link" type="button"
data-bs-toggle="collapse" data-bs-target="#collapseAllNodes_{capture_uuid}"
aria-expanded="false" aria-controls="collapseAllNodes_{capture_uuid}">
Show
</button>
</p>
<div class="collapse" id="collapseAllNodes_{capture_uuid}">
<div class="card card-body">
Click on the link to go directly on the node in the tree.
<span class="d-inline-block text-break">
"""
to_return += '<ul class="list-group list-group-flush">'
for url, node in nodes:
url_span = f'<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(url, 100, with_title=True)}</span>'
to_return += '<li>'
url_span = f'<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(url, 50, with_title=True)}</span>'
to_return += '<li class="list-group-item">'
if from_popup:
to_return += f"""<a href="#" class="openNewTab" data-capture="{capture_uuid}" data-hostnode="{node}">{url_span}</a>"""
else:
to_return += f'<a href="{url_for("tree", tree_uuid=capture_uuid, node_uuid=node)}">{url_span}</a>'
to_return += '</li>'
to_return += '</ul>'
to_return += '</ul></span></div></div>'
return to_return


def __prepare_title_in_modal(capture_uuid: str, title: str, from_popup: bool=False) -> str:
span_title = f'<span class="d-inline-block text-break">{title}</span>'
if from_popup:
return f'<a href="#" class="openNewTab" data-capture="{capture_uuid}">{span_title}</a>'
return f'<a href="{url_for("tree", tree_uuid=capture_uuid)}">{span_title}</a>'


def __prepare_landings_in_modal(landing_page: str) -> str:
return f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""


@app.route('/tables/<string:table_name>/<string:value>', methods=['POST'])
def post_table(table_name: str, value: str) -> Response:
from_popup = True if (request.args.get('from_popup') and request.args.get('from_popup') == 'True') else False
Expand Down Expand Up @@ -2087,16 +2111,11 @@ def post_table(table_name: str, value: str) -> Response:
captures = captures[start:start + length]
prepared_captures = []
for capture_uuid, title, landing_page, capture_time, nodes in captures:
_nodes = __prepare_node_view(capture_uuid, nodes, from_popup)
to_append = {
'capture_time': capture_time.isoformat(),
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': f'{__prepare_title_in_modal(capture_uuid, title, from_popup)}</br>{__prepare_node_view(capture_uuid, nodes, from_popup)}',
'landing_page': __prepare_landings_in_modal(landing_page)
}
if from_popup:
to_append['capture_title'] = f""" <a href="#" class="openNewTab" data-capture="{capture_uuid}"">{title}</a>"""
else:
to_append['capture_title'] = f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>"""
to_append['capture_title'] += f'</br>{_nodes}'
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})

Expand All @@ -2108,16 +2127,11 @@ def post_table(table_name: str, value: str) -> Response:
captures = captures[start:start + length]
prepared_captures = []
for capture_uuid, title, landing_page, capture_time, nodes in captures:
_nodes = __prepare_node_view(capture_uuid, nodes, from_popup)
to_append = {
'capture_time': capture_time.isoformat(),
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': f'{__prepare_title_in_modal(capture_uuid, title, from_popup)}</br>{__prepare_node_view(capture_uuid, nodes, from_popup)}',
'landing_page': __prepare_landings_in_modal(landing_page)
}
if from_popup:
to_append['capture_title'] = f"""<a href="#" class="openNewTab" data-capture="{capture_uuid}">{title}</a>"""
else:
to_append['capture_title'] = f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>"""
to_append['capture_title'] += f'</br>{_nodes}'
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})

Expand All @@ -2129,16 +2143,11 @@ def post_table(table_name: str, value: str) -> Response:
captures = captures[start:start + length]
prepared_captures = []
for capture_uuid, title, landing_page, capture_time, nodes in captures:
_nodes = __prepare_node_view(capture_uuid, nodes, from_popup)
to_append = {
'capture_time': capture_time.isoformat(),
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': f'{__prepare_title_in_modal(capture_uuid, title, from_popup)}</br>{__prepare_node_view(capture_uuid, nodes, from_popup)}',
'landing_page': __prepare_landings_in_modal(landing_page)
}
if from_popup:
to_append['capture_title'] = f""" <a href="#" class="openNewTab" data-capture="{capture_uuid}">{title}</a>"""
else:
to_append['capture_title'] = f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>"""
to_append['capture_title'] += f'</br>{_nodes}'
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})

Expand All @@ -2152,8 +2161,8 @@ def post_table(table_name: str, value: str) -> Response:
for capture_uuid, title, landing_page, capture_time in captures:
to_append = {
'capture_time': capture_time.isoformat(),
'capture_title': f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>""",
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': __prepare_title_in_modal(capture_uuid, title, from_popup),
'landing_page': __prepare_landings_in_modal(landing_page)
}
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})
Expand All @@ -2168,8 +2177,8 @@ def post_table(table_name: str, value: str) -> Response:
for capture_uuid, title, landing_page, capture_time in captures:
to_append = {
'capture_time': capture_time.isoformat(),
'capture_title': f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>""",
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': __prepare_title_in_modal(capture_uuid, title, from_popup),
'landing_page': __prepare_landings_in_modal(landing_page)
}
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})
Expand All @@ -2183,8 +2192,8 @@ def post_table(table_name: str, value: str) -> Response:
for capture_uuid, title, landing_page, capture_time in captures:
to_append = {
'capture_time': capture_time.isoformat(),
'capture_title': f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>""",
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': __prepare_title_in_modal(capture_uuid, title, from_popup),
'landing_page': __prepare_landings_in_modal(landing_page)
}
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})
Expand All @@ -2196,16 +2205,11 @@ def post_table(table_name: str, value: str) -> Response:
captures = captures[start:start + length]
prepared_captures = []
for capture_uuid, title, landing_page, capture_time, nodes in captures:
_nodes = __prepare_node_view(capture_uuid, nodes, from_popup)
to_append = {
'capture_time': capture_time.isoformat(),
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': f'{__prepare_title_in_modal(capture_uuid, title, from_popup)}</br>{__prepare_node_view(capture_uuid, nodes, from_popup)}',
'landing_page': __prepare_landings_in_modal(landing_page)
}
if from_popup:
to_append['capture_title'] = f"""<a href="#" class="openNewTab" data-capture="{capture_uuid}">{title}</a>"""
else:
to_append['capture_title'] = f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>"""
to_append['capture_title'] += f'</br>{_nodes}'
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})

Expand All @@ -2217,16 +2221,11 @@ def post_table(table_name: str, value: str) -> Response:
captures = captures[start:start + length]
prepared_captures = []
for capture_uuid, title, landing_page, capture_time, nodes in captures:
_nodes = __prepare_node_view(capture_uuid, nodes, from_popup)
to_append = {
'capture_time': capture_time.isoformat(),
'landing_page': f"""<span class="d-inline-block text-break" style="max-width: 400px;">{shorten_string(landing_page, 100, with_title=True)}</span>"""
'capture_title': f'{__prepare_title_in_modal(capture_uuid, title, from_popup)}</br>{__prepare_node_view(capture_uuid, nodes, from_popup)}',
'landing_page': __prepare_landings_in_modal(landing_page)
}
if from_popup:
to_append['capture_title'] = f"""<a href="#" class="openNewTab" data-capture="{capture_uuid}">{title}</a>"""
else:
to_append['capture_title'] = f"""<a href="{url_for('tree', tree_uuid=capture_uuid)}">{title}</a>"""
to_append['capture_title'] += f'</br>{_nodes}'
prepared_captures.append(to_append)
return jsonify({'draw': draw, 'recordsTotal': total, 'recordsFiltered': total if not search else total_filtered, 'data': prepared_captures})
return jsonify({})
Expand Down
8 changes: 5 additions & 3 deletions website/web/templates/tree_hostnames.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
</span>
</td>
<td>
There are <b>{{ info['nodes'] | length }}</b> URLs in this hostname in the current tree.
<br>
<p class="d-inline-flex gap-1">
<button class="btn btn-primary" type="button"
<button class="btn btn-link" type="button"
data-bs-toggle="collapse" data-bs-target="#collapseAllNodes_{{loop.index}}"
aria-expanded="false" aria-controls="collapseAllNodes_{{loop.index}}">
Show
Expand All @@ -29,9 +31,9 @@
<div class="collapse" id="collapseAllNodes_{{loop.index}}">
<div class="card card-body">
<span class="d-inline-block text-break">
<ul>
<ul class="list-group list-group-flush">
{% for node in info['nodes'] %}
<li>
<li class="list-group-item">
<p class="text-break">{{ node.name }}</p>
<button type="button" class="btn btn-link openNewTab" data-capture="{{tree_uuid}}" data-hostnode="{{node.uuid}}">Show on tree</button>
</li>
Expand Down

0 comments on commit 0009bbe

Please sign in to comment.