Handle hostnames with upper-case letters
[webmin.git] / dhcp-dns / index.cgi
1 #!/usr/local/bin/perl
2 # Show a list of clients, and a form to add
3
4 require './dhcp-dns-lib.pl';
5 &ui_print_header(undef, $module_info{'desc'}, "", undef, 1, 1);
6 &ReadParse();
7
8 # Check for servers
9 if (!&foreign_installed("bind8", 1)) {
10         &ui_print_endpage(&text('index_ebind8', "../bind8/"));
11         }
12 if (!&foreign_installed("dhcpd", 1)) {
13         &ui_print_endpage(&text('index_edhcpd', "../dhcpd/"));
14         }
15
16 # Check config
17 if (!$config{'domain'}) {
18         &ui_print_endpage(&text('index_edomain', "../config.cgi?$module_name"));
19         }
20 ($fn, $recs) = &get_dns_zone();
21 if (!$fn) {
22         &ui_print_endpage(&text('index_edomain2', "../config.cgi?$module_name",
23                                 '../bind8/'));
24         }
25
26 # Show form to add
27 print &ui_hidden_start($text{'index_cheader'}, "create", 0, "index.cgi");
28 print &host_form();
29 print &ui_hidden_end();
30
31 # Show hosts, if any
32 @hosts = &list_dhcp_hosts();
33 if (@hosts) {
34         # Show search form
35         print &ui_form_start("index.cgi");
36         print $text{'index_search'}," ",
37               &ui_textbox("search", $in{'search'}, 40)," ",
38               &ui_submit($text{'index_ok'}),"<p>\n",
39               &ui_form_end();
40         if ($in{'search'}) {
41                 $s = $in{'search'};
42                 @hosts = grep {
43                     $fixed = &dhcpd::find("fixed-address", $_->{'members'});
44                     $hard = &dhcpd::find("hardware", $_->{'members'});
45                     $_->{'values'}->[0] =~ /\Q$s\E/i ||
46                      $_->{'comment'} =~ /\Q$s\E/i ||
47                      $fixed->{'values'}->[0] =~ /\Q$s\E/i ||
48                      $hard->{'values'}->[1] =~ /\Q$s\E/i } @hosts;
49                 }
50         }
51
52 if (@hosts) {
53         @tds = ( "width=5" );
54         print &ui_form_start("delete.cgi");
55         @links = ( &select_invert_link("d", 1) );
56         print &ui_links_row(\@links);
57         print &ui_columns_start([ "",
58                                   $text{'index_host'},
59                                   $text{'index_subnet'},
60                                   $text{'index_ip'},
61                                   $text{'index_mac'},
62                                   $text{'index_desc'},
63                                 ], 100, 0, \@tds);
64         foreach $h (sort { lc($a->{'values'}->[0]) cmp
65                            lc($b->{'values'}->[0]) } @hosts) {
66                 $fixed = &dhcpd::find("fixed-address", $h->{'members'});
67                 $hard = &dhcpd::find("hardware", $h->{'members'});
68                 my $parentdesc;
69                 my $par = $h->{'parent'};
70                 if ($par) {
71                         if ($par->{'name'} eq 'subnet') {
72                                 $parentdesc = $par->{'values'}->[0];
73                                 }
74                         elsif ($par->{'name'} eq 'group') {
75                                 $parentdesc = $par->{'comment'} || 'Group';
76                                 }
77                         elsif ($par->{'name'} eq 'shared-network') {
78                                 $parentdesc = $par->{'values'}->[0];
79                                 }
80                         }
81                 print &ui_checked_columns_row([
82                         "<a href='edit.cgi?host=".&urlize($h->{'values'}->[0]).
83                           "'>".
84                           &html_escape(&short_hostname($h->{'values'}->[0])).
85                           "</a>",
86                         $parentdesc,
87                         $fixed ? $fixed->{'values'}->[0] : undef,
88                         $hard ? $hard->{'values'}->[1] : undef,
89                         &html_escape($h->{'comment'}),
90                         ], \@tds, "d", $h->{'values'}->[0])
91                 }
92         print &ui_columns_end();
93         print &ui_links_row(\@links);
94         print &ui_form_end([ [ undef, $text{'index_delete'} ] ]);
95         }
96 elsif ($in{'search'}) {
97         # Nothing matched search
98         print "<b>$text{'index_none2'}</b><p>\n";
99         }
100 else {
101         # Really none
102         print "<b>$text{'index_none'}</b><p>\n";
103         }
104
105 print &ui_hr();
106 print &ui_buttons_start();
107 print &ui_buttons_row("apply.cgi", $text{'index_apply'},
108                       $text{'index_applydesc'});
109 print &ui_buttons_end();
110
111 &ui_print_footer("/", $text{'index'});
112