Handle hostnames with upper-case letters
[webmin.git] / sendmail / list_mailers.cgi
1 #!/usr/local/bin/perl
2 # list_mailers.cgi
3 # Display a list of mailertable domains
4
5 require './sendmail-lib.pl';
6 require './mailers-lib.pl';
7
8 $access{'mailers'} || &error($text{'mailers_cannot'});
9 &ui_print_header(undef, $text{'mailers_title'}, "");
10
11 $conf = &get_sendmailcf();
12 $mfile = &mailers_file($conf);
13 ($mdbm, $mdbmtype) = &mailers_dbm($conf);
14 if (!$mdbm) {
15         # No Kmailertable directive in sendmail.cf
16         print "<b>",&text('mailers_efeature', 'list_features.cgi'),"</b><p>\n";
17         &ui_print_footer("", $text{'index_return'});
18         exit;
19         }
20 if (!-r $mfile) {
21         # Text file not found
22         print "<b>",&text('mailers_efile', "<tt>$mfile</tt>",
23               "<tt>$mdbm</tt>", "$gconfig{'webprefix'}/config.cgi?$module_name"),"</b> <p>\n";
24         print "<b>",&text('virtusers_createfile',
25                           'create_file.cgi?mode=mailers'),"</b><p>\n";
26         &ui_print_footer("", $text{'index_return'});
27         exit;
28         }
29 @mailers = &list_mailers($mfile);
30
31 &mailer_form();
32 if (@mailers) {
33         # sort if needed
34         if ($config{'sort_mode'} == 1) {
35                 @mailers = sort { $a->{'domain'} cmp $b->{'domain'} } @mailers;
36                 }
37
38         # render table of mailers
39         print &ui_form_start("delete_mailers.cgi", "post");
40         @links = ( &select_all_link("d", 1),
41                    &select_invert_link("d", 1) );
42         print &ui_links_row(\@links);
43         if ($config{'columns'} == 2) {
44                 $mid = int((@mailers+1)/2);
45                 print "<table width=100%> <tr><td width=50% valign=top>\n";
46                 &mailers_table(@mailers[0..$mid-1]);
47                 print "</td><td width=50% valign=top>\n";
48                 if ($mid < @mailers) { &mailers_table(@mailers[$mid..$#mailers]); }
49                 print "</td></tr> </table><br>\n";
50                 }
51         else {
52                 &mailers_table(@mailers);
53                 }
54         print &ui_links_row(\@links);
55         print &ui_form_end([ [ "delete", $text{'mailers_delete'} ] ]);
56         }
57 print "<a href='edit_file.cgi?mode=mailers'>",
58         &text('file_edit', "<tt>$mfile</tt>"),"</a><p>\n"
59         if ($access{'manual'});
60 print $text{'mailers_desc1'},"<p>\n";
61 print &text('mailers_desc2', 'list_cws.cgi')," ",
62       &text('mailers_desc3', 'list_relay.cgi'),"<br>\n";
63
64 &ui_print_footer("", $text{'index_return'});
65
66 sub mailers_table
67 {
68 local @tds = ( "width=5" );
69 print &ui_columns_start([ "",
70                           $text{'mailers_for'},
71                           $text{'mailers_delivery'},
72                           $text{'mailers_to'},
73                           $config{'show_cmts'} ? ( $text{'virtusers_cmt'} )
74                                                : ( ) ], 100, 0, \@tds);
75 foreach $m (@_) {
76         local @cols;
77         push(@cols, "<a href=\"edit_mailer.cgi?num=$m->{'num'}\">".
78                     &html_escape($m->{'domain'})."</a>");
79         $md = $mailer_desc{$m->{'mailer'}};
80         push(@cols, $md ? $md : $m->{'mailer'});
81         push(@cols, &html_escape($m->{'dest'}));
82         push(@cols, &html_escape($m->{'cmt'})) if ($config{'show_cmts'});
83         print &ui_checked_columns_row(\@cols, \@tds, "d", $m->{'domain'});
84         }
85 print &ui_columns_end();
86 }
87