From 5252d230ff6b00196dc0ab0baad71e55429edf14 Mon Sep 17 00:00:00 2001 From: kjg Date: Thu, 30 Jul 2020 15:18:08 +0900 Subject: [PATCH] [Django #9] Starting with the ULA registry --- kjg/IPv6/.gitignore | 3 + kjg/IPv6/ula/manage.py | 21 +++ kjg/IPv6/ula/ula/__init__.py | 0 kjg/IPv6/ula/ula/asgi.py | 16 +++ kjg/IPv6/ula/ula/settings.py | 125 ++++++++++++++++++ kjg/IPv6/ula/ula/urls.py | 27 ++++ kjg/IPv6/ula/ula/wsgi.py | 16 +++ kjg/IPv6/ula/ularegistry/__init__.py | 0 kjg/IPv6/ula/ularegistry/admin.py | 3 + kjg/IPv6/ula/ularegistry/apps.py | 5 + kjg/IPv6/ula/ularegistry/forms.py | 6 + .../ularegistry/migrations/0001_initial.py | 22 +++ .../ula/ularegistry/migrations/__init__.py | 0 kjg/IPv6/ula/ularegistry/models.py | 13 ++ kjg/IPv6/ula/ularegistry/templates/index.html | 14 ++ kjg/IPv6/ula/ularegistry/tests.py | 3 + kjg/IPv6/ula/ularegistry/urls.py | 8 ++ kjg/IPv6/ula/ularegistry/views.py | 31 +++++ 18 files changed, 313 insertions(+) create mode 100644 kjg/IPv6/.gitignore create mode 100755 kjg/IPv6/ula/manage.py create mode 100644 kjg/IPv6/ula/ula/__init__.py create mode 100644 kjg/IPv6/ula/ula/asgi.py create mode 100644 kjg/IPv6/ula/ula/settings.py create mode 100644 kjg/IPv6/ula/ula/urls.py create mode 100644 kjg/IPv6/ula/ula/wsgi.py create mode 100644 kjg/IPv6/ula/ularegistry/__init__.py create mode 100644 kjg/IPv6/ula/ularegistry/admin.py create mode 100644 kjg/IPv6/ula/ularegistry/apps.py create mode 100644 kjg/IPv6/ula/ularegistry/forms.py create mode 100644 kjg/IPv6/ula/ularegistry/migrations/0001_initial.py create mode 100644 kjg/IPv6/ula/ularegistry/migrations/__init__.py create mode 100644 kjg/IPv6/ula/ularegistry/models.py create mode 100644 kjg/IPv6/ula/ularegistry/templates/index.html create mode 100644 kjg/IPv6/ula/ularegistry/tests.py create mode 100644 kjg/IPv6/ula/ularegistry/urls.py create mode 100644 kjg/IPv6/ula/ularegistry/views.py diff --git a/kjg/IPv6/.gitignore b/kjg/IPv6/.gitignore new file mode 100644 index 0000000..2a14529 --- /dev/null +++ b/kjg/IPv6/.gitignore @@ -0,0 +1,3 @@ +venv/ +*.pyc +db.* \ No newline at end of file diff --git a/kjg/IPv6/ula/manage.py b/kjg/IPv6/ula/manage.py new file mode 100755 index 0000000..2cef8fc --- /dev/null +++ b/kjg/IPv6/ula/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ula.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/kjg/IPv6/ula/ula/__init__.py b/kjg/IPv6/ula/ula/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kjg/IPv6/ula/ula/asgi.py b/kjg/IPv6/ula/ula/asgi.py new file mode 100644 index 0000000..bba5789 --- /dev/null +++ b/kjg/IPv6/ula/ula/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for ula project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ula.settings') + +application = get_asgi_application() diff --git a/kjg/IPv6/ula/ula/settings.py b/kjg/IPv6/ula/ula/settings.py new file mode 100644 index 0000000..fd9826f --- /dev/null +++ b/kjg/IPv6/ula/ula/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for ula project. + +Generated by 'django-admin startproject' using Django 3.0.8. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'fj+%jfo4xd5rb(7w!7feda03q)y4md)*)e_rjw8i_gyab!6#-h' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ["192.168.0.12",] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'ularegistry', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'ula.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'ula.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'kjg', + 'USER': 'kjg', + 'PASSWORD': 'kjg#test', + 'HOST': 'localhost', + 'PORT': '', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/kjg/IPv6/ula/ula/urls.py b/kjg/IPv6/ula/ula/urls.py new file mode 100644 index 0000000..2268978 --- /dev/null +++ b/kjg/IPv6/ula/ula/urls.py @@ -0,0 +1,27 @@ +"""ula URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + + +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('ularegistry/', include('ularegistry.urls')), + path('admin/', admin.site.urls), +] + diff --git a/kjg/IPv6/ula/ula/wsgi.py b/kjg/IPv6/ula/ula/wsgi.py new file mode 100644 index 0000000..44854f1 --- /dev/null +++ b/kjg/IPv6/ula/ula/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for ula project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ula.settings') + +application = get_wsgi_application() diff --git a/kjg/IPv6/ula/ularegistry/__init__.py b/kjg/IPv6/ula/ularegistry/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kjg/IPv6/ula/ularegistry/admin.py b/kjg/IPv6/ula/ularegistry/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/kjg/IPv6/ula/ularegistry/apps.py b/kjg/IPv6/ula/ularegistry/apps.py new file mode 100644 index 0000000..c19dcc7 --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UlaregistryConfig(AppConfig): + name = 'ularegistry' diff --git a/kjg/IPv6/ula/ularegistry/forms.py b/kjg/IPv6/ula/ularegistry/forms.py new file mode 100644 index 0000000..e166b86 --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/forms.py @@ -0,0 +1,6 @@ +from django import forms +from netfields import CidrAddressField, NetManager + +class ip(forms.Form): + inputIP = forms.CharField() + #inputIP = CidrAddressField() diff --git a/kjg/IPv6/ula/ularegistry/migrations/0001_initial.py b/kjg/IPv6/ula/ularegistry/migrations/0001_initial.py new file mode 100644 index 0000000..9df6f8a --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/migrations/0001_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 3.0.8 on 2020-07-29 13:34 + +from django.db import migrations, models +import netfields.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='IPs', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('inet', netfields.fields.CidrAddressField(max_length=43)), + ], + ), + ] diff --git a/kjg/IPv6/ula/ularegistry/migrations/__init__.py b/kjg/IPv6/ula/ularegistry/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kjg/IPv6/ula/ularegistry/models.py b/kjg/IPv6/ula/ularegistry/models.py new file mode 100644 index 0000000..9e47b7c --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/models.py @@ -0,0 +1,13 @@ +from django.db import models +from netfields import CidrAddressField, NetManager + + +# Create your models here. +class ips(models.Model): + inet = CidrAddressField() + objects = NetManager() + def __str__(self): + st = str(self.inet) + return st + + diff --git a/kjg/IPv6/ula/ularegistry/templates/index.html b/kjg/IPv6/ula/ularegistry/templates/index.html new file mode 100644 index 0000000..0c6df4a --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/templates/index.html @@ -0,0 +1,14 @@ +
+ {% csrf_token %} + {{ form }} + +
+{% if ips_list %} + +{% else %} +

No polls are available.

+{% endif %} diff --git a/kjg/IPv6/ula/ularegistry/tests.py b/kjg/IPv6/ula/ularegistry/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/kjg/IPv6/ula/ularegistry/urls.py b/kjg/IPv6/ula/ularegistry/urls.py new file mode 100644 index 0000000..1abf425 --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('/results/', views.results, name='results'), +] diff --git a/kjg/IPv6/ula/ularegistry/views.py b/kjg/IPv6/ula/ularegistry/views.py new file mode 100644 index 0000000..619e369 --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/views.py @@ -0,0 +1,31 @@ +from django.shortcuts import render +from django.http import HttpResponse +from .forms import ip +#from .forms import PostForm +from ularegistry.models import ips +from django.shortcuts import redirect + +# Create your views here. +def index(request): + if request.method == "POST": + form = ip(request.POST) + print(form) + if form.is_valid(): + q = ips(inet=form.cleaned_data['inputIP']) + q.save() + return redirect('index') + + else: + form = ip() + + ips_list = ips.objects.all() + ctx = { 'form' : form, + 'ips_list' : ips_list, + } + return render(request, 'index.html', ctx) + #return HttpResponse("Hello, world.") + + +def results(request, ips_id): + return HttpResponse(ips_id) +