mirror of https://github.com/CIRCL/lookyloo
new: Show error message in bulk capture
parent
572f85dace
commit
56ed06eb84
|
@ -404,10 +404,6 @@ class Lookyloo():
|
|||
return CaptureStatusCore.ONGOING
|
||||
return lacus_status
|
||||
|
||||
def try_error_status(self, capture_uuid: str, /) -> Optional[str]:
|
||||
'''If it is not possible to do the capture, we store the error for a short amount of time'''
|
||||
return self.redis.get(f'error_{capture_uuid}')
|
||||
|
||||
def capture_cache(self, capture_uuid: str, /) -> Optional[CaptureCache]:
|
||||
"""Get the cache from redis, rebuild the tree if the internal UUID changed => slow"""
|
||||
try:
|
||||
|
|
|
@ -50,7 +50,7 @@ python-versions = "*"
|
|||
|
||||
[[package]]
|
||||
name = "asttokens"
|
||||
version = "2.1.0"
|
||||
version = "2.2.0"
|
||||
description = "Annotate AST trees with source code positions"
|
||||
category = "dev"
|
||||
optional = false
|
||||
|
@ -60,7 +60,7 @@ python-versions = "*"
|
|||
six = "*"
|
||||
|
||||
[package.extras]
|
||||
test = ["astroid (<=2.5.3)", "pytest"]
|
||||
test = ["astroid", "pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "async-timeout"
|
||||
|
@ -1208,8 +1208,8 @@ python-versions = ">=3.7"
|
|||
|
||||
[[package]]
|
||||
name = "traitlets"
|
||||
version = "5.5.0"
|
||||
description = ""
|
||||
version = "5.6.0"
|
||||
description = "Traitlets Python configuration system"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
@ -1540,8 +1540,8 @@ appnope = [
|
|||
{file = "appnope-0.1.3.tar.gz", hash = "sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24"},
|
||||
]
|
||||
asttokens = [
|
||||
{file = "asttokens-2.1.0-py2.py3-none-any.whl", hash = "sha256:1b28ed85e254b724439afc783d4bee767f780b936c3fe8b3275332f42cf5f561"},
|
||||
{file = "asttokens-2.1.0.tar.gz", hash = "sha256:4aa76401a151c8cc572d906aad7aea2a841780834a19d780f4321c0fe1b54635"},
|
||||
{file = "asttokens-2.2.0-py2.py3-none-any.whl", hash = "sha256:c56caef774a929923696f09ceea0eadcb95c94b30e8ee4f9fc4f5867096caaeb"},
|
||||
{file = "asttokens-2.2.0.tar.gz", hash = "sha256:e27b1f115daebfafd4d1826fc75f9a72f0b74bd3ae4ee4d9380406d74d35e52c"},
|
||||
]
|
||||
async-timeout = [
|
||||
{file = "async-timeout-4.0.2.tar.gz", hash = "sha256:2163e1640ddb52b7a8c80d0a67a08587e5d245cc9c553a74a847056bc2976b15"},
|
||||
|
@ -2571,8 +2571,8 @@ tomli = [
|
|||
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
|
||||
]
|
||||
traitlets = [
|
||||
{file = "traitlets-5.5.0-py3-none-any.whl", hash = "sha256:1201b2c9f76097195989cdf7f65db9897593b0dfd69e4ac96016661bb6f0d30f"},
|
||||
{file = "traitlets-5.5.0.tar.gz", hash = "sha256:b122f9ff2f2f6c1709dab289a05555be011c87828e911c0cf4074b85cb780a79"},
|
||||
{file = "traitlets-5.6.0-py3-none-any.whl", hash = "sha256:1410755385d778aed847d68deb99b3ba30fbbf489e17a1e8cbb753060d5cce73"},
|
||||
{file = "traitlets-5.6.0.tar.gz", hash = "sha256:10b6ed1c9cedee83e795db70a8b9c2db157bb3778ec4587a349ecb7ef3b1033b"},
|
||||
]
|
||||
types-beautifulsoup4 = [
|
||||
{file = "types-beautifulsoup4-4.11.6.1.tar.gz", hash = "sha256:d46be8f409ddccb6daaa9d118484185e70bcf552085c39c6d05b157cd1462e04"},
|
||||
|
|
|
@ -639,11 +639,7 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None):
|
|||
if not cache:
|
||||
status = lookyloo.get_capture_status(tree_uuid)
|
||||
if status == CaptureStatus.UNKNOWN:
|
||||
error = lookyloo.try_error_status(tree_uuid)
|
||||
if error:
|
||||
flash(error, 'warning')
|
||||
else:
|
||||
flash(f'Unable to find this UUID ({tree_uuid}).', 'warning')
|
||||
flash(f'Unable to find this UUID ({tree_uuid}).', 'warning')
|
||||
return index_generic()
|
||||
elif status == CaptureStatus.QUEUED:
|
||||
message = "The capture is queued, but didn't start yet."
|
||||
|
|
|
@ -10,6 +10,8 @@ from flask import request, send_file
|
|||
from flask_restx import Namespace, Resource, abort, fields # type: ignore
|
||||
from werkzeug.security import check_password_hash
|
||||
|
||||
from lacuscore import CaptureStatus as CaptureStatusCore
|
||||
from pylacus import CaptureStatus as CaptureStatusPy
|
||||
from lookyloo.lookyloo import Lookyloo
|
||||
|
||||
from .helpers import build_users_table, load_user_from_request, src_request_ip
|
||||
|
@ -61,8 +63,17 @@ class AuthToken(Resource):
|
|||
@api.doc(description='Get the status of a capture',
|
||||
params={'capture_uuid': 'The UUID of the capture'})
|
||||
class CaptureStatusQuery(Resource):
|
||||
|
||||
@api.param('with_error', 'Add the error message of the capture (if there is one)')
|
||||
def get(self, capture_uuid: str):
|
||||
return {'status_code': lookyloo.get_capture_status(capture_uuid)}
|
||||
with_error: bool = True if request.args.get('with_error') else False
|
||||
status_code = lookyloo.get_capture_status(capture_uuid)
|
||||
to_return: Dict[str, Any] = {'status_code': status_code}
|
||||
if status_code in [CaptureStatusCore.DONE, CaptureStatusPy.DONE] and with_error:
|
||||
cache = lookyloo.capture_cache(capture_uuid)
|
||||
if cache and cache.error:
|
||||
to_return['error'] = cache.error
|
||||
return to_return
|
||||
|
||||
|
||||
@api.route('/json/<string:capture_uuid>/hostnames')
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
<script>
|
||||
async function update_status() {
|
||||
let capture_status = document.getElementsByClassName('capture_status');
|
||||
let capture_error = document.getElementsByClassName('capture_error');
|
||||
let keep_going = false;
|
||||
for (let i = 0; i < capture_status.length; i++) {
|
||||
await fetch(`/json/${capture_status[i].id}/status`)
|
||||
await fetch(`/json/${capture_status[i].id}/status?with_error=1`)
|
||||
.then(response => response.json())
|
||||
.then(cs => {
|
||||
if ((cs.status_code == 0) || (cs.status_code == 2)) {
|
||||
|
@ -27,6 +28,9 @@
|
|||
}
|
||||
else if (cs.status_code == 1){
|
||||
capture_status[i].innerHTML = "Capture done.";
|
||||
if ('error' in cs ){
|
||||
capture_error[i].innerHTML = cs.error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
capture_status[i].innerHTML = "Unknown capture.";
|
||||
|
@ -59,6 +63,7 @@
|
|||
<th>URL</th>
|
||||
<th>Link</th>
|
||||
<th>Status</th>
|
||||
<th>Error message</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -69,6 +74,7 @@
|
|||
</td>
|
||||
<td><a href="{{ url_for('tree', tree_uuid=uuid) }}">Show capture</a></td>
|
||||
<td id="{{uuid}}" class="capture_status">Please wait...</td>
|
||||
<td id="{{uuid}}" class="capture_error"></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue