diff options
Diffstat (limited to 'src/lib/Server/Hostbase/hostbase')
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/models.py | 7 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/urls.py | 64 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/views.py | 83 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/dns.html | 36 | ||||
-rw-r--r-- | src/lib/Server/Hostbase/hostbase/webtemplates/logviewer.html | 8 |
5 files changed, 84 insertions, 114 deletions
diff --git a/src/lib/Server/Hostbase/hostbase/models.py b/src/lib/Server/Hostbase/hostbase/models.py index 529f420d2..3d72138c4 100644 --- a/src/lib/Server/Hostbase/hostbase/models.py +++ b/src/lib/Server/Hostbase/hostbase/models.py @@ -62,6 +62,12 @@ class Host(models.Model): def __str__(self): return self.hostname + def get_logs(self): + """ + Get host's log. + """ + return Log.objects.filter(hostname=self.hostname) + class Interface(models.Model): TYPE_CHOICES = ( ('eth', 'ethernet'), ('wl', 'wireless'), ('virtual', 'virtual'), ('myr', 'myr'), @@ -187,6 +193,7 @@ class Zone(models.Model): pass class Log(models.Model): + # FIXME: Proposal hostname = models.ForeignKey(Host) hostname = models.CharField(max_length=64) date = models.DateTimeField(auto_now=True, auto_now_add=True) log = models.TextField() diff --git a/src/lib/Server/Hostbase/hostbase/urls.py b/src/lib/Server/Hostbase/hostbase/urls.py index 0e4588446..0ee204abe 100644 --- a/src/lib/Server/Hostbase/hostbase/urls.py +++ b/src/lib/Server/Hostbase/hostbase/urls.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- from django.conf.urls.defaults import * +from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse +from django.views.generic.create_update import create_object, update_object, delete_object +from django.views.generic.list_detail import object_detail, object_list -from models import Host, Zone +from models import Host, Zone, Log host_detail_dict = { 'queryset':Host.objects.all(), @@ -10,45 +13,56 @@ host_detail_dict = { 'template_object_name':'host', } +host_delete_dict = { + 'model':Host, + 'post_delete_redirect':'/', +} + +host_log_detail_dict = host_detail_dict.copy() +host_log_detail_dict['template_name'] = 'logviewer.html' + +host_dns_detail_dict = host_detail_dict.copy() +host_dns_detail_dict['template_name'] = 'dns.html' + zone_new_dict = { 'model':Zone, 'template_name':'zonenew.html', - 'post_save_redirect':'/hostbase/zones', + 'post_save_redirect':'../%(id)s', } + zones_list_dict = { 'queryset':Zone.objects.all(), 'template_name':'zones.html', 'template_object_name':'zone', } + zone_detail_dict = { 'queryset':Zone.objects.all(), 'template_name':'zoneview.html', 'template_object_name':'zone', } -urlpatterns = patterns('django.views.generic.list_detail', - (r'^(?P<object_id>\d+)/$', 'object_detail', host_detail_dict, 'host_detail'), - (r'^zones/$', 'object_list', zones_list_dict, 'zone_list'), - (r'^zones/(?P<object_id>\d+)/$', 'object_detail', zone_detail_dict, 'zone_detail'), -) - -urlpatterns += patterns('django.views.generic.create_update', - (r'^zones/new/$', 'create_object', zone_new_dict, 'zone_new'), - (r'^zones/(?P<object_id>\d+)/edit', 'update_object', zone_new_dict, 'zone_edit'), +urlpatterns = patterns('', + (r'^(?P<object_id>\d+)/$', object_detail, host_detail_dict, 'host_detail'), + (r'^zones/new/$', login_required(create_object), zone_new_dict, 'zone_new'), + (r'^zones/(?P<object_id>\d+)/edit', login_required(update_object), zone_new_dict, 'zone_edit'), + (r'^zones/$', object_list, zones_list_dict, 'zone_list'), + (r'^zones/(?P<object_id>\d+)/$', object_detail, zone_detail_dict, 'zone_detail'), + (r'^zones/(?P<object_id>\d+)/$', object_detail, zone_detail_dict, 'zone_detail'), + (r'^\d+/logs/(?P<object_id>\d+)/', object_detail, { 'queryset':Log.objects.all() }, 'log_detail'), + (r'^(?P<object_id>\d+)/logs/', object_detail, host_log_detail_dict, 'host_log_list'), + (r'^(?P<object_id>\d+)/dns', object_detail, host_dns_detail_dict, 'host_dns_list'), + (r'^(?P<object_id>\d+)/remove', login_required(delete_object), host_delete_dict, 'host_delete'), ) urlpatterns += patterns('Bcfg2.Server.Hostbase.hostbase.views', - (r'^$', 'search'), - (r'^(?P<host_id>\d+)/edit', 'edit'), - (r'^(?P<host_id>\d+)/remove', 'remove'), - (r'^(?P<host_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/confirm', 'confirm'), - (r'^(?P<host_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/(?P<name_id>\d+)/confirm', 'confirm'), - (r'^(?P<host_id>\d+)/dns/edit', 'dnsedit'), - (r'^(?P<host_id>\d+)/dns', 'dns'), - (r'^(?P<host_id>\d+)/logs/(?P<log_id>\d+)', 'printlog'), - (r'^(?P<host_id>\d+)/logs', 'logs'), - (r'^new', 'new'), - (r'^(?P<host_id>\d+)/copy', 'copy'), -# (r'^hostinfo', 'hostinfo'), - (r'^zones/(?P<zone_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/confirm', 'confirm'), - ) + (r'^$', 'search'), + (r'^(?P<host_id>\d+)/edit', 'edit'), + (r'^(?P<host_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/confirm', 'confirm'), + (r'^(?P<host_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/(?P<name_id>\d+)/confirm', 'confirm'), + (r'^(?P<host_id>\d+)/dns/edit', 'dnsedit'), + (r'^new', 'new'), + (r'^(?P<host_id>\d+)/copy', 'copy'), +# (r'^hostinfo', 'hostinfo'), + (r'^zones/(?P<zone_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/confirm', 'confirm'), +) diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py index 075497174..9768c69c5 100644 --- a/src/lib/Server/Hostbase/hostbase/views.py +++ b/src/lib/Server/Hostbase/hostbase/views.py @@ -90,45 +90,6 @@ def search(request): 'logged_in': request.session.get('_auth_user_id', False)}, context_instance = RequestContext(request)) -def logs(request, host_id): - """Displays general host information""" - host = Host.objects.get(id=host_id) - logs = Log.objects.filter(hostname=host.hostname) - return render_to_response('logviewer.html', - {'hostname': host.hostname, - 'logs': logs, - 'logged_in': request.session.get('_auth_user_id', False)}, - context_instance = RequestContext(request)) - -def printlog(request, host_id, log_id): - """Displays general host information""" - log = Log.objects.get(id=log_id) - return render_to_response('log.html', - {'text': log.log, - 'logged_in': request.session.get('_auth_user_id', False)}, - context_instance = RequestContext(request)) - -def dns(request, host_id): - host = Host.objects.get(id=host_id) - ips = [] - info = [] - cnames = [] - mxs = [] - for interface in host.interface_set.all(): - ips.extend(interface.ip_set.all()) - for ip in ips: - info.append([ip, ip.name_set.all()]) - for name in ip.name_set.all(): - cnames.extend(name.cname_set.all()) - mxs.append((name.id, name.mxs.all())) - return render_to_response('dns.html', - {'host': host, - 'info': info, - 'cnames': cnames, - 'mxs': mxs, - 'logged_in': request.session.get('_auth_user_id', False)}, - context_instance = RequestContext(request)) - def gethostdata(host_id, dnsdata=False): """Grabs the necessary data about a host @@ -586,6 +547,8 @@ def new(request): new_inter.save() if request.POST['mac_addr_new'] and request.POST['ip_addr_new']: new_ip = IP(interface=new_inter, ip_addr=request.POST['ip_addr_new']) +# Change all this things. Use a "post_save" signal handler for model Host to create all sociate models +# and use a generi view. new_ip.save() mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX) if created: @@ -876,29 +839,19 @@ def copy(request, host_id): 'WHATAMI_CHOICES': Host.WHATAMI_CHOICES, 'logged_in': request.session.get('_auth_user_id', False)}, context_instance = RequestContext(request)) - -def remove(request, host_id): - host = Host.objects.get(id=host_id) - if 'sub' in request: - for interface in host.interface_set.all(): - for ip in interface.ip_set.all(): - for name in ip.name_set.all(): - name.cname_set.all().delete() - ip.name_set.all().delete() - interface.ip_set.all().delete() - interface.delete() - host.delete() - return HttpResponseRedirect('/hostbase/') - else: - """Displays general host information""" - interfaces = [] - for interface in host.interface_set.all(): - interfaces.append([interface, interface.ip_set.all()]) - return render_to_response('remove.html', - {'host': host, - 'interfaces': interfaces, - 'logged_in': request.session.get('_auth_user_id', False)}, - context_instance = RequestContext(request)) + +# FIXME: delete all this things in a signal handler "pre_delete" +#def remove(request, host_id): +# host = Host.objects.get(id=host_id) +# if 'sub' in request: +# for interface in host.interface_set.all(): +# for ip in interface.ip_set.all(): +# for name in ip.name_set.all(): +# name.cname_set.all().delete() +# ip.name_set.all().delete() +# interface.ip_set.all().delete() +# interface.delete() +# host.delete() def validate(request, new=False, host_id=None): """Function for checking form data""" @@ -936,10 +889,10 @@ def validate(request, new=False, host_id=None): and request.POST['mac_addr_new']): failures.append('mac_addr (#1)') if ((request.POST['mac_addr_new'] or request.POST['ip_addr_new']) and - not 'hdwr_type_new' in request): + not 'hdwr_type_new' in request.REQUEST): failures.append('hdwr_type (#1)') if ((request.POST['mac_addr_new2'] or request.POST['ip_addr_new2']) and - not 'hdwr_type_new2' in request): + not 'hdwr_type_new2' in request.REQUEST): failures.append('hdwr_type (#2)') if (not regex.macaddr.match(request.POST['mac_addr_new2']) @@ -1005,7 +958,7 @@ confirm = login_required(confirm) dnsedit = login_required(dnsedit) new = login_required(new) copy = login_required(copy) -remove = login_required(remove) +#remove = login_required(remove) #zoneedit = login_required(zoneedit) #zonenew = login_required(zonenew) diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/dns.html b/src/lib/Server/Hostbase/hostbase/webtemplates/dns.html index ab75dd956..87c858a85 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/dns.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/dns.html @@ -20,25 +20,21 @@ {% block content %} - {% for ip in info %} - <ul><li> <b>ip_addr:</b> {{ ip.0.ip_addr }}</li> - {% for name in ip.1 %} - <ul> <li><b>name:</b> {{ name.name }}</li> <ul> - {% for cname in cnames %} - {% ifequal cname.name_id name.id %} - <li> <b>cname:</b> {{ cname.cname }}</li> - {% endifequal %} - {% endfor %} - {% for mx in mxs %} - {% ifequal mx.0 name.id %} - {% for record in mx.1 %} - <li> <b>mx:</b> {{ record.priority }} {{ record.mx }}</li> - {% endfor %} - {% endifequal %} - {% endfor %} - </ul></ul> - {% endfor %} - </ul> - {% endfor %} +{% for interface in host.interface_set.all %} + {% for ip in interface.ip_set.all %} + <ul><li> <b>ip_addr:</b> {{ ip.ip_addr }}</li> + {% for name in ip.name_set.all %} + <ul> <li><b>name:</b> {{ name.name }}</li> <ul> + {% for cname in name.cname_set.all %} + <li> <b>cname:</b> {{ cname.cname }}</li> + {% endfor %} + {% for mx in name.mxs.all %} + <li> <b>mx:</b> {{ mx.priority }} {{ mx.mx }}</li> + {% endfor %} + </ul></ul> + {% endfor %} + </ul> + {% endfor %} +{% endfor %} {% endblock %} diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/logviewer.html b/src/lib/Server/Hostbase/hostbase/webtemplates/logviewer.html index 7f2b60b8c..8f614ef76 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/logviewer.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/logviewer.html @@ -14,14 +14,14 @@ {% block content %} -{% if logs %} +{% if host.get_logs %} <ul> -{% for log in logs %} -<li><a href="{{ log.id }}">{{ log.date }}</li> +{% for log in host.get_logs %} +<li><a href="{{ log.id }}/">{{ log.date }}</li> {% endfor %} </ul> {% else %} There are no logs for this host<br> {% endif %} -{% endblock %}
\ No newline at end of file +{% endblock %} |