Skip to content

Commit

Permalink
Add symbols edition deletion + Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
k1nd0ne committed Jun 8, 2022
1 parent 44b8519 commit c24d47c
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ docker/nginx/log/
db.sqlite3
investigations/.DS_Store
.DS_Store

*.json
4 changes: 1 addition & 3 deletions VolWeb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@
path('', include('dashboard.urls')),
path('investigations/', include('investigations.urls')),
path('iocs/', include('iocs.urls')),
path('symobls/', include('symbols.urls')),


path('symbols/', include('symbols.urls')),
]
9 changes: 9 additions & 0 deletions dashboard/static/js/bs-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ if (document.getElementById('indcount')) {
console.error(countUp.error);
}
}

if (document.getElementById('symcount')) {
const countUp = new CountUp('symcount', document.getElementById("symcount").getAttribute("countTosym"));
if (!countUp.error) {
countUp.start();
} else {
console.error(countUp.error);
}
}
14 changes: 11 additions & 3 deletions dashboard/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,31 @@
</div>
<div class="container-fluid">
<div class="row">
<div class="col-1"></div>
<div class="col-3">
<div class="col-1"></div>
<div class="col-2">
<div class="card bg-light border border-dark">
<div class="card-body">
<h4 class="card-title text-dark">Analysis</h4>
<h6 class="fs-1 text-primary card-subtitle mb-2" id="memcount" countTomem="{{investigations}}"></h6><a class="card-link text-dark" href="{% url 'investigations' %}">View&gt;</a><a class=" text-dark card-link" href="{% url 'newinvest' %}">Create&gt;</a>
</div>
</div>
</div>
<div class="col-3">
<div class="col-2">
<div class="card bg-light border border-dark">
<div class="card-body">
<h4 class="card-title text-dark">IOCs</h4>
<h6 class="fs-1 text-danger card-subtitle mb-2" id="indcount" countToind="{{iocs}}"></h6><a class="text-dark card-link" href="{% url 'iocs' %}">View&gt;</a><a class="text-dark card-link" href="{% url 'newioc' %}">Create&gt;</a>
</div>
</div>
</div>
<div class="col-2">
<div class="card bg-light border border-dark">
<div class="card-body">
<h4 class="card-title text-dark">Symbol Tables</h4>
<h6 class="fs-1 text-success card-subtitle mb-2" id="symcount" countToSym="{{symbols}}"></h6><a class="text-dark card-link" href="{% url 'symbols' %}">View&gt;</a><a class="text-dark card-link" href="{% url 'addsymbols' %}">Create&gt;</a>
</div>
</div>
</div>
</div>
</div>
<script src="{% static 'js/countup.min.js'%}"></script>
Expand Down
9 changes: 8 additions & 1 deletion dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth.decorators import login_required
from investigations.models import UploadInvestigation, Activity
from iocs.models import IOC
from symbols.models import Symbols
from django.contrib.auth import get_user_model
from django.core import serializers

