--- /dev/null
+#!/usr/local/bin/perl
+# Apply the current configuration
+
+require './dhcp-dns-lib.pl';
+&ReadParse();
+&error_setup($text{'apply_err'});
+$err = &apply_configuration();
+if ($err) {
+ &error($err);
+ }
+else {
+ &redirect("");
+ }
+
&dhcpd::save_directive($host->{'parent'}, [ $host ], [ ], $indent);
}
($fn, $recs) = &get_dns_zone();
- ($old) = grep { $_->{'name'} eq $d.'.' } @$recs;
+ ($old) = grep { lc($_->{'name'}) eq lc($d).'.' } @$recs;
if ($old) {
&bind8::delete_record($fn, $old);
&bind8::bump_soa_record($fn, $recs);
# Apply config
&flush_file_lines();
-&apply_configuration();
&redirect("");
}
$rv .= &ui_table_start($text{'form_header'}, "width=100%", 2);
+# Description
+$rv .= &ui_table_row($text{'form_comment'},
+ &ui_textbox("comment", $host->{'comment'}, 50));
+
# Hostname
local $short = &short_hostname($h->{'values'}->[0]);
local $indom = $new || $short ne $h->{'values'}->[0];
# MAC address
local $hard = &dhcpd::find("hardware", $h->{'members'});
-$rv .= &ui_hidden("oldmac", $hard->{'values'}->[0]) if ($hard);
+$rv .= &ui_hidden("oldmac", $hard->{'values'}->[1]) if ($hard);
$rv .= &ui_table_row($text{'form_mac'},
# &ui_select("media", $hard ? $hard->{'values'}->[0] : "ethernet",
# [ [ "ethernet", $text{'form_ethernet'} ],
sub apply_configuration
{
-&dhcpd::restart_dhcpd();
-&bind8::restart_bind();
+local $err = &dhcpd::restart_dhcpd();
+return "DHCPD failed : $err" if ($err);
+$err = &bind8::restart_bind();
+return "BIND failed : $err" if ($err);
+return undef;
}
1;
--- /dev/null
+#!/usr/local/bin/perl
+# Show one existing host
+
+require './dhcp-dns-lib.pl';
+&ReadParse();
+($host) = grep { $_->{'values'}->[0] eq $in{'host'} } &list_dhcp_hosts();
+$host || &error($text{'edit_egone'});
+
+&ui_print_header(undef, $text{'edit_title'}, "");
+print &host_form($host);
+&ui_print_footer("", $text{'index_return'});
+
+
print &ui_links_row(\@links);
print &ui_columns_start([ "",
$text{'index_host'},
+ $text{'index_subnet'},
$text{'index_ip'},
$text{'index_mac'},
+ $text{'index_desc'},
], 100, 0, \@tds);
foreach $h (@hosts) {
$fixed = &dhcpd::find("fixed-address", $h->{'members'});
$hard = &dhcpd::find("hardware", $h->{'members'});
+ my $parentdesc;
+ my $par = $h->{'parent'};
+ if ($par) {
+ if ($par->{'name'} eq 'subnet') {
+ $parentdesc = $par->{'values'}->[0];
+ }
+ elsif ($par->{'name'} eq 'group') {
+ $parentdesc = $par->{'comment'} || 'Group';
+ }
+ elsif ($par->{'name'} eq 'shared-network') {
+ $parentdesc = $par->{'values'}->[0];
+ }
+ }
print &ui_checked_columns_row([
"<a href='edit.cgi?host=".&urlize($h->{'values'}->[0]).
- "'>".
- &html_escape(&short_hostname($h->{'values'}->[0])).
- "</a>",
+ "'>".
+ &html_escape(&short_hostname($h->{'values'}->[0])).
+ "</a>",
+ $parentdesc,
$fixed ? $fixed->{'values'}->[0] : undef,
$hard ? $hard->{'values'}->[1] : undef,
+ &html_escape($h->{'comment'}),
], \@tds, "d", $h->{'values'}->[0])
}
print &ui_columns_end();
print &ui_links_row(\@links);
}
+print "<hr>\n";
+print &ui_buttons_start();
+print &ui_buttons_row("apply.cgi", $text{'index_apply'},
+ $text{'index_applydesc'});
+print &ui_buttons_end();
+
&ui_print_footer("/", $text{'index'});
desc=DHCP and DNS Hosts
category=servers
depends=bind8 dhcpd
-version=1.1
+version=1.2
@hosts = &list_dhcp_hosts();
($fn, $recs) = &get_dns_zone();
if (!$in{'new'}) {
+ # Get existing host object
($host) = grep { $_->{'values'}->[0] eq $in{'old'} } @hosts;
$host || &error($text{'edit_egone'});
$par = $host->{'parent'};
+ ($old) = grep { lc($_->{'name'}) eq lc($in{'old'}).'.' } @$recs;
}
else {
+ # Create new, and work out parent
$host = { 'name' => 'host',
'type' => 1,
'members' => [ ] };
if ($in{'delete'}) {
# Remove the DHCP and DNS hosts
&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
- $in{'host'} =~ /^[a-z0-9\.\-]+$/ || &error($text{'save_ehost'});
+ $host->{'comment'} = $in{'comment'};
+ $in{'host'} =~ /^[a-zA-Z0-9\.\-]+$/ || &error($text{'save_ehost'});
if ($in{'indom'}) {
$in{'host'} .= '.'.$config{'domain'};
}
- if ($in{'new'} || $in{'host'} ne $in{'old'}) {
+ if ($in{'new'} || lc($in{'host'}) ne lc($in{'old'})) {
# Check for hostname clash
- ($clash) = grep { $_->{'values'}->[0] eq $in{'host'} } @hosts;
+ ($clash) = grep { lc($_->{'values'}->[0]) eq lc($in{'host'}) }
+ @hosts;
$clash && &error($text{'save_eclash'});
}
$host->{'values'} = [ $in{'host'} ];
if ($in{'new'} || $in{'ip'} ne $in{'oldip'}) {
# Check for IP clash
($clash) = grep { my $f = &dhcpd::find("fixed-address", $_->{'members'}); $f->{'values'}->[0] eq $in{'ip'} } @hosts;
- $clash && &error($text{'save_eclaship'});
+ $clash && &error(&text('save_eclaship',
+ $clash->{'values'}->[0]));
}
&dhcpd::save_directive($host, 'fixed-address',
[ { 'name' => 'fixed-address',
'values' => [ $in{'ip'} ] } ]);
- $in{'mac'} =~ /^[a-f0-9:]+$/i || &error($text{'save_emac'});
- if ($in{'new'} || $in{'mac'} ne $in{'oldmac'}) {
+ $in{'mac'} =~ /^[a-fA-F0-9:]+$/i || &error($text{'save_emac'});
+ if ($in{'new'} || lc($in{'mac'}) ne lc($in{'oldmac'})) {
# Check for MAC clash
- ($clash) = grep { my $h = &dhcpd::find("hardware", $_->{'members'}); $h->{'values'}->[1] eq $in{'mac'} } @hosts;
- $clash && &error($text{'save_eclaship'});
+ ($clash) = grep { my $h = &dhcpd::find("hardware", $_->{'members'}); lc($h->{'values'}->[1]) eq lc($in{'mac'}) } @hosts;
+ $clash && &error(&text('save_eclashmac',
+ $clash->{'values'}->[0]));
}
&dhcpd::save_directive($host, 'hardware',
[ { 'name' => 'hardware',
}
else {
# Update in DNS
- ($old) = grep { $_->{'name'} eq $in{'old'}.'.' } @$recs;
if ($old) {
&bind8::modify_record($fn, $old, $in{'host'}.'.',
$old->{'ttl'}, $old->{'class'},
[ $host ], $indent);
}
&flush_file_lines();
-&apply_configuration();
&redirect("");