From e4ea3a445b35857544dc142fcdceed7eca0941d0 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 17 Jan 2008 23:38:58 +0000 Subject: [PATCH] Various updates --- dhcp-dns/apply.cgi | 14 ++++++++++++++ dhcp-dns/delete.cgi | 3 +-- dhcp-dns/dhcp-dns-lib.pl | 13 ++++++++++--- dhcp-dns/edit.cgi | 13 +++++++++++++ dhcp-dns/index.cgi | 29 ++++++++++++++++++++++++++--- dhcp-dns/module.info | 2 +- dhcp-dns/save.cgi | 26 +++++++++++++++----------- 7 files changed, 80 insertions(+), 20 deletions(-) create mode 100755 dhcp-dns/apply.cgi create mode 100644 dhcp-dns/edit.cgi diff --git a/dhcp-dns/apply.cgi b/dhcp-dns/apply.cgi new file mode 100755 index 000000000..843f7b674 --- /dev/null +++ b/dhcp-dns/apply.cgi @@ -0,0 +1,14 @@ +#!/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(""); + } + diff --git a/dhcp-dns/delete.cgi b/dhcp-dns/delete.cgi index 11d98ffea..1b6381a12 100644 --- a/dhcp-dns/delete.cgi +++ b/dhcp-dns/delete.cgi @@ -15,7 +15,7 @@ foreach $d (@d) { &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); @@ -24,5 +24,4 @@ foreach $d (@d) { # Apply config &flush_file_lines(); -&apply_configuration(); &redirect(""); diff --git a/dhcp-dns/dhcp-dns-lib.pl b/dhcp-dns/dhcp-dns-lib.pl index 8b8b187af..b1fe1fcdb 100644 --- a/dhcp-dns/dhcp-dns-lib.pl +++ b/dhcp-dns/dhcp-dns-lib.pl @@ -112,6 +112,10 @@ else { } $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]; @@ -133,7 +137,7 @@ $rv .= &ui_table_row($text{'form_ip'}, # 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'} ], @@ -183,8 +187,11 @@ return ( $fn, \@recs ); 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; diff --git a/dhcp-dns/edit.cgi b/dhcp-dns/edit.cgi new file mode 100644 index 000000000..e512ff36c --- /dev/null +++ b/dhcp-dns/edit.cgi @@ -0,0 +1,13 @@ +#!/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'}); + + diff --git a/dhcp-dns/index.cgi b/dhcp-dns/index.cgi index 68e245f01..49b54b2de 100644 --- a/dhcp-dns/index.cgi +++ b/dhcp-dns/index.cgi @@ -39,19 +39,36 @@ if (@hosts) { 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([ "[0]). - "'>". - &html_escape(&short_hostname($h->{'values'}->[0])). - "", + "'>". + &html_escape(&short_hostname($h->{'values'}->[0])). + "", + $parentdesc, $fixed ? $fixed->{'values'}->[0] : undef, $hard ? $hard->{'values'}->[1] : undef, + &html_escape($h->{'comment'}), ], \@tds, "d", $h->{'values'}->[0]) } print &ui_columns_end(); @@ -63,5 +80,11 @@ else { print &ui_links_row(\@links); } +print "
\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'}); diff --git a/dhcp-dns/module.info b/dhcp-dns/module.info index dd85d9ca1..8bd0a296d 100644 --- a/dhcp-dns/module.info +++ b/dhcp-dns/module.info @@ -1,4 +1,4 @@ desc=DHCP and DNS Hosts category=servers depends=bind8 dhcpd -version=1.1 +version=1.2 diff --git a/dhcp-dns/save.cgi b/dhcp-dns/save.cgi index 6ade3861f..720bd24fc 100644 --- a/dhcp-dns/save.cgi +++ b/dhcp-dns/save.cgi @@ -7,11 +7,14 @@ require './dhcp-dns-lib.pl'; @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' => [ ] }; @@ -35,7 +38,6 @@ else { 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); @@ -43,13 +45,15 @@ if ($in{'delete'}) { } 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'} ]; @@ -58,17 +62,19 @@ else { 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', @@ -81,7 +87,6 @@ else { } else { # Update in DNS - ($old) = grep { $_->{'name'} eq $in{'old'}.'.' } @$recs; if ($old) { &bind8::modify_record($fn, $old, $in{'host'}.'.', $old->{'ttl'}, $old->{'class'}, @@ -95,6 +100,5 @@ else { [ $host ], $indent); } &flush_file_lines(); -&apply_configuration(); &redirect("");