Handle hostnames with upper-case letters
[webmin.git] / spam / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display a menu of spamassassin config category icons
4
5 require './spam-lib.pl';
6 &ReadParse();
7 $hsl = $module_info{'usermin'} ? undef :
8                 &help_search_link("spamassassin", "perl", "google");
9 &set_config_file_in(\%in);
10
11 if (!&has_command($config{'spamassassin'}) ||
12     (!$module_info{'usermin'} && !($vers = &get_spamassassin_version(\$out)))) {
13         # Program not found
14         &ui_print_header($header_subtext, $text{'index_title'}, "", undef, 1, 1,
15                          undef, $hsl);
16
17         if ($module_info{'usermin'}) {
18                 print &text('index_ecmd2',
19                             "<tt>$config{'spamassassin'}</tt>"),"<p>\n";
20                 }
21         else {
22                 print &text('index_ecmd', "<tt>$config{'spamassassin'}</tt>",
23                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
24
25                 # Offer to install package
26                 &foreign_require("software", "software-lib.pl");
27                 $lnk = &software::missing_install_link(
28                                 "spamassassin", $text{'index_spamassassin'},
29                                 "../$module_name/", $text{'index_title'});
30                 if ($lnk) {
31                         print $lnk,"<p>\n";
32                         }
33                 elsif (&foreign_available("cpan")) {
34                         # Offer to install perl module
35                         $modname = "Mail::SpamAssassin";
36                         print &text('index_cpan', "<tt>$modname</tt>",
37                                     "../cpan/download.cgi?source=3&cpan=$modname&mode=2&return=/$module_name/&returndesc=".&urlize($module_info{'desc'})),"<p>\n";
38                         }
39                 }
40         }
41 else {
42         $vtext = $module_info{'usermin'} ? undef :
43                         &text('index_version', $vers);
44         &ui_print_header($header_subtext, $text{'index_title'}, "", undef,
45                          1, 1, undef, $hsl, undef, undef, $vtext);
46
47         if (!-r $local_cf && !-d $local_cf && !$module_info{'usermin'}) {
48                 # Config not found
49                 print &text('index_econfig',
50                         "<tt>$local_cf</tt>",
51                         "../config.cgi?$module_name"),"<p>\n";
52                 }
53         elsif ($dberr = &check_spamassassin_db()) {
54                 # Cannot contact the DB
55                 print &text('index_edb', $dberr,
56                             "../config.cgi?$module_name"),"<p>\n";
57                 }
58         else {
59                 # Work out if SpamAssassin is enabled in procmail
60                 if ($warn_procmail && &foreign_check("procmail")) {
61                         &foreign_require("procmail", "procmail-lib.pl");
62                         $spam_enabled = 0;      # Found call to spamassassin
63                         $delivery_enabled = 0;  # Found X-Spam: header rule
64                         @pmrcs = &get_procmailrc();
65                         foreach $pmrc (@pmrcs) {
66                                 local @recipes =
67                                         &procmail::parse_procmail_file($pmrc);
68                                 local $isglobal = $pmrc eq
69                                                   $config{'global_procmailrc'};
70                                 if (&find_spam_recipe(\@recipes)) {
71                                         $spam_enabled ||= 1;
72                                         }
73                                 if (&find_file_recipe(\@recipes)) {
74                                         if ($isglobal) {
75                                                 # Enabled globally, and so
76                                                 # cannot be changed by user
77                                                 $delivery_enabled ||= -2;
78                                                 }
79                                         else {
80                                                 $delivery_enabled ||= 1;
81                                                 }
82                                         }
83                                 if (&find_virtualmin_recipe(\@recipes)) {
84                                         # Controlled by Virtualmin
85                                         if ($isglobal &&
86                                             &find_force_default_receipe(
87                                               \@recipes)) {
88                                                 # User .procmailrc files are
89                                                 # prevented
90                                                 $spam_enabled ||= -2;
91                                                 $delivery_enabled ||= -2;
92                                                 }
93                                         else {
94                                                 # Users can have a .procmailrc
95                                                 $spam_enabled ||= -2;
96                                                 $delivery_enabled ||= 1;
97                                                 }
98                                         }
99                                 }
100                         }
101                 else {
102                         # don't know, or checking disabled
103                         $spam_enabled = -1;
104                         $delivery_enabled = -1;
105                         }
106                 if ($spam_enabled == 0) {
107                         if ($module_info{'usermin'}) {
108                                 print &text('index_warn_usermin',
109                                             "<tt>$pmrcs[0]</tt>",
110                                             "<tt>$pmrcs[1]</tt>"),"<p>\n";
111                                 }
112                         else {
113                                 print &text('index_warn_webmin',
114                                             "<tt>$pmrcs[0]</tt>"),"<p>\n";
115                                 }
116                         }
117
118                 # Check if razor is set up
119                 if ($module_info{'usermin'} &&
120                     -r "$remote_user_info[7]/.razor/identity") {
121                         $razor = 1;
122                         }
123
124                 # Show icons
125                 @pages = ( 'white', 'score', 'report', 'user' );
126                 push(@pages, 'simple') if (!$module_info{'usermin'} ||
127                                            &find_default("allow_user_rules",0));
128                 push(@pages, 'priv') if (!$module_info{'usermin'});
129                 push(@pages, 'mail') if ($module_info{'usermin'} &&
130                                          $userconfig{'spam_file'});
131                 push(@pages, 'razor') if (!$razor && $module_info{'usermin'});
132                 push(@pages, 'setup') if ($spam_enabled == 0);
133                 push(@pages, 'procmail') if ($delivery_enabled == 1);
134                 push(@pages, 'db') if (!$module_info{'usermin'});
135                 push(@pages, 'awl') if (&supports_auto_whitelist());
136                 @pages = grep { &can_use_page($_) } @pages;
137                 $sfolder = $module_info{'usermin'} ? &spam_file_folder()
138                                                    : undef;
139                 if (!$sfolder) {
140                         @pages = grep { $_ ne 'mail' } @pages;
141                         }
142                 @links = map { $_ eq "mail" ? "../mailbox/index.cgi?folder=$sfolder->{'index'}" : "edit_${_}.cgi" } @pages;
143                 if ($in{'file'}) {
144                         foreach my $l (@links) {
145                                 if ($l !~ /\//) {
146                                         $l .= "?file=".&urlize($in{'file'}).
147                                               "&title=".&urlize($in{'title'});
148                                         }
149                                 }
150                         }
151                 @icons = map { "images/${_}.gif" } @pages;
152                 @titles = map { $text{"${_}_title"} } @pages;
153                 &icons_table(\@links, \@titles, \@icons);
154
155                 # Show buttons for HUPing spamd processes (if any)
156                 if (!$module_info{'usermin'} &&
157                     (@pids = &get_process_pids())) {
158                         print &ui_hr();
159                         print "<form action=apply.cgi>\n";
160                         print "<table>\n";
161                         print "<tr> <td><input type=submit ",
162                               "value='$text{'index_apply'}'></td>\n";
163                         print "<td>",&text('index_applydesc',
164                                 "<tt>".join(" and ", &unique(
165                                 map { $_->[1] } @pids))."</tt>"),"</td>\n";
166                         print "</table>\n";
167                         }
168                 }
169         }
170
171 &ui_print_footer("/", $text{'index'});
172