Handle hostnames with upper-case letters
[webmin.git] / spam / edit_white.cgi
1 #!/usr/local/bin/perl
2 # edit_white.cgi
3 # Display white and black lists of to and from addresses
4
5 require './spam-lib.pl';
6 &ReadParse();
7 &set_config_file_in(\%in);
8 &can_use_check("white");
9 &ui_print_header($header_subtext, $text{'white_title'}, "");
10 $conf = &get_config();
11
12 print "$text{'white_desc'}<p>\n";
13 print &ui_form_start("save_white.cgi", "form-data");
14 print $form_hiddens;
15
16 # Start of tabs
17 $url = "edit_white.cgi?file=".&urlize($in{'file'}).
18        "&title=".&urlize($in{'title'});
19 print &ui_tabs_start(
20         [ map { [ $_, $text{'white_tab'.$_}, $url."&mode=$_" ] }
21               ( 'ham', 'spam', 'some', 'import' ) ],
22         "mode", $in{'mode'} || "ham", 1);
23
24 # Start of ham addresses tab
25 print &ui_tabs_start_tab("mode", "ham");
26 print $text{'white_hamdesc'},"<p>\n";
27 print &ui_table_start(undef, undef, 2);
28
29 # Addresses to always whitelist
30 @from = &find("whitelist_from", $conf);
31 print &ui_table_row($text{'white_from'},
32         &edit_textbox("whitelist_from",
33                       [ map { @{$_->{'words'}} } @from ], 60, 10));
34
35 # Exceptions to whitelist
36 @un = &find("unwhitelist_from", $conf);
37 print &ui_table_row($text{'white_unfrom'},
38         &edit_textbox("unwhitelist_from",
39                       [ map { @{$_->{'words'}} } @un ], 60, 5));
40
41 if ($config{'show_global'}) {
42         # Global white and blacklists
43         $gconf = &get_config($config{'global_cf'}, 1);
44         @gfrom = &find("whitelist_from", $gconf);
45         print &ui_table_row($text{'white_gfrom'},
46                 &edit_textbox("gwhitelist_from",
47                               [ map { @{$_->{'words'}} } @gfrom ], 40, 5, 1));
48
49         @gun = &find("unwhitelist_from", $gconf);
50         print &ui_table_row($text{'white_gunfrom'},
51                 &edit_textbox("gunwhitelist_from",
52                               [ map { @{$_->{'words'}} } @gun ], 40, 5));
53         }
54
55 # Whitelist by received header
56 @rcvd = &find("whitelist_from_rcvd", $conf);
57 print &ui_table_row($text{'white_rcvd2'},
58         &edit_table("whitelist_from_rcvd",
59                 [ $text{'white_addr'}, $text{'white_rcvdhost'} ],
60                 [ map { $_->{'words'} } @rcvd ], [ 40, 30 ], undef, 3));
61
62 print &ui_table_end();
63 print &ui_tabs_end_tab("mode", "ham");
64
65 # Start of spam addresses tab
66 print &ui_tabs_start_tab("mode", "spam");
67 print $text{'white_spamdesc'},"<p>\n";
68 print &ui_table_start(undef, undef, 2);
69
70 # Blacklisted addresses
71 @from = &find("blacklist_from", $conf);
72 print &ui_table_row($text{'white_black'},
73         &edit_textbox("blacklist_from",
74                       [ map { @{$_->{'words'}} } @from ], 60, 10));
75
76 # Exceptions to blacklist
77 @un = &find("unblacklist_from", $conf);
78 print &ui_table_row($text{'white_unblack'},
79         &edit_textbox("unblacklist_from",
80                       [ map { @{$_->{'words'}} } @un ], 40, 5));
81
82 if ($config{'show_global'}) {
83         # Global blacklist
84         @gfrom = &find("blacklist_from", $gconf);
85         print &ui_table_row($text{'white_gblack'},
86                 &edit_textbox("gblacklist_from",
87                               [ map { @{$_->{'words'}} } @gfrom ], 40, 5, 1));
88
89         @gun = &find("gunblacklist_from", $gconf);
90         print &ui_table_row($text{'white_gunblack'},
91                 &edit_textbox("gunblacklist_from",
92                               [ map { @{$_->{'words'}} } @gun ], 40, 5, 1));
93         }
94
95 print &ui_table_end();
96 print &ui_tabs_end_tab("mode", "spam");
97
98 print &ui_tabs_start_tab("mode", "some");
99 print $text{'white_somedesc'},"<p>\n";
100 print &ui_table_start(undef, undef, 2);
101
102 # Addresses to allow some spam to
103 push(@to, map { [ $_, 0 ] } map { @{$_->{'words'}} }
104               &find("whitelist_to", $conf));
105 push(@to, map { [ $_, 1 ] } map { @{$_->{'words'}} }
106               &find("more_spam_to", $conf));
107 push(@to, map { [ $_, 2 ] } map { @{$_->{'words'}} }
108               &find("all_spam_to", $conf));
109 print &ui_table_row($text{'white_to'},
110         &edit_table("whitelist_to",
111                     [ $text{'white_addr'}, $text{'white_level'} ],
112                     \@to, [ 40, 0 ], \&whitelist_to_conv, 3));
113
114 print &ui_table_end();
115 print &ui_tabs_end_tab("mode", "some");
116
117 # Show whitelist import form
118 print &ui_tabs_start_tab("mode", "import");
119 print "$text{'white_importdesc'}<p>\n";
120 print &ui_table_start(undef, undef, 2);
121
122 # File to import, uploaded
123 print &ui_table_row($text{'white_import'}, &ui_upload("import"));
124
125 # Sort addresses?
126 print &ui_table_row($text{'white_sort'}, &ui_yesno_radio("sort", 0));
127
128 print &ui_table_end();
129 print &ui_tabs_end_tab("mode", "import");
130
131 print &ui_tabs_end(1);
132 print &ui_form_end([ [ undef, $text{'save'} ] ]);
133
134 &ui_print_footer($redirect_url, $text{'index_return'});
135
136 # whitelist_to_conv(col, name, size, value)
137 sub whitelist_to_conv
138 {
139 if ($_[0] == 0) {
140         return &default_convfunc(@_);
141         }
142 else {
143         return &ui_select($_[1], $_[3],
144                 [ [ 0, $text{"white_level0"} ],
145                   [ 1, $text{"white_level1"} ],
146                   [ 2, $text{"white_level2"} ] ]);
147         }
148 }
149