diff --git a/CHANGELOG.md b/CHANGELOG.md index 922446a..9b83cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index a6b58af..8f812c1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# BuffaLogs + +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: @@ -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/ diff --git a/buffalogs/impossible_travel/management/commands/setup_config.py b/buffalogs/impossible_travel/management/commands/setup_config.py index e47a588..ae013ab 100644 --- a/buffalogs/impossible_travel/management/commands/setup_config.py +++ b/buffalogs/impossible_travel/management/commands/setup_config.py @@ -5,42 +5,41 @@ 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() + + 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}" + ) diff --git a/buffalogs/impossible_travel/management/commands/update_config.py b/buffalogs/impossible_travel/management/commands/update_config.py deleted file mode 100644 index 8203004..0000000 --- a/buffalogs/impossible_travel/management/commands/update_config.py +++ /dev/null @@ -1,39 +0,0 @@ -import logging - -from django.core.management.base import BaseCommand -from impossible_travel.models import Config - -logger = logging.getLogger() - - -class Command(BaseCommand): - help = "Command to update configs in the Config model" - - def add_arguments(self, parser): - # Optional arguments - parser.add_argument("--overwrite", nargs="?", help="Option to overwrite (not append) the new elements to the targeted list") - parser.add_argument("--ignored_users", nargs="?", type=str, default="", help="List of users to update in the Config model") - parser.add_argument("--ignored_ips", nargs="?", type=str, default="", help="List of ips to update in the Config model") - parser.add_argument("--allowed_countries", nargs="?", type=str, default="", help="List of countries to update in the Config model") - parser.add_argument("--vip_users", nargs="?", type=str, default="", help="List of users to to update in the Config model") - - def handle(self, *args, **options): - """Update or overwrite the configurations into the Config model""" - logger = logging.getLogger() - print(options) - if not Config.objects.exists(): - self.stdout.write(self.style.ERROR("Error: There is no config to update")) - else: - config = Config.objects.all()[0] - for opt in options: - if options[opt]: - try: - self.stdout.write(f"Options:{options[opt]}") - if "overwrite" not in options: - getattr(config, opt).append(options[opt]) - else: - setattr(config, opt, options[opt].split()) - config.save() - self.stdout.write(self.style.SUCCESS(f"Correctly updated {opt} field. New entire value is: {getattr(config, opt)}")) - except AttributeError: - pass diff --git a/buffalogs/impossible_travel/static/css/base.css b/buffalogs/impossible_travel/static/css/base.css index 739578a..7834898 100644 --- a/buffalogs/impossible_travel/static/css/base.css +++ b/buffalogs/impossible_travel/static/css/base.css @@ -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%; diff --git a/buffalogs/impossible_travel/static/images/header_backg.jpg b/buffalogs/impossible_travel/static/images/header_backg.jpg deleted file mode 100644 index 2607b6d..0000000 Binary files a/buffalogs/impossible_travel/static/images/header_backg.jpg and /dev/null differ diff --git a/django-buffalogs/MANIFEST.in b/django-buffalogs/MANIFEST.in index 764945d..9a909a3 100644 --- a/django-buffalogs/MANIFEST.in +++ b/django-buffalogs/MANIFEST.in @@ -1,6 +1,7 @@ include LICENSE include README.rst +recursive-include docs/static * recursive-include impossible_travel/management * recursive-include impossible_travel/modules * recursive-exclude impossible_travel/dashboard * -recursive-exclude impossible_travel/tests * \ No newline at end of file +recursive-exclude impossible_travel/tests * diff --git a/django-buffalogs/README.rst b/django-buffalogs/README.rst index 3ab2de9..dbc34c0 100644 --- a/django-buffalogs/README.rst +++ b/django-buffalogs/README.rst @@ -2,6 +2,8 @@ BuffaLogs ========= +.. image:: docs/static/cover_buffalogs.png + BuffaLogs is a Django app whose main purpose is to detect anomaly logins. Detaild documentation is in the ``docs/`` directory. diff --git a/django-buffalogs/buffalogs.egg-info/PKG-INFO b/django-buffalogs/buffalogs.egg-info/PKG-INFO index 7057566..b28ac82 100644 --- a/django-buffalogs/buffalogs.egg-info/PKG-INFO +++ b/django-buffalogs/buffalogs.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: buffalogs -Version: 1.2.1 +Version: 1.2.2 Summary: A Django app to detect anomaly logins. Home-page: UNKNOWN Author: Lorena Goldoni @@ -18,6 +18,8 @@ License-File: LICENSE.txt BuffaLogs ========= +.. image:: docs/static/cover_buffalogs.png + BuffaLogs is a Django app whose main purpose is to detect anomaly logins. Detaild documentation is in the ``docs/`` directory. diff --git a/django-buffalogs/buffalogs.egg-info/SOURCES.txt b/django-buffalogs/buffalogs.egg-info/SOURCES.txt index c7f6e6c..e235210 100644 --- a/django-buffalogs/buffalogs.egg-info/SOURCES.txt +++ b/django-buffalogs/buffalogs.egg-info/SOURCES.txt @@ -4,11 +4,13 @@ README.rst pyproject.toml setup.cfg setup.py +../docs/static/cover_buffalogs.png buffalogs.egg-info/PKG-INFO buffalogs.egg-info/SOURCES.txt buffalogs.egg-info/dependency_links.txt buffalogs.egg-info/requires.txt buffalogs.egg-info/top_level.txt +docs/static/cover_buffalogs.png impossible_travel/__init__.py impossible_travel/admin.py impossible_travel/apps.py @@ -18,7 +20,7 @@ impossible_travel/views.py impossible_travel/management/commands/clear_models.py impossible_travel/management/commands/impossible_travel.py impossible_travel/management/commands/setup_config.py -impossible_travel/management/commands/update_config.py +impossible_travel/management/commands/__pycache__/setup_config.cpython-310.pyc impossible_travel/migrations/0001_initial.py impossible_travel/migrations/0002_alert_updated.py impossible_travel/migrations/0003_alter_alert_updated.py diff --git a/django-buffalogs/docs/static/cover_buffalogs.png b/django-buffalogs/docs/static/cover_buffalogs.png new file mode 100644 index 0000000..6710463 Binary files /dev/null and b/django-buffalogs/docs/static/cover_buffalogs.png differ diff --git a/django-buffalogs/setup.cfg b/django-buffalogs/setup.cfg index 999981b..5fc601a 100644 --- a/django-buffalogs/setup.cfg +++ b/django-buffalogs/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = buffalogs -version = 1.2.1 +version = 1.2.2 description = A Django app to detect anomaly logins. long_description = file: README.rst author = Lorena Goldoni diff --git a/docs/static/cover_buffalogs.png b/docs/static/cover_buffalogs.png new file mode 100644 index 0000000..6710463 Binary files /dev/null and b/docs/static/cover_buffalogs.png differ