a6da8d4f47c32fb8718840fa4c5e29eaa1b6df01
[webmin.git] / postfix / index.cgi
1 #!/usr/local/bin/perl
2 #
3 # postfix-module by Guillaume Cottenceau <gc@mandrakesoft.com>,
4 # for webmin by Jamie Cameron
5 #
6 # A word about this module.
7 #
8 # Postfix provides a command to control its parameters: `postconf'.
9 # That's the reason why I don't parse and set the values manually.
10 # It's much better because it can resist to changes of the Postfix
11 # config files.
12 #
13 # However, to `set back to default' an already changed parameter,
14 # there is no way to do it in the case of dynamic parameters.
15 # [example: I mean that for `static' parameters, which defaults to
16 # `0', I can set the parameter to `0' ; but for `dynamic'
17 # parameters such as domainname [which comes from a system call]
18 # I have no way]
19 # So for this special case, I parse the config file, and delete
20 # manually the correct line.
21 #
22 # gc.
23 #
24
25
26 require './postfix-lib.pl';
27
28 if (&has_command($config{'postfix_config_command'}) &&
29     &backquote_command("$config{'postfix_config_command'} mail_version 2>&1", 1) =~ /mail_version\s*=\s*(.*)/) {
30         # Got the version
31         $postfix_version = $1;
32         }
33 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
34         &help_search_link("postfix", "man", "doc", "google"),
35         undef, undef, $postfix_version ?
36                 &text('index_version', $postfix_version) : undef);
37
38 # Save the version for use by other CGIs
39 &open_tempfile(VERSION, ">$module_config_directory/version", 0, 1);
40 &print_tempfile(VERSION, "$postfix_version\n");
41 &close_tempfile(VERSION);
42
43 # Verify the postfix control command
44 if (!-x $config{'postfix_control_command'}) {
45         print &text('index_epath',
46                 "<tt>$config{'postfix_control_command'}</tt>",
47                 "../config.cgi?$module_name"),"<p>\n";
48
49         &foreign_require("software", "software-lib.pl");
50         $lnk = &software::missing_install_link(
51                         "postfix", $text{'index_postfix'},
52                         "../$module_name/", $text{'index_title'});
53         print $lnk,"<p>\n" if ($lnk);
54
55         &ui_print_footer("/", $text{'index'});
56         exit;
57         }
58
59 # Verify the postfix config command
60 if (!-x $config{'postfix_config_command'}) {
61         print &text('index_econfig',
62                 "<tt>$config{'postfix_config_command'}</tt>",
63                 "../config.cgi?$module_name"),"<p>\n";
64         &ui_print_footer("/", $text{'index'});
65         exit;
66         }
67
68 # Verify the postsuper command
69 if (!-x $config{'postfix_super_command'}) {
70         print &text('index_esuper',
71                 "<tt>$config{'postfix_super_command'}</tt>",
72                 "../config.cgi?$module_name"),"<p>\n";
73         &ui_print_footer("/", $text{'index'});
74         exit;
75         }
76
77 # Verify that current configuration is valid. If not, only allow manual editing
78 if ($config{'index_check'} && ($err = &check_postfix())) {
79         print &text('check_error'),"<p>\n";
80         print "<pre>$err</pre>\n";
81         if ($access{'manual'}) {
82                 print "<a href=edit_manual.cgi>$text{'check_manual'}</a><p>\n";
83                 }
84         &ui_print_footer("/", $text{'index'});
85         exit;
86         }
87
88 @onames =  ( "general", "address_rewriting", "aliases", "canonical", "virtual", "transport", "relocated", "header", "body", "bcc",
89              "local_delivery", "resource",
90              "smtpd", "smtp", "sasl", "client",
91              "rate", "debug", $postfix_version > 2 ? ( ) : ( "ldap" ),
92              "master", "mailq", "postfinger", "boxes", "manual" );
93
94 $access{'boxes'} = &foreign_available("mailboxes");
95 foreach $oitem (@onames)
96 {
97         if ($access{$oitem}) {
98                 push (@olinks, $oitem eq "boxes" ? "../mailboxes/"
99                                                  : $oitem . ".cgi");
100                 push (@otitles, $oitem eq 'manual' ? $text{'cmanual_title'}
101                                                    : $text{$oitem . "_title"});
102                 if ($oitem eq 'mailq' && !$config{'mailq_count'}) {
103                         # Count the queue
104                         local @mqueue = &list_queue();
105                         local $mcount = scalar(@mqueue);
106                         $otitles[$#otitles] .=
107                                 "<br>".&text('mailq_count', $mcount);
108                         }
109                 push (@oicons, "images/" . $oitem . ".gif");
110         }
111 }
112
113 &icons_table(\@olinks, \@otitles, \@oicons);
114
115
116 if ($access{'startstop'})
117 {
118     print &ui_hr();
119
120     if (&is_postfix_running())
121     {
122         print "<table cellpadding=5 width=100%><tr><td>\n";
123         print "<form action=stop.cgi>\n";
124         print "<input type=submit value=\"$text{'index_stop'}\">\n";
125         print "</td> <td>$text{'index_stopmsg'}\n";
126     }
127     else
128     {
129         print "<table cellpadding=5 width=100%><tr><td>\n";
130         print "<form action=start.cgi>\n";
131         print "<input type=submit value=\"$text{'index_start'}\">\n";
132         print "</td> <td>$text{'index_startmsg'}\n";
133     }
134     print "</td></tr></table></form>\n";
135 }
136
137 &ui_print_footer("/", $text{'index'});
138
139
140