Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup config #70

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 1.2.x
### 1.2.2
#### Bugfix
* Updated setup_config management command in order to overwrite the configs
### 1.2.1
#### Bugfix
* Fixed Elasticsearch environment variable
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# BuffaLogs

<img src="docs/static/cover_buffalogs.png" width=750 height=400 alt="BuffaLogs"/>

BuffaLogs is an Open Source Django Project whose main purpose is to detect impossible travel logins.

In detail, it sends several types of alerts:
Expand Down Expand Up @@ -153,3 +155,6 @@ BuffaLogs is an Open Source project and was developed in order to allow enrichme

## Licence
This project is protected by the Apache Licence 2.0.


[def]: docs/
80 changes: 53 additions & 27 deletions buffalogs/impossible_travel/management/commands/setup_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,68 @@

logger = logging.getLogger()
IGNORED_USERS = ["N/A", "Not Available"]
IGNORED_IPS = [""]
IGNORED_IPS = ["127.0.0.1"]


class Command(BaseCommand):
help = "Command to setup configs in the Config model"
help = "Setup the Configs overwriting them"

def add_arguments(self, parser):
# Optional arguments
parser.add_argument("--ignored_users", nargs="?", action="append", default=[], help="List of users to filter and to not consider in the detection")
parser.add_argument("--ignored_ips", nargs="?", action="append", default=[], help="List of ips or subnets to not consider in the detection")
parser.add_argument("--allowed_countries", nargs="?", action="append", default=[], help="List of countries from which the logins are always allowed")
parser.add_argument("--vip_users", nargs="?", action="append", default=[], help="List of users to which pay particular attention")
parser.add_argument("--ignored_users", nargs="?", default=[], help="List of users to filter and to not consider in the detection")
parser.add_argument("--ignored_ips", nargs="?", default=[], help="List of ips or subnets to not consider in the detection")
parser.add_argument("--allowed_countries", nargs="?", default=[], help="List of countries from which the logins are always allowed")
parser.add_argument("--vip_users", nargs="?", default=[], help="List of users to which pay particular attention")

def handle(self, *args, **options):
"""Setup the configurations into the Config model"""
logger = logging.getLogger()
print(options)

if Config.objects.all().exists():
config_obj = Config.objects.all()[0]
else:
config_obj = Config.objects.create()
if not options["ignored_users"] and not options["ignored_ips"] and not options["allowed_countries"] and not options["vip_users"]:
# Setup default configs
Config.objects.update_or_create(ignored_users=IGNORED_USERS, ignored_ips=IGNORED_IPS)
# Set default values
config_obj.ignored_users = IGNORED_USERS
config_obj.ignored_ips = IGNORED_IPS
else:
if not Config.objects.exists():
Config.objects.create(
ignored_users=options["ignored_users"],
ignored_ips=options["ignored_ips"],
allowed_countries=options["allowed_countries"],
vip_users=["vip_users"],
)
self.stdout.write(
self.style.SUCCESS(
f"Configs set correctly:\
\nIgnored users: {options['ignored_users']}\
\nIgnored ips: {options['ignored_ips']}\
\nAllowed countries: {options['allowed_countries']}\
\nVip users: {options['vip_users']}"
)
)
else:
self.stdout.write(self.style.ERROR("Error: Configs already exist. Use the update_config or the clear_models commands"))
for opt in options:
if opt in ["ignored_users", "ignored_ips", "allowed_countries", "vip_users"]:
if not options[opt]:
setattr(config_obj, opt, [])
else:
setattr(config_obj, opt, options[opt].split(","))

config_obj.save()

# if Config.objects.all().exists():
# config_obj = Config.objects.all()[0]
# if not options["ignored_users"] and not options["ignored_ips"] and not options["allowed_countries"] and not options["vip_users"]:
# # Set default values
# config_obj.ignored_users = IGNORED_USERS
# config_obj.ignored_ips = IGNORED_IPS
# else:
# for opt in options:
# if options[opt] and type(options[opt]) is str:
# try:
# setattr(config_obj, opt, options[opt].split(','))
# except AttributeError:
# pass

# else:
# if not options["ignored_users"] and not options["ignored_ips"] and not options["allowed_countries"] and not options["vip_users"]:
# config_obj = Config.objects.create(ignored_users=IGNORED_USERS, ignored_ips=IGNORED_IPS)
# else:
# config_obj = Config.objects.create()
# for opt in options:
# if options[opt] and type(options[opt]) is str:
# try:
# setattr(config_obj, opt, options[opt].split(','))
# except AttributeError:
# pass
# config_obj.save()

logger.info(
f"Updated Config values - Ignored users: {config_obj.ignored_users}, Ignored IPs: {config_obj.ignored_ips}, Allowed countries: {config_obj.allowed_countries}, Vip users: {config_obj.vip_users}"
)
39 changes: 0 additions & 39 deletions buffalogs/impossible_travel/management/commands/update_config.py

This file was deleted.

1 change: 0 additions & 1 deletion buffalogs/impossible_travel/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ li a:link{
}
.sidebar-header::before{
content:"";
background-image: url("../images/header_backg.jpg");
opacity: 0.8;
position: absolute;
background-size: 100% 100%;
Expand Down
Binary file not shown.
Binary file added docs/static/cover_buffalogs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.