Partially done host saving
authorJamie Cameron <jcameron@webmin.com>
Fri, 11 Jan 2008 01:35:39 +0000 (01:35 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 11 Jan 2008 01:35:39 +0000 (01:35 +0000)
dhcp-dns/dhcp-dns-lib.pl
dhcp-dns/index.cgi
dhcp-dns/save.cgi [new file with mode: 0644]

index 9f59173..b9a1a14 100644 (file)
@@ -60,7 +60,7 @@ local $indom = $new || $short ne $h->{'values'}->[0];
 $rv .= &ui_table_row($text{'form_host'},
        &ui_textbox("host", $short, 20).
        ($indom ? "<tt>.$config{'domain'}</tt>" : ""));
-$rv .= &ui_hidden("indom", 1);
+$rv .= &ui_hidden("indom", $indom);
 
 # Fixed IP address
 local $fixed = &dhcpd::find("fixed-address", $h->{'members'});
@@ -98,5 +98,28 @@ else {
        }
 }
 
+# get_dns_zone()
+# Returns the records file and list of records for the domain
+sub get_dns_zone
+{
+local $conf = &bind8::get_config();
+local @zones = &bind8::find("zone", $conf);
+foreach my $v (&bind8::find("view", $conf)) {
+       push(@zones, &bind8::find("zone", $v->{'members'}));
+       }
+local ($z) = grep { lc($_->{'value'}) eq lc($config{'domain'}) } @zones;
+return ( ) if (!$z);
+local $file = &bind8::find("file", $z->{'members'});
+local $fn = $file->{'values'}->[0];
+local @recs = &bind8::read_zone_file($fn, $config{'domain'});
+return ( $fn, \@recs );
+}
+
+sub apply_configuration
+{
+&dhcpd::restart_dhcpd();
+&bind8::restart_bind();
+}
+
 1;
 
index ff16272..7caf4e7 100644 (file)
@@ -19,6 +19,11 @@ if (!$config{'domain'}) {
 if (!$config{'subnets'}) {
        &ui_print_endpage(&text('index_esubnets',"../config.cgi?$module_name"));
        }
+($fn, $recs) = &get_dns_zone();
+if (!$fn) {
+       &ui_print_endpage(&text('index_edomain2', "../config.cgi?$module_name",
+                               '../bind8/'));
+       }
 
 # Show form to add
 print &ui_hidden_start($text{'index_cheader'}, "create", 0, "index.cgi");
diff --git a/dhcp-dns/save.cgi b/dhcp-dns/save.cgi
new file mode 100644 (file)
index 0000000..a907d37
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/local/bin/perl
+# Update, delete or create a host (in both DHCP and DNS)
+
+require './dhcp-dns-lib.pl';
+&ReadParse();
+&error_setup($text{'save_err'});
+@hosts = &list_dhcp_hosts();
+if (!$in{'new'}) {
+       ($host) = grep { $_->{'values'}->[0] eq $in{'old'} } @hosts;
+       $host || &error($text{'edit_egone'});
+       $par = $host->{'parent'};
+       }
+else {
+       $host = { 'name' => 'host',
+                 'type' => 1,
+                 'members' => [ ] };
+       $par = @hosts ? $hosts[0]->{'parent'}
+                     : &dhcpd::get_config_parent();
+       }
+
+if ($in{'delete'}) {
+       # Remove the DHCP and DNS hosts
+       # XXX
+       }
+else {
+       # Validate inputs
+       $in{'host'} =~ /^[a-z0-9\.\-]+$/ || &error($text{'save_ehost'});
+       if ($in{'indom'}) {
+               $in{'host'} .= '.'.$config{'domain'};
+               }
+       if ($in{'new'} || $in{'host'} ne $in{'old'}) {
+               # Check for clash
+               ($clash) = grep { $_->{'values'}->[0] eq $in{'host'} } @hosts;
+               $clash && &error($text{'save_eclash'});
+               }
+       $host->{'values'} = [ $in{'host'} ];
+       &check_ipaddress($in{'ip'}) || &error($text{'save_eip'});
+       &dhcpd::save_directive($host, 'fixed-address',
+                       [ { 'name' => 'fixed-address',
+                           'values' => [ $in{'ip'} ] } ]);
+       $in{'mac'} =~ /^[a-f0-9:]+$/i || &error($text{'save_emac'});
+       &dhcpd::save_directive($host, 'hardware',
+                       [ { 'name' => 'hardware',
+                           'values' => [ $in{'media'}, $in{'mac'} ] } ]);
+
+       if ($in{'new'}) {
+               # Add to DNS
+               # XXX
+               }
+       else {
+               # Update in DNS
+               # XXX
+               }
+
+       # Save DHCP host
+       &dhcpd::save_directive($par, $in{'new'} ? [ ] : [ $host ],
+                               [ $host ], $indent);
+       &flush_file_lines();
+       }
+&apply_configuration();
+&redirect("");
+