Skip to content

Commit

Permalink
suricata: add SURICATA_NAME_IS_HOSTNAME option
Browse files Browse the repository at this point in the history
If True, the name of the Suricata object will be equal to the
hostname. This will prevent amount of bug reports of people
that are using SELKS distribution.

The option is False by default for backward compatibility.
  • Loading branch information
regit committed Aug 23, 2017
1 parent 63e6df4 commit cec4a2d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scirius/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
# Suricata binary
SURICATA_BINARY = "suricata"

SURICATA_NAME_IS_HOSTNAME = False

# Elastic search

USE_ELASTICSEARCH = True
Expand Down
3 changes: 3 additions & 0 deletions suricata/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

from django import forms
from django.conf import settings
from suricata.models import Suricata
from rules.models import Ruleset
from rules.forms import CommentForm
Expand All @@ -27,6 +28,8 @@ class SuricataForm(forms.ModelForm, CommentForm):
class Meta:
model = Suricata
exclude = ('created_date', 'updated_date')
if settings.SURICATA_NAME_IS_HOSTNAME:
exclude = exclude + ('name', )

class SuricataUpdateForm(CommentForm):
reload = forms.BooleanField(required=False)
Expand Down
4 changes: 4 additions & 0 deletions suricata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
from django.db import models
from django.core.exceptions import ValidationError
from django.utils import timezone
from django.conf import settings

# Create your models here.
import os
import socket

from rules.models import Ruleset

Expand Down Expand Up @@ -87,6 +89,8 @@ def get_absolute_url(self):
return reverse('suricata_index')

def get_probe_hostnames(limit = 10):
if settings.SURICATA_NAME_IS_HOSTNAME:
return [ socket.gethostname() ]
suricata = Suricata.objects.all()
if suricata != None:
return [ suricata[0].name ]
Expand Down
3 changes: 3 additions & 0 deletions suricata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

from time import time
import socket

from django.shortcuts import render, redirect
from django.db import IntegrityError
Expand Down Expand Up @@ -53,6 +54,8 @@ def get_suri():
def index(request, error = None):
# try to get suricata from db
suri = get_suri()
if settings.SURICATA_NAME_IS_HOSTNAME:
suri.name = socket.gethostname()

if suri:
context = {'suricata': suri}
Expand Down

0 comments on commit cec4a2d

Please sign in to comment.