Completed saving and deletion
authorJamie Cameron <jcameron@webmin.com>
Fri, 11 Jan 2008 06:44:11 +0000 (06:44 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 11 Jan 2008 06:44:11 +0000 (06:44 +0000)
dhcp-dns/delete.cgi [new file with mode: 0644]
dhcp-dns/module.info
dhcp-dns/save.cgi

diff --git a/dhcp-dns/delete.cgi b/dhcp-dns/delete.cgi
new file mode 100644 (file)
index 0000000..11d98ff
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/local/bin/perl
+# Delete multiple hosts
+
+require './dhcp-dns-lib.pl';
+&ReadParse();
+&error_setup($text{'delete_err'});
+@d = split(/\0/, $in{'d'});
+@d || &error($text{'delete_enone'});
+
+# Do each host
+@hosts = &list_dhcp_hosts();
+foreach $d (@d) {
+       ($host) = grep { $_->{'values'}->[0] eq $d } @hosts;
+       if ($host) {
+               &dhcpd::save_directive($host->{'parent'}, [ $host ], [ ], $indent);
+               }
+       ($fn, $recs) = &get_dns_zone();
+       ($old) = grep { $_->{'name'} eq $d.'.' } @$recs;
+       if ($old) {
+               &bind8::delete_record($fn, $old);
+               &bind8::bump_soa_record($fn, $recs);
+               }
+       }
+
+# Apply config
+&flush_file_lines();
+&apply_configuration();
+&redirect("");
index 8e5da31..67c3685 100644 (file)
@@ -1,3 +1,4 @@
 desc=DHCP and DNS Hosts
 category=servers
 depends=bind8 dhcpd
+version=1.0
index a907d37..d5616a7 100644 (file)
@@ -5,6 +5,7 @@ require './dhcp-dns-lib.pl';
 &ReadParse();
 &error_setup($text{'save_err'});
 @hosts = &list_dhcp_hosts();
+($fn, $recs) = &get_dns_zone();
 if (!$in{'new'}) {
        ($host) = grep { $_->{'values'}->[0] eq $in{'old'} } @hosts;
        $host || &error($text{'edit_egone'});
@@ -20,7 +21,12 @@ else {
 
 if ($in{'delete'}) {
        # Remove the DHCP and DNS hosts
-       # XXX
+       &dhcpd::save_directive($par, [ $host ], [ ], $indent);
+       ($old) = grep { $_->{'name'} eq $in{'old'}.'.' } @$recs;
+       if ($old) {
+               &bind8::delete_record($fn, $old);
+               &bind8::bump_soa_record($fn, $recs);
+               }
        }
 else {
        # Validate inputs
@@ -45,18 +51,25 @@ else {
 
        if ($in{'new'}) {
                # Add to DNS
-               # XXX
+               &bind8::create_record($fn, $in{'host'}.'.', undef, "IN",
+                                     "A", $in{'ip'});
                }
        else {
                # Update in DNS
-               # XXX
+               ($old) = grep { $_->{'name'} eq $in{'old'}.'.' } @$recs;
+               if ($old) {
+                       &bind8::modify_record($fn, $old, $in{'host'}.'.',
+                                             $old->{'ttl'}, $old->{'class'},
+                                             $old->{'type'}, $in{'ip'});
+                       }
                }
+       &bind8::bump_soa_record($fn, $recs);
 
        # Save DHCP host
        &dhcpd::save_directive($par, $in{'new'} ? [ ] : [ $host ],
                                [ $host ], $indent);
-       &flush_file_lines();
        }
+&flush_file_lines();
 &apply_configuration();
 &redirect("");