View list of evidences
This commit is contained in:
parent
46a0bb392d
commit
f3117e2f00
|
@ -7,6 +7,25 @@ from evidence.xapian import search
|
||||||
from user.models import User
|
from user.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class Annotation(models.Model):
|
||||||
|
class Type(models.IntegerChoices):
|
||||||
|
SYSTEM= 0, "System"
|
||||||
|
USER = 1, "User"
|
||||||
|
DOCUMENT = 2, "Document"
|
||||||
|
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
uuid = models.UUIDField()
|
||||||
|
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
type = models.SmallIntegerField(choices=Type)
|
||||||
|
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||||
|
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Evidence:
|
class Evidence:
|
||||||
def __init__(self, uuid):
|
def __init__(self, uuid):
|
||||||
self.uuid = uuid
|
self.uuid = uuid
|
||||||
|
@ -51,21 +70,9 @@ class Evidence:
|
||||||
def components(self):
|
def components(self):
|
||||||
return self.doc.get('components', [])
|
return self.doc.get('components', [])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
class Annotation(models.Model):
|
def get_all(cls, user):
|
||||||
class Type(models.IntegerChoices):
|
return Annotation.objects.filter(
|
||||||
SYSTEM= 0, "System"
|
owner=user,
|
||||||
USER = 1, "User"
|
type=Annotation.Type.SYSTEM,
|
||||||
DOCUMENT = 2, "Document"
|
).order_by("-created").values_list("uuid", flat=True).distinct()
|
||||||
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
uuid = models.UUIDField()
|
|
||||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
||||||
type = models.SmallIntegerField(choices=Type)
|
|
||||||
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
|
||||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
constraints = [
|
|
||||||
models.UniqueConstraint(fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
|
||||||
]
|
|
||||||
|
|
|
@ -10,11 +10,15 @@ from utils.constants import ALGOS
|
||||||
|
|
||||||
|
|
||||||
class Build:
|
class Build:
|
||||||
def __init__(self, evidence_json, user):
|
def __init__(self, evidence_json, user, check=False):
|
||||||
self.json = evidence_json
|
self.json = evidence_json
|
||||||
self.uuid = self.json['uuid']
|
self.uuid = self.json['uuid']
|
||||||
self.user = user
|
self.user = user
|
||||||
self.hid = None
|
self.hid = None
|
||||||
|
self.generate_chids()
|
||||||
|
|
||||||
|
if check:
|
||||||
|
return
|
||||||
|
|
||||||
self.index()
|
self.index()
|
||||||
self.create_annotations()
|
self.create_annotations()
|
||||||
|
@ -23,6 +27,11 @@ class Build:
|
||||||
snap = json.dumps(self.json)
|
snap = json.dumps(self.json)
|
||||||
index(self.uuid, snap)
|
index(self.uuid, snap)
|
||||||
|
|
||||||
|
def generate_chids(self):
|
||||||
|
self.algorithms = {
|
||||||
|
'hidalgo1': self.get_hid_14(),
|
||||||
|
}
|
||||||
|
|
||||||
def get_hid_14(self):
|
def get_hid_14(self):
|
||||||
device = self.json['device']
|
device = self.json['device']
|
||||||
manufacturer = device.get("manufacturer", '')
|
manufacturer = device.get("manufacturer", '')
|
||||||
|
@ -34,22 +43,8 @@ class Build:
|
||||||
return hashlib.sha3_256(hid.encode()).hexdigest()
|
return hashlib.sha3_256(hid.encode()).hexdigest()
|
||||||
|
|
||||||
def create_annotations(self):
|
def create_annotations(self):
|
||||||
algorithms = {
|
|
||||||
'hidalgo1': self.get_hid_14(),
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO is neccesary?
|
|
||||||
annotation = Annotation.objects.filter(
|
|
||||||
owner=self.user,
|
|
||||||
type=Annotation.Type.SYSTEM,
|
|
||||||
key='hidalgo1',
|
|
||||||
value = algorithms['hidalgo1']
|
|
||||||
).first()
|
|
||||||
|
|
||||||
for k, v in algorithms.items():
|
|
||||||
if annotation and k == annotation.key:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
for k, v in self.algorithms.items():
|
||||||
Annotation.objects.create(
|
Annotation.objects.create(
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
owner=self.user,
|
owner=self.user,
|
||||||
|
@ -57,4 +52,3 @@ class Build:
|
||||||
key=k,
|
key=k,
|
||||||
value=v
|
value=v
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,33 +8,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dataTable-container">
|
|
||||||
<form method="post">
|
<div class="row">
|
||||||
{% csrf_token %}
|
<table class="table table-striped table-sm">
|
||||||
<table class="table">
|
{% for ev in evidences %}
|
||||||
<thead>
|
<tr>
|
||||||
<tr>
|
<td>
|
||||||
<th scope="col" data-sortable="">
|
<a href="{# url 'evidence:details' ev #}">{{ ev }}</a>
|
||||||
<a class="dataTable-sorter" href="#">Title</a>
|
</td>
|
||||||
</th>
|
<td>
|
||||||
</tr>
|
<a href="{# url 'evidence:delete' ev #}"><i class="bi bi-trash text-danger"></i></a>
|
||||||
</thead>
|
</td>
|
||||||
{% for snap in evicendes %}
|
</tr>
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<input type="checkbox" name="evidences" value="{{ snap.id }}" />
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="{# url 'evidence:details' snap.pk #}">{{ snap.uuid }} {{ snap.sid }} {{ snap.version }}</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="{% url 'device:details' snap.computer.device.pk %}">{{ snap.computer.device.manufacturer }} {{ snap.computer.device.model }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,13 +2,11 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.views.generic.edit import (
|
from django.views.generic.edit import (
|
||||||
CreateView,
|
|
||||||
UpdateView,
|
|
||||||
FormView,
|
FormView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from dashboard.mixins import DashboardView
|
from dashboard.mixins import DashboardView
|
||||||
from evidence.models import Evidence, Annotation
|
from evidence.models import Evidence
|
||||||
from evidence.forms import UploadForm
|
from evidence.forms import UploadForm
|
||||||
# from django.shortcuts import render
|
# from django.shortcuts import render
|
||||||
# from rest_framework import viewsets
|
# from rest_framework import viewsets
|
||||||
|
@ -28,8 +26,8 @@ class ListEvidencesView(DashboardView, TemplateView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
# evidences = Evidence.objects.filter(owner=self.request.user)
|
evidences = Evidence.get_all(self.request.user)
|
||||||
evidences = []
|
|
||||||
context.update({
|
context.update({
|
||||||
'evidences': evidences,
|
'evidences': evidences,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue