Skip to content

Commit

Permalink
Merge pull request #1 from tldtest/sorter
Browse files Browse the repository at this point in the history
not yet working
  • Loading branch information
altf4arnold authored Feb 15, 2024
2 parents 963616f + cc621e2 commit 49c565a
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 3 deletions.
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ asgiref==3.7.2
build==1.0.3
click==8.1.7
Django==5.0.2
django-admin-extra-buttons==1.5.7
flake8==7.0.0
mccabe==0.7.0
packaging==23.2
Expand All @@ -10,3 +11,4 @@ pycodestyle==2.11.1
pyflakes==3.2.0
pyproject_hooks==1.0.0
sqlparse==0.4.4
zonefile-parser==0.1.14
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
Expand All @@ -18,6 +18,8 @@ click==8.1.7
# pip-tools
django==5.0.2
# via -r requirements.in
django-admin-extra-buttons==1.5.7
# via -r requirements.in
flake8==7.0.0
# via -r requirements.in
mccabe==0.7.0
Expand Down Expand Up @@ -48,6 +50,8 @@ sqlparse==0.4.4
# django
wheel==0.42.0
# via pip-tools
zonefile-parser==0.1.14
# via -r requirements.in

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
1 change: 1 addition & 0 deletions tldtest/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin_extra_buttons',
'tldtester',
]

Expand Down
16 changes: 16 additions & 0 deletions tldtester/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
from admin_extra_buttons.api import ExtraButtonsMixin, button
from admin_extra_buttons.utils import HttpResponseRedirectToReferrer
from django.contrib import admin
from .models import TLD
from .models import zonecontent
import tldtester.sorter as sorter


class tlds(admin.ModelAdmin):
list_display = ('tld', 'inet', 'dnssec', 'lastEdition')


class zone(ExtraButtonsMixin, admin.ModelAdmin):
list_display = ('name', 'rtype', 'rclass', 'ttl', 'data', 'lastEdition')

@button(change_form=True, html_attrs={'style': 'background-color:#88FF88;color:black'})
def refresh(self, request):
self.message_user(request, 'refresh called')
sorter.main()
# Optional: returns HttpResponse
return HttpResponseRedirectToReferrer(request)


admin.site.register(TLD, tlds)
admin.site.register(zonecontent, zone)
27 changes: 27 additions & 0 deletions tldtester/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 5.0.2 on 2024-02-12 16:08

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='TLD',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tld', models.CharField(max_length=30)),
('dnssec', models.IntegerField(choices=[(0, 'Delete DS'), (1, 'RSA/MD5'), (2, 'Diffie-Hellman'), (3, 'DSA/SHA1'), (5, 'RSA/SHA-1'), (6, 'DSA-NSEC3-SHA1'), (7, 'RSASHA1-NSEC3-SHA1'), (8, 'RSA/SHA-256'), (10, 'RSA/SHA-512'), (12, 'GOST R 34.10-2001'), (13, 'ECDSA Curve P-256 with SHA-256'), (14, 'ECDSA Curve P-384 with SHA-384'), (15, 'Ed25519'), (16, 'Ed448'), (17, 'SM2 signing algorithm with SM3 hashing algorithm'), (23, 'GOST R 34.10-2012'), (252, 'Reserved for Indirect Keys'), (253, 'private algorithm'), (254, 'private algorithm OID'), (300, 'Unknown')], default=300)),
('inet', models.IntegerField(choices=[(0, 'IPv4'), (1, 'IPv6'), (2, 'IPv4 + IPv6')], default=0)),
('lastEdition', models.DateTimeField(auto_now=True)),
],
options={
'indexes': [models.Index(fields=['tld'], name='tldtester_t_tld_b4cdc5_idx'), models.Index(fields=['dnssec'], name='tldtester_t_dnssec_694343_idx'), models.Index(fields=['inet'], name='tldtester_t_inet_b6132b_idx')],
},
),
]
24 changes: 24 additions & 0 deletions tldtester/migrations/0002_zonecontent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.2 on 2024-02-12 19:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tldtester', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='zonecontent',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rtype', models.CharField(max_length=10)),
('name', models.CharField(max_length=100)),
('rclass', models.CharField(max_length=10)),
('ttl', models.IntegerField(default=0)),
('data', models.CharField(max_length=1000)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.2 on 2024-02-12 19:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tldtester', '0002_zonecontent'),
]

operations = [
migrations.AddIndex(
model_name='zonecontent',
index=models.Index(fields=['name'], name='tldtester_z_name_83c518_idx'),
),
]
18 changes: 18 additions & 0 deletions tldtester/migrations/0004_zonecontent_lastedition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-02-12 19:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tldtester', '0003_zonecontent_tldtester_z_name_83c518_idx'),
]

operations = [
migrations.AddField(
model_name='zonecontent',
name='lastEdition',
field=models.DateTimeField(auto_now=True),
),
]
18 changes: 18 additions & 0 deletions tldtester/migrations/0005_alter_zonecontent_ttl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-02-12 20:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tldtester', '0004_zonecontent_lastedition'),
]

operations = [
migrations.AlterField(
model_name='zonecontent',
name='ttl',
field=models.CharField(max_length=5),
),
]
17 changes: 17 additions & 0 deletions tldtester/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,20 @@ class Meta:
models.Index(fields=["dnssec"]),
models.Index(fields=["inet"]),
]


class zonecontent(models.Model):
rtype = models.CharField(max_length=10)
name = models.CharField(max_length=100)
rclass = models.CharField(max_length=10)
ttl = models.CharField(max_length=5)
data = models.CharField(max_length=1000)
lastEdition = models.DateTimeField(auto_now=True)

def __str__(self):
return self.name

class Meta:
indexes = [
models.Index(fields=["name"]),
]
26 changes: 24 additions & 2 deletions tldtester/sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Link to IANA website : https://www.internic.net/domain/root.zone
"""
import urllib.request
import zonefile_parser
import json
from tldtester.models import zonecontent


def downloader():
Expand All @@ -22,13 +25,32 @@ def sorter(rawdata):
"""
This file removes the tabs and line breaks from rawdata
returns as a list with dictionary in it
:returns: a list of dictionaries
"""
print(str(rawdata))
encodeddata = zonefile_parser.parse(rawdata)
properdata = []
for line in encodeddata:
properdata.append(dict(json.loads(str(line).replace("'", '"'))))
return properdata


def dbwriter(data):
"""
Writes everything in the Zone database
"""
for line in data:
DB = zonecontent()
DB.rtype = line["rtype"]
DB.name = line["name"]
DB.rclass = line["rclass"]
DB.data = line["rdata"]
DB.ttl = int(line["ttl"])
DB.save()


def main():
try:
sorter(downloader())
dbwriter(sorter(downloader()))
except Exception as e:
print(e)

Expand Down

0 comments on commit 49c565a

Please sign in to comment.