aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--portal-gui/rpki/__init__.py0
-rw-r--r--portal-gui/rpki/manage.py11
-rw-r--r--portal-gui/rpki/myrpki/__init__.py0
-rw-r--r--portal-gui/rpki/myrpki/forms.py8
-rw-r--r--portal-gui/rpki/myrpki/models.py68
-rw-r--r--portal-gui/rpki/myrpki/views.py56
-rw-r--r--portal-gui/rpki/settings-old.py81
-rw-r--r--portal-gui/rpki/settings.py80
-rw-r--r--portal-gui/rpki/templates/base.html21
-rw-r--r--portal-gui/rpki/urls.py16
10 files changed, 341 insertions, 0 deletions
diff --git a/portal-gui/rpki/__init__.py b/portal-gui/rpki/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/portal-gui/rpki/__init__.py
diff --git a/portal-gui/rpki/manage.py b/portal-gui/rpki/manage.py
new file mode 100644
index 00000000..5e78ea97
--- /dev/null
+++ b/portal-gui/rpki/manage.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
diff --git a/portal-gui/rpki/myrpki/__init__.py b/portal-gui/rpki/myrpki/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/portal-gui/rpki/myrpki/__init__.py
diff --git a/portal-gui/rpki/myrpki/forms.py b/portal-gui/rpki/myrpki/forms.py
new file mode 100644
index 00000000..fda6faaa
--- /dev/null
+++ b/portal-gui/rpki/myrpki/forms.py
@@ -0,0 +1,8 @@
+from django import forms
+from myrpki import models
+
+# TODO: Point the cert.conf to the handle from the session
+class CertForm( forms.ModelForm ):
+ class Meta:
+ model = models.Cert
+
diff --git a/portal-gui/rpki/myrpki/models.py b/portal-gui/rpki/myrpki/models.py
new file mode 100644
index 00000000..3a923ab3
--- /dev/null
+++ b/portal-gui/rpki/myrpki/models.py
@@ -0,0 +1,68 @@
+from django.db import models
+from django.contrib.auth.models import Group
+
+# TO DO:
+# URL: text?
+class HandleField( models.CharField ):
+ def __init__( self, **kwargs ):
+ models.CharField.__init__( self, max_length=255, **kwargs )
+
+class IPAddressField( models.CharField ):
+ def __init__( self, **kwargs ):
+ models.CharField.__init__( self, max_length=40, **kwargs )
+
+class Cert( models.Model ):
+ conf = models.ForeignKey( 'Conf' )
+ name = models.CharField( unique=True, max_length=255 )
+ data = models.TextField()
+ def __unicode__( self ):
+ return self.name
+
+class Conf( models.Model ):
+ handle = HandleField( unique=True, db_index=True )
+ repository_bpki_cert = models.ForeignKey( Cert,
+ related_name='conf_bpki_cert' )
+ my_bpki_ta = models.ForeignKey( Cert, related_name='conf_my_ta' )
+ repository_handle = HandleField()
+ owner = models.OneToOneField( Group )
+
+class Child( models.Model ):
+ conf = models.ForeignKey( Conf )
+ handle = HandleField()
+ validity = models.DateTimeField()
+ bpki_cert = models.ForeignKey( Cert )
+
+class Prefix( models.Model ):
+ child = models.ForeignKey( Child )
+ lo = IPAddressField()
+ hi = IPAddressField()
+
+class Asn( models.Model ):
+ child = models.ForeignKey( Child )
+ min = models.IntegerField()
+ max = models.IntegerField()
+
+class Parent( models.Model ):
+ conf = models.ForeignKey( Conf )
+ handle = HandleField( unique=True )
+ service_uri = models.URLField( verify_exists=False )
+ cms_bpki_cert = models.ForeignKey( Cert, related_name='parent_cms' )
+ https_bpki_cert = models.ForeignKey( Cert, related_name='parent_https' )
+ my_handle = HandleField()
+ sia_base = models.URLField( verify_exists=False )
+
+# This table is really owned by the publication server.
+#class PubClient( models.Model ):
+# handle = models.CharField( unique=True, max_length=255 )
+# bpki_cert = models.ForeignKey( Cert )
+# sia_base = models.URLField( verify_exists=False )
+
+class Roa( models.Model ):
+ conf = models.ForeignKey( Conf )
+ prefix = IPAddressField()
+ len = models.IntegerField()
+ max_len = models.IntegerField()
+ asn = models.IntegerField()
+ active = models.BooleanField()
+ comments = models.TextField()
+ group = models.CharField( max_length=40 )
diff --git a/portal-gui/rpki/myrpki/views.py b/portal-gui/rpki/myrpki/views.py
new file mode 100644
index 00000000..cd24ff73
--- /dev/null
+++ b/portal-gui/rpki/myrpki/views.py
@@ -0,0 +1,56 @@
+from django.views.generic.create_update import create_object, update_object,
+ delete_object
+from django.views.generic.list_detail import object_detail
+from django.contrib.auth.decorators import login_required
+from django.shortcuts import get_object_or_404, render_to_response
+import models
+import forms
+
+
+# For each type of object, we have a detail view, a create view and
+# an update view. We heavily leverage the generic views, only
+# adding our own idea of authorization.
+
+def handle( request ):
+ '''If the session has a handle, return the config. If the user only has
+ one config that he can access, return that one; else return None.'''
+ if 'handle' in request.session:
+ return Conf.objects.get( handle=request.session[ 'handle' ] )
+ conf = Conf.objects.all().filter( owner__in=request.user.groups )
+ if conf.count() == 1:
+ return conf[ 0 ]
+ return None
+
+def choose_handle( request ):
+ '''The logged-in user can access multiple (or no) handles.
+ Ask them to pick which one(s) they want to access.'''
+ raise NotImplementedError
+
+@login_required
+def dashboard( request ):
+ '''The user's dashboard. If the handle is not specified,
+ see what the user has access to based on his groups. If
+ multiple, give him a selector and store the result in the
+ session.'''
+ handle = handle( request )
+ if handle is None:
+ return choose_handle( request )
+ # ... pick out data for the dashboard and return it
+ return render_to_response( 'myrpki/dashboard.html', context={ 'conf': handle } )
+
+@login_required
+def cert_add( request ):
+ return create_object( request, form_class=forms.CertForm )
+
+@login_required
+def cert_edit( request, id ):
+ cert = get_object_or_404( models.Cert, pk=id )
+ # make sure it is owned by the current handle
+ return update_object( request, form_class=forms.CertForm, object_id=id )
+
+@login_required
+def cert_delete( request, id ):
+ cert = get_object_or_404( models.Cert, pk=id )
+ # make sure it is owned by the current handle
+ return delete_object( request, model=models.Cert, object_id=id,
+ post_delete_redirect='/dashboard/' )
diff --git a/portal-gui/rpki/settings-old.py b/portal-gui/rpki/settings-old.py
new file mode 100644
index 00000000..f2ca2329
--- /dev/null
+++ b/portal-gui/rpki/settings-old.py
@@ -0,0 +1,81 @@
+# Django settings for rpki project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+DATABASE_NAME = '/tmp/fooop' # Or path to database file if using sqlite3.
+DATABASE_USER = '' # Not used with sqlite3.
+DATABASE_PASSWORD = '' # Not used with sqlite3.
+DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
+# although not all variations may be possible on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
+# http://blogs.law.harvard.edu/tech/stories/storyReader$15
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT.
+# Example: "http://media.lawrence.com"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '+g%0!&l$!)3y%a4fuwt)%(3l!0)tl#@k!h&_$n9(v^&2d&4$f3'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.load_template_source',
+ 'django.template.loaders.app_directories.load_template_source',
+# 'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.middleware.doc.XViewMiddleware',
+)
+
+ROOT_URLCONF = 'rpki.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'rpki.myrpki',
+)
diff --git a/portal-gui/rpki/settings.py b/portal-gui/rpki/settings.py
new file mode 100644
index 00000000..5488fd0c
--- /dev/null
+++ b/portal-gui/rpki/settings.py
@@ -0,0 +1,80 @@
+# Django settings for rpki project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = '/tmp/rpkiop' # Or path to database file if using sqlite3.
+DATABASE_USER = '' # Not used with sqlite3.
+DATABASE_PASSWORD = '' # Not used with sqlite3.
+DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://rpki.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '81d$t*$7hr!&*s6*-@)_b6@(*%3eo82zu342vssj6x4&_(m_+s'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.load_template_source',
+ 'django.template.loaders.app_directories.load_template_source',
+# 'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+ROOT_URLCONF = 'rpki.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'rpki.myrpki',
+)
diff --git a/portal-gui/rpki/templates/base.html b/portal-gui/rpki/templates/base.html
new file mode 100644
index 00000000..43def531
--- /dev/null
+++ b/portal-gui/rpki/templates/base.html
@@ -0,0 +1,21 @@
+<html>
+<head>
+ <title>{% block title %}MyRPKI{% endblock %}
+ {% block head %}{% endblock %}
+ <style type="text/css"><!--
+ {% block css %}{% endblock %}
+ // -->
+ </style>
+</head>
+<body>
+ <div id="content">
+ {% if user.is_authenticated %}
+ <span style="float: right; font-size: 80%;">Logged in as {{ user }} |
+ <a href="{% url django.contrib.auth.views.logout %}">Log Out</a></span>
+ {% else %}
+ <span style="float: right; font-size: 80%;"><a href="{% url django.contrib.auth.views.login %}">Log In</a></span>
+ {% endif %}
+ {% block content %}{% endblock %}
+ </div>
+</body>
+</html>
diff --git a/portal-gui/rpki/urls.py b/portal-gui/rpki/urls.py
new file mode 100644
index 00000000..51e6c0e9
--- /dev/null
+++ b/portal-gui/rpki/urls.py
@@ -0,0 +1,16 @@
+from django.conf.urls.defaults import *
+
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+ # Example:
+ # (r'^foo/', include('foo.foo.urls')),
+
+ # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
+ # to INSTALLED_APPS to enable admin documentation:
+ # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ # Uncomment the next line to enable the admin:
+ (r'^admin/', include(admin.site.urls)),
+)