Skip to content

Commit

Permalink
Django rest framework (#42)
Browse files Browse the repository at this point in the history
* Update CHANGELOG.md

* Updated requirements.txt

* Updated CHANGELOG.md

* Added APIs urls

* Countries list refactoring

* Added APIs

* Fixed alerts_line_chart_api for months

* Added tests for the APIs

* Fixed world_map_chart_api

* Added test for the world_map API

* Added http method required GET

* Removed unused imports

* Added query parameters

* Fixed views tests

* Updated README.md

* Updated CHANGELOG.md

---------

Co-authored-by: Federico <[email protected]>
  • Loading branch information
Lorygold and ManofWax committed Jun 26, 2023
1 parent a4d3a78 commit c8cfd3b
Show file tree
Hide file tree
Showing 11 changed files with 516 additions and 196 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# 1.0.0 (2023-05-25)
To learn about the release highlights, please check out the [v1.0.0 release announcement]()
## 1.1.x
### 1.1.0
#### Features
* Implemented REST APIs for charts data in order to support the new interface integration

# 1.0.0 (2023-06-16)
To learn about the release highlights, please check out the [v1.0.0 release announcement]()
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In detail, it sends several types of alerts:

This alert is dispatched if the system is logged by a user from a country where they have never authenticated before.

*For futher details: [Wiki - About](https://github.com/certego/BuffaLogs/wiki/1.-About)*
*For further details: [Wiki - About](https://github.com/certego/BuffaLogs/wiki/1.-About)*

## BuffaLogs is participating in GSoC 2023 thanks to Honeynet project and IntelOwl!

Expand Down Expand Up @@ -83,7 +83,7 @@ After that, there are two ways of running BuffaLogs, depending on your system co

![buffalogs_dashboard_screenshot](https://user-images.githubusercontent.com/33703137/220879987-b6453e9d-0129-45c1-bc26-0542005e8730.png)

*For futher examples: [Wiki - Example](https://github.com/certego/BuffaLogs/wiki/2.-Example)*
*For further examples: [Wiki - Example](https://github.com/certego/BuffaLogs/wiki/2.-Example)*

## Logs Structure

Expand Down Expand Up @@ -112,7 +112,13 @@ For a basic analysis to detect only impossible travel logins, the *user_agent* f
## BuffaLogs Architecture
![Buffalogs_Architecture](https://user-images.githubusercontent.com/33703137/220896332-4fe08f32-1879-4150-bd5d-9df9dc21a7a7.jpg)

*For futher details: [Wiki - Architecture](https://github.com/certego/BuffaLogs/wiki/3.-Architecture)*
*For further details: [Wiki - Architecture](https://github.com/certego/BuffaLogs/wiki/3.-Architecture)*

## REST APIs

In order to obtain the charts data, you can query the REST APIs.

*For further details: [Wiki - REST APIs](https://github.com/certego/BuffaLogs/wiki/5.-REST-APIs)*

## Uninstall

Expand Down
3 changes: 3 additions & 0 deletions buffalogs/buffalogs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
path("users/<int:pk_user>/all_logins", views.all_logins, name="all_logins"),
path("users/<int:pk_user>/alerts/get_alerts", views.get_alerts, name="get_alerts"),
path("users/<int:pk_user>/alerts", views.alerts, name="alerts"),
path("users_pie_chart_api/", views.users_pie_chart_api, name="users_pie_chart_api"),
path("alerts_line_chart_api/", views.alerts_line_chart_api, name="alerts_line_chart_api"),
path("world_map_chart_api/", views.world_map_chart_api, name="world_map_chart_api"),
path("authentication/", include("authentication.urls")),
]
196 changes: 10 additions & 186 deletions buffalogs/impossible_travel/dashboard/charts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import os
from datetime import timedelta

import pygal
Expand All @@ -10,6 +12,13 @@
imp_travel = impossible_travel.Impossible_Travel()


def _load_data(name):
DATA_PATH = "impossible_travel/dashboard/"
with open(os.path.join(DATA_PATH, name + ".json")) as file:
data = json.load(file)
return data


def users_pie_chart(start, end):
custom_style = Style(
background="transparent",
Expand Down Expand Up @@ -121,192 +130,7 @@ def world_map_chart(start, end):
height=130,
show_legend=False,
)
countries = {
"ad": "Andorra",
"ae": "United Arab Emirates",
"af": "Afghanistan",
"al": "Albania",
"am": "Armenia",
"ao": "Angola",
"aq": "Antarctica",
"ar": "Argentina",
"at": "Austria",
"au": "Australia",
"az": "Azerbaijan",
"ba": "Bosnia and Herzegovina",
"bd": "Bangladesh",
"be": "Belgium",
"bf": "Burkina Faso",
"bg": "Bulgaria",
"bh": "Bahrain",
"bi": "Burundi",
"bj": "Benin",
"bn": "Brunei Darussalam",
"bo": "Bolivia, Plurinational State of",
"br": "Brazil",
"bt": "Bhutan",
"bw": "Botswana",
"by": "Belarus",
"bz": "Belize",
"ca": "Canada",
"cd": "Congo, the Democratic Republic of the",
"cf": "Central African Republic",
"cg": "Congo",
"ch": "Switzerland",
"ci": "Cote d'Ivoire",
"cl": "Chile",
"cm": "Cameroon",
"cn": "China",
"co": "Colombia",
"cr": "Costa Rica",
"cu": "Cuba",
"cv": "Cape Verde",
"cy": "Cyprus",
"cz": "Czech Republic",
"de": "Germany",
"dj": "Djibouti",
"dk": "Denmark",
"do": "Dominican Republic",
"dz": "Algeria",
"ec": "Ecuador",
"ee": "Estonia",
"eg": "Egypt",
"eh": "Western Sahara",
"er": "Eritrea",
"es": "Spain",
"et": "Ethiopia",
"fi": "Finland",
"fr": "France",
"ga": "Gabon",
"gb": "United Kingdom",
"ge": "Georgia",
"gf": "French Guiana",
"gh": "Ghana",
"gl": "Greenland",
"gm": "Gambia",
"gn": "Guinea",
"gq": "Equatorial Guinea",
"gr": "Greece",
"gt": "Guatemala",
"gu": "Guam",
"gw": "Guinea-Bissau",
"gy": "Guyana",
"hk": "Hong Kong",
"hn": "Honduras",
"hr": "Croatia",
"ht": "Haiti",
"hu": "Hungary",
"id": "Indonesia",
"ie": "Ireland",
"il": "Israel",
"in": "India",
"iq": "Iraq",
"ir": "Iran, Islamic Republic of",
"is": "Iceland",
"it": "Italy",
"jm": "Jamaica",
"jo": "Jordan",
"jp": "Japan",
"ke": "Kenya",
"kg": "Kyrgyzstan",
"kh": "Cambodia",
"kp": "Korea, Democratic People's Republic of",
"kr": "Korea, Republic of",
"kw": "Kuwait",
"kz": "Kazakhstan",
"la": "Lao People's Democratic Republic",
"lb": "Lebanon",
"li": "Liechtenstein",
"lk": "Sri Lanka",
"lr": "Liberia",
"ls": "Lesotho",
"lt": "Lithuania",
"lu": "Luxembourg",
"lv": "Latvia",
"ly": "Libyan Arab Jamahiriya",
"ma": "Morocco",
"mc": "Monaco",
"md": "Moldova, Republic of",
"me": "Montenegro",
"mg": "Madagascar",
"mk": "Macedonia, the former Yugoslav Republic of",
"ml": "Mali",
"mm": "Myanmar",
"mn": "Mongolia",
"mo": "Macao",
"mr": "Mauritania",
"mt": "Malta",
"mu": "Mauritius",
"mv": "Maldives",
"mw": "Malawi",
"mx": "Mexico",
"my": "Malaysia",
"mz": "Mozambique",
"na": "Namibia",
"ne": "Niger",
"ng": "Nigeria",
"ni": "Nicaragua",
"nl": "Netherlands",
"no": "Norway",
"np": "Nepal",
"nz": "New Zealand",
"om": "Oman",
"pa": "Panama",
"pe": "Peru",
"pg": "Papua New Guinea",
"ph": "Philippines",
"pk": "Pakistan",
"pl": "Poland",
"pr": "Puerto Rico",
"ps": "Palestine, State of",
"pt": "Portugal",
"py": "Paraguay",
"re": "Reunion",
"ro": "Romania",
"rs": "Serbia",
"ru": "Russian Federation",
"rw": "Rwanda",
"sa": "Saudi Arabia",
"sc": "Seychelles",
"sd": "Sudan",
"se": "Sweden",
"sg": "Singapore",
"sh": "Saint Helena, Ascension and Tristan da Cunha",
"si": "Slovenia",
"sk": "Slovakia",
"sl": "Sierra Leone",
"sm": "San Marino",
"sn": "Senegal",
"so": "Somalia",
"sr": "Suriname",
"st": "Sao Tome and Principe",
"sv": "El Salvador",
"sy": "Syrian Arab Republic",
"sz": "Swaziland",
"td": "Chad",
"tg": "Togo",
"th": "Thailand",
"tj": "Tajikistan",
"tl": "Timor-Leste",
"tm": "Turkmenistan",
"tn": "Tunisia",
"tr": "Turkey",
"tw": "Taiwan (Republic of China)",
"tz": "Tanzania, United Republic of",
"ua": "Ukraine",
"ug": "Uganda",
"us": "United States",
"uy": "Uruguay",
"uz": "Uzbekistan",
"va": "Holy See (Vatican City State)",
"ve": "Venezuela, Bolivarian Republic of",
"vn": "Viet Nam",
"ye": "Yemen",
"yt": "Mayotte",
"za": "South Africa",
"zm": "Zambia",
"zw": "Zimbabwe",
}
countries = _load_data("countries")
tmp = {}
for key, value in countries.items():
country_alerts = Alert.objects.filter(
Expand Down
Loading

0 comments on commit c8cfd3b

Please sign in to comment.