From 2c2766fe6d404b63729d34874aa0b18a87dd7d43 Mon Sep 17 00:00:00 2001 From: Ken Raffenetti Date: Thu, 30 Nov 2006 20:13:52 +0000 Subject: tweaks for a more standard installation git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2554 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Hostbase/hostbase/models.py | 2 +- src/lib/Server/Hostbase/hostbase/views.py | 104 ++++++------- .../Hostbase/hostbase/webtemplates/edit.html | 169 +++++++++------------ .../Hostbase/hostbase/webtemplates/errors.html | 4 +- .../Hostbase/hostbase/webtemplates/host.html | 4 - src/lib/Server/Hostbase/nisauth.py | 2 +- src/lib/Server/Hostbase/settings.py | 10 +- src/lib/Server/Hostbase/urls.py | 12 +- 8 files changed, 128 insertions(+), 179 deletions(-) (limited to 'src/lib/Server/Hostbase') diff --git a/src/lib/Server/Hostbase/hostbase/models.py b/src/lib/Server/Hostbase/hostbase/models.py index 4c29c8178..dbb63cc3a 100644 --- a/src/lib/Server/Hostbase/hostbase/models.py +++ b/src/lib/Server/Hostbase/hostbase/models.py @@ -44,7 +44,7 @@ class Host(models.Model): security_class = models.CharField('class', maxlength=16) support = models.CharField(maxlength=8, choices=SUPPORT_CHOICES) csi = models.CharField(maxlength=32, blank=True) - printq = models.CharField(maxlength=32) + printq = models.CharField(maxlength=32, blank=True) outbound_smtp = models.BooleanField() primary_user = models.EmailField() administrator = models.EmailField(blank=True) diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py index 241c01296..35f1ede32 100644 --- a/src/lib/Server/Hostbase/hostbase/views.py +++ b/src/lib/Server/Hostbase/hostbase/views.py @@ -9,13 +9,13 @@ from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required from django.contrib.auth import logout -from Hostbase.hostbase.models import * +from Bcfg2.Server.Hostbase.hostbase.models import * from datetime import date from django.db import connection from django.shortcuts import render_to_response from django import forms -from Hostbase import settings, regex -import re +from Bcfg2.Server.Hostbase import settings, regex +import dns, re attribs = ['hostname', 'whatami', 'netgroup', 'security_class', 'support', 'csi', 'printq', 'primary_user', 'administrator', 'location', @@ -153,34 +153,26 @@ def fill(template, hostdata, dnsdata=False): return template def edit(request, host_id): - """Edit general host information - Data is validated before being committed to the database""" - # fix bug when ip address changes, update the dns info appropriately + """Edit general host information""" + manipulator = Host.ChangeManipulator(host_id) changename = False - if request.GET.has_key('sub'): + if request.method == 'POST': host = Host.objects.get(id=host_id) if request.POST['hostname'] != host.hostname: oldhostname = host.hostname.split(".")[0] - host.hostname = request.POST['hostname'] - host.save() changename = True interfaces = host.interface_set.all() - if not validate(request, False, host_id): - if (request.POST.has_key('outbound_smtp') - and not host.outbound_smtp or - not request.POST.has_key('outbound_smtp') - and host.outbound_smtp): - host.outbound_smtp = not host.outbound_smtp - # add validation for attribs here - # likely use a helper fucntion - for attrib in attribs: - if request.POST.has_key(attrib): - host.__dict__[attrib] = request.POST[attrib].lower() - if request.POST.has_key('comments'): - host.comments = request.POST['comments'] - if len(request.POST['expiration_date'].split("-")) == 3: - (year, month, day) = request.POST['expiration_date'].split("-") - host.expiration_date = date(int(year), int(month), int(day)) + new_data = request.POST.copy() + + errors = manipulator.get_validation_errors(new_data) + if not errors: + + # somehow keep track of multiple interface change manipulators + # as well as multiple ip chnage manipulators??? (add manipulators???) + # change to many-to-many?????? + + # dynamically look up mx records? + for inter in interfaces: changetype = False ips = IP.objects.filter(interface=inter.id) @@ -298,7 +290,7 @@ def edit(request, host_id): return HttpResponseRedirect('/hostbase/%s/' % host.id) else: return render_to_response('errors.html', - {'failures': validate(request, False, host_id), + {'failures': errors, 'logged_in': request.session.get('_auth_user_id', False)}) else: host = Host.objects.get(id=host_id) @@ -676,19 +668,19 @@ def validate(request, new=False, host_id=None): and regex.host.match(request.POST['hostname'])): failures.append('hostname') - if not regex.printq.match(request.POST['printq']) and request.POST['printq']: - failures.append('printq') +## if not regex.printq.match(request.POST['printq']) and request.POST['printq']: +## failures.append('printq') - if not regex.user.match(request.POST['primary_user']): - failures.append('primary_user') +## if not regex.user.match(request.POST['primary_user']): +## failures.append('primary_user') - if (not regex.user.match(request.POST['administrator']) - and request.POST['administrator']): - failures.append('administrator') +## if (not regex.user.match(request.POST['administrator']) +## and request.POST['administrator']): +## failures.append('administrator') - if not (request.POST['location'] - and regex.location.match(request.POST['location'])): - failures.append('location') +## if not (request.POST['location'] +## and regex.location.match(request.POST['location'])): +## failures.append('location') if new: if (not regex.macaddr.match(request.POST['mac_addr_new']) @@ -787,11 +779,12 @@ def zonenew(request): nsform = forms.FormWrapper(nsmanipulator, {}, {}) mxform = forms.FormWrapper(mxmanipulator, {}, {}) aform = forms.FormWrapper(addressmanipulator, {}, {}) - return render_to_response('zonenew.html', {'form': form, - 'nsform': nsform, - 'mxform': mxform, - 'aform': aform, - }) + context = {'form': form, + 'nsform': nsform, + 'mxform': mxform, + 'aform': aform, + } + return render_to_response('zonenew.html', context) def zoneedit(request, zone_id): manipulator = Zone.ChangeManipulator(zone_id) @@ -799,9 +792,11 @@ def zoneedit(request, zone_id): mxaddmanipulator = MX.AddManipulator() addressaddmanipulator = ZoneAddress.AddManipulator() zone = manipulator.original_object - nsmanipulators = [Nameserver.ChangeManipulator(ns.id) for ns in zone.nameservers.all()] + nsmanipulators = [Nameserver.ChangeManipulator(ns.id) + for ns in zone.nameservers.all()] mxmanipulators = [MX.ChangeManipulator(mx.id) for mx in zone.mxs.all()] - addressmanipulators = [ZoneAddress.ChangeManipulator(address.id) for address in zone.addresses.all()] + addressmanipulators = [ZoneAddress.ChangeManipulator(address.id) + for address in zone.addresses.all()] if request.method == 'POST': new_data = request.POST.copy() new_data['serial'] = str(zone.serial) @@ -820,16 +815,17 @@ def zoneedit(request, zone_id): nsforms = [forms.FormWrapper(nsm, nsm.flatten_data(), {}) for nsm in nsmanipulators] mxforms = [forms.FormWrapper(mxm, mxm.flatten_data(), {}) for mxm in mxmanipulators] aforms = [forms.FormWrapper(am, am.flatten_data(), {}) for am in addressmanipulators] - return render_to_response('zoneedit.html', {'form': form, - 'nsforms': nsforms, - 'mxforms': mxforms, - 'aforms': aforms, - 'nsadd': forms.FormWrapper(nsaddmanipulator, {}, {}), - 'mxadd': forms.FormWrapper(mxaddmanipulator, {}, {}), - 'addadd': forms.FormWrapper(addressaddmanipulator, {}, {}), - 'zone_id': zone_id, - 'zone': zone.zone - }) + context = {'form': form, + 'nsforms': nsforms, + 'mxforms': mxforms, + 'aforms': aforms, + 'nsadd': forms.FormWrapper(nsaddmanipulator, {}, {}), + 'mxadd': forms.FormWrapper(mxaddmanipulator, {}, {}), + 'addadd': forms.FormWrapper(addressaddmanipulator, {}, {}), + 'zone_id': zone_id, + 'zone': zone.zone + } + return render_to_response('zoneedit.html', context) def do_zone_add(manipulator, new_data): manipulator.do_html2python(new_data) @@ -857,7 +853,7 @@ def check_zone_errors(new_data): priorities = new_data.getlist('priority') count = 0 for mx in new_data.getlist('mx'): - errors.update(MX.AddManipulator().get_validation_errors({'mx':mx, 'priority':priorities[0]})) + errors.update(MX.AddManipulator().get_validation_errors({'mx':mx, 'priority':priorities[count]})) count += 1 return errors diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html index d3bb848ca..297a3860b 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html @@ -45,16 +45,12 @@ div#interface{ } -
+ +
- - - - - - - - - - - - - - - - - - - - + {% else %} - - {% endif %} - - - - - - - - + + {% endif %}
+ +
+ +
+ +
+ + YYYY-MM-DD
{% for interface in interfaces %} - - - + {% else %} - - {% endif %} - - + + {% endif %}
+ + + remove
{% for ip in interface.1 %} - - + + + remove
{% endfor %} -
hostname
whatami + +
+
netgroup +
+ -
class +
+
support +
+
csi
printq
outbound_smtp +
+ +
+ +
+ {% if host.outbound_smtp %} -
primary_user
administrator
location
expiration_date YYYY-MM-DD

Interface -

- {% for choice in interface.0.TYPE_CHOICES %} - {% ifequal interface.0.hdwr_type choice.0 %} - {{ choice.1 }} - {% else %} - {{ choice.1 }} - {% endifequal %} - {% endfor %} -
dhcp + +
+ {% if interface.0.dhcp %} -
mac_addr - remove -
ip_addr - - remove -
- - - - - - -
ip_addr
+ +
- Add a New IP Address - - - - + Add a New IP Address
{% endfor %} -
- - - - - - - + {% else %} - - {% endif %} - - - - -

Interface

+ + {{ choice.1 }} +
dhcp +
+ {% if host.dhcp %} -
mac_addr
ip_addr
+ + {% endif %}
+ +
+ +
-Add a New Interface +Add a New Interface
- - - - - - -
comments
+ +
edit detailed DNS information for this host
this host is @@ -217,7 +183,8 @@ this host is {% endfor %}
last update on {{ host.last }}
-

+ +

{% endblock %} diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html b/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html index 724bf9c34..46050d941 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html @@ -16,9 +16,9 @@ {% if failures %} There were errors in the following fields

-{% for failure in failures %} +{% for failure in failures.items %} -{{ failure }}
+{{ failure.0 }}: {{ failure.1|join:", " }}
{% endfor %} {% endif %} diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/host.html b/src/lib/Server/Hostbase/hostbase/webtemplates/host.html index 39cdc7ae4..75cac61db 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/host.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/host.html @@ -56,13 +56,9 @@ {% ifnotequal interface.0.hdwr_type 'no' %}
{{ interface.0.hdwr_type }} {% endifnotequal %} - dhcp {% if interface.0.dhcp %} - y mac_addr {{ interface.0.mac_addr }} - {% else %} - n {% endif %} {% for ip in interface.1 %} ip_addr diff --git a/src/lib/Server/Hostbase/nisauth.py b/src/lib/Server/Hostbase/nisauth.py index 9c68c44eb..9bce9511f 100644 --- a/src/lib/Server/Hostbase/nisauth.py +++ b/src/lib/Server/Hostbase/nisauth.py @@ -1,6 +1,6 @@ import os import crypt, nis -from Hostbase.settings import AUTHORIZED_GROUP +from Bcfg2.Server.Hostbase.settings import AUTHORIZED_GROUP """Checks with NIS to see if the current user is in the support group""" diff --git a/src/lib/Server/Hostbase/settings.py b/src/lib/Server/Hostbase/settings.py index de319ca0b..047b330b4 100644 --- a/src/lib/Server/Hostbase/settings.py +++ b/src/lib/Server/Hostbase/settings.py @@ -95,10 +95,10 @@ ROOT_URLCONF = 'Hostbase.urls' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates". # Always use forward slashes, even on Windows. - '/usr/lib/python2.3/site-packages/Hostbase/hostbase/webtemplates', - '/usr/lib/python2.4/site-packages/Hostbase/hostbase/webtemplates', - '/usr/lib/python2.3/site-packages/Hostbase/templates', - '/usr/lib/python2.4/site-packages/Hostbase/templates', + '/usr/lib/python2.3/site-packages/Bcfg2/Server/Hostbase/hostbase/webtemplates', + '/usr/lib/python2.4/site-packages/Bcfg2/Server/Hostbase/hostbase/webtemplates', + '/usr/lib/python2.3/site-packages/Bcfg2/Server/Hostbase/templates', + '/usr/lib/python2.4/site-packages/Bcfg2/Server/Hostbase/templates', ) @@ -108,7 +108,7 @@ INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', - 'Hostbase.hostbase', + 'Bcfg2.Server.Hostbase.hostbase', ) diff --git a/src/lib/Server/Hostbase/urls.py b/src/lib/Server/Hostbase/urls.py index e4ed42996..fe76ae7b2 100644 --- a/src/lib/Server/Hostbase/urls.py +++ b/src/lib/Server/Hostbase/urls.py @@ -1,7 +1,7 @@ import os from django.conf.urls.defaults import * -urlpatterns = patterns('Hostbase.hostbase.views', +urlpatterns = patterns('Bcfg2.Server.Hostbase.hostbase.views', (r'^admin/', include('django.contrib.admin.urls')), (r'^hostbase/$', 'search'), @@ -22,16 +22,6 @@ urlpatterns = patterns('Hostbase.hostbase.views', (r'^hostbase/zones/(?P\d+)/(?P\D+)/(?P\d+)/confirm', 'confirm'), ) -#fixme: this is a temp. kludge to handle static serving of css, img, js etc... -#a better solution is to use mod_python/apache directives for the static serving -os.environ['bcfg_media_root'] = '/usr/lib/python2.4/site-packages/Hostbase/media' - -urlpatterns += patterns('', - (r'^site_media/(.*)$', - 'django.views.static.serve', - {'document_root': os.environ['bcfg_media_root'], - 'show_indexes': True}), - ) urlpatterns += patterns('', (r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}), -- cgit v1.2.3-1-g7c22