Compare commits

..

2 commits

Author SHA1 Message Date
pedro 5e7e7df1be README: small changes 2024-11-08 16:00:05 +01:00
sergio_gimenez 0d9b580917 Add improved redame 2024-10-29 08:52:17 +01:00
6 changed files with 36 additions and 59 deletions

View file

@ -1,16 +1,16 @@
DOMAIN=localhost DOMAIN=localhost
DEMO=true DEMO=false
# note that with DEBUG=true, logs are more verbose (include tracebacks)
DEBUG=true
ALLOWED_HOSTS=localhost,localhost:8000,127.0.0.1,
STATIC_ROOT=/tmp/static/ STATIC_ROOT=/tmp/static/
MEDIA_ROOT=/tmp/media/ MEDIA_ROOT=/tmp/media/
ALLOWED_HOSTS=localhost,localhost:8000,127.0.0.1,
DOMAIN=localhost
DEBUG=True
EMAIL_HOST="mail.example.org" EMAIL_HOST="mail.example.org"
EMAIL_HOST_USER="fillme_noreply" EMAIL_HOST_USER="fillme_noreply"
EMAIL_HOST_PASSWORD="fillme_passwd" EMAIL_HOST_PASSWORD="fillme_passwd"
EMAIL_PORT=587 EMAIL_PORT=587
EMAIL_USE_TLS=true EMAIL_USE_TLS=True
EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend" EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
EMAIL_FILE_PATH="/tmp/app-messages" EMAIL_FILE_PATH="/tmp/app-messages"
ENABLE_EMAIL=false ENABLE_EMAIL=false

View file

@ -55,7 +55,8 @@
<div class="col-lg-3 col-md-4 label ">{% trans "Type" %}</div> <div class="col-lg-3 col-md-4 label ">{% trans "Type" %}</div>
<div class="col-lg-9 col-md-8">{{ object.type }}</div> <div class="col-lg-9 col-md-8">{{ object.type }}</div>
</div> </div>
{% if object.is_websnapshot and object.last_user_evidence %}
{% if object.is_websnapshot %}
{% for k, v in object.last_user_evidence %} {% for k, v in object.last_user_evidence %}
<div class="row"> <div class="row">
<div class="col-lg-3 col-md-4 label">{{ k }}</div> <div class="col-lg-3 col-md-4 label">{{ k }}</div>

View file

@ -14,11 +14,6 @@ main() {
if [ "${DETACH:-}" ]; then if [ "${DETACH:-}" ]; then
detach_arg='-d' detach_arg='-d'
fi fi
if [ ! -f .env ]; then
cp -v .env.example .env
echo "WARNING: .env was not there, .env.example was copied, this only happens once"
fi
# remove old database # remove old database
sudo rm -vfr ./db/* sudo rm -vfr ./db/*
docker compose down -v docker compose down -v

View file

@ -35,14 +35,10 @@ class UploadForm(forms.Form):
).first() ).first()
if exist_annotation: if exist_annotation:
raise ValidationError("Error: {} already exists".format(file_name)) raise ValidationError("error: {} exist".format(file_name))
except json.JSONDecodeError: except Exception:
raise ValidationError("Error in parsing JSON: '{}'. Check for file integrity.".format(file_name)) raise ValidationError("error in: {}".format(file_name))
except ValidationError as e:
raise e
except Exception as e:
raise ValidationError("Oops! Something went wrong in '{}': {}".format(file_name, str(e)))
self.evidences.append((file_name, file_json)) self.evidences.append((file_name, file_json))

View file

@ -1,18 +1,12 @@
import os import os
import json import json
import logging
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.conf import settings
from utils.save_snapshots import move_json, save_in_disk
from evidence.parse import Build from evidence.parse import Build
logger = logging.getLogger('django')
User = get_user_model() User = get_user_model()
@ -37,11 +31,9 @@ class Command(BaseCommand):
elif os.path.isdir(path): elif os.path.isdir(path):
self.read_directory(path) self.read_directory(path)
else:
raise ValueError(f"The path {path} is neither a file nor a directory")
self.parsing() self.parsing()
def read_directory(self, directory): def read_directory(self, directory):
for filename in os.listdir(directory): for filename in os.listdir(directory):
filepath = os.path.join(directory, filename) filepath = os.path.join(directory, filename)
@ -49,27 +41,10 @@ class Command(BaseCommand):
self.open(filepath) self.open(filepath)
def open(self, filepath): def open(self, filepath):
try: with open(filepath, 'r') as file:
with open(filepath, 'r') as file: content = json.loads(file.read())
content = json.loads(file.read()) self.snapshots.append(content)
path_name = save_in_disk(content, self.user.institution.name)
self.snapshots.append((content, path_name))
except json.JSONDecodeError as e:
raise e
#or we cath'em all
except Exception:
raise Exception(f"Oops! Something went wrong there")
def parsing(self): def parsing(self):
for s, p in self.snapshots: for s in self.snapshots:
try: self.devices.append(Build(s, self.user))
self.devices.append(Build(s, self.user))
move_json(p, self.user.institution.name)
except Exception as err:
if settings.DEBUG:
logger.exception("%s", err)
snapshot_id = s.get("uuid", "")
txt = "It is not possible to parse snapshot: %s"
logger.error(txt, snapshot_id)

View file

@ -5,15 +5,23 @@ import logging
from dmidecode import DMIParse from dmidecode import DMIParse
from json_repair import repair_json from json_repair import repair_json
from evidence.parse_details import get_lshw_child
from evidence.models import Annotation from evidence.models import Annotation
from evidence.xapian import index from evidence.xapian import index
from utils.constants import CHASSIS_DH from utils.constants import CHASSIS_DH
logger = logging.getLogger(__name__) logger = logging.getLogger('django')
def get_network_cards(child, nets):
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
nets.append(child)
if child.get('children'):
[get_network_cards(x, nets) for x in child['children']]
def get_mac(lshw): def get_mac(lshw):
nets = []
try: try:
if type(lshw) is dict: if type(lshw) is dict:
hw = lshw hw = lshw
@ -22,17 +30,19 @@ def get_mac(lshw):
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
hw = json.loads(repair_json(lshw)) hw = json.loads(repair_json(lshw))
networks = [] try:
get_lshw_child(hw, networks, 'network') get_network_cards(hw, nets)
except Exception as ss:
print("WARNING!! {}".format(ss))
return
nets_sorted = sorted(networks, key=lambda x: x['businfo']) nets_sorted = sorted(nets, key=lambda x: x['businfo'])
# This funcion get the network card integrated in motherboard # This funcion get the network card integrated in motherboard
# integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')] # integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
if nets_sorted: if nets_sorted:
mac = nets_sorted[0]['serial'] return nets_sorted[0]['serial']
logger.debug("The snapshot has the following MAC: %s" , mac)
return mac
class Build: class Build:
def __init__(self, evidence_json, user, check=False): def __init__(self, evidence_json, user, check=False):