Expand All @@ -18,4 +19,10 @@ def dashboard(request):
"""
User = get_user_model()
activity = serializers.serialize("json", Activity.objects.all(), fields = ("date", "count"))
return render(request,'dashboard/dashboard.html',{'Activity': activity, 'Users':User.objects.filter(is_superuser = False),'investigations':UploadInvestigation.objects.all().count(), 'iocs':IOC.objects.all().count()})
return render(request,'dashboard/dashboard.html',
{
'Activity': activity, 'Users':User.objects.filter(is_superuser = False),
'investigations':UploadInvestigation.objects.all().count(),
'iocs':IOC.objects.all().count(),
'symbols':Symbols.objects.all().count()
})
6 changes: 3 additions & 3 deletions investigations/templates/investigations/invest.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
<a class="link-dark" href=# onclick="DisplayInvestigation('{{i.id}}')">
<li id="{{i.id}}" class="invest-card list-group-item d-flex flex-row justify-content-left align-items-center bg-light border-sm border-dark mt-1">
{% if i.os_version == "Windows" %}
<i class="fab fa-windows text-info d-xxl-flex" style="font-size: 20px;margin-right: 10px;"></i>
<i class="fab fa-windows text-info d-xxl-flex" style="font-size: 25px;margin-right: 10px;"></i>
{% endif %}
{% if i.os_version == "Linux" %}
<code><i class="fab fa-linux d-xxl-flex" style="font-size: 20px;margin-right: 10px;"></i></code>
<code><i class="fab fa-linux d-xxl-flex" style="font-size: 25px;margin-right: 10px;"></i></code>
{% endif %}
{% if i.os_version == "MacOs" %}
<i class="fab fa-apple text-dark d-xxl-flex" style="font-size: 20px;margin-right: 10px;"></i>
<i class="fab fa-apple text-dark d-xxl-flex" style="font-size: 25px;margin-right: 10px;"></i>
{% endif %}
<span class="text-light" style="margin-right: 10px;">{{i.title}}</span>
<div id="pb_{{i.id}}" class="ms-auto">
Expand Down
2 changes: 1 addition & 1 deletion investigations/templates/investigations/newinvest.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "dashboard/base.html" %}
{% load static %}
{% block content%}
<div class="container-fluid"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'investigations' %}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="container"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'investigations' %}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="d-sm-flex justify-content-between align-items-center mb-4">
<h3 class="text-dark mb-0">New investigation</h3>
</div>
Expand Down
2 changes: 1 addition & 1 deletion iocs/templates/iocs/customioc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% extends "dashboard/base.html" %}

{% block content %}
<div class="container-fluid"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'iocs'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="container"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'iocs'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="d-sm-flex justify-content-between align-items-center mb-4">
<h3 class="text-dark mb-0">Custom IOC</h3>
</div>
Expand Down
1 change: 0 additions & 1 deletion iocs/templates/iocs/iocs.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
</div>
<form action="" method="POST">
{% csrf_token %}
{{form.id}}
</form>
<script>
$(document).ready(function(){
Expand Down
4 changes: 2 additions & 2 deletions iocs/templates/iocs/newioc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{% extends "dashboard/base.html" %}

{% block content %}
<div class="container-fluid"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'iocs'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="container"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'iocs'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="d-sm-flex justify-content-between align-items-center mb-4">
<h3 class="text-dark mb-0">New string based IOC</h3>
</div>
<form method="POST">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="card bg-light border border-dark border-sm shadow mb-3">
<div class="card-header py-3">
Expand Down
4 changes: 2 additions & 2 deletions iocs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def iocs(request):
Comment: Display all of the iocs
"""
form = ManageIOC()
return render(request,'iocs/iocs.html',{'iocs':IOC.objects.all(), 'investigations':UploadInvestigation.objects.all(), 'form':form})
return render(request,'iocs/iocs.html',{'iocs':IOC.objects.all(), 'investigations':UploadInvestigation.objects.all()})

@login_required
def newioc(request):
Expand Down Expand Up @@ -56,6 +55,7 @@ def customioc(request):
return render(request,'iocs/customioc.html',{'form': custom_form, 'ioc_id':id, 'investigations':UploadInvestigation.objects.all()})
if request.method == 'POST':
form = SaveCustomIOC(request.POST)
print(request.POST)
if form.is_valid():
ioc_record = IOC.objects.get(pk=form.cleaned_data['ioc_id'])
ioc_record.name = form.cleaned_data['name']
Expand Down
2 changes: 2 additions & 0 deletions symbols/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib import admin
from .models import Symbols
admin.site.register(Symbols)

# Register your models here.
20 changes: 18 additions & 2 deletions symbols/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from .models import Symbols
from django.forms import ModelForm, TextInput, Textarea, ModelChoiceField, Select, FileInput
from django.forms import ModelForm, TextInput, Textarea, Select, FileInput

#This ModelForm is made to create a new IOC
class NewSymbolsForm(forms.ModelForm):
Expand All @@ -11,5 +11,21 @@ class Meta:
'name': TextInput(attrs={'class':'form-control','placeholder': 'Usually the distribution name and kernel version','required':'""'}),
'os': Select(attrs={'class': 'form-control','required':'""'}),
'description' : Textarea(attrs={'class':'form-control','rows':"4",'placeholder':'Detailed informations about this ISF','required':'""'}),
'symbols_file' : FileInput(attrs={'class': 'form-control','required':'""'}),
'symbols_file' : FileInput(attrs={'class': 'form-control'}),
}

class CustomSymbolsForm(forms.ModelForm):
symbols_id = forms.CharField(max_length=100, widget=forms.TextInput(attrs={
'class': 'd-none','value':'a'}))
class Meta:
model = Symbols
fields = ('name','os','description')
widgets = {
'name': TextInput(attrs={'class':'form-control','placeholder': 'Usually the distribution name and kernel version','required':'""'}),
'os': Select(attrs={'class': 'form-control','required':'""'}),
'description' : Textarea(attrs={'class':'form-control','rows':"4",'placeholder':'Detailed informations about this ISF','required':'""'}),
}

