From d2407fc1c39c270dc2c2aa8d216706260ee2fe4d Mon Sep 17 00:00:00 2001 From: Ken Raffenetti Date: Thu, 7 Sep 2006 19:46:18 +0000 Subject: updated for use with apache git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2222 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Hostbase/hostbase/models.py | 19 ++++++++ src/lib/Server/Hostbase/hostbase/views.py | 50 +++++++++++++++++----- .../Hostbase/hostbase/webtemplates/edit.html | 18 ++++---- .../Hostbase/hostbase/webtemplates/host.html | 8 +++- .../Hostbase/hostbase/webtemplates/results.html | 2 +- 5 files changed, 75 insertions(+), 22 deletions(-) (limited to 'src/lib/Server') diff --git a/src/lib/Server/Hostbase/hostbase/models.py b/src/lib/Server/Hostbase/hostbase/models.py index 6253a7b50..92bbb4b00 100644 --- a/src/lib/Server/Hostbase/hostbase/models.py +++ b/src/lib/Server/Hostbase/hostbase/models.py @@ -19,6 +19,25 @@ class Host(models.Model): ('operations','operations'),('guest','guest'), ('confidential','confidential'),('public','public') ) + WHATAMI_CHOICES = ( + ('aix-3', 'aix-3'), ('aix-4', 'aix-4'), + ('aix-5', 'aix-5'), ('baytech', 'baytech'), + ('decserver', 'decserver'), ('dialup', 'dialup'), + ('dos', 'dos'), ('freebsd', 'freebsd'), + ('hpux', 'hpux'), ('irix-5', 'irix-5'), + ('irix-6', 'irix-6'), ('linux', 'linux'), + ('linux-2', 'linux-2'), ('linux-rh73', 'linux-rh73'), + ('linux-rh80', 'linux-rh80'), ('linux-sles80', 'linux-sles80'), + ('linux-sles80-64', 'linux-sles80-64'), ('linux-sles80-ia32', 'linux-sles80-ia32'), + ('linux-sles80-ia64', 'linux-sles80-ia64'), ('mac', 'mac'), + ('network', 'network'), ('next', 'next'), + ('none', 'none'), ('osf', 'osf'), ('printer', 'printer'), + ('robot', 'robot'), ('solaris-2', 'solaris-2'), + ('sun4', 'sun4'), ('unknown', 'unknown'), ('virtual', 'virtual'), + ('win31', 'win31'), ('win95', 'win95'), + ('winNTs', 'winNTs'), ('winNTw', 'winNTw'), + ('win2k', 'win2k'), ('winXP', 'winXP'), ('xterm', 'xterm') + ) hostname = models.CharField(maxlength=64) whatami = models.CharField(maxlength=16) netgroup = models.CharField(maxlength=32, choices=NETGROUP_CHOICES) diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py index 1077cbede..299cc5829 100644 --- a/src/lib/Server/Hostbase/hostbase/views.py +++ b/src/lib/Server/Hostbase/hostbase/views.py @@ -6,12 +6,14 @@ Also has does form validation __revision__ = 0.1 from django.http import HttpResponse, HttpResponseRedirect -from models import * +from hostbase.models import * from Cheetah.Template import Template from datetime import date from django.db import connection import re +templatedir = '/usr/lib/python2.3/site-packages/Hostbase/hostbase/webtemplates' + attribs = ['hostname', 'whatami', 'netgroup', 'security_class', 'support', 'csi', 'printq', 'primary_user', 'administrator', 'location', 'comments', 'status'] @@ -88,11 +90,11 @@ def search(request): cursor.execute(querystring) results = cursor.fetchall() - temp = Template(open('./hostbase/webtemplates/results.html').read()) + temp = Template(open('%s/results.html' % templatedir).read()) temp.hosts = results return HttpResponse(str(temp)) else: - temp = Template(open('./hostbase/webtemplates/search.html').read()) + temp = Template(open('%s/search.html' % templatedir).read()) temp.TYPE_CHOICES = Interface.TYPE_CHOICES temp.DNS_CHOICES = Name.DNS_CHOICES temp.yesno = [(1, 'yes'), (0, 'no')] @@ -100,13 +102,13 @@ def search(request): def look(request, host_id): """Displays general host information""" - temp = Template(open('./hostbase/webtemplates/host.html').read()) + temp = Template(open('%s/host.html' % templatedir).read()) hostdata = gethostdata(host_id) temp = fill(temp, hostdata) return HttpResponse(str(temp)) def dns(request, host_id): - temp = Template(open('./hostbase/webtemplates/dns.html').read()) + temp = Template(open('%s/dns.html' % templatedir).read()) hostdata = gethostdata(host_id, True) temp = fill(temp, hostdata, True) return HttpResponse(str(temp)) @@ -247,12 +249,12 @@ def edit(request, host_id): host.save() return HttpResponseRedirect('/hostbase/%s/' % host.id) else: - t = Template(open('./hostbase/webtemplates/errors.html').read()) + t = Template(open('%s/errors.html' % templatedir).read()) t.failures = validate(request, False, host_id) return HttpResponse(str(t)) # examine the check boxes for any changes else: - t = Template(open('./hostbase/webtemplates/edit.html').read()) + t = Template(open('%s/edit.html' % templatedir).read()) hostdata = gethostdata(host_id) t = fill(t, hostdata) t.type_choices = Interface.TYPE_CHOICES @@ -287,7 +289,7 @@ def confirm(request, item, item_id, host_id, name_id=None): else: return HttpResponseRedirect('/hostbase/%s/edit' % host_id) else: - temp = Template(open('./hostbase/webtemplates/confirm.html').read()) + temp = Template(open('%s/confirm.html' % templatedir).read()) interface = None ips = [] names = {} @@ -375,7 +377,7 @@ def dnsedit(request, host_id): name.mxs.add(mx) return HttpResponseRedirect('/hostbase/%s/dns' % host_id) else: - temp = Template(open('./hostbase/webtemplates/dnsedit.html').read()) + temp = Template(open('%s/dnsedit.html' % templatedir).read()) hostdata = gethostdata(host_id, True) temp = fill(temp, hostdata, True) temp.request = request @@ -430,7 +432,7 @@ def new(request): host.status = 'active' host.save() else: - temp = Template(open('./hostbase/webtemplates/errors.html').read()) + temp = Template(open('%s/errors.html' % templatedir).read()) temp.failures = validate(request, True) return HttpResponse(str(temp)) if request.POST['mac_addr_new']: @@ -553,7 +555,7 @@ def new(request): host.save() return HttpResponseRedirect('/hostbase/%s/' % host.id) else: - temp = Template(open('./hostbase/webtemplates/new.html').read()) + temp = Template(open('%s/new.html' % templatedir).read()) temp.TYPE_CHOICES = Interface.TYPE_CHOICES temp.NETGROUP_CHOICES = Host.NETGROUP_CHOICES temp.CLASS_CHOICES = Host.CLASS_CHOICES @@ -652,3 +654,29 @@ def validate(request, new=False, host_id=None): if not failures: return 0 return failures + +def push(request): + if request.GET.has_key('sub'): + # do xmlrpc function here + return HttpResponse("TBD") + else: + temp = Template(open('%s/push.html' % templatedir).read()) + temp.dirtyhosts = Host.objects.filter(dirty=True) + return HttpResponse(str(temp)) + +def zones(request): + zones = Zone.objects.all() + temp = Template(open('%s/zones.html' % templatedir).read()) + temp.zones = zones + return HttpResponse(str(temp)) + +def zoneview(request, zone_id): + zone = Zone.objects.get(id=zone_id) + temp = Template(open('%s/zoneview.html' % templatedir).read()) + temp.zone = zone + aux = zone.aux.split('\n') + temp.aux = aux + temp.nameservers = zone.nameservers.all() + temp.mxs = zone.mxs.all() + temp.addresses = zone.addresses.all() + return HttpResponse(str(temp)) diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html index 71ca621a1..571fa3f5d 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html @@ -101,13 +101,6 @@ function toggleInter(){ div#ipaddr${interface.id}{ display: none; } - #end for div#interface{ display: none; @@ -130,7 +123,16 @@ ok, submitted hostname whatami - + + netgroup