Handle hostnames with upper-case letters
[webmin.git] / sendmail / list_access.cgi
1 #!/usr/local/bin/perl
2 # list_access.cgi
3 # Display a list of all domain and address mappings
4
5 require './sendmail-lib.pl';
6 require './access-lib.pl';
7 &ReadParse();
8 $access{'access'} || &error($text{'access_ecannot'});
9 &ui_print_header(undef, $text{'access_title'}, "");
10
11 $conf = &get_sendmailcf();
12 $afile = &access_file($conf);
13 ($adbm, $adbmtype) = &access_dbm($conf);
14 if (!$adbm) {
15         # No Kaccess directive in sendmail.cf
16         print "<b>",&text('access_efeature', 'list_features.cgi'),"</b><p>\n";
17         &ui_print_footer("", $text{'index_return'});
18         exit;
19         }
20 if (!-r $afile) {
21         # Text file not found
22         print "<b>",&text('access_efile', "<tt>$afile</tt>",
23               "<tt>$adbm</tt>", "$gconfig{'webprefix'}/config.cgi?$module_name"),"</b> <p>\n";
24         print "<b>",&text('virtusers_createfile',
25                           'create_file.cgi?mode=access'),"</b><p>\n";
26         &ui_print_footer("", $text{'index_return'});
27         exit;
28         }
29
30 # Get list of spam control rules, limited to those the user can edit
31 @accs = &list_access($afile);
32 if ($access{'smode'} == 2) {
33         @accs = grep { $_->{'from'} =~ /$access{'saddrs'}/i } @accs;
34         }
35
36 &access_form();
37
38 if ($in{'search'}) {
39         # Restrict to search results
40         @accs = grep { $_->{'from'} =~ /$in{'search'}/i ||
41                        $_->{'to'} =~ /$in{'search'}/i } @accs;
42         }
43 elsif ($config{'max_records'} && @accs > $config{'max_records'}) {
44         # Show search form
45         print $text{'access_toomany'},"<br>\n";
46         print "<form action=list_access.cgi>\n";
47         print "<input type=submit value='$text{'access_go'}'>\n";
48         print "<input name=search size=20></form>\n";
49         undef(@accs);
50         }
51
52 if (@accs) {
53         # sort if needed
54         if ($config{'sort_mode'} == 1) {
55                 @accs = sort { $a->{'from'} cmp $b->{'from'} } @accs;
56                 }
57
58         # render table of access rules
59         print &ui_form_start("delete_access.cgi", "post");
60         @links = ( &select_all_link("d", 1),
61                    &select_invert_link("d", 1) );
62         print &ui_links_row(\@links);
63         if ($config{'columns'} == 2) {
64                 $mid = int((@accs+1)/2);
65                 print "<table width=100%> <tr><td width=50% valign=top>\n";
66                 &accs_table(@accs[0..$mid-1]);
67                 print "</td><td width=50% valign=top>\n";
68                 if ($mid < @accs) { &accs_table(@accs[$mid..$#accs]); }
69                 print "</td></tr> </table><br>\n";
70                 }
71         else {
72                 &accs_table(@accs);
73                 }
74         print &ui_links_row(\@links);
75         print &ui_form_end([ [ "delete", $text{'access_delete'} ] ]);
76         }
77 print "<a href='edit_file.cgi?mode=access'>",
78         &text('file_edit', "<tt>$afile</tt>"),"</a><p>\n"
79         if ($access{'manual'});
80 print $text{'access_desc1'},"<p>\n";
81
82 &ui_print_footer("", $text{'index_return'});
83
84 sub accs_table
85 {
86 local @tds = ( "width=5" );
87 print &ui_columns_start([ "",
88                           $text{'access_source'},
89                           $text{'access_action'},
90                           $config{'show_cmts'} ? ( $text{'virtusers_cmt'} )
91                                                : ( ) ], 100, 0, \@tds);
92 foreach $m (@_) {
93         $from = $m->{'tag'} ? "$m->{'tag'}: $m->{'from'}" : $m->{'from'};
94         local @cols;
95         push(@cols, "<a href=\"edit_access.cgi?num=$m->{'num'}\">".
96                     &html_escape($from)."</a>");
97         push(@cols, &html_escape($m->{'action'}));
98         push(@cols, &html_escape($m->{'cmt'})) if ($config{'show_cmts'});
99         print &ui_checked_columns_row(\@cols, \@tds, "d", $m->{'from'});
100         }
101 print &ui_columns_end();
102 }
103