class ManageSymbols(forms.Form):
symbols_id = forms.CharField(max_length=100, widget=forms.TextInput(attrs={
'class': 'd-none',}))
6 changes: 3 additions & 3 deletions symbols/templates/symbols/addsymbols.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends "dashboard/base.html" %}
{% load static %}
{% block content%}
<div class="container-fluid"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'symbols'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="container"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'symbols'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="d-sm-flex justify-content-between align-items-center mb-4">
<h3 class="text-dark mb-0">Add a new symbol</h3>
<h3 class="text-dark mb-0">Upload a symbol table</h3>
</div>
<form method="POST">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="card bg-light border border-dark border-sm shadow mb-3">
<div class="card-header py-3">
Expand Down
45 changes: 45 additions & 0 deletions symbols/templates/symbols/customsymbols.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends "dashboard/base.html" %}
{% load static %}
{% block content%}
<div class="container"><a class="btn btn-link link-primary mb-3" role="button" target="_parent" href="{% url 'symbols'%}"><i class="fas fa-arrow-left"></i>&nbsp;Back</a>
<div class="d-sm-flex justify-content-between align-items-center mb-4">
<h3 class="text-dark mb-0">Upload a symbol table</h3>
</div>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="card bg-light border border-dark border-sm shadow mb-3">
<div class="card-header py-3">
<p class="text-dark m-0 fw-bold">Fill in the required fields *</p>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-12 col-md-8 col-lg-8">
<div class="mb-3"><label class="form-label" for="service_name"><strong>Name *</strong></label>{{form.name}}</div>
</div>
<div class="col-sm-12 col-md-4 col-lg-4">
<div class="mb-3"><label class="form-label" for="service_price"><strong>OS *</strong><br></label>{{form.os}}</div>
</div>
</div>
<div class="mb-3"><label class="form-label" for="client_description"><strong>Description *</strong><br></label>{{form.description}}</div>
<div class="mb-3"><label class="form-label" for="service_client_end_date"><strong>ISF :</strong><br></label>
{{file}}
</div>
{{form.symbols_id}}
<button class="btn btn-primary" id="submit">Save</button>
</div>
</div>
<div class="text-end mb-3"></div>
</form>
</div>

<script>

$(document).ready(function(){
$('#id_symbols_id').val('{{symbols_id}}');
$('.container').show();
$('.container-fluid').show();
$('.spinner-main').hide();
});

</script>
{% endblock content %}
48 changes: 42 additions & 6 deletions symbols/templates/symbols/symbols.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="{% url 'addsymbols' %}" type="button" class="btn border-sm border-light btn-dark btn-sm">+ Add new symbols</a>
</div>
<div class="col-12 mt-3 mb-3 mb-lg-0" role="search">
<input type="search" class="form-control" placeholder="Search for a kernel version" aria-label="Search">
<input type="search" id="searchSymb" class="form-control" placeholder="Search for symbols tables" aria-label="Search">
</div>
</div>
<div class="container mt-4">
Expand All @@ -25,21 +25,22 @@
<th>Name</th>
<th>Description</th>
<th>Operating system</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tbody id="symbolsTable">
{% if symbols %}
{% for s in symbols %}
<tr>
<td>{{s.name}}</td>
<td>{{s.description}}</td>
<td>{{s.os}}</td>
<td>
<form style="all: unset;" id="reviewform" action="{% url 'customioc' %}" method="GET">
<input type="hidden" name="ioc_id" value="{{ioc.id}}">
<form style="all: unset;" id="reviewform" action="{% url 'customsymbols' %}" method="GET">
<input type="hidden" name="symbols_id" value="{{s.id}}">
<input class="btn border border-light btn-dark btn-sm" type="submit" style="margin-right: 10px;" value="Edit">
</form>
<a class="btn border border-light btn-danger btn-sm" role="button" onclick="DeleteIOC({{ioc.id}})">Delete</a>
<a class="btn border border-light btn-danger btn-sm" role="button" onclick="DeleteSymbols({{s.id}})">Delete</a>
</tr>
{% endfor %}
{% endif %}
Expand All @@ -49,13 +50,48 @@
</div>
</div>
</div>

<form action="" method="POST">
{% csrf_token %}
<script>

$(document).ready(function(){
$('.container').show();
$('.container-fluid').show();
$('.spinner-main').hide();
//Process Env SearchBar

$("#searchSymb").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#symbolsTable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});

//Ask for IOC deletion
function DeleteSymbols(id){
const csrf = document.getElementsByName('csrfmiddlewaretoken');
const fd = new FormData();
fd.append('csrfmiddlewaretoken', csrf[0].value);
fd.append('symbols_id', id);
$.ajax({
type:'POST',
url: "{% url 'deletesymbols' %}",
enctype: 'multipart/form-data',
data: fd,
beforeSend: function(){
},
success: function(response){
location.reload();
},
error: function(error){

},
cache: false,
contentType : false,
processData: false
});
}

</script>
{% endblock content %}
Empty file added symbols/uploads/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions symbols/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
urlpatterns = [
path('',views.symbols,name='symbols'),
path('addsymbols',views.addsymbols,name='addsymbols'),
path('customsymbols',views.customsymbols,name='customsymbols'),
path('deletesymbols',views.deletesymbols,name='deletesymbols'),
]
Loading

0 comments on commit c24d47c

Please sign in to comment.