Handle hostnames with upper-case letters
[webmin.git] / sendmail / list_domains.cgi
1 #!/usr/local/bin/perl
2 # list_domains.cgi
3 # Display a list of all domain mappings
4
5 require './sendmail-lib.pl';
6 require './domain-lib.pl';
7 $access{'domains'} || &error($text{'domains_ecannot'});
8 &ui_print_header(undef, $text{'domains_title'}, "");
9
10 $conf = &get_sendmailcf();
11 $dfile = &domains_file($conf);
12 ($ddbm, $ddbmtype) = &domains_dbm($conf);
13 if (!$ddbm) {
14         # No Kdomain directive in sendmail.cf
15         print "<b>",&text('domains_efeature', 'list_features.cgi'),"</b><p>\n";
16         &ui_print_footer("", $text{'index_return'});
17         exit;
18         }
19 if (!-r $dfile) {
20         # Text file not found
21         print "<b>",&text('domains_efile', "<tt>$dfile</tt>",
22               "<tt>$ddbm</tt>", "$gconfig{'webprefix'}/config.cgi?$module_name"),"</b> <p>\n";
23         print "<b>",&text('virtusers_createfile',
24                           'create_file.cgi?mode=domains'),"</b><p>\n";
25         &ui_print_footer("", $text{'index_return'});
26         exit;
27         }
28 @doms = &list_domains($dfile);
29
30 &domain_form();
31 if (@doms) {
32         # sort if needed
33         if ($config{'sort_mode'} == 1) {
34                 @doms = sort { $a->{'from'} cmp $b->{'from'} } @doms;
35                 }
36
37         # render table of domains
38         print &ui_form_start("delete_domains.cgi", "post");
39         @links = ( &select_all_link("d", 1),
40                    &select_invert_link("d", 1) );
41         print &ui_links_row(\@links);
42         if ($config{'columns'} == 2) {
43                 $mid = int((@doms+1)/2);
44                 print "<table width=100%> <tr><td width=50% valign=top>\n";
45                 &doms_table(@doms[0..$mid-1]);
46                 print "</td><td width=50% valign=top>\n";
47                 if ($mid < @doms) { &doms_table(@doms[$mid..$#doms]); }
48                 print "</td></tr> </table><br>\n";
49                 }
50         else {
51                 &doms_table(@doms);
52                 }
53         print &ui_links_row(\@links);
54         print &ui_form_end([ [ "delete", $text{'domains_delete'} ] ]);
55         }
56 print "<a href='edit_file.cgi?mode=domains'>",
57         &text('file_edit', "<tt>$dfile</tt>"),"</a><p>\n"
58         if ($access{'manual'});
59 print $text{'domains_desc'},"<p>\n";
60
61 &ui_print_footer("", $text{'index_return'});
62
63 sub doms_table
64 {
65 local @tds = ( "width=5" );
66 print &ui_columns_start([ "",
67                           $text{'domains_from'},
68                           $text{'domains_to'},
69                           $config{'show_cmts'} ? ( $text{'virtusers_cmt'} )
70                                                : ( ) ], 100, 0, \@tds);
71 foreach $m (@_) {
72         local @cols;
73         push(@cols, "<a href=\"edit_domain.cgi?num=$m->{'num'}\">".
74                     &html_escape($m->{'from'})."</a>");
75         push(@cols, &html_escape($m->{'to'}));
76         push(@cols, &html_escape($m->{'cmt'})) if ($config{'show_cmts'});
77         print &ui_checked_columns_row(\@cols, \@tds, "d", $m->{'from'});
78         }
79 print &ui_columns_end();
80 }
81