View list of evidences

This commit is contained in:
Cayo Puigdefabregas 2024-07-31 13:28:46 +02:00
parent 46a0bb392d
commit f3117e2f00
4 changed files with 52 additions and 67 deletions

View File

@ -7,6 +7,25 @@ from evidence.xapian import search
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:
def __init__(self, uuid):
self.uuid = uuid
@ -51,21 +70,9 @@ class Evidence:
def components(self):
return self.doc.get('components', [])
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")
]
@classmethod
def get_all(cls, user):
return Annotation.objects.filter(
owner=user,
type=Annotation.Type.SYSTEM,
).order_by("-created").values_list("uuid", flat=True).distinct()

View File

@ -10,11 +10,15 @@ from utils.constants import ALGOS
class Build:
def __init__(self, evidence_json, user):
def __init__(self, evidence_json, user, check=False):
self.json = evidence_json
self.uuid = self.json['uuid']
self.user = user
self.hid = None
self.generate_chids()
if check:
return
self.index()
self.create_annotations()
@ -23,6 +27,11 @@ class Build:
snap = json.dumps(self.json)
index(self.uuid, snap)
def generate_chids(self):
self.algorithms = {
'hidalgo1': self.get_hid_14(),
}
def get_hid_14(self):
device = self.json['device']
manufacturer = device.get("manufacturer", '')
@ -34,22 +43,8 @@ class Build:
return hashlib.sha3_256(hid.encode()).hexdigest()
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(
uuid=self.uuid,
owner=self.user,
@ -57,4 +52,3 @@ class Build:
key=k,
value=v
)

View File

@ -8,33 +8,19 @@
</div>
</div>
<div class="dataTable-container">
<form method="post">
{% csrf_token %}
<table class="table">
<thead>
<tr>
<th scope="col" data-sortable="">
<a class="dataTable-sorter" href="#">Title</a>
</th>
</tr>
</thead>
{% for snap in evicendes %}
<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>
<div class="row">
<table class="table table-striped table-sm">
{% for ev in evidences %}
<tr>
<td>
<a href="{# url 'evidence:details' ev #}">{{ ev }}</a>
</td>
<td>
<a href="{# url 'evidence:delete' ev #}"><i class="bi bi-trash text-danger"></i></a>
</td>
</tr>
{% endfor %}
</table>
</form>
</div>
{% endblock %}

View File

@ -2,13 +2,11 @@ from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView
from django.urls import reverse_lazy
from django.views.generic.edit import (
CreateView,
UpdateView,
FormView,
)
from dashboard.mixins import DashboardView
from evidence.models import Evidence, Annotation
from evidence.models import Evidence
from evidence.forms import UploadForm
# from django.shortcuts import render
# from rest_framework import viewsets
@ -28,8 +26,8 @@ class ListEvidencesView(DashboardView, TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# evidences = Evidence.objects.filter(owner=self.request.user)
evidences = []
evidences = Evidence.get_all(self.request.user)
context.update({
'evidences': evidences,
})