Handle hostnames with upper-case letters
[webmin.git] / procmail / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display the current list of procmail recipes
4
5 require './procmail-lib.pl';
6 if ($minfo{'usermin'}) {
7         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
8         }
9 else {
10         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
11         }
12
13 # Make sure procmail is installed
14 if (!$module_info{'usermin'} && !&has_command($config{'procmail'})) {
15         print &text('index_ecmd', "<tt>$config{'procmail'}</tt>",
16                                   "../config.cgi?$module_name"),"<p>\n";
17
18         &foreign_require("software", "software-lib.pl");
19         $lnk = &software::missing_install_link(
20                         "procmail", $text{'index_procmail'},
21                         "../$module_name/", $text{'index_title'});
22         print $lnk,"<p>\n" if ($lnk);
23
24         &ui_print_footer("/", $text{'index_return'});
25         exit;
26         }
27
28 # Tell user when procmail will be used
29 if ($module_info{'usermin'}) {
30         print &text('index_desc', "<tt>$procmailrc</tt>"),"<p>\n";
31         }
32 else {
33         ($ms, $mserr) = &check_mailserver_config();
34         if ($mserr) {
35                 print "<b>",&text('index_mserr', $mserr),"</b><p>\n";
36                 }
37         elsif (!$ms) {
38                 print &text('index_desc_other', "<tt>$procmailrc</tt>"),"<p>\n";
39                 }
40         }
41
42 # Build links for adding things
43 @links = ( "<a href='edit_recipe.cgi?new=1'>$text{'index_add'}</a>",
44            "<a href='edit_recipe.cgi?new=1&block=1'>$text{'index_badd'}</a>",
45            "<a href='edit_env.cgi?new=1'>$text{'index_eadd'}</a>" );
46 push(@links, "<a href='edit_inc.cgi?new=1'>$text{'index_iadd'}</a>")
47         if (!$includes);
48
49 @conf = &get_procmailrc();
50 if (@conf) {
51         @tds = ( "width=5" );
52         print &ui_form_start("delete_recipes.cgi", "post");
53         unshift(@links, &select_all_link("d"),
54                         &select_invert_link("d") );
55         print &ui_links_row(\@links);
56         print &ui_columns_start([
57                 "",
58                 $text{'index_action'},
59                 $text{'index_conds'},
60                 $text{'index_move'},
61                 $text{'index_ba'} ], 100, 0, \@tds);
62         foreach $c (@conf) {
63                 local @cols;
64                 local @tds = ( "width=5" );
65                 if ($c->{'name'}) {
66                         # Environment variable assignment
67                         local $v = length($c->{'value'}) > 80 ?
68                                         substr($c->{'value'}, 0, 80)." ..." :
69                                         $c->{'value'};
70                         push(@cols, "<a href='edit_env.cgi?idx=$c->{'index'}'>".
71                               &text('index_env',
72                                 "<tt>".&html_escape($c->{'name'})."</tt>",
73                                 "<tt>".&html_escape($v)."</tt>")."</a>");
74                         push(@tds, "width=100% colspan=2");
75                         }
76                 elsif ($c->{'include'}) {
77                         # Included file
78                         push(@cols, "<a href='edit_inc.cgi?idx=$c->{'index'}'>".
79                                 &text('index_include', 
80                                 "<tt>".&html_escape($c->{'include'})."</tt>").
81                                 "</a>");
82                         push(@tds, "width=100% colspan=2");
83                         }
84                 else {
85                         # Procmail recipe
86                         local ($t, $a) = &parse_action($c);
87                         push(@cols,
88                             "<a href='edit_recipe.cgi?idx=$c->{'index'}'>".
89                             &text('index_act'.$t,
90                                     "<tt>".&html_escape($a)."</tt>")."</a>");
91                         push(@tds, "valign=top width=50%");
92
93                         local @c = @{$c->{'conds'}};
94                         if (!@c) {
95                                 push(@cols, $text{'index_noconds'});
96                                 }
97                         else {
98                                 local $c;
99                                 foreach $n (@c) {
100                                         local $he ="<tt>".&html_escape($n->[1]).
101                                                    "</tt>";
102                                         if ($n->[0] eq '') {
103                                                 $c .= &text('index_re', $he);
104                                                 }
105                                         elsif ($n->[0] eq '!') {
106                                                 $c .= &text('index_nre', $he);
107                                                 }
108                                         elsif ($n->[0] eq '$') {
109                                                 $c .= &text('index_shell', $he);
110                                                 }
111                                         elsif ($n->[0] eq '?') {
112                                                 $c .= &text('index_exit', $he);
113                                                 }
114                                         elsif ($n->[0] eq '<') {
115                                                 $c .= &text('index_lt',$n->[1]);
116                                                 }
117                                         elsif ($n->[0] eq '>') {
118                                                 $c .= &text('index_gt',$n->[1]);
119                                                 }
120                                         $c .= "<br>\n";
121                                         }
122                                 push(@cols, $c);
123                                 }
124                         push(@tds, "width=50%");
125                         }
126
127                 # Move up/down links
128                 local $mover;
129                 if ($c eq $conf[@conf-1] ||
130                     $c->{'file'} ne $conf[$c->{'index'}+1]->{'file'}) {
131                         $mover .= "<img src=images/gap.gif>";
132                         }
133                 else {
134                         $mover .= "<a href='down.cgi?idx=$c->{'index'}'>".
135                               "<img src=images/down.gif border=0></a>";
136                         }
137                 if ($c eq $conf[0] ||
138                     $c->{'file'} ne $conf[$c->{'index'}-1]->{'file'}) {
139                         $mover .= "<img src=images/gap.gif>";
140                         }
141                 else {
142                         $mover .= "<a href='up.cgi?idx=$c->{'index'}'>".
143                               "<img src=images/up.gif border=0></a>";
144                         }
145                 push(@cols, $mover);
146                 push(@tds, "width=32");
147
148                 # Add before/after links
149                 push(@cols, "<a href='edit_recipe.cgi?new=1&before=$c->{'index'}'><img src=images/before.gif border=0></a><a href='edit_recipe.cgi?new=1&after=$c->{'index'}'><img src=images/after.gif border=0></a>");
150                 print &ui_checked_columns_row(\@cols, \@tds, "d",$c->{'index'});
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         print "<b>$text{'index_none'}</b><p>\n";
158         print &ui_links_row(\@links);
159         }
160
161 # Manual edit button
162 print &ui_hr();
163 print &ui_buttons_start();
164 print &ui_buttons_row("manual_form.cgi",
165                       $text{'index_man'}, $text{'index_mandesc'});
166 print &ui_buttons_end();
167
168 print "<a href='manual_form.cgi'>$text{'index_manual'}</a>\n";
169 print "<p>\n";
170
171 &ui_print_footer("/", $text{'index'});
172