diff options
author | Michael Elkins <melkins@tislabs.com> | 2011-10-12 13:49:56 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2011-10-12 13:49:56 +0000 |
commit | 1646f116ec8b6e9b4b28a83c08cddec398ac52db (patch) | |
tree | b3777fa7859e8ee6be52bfa31e32c1e29f2cfa16 /rpkid | |
parent | 000e3654220eafc6e8933b4740797e7cb2eb17d4 (diff) |
add support for oo setup via portal gui
svn path=/rpkid/rpki/gui/app/forms.py; revision=4033
Diffstat (limited to 'rpkid')
-rw-r--r-- | rpkid/rpki/gui/app/forms.py | 37 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/glue.py | 172 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/child_delete_form.html | 20 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/child_form.html | 2 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/child_view.html | 4 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/dashboard.html | 21 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/destroy_handle_form.html | 17 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/generic_result.html | 13 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/parent_form.html | 11 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/parent_view.html | 8 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/templates/rpkigui/update_bpki_form.html | 15 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/urls.py | 6 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/views.py | 169 |
13 files changed, 374 insertions, 121 deletions
diff --git a/rpkid/rpki/gui/app/forms.py b/rpkid/rpki/gui/app/forms.py index bb5b6da9..41e154e5 100644 --- a/rpkid/rpki/gui/app/forms.py +++ b/rpkid/rpki/gui/app/forms.py @@ -210,43 +210,25 @@ class ChildForm(forms.ModelForm): def ImportChildForm(parent_conf, *args, **kwargs): class wrapped(forms.Form): handle = forms.CharField(max_length=30, help_text="Child's RPKI handle") - - child = forms.ModelChoiceField(queryset=models.Conf.objects.all(), required=False, - help_text="import locally hosted child") - xml = forms.FileField(help_text="Child's identity.xml files", required=False) + xml = forms.FileField(help_text="Child's identity.xml file") def clean_handle(self): if parent_conf.children.filter(handle=self.cleaned_data['handle']): raise forms.ValidationError, "a child with that handle already exists" return self.cleaned_data['handle'] - def clean(self): - if ((self.cleaned_data.get('child') and self.cleaned_data.get('xml')) or - not (self.cleaned_data.get('child') or self.cleaned_data.get('xml'))): - raise forms.ValidationError, "specify either a locally hosted resource handle OR identity.xml file" - return self.cleaned_data - return wrapped(*args, **kwargs) def ImportParentForm(conf, *args, **kwargs): class wrapped(forms.Form): handle = forms.CharField(max_length=30, help_text="Parent's RPKI handle") - - parent = forms.ModelChoiceField(queryset=models.Conf.objects.all(), required=False, - help_text="import locally hosted parent") - xml = forms.FileField(help_text="Parent's identity.xml files", required=False) + xml = forms.FileField(help_text="XML response from parent", required=False) def clean_handle(self): if conf.parents.filter(handle=self.cleaned_data['handle']): raise forms.ValidationError, "a parent with that handle already exists" return self.cleaned_data['handle'] - def clean(self): - if ((self.cleaned_data.get('parent') and self.cleaned_data.get('xml')) or - not (self.cleaned_data.get('parent') or self.cleaned_data.get('xml'))): - raise forms.ValidationError, "specify either a locally hosted resource handle OR xml file" - return self.cleaned_data - return wrapped(*args, **kwargs) class ImportRepositoryForm(forms.Form): @@ -256,15 +238,12 @@ class ImportRepositoryForm(forms.Form): class ImportPubClientForm(forms.Form): xml = forms.FileField(help_text='xml file from publication client') -class InitializeForm(forms.Form): - """ - Stub form for initialize new resource handles. - """ - pass - def ChildWizardForm(parent, *args, **kwargs): class wrapped(forms.Form): handle = forms.CharField(max_length=30, help_text='handle for new child') + #create_user = forms.BooleanField(help_text='create a new user account for this handle?') + #password = forms.CharField(widget=forms.PasswordInput, help_text='password for new user', required=False) + #password2 = forms.CharField(widget=forms.PasswordInput, help_text='repeat password', required=False) def clean_handle(self): if parent.children.filter(handle=self.cleaned_data['handle']): @@ -273,4 +252,10 @@ def ChildWizardForm(parent, *args, **kwargs): return wrapped(*args, **kwargs) +class GenericConfirmationForm(forms.Form): + """ + stub form used for doing confirmations. + """ + pass + # vim:sw=4 ts=8 expandtab diff --git a/rpkid/rpki/gui/app/glue.py b/rpkid/rpki/gui/app/glue.py index c5990845..687af268 100644 --- a/rpkid/rpki/gui/app/glue.py +++ b/rpkid/rpki/gui/app/glue.py @@ -17,12 +17,13 @@ PERFORMANCE OF THIS SOFTWARE. from __future__ import with_statement -import os, os.path, csv, stat, sys +import os, os.path, csv, shutil, stat, sys from datetime import datetime, timedelta from django.db.models import F import rpki, rpki.async, rpki.http, rpki.x509, rpki.left_right, rpki.myrpki +import rpki.publication from rpki.gui.app import models, settings def confpath(*handle): @@ -93,6 +94,22 @@ def build_rpkid_caller(cfg, verbose=False): url = rpkid_base + "left-right", debug = verbose)) +def build_pubd_caller(cfg): + bpki_servers_dir = cfg.get("bpki_servers_directory") + if not bpki_servers_dir.startswith('/'): + bpki_servers_dir = confpath(cfg.get('handle'), bpki_servers_dir) + + bpki_servers = rpki.myrpki.CA(cfg.filename, bpki_servers_dir) + pubd_base = "http://%s:%s/" % (cfg.get("pubd_server_host"), cfg.get("pubd_server_port")) + + return rpki.async.sync_wrapper(rpki.http.caller( + proto = rpki.publication, + client_key = rpki.x509.RSA( PEM_file = bpki_servers.dir + "/irbe.key"), + client_cert = rpki.x509.X509(PEM_file = bpki_servers.dir + "/irbe.cer"), + server_ta = rpki.x509.X509(PEM_file = bpki_servers.cer), + server_cert = rpki.x509.X509(PEM_file = bpki_servers.dir + "/pubd.cer"), + url = pubd_base + "control")) + def ghostbuster_to_vcard(gbr): """ Convert a Ghostbuster object into a vCard object. @@ -204,7 +221,8 @@ def list_received_resources(log, conf): cfg = rpki.config.parser(confpath(rpki_conf.handle, 'rpki.conf'), 'myrpki') call_rpkid = build_rpkid_caller(cfg) pdus = call_rpkid(rpki.left_right.list_received_resources_elt.make_pdu(self_handle=conf.handle), - rpki.left_right.child_elt.make_pdu(action="list", self_handle=conf.handle)) + rpki.left_right.child_elt.make_pdu(action="list", self_handle=conf.handle), + rpki.left_right.parent_elt.make_pdu(action="list", self_handle=conf.handle)) for pdu in pdus: if isinstance(pdu, rpki.left_right.child_elt): @@ -218,6 +236,13 @@ def list_received_resources(log, conf): valid_until=valid_until) child.save() + elif isinstance(pdu, rpki.left_right.parent_elt): + # have we seen this parent before? + parent_set = conf.parents.filter(handle=pdu.parent_handle) + if not parent_set: + parent = models.Parent(conf=conf, handle=pdu.parent_handle) + parent.save() + elif isinstance(pdu, rpki.left_right.list_received_resources_elt): # have we seen this parent before? @@ -297,20 +322,19 @@ def config_from_template(dest, a): class Myrpki(rpki.myrpki.main): """ - wrapper around rpki.myrpki.main to force the config file to what i want. + wrapper around rpki.myrpki.main to force the config file to what i want, + and avoid cli arg parsing. """ - def __init__(self, cfg_file): - self.cfg_file = cfg_file - - # quack, quack (act like rpki.myrpki.main object) - rpki.myrpki.main.read_config(self) + def __init__(self, handle): + self.cfg_file = confpath(handle, 'rpki.conf') + self.read_config() def configure_daemons(log, conf, m): if conf.host: m.configure_resources_main() - h = Myrpki(confpath(host.handle, 'rpki.conf')) - m.do_configure_daemons(m.cfg.get('xml_filename')) + host = Myrpki(conf.host.handle) + host.do_configure_daemons(m.cfg.get('xml_filename')) else: m.do_configure_daemons('') @@ -350,7 +374,7 @@ def initialize_handle(log, handle, host, owner=None, commit=True): f.close() # load configuration for self - m = Myrpki(cfg_file) + m = Myrpki(conf.handle) m.do_initialize('') if commit: @@ -358,57 +382,119 @@ def initialize_handle(log, handle, host, owner=None, commit=True): configure_daemons(log, conf, m) configure_daemons(log, conf, m) - return conf + return conf, m -def import_child(log, conf, child_handle, xml_file, commit=True): +def import_child(log, conf, child_handle, xml_file): """ Import a child's identity.xml. """ - cfg_file = confpath(conf.handle, 'rpki.conf') - m = Myrpki(cfg_file) + m = Myrpki(conf.handle) m.do_configure_child(xml_file) + configure_daemons(log, conf, m) - if commit: - configure_daemons(log, conf, m) - -def import_parent(log, conf, parent_handle, xml_file, commit=True): - cfg_file = confpath(conf.handle, 'rpki.conf') - m = Myrpki(cfg_file) +def import_parent(log, conf, parent_handle, xml_file): + m = Myrpki(conf.handle) m.do_configure_parent(xml_file) + configure_daemons(log, conf, m) - if commit: - configure_daemons(log, conf, m) - -def import_pubclient(log, conf, xml_file, commit=True): - cfg_file = confpath(conf.handle, 'rpki.conf') - m = Myrpki(cfg_file) +def import_pubclient(log, conf, xml_file): + m = Myrpki(conf.handle) m.do_configure_publication_client(xml_file) + configure_daemons(log, conf, m) - if commit: - configure_daemons(log, conf, m) - -def import_repository(log, conf, xml_file, commit=True): - cfg_file = confpath(conf.handle, 'rpki.conf') - m = Myrpki(cfg_file) +def import_repository(log, conf, xml_file): + m = Myrpki(conf.handle) m.do_configure_repository(xml_file) - - if commit: - configure_daemons(log, conf, m) + configure_daemons(log, conf, m) def create_child(log, parent_conf, child_handle): """ implements the child create wizard to create a new locally hosted child """ + child_conf, child = initialize_handle(log, handle=child_handle, host=parent_conf, commit=False) + parent_handle = parent_conf.handle - child_conf = initialize_handle(log, handle=child_handle, host=parent_conf, commit=False) - import_child(log, parent_conf, child_handle, confpath(child_handle, 'entitydb', 'identity.xml'), commit=False) - import_parent(log, child_conf, parent_handle, confpath(parent_handle, 'entitydb', 'children', child_handle + '.xml'), commit=False) + parent = Myrpki(parent_handle) + + child_identity_xml = os.path.join(child.cfg.get("entitydb_dir"), 'identity.xml') + parent_response_xml = os.path.join(parent.cfg.get("entitydb_dir"), 'children', child_handle + '.xml') + repo_req_xml = os.path.join(child.cfg.get('entitydb_dir'), 'repositories', parent_handle + '.xml') # XXX for now we assume the child is hosted by parent's pubd - import_pubclient(log, parent_conf, confpath(child_handle, 'entitydb', 'repositories', parent_handle + '.xml'), commit=False) - import_repository(log, child_conf, confpath(parent_handle, 'entitydb', 'pubclients', '%s.%s.xml' % (parent_handle, child_handle)), commit=False) + repo_resp_xml = os.path.join(parent.cfg.get('entitydb_dir'), 'pubclients', '%s.%s.xml' % (parent_handle, child_handle)) + + parent.do_configure_child(child_identity_xml) + + child.do_configure_parent(parent_response_xml) + + parent.do_configure_publication_client(repo_req_xml) + + child.do_configure_repository(repo_resp_xml) # run twice the first time to get bsc cert issued - configure_daemons(log, child_conf) - configure_daemons(log, child_conf) + sys.stdout = sys.stderr + configure_daemons(log, child_conf, child) + configure_daemons(log, child_conf, child) + +def destroy_handle(log, handle): + conf = models.Conf.objects.get(handle=handle) + + cfg = rpki.config.parser(confpath(conf.host.handle, 'rpki.conf'), 'myrpki') + call_rpkid = build_rpkid_caller(cfg) + call_pubd = build_pubd_caller(cfg) + + # destroy the <self/> object and the <child/> object from the host/parent. + rpkid_reply = call_rpkid( + rpki.left_right.self_elt.make_pdu(action="destroy", self_handle=handle), + rpki.left_right.child_elt.make_pdu(action="destroy", self_handle=conf.host.handle, child_handle=handle)) + if isinstance(rpkid_reply[0], rpki.left_right.report_error_elt): + print >>log, "Error while calling pubd to delete client %s:" % handle + print >>log, rpkid_reply[0] + + pubd_reply = call_pubd(rpki.publication.client_elt.make_pdu(action="destroy", client_handle=handle)) + if isinstance(pubd_reply[0], rpki.publication.report_error_elt): + print >>log, "Error while calling pubd to delete client %s:" % handle + print >>log, pubd_reply[0] + + conf.delete() + + shutil.remove(confpath(handle)) + +def read_child_response(log, conf, child_handle): + m = Myrpki(conf.handle) + bname = child_handle + '.xml' + return open(os.path.join(m.cfg.get('entitydb_dir'), 'children', bname)).read() + +def read_child_repo_response(log, conf, child_handle): + """ + Return the XML file for the configure_publication_client response to the + child. + + Note: the current model assumes the publication client is a child of this + handle. + """ + + m = Myrpki(conf.handle) + return open(os.path.join(m.cfg.get('entitydb_dir'), 'pubclients', '%s.%s.xml' % (conf.handle, child_handle))).read() + +def update_bpki(log, conf): + m = Myrpki(conf.handle) + + # automatically runs configure_daemons when self-hosted + # otherwise runs configure_resources + m.do_update_bpki('') + + # when hosted, ship off to rpkid host + if conf.host: + configure_daemons(log, conf, m) + +def delete_child(log, conf, child_handle): + m = Myrpki(conf.handle) + m.do_delete_child(child_handle) + configure_daemons(log, conf, m) + +def delete_parent(log, conf, parent_handle): + m = Myrpki(conf.handle) + m.do_delete_parent(parent_handle) + configure_daemons(log, conf, m) # vim:sw=4 ts=8 expandtab diff --git a/rpkid/rpki/gui/app/templates/rpkigui/child_delete_form.html b/rpkid/rpki/gui/app/templates/rpkigui/child_delete_form.html new file mode 100644 index 00000000..22c40a60 --- /dev/null +++ b/rpkid/rpki/gui/app/templates/rpkigui/child_delete_form.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block content %} + +<p id='breadcrumb'> +<a href="{% url rpki.gui.app.views.dashboard %}">{{ request.session.handle.handle }}</a> > +<a href="{{ object.get_absolute_url }}">{{ object.handle }}</a> > Delete +</p> + +<h1>Delete Child</h1> + +<p><span style='font-weight:bold'>Child:</span> {{ object.handle }}</p> + +<form method='POST' action='{{ request.get_full_path }}'> + {% csrf_token %} + {{ form.as_p }} + <input type='submit'/ value='Delete'> +</form> + +{% endblock %} diff --git a/rpkid/rpki/gui/app/templates/rpkigui/child_form.html b/rpkid/rpki/gui/app/templates/rpkigui/child_form.html index 1737fc43..0e5a5ac2 100644 --- a/rpkid/rpki/gui/app/templates/rpkigui/child_form.html +++ b/rpkid/rpki/gui/app/templates/rpkigui/child_form.html @@ -14,7 +14,7 @@ <form method='POST' action='{{ request.get_full_path }}'> {% csrf_token %} {{ form.as_p }} - <input type='submit'/> + <input type='submit'/ value='Save'> </form> {% endblock %} diff --git a/rpkid/rpki/gui/app/templates/rpkigui/child_view.html b/rpkid/rpki/gui/app/templates/rpkigui/child_view.html index f5b6afe9..474798ce 100644 --- a/rpkid/rpki/gui/app/templates/rpkigui/child_view.html +++ b/rpkid/rpki/gui/app/templates/rpkigui/child_view.html @@ -3,6 +3,10 @@ {% block sidebar %} <ul class='compact'> <li><a href="{{ child.get_absolute_url }}/edit">edit</a></li> + <li><a href="{{ child.get_absolute_url }}/export" title="download XML response file to return to child">export child response</a></li> + <li><a href="{{ child.get_absolute_url }}/export_repo" title="download XML response to publication client request">export repo response</a></li> + <li><a href="{{ child.get_absolute_url }}/delete" title="remove this handle as a RPKI child">delete</a></li> + <li><a href="{{ child.get_absolute_url }}/destroy" title="completely remove a locally hosted resource handle and gui account">destroy</a></li> </ul> {% endblock %} diff --git a/rpkid/rpki/gui/app/templates/rpkigui/dashboard.html b/rpkid/rpki/gui/app/templates/rpkigui/dashboard.html index bcb2d4fd..8a14a8ef 100644 --- a/rpkid/rpki/gui/app/templates/rpkigui/dashboard.html +++ b/rpkid/rpki/gui/app/templates/rpkigui/dashboard.html @@ -17,16 +17,23 @@ h2 { text-align:center; background-color:#dddddd } </ul> <ul class='compact'> - <li><a href="{% url rpki.gui.app.views.conf_export %}">export identity</a></li> - <li><a href="{% url rpki.gui.app.views.conf_list %}">select identity</a></li> + <li><a href="{% url rpki.gui.app.views.conf_export %}" title="download XML identity to send to parent">export identity</a></li> + <li><a href="{% url rpki.gui.app.views.update_bpki %}" title="renew all BPKI certificates">update bpki</a></li> + <li><a href="{% url rpki.gui.app.views.conf_list %}" title="select a different resource handle to manage">select identity</a></li> </ul> <ul class='compact'> - <li><a href="{% url rpki.gui.app.views.import_child %}">import child</a></li> - <li><a href="{% url rpki.gui.app.views.import_parent %}">import parent</a></li> - <li><a href="{% url rpki.gui.app.views.import_repository %}">import repository</a></li> - <li><a href="{% url rpki.gui.app.views.import_pubclient %}">import pubclient</a></li> - <li><a href="{% url rpki.gui.app.views.child_wizard %}">create child wizard</a></li> + <li><a href="{% url rpki.gui.app.views.child_wizard %}" title="create a new locally hosted resource handle">create child wizard</a></li> +</ul> + +<ul class='compact'> + <li><a href="{% url rpki.gui.app.views.import_parent %}" title="upload XML response from remote parent">import parent</a></li> + <li><a href="{% url rpki.gui.app.views.import_repository %}" title="upload XML response from remote repository">import repository</a></li> +</ul> + +<ul class='compact'> + <li><a href="{% url rpki.gui.app.views.import_child %}" title="import a new child's identity.xml file">import child</a></li> + <li><a href="{% url rpki.gui.app.views.import_pubclient %}" title="import XML request from a publication client">import pubclient</a></li> </ul> <ul class='compact'> diff --git a/rpkid/rpki/gui/app/templates/rpkigui/destroy_handle_form.html b/rpkid/rpki/gui/app/templates/rpkigui/destroy_handle_form.html new file mode 100644 index 00000000..e1e6711f --- /dev/null +++ b/rpkid/rpki/gui/app/templates/rpkigui/destroy_handle_form.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + +{% block content %} + +<h1>Destroy {{ handle }}?</h1> + +<p> +Please confirm that you wish to destroy this resource handle by clicking the Destroy button below. All configuration files and data associated with this handle will be permanently removed, and can not be undone. +</p> + +<form method="POST" action="{{ request.get_full_path }}"> + {% csrf_token %} + <input type="submit" value="Destroy"> +</form> + +{% endblock %} + diff --git a/rpkid/rpki/gui/app/templates/rpkigui/generic_result.html b/rpkid/rpki/gui/app/templates/rpkigui/generic_result.html new file mode 100644 index 00000000..65d4e42e --- /dev/null +++ b/rpkid/rpki/gui/app/templates/rpkigui/generic_result.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} + +{% block content %} + +<h1>{{ operation }} {{ result }}</h1> + +{% if reason %} +<p> +{{ reason }} +</p> +{% endif %} + +{% endblock %} diff --git a/rpkid/rpki/gui/app/templates/rpkigui/parent_form.html b/rpkid/rpki/gui/app/templates/rpkigui/parent_form.html new file mode 100644 index 00000000..4209c537 --- /dev/null +++ b/rpkid/rpki/gui/app/templates/rpkigui/parent_form.html @@ -0,0 +1,11 @@ +{% extends "rpkigui/parent_view.html" %} + +{% block form %} + +<form method="POST" action="{{ request.get_full_path }}"> +{% csrf_token %} +{{ form }} +<input type="submit" value="{{ submit_label }}"> +</form> + +{% endblock %} diff --git a/rpkid/rpki/gui/app/templates/rpkigui/parent_view.html b/rpkid/rpki/gui/app/templates/rpkigui/parent_view.html index 23509311..a57bd888 100644 --- a/rpkid/rpki/gui/app/templates/rpkigui/parent_view.html +++ b/rpkid/rpki/gui/app/templates/rpkigui/parent_view.html @@ -1,5 +1,11 @@ {% extends "base.html" %} +{% block sidebar %} +<ul class='compact'> + <li><a href="{{ parent.get_absolute_url }}/delete">delete</a></li> +</ul> +{% endblock %} + {% block content %} <p id='breadcrumb'> <a href="{% url rpki.gui.app.views.dashboard %}">{{ request.session.handle.handle }}</a> > Parent View > {{ parent.handle }} @@ -27,4 +33,6 @@ {% endfor %} </ul> +{% block form %}{% endblock %} + {% endblock %} diff --git a/rpkid/rpki/gui/app/templates/rpkigui/update_bpki_form.html b/rpkid/rpki/gui/app/templates/rpkigui/update_bpki_form.html new file mode 100644 index 00000000..b232c4e9 --- /dev/null +++ b/rpkid/rpki/gui/app/templates/rpkigui/update_bpki_form.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block content %} + +<p>Click the button to rewew your BPKI certificates.</p> + +<form method="POST" action="{{ request.get_full_path }}"> + {% csrf_token %} + <table> +{{ form.as_table }} +</table> +<input type="submit" value="Update"> +</form> + +{% endblock %} diff --git a/rpkid/rpki/gui/app/urls.py b/rpkid/rpki/gui/app/urls.py index dff8b69c..ae9352b1 100644 --- a/rpkid/rpki/gui/app/urls.py +++ b/rpkid/rpki/gui/app/urls.py @@ -24,8 +24,13 @@ urlpatterns = patterns('', (r'^conf/list$', views.conf_list), (r'^conf/select$', views.conf_select), (r'^parent/(?P<parent_handle>[^/]+)$', views.parent_view), + (r'^parent/(?P<parent_handle>[^/]+)/delete$', views.parent_delete), (r'^child/(?P<child_handle>[^/]+)$', views.child_view), + (r'^child/(?P<child_handle>[^/]+)/delete$', views.child_delete), (r'^child/(?P<child_handle>[^/]+)/edit$', views.child_edit), + (r'^child/(?P<child_handle>[^/]+)/export$', views.export_child_response), + (r'^child/(?P<child_handle>[^/]+)/export_repo$', views.export_child_repo_response), + (r'^child/(?P<handle>[^/]+)/destroy$', views.destroy_handle), (r'^address/(?P<pk>\d+)$', views.address_view), (r'^address/(?P<pk>\d+)/split$', views.prefix_split_view), (r'^address/(?P<pk>\d+)/allocate$', views.prefix_allocate_view), @@ -55,6 +60,7 @@ urlpatterns = patterns('', (r'^import_repository$', views.import_repository), # (r'^initialize$', views.initialize), (r'^child_wizard$', views.child_wizard), + (r'^update_bpki', views.update_bpki), ) # vim:sw=4 ts=8 expandtab diff --git a/rpkid/rpki/gui/app/views.py b/rpkid/rpki/gui/app/views.py index 4b175ee8..0fb34525 100644 --- a/rpkid/rpki/gui/app/views.py +++ b/rpkid/rpki/gui/app/views.py @@ -1,3 +1,4 @@ + # $Id$ """ Copyright (C) 2010, 2011 SPARTA, Inc. dba Cobham Analytic Solutions @@ -19,7 +20,7 @@ from __future__ import with_statement import email.message, email.utils, mailbox import os, os.path -import sys +import sys, tempfile from django.contrib.auth.decorators import login_required from django.contrib import auth @@ -651,25 +652,16 @@ def import_parent(request): if request.method == 'POST': form = forms.ImportParentForm(conf, request.POST, request.FILES) if form.is_valid(): - tmpf = None - - # determine if we are importing a locally hosted parent or an identity.xml file - if form.get('parent'): - # locally hosted - f = confdir(form['parent'].handle, 'entitydb', 'children', conf.handle + '.xml') - else: - # uploaded xml file - tmpf = NamedTemporaryFile(prefix='parent', suffix='xml', delete=False) - f = tmpf.name - tmpf.write(f.read()) - tmpf.close() + tmpf = tempfile.NamedTemporaryFile(prefix='parent', suffix='.xml', delete=False) + f = tmpf.name + tmpf.write(form.cleaned_data['xml'].read()) + tmpf.close() - obj = glue.import_parent(log, conf, form.get('handle'), f) + glue.import_parent(log, conf, form.cleaned_data['handle'], f) - if tmpf: - os.remove(tmpf.name) + os.remove(tmpf.name) - return http.HttpResponseRedirect(obj.get_absolute_url()) + return http.HttpResponseRedirect(reverse(dashboard)) else: form = forms.ImportParentForm(conf) @@ -683,17 +675,16 @@ def import_repository(request): if request.method == 'POST': form = forms.ImportRepositoryForm(request.POST, request.FILES) if form.is_valid(): - # uploaded xml file - tmpf = NamedTemporaryFile(prefix='repository', suffix='xml', delete=False) + tmpf = tempfile.NamedTemporaryFile(prefix='repository', suffix='.xml', delete=False) f = tmpf.name - tmpf.write(f.read()) + tmpf.write(form.cleaned_data['xml'].read()) tmpf.close() - obj = glue.import_repository(log, conf, f) + glue.import_repository(log, conf, f) os.remove(tmpf.name) - return http.HttpResponseRedirect(obj.get_absolute_url()) + return http.HttpResponseRedirect(reverse(dashboard)) else: form = forms.ImportRepositoryForm() @@ -707,17 +698,16 @@ def import_pubclient(request): if request.method == 'POST': form = forms.ImportPubClientForm(request.POST, request.FILES) if form.is_valid(): - # uploaded xml file - tmpf = NamedTemporaryFile(prefix='pubclient', suffix='xml', delete=False) + tmpf = tempfile.NamedTemporaryFile(prefix='pubclient', suffix='.xml', delete=False) f = tmpf.name - tmpf.write(f.read()) + tmpf.write(form.cleaned_data['xml'].read()) tmpf.close() - obj = glue.import_repository(log, conf, f) + glue.import_pubclient(log, conf, f) os.remove(tmpf.name) - return http.HttpResponseRedirect(obj.get_absolute_url()) + return http.HttpResponseRedirect(reverse(dashboard)) else: form = forms.ImportPubClientForm() @@ -730,28 +720,20 @@ def import_child(request): """ conf = request.session['handle'] log = request.META['wsgi.errors'] - tmpf = None if request.method == 'POST': form = forms.ImportChildForm(conf, request.POST, request.FILES) if form.is_valid(): - # determine if we are importing a locally hosted child or an identity.xml file - if form.get('child'): - # locally hosted - f = confdir(child.handle, 'entitydb', 'identity.xml') - else: - # identity.xml - tmpf = NamedTemporaryFile(prefix='identity', suffix='xml', delete=False) - f = tmpf.name - tmpf.write(f.read()) - tmpf.close() + tmpf = tempfile.NamedTemporaryFile(prefix='identity', suffix='.xml', delete=False) + f = tmpf.name + tmpf.write(form.cleaned_data['xml'].read()) + tmpf.close() - obj = glue.import_child(log, conf, form.cleaned_data['handle'], f) + glue.import_child(log, conf, form.cleaned_data['handle'], f) - if tmpf: - os.remove(tmpf.name) + os.remove(tmpf.name) - return http.HttpResponseRedirect(obj.get_absolute_url()) + return http.HttpResponseRedirect(reverse(dashboard)) else: form = forms.ImportChildForm(conf) @@ -763,12 +745,12 @@ def initialize(request): Initialize a new user account. """ if request.method == 'POST': - form = forms.InitializeForm(request.POST) + form = forms.GenericConfirmationForm(request.POST) if form.is_valid(): glue.initialize_handle(request.META['wsgi.errors'], handle=request.user.username, owner=request.user) return http.HttpResponseRedirect(reverse(dashboard)) else: - form = forms.InitializeForm() + form = forms.GenericConfirmationForm() return render('rpkigui/initialize_form.html', { 'form': form }, request) @@ -779,6 +761,9 @@ def child_wizard(request): """ conf = request.session['handle'] log = request.META['wsgi.errors'] + if not request.user.is_superuser: + return http.HttpResponseForbidden() + if request.method == 'POST': form = forms.ChildWizardForm(conf, request.POST) if form.is_valid(): @@ -789,4 +774,100 @@ def child_wizard(request): return render('rpkigui/child_wizard_form.html', { 'form': form }, request) +@handle_required +def export_child_response(request, child_handle): + """ + Export the XML file containing the output of the configure_child + to send back to the client. + """ + conf = request.session['handle'] + log = request.META['wsgi.errors'] + return serve_xml(glue.read_child_response(log, conf, child_handle), child_handle) + +@handle_required +def export_child_repo_response(request, child_handle): + """ + Export the XML file containing the output of the configure_child + to send back to the client. + """ + conf = request.session['handle'] + log = request.META['wsgi.errors'] + return serve_xml(glue.read_child_repo_response(log, conf, child_handle), child_handle) + +@handle_required +def update_bpki(request): + conf = request.session['handle'] + log = request.META['wsgi.errors'] + + if request.method == 'POST': + form = forms.GenericConfirmationForm(request.POST, request.FILES) + if form.is_valid(): + glue.update_bpki(log, conf) + return http.HttpResponseRedirect(reverse(dashboard)) + else: + form = forms.GenericConfirmationForm() + + return render('rpkigui/update_bpki_form.html', { 'form': form }, request) + +@handle_required +def child_delete(request, child_handle): + conf = request.session['handle'] + log = request.META['wsgi.errors'] + child = get_object_or_404(conf.children, handle__exact=child_handle) + + if request.method == 'POST': + form = forms.GenericConfirmationForm(request.POST, request.FILES) + if form.is_valid(): + glue.delete_child(log, conf, child_handle) + child.delete() + return http.HttpResponseRedirect(reverse(dashboard)) + else: + form = forms.GenericConfirmationForm() + + return render('rpkigui/child_delete_form.html', { 'form': form , 'object': child }, request) + +@handle_required +def parent_delete(request, parent_handle): + conf = request.session['handle'] + log = request.META['wsgi.errors'] + parent = get_object_or_404(conf.parents, handle__exact=parent_handle) + + if request.method == 'POST': + form = forms.GenericConfirmationForm(request.POST, request.FILES) + if form.is_valid(): + glue.delete_parent(log, conf, parent_handle) + parent.delete() + return http.HttpResponseRedirect(reverse(dashboard)) + else: + form = forms.GenericConfirmationForm() + + return render('rpkigui/parent_form.html', { 'form': form , + 'parent': parent, 'submit_label': 'Delete' }, request) + +@login_required +def destroy_handle(request, handle): + """ + Completely remove a hosted resource handle. + """ + + log = request.META['wsgi.errors'] + + if not request.user.is_superuser: + return http.HttpResponseForbidden() + + conf = get_object_or_404(models.Conf, handle=handle) + + if request.method == 'POST': + form = forms.GenericConfirmationForm(request.POST, request.FILES) + if form.is_valid(): + glue.destroy_handle(log, handle) + return render('rpkigui/generic_result.html', + { 'operation': 'Destroy ' + handle, + 'result': 'Succeeded' }, request) + else: + form = forms.GenericConfirmationForm() + + return render('rpkigui/destroy_handle_form.html', { 'form': form , + 'handle': handle }, request) + # vim:sw=4 ts=8 expandtab |