Add reload button, and change the reload_postfix function to return an error instead of showing it to the user

This commit is contained in:
Jamie Cameron
2015-01-05 15:26:49 -08:00
parent 49e05cbdfe
commit fe4758b8eb
24 changed files with 84 additions and 47 deletions

View File

@@ -84,3 +84,5 @@ Destination email addresses that are allowed for relaying can now be configured
Added a refresh button to the mail queue.
---- Changes since 1.590 ----
Added a new page, visible for Postfix 2.7 and later, for editing sender dependent transport mappings.
---- Changes since 1.730 ----
Added a button to reload the Postfix configuration.

View File

@@ -27,7 +27,8 @@ foreach $alias (@delaliases) {
&unlock_alias_files(\@afiles);
&regenerate_aliases();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("delete", "aliases", scalar(@delaliases));
&redirect("aliases.cgi");

View File

@@ -19,7 +19,8 @@ foreach $d (@d) {
&unlock_all_files();
&regenerate_map_table($in{'map_name'});
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("delete", $in{'map_name'}.'s', scalar(@d));
&redirect_to_map_list($in{'map_name'});

View File

@@ -115,27 +115,23 @@ foreach $oitem (@onames)
&icons_table(\@olinks, \@otitles, \@oicons);
# Show start / stop / reload buttons
if ($access{'startstop'}) {
print &ui_hr();
print &ui_buttons_start();
if ($access{'startstop'})
{
print &ui_hr();
if (&is_postfix_running())
{
print "<table cellpadding=5 width=100%><tr><td>\n";
print "<form action=stop.cgi>\n";
print "<input type=submit value=\"$text{'index_stop'}\">\n";
print "</td> <td>$text{'index_stopmsg'}\n";
}
else
{
print "<table cellpadding=5 width=100%><tr><td>\n";
print "<form action=start.cgi>\n";
print "<input type=submit value=\"$text{'index_start'}\">\n";
print "</td> <td>$text{'index_startmsg'}\n";
}
print "</td></tr></table></form>\n";
}
if (&is_postfix_running()) {
print &ui_buttons_row("stop.cgi", $text{'index_stop'},
$text{'index_stopmsg'});
print &ui_buttons_row("reload.cgi", $text{'index_reload'},
$text{'index_reloadmsg'});
}
else {
print &ui_buttons_row("start.cgi", $text{'index_start'},
$text{'index_startmsg'});
}
print &ui_buttons_end();
}
&ui_print_footer("/", $text{'index'});

View File

@@ -9,8 +9,10 @@ index_econfig=The Postfix config command $1 does not exist. Maybe your <a href='
index_esuper=The Postfix supervisor command $1 does not exist. Maybe your <a href='$2'>module configuration</a> is incorrect.
index_stop=Stop Postfix
index_start=Start Postfix
index_reload=Reload Configuration
index_stopmsg=Click this button to stop the running Postfix mail server. This will stop mail from being delivered to local users from other systems, and prevent clients using this system as a mail server from sending mail.
index_startmsg=Click this button to start the Postfix mail server. Until this is done mail will not be delivered to local users from other systems, and clients will not be able to use this system as a mail server.
index_reloadmsg=Click this button to have Postfix re-read all of its configuration files. This can be useful if the Postfix configuration files have been manually modified.
index_version=Postfix version $1
opts_err=Failed to save options
@@ -407,6 +409,9 @@ stop_ecannot=You are not allowed to stop Postfix
start_efailed=Failed to start Postfix
start_ecannot=You are not allowed to start Postfix
reload_efailed=Failed to reload Postfix
reload_ecannot=You are not allowed to reload Postfix
query_get_efailed=Failed to query Postfix config command to get the current value of parameter $1: <tt>$2</tt>
query_set_efailed=Failed to query Postfix config command to set the current value of parameter $1 to $2: <tt>$3</tt>
reload_ecannot=You are not allowed to reload Postfix
@@ -783,6 +788,7 @@ log_master_delete=Deleted server process $1
log_manual=Manually edited configuration file $1
log_stop=Stopped Postfix server
log_start=Started Postfix server
log_reload=Reloaded Postfix configuration
log_delqs=Deleted $1 messages from mail queue
log_flushq=Flushed mail queue
log_backend=Updated configuration file for map $1

View File

@@ -234,19 +234,23 @@ sub check_postfix
#
sub reload_postfix
{
$access{'startstop'} || &error($text{'reload_ecannot'});
if (is_postfix_running())
{
if (check_postfix()) { &error("$text{'check_error'}"); }
my $ex;
if (check_postfix()) {
return $text{'check_error'};
}
my $cmd;
if (!$config{'reload_cmd'}) {
$ex = &system_logged("$config{'postfix_control_command'} -c $config_dir reload >/dev/null 2>&1");
$cmd = "$config{'postfix_control_command'} -c $config_dir ".
"reload";
}
else {
$ex = &system_logged("$config{'reload_cmd'} >/dev/null 2>&1");
$cmd = $config{'reload_cmd'};
}
if ($ex) { &error($text{'reload_efailed'}); }
my $ex = &system_logged("$cmd >/dev/null 2>&1");
return $ex ? ($out || "$cmd failed") : undef;
}
return undef;
}
# stop_postfix()

12
postfix/reload.cgi Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/local/bin/perl
# Have Postfix re-read its config
require './postfix-lib.pl';
$access{'startstop'} || &error($text{'reload_ecannot'});
&error_setup($text{'reload_efailed'});
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("reload");
&redirect("");

View File

@@ -94,7 +94,8 @@ else {
# re-creates aliases database
&regenerate_aliases();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log($in{'new'} ? 'create' : $in{'delete'} ? 'delete' : 'modify',
'alias', $loga->{'name'}, $loga);

View File

@@ -69,7 +69,8 @@ else {
&unlock_postfix_files();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("client");
&redirect("");

View File

@@ -16,7 +16,8 @@ $in{'data'} =~ s/\r//g;
# Regenerate map
&regenerate_map_table($in{'map_name'});
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("manual", $in{'map_name'}.'s', $in{'file'});
&redirect_to_map_list($in{'map_name'});

View File

@@ -96,7 +96,8 @@ else
# re-creates database
&regenerate_map_table($in{'map_name'});
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log($action, $in{'map_name'}, $logmap->{'name'}, $logmap);

View File

@@ -82,7 +82,8 @@ else {
&unlock_file($config{'postfix_master'});
# Apply config
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log($in{'delete'} ? "delete" : $in{'new'} ? "create" : "modify",
"master", $prog->{'name'}, $prog);

View File

@@ -26,8 +26,8 @@ if (defined($in{"debug_peer_level_def"})) {
&save_options(\%in);
&unlock_postfix_files();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log($in{'_log_form'} || "opts");
&redirect("");

View File

@@ -25,7 +25,8 @@ require './postfix-lib.pl';
&regenerate_aliases();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("aliases");
&redirect("");

View File

@@ -21,7 +21,8 @@ $access{'bcc'} || &error($text{'bcc_ecannot'});
&regenerate_bcc_table();
&regenerate_recipient_bcc_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("bcc");
&redirect("");

View File

@@ -29,7 +29,8 @@ $in{'body_checks'} =~ /^(regexp|pcre):\/\S+$/ ||
&regenerate_body_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("body");
&redirect("");

View File

@@ -30,7 +30,8 @@ $access{'canonical'} || &error($text{'canonical_ecannot'});
&regenerate_canonical_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("canonical");
&redirect("");

View File

@@ -26,7 +26,8 @@ $access{'dependent'} || &error($text{'dependent_ecannot'});
&regenerate_dependent_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("dependent");
&redirect("");

View File

@@ -29,7 +29,8 @@ $in{'header_checks'} =~ /^(regexp|pcre):\/\S+$/ ||
&regenerate_header_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("header");
&redirect("");

View File

@@ -27,7 +27,8 @@ require './postfix-lib.pl';
&regenerate_relocated_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("misc");
&redirect("");

View File

@@ -28,7 +28,8 @@ $access{'relocated'} || &error($text{'relocated_ecannot'});
&regenerate_relocated_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("relocated");
&redirect("");

View File

@@ -25,10 +25,10 @@ $access{'transport'} || &error($text{'transport_ecannot'});
&after_save();
&unlock_postfix_files();
&regenerate_transport_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("transport");
&redirect("");

View File

@@ -28,7 +28,8 @@ $access{'virtual'} || &error($text{'virtual_ecannot'});
&regenerate_virtual_table();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("virtual");
&redirect("");

View File

@@ -87,7 +87,8 @@ if ($rh) {
&unlock_postfix_files();
&reload_postfix();
$err = &reload_postfix();
&error($err) if ($err);
&webmin_log("sasl");
&redirect("");