diff options
author | Ken Raffenetti <raffenet@mcs.anl.gov> | 2006-09-29 16:17:59 +0000 |
---|---|---|
committer | Ken Raffenetti <raffenet@mcs.anl.gov> | 2006-09-29 16:17:59 +0000 |
commit | 40625ce24d69afc3b06a510c4b96faf4483fad98 (patch) | |
tree | 919964b404688fcfd9d37e117e02a6c0d5edfa09 /src/lib | |
parent | 51a48233c0bf82e0b11d0a336d01a31dc2809f1c (diff) | |
download | bcfg2-40625ce24d69afc3b06a510c4b96faf4483fad98.tar.gz bcfg2-40625ce24d69afc3b06a510c4b96faf4483fad98.tar.bz2 bcfg2-40625ce24d69afc3b06a510c4b96faf4483fad98.zip |
added to zone file editing system
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2347 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
8 files changed, 153 insertions, 31 deletions
diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py index e9673e0a1..8da790d5f 100644 --- a/src/lib/Server/Hostbase/hostbase/views.py +++ b/src/lib/Server/Hostbase/hostbase/views.py @@ -307,7 +307,7 @@ def edit(request, host_id): 'interfaces': interfaces, 'TYPE_CHOICES': Interface.TYPE_CHOICES}) -def confirm(request, item, item_id, host_id, name_id=None): +def confirm(request, item, item_id, host_id=None, name_id=None, zone_id=None): """Asks if the user is sure he/she wants to remove an item""" if request.GET.has_key('sub'): if item == 'interface': @@ -330,8 +330,19 @@ def confirm(request, item, item_id, host_id, name_id=None): elif item=='name': Name.objects.get(id=item_id).cname_set.all().delete() Name.objects.get(id=item_id).delete() + elif item=='nameserver': + nameserver = Nameserver.objects.get(id=item_id) + Zone.objects.get(id=zone_id).nameservers.remove(nameserver) + elif item=='zonemx': + mx = MX.objects.get(id=item_id) + Zone.objects.get(id=zone_id).mxs.remove(mx) + elif item=='address': + address = ZoneAddress.objects.get(id=item_id) + Zone.objects.get(id=zone_id).addresses.remove(address) if item == 'cname' or item == 'mx' or item == 'name': - return HttpResponseRedirect('/hostbase/%s/dns' % host_id) + return HttpResponseRedirect('/hostbase/%s/dnsedit' % host_id) + elif item == 'nameserver' or item == 'zonemx' or item == 'address': + return HttpResponseRedirect('/hostbase/zones/%s/edit' % zone_id) else: return HttpResponseRedirect('/hostbase/%s/edit' % host_id) else: @@ -340,6 +351,9 @@ def confirm(request, item, item_id, host_id, name_id=None): names = [] cnames = [] mxs = [] + zonemx = None + nameserver = None + address = None if item == 'interface': interface = Interface.objects.get(id=item_id) ips = interface.ip_set.all() @@ -368,6 +382,12 @@ def confirm(request, item, item_id, host_id, name_id=None): cnames = [CName.objects.get(id=item_id)] elif item=='mx': mxs = [MX.objects.get(id=item_id)] + elif item=='zonemx': + zonemx = MX.objects.get(id=item_id) + elif item=='nameserver': + nameserver = Nameserver.objects.get(id=item_id) + elif item=='address': + address = ZoneAddress.objects.get(id=item_id) return render_to_response('confirm.html', {'interface': interface, 'ips': ips, @@ -376,7 +396,11 @@ def confirm(request, item, item_id, host_id, name_id=None): 'id': item_id, 'type': item, 'host_id': host_id, - 'mxs': mxs}) + 'mxs': mxs, + 'zonemx': zonemx, + 'nameserver': nameserver, + 'address': address, + 'zone_id': zone_id}) def dnsedit(request, host_id): """Edits specific DNS information @@ -424,7 +448,7 @@ def dnsedit(request, host_id): mx=request.POST['%smx' % ipaddrstr]) if created: mx.save() - name.mxs.add(mx) + name.mxs.add(mx) return HttpResponseRedirect('/hostbase/%s/dns' % host_id) else: host = Host.objects.get(id=host_id) @@ -603,7 +627,7 @@ def new(request): 'WHATAMI_CHOICES': Host.WHATAMI_CHOICES}) def remove(request, host_id): - host = Host.objects.get(id=host_id) + host = Host.GET.objects.get(id=host_id) if request.has_key('sub'): for interface in host.interface_set.all(): for ip in interface.ip_set.all(): @@ -613,7 +637,7 @@ def remove(request, host_id): interface.ip_set.all().delete() interface.delete() host.delete() - return HttpResponseRedirect('/hostbase/') + return HttpResponseRedirect('/hostbase/%s/' % host_id) else: """Displays general host information""" interfaces = [] @@ -730,27 +754,53 @@ def zoneview(request, zone_id): }) def zoneedit(request, zone_id): - if request.has_key('sub'): + if request.GET.has_key('sub'): zone = Zone.objects.get(id=zone_id) for attrib in zoneattribs: if request.POST.has_key(attrib): zone.__dict__[attrib] = request.POST[attrib] count = 0 -## for nameserver in zone.nameservers.all(): -## nameserver.name = request.POST['nameserver%i' % count] -## nameserver.save() -## count += 1 -## count = 0 -## for mx in zone.mxs.all(): -## mx.priority = request.POST['priority%i' % count] -## mx.mx = request.POST['mx%i' % count] -## mx.save() -## count += 1 -## count = 0 -## for address in zone.addresses.all(): -## address.ip_addr = request.POST['address%i' % count] -## count += 1 + for nameserver in zone.nameservers.all(): + ns, created = Nameserver.objects.get_or_create(name=request.POST['nameserver%i' % count]) + if created or not (nameserver == ns): + ns.save() + zone.nameservers.add(ns) + zone.nameservers.remove(nameserver) + count += 1 + count = 0 + for mx in zone.mxs.all(): + mrecord, created = MX.objects.get_or_create(priority=request.POST['priority%i' % count], + mx=request.POST['mx%i' % count]) + if created or not (mx == mrecord): + mrecord.save() + zone.mxs.add(mrecord) + zone.mxs.remove(mx) + count += 1 + count = 0 + for address in zone.addresses.all(): + arecord, created = ZoneAddress.objects.get_or_create(ip_addr=request.POST['address%i' % count]) + if created or not (arecord == address): + arecord.save() + zone.addresses.add(arecord) + zone.addresses.remove(address) + count += 1 zone.save() + if request.POST['new_nameserver']: + nameserver, created = Nameserver.objects.get_or_create(name=request.POST['new_nameserver']) + if created: + nameserver.save() + zone.nameservers.add(nameserver) + if request.POST['new_mx'] and request.POST['new_priority']: + mx, created = MX.objects.get_or_create(priority=request.POST['new_priority'], + mx=request.POST['new_mx']) + if created: + mx.save() + zone.mxs.add(mx) + if request.POST['new_address'] and not request.POST['new_address'] == 'none': + address, created = ZoneAddress.objects.get_or_create(ip_addr=request.POST['new_address']) + if created: + address.save() + zone.addresses.add(address) return HttpResponseRedirect('/hostbase/zones/%s/' % zone.id) else: zone = Zone.objects.get(id=zone_id) @@ -760,3 +810,43 @@ def zoneedit(request, zone_id): 'mxs': zone.mxs.all(), 'addresses': zone.addresses.all() }) + +def zonenew(request): + if request.GET.has_key('sub'): + try: + Zone.objects.get(zone=request.POST['zone']) + return render_to_response('errors.html', + {'failures': ['%s already exists in database' % request.POST['zone']]}) + except: + zone = Zone(zone=request.POST['zone']) + for attrib in zoneattribs: + if request.POST.has_key(attrib): + zone.__dict__[attrib] = request.POST[attrib] + zone.serial = 1 + zone.save() + for num in range(0,4): + if request.POST['nameserver%i' % num]: + ns, created = Nameserver.objects.get_or_create(name=request.POST['nameserver%i' % num]) + if created: + ns.save() + zone.nameservers.add(ns) + for num in range(0,2): + if request.POST['priority%i' % num] and request.POST['mx%i' % num]: + mrecord, created = MX.objects.get_or_create(priority=request.POST['priority%i' % num], + mx=request.POST['mx%i' % num]) + if created: + mrecord.save() + zone.mxs.add(mrecord) + for num in range(0,2): + if request.POST['address%i' % num]: + arecord, created = ZoneAddress.objects.get_or_create(ip_addr=request.POST['address%i' % num]) + if created: + arecord.save() + zone.addresses.add(arecord) + return HttpResponseRedirect('/hostbase/zones/%s/' % zone.id) + else: + return render_to_response('zonenew.html', + {'nameservers': range(0,4), + 'mxs': range(0,2), + 'addresses': range(0,2) + }) diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/confirm.html b/src/lib/Server/Hostbase/hostbase/webtemplates/confirm.html index c7761c3ea..f1f90939e 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/confirm.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/confirm.html @@ -93,6 +93,22 @@ Are you sure you want to remove these items? </ul> {% endif %} +{% if zone_id %} +<ul> +{% ifequal type 'zonemx' %} +<li> mx: {{ zonemx.priority }} {{ zonemx.mx }} </li> +{% endifequal %} + +{% ifequal type 'nameserver' %} +<li> nameserver: {{ nameserver.name }} </li> +{% endifequal %} + +{% ifequal type 'address' %} +<li> address: {{ address.ip_addr }} </li> +{% endifequal %} +</ul> +{% endif %} + <input type="submit" value="confirm"> <input type="reset" value="cancel" onclick="history.back()"> </form> diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/navbar b/src/lib/Server/Hostbase/hostbase/webtemplates/navbar index 767601aca..32ef99177 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/navbar +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/navbar @@ -1,2 +1,4 @@ <a href="/hostbase/" class="sidebar">new search</a><br> -<a href="/hostbase/new" class="sidebar">add a new host</a> +<a href="/hostbase/new" class="sidebar">add a new host</a><br> +<a href="/hostbase/zones" class="sidebar">zone file information</a> + diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/results.html b/src/lib/Server/Hostbase/hostbase/webtemplates/results.html index 6fb45692e..584453f98 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/results.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/results.html @@ -33,7 +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> +<!-- <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 4ac950ae0..31f9d5184 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/search.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/search.html @@ -9,7 +9,8 @@ {% endblock %} {% block sidebar %} -<a href="/hostbase/new" class="sidebar">add a new host</a> +<a href="/hostbase/new" class="sidebar">add a new host</a><br> +<a href="/hostbase/zones" class="sidebar">zone file information</a> {% endblock %} {% block content %} diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/zoneedit.html b/src/lib/Server/Hostbase/hostbase/webtemplates/zoneedit.html index 918f80398..c86268614 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/zoneedit.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/zoneedit.html @@ -10,6 +10,10 @@ {% block sidebar %} {% include "navbar" %} +<ul> +<li><a href="/hostbase/zones/{{ zone.id }}/" class="sidebar">view zone</a><br> +</li> +</ul> {% endblock %} {% block content %} @@ -61,7 +65,8 @@ div#address{ </td> <td> {% for nameserver in nameservers %} - <input name="nameserver{{ forloop.counter0 }}" type="text" size="32" value="{{ nameserver.name }}"><br> + <input name="nameserver{{ forloop.counter0 }}" type="text" size="32" value="{{ nameserver.name }}"> + <a style="font-size:75%" href="/hostbase/zones/{{ zone.id }}/nameserver/{{ nameserver.id }}/confirm">remove<br> {% endfor %} </td></tr> </table> @@ -84,7 +89,8 @@ div#address{ <td> {% for mx in mxs %} <input name="priority{{ forloop.counter0 }}" type="text" size="6" value="{{ mx.priority }}"> - <input name="mx{{ forloop.counter0 }}" type="text" size="32" value="{{ mx.mx }}"><br> + <input name="mx{{ forloop.counter0 }}" type="text" size="32" value="{{ mx.mx }}"> + <a style="font-size:75%" href="/hostbase/zones/{{ zone.id }}/zonemx/{{ mx.id }}/confirm">remove<br> {% endfor %} </td></tr> </table> @@ -103,15 +109,16 @@ div#address{ <colgroup> <col width="200"> <col width="*"> - <tr><td valign="top"> <b>A records</b><br> + <tr><td valign="top"> <b>A records</b> {% if addresses %} - <a style="font-size:75%" href=# onclick="toggleField('address')">add a new MX record</a> + <br><a style="font-size:75%" href=# onclick="toggleField('address')">add a new MX record</a> {% endif %} </td> <td> {% if addresses %} {% for address in addresses %} - <input name="address{{ forloop.counter0 }}" type="text" value="{{ address.ip_addr }}"><br> + <input name="address{{ forloop.counter0 }}" type="text" value="{{ address.ip_addr }}"> + <a style="font-size:75%" href="/hostbase/zones/{{ zone.id }}/address/{{ address.id }}/confirm">remove<br> {% endfor %} </td></tr> </table> @@ -130,7 +137,7 @@ div#address{ <col width="200"> <col width="*"> {% else %} - <input name="new_address" type="text" value="none" > + <input name="new_address" type="text" value="none" > {% endif %} </td></tr> diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/zoneview.html b/src/lib/Server/Hostbase/hostbase/webtemplates/zoneview.html index c7ac36402..712ec98bc 100644 --- a/src/lib/Server/Hostbase/hostbase/webtemplates/zoneview.html +++ b/src/lib/Server/Hostbase/hostbase/webtemplates/zoneview.html @@ -10,6 +10,10 @@ {% block sidebar %} {% include "navbar" %} +<ul class="sidebar"> +<li><a href="/hostbase/zones/{{ zone.id }}/edit/" class="sidebar">edit zone</a><br> +</li> +</ul> {% endblock %} {% block content %} diff --git a/src/lib/Server/Hostbase/urls.py b/src/lib/Server/Hostbase/urls.py index 526990d95..6ff12c631 100644 --- a/src/lib/Server/Hostbase/urls.py +++ b/src/lib/Server/Hostbase/urls.py @@ -19,4 +19,6 @@ urlpatterns = patterns('Hostbase.hostbase.views', (r'^hostbase/zones/$', 'zones'), (r'^hostbase/zones/(?P<zone_id>\d+)/$', 'zoneview'), (r'^hostbase/zones/(?P<zone_id>\d+)/edit', 'zoneedit'), -) + (r'^hostbase/zones/new/$', 'zonenew'), + (r'^hostbase/zones/(?P<zone_id>\d+)/(?P<item>\D+)/(?P<item_id>\d+)/confirm', 'confirm'), + ) |