$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'});
}
}
+# 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;
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");
--- /dev/null
+#!/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("");
+