xapian #1

Merged
cayop merged 26 commits from xapian into master 2024-09-17 10:11:28 +00:00
26 changed files with 69 additions and 69 deletions
Showing only changes of commit e2f9855954 - Show all commits

View File

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

View File

@ -108,19 +108,19 @@
</ul> </ul>
</li> </li>
<li class="nav-item"> <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> <i class="bi bi-usb-drive icon_sidebar"></i>
{% trans 'Snapshots' %} {% trans 'evidences' %}
</a> </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"> <li class="nav-item">
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{# url 'idhub:admin_people_list' #}"> <a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{# url 'idhub:admin_people_list' #}">
{% trans 'Upload one' %} {% trans 'Upload one' %}
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'snapshot:list' %}"> <a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'evidence:list' %}">
{% trans 'Old snapshots' %} {% trans 'Old evidences' %}
</a> </a>
</li> </li>
</ul> </ul>

View File

@ -151,12 +151,12 @@
</a> </a>
</li><!-- End Dashboard Nav --> </li><!-- End Dashboard Nav -->
<li class="nav-heading">Snapshots</li> <li class="nav-heading">evidences</li>
<li class="nav-item"> <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> <i class="bi-menu-button-wide"></i>
<span>Uploaded Snapshots</span> <span>Uploaded evidences</span>
</a> </a>
</li> </li>

View File

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

View File

@ -1,7 +1,7 @@
from django.db import models from django.db import models
from utils.constants import STR_SM_SIZE, STR_SIZE, STR_EXTEND_SIZE, ALGOS 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 user.models import User
from lot.models import DeviceLot from lot.models import DeviceLot
@ -32,15 +32,15 @@ class Device:
self.annotations = [] self.annotations = []
self.hids = [] self.hids = []
self.uuids = [] self.uuids = []
self.snapshots = [] self.evidences = []
self.last_snapshot = None self.last_evidence = None
self.get_last_snapshot() self.get_last_evidence()
def initial(self): def initial(self):
self.get_annotations() self.get_annotations()
self.get_uuids() self.get_uuids()
self.get_hids() self.get_hids()
self.get_snapshots() self.get_evidences()
def get_annotations(self): def get_annotations(self):
if self.annotations: if self.annotations:
@ -70,17 +70,17 @@ class Device:
key__in=ALGOS.keys(), key__in=ALGOS.keys(),
).values_list("value", flat=True) ).values_list("value", flat=True)
def get_snapshots(self): def get_evidences(self):
if not self.uuids: if not self.uuids:
self.get_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() annotations = self.get_annotations()
if annotations: if annotations:
annotation = annotations.first() annotation = annotations.first()
self.last_snapshot = Snapshot(annotation.uuid) self.last_evidence = Evidence(annotation.uuid)
def last_uuid(self): def last_uuid(self):
return self.uuids[0] return self.uuids[0]
@ -100,24 +100,24 @@ class Device:
@property @property
def manufacturer(self): def manufacturer(self):
if not self.last_snapshot: if not self.last_evidence:
self.get_last_snapshot() self.get_last_evidence()
return self.last_snapshot.doc['device']['manufacturer'] return self.last_evidence.doc['device']['manufacturer']
@property @property
def type(self): def type(self):
if not self.last_snapshot: if not self.last_evidence:
self.get_last_snapshot() self.get_last_evidence()
return self.last_snapshot.doc['device']['type'] return self.last_evidence.doc['device']['type']
@property @property
def model(self): def model(self):
if not self.last_snapshot: if not self.last_evidence:
self.get_last_snapshot() self.get_last_evidence()
return self.last_snapshot.doc['device']['model'] return self.last_evidence.doc['device']['model']
@property @property
def type(self): def type(self):
if not self.last_snapshot: if not self.last_evidence:
self.get_last_snapshot() self.get_last_evidence()
return self.last_snapshot.doc['device']['type'] 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> <button class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</button>
</li> </li>
<li class="nav-items"> <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>
<li class="nav-items"> <li class="nav-items">
<a class="nav-link" href="">Web</a> <a class="nav-link" href="">Web</a>
@ -69,7 +69,7 @@
<div class="row"> <div class="row">
<div class="col-lg-3 col-md-4 label">Serial Number</div> <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>
<div class="row"> <div class="row">
<div class="col-lg-3 col-md-4 label">Identifiers</div> <div class="col-lg-3 col-md-4 label">Identifiers</div>
@ -163,13 +163,13 @@
</div> </div>
<div class="tab-pane fade profile-overview" id="components"> <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"> <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="list-group-item">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ c.type }}</h5> <h5 class="mb-1">{{ c.type }}</h5>
<small class="text-muted">{{ snapshot.created }}</small> <small class="text-muted">{{ evidence.created }}</small>
</div> </div>
<p class="mb-1"> <p class="mb-1">
{{ c.manufacturer }}<br /> {{ c.manufacturer }}<br />
@ -183,10 +183,10 @@
</div> </div>
</div> </div>
<div class="tab-pane fade profile-overview" id="snapshots"> <div class="tab-pane fade profile-overview" id="evidences">
<h5 class="card-title">List of snapshots</h5> <h5 class="card-title">List of evidences</h5>
<div class="list-group col-6"> <div class="list-group col-6">
{% for snap in object.snapshots %} {% for snap in object.evidences %}
<div class="list-group-item"> <div class="list-group-item">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"></h5> <h5 class="mb-1"></h5>

View File

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

View File

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

View File

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

View File

@ -3,11 +3,11 @@ import json
from django.db import models from django.db import models
from utils.constants import STR_SM_SIZE, STR_EXTEND_SIZE 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 from user.models import User
class Snapshot: class Evidence:
def __init__(self, uuid): def __init__(self, uuid):
self.uuid = uuid self.uuid = uuid
self.owner = None self.owner = None

View File

@ -4,14 +4,14 @@ import shutil
import hashlib import hashlib
from datetime import datetime from datetime import datetime
from snapshot.xapian import search, index from evidence.xapian import search, index
from snapshot.models import Snapshot, Annotation from evidence.models import Evidence, Annotation
from utils.constants import ALGOS from utils.constants import ALGOS
class Build: class Build:
def __init__(self, snapshot_json, user): def __init__(self, evidence_json, user):
self.json = snapshot_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

View File

@ -1,15 +1,15 @@
from rest_framework import serializers from rest_framework import serializers
from snapshot.models import SnapshotJson from evidence.models import EvidenceJson
import json import json
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse 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: class Meta:
model = SnapshotJson model = EvidenceJson
fields = ['id', 'title', 'content'] fields = ['id', 'title', 'content']
@csrf_exempt @csrf_exempt

View File

@ -19,14 +19,14 @@
</th> </th>
</tr> </tr>
</thead> </thead>
{% for snap in snapshots %} {% for snap in evicendes %}
<tbody> <tbody>
<tr> <tr>
<td> <td>
<input type="checkbox" name="snapshots" value="{{ snap.id }}" /> <input type="checkbox" name="evidences" value="{{ snap.id }}" />
</td> </td>
<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>
<td> <td>
<a href="{% url 'device:details' snap.computer.device.pk %}">{{ snap.computer.device.manufacturer }} {{ snap.computer.device.model }}</a> <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)), # path('', include(router.urls)),
# ] # ]
from django.urls import path from django.urls import path
from snapshot import views from evidence import views
app_name = 'snapshot' app_name = 'evidence'
urlpatterns = [ 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 dashboard.mixins import DashboardView
from snapshot.models import Snapshot, Annotation from evidence.models import Evidence, Annotation
# from snapshot.forms import UploadForm # from snapshot.forms import UploadForm
# from django.shortcuts import render # from django.shortcuts import render
# from rest_framework import viewsets # from rest_framework import viewsets
@ -20,18 +20,18 @@ from snapshot.models import Snapshot, Annotation
# serializer_class = SnapshotSerializer # serializer_class = SnapshotSerializer
class ListSnapshotsView(DashboardView, TemplateView): class ListEvidencesView(DashboardView, TemplateView):
template_name = "snapshots.html" template_name = "evidences.html"
section = "snapshots" section = "evidences"
title = _("Snapshots") title = _("Evidences")
breadcrumb = "Snapshots" breadcrumb = "Evidences"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
# snapshots = Snapshot.objects.filter(owner=self.request.user) # evidences = Evidence.objects.filter(owner=self.request.user)
snapshots = [] evidences = []
context.update({ context.update({
'snapshots': snapshots, 'evidences': evidences,
}) })
return context return context

View File

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