Handle hostnames with upper-case letters
[webmin.git] / filter / index.cgi
1 #!/usr/local/bin/perl
2 # Show a table of simple actions
3
4 require './filter-lib.pl';
5 &foreign_require("mailbox", "mailbox-lib.pl");
6 &ui_print_header(undef, $text{'index_title'}, "", undef, 0, 1);
7
8 if (&get_product_name() eq 'webmin') {
9         &ui_print_endpage($text{'index_nowebmin'});
10         }
11
12 # Warn if procmail is not installed
13 if ($config{'warn_procmail'} && !&has_command("procmail")) {
14         print "$text{'index_warn'}<p>\n";
15         }
16
17 # Check for an override alias
18 $alias = &get_override_alias();
19 if ($alias) {
20         # Got one .. but does it deliver locally
21         $noat = $remote_user;
22         $noat =~ s/\@/-/g;
23         @values = @{$alias->{'values'}};
24         ($tome) = grep { $_ eq "\\$remote_user" ||
25                          $_ eq "\\$noat" } @values;
26         if ($tome) {
27                 @values = grep { $_ ne $tome } @values;
28                 $msg = 'index_aliasme';
29                 }
30         else {
31                 $msg = 'index_alias';
32                 }
33         print "<b>$text{$msg}</b><br>\n";
34         print "<ul>\n";
35         foreach $dest (&describe_alias_dest(\@values)) {
36                 print "<li>$dest\n";
37                 }
38         print "</ul>\n";
39         }
40
41 # Check if /etc/procmailrc forces local delivery
42 if (&no_user_procmailrc()) {
43         print "<b>",$text{'index_force'},"</b><p>\n";
44         }
45
46 @filters = &list_filters();
47 @links = ( );
48 if (@filters) {
49         push(@links, &select_all_link("d"), &select_invert_link("d"));
50         }
51 push(@links, "<a href='edit.cgi?new=1'>$text{'index_add'}</a>");
52 ($auto) = grep { $_->{'actionreply'} } @filters;
53 if (&can_simple_autoreply() && !$auto) {
54         push(@links, "<a href='edit_auto.cgi'>$text{'index_addauto'}</a>");
55         }
56 ($fwd) = grep { $_->{'actiontype'} eq '!' } @filters;
57 if (&can_simple_forward() && !$fwd) {
58         push(@links, "<a href='edit_forward.cgi'>$text{'index_addfwd'}</a>");
59         }
60
61 @folders = &mailbox::list_folders();
62 if (@filters || &get_global_spamassassin()) {
63         # Show table of filters
64         print &ui_form_start("delete.cgi", "post");
65         @tds = ( "width=5", "width=50%", "width=50%", "width=32" );
66         print &ui_links_row(\@links);
67         print &ui_columns_start([ "",
68                                   $text{'index_condition'},
69                                   $text{'index_action'},
70                                   @filters > 1 ? ( $text{'index_move'} ) : ( ),
71                                 ], 100, 0, \@tds);
72
73         # Add a magic non-editable row(s) for global spamassassin run
74         if (&get_global_spamassassin()) {
75                 print &ui_columns_row(
76                         [ "", $text{'index_calways'}, $text{'index_aspam'},
77                           @filters > 1 ? ( "" ) : ( ) ],
78                         \@tds);
79                 # Delete level
80                 $spamlevel = &get_global_spam_delete();
81                 if ($spamlevel) {
82                         print &ui_columns_row(
83                                 [ "", &text('index_clevel', $spamlevel),
84                                       $text{'index_athrow'},
85                                   @filters > 1 ? ( "" ) : ( ) ],
86                                 \@tds);
87                         }
88                 # Delivery path
89                 $spamfile = &get_global_spam_path();
90                 if ($spamfile) {
91                         $folder = &file_to_folder($spamfile, \@folders, 0, 1);
92                         $id = &mailbox::folder_name($folder);
93                         if ($folder->{'fake'}) {
94                                 $sflink = "<u>$folder->{'name'}</u>";
95                                 }
96                         else {
97                                 $sflink =
98                                     "<a href='../mailbox/index.cgi?id=$id'>".
99                                     "$folder->{'name'}</a>";
100                                 }
101                         print &ui_columns_row(
102                                 [ "", $text{'index_cspam'},
103                                       &text('index_afolder', $sflink),
104                                   @filters > 1 ? ( "" ) : ( ) ],
105                                 \@tds);
106                         }
107                 }
108
109         # Show editable rows
110         foreach $f (@filters) {
111                 # Work out nice condition and action descriptions
112                 local $cond;
113                 ($cond, $lastalways) = &describe_condition($f);
114                 $cond = "<a href='edit.cgi?idx=$f->{'index'}'>$cond</a>";
115                 local $action = &describe_action($f, \@folders);
116
117                 # Create mover links
118                 local $mover;
119                 if ($f eq $filters[0]) {
120                         $mover .= "<img src=images/gap.gif alt=' '>";
121                         }
122                 else {
123                         $mover .= "<a href='up.cgi?idx=$f->{'index'}'>".
124                               "<img src=images/up.gif border=0 alt='Up'></a>";
125                         }
126                 if ($f eq $filters[$#filters]) {
127                         $mover .= "<img src=images/gap.gif alt=' '>";
128                         }
129                 else {
130                         $mover .= "<a href='down.cgi?idx=$f->{'index'}'>".
131                             "<img src=images/down.gif border=0 alt='Down'></a>";
132                         }
133
134                 # Show the row
135                 print &ui_checked_columns_row(
136                         [ $cond,
137                           $action,
138                           @filters > 1 ? ( $mover ) : ( ) ],
139                         \@tds, "d", $f->{'index'}
140                         );
141
142                 }
143
144         # Add a magic non-editable row for default delivery
145         if (!$lastalways) {
146                 print &ui_columns_row(
147                         [ "", $text{'index_calways'}, $text{'index_adefault'},
148                           @filters > 1 ? ( "" ) : ( ) ],
149                         \@tds);
150                 }
151
152         print &ui_columns_end();
153         print &ui_links_row(\@links);
154         print &ui_form_end([ [ "delete", $text{'index_delete'} ] ]);
155         }
156 else {
157         # Tell the user there are none
158         @pmrc = &procmail::get_procmailrc();
159         if (@pmrc) {
160                 print "<b>$text{'index_none2'}</b><p>\n";
161                 }
162         else {
163                 print "<b>$text{'index_none'}</b><p>\n";
164                 }
165         print &ui_links_row(\@links);
166         }
167
168 &ui_print_footer("/", $text{'index'});
169