Handle hostnames with upper-case letters
[webmin.git] / majordomo / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display all mailing lists and majordomo options
4
5 require './majordomo-lib.pl';
6 %access = &get_module_acl();
7
8 # Check for the majordomo config file
9 if (!-r $config{'majordomo_cf'}) {
10         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
11                 &help_search_link("majordomo", "man", "doc", "google"));
12         print &text('index_econfig', "<tt>$config{'majordomo_cf'}</tt>",
13                  "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
14         &ui_print_footer("/", $text{'index'});
15         exit;
16         }
17
18 # Check for the programs dir
19 if (!-d $config{'program_dir'}) {
20         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
21                 &help_search_link("majordomo", "man", "doc", "google"));
22         print &text('index_eprograms', "<tt>$config{'program_dir'}</tt>",
23                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
24         &ui_print_footer("/", $text{'index'});
25         exit;
26         }
27
28 # Check majordomo version
29 if (!-r "$config{'program_dir'}/majordomo_version.pl") {
30         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
31                 &help_search_link("majordomo", "man", "doc", "google"));
32         print &text('index_eversion2', "majordomo_version.pl",
33                           $config{'program_dir'},
34                           "$gconfig{'webprefix'}/config.cgi?$module_name"),
35               "<p>\n";
36         &ui_print_footer("/", $text{'index'});
37         exit;
38         }
39 require "$config{'program_dir'}/majordomo_version.pl";
40 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
41         &help_search_link("majordomo", "man", "doc", "google"),
42         undef, undef, &text('index_version', $majordomo_version));
43 if ($majordomo_version < 1.94 || $majordomo_version >= 2) {
44         print "$text{'index_eversion'}<p>\n";
45         &ui_print_footer("/", $text{'index'});
46         exit;
47         }
48
49 # Check $homedir in majordomo.cf
50 $conf = &get_config();
51 if (!&homedir_valid($conf)) {
52         print &text('index_ehomedir', "<tt>$homedir</tt>"),"<p>\n";
53         &ui_print_footer("/", $text{'index'});
54         exit;
55         }
56
57 # Check $listdir in majordomo.cf
58 $listdir = &perl_var_replace(&find_value("listdir", $conf), $conf);
59 if (!-d $listdir) {
60         print &text('index_elistdir', "<tt>$listdir</tt>"),"<p>\n";
61         &ui_print_footer("/", $text{'index'});
62         exit;
63         }
64
65 # Check if module needed for aliases is OK
66 if ($config{'aliases_file'} eq 'postfix') {
67         # Postfix has to be installed
68         &foreign_installed("postfix", 1) ||
69                 &ui_print_endpage(&text('index_epostfix', '../postfix/'));
70         }
71 elsif ($config{'aliases_file'} eq '') {
72         # Sendmail has to be installed
73         &foreign_installed("sendmail", 1) ||
74                 &ui_print_endpage(&text('index_esendmail2', '','../sendmail/'));
75         }
76 else {
77         # Only the sendmail module has to be installed
78         &foreign_check("sendmail") ||
79                 &ui_print_endpage(&text('index_esendmail3'));
80         }
81
82 # Check for the majordomo aliases
83 $aliases_files = &get_aliases_file();
84 $email = &find_value("whoami", $conf); $email =~ s/\@.*$//g;
85 $owner = &find_value("whoami_owner", $conf); $owner =~ s/\@.*$//g;
86 @aliases = &foreign_call($aliases_module, "list_aliases", $aliases_files);
87 foreach $a (@aliases) {
88         if ($a->{'enabled'} && lc($a->{'name'}) eq lc($email)) {
89                 $majordomo_alias = 1;
90                 }
91         if ($a->{'enabled'} && lc($a->{'name'}) eq lc($owner)) {
92                 $majordomo_owner = 1;
93                 }
94         }
95
96 # Offer to setup aliases
97 if (!$majordomo_alias) {
98         print "<p>$text{'index_setupdesc'}\n";
99         print "<center><form action=alias_setup.cgi>\n";
100         if (!$majordomo_owner) {
101                 print "<b>$text{'index_owner'}</b>\n";
102                 print "<input name=owner size=25>\n";
103                 print "<input type=hidden name=owner_a value='$owner'>\n";
104                 }
105         print "<input type=hidden name=email_a value='$email'>\n";
106         print "<input type=submit value=\"$text{'index_setup'}\">\n";
107         print "</form></center>\n";
108         print &ui_hr();
109         }
110
111 # Display active lists
112 @lists = &list_lists($conf);
113 @lists = sort { $a cmp $b } @lists if ($config{'sort_mode'});
114 map { $lcan{$_}++ } split(/\s+/, $access{'lists'});
115 foreach $l (grep { $lcan{$_} || $lcan{"*"} } @lists) {
116         push(@links, "edit_list.cgi?name=$l");
117         push(@titles, &html_escape($l));
118         push(@icons, "images/list.gif");
119         }
120 if (@links) {
121         @crlinks = ( "<a href='create_form.cgi'>$text{'index_add'}</a>" );
122         if (@links) {
123                 push(@crlinks, "<a href='digest_form.cgi'>$text{'index_digest'}</a>");
124                 }
125         if ($access{'create'}) {
126                 print &ui_links_row(\@crlinks);
127                 }
128         &icons_table(\@links, \@titles, \@icons, 5);
129         }
130 else {
131         print "<b>$text{'index_none'}</b>.<p>\n";
132         }
133 if ($access{'create'}) {
134         print &ui_links_row(\@crlinks);
135         }
136
137 if ($access{'global'}) {
138         print &ui_hr();
139         print "<table> <tr>\n";
140         print "<form action=edit_global.cgi>\n";
141         print "<td><input type=submit value='$text{'index_global'}'></td>\n";
142         print "<td>$text{'index_globaldesc'}</td> </tr> </form>\n";
143         print "</table>\n";
144         }
145
146 &ui_print_footer("/", $text{'index'});
147