change snapshots for evidences

This commit is contained in:
Cayo Puigdefabregas 2024-07-26 17:59:34 +02:00
parent 70ded10852
commit 91780be94b
26 changed files with 69 additions and 69 deletions

View File

@ -5,7 +5,7 @@ from django.core.exceptions import PermissionDenied
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic.base import TemplateView
from device.models import Device
from snapshot.models import Annotation
from evidence.models import Annotation
from lot.models import LotTag

View File

@ -108,19 +108,19 @@
</ul>
</li>
<li class="nav-item">
<a class="admin {% if section == 'People' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_snapshots" aria-expanded="false" aria-controls="ul_snapshots" href="javascript:void()">
<a class="admin {% if section == 'People' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_evidences" aria-expanded="false" aria-controls="ul_evidences" href="javascript:void()">
<i class="bi bi-usb-drive icon_sidebar"></i>
{% trans 'Snapshots' %}
{% trans 'evidences' %}
</a>
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="ul_snapshots" data-bs-parent="#sidebarMenu">
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="ul_evidences" data-bs-parent="#sidebarMenu">
<li class="nav-item">
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{# url 'idhub:admin_people_list' #}">
{% trans 'Upload one' %}
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'snapshot:list' %}">
{% trans 'Old snapshots' %}
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'evidence:list' %}">
{% trans 'Old evidences' %}
</a>
</li>
</ul>

View File

@ -151,12 +151,12 @@
</a>
</li><!-- End Dashboard Nav -->
<li class="nav-heading">Snapshots</li>
<li class="nav-heading">evidences</li>
<li class="nav-item">
<a class="nav-link collapsed" href="{# url_for('inventory.snapshotslist') #}">
<a class="nav-link collapsed" href="{# url_for('inventory.evidenceslist') #}">
<i class="bi-menu-button-wide"></i>
<span>Uploaded Snapshots</span>
<span>Uploaded evidences</span>
</a>
</li>

View File

@ -4,8 +4,8 @@ from django.utils.translation import gettext_lazy as _
from django.db.models import Count
from dashboard.mixins import InventaryMixin, DetailsMixin
from device.models import Device
from snapshot.xapian import search
from snapshot.models import Annotation
from evidence.xapian import search
from evidence.models import Annotation
from lot.models import Lot, LotTag

View File

@ -1,7 +1,7 @@
from django.db import models
from utils.constants import STR_SM_SIZE, STR_SIZE, STR_EXTEND_SIZE, ALGOS
from snapshot.models import Annotation, Snapshot
from evidence.models import Annotation, Evidence
from user.models import User
from lot.models import DeviceLot
@ -32,15 +32,15 @@ class Device:
self.annotations = []
self.hids = []
self.uuids = []
self.snapshots = []
self.last_snapshot = None
self.get_last_snapshot()
self.evidences = []
self.last_evidence = None
self.get_last_evidence()
def initial(self):
self.get_annotations()
self.get_uuids()
self.get_hids()
self.get_snapshots()
self.get_evidences()
def get_annotations(self):
if self.annotations:
@ -70,17 +70,17 @@ class Device:
key__in=ALGOS.keys(),
).values_list("value", flat=True)
def get_snapshots(self):
def get_evidences(self):
if not self.uuids:
self.get_uuids()
self.snapshots = [Snapshot(u) for u in self.uuids]
self.evidences = [Evidence(u) for u in self.uuids]
def get_last_snapshot(self):
def get_last_evidence(self):
annotations = self.get_annotations()
if annotations:
annotation = annotations.first()
self.last_snapshot = Snapshot(annotation.uuid)
self.last_evidence = Evidence(annotation.uuid)
def last_uuid(self):
return self.uuids[0]
@ -100,24 +100,24 @@ class Device:
@property
def manufacturer(self):
if not self.last_snapshot:
self.get_last_snapshot()
return self.last_snapshot.doc['device']['manufacturer']
if not self.last_evidence:
self.get_last_evidence()
return self.last_evidence.doc['device']['manufacturer']
@property
def type(self):
if not self.last_snapshot:
self.get_last_snapshot()
return self.last_snapshot.doc['device']['type']
if not self.last_evidence:
self.get_last_evidence()
return self.last_evidence.doc['device']['type']
@property
def model(self):
if not self.last_snapshot:
self.get_last_snapshot()
return self.last_snapshot.doc['device']['model']
if not self.last_evidence:
self.get_last_evidence()
return self.last_evidence.doc['device']['model']
@property
def type(self):
if not self.last_snapshot:
self.get_last_snapshot()
return self.last_snapshot.doc['device']['type']
if not self.last_evidence:
self.get_last_evidence()
return self.last_evidence.doc['device']['type']

View File

@ -27,7 +27,7 @@
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</button>
</li>
<li class="nav-items">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#snapshots">Snapshots</button>
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#evidences">Evidences</button>
</li>
<li class="nav-items">
<a class="nav-link" href="">Web</a>
@ -69,7 +69,7 @@
<div class="row">
<div class="col-lg-3 col-md-4 label">Serial Number</div>
<div class="col-lg-9 col-md-8">{{ object.last_snapshot.doc.device.serialNumber|default:"" }}</div>
<div class="col-lg-9 col-md-8">{{ object.last_evidence.doc.device.serialNumber|default:"" }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Identifiers</div>
@ -163,13 +163,13 @@
</div>
<div class="tab-pane fade profile-overview" id="components">
<h5 class="card-title">Components last snapshot</h5>
<h5 class="card-title">Components last evidence</h5>
<div class="list-group col-6">
{% for c in object.last_snapshot.doc.components %}
{% for c in object.last_evidence.doc.components %}
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ c.type }}</h5>
<small class="text-muted">{{ snapshot.created }}</small>
<small class="text-muted">{{ evidence.created }}</small>
</div>
<p class="mb-1">
{{ c.manufacturer }}<br />
@ -183,10 +183,10 @@
</div>
</div>
<div class="tab-pane fade profile-overview" id="snapshots">
<h5 class="card-title">List of snapshots</h5>
<div class="tab-pane fade profile-overview" id="evidences">
<h5 class="card-title">List of evidences</h5>
<div class="list-group col-6">
{% for snap in object.snapshots %}
{% for snap in object.evidences %}
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"></h5>

View File

@ -47,7 +47,7 @@ INSTALLED_APPS = [
"login",
"user",
"device",
"snapshot",
"evidence",
"action",
"tag",
"lot",

View File

@ -3,4 +3,4 @@ from django.apps import AppConfig
class ActionConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "snapshot"
name = "evidence"

View File

@ -2,7 +2,7 @@
class UploadForm(forms.Form):
snapshot_file = forms.FileField(label=_("File"))
evidence_file = forms.FileField(label=_("File"))
def clean(self):
data = self.cleaned_data

View File

@ -3,11 +3,11 @@ import json
from django.db import models
from utils.constants import STR_SM_SIZE, STR_EXTEND_SIZE
from snapshot.xapian import search
from evidence.xapian import search
from user.models import User
class Snapshot:
class Evidence:
def __init__(self, uuid):
self.uuid = uuid
self.owner = None

View File

@ -4,14 +4,14 @@ import shutil
import hashlib
from datetime import datetime
from snapshot.xapian import search, index
from snapshot.models import Snapshot, Annotation
from evidence.xapian import search, index
from evidence.models import Evidence, Annotation
from utils.constants import ALGOS
class Build:
def __init__(self, snapshot_json, user):
self.json = snapshot_json
def __init__(self, evidence_json, user):
self.json = evidence_json
self.uuid = self.json['uuid']
self.user = user
self.hid = None

View File

@ -1,15 +1,15 @@
from rest_framework import serializers
from snapshot.models import SnapshotJson
from evidence.models import EvidenceJson
import json
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from snapshot.parse import Parse
from evidence.parse import Parse
class SnapshotSerializer(serializers.ModelSerializer):
class EvidenceSerializer(serializers.ModelSerializer):
class Meta:
model = SnapshotJson
model = EvidenceJson
fields = ['id', 'title', 'content']
@csrf_exempt

View File

@ -19,14 +19,14 @@
</th>
</tr>
</thead>
{% for snap in snapshots %}
{% for snap in evicendes %}
<tbody>
<tr>
<td>
<input type="checkbox" name="snapshots" value="{{ snap.id }}" />
<input type="checkbox" name="evidences" value="{{ snap.id }}" />
</td>
<td>
<a href="{# url 'snapshot:details' snap.pk #}">{{ snap.uuid }} {{ snap.sid }} {{ snap.version }}</a>
<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>

View File

@ -9,10 +9,10 @@
# path('', include(router.urls)),
# ]
from django.urls import path
from snapshot import views
from evidence import views
app_name = 'snapshot'
app_name = 'evidence'
urlpatterns = [
path("", views.ListSnapshotsView.as_view(), name="list"),
path("", views.ListEvidencesView.as_view(), name="list"),
]

View File

@ -8,7 +8,7 @@ from django.views.generic.edit import (
)
from dashboard.mixins import DashboardView
from snapshot.models import Snapshot, Annotation
from evidence.models import Evidence, Annotation
# from snapshot.forms import UploadForm
# from django.shortcuts import render
# from rest_framework import viewsets
@ -20,18 +20,18 @@ from snapshot.models import Snapshot, Annotation
# serializer_class = SnapshotSerializer
class ListSnapshotsView(DashboardView, TemplateView):
template_name = "snapshots.html"
section = "snapshots"
title = _("Snapshots")
breadcrumb = "Snapshots"
class ListEvidencesView(DashboardView, TemplateView):
template_name = "evidences.html"
section = "evidences"
title = _("Evidences")
breadcrumb = "Evidences"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# snapshots = Snapshot.objects.filter(owner=self.request.user)
snapshots = []
# evidences = Evidence.objects.filter(owner=self.request.user)
evidences = []
context.update({
'snapshots': snapshots,
'evidences': evidences,
})
return context

View File

@ -8,7 +8,7 @@ from utils.constants import (
from user.models import User
# from device.models import Device
from snapshot.models import Annotation
from evidence.models import Annotation
class LotTag(models.Model):