summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Hostbase/hostbase/views.py80
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/errors.html1
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/new.html2
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/results.html2
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/search.html7
-rw-r--r--src/lib/Server/Hostbase/urls.py1
-rw-r--r--src/lib/Server/Plugins/Hostbase.py1
7 files changed, 61 insertions, 33 deletions
diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py
index f26c4b891..c45f187d8 100644
--- a/src/lib/Server/Hostbase/hostbase/views.py
+++ b/src/lib/Server/Hostbase/hostbase/views.py
@@ -7,7 +7,6 @@ __revision__ = 0.1
from django.http import HttpResponse, HttpResponseRedirect
from hostbase.models import *
-from Cheetah.Template import Template
from datetime import date
from django.db import connection
from django.shortcuts import render_to_response
@@ -293,10 +292,8 @@ def edit(request, host_id):
host.save()
return HttpResponseRedirect('/hostbase/%s/' % host.id)
else:
- t = Template(open('errors.html').read())
- t.failures = validate(request, False, host_id)
- return HttpResponse(str(t))
- # examine the check boxes for any changes
+ return render_to_response('errors.html',
+ {'failures': validate(request, False, host_id)})
else:
host = Host.objects.get(id=host_id)
interfaces = []
@@ -476,27 +473,27 @@ def new(request):
new_ip = IP(interface=new_inter,
num=0, ip_addr=request.POST['ip_addr_new'])
new_ip.save()
+ mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ if created:
+ mx.save()
new_name = "-".join([host.hostname.split(".")[0],
new_ip.ip_addr.split(".")[2]])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name, dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
new_name = "-".join([host.hostname.split(".")[0],
new_inter.hdwr_type])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
name = Name(ip=new_ip, name=host.hostname,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
- if request.POST['ip_addr_new1'] and not request.POST['mac_addr_new1']:
+ name.mxs.add(mx)
+ if request.POST['ip_addr_new'] and not request.POST['mac_addr_new']:
new_inter = Interface(host=host,
mac_addr="",
hdwr_type=request.POST['hdwr_type_new1'])
@@ -504,27 +501,27 @@ def new(request):
new_ip = IP(interface=new_inter, num=0,
ip_addr=request.POST['ip_addr_new1'])
new_ip.save()
+ mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ if created:
+ mx.save()
new_name = "-".join([host.hostname.split(".")[0],
new_ip.ip_addr.split(".")[2]])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
new_name = "-".join([host.hostname.split(".")[0],
new_inter.hdwr_type])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
name = Name(ip=new_ip, name=host.hostname,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
if request.POST['mac_addr_new2']:
new_inter = Interface(host=host,
mac_addr=request.POST['mac_addr_new2'],
@@ -534,27 +531,27 @@ def new(request):
new_ip = IP(interface=new_inter, num=0,
ip_addr=request.POST['ip_addr_new2'])
new_ip.save()
+ mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ if created:
+ mx.save()
new_name = "-".join([host.hostname.split(".")[0],
new_ip.ip_addr.split(".")[2]])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
new_name = "-".join([host.hostname.split(".")[0],
new_inter.hdwr_type])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
name = Name(ip=new_ip, name=host.hostname,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
if request.POST['ip_addr_new2'] and not request.POST['mac_addr_new2']:
new_inter = Interface(host=host,
mac_addr="",
@@ -563,27 +560,27 @@ def new(request):
new_ip = IP(interface=new_inter, num=0,
ip_addr=request.POST['ip_addr_new2'])
new_ip.save()
+ mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ if created:
+ mx.save()
new_name = "-".join([host.hostname.split(".")[0],
new_ip.ip_addr.split(".")[2]])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
new_name = "-".join([host.hostname.split(".")[0],
new_inter.hdwr_type])
new_name += "." + host.hostname.split(".", 1)[1]
name = Name(ip=new_ip, name=new_name,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
name = Name(ip=new_ip, name=host.hostname,
dns_view='global', only=False)
name.save()
- mx = MX(name=name, priority=30, mx='mailgw.mcs.anl.gov')
- mx.save()
+ name.mxs.add(mx)
host.save()
return HttpResponseRedirect('/hostbase/%s/' % host.id)
else:
@@ -594,6 +591,27 @@ def new(request):
'SUPPORT_CHOICES': Host.SUPPORT_CHOICES,
'WHATAMI_CHOICES': Host.WHATAMI_CHOICES})
+def remove(request, host_id):
+ host = Host.objects.get(id=host_id)
+ if request.has_key('sub'):
+ 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})
+
def validate(request, new=False, host_id=None):
"""Function for checking form data"""
failures = []
@@ -638,7 +656,7 @@ def validate(request, new=False, host_id=None):
if ((request.POST['mac_addr_new'] or request.POST['ip_addr_new']) and
not request.has_key('hdwr_type_new')):
failures.append('hdwr_type (#1)')
- if ((request.POST['mac_addr_new2'] or request.POST['ip_addr_new']) and
+ if ((request.POST['mac_addr_new2'] or request.POST['ip_addr_new2']) and
not request.has_key('hdwr_type_new2')):
failures.append('hdwr_type (#2)')
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html b/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html
index 2d5e6fdf9..47d32ede4 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/errors.html
@@ -21,6 +21,7 @@ There were errors in the following fields<br><br>
{% endfor %}
{% endif %}
+<br>
Press the back button on your browser and edit those field(s)
{% endblock %} \ No newline at end of file
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
index 6a0f927fe..fd57e2c8e 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
@@ -9,7 +9,7 @@
{% block sidebar %}
<ul class="sidebar">
- <li><a href="/hostbase/" class="sidebar">search</a></li>
+ <li><a href="/hostbase/" class="sidebar">search hostbase</a></li>
</ul>
{% endblock %}
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/results.html b/src/lib/Server/Hostbase/hostbase/webtemplates/results.html
index 3db1a8c9b..f5e98c804 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/results.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/results.html
@@ -19,6 +19,7 @@
<col width="200">
<col width="75">
<col width="50">
+ <col width="50">
<col width="*">
<tr> <td><b>hostname</b></td>
<td> <b>status</b> </td>
@@ -32,6 +33,7 @@
{% endif %}
<td> <a href="{{ host.1 }}">view</a> </td>
<td> <a href="{{ host.1 }}/edit">edit</a> </td>
+ <td> <a href="{{ host.1 }}/remove">remove</a> </td>
</tr>
{% endfor %}
</table>
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/search.html b/src/lib/Server/Hostbase/hostbase/webtemplates/search.html
index 7fefdf6f9..4ac950ae0 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/search.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/search.html
@@ -3,11 +3,16 @@
{% block pagebanner %}
<div class="header">
<h2>Welcome to Hostbase!</h2>
+ <p>search for hosts using one or more of the fields below
</div>
<br/>
{% endblock %}
+
+{% block sidebar %}
+<a href="/hostbase/new" class="sidebar">add a new host</a>
+{% endblock %}
+
{% block content %}
-Find hosts using one or more of the searchable fields below.<br>
<!-- ...or go to <a href="hostinfo">this</a>
page to enter hostinfo-like queries<br><br> -->
<form name="input" action="?sub=true" method="post">
diff --git a/src/lib/Server/Hostbase/urls.py b/src/lib/Server/Hostbase/urls.py
index 9df252dd9..49c498297 100644
--- a/src/lib/Server/Hostbase/urls.py
+++ b/src/lib/Server/Hostbase/urls.py
@@ -9,6 +9,7 @@ urlpatterns = patterns('Hostbase.hostbase.views',
(r'^hostbase/$', 'search'),
(r'^hostbase/(?P<host_id>\d+)/$', 'look'),
(r'^hostbase/(?P<host_id>\d+)/edit', 'edit'),
+ (r'^hostbase/(?P<host_id>\d+)/remove', 'remove'),
(r'^hostbase/(?P<host_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/confirm', 'confirm'),
(r'^hostbase/(?P<host_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/(?P<name_id>\d+)/confirm', 'confirm'),
(r'^hostbase/(?P<host_id>\d+)/dns/edit', 'dnsedit'),
diff --git a/src/lib/Server/Plugins/Hostbase.py b/src/lib/Server/Plugins/Hostbase.py
index 0dc8bf65f..bc5468926 100644
--- a/src/lib/Server/Plugins/Hostbase.py
+++ b/src/lib/Server/Plugins/Hostbase.py
@@ -256,6 +256,7 @@ class Hostbase(Plugin):
self.buildHostsLPD()
self.buildPrinters()
self.buildNetgroups()
+ return True
def buildDHCP(self):
'''Pre-build dhcpd.conf and stash in the filedata table'''