Various updates
authorJamie Cameron <jcameron@webmin.com>
Thu, 17 Jan 2008 23:38:58 +0000 (23:38 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 17 Jan 2008 23:38:58 +0000 (23:38 +0000)
dhcp-dns/apply.cgi [new file with mode: 0755]
dhcp-dns/delete.cgi
dhcp-dns/dhcp-dns-lib.pl
dhcp-dns/edit.cgi [new file with mode: 0644]
dhcp-dns/index.cgi
dhcp-dns/module.info
dhcp-dns/save.cgi

diff --git a/dhcp-dns/apply.cgi b/dhcp-dns/apply.cgi
new file mode 100755 (executable)
index 0000000..843f7b6
--- /dev/null
@@ -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("");
+       }
+
index 11d98ff..1b6381a 100644 (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("");
index 8b8b187..b1fe1fc 100644 (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;
diff --git a/dhcp-dns/edit.cgi b/dhcp-dns/edit.cgi
new file mode 100644 (file)
index 0000000..e512ff3
--- /dev/null
@@ -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'});
+
+
index 68e245f..49b54b2 100644 (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'});
 
index dd85d9c..8bd0a29 100644 (file)
@@ -1,4 +1,4 @@
 desc=DHCP and DNS Hosts
 category=servers
 depends=bind8 dhcpd
-version=1.1
+version=1.2
index 6ade386..720bd24 100644 (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("");