Various updates

This commit is contained in:
Jamie Cameron
2008-01-17 23:38:58 +00:00
parent e6872308d2
commit e4ea3a445b
7 changed files with 80 additions and 20 deletions

14
dhcp-dns/apply.cgi Executable file
View File

@@ -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("");
}

View File

@@ -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("");

View File

@@ -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;

13
dhcp-dns/edit.cgi Normal file
View File

@@ -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'});

View File

@@ -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([
"<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();
@@ -63,5 +80,11 @@ else {
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'});

View File

@@ -1,4 +1,4 @@
desc=DHCP and DNS Hosts
category=servers
depends=bind8 dhcpd
version=1.1
version=1.2

View File

@@ -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("");