Handle hostnames with upper-case letters
[webmin.git] / mailboxes / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display all users on the system
4
5 require './mailboxes-lib.pl';
6
7 if ($config{'mail_system'} == 3) {
8         # Need to detect mail server
9         $ms = &detect_mail_system();
10         if ($ms == 3) {
11                 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
12                 &ui_print_endpage(&text('index_esystem',
13                                         "../config.cgi?$module_name"));
14                 }
15         else {
16                 $config{'mail_system'} = $ms;
17                 &save_module_config();
18                 }
19         }
20 elsif (!$config{'send_mode'} || !$config{'auto'}) {
21         # Make sure mail system is valid
22         local ($ms) = grep { $_->[1] == $config{'mail_system'} }
23                            @mail_system_modules;
24         if (!&check_mail_system($ms)) {
25                 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
26                 &ui_print_endpage(&text('index_esystem2',
27                                         "../config.cgi?$module_name"));
28                 }
29         }
30
31 # Make sure mail system is running
32 $err = &test_mail_system();
33 if ($err) {
34         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
35         &ui_print_endpage(&text('index_esystem3',
36                                 "../config.cgi?$module_name", $err));
37         }
38
39 # Show main page header
40 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
41                  undef, undef, undef,
42                  $text{'index_system'.$config{'mail_system'}});
43
44 # Check for Perl modules for SMTP authentication
45 if ($config{'smtp_user'}) {
46         local @needed = ( "Authen::SASL" );
47         local $smode = $config{'smtp_auth'} || "Cram-MD5";
48         $smode = uc($smode);
49         $smode =~ s/-/_/g;
50         push(@needed, "Authen::SASL::Perl::$smode");
51         foreach $n (@needed) {
52                 eval "use $n";
53                 if ($@) {
54                         &ui_print_endpage(
55                                 "<p>".&text('index_eperl', "<tt>$n</tt>",
56                                   "/cpan/download.cgi?source=3&cpan=$n&mode=2&".
57                                   "return=/$module_name/&returndesc=".
58                                   &urlize($text{'index_return'}))."<p>\n".
59                                 "$text{'index_eperl2'}\n".
60                                 "<pre>$@</pre>\n");
61                         }
62                 }
63         }
64
65 # Build a list of all available users
66 @users = &list_mail_users($config{'max_records'}, \&can_user);
67
68 $form = 0;
69 if (!@users) {
70         # No users!
71         print "<b>$text{'index_none'}</b> <p>\n";
72         }
73 elsif ($config{'max_records'} && @users > $config{'max_records'}) {
74         # Show input for searching for a user
75         print $text{'index_toomany'},"<p>\n";
76         print &ui_form_start("find.cgi");
77         print &ui_submit($text{'index_find'}),"\n";
78         print &ui_select("match", undef, [ [ "0", $text{'index_equals'} ],
79                                            [ "1", $text{'index_contains'} ] ]),"\n";
80         print &ui_user_textbox("user"),"\n";
81         print &ui_form_end();
82         $form++;
83         }
84 else {
85         # Show using selected mode and sort
86         &show_users_table(\@users, $config{'show_mail'});
87         }
88
89 if (&allowed_directory()) {
90         # Show form to view any mail file
91         print &ui_hr();
92         print &ui_form_start("list_mail.cgi");
93         print &ui_submit($text{'index_file'}),"\n";
94         print &ui_textbox("user", undef, 40),"\n",
95               &file_chooser_button("user", $form),"<br>\n";
96         print &ui_form_end();
97         }
98
99 &ui_print_footer("/", $text{'index'});
100