Merge pull request #71 from altf4arnold/Atlas

[ADD] Module for Atlas
This commit is contained in:
Arnold Dechamps 2024-06-02 01:35:11 +02:00 committed by GitHub
commit 586c194c2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 177 additions and 4 deletions

0
atlas/__init__.py Normal file
View file

21
atlas/admin.py Normal file
View file

@ -0,0 +1,21 @@
from admin_extra_buttons.api import ExtraButtonsMixin, button
from admin_extra_buttons.utils import HttpResponseRedirectToReferrer
from django.contrib import admin
from .models import Atlas
import atlas.atlascreator as atlascreator
import threading
class atlas(ExtraButtonsMixin, admin.ModelAdmin):
list_display = ('unicodetld', 'stack', 'measurement', 'lastEdition')
@button(change_form=True, html_attrs={'style': 'background-color:#88FF88;color:black'})
def refresh(self, request):
self.message_user(request, 'refresh called')
t1 = threading.Thread(target=atlascreator.main())
t1.start()
# Optional: returns HttpResponse
return HttpResponseRedirectToReferrer(request)
admin.site.register(Atlas, atlas)

6
atlas/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class AtlasConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'atlas'

101
atlas/atlascreator.py Normal file
View file

@ -0,0 +1,101 @@
import requests
import config
from tldtester.models import TLD
from .models import Atlas
def webrequest(tld, stack):
description_string = ("DNS measurement for ." + tld + " in IPv" + str(stack))
url = "https://atlas.ripe.net/api/v2/measurements/"
api_key = config.ATLAS_API
headers = {
"Authorization": f"Key {api_key}",
"Content-Type": "application/json"
}
data = {
"definitions": [
{
"type": "dns",
"af": stack,
"resolve_on_probe": True,
"description": description_string,
"query_class": "IN",
"query_type": "SOA",
"use_macros": False,
"protocol": "UDP",
"udp_payload_size": 512,
"retry": 0,
"skip_dns_check": False,
"include_qbuf": False,
"include_abuf": True,
"prepend_probe_id": False,
"set_rd_bit": True,
"set_do_bit": False,
"set_cd_bit": False,
"timeout": 5000,
"use_probe_resolver": True,
"set_nsid_bit": True,
"query_argument": tld
}
],
"probes": [
{
"type": "msm",
"value": 69775666,
"requested": 624
}
],
"is_oneoff": True,
"bill_to": config.BILLING_RIPE
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 201:
data = (response.json())
measurement = data['measurements'][0]
else:
measurement = None
dbwriter(tld, stack, measurement)
def dbwriter(unicodetld, stack, measurement):
tld = Atlas.objects.filter(unicodetld=unicodetld)
tldstack = tld.filter(stack=stack)
if tldstack.exists():
primary_key = tldstack.values_list('pk', flat=True).first()
db = Atlas.objects.get(pk=primary_key)
else:
db = Atlas()
db.unicodetld = unicodetld
db.stack = stack
db.measurement = measurement
db.save()
tld = TLD.objects.filter(unicodetld=unicodetld)
if tld.exists():
primary_key = tld.values_list('pk', flat=True).first()
db = TLD.objects.get(pk=primary_key)
if stack == 4:
db.atlasv4 = measurement
db.save()
elif stack == 6:
db.atlasv6 = measurement
db.save()
else:
print("Unknown IP version")
def main():
unicodetlds = []
# This will get the TLD's in unicode format from the database and put them in the list
tlds = TLD.objects.all().order_by('tld')
for tld in tlds:
db = TLD.objects.get(tld=tld)
unicodetlds.append(db.unicodetld)
for tld in unicodetlds:
webrequest(tld, 4)
webrequest(tld, 6)
if __name__ == "__main__":
main()

View file

17
atlas/models.py Normal file
View file

@ -0,0 +1,17 @@
from django.db import models
class Atlas(models.Model):
STACK = ((0, "Unknown"), (4, "IPv4"), (6, "IPv6"))
unicodetld = models.CharField(max_length=100)
stack = models.IntegerField(default=0, choices=STACK)
measurement = models.IntegerField(default=0, blank=True, null=True)
lastEdition = models.DateTimeField(auto_now=True)
def __str__(self):
return self.unicodetld
class Meta:
indexes = [
models.Index(fields=['stack', 'unicodetld']),
]

3
atlas/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
atlas/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View file

@ -9,3 +9,7 @@ DBUSER = "tldtest"
DBPASSWORD = "clubmate2010"
CSRF_TRUSTED_ORIGINS = []
ATLAS_API = ""
BILLING_RIPE = ""

View file

@ -801,6 +801,10 @@ video {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.underline {
text-decoration-line: underline;
}
.shadow {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -801,6 +801,10 @@ video {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.underline {
text-decoration-line: underline;
}
.shadow {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);

View file

@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'admin_extra_buttons',
'tldtester.apps.TldtesterConfig',
'atlas.apps.AtlasConfig',
'tldtest',
'compressor',
'rest_framework',

View file

@ -6,13 +6,14 @@
<table class="table-auto border-separate border border-slate-500">
<thead>
<tr>
<th class="border border-slate-600">Top Level Domain</th>
<th class="border border-slate-600 text-l-blue-600">Total servers</th>
<th class="border border-slate-600">TLD</th>
<th class="border border-slate-600 text-l-blue-600"># Servers</th>
<th class="border border-slate-600 text-red-700">IPv4</th>
<th class="border border-slate-600 text-green-600">IPv6</th>
<th class="border border-slate-600">Strongest DNSSEC algo</th>
<th class="border border-slate-600"># DNSSEC keys</th>
<th class="border border-slate-600"># keys</th>
<th class="border border-slate-600">RDAP</th>
<th class="border border-slate-600">latency-map</th>
<th class="border border-slate-600">Organisation</th>
</tr>
</thead>
@ -31,6 +32,7 @@
{% else %}
<td class="border border-slate-700 text-red-700">{{ TLD.rdap }}</td>
{% endif %}
<td class="border border-slate-700"><a class="text-red-700 underline" href="https://atlas.ripe.net/measurementdetail/{{ TLD.atlasv4 }}" target="_blank">IPv4</a> <a class="text-green-600 underline" href="https://atlas.ripe.net/measurementdetail/{{ TLD.atlasv6 }}" target="_blank">IPv6</a></td>
<td class="border border-slate-700"><a href="{{ TLD.link }}"
class="font-medium text-blue-600 dark:text-blue-500 hover:underline"
target="_blank"

View file

@ -7,7 +7,7 @@ import threading
class tlds(ExtraButtonsMixin, admin.ModelAdmin):
list_display = ('tld', 'nsamount', 'v4nsamount', 'v6nsamount', 'dnssec', 'lastEdition')
list_display = ('tld', 'nsamount', 'v4nsamount', 'v6nsamount', 'dnssec', 'atlasv4', 'atlasv6', 'lastEdition')
@button(change_form=True, html_attrs={'style': 'background-color:#88FF88;color:black'})
def refresh(self, request):

View file

@ -39,6 +39,8 @@ class TLD(models.Model):
organisation = models.CharField(max_length=100)
rdap = models.CharField(max_length=10, default="No")
link = models.CharField(max_length=800, default="https://tldtest.net/")
atlasv4 = models.IntegerField(default=0, blank=True, null=True)
atlasv6 = models.IntegerField(default=0, blank=True, null=True)
def __str__(self):
return self.tld