diff --git a/cgi_args.pl b/cgi_args.pl index 2e7bc7c..acbea7e 100755 --- a/cgi_args.pl +++ b/cgi_args.pl @@ -1,3 +1,6 @@ +use strict; +use warnings; +our $module_name; do 'virtualmin-mailrelay-lib.pl'; diff --git a/edit.cgi b/edit.cgi index 9383080..0271a22 100755 --- a/edit.cgi +++ b/edit.cgi @@ -1,14 +1,17 @@ #!/usr/local/bin/perl # Show a form for editing a mail relay domain's destination server +use strict; +use warnings; +our (%text, %in); require 'virtualmin-mailrelay-lib.pl'; &ReadParse(); # Get and check the domain &can_edit_relay($in{'dom'}) || &error($text{'edit_ecannot'}); -$d = &virtual_server::get_domain_by("dom", $in{'dom'}); +my $d = &virtual_server::get_domain_by("dom", $in{'dom'}); $d || &error($text{'edit_edomain'}); -$relay = &get_relay_destination($in{'dom'}); +my $relay = &get_relay_destination($in{'dom'}); $relay || &error($text{'edit_erelay'}); &ui_print_header(&virtual_server::domain_in($d), $text{'edit_title'}, ""); @@ -35,7 +38,7 @@ if (&supports_mail_queue() && $relay) { print &ui_hr(); print &ui_subheading($text{'edit_queue'}); - @queue = &list_mail_queue($d); + my @queue = &list_mail_queue($d); print &ui_columns_table( [ $text{'edit_from'}, $text{'edit_to'}, $text{'edit_date'}, $text{'edit_size'} ], @@ -49,4 +52,3 @@ if (&supports_mail_queue() && $relay) { } &ui_print_footer("/", $text{'index'}); - diff --git a/log_parser.pl b/log_parser.pl index 90e3dbe..1d8e810 100755 --- a/log_parser.pl +++ b/log_parser.pl @@ -1,5 +1,7 @@ # log_parser.pl # Functions for parsing this module's logs +use strict; +use warnings; do 'virtualmin-mailrelay-lib.pl'; @@ -7,7 +9,7 @@ # Converts logged information from this module into human-readable form sub parse_webmin_log { -local ($user, $script, $action, $type, $object, $p) = @_; +my ($user, $script, $action, $type, $object, $p) = @_; if ($action eq 'save') { return &text('log_save', "".&html_escape($object).""); } @@ -15,4 +17,3 @@ sub parse_webmin_log } 1; - diff --git a/save.cgi b/save.cgi index 6e834ed..e9760cb 100755 --- a/save.cgi +++ b/save.cgi @@ -1,5 +1,8 @@ #!/usr/local/bin/perl # Update master server IPs +use strict; +use warnings; +our (%text, %in); require 'virtualmin-mailrelay-lib.pl'; &ReadParse(); @@ -7,9 +10,9 @@ require 'virtualmin-mailrelay-lib.pl'; # Get and check the domain &can_edit_relay($in{'dom'}) || &error($text{'edit_ecannot'}); -$d = &virtual_server::get_domain_by("dom", $in{'dom'}); +my $d = &virtual_server::get_domain_by("dom", $in{'dom'}); $d || &error($text{'edit_edomain'}); -$relay = &get_relay_destination($in{'dom'}); +my $relay = &get_relay_destination($in{'dom'}); $relay || &error($text{'edit_erelay'}); # Validate inputs @@ -22,7 +25,7 @@ $in{'relay'} =~ /\S/ || &error($text{'save_enone'}); # Run the before command &virtual_server::set_domain_envs($d, "MODIFY_DOMAIN", $d); -$merr = &virtual_server::making_changes(); +my $merr = &virtual_server::making_changes(); &virtual_server::reset_domain_envs($d); &error(&virtual_server::text('save_emaking', "$merr")) if (defined($merr)); @@ -36,7 +39,7 @@ $merr = &virtual_server::making_changes(); &$virtual_server::second_print($virtual_server::text{'setup_done'}); if (&can_domain_filter() && defined($in{'filter'})) { - $old = &get_domain_filter($d->{'dom'}); + my $old = &get_domain_filter($d->{'dom'}); if ($in{'filter'} && !$old) { # Turn on spam filter &$virtual_server::first_print($text{'save_spamon'}); @@ -63,4 +66,3 @@ $merr = &virtual_server::made_changes(); &webmin_log("save", undef, $in{'dom'}); &ui_print_footer("edit.cgi?dom=$in{'dom'}", $text{'edit_return'}); - diff --git a/virtual_feature.pl b/virtual_feature.pl index b864e8a..23fe1a5 100755 --- a/virtual_feature.pl +++ b/virtual_feature.pl @@ -1,6 +1,10 @@ +use strict; +use warnings; +our (%text); +our $module_name; require 'virtualmin-mailrelay-lib.pl'; -$input_name = $module_name; +my $input_name = $module_name; $input_name =~ s/[^A-Za-z0-9]/_/g; # feature_name() @@ -22,7 +26,7 @@ sub feature_losing # editing form sub feature_label { -local ($edit) = @_; +my ($edit) = @_; return $edit ? $text{'feat_label2'} : $text{'feat_label'}; } @@ -44,16 +48,16 @@ sub feature_check &virtual_server::require_mail(); if ($virtual_server::config{'mail_system'} == 0) { # Check for Postfix transport map - local $trans = &postfix::get_real_value("transport_maps"); + my $trans = &postfix::get_real_value("transport_maps"); $trans || return $text{'feat_echecktrans'}; if (defined(&postfix::can_access_map)) { - local @tv = &postfix::get_maps_types_files("transport_maps"); + my @tv = &postfix::get_maps_types_files("transport_maps"); foreach my $tv (@tv) { if (!&postfix::supports_map_type($tv->[0])) { return &text('feat_echeckmap', "$tv->[0]:$tv->[1]"); } - local $err = &postfix::can_access_map(@$tv); + my $err = &postfix::can_access_map(@$tv); if ($err) { return &text('feat_echeckmapaccess', "$tv->[0]:$tv->[1]", $err); @@ -64,7 +68,7 @@ sub feature_check elsif ($virtual_server::config{'mail_system'} == 1) { # Check for Sendmail mailertable &foreign_require("sendmail", "mailers-lib.pl"); - local ($mdbm, $mtype) = &sendmail::mailers_dbm( + my ($mdbm, $mtype) = &sendmail::mailers_dbm( &sendmail::get_sendmailcf()); if (!$mdbm) { return $text{'feat_echeckmailertable'}; @@ -84,10 +88,10 @@ sub feature_check # Checks for a default master IP address in template. sub feature_depends { -local ($d, $oldd) = @_; +my ($d, $oldd) = @_; return $text{'feat_email'} if ($d->{'mail'}); -local $tmpl = &virtual_server::get_template($d->{'template'}); -local $mip = $d->{$module_name."server"} || +my $tmpl = &virtual_server::get_template($d->{'template'}); +my $mip = $d->{$module_name."server"} || $tmpl->{$module_name."server"}; if (!$oldd || !$oldd->{$module_name}) { return $text{'feat_eserver'} if ($mip eq '' || $mip eq 'none'); @@ -101,13 +105,13 @@ sub feature_depends # Checks for a mailertable entry on Sendmail sub feature_clash { -local ($d, $field) = @_; +my ($d, $field) = @_; return undef if ($field && $field ne "dom"); &virtual_server::require_mail(); if ($virtual_server::config{'mail_system'} == 0) { # Check for transport entry - local $trans = &postfix::get_maps("transport_maps"); - local ($clash) = grep { $_->{'name'} eq $_[0]->{'dom'} } @$trans; + my $trans = &postfix::get_maps("transport_maps"); + my ($clash) = grep { $_->{'name'} eq $_[0]->{'dom'} } @$trans; if ($clash) { return $text{'feat_eclashtrans'}; } @@ -115,9 +119,9 @@ sub feature_clash elsif ($virtual_server::config{'mail_system'} == 1) { # Check for mailertable entry &foreign_require("sendmail", "mailers-lib.pl"); - local $mfile = &sendmail::mailers_file(&sendmail::get_sendmailcf()); - local @mailers = &sendmail::list_mailers($mfile); - local ($clash) = grep { $_->{'domain'} eq $_[0]->{'dom'} } @mailers; + my $mfile = &sendmail::mailers_file(&sendmail::get_sendmailcf()); + my @mailers = &sendmail::list_mailers($mfile); + my ($clash) = grep { $_->{'domain'} eq $_[0]->{'dom'} } @mailers; if ($clash) { return $text{'feat_eclashmailertable'}; } @@ -130,7 +134,7 @@ sub feature_clash # parent and sub domains. sub feature_suitable { -local ($parentdom, $aliasdom, $subdom) = @_; +my ($parentdom, $aliasdom, $subdom) = @_; return 1; } @@ -139,9 +143,9 @@ sub feature_suitable # Adds a mailertable or transport entry sub feature_setup { -local ($d) = @_; -local $tmpl = &virtual_server::get_template($d->{'template'}); -local $server = $d->{$module_name."server"} || +my ($d) = @_; +my $tmpl = &virtual_server::get_template($d->{'template'}); +my $server = $d->{$module_name."server"} || $tmpl->{$module_name."server"}; &$virtual_server::first_print($text{'setup_relay'}); if (!$server) { @@ -153,20 +157,20 @@ sub feature_setup # Add relay for domain, using appropriate mail server if ($virtual_server::config{'mail_system'} == 0) { # Add SMTP transport - local $map = { 'name' => $d->{'dom'}, + my $map = { 'name' => $d->{'dom'}, 'value' => "smtp:[$server]" }; &postfix::create_mapping("transport_maps", $map); &postfix::regenerate_any_table("transport_maps"); } elsif ($virtual_server::config{'mail_system'} == 1) { # Add mailertable entry - local $map = { 'domain' => $d->{'dom'}, + my $map = { 'domain' => $d->{'dom'}, 'mailer' => 'smtp', 'dest' => "[$server]" }; &foreign_require("sendmail", "mailers-lib.pl"); - local $conf = &sendmail::get_sendmailcf(); - local ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); - local $mfile = &sendmail::mailers_file($conf); + my $conf = &sendmail::get_sendmailcf(); + my ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); + my $mfile = &sendmail::mailers_file($conf); &sendmail::create_mailer($map, $mfile, $mdbm, $mtype); } @@ -188,19 +192,19 @@ sub feature_setup &virtual_server::obtain_lock_dns($d, 1); } - local $z = &virtual_server::get_bind_zone($d->{'dom'}); - local $file = &bind8::find("file", $z->{'members'}); - local $fn = $file->{'values'}->[0]; - local $zonefile = &bind8::make_chroot($fn); - local @recs = &bind8::read_zone_file($fn, $d->{'dom'}); - local ($mx) = grep { $_->{'type'} eq 'MX' && + my $z = &virtual_server::get_bind_zone($d->{'dom'}); + my $file = &bind8::find("file", $z->{'members'}); + my $fn = $file->{'values'}->[0]; + my $zonefile = &bind8::make_chroot($fn); + my @recs = &bind8::read_zone_file($fn, $d->{'dom'}); + my ($mx) = grep { $_->{'type'} eq 'MX' && $_->{'name'} eq $d->{'dom'}."." || $_->{'type'} eq 'A' && $_->{'name'} eq "mail.".$d->{'dom'}."." } @recs; if (!$mx) { &$virtual_server::first_print( $virtual_server::text{'save_dns4'}); - local $ip = $d->{'dns_ip'} || $d->{'ip'}; + my $ip = $d->{'dns_ip'} || $d->{'ip'}; &virtual_server::create_mx_records($fn, $d, $ip); &bind8::bump_soa_record($fn, \@recs); &$virtual_server::second_print( @@ -223,7 +227,7 @@ sub feature_setup # Renames the mailertable or transport entry sub feature_modify { -local ($d, $oldd) = @_; +my ($d, $oldd) = @_; if ($d->{'dom'} ne $oldd->{'dom'}) { &$virtual_server::first_print($text{'modify_relay'}); &obtain_lock_virtualmin_mailrelay($d); @@ -231,10 +235,10 @@ sub feature_modify # Modify for domain, using appropriate mail server if ($virtual_server::config{'mail_system'} == 0) { # Change SMTP transport - local $trans = &postfix::get_maps("transport_maps"); - local ($old) = grep { $_->{'name'} eq $oldd->{'dom'} } @$trans; + my $trans = &postfix::get_maps("transport_maps"); + my ($old) = grep { $_->{'name'} eq $oldd->{'dom'} } @$trans; if ($old) { - local $nw = { %$old }; + my $nw = { %$old }; $nw->{'name'} = $d->{'dom'}; &postfix::modify_mapping("transport_maps", $old, $nw); &postfix::regenerate_any_table("transport_maps"); @@ -249,14 +253,14 @@ sub feature_modify elsif ($virtual_server::config{'mail_system'} == 1) { # Change mailertable entry &foreign_require("sendmail", "mailers-lib.pl"); - local $conf = &sendmail::get_sendmailcf(); - local $mfile = &sendmail::mailers_file($conf); - local ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); - local @mailers = &sendmail::list_mailers($mfile); - local ($old) = grep { $_->{'domain'} eq $oldd->{'dom'} } + my $conf = &sendmail::get_sendmailcf(); + my $mfile = &sendmail::mailers_file($conf); + my ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); + my @mailers = &sendmail::list_mailers($mfile); + my ($old) = grep { $_->{'domain'} eq $oldd->{'dom'} } @mailers; if ($old) { - local $nw = { %$old }; + my $nw = { %$old }; $nw->{'domain'} = $d->{'dom'}; &sendmail::modify_mailer($old, $nw, $mfile, $mdbm, $mtype); @@ -275,7 +279,7 @@ sub feature_modify # Change domain name to filter if (&can_domain_filter()) { - local $filter = &get_domain_filter($oldd->{'dom'}); + my $filter = &get_domain_filter($oldd->{'dom'}); &save_domain_filter($oldd->{'dom'}, 0); &save_domain_filter($d->{'dom'}, $filter); } @@ -291,15 +295,15 @@ sub feature_modify # Called when this feature is disabled, or when the domain is being deleted sub feature_delete { -local ($d) = @_; +my ($d) = @_; &$virtual_server::first_print($text{'delete_relay'}); &obtain_lock_virtualmin_mailrelay($d); # Delete for domain, using appropriate mail server if ($virtual_server::config{'mail_system'} == 0) { # Delete SMTP transport - local $trans = &postfix::get_maps("transport_maps"); - local ($old) = grep { $_->{'name'} eq $d->{'dom'} } @$trans; + my $trans = &postfix::get_maps("transport_maps"); + my ($old) = grep { $_->{'name'} eq $d->{'dom'} } @$trans; if ($old) { &postfix::delete_mapping("transport_maps", $old); &postfix::regenerate_any_table("transport_maps"); @@ -313,11 +317,11 @@ sub feature_delete elsif ($virtual_server::config{'mail_system'} == 1) { # Change mailertable entry &foreign_require("sendmail", "mailers-lib.pl"); - local $conf = &sendmail::get_sendmailcf(); - local $mfile = &sendmail::mailers_file($conf); - local ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); - local @mailers = &sendmail::list_mailers($mfile); - local ($old) = grep { $_->{'domain'} eq $d->{'dom'} } + my $conf = &sendmail::get_sendmailcf(); + my $mfile = &sendmail::mailers_file($conf); + my ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); + my @mailers = &sendmail::list_mailers($mfile); + my ($old) = grep { $_->{'domain'} eq $d->{'dom'} } @mailers; if ($old) { &sendmail::delete_mailer($old, $mfile, $mdbm, $mtype); @@ -338,14 +342,14 @@ sub feature_delete } &release_lock_virtualmin_mailrelay($d); -# Remove MX records, if any +# Remove MX records, if any if ($d->{'dns'}) { - local $z = &virtual_server::get_bind_zone($d->{'dom'}); - local $file = &bind8::find("file", $z->{'members'}); - local $fn = $file->{'values'}->[0]; - local $zonefile = &bind8::make_chroot($fn); - local @recs = &bind8::read_zone_file($fn, $newzonename); - local @mx = grep { $_->{'type'} eq 'MX' && + my $z = &virtual_server::get_bind_zone($d->{'dom'}); + my $file = &bind8::find("file", $z->{'members'}); + my $fn = $file->{'values'}->[0]; + my $zonefile = &bind8::make_chroot($fn); + my @recs = &bind8::read_zone_file($fn, $newzonename); + my @mx = grep { $_->{'type'} eq 'MX' && $_->{'name'} eq $_[0]->{'dom'}."." || $_->{'type'} eq 'A' && $_->{'name'} eq "mail.".$_[0]->{'dom'}."." } @recs; @@ -377,8 +381,8 @@ sub feature_inputs_show # Returns a field for destination mail server sub feature_inputs { -local ($d) = @_; -local $tmpl = &virtual_server::get_template($d ? $d->{'template'} : 0); +my ($d) = @_; +my $tmpl = &virtual_server::get_template($d ? $d->{'template'} : 0); return &ui_table_row($text{'feat_server'}, &ui_opt_textbox($input_name."_server", $tmpl->{$module_name."server"}, 30, @@ -389,7 +393,7 @@ sub feature_inputs # Update the domain object with a custom destination mail server sub feature_inputs_parse { -local ($d, $in) = @_; +my ($d, $in) = @_; if (defined($in->{$input_name."_server"}) && !$in->{$input_name."_server_def"}) { &to_ipaddress($in->{$input_name."_server"}) || @@ -414,7 +418,7 @@ sub feature_args # Parse command-line arguments from feature_args sub feature_args_parse { -local ($d, $args) = @_; +my ($d, $args) = @_; if (defined($args->{$module_name."-server"})) { &to_ipaddress($args->{$module_name."-server"}) || return "Invalid mail server for relaying"; @@ -430,9 +434,9 @@ sub feature_args_parse # or 0 if not sub feature_import { -local ($dname, $user, $db) = @_; -local $fake = { 'dom' => $dname }; -local $err = &feature_clash($fake); +my ($dname, $user, $db) = @_; +my $fake = { 'dom' => $dname }; +my $err = &feature_clash($fake); return $err ? 1 : 0; } @@ -440,7 +444,7 @@ sub feature_import # Returns an array of link objects for webmin modules for this feature sub feature_links { -local ($d) = @_; +my ($d) = @_; return ( { 'mod' => $module_name, 'desc' => $text{'links_link'}, 'page' => 'edit.cgi?dom='.$d->{'dom'}, @@ -453,7 +457,7 @@ sub feature_links # the Webmin user when this feature is enabled sub feature_webmin { -local @doms = map { $_->{'dom'} } grep { $_->{$module_name} } @{$_[1]}; +my @doms = map { $_->{'dom'} } grep { $_->{$module_name} } @{$_[1]}; if (@doms) { return ( [ $module_name, { 'dom' => join(" ", @doms), @@ -475,9 +479,9 @@ sub feature_modules # Just saves the relay dest and spam flag sub feature_backup { -local ($d, $file) = @_; +my ($d, $file) = @_; &$virtual_server::first_print($text{'backup_conf'}); -local %binfo; +my %binfo; $binfo{'dest'} = &get_relay_destination($d->{'dom'}); if (&can_domain_filter()) { $binfo{'filter'} = &get_domain_filter($d->{'dom'}); @@ -494,10 +498,10 @@ sub feature_backup # Just re-sets the old relay dest and spam filter sub feature_restore { -local ($d, $file) = @_; +my ($d, $file) = @_; &$virtual_server::first_print($text{'restore_conf'}); &obtain_lock_virtualmin_mailrelay($d); -local %binfo; +my %binfo; &read_file($file, \%binfo); if ($binfo{'dest'} ne '') { &save_relay_destination($d->{'dom'}, $binfo{'dest'}); @@ -523,7 +527,7 @@ sub feature_backup_name # Checks that the mailertable or transport entry exists sub feature_validate { -local ($d) = @_; +my ($d) = @_; if (!&feature_clash($d)) { return $virtual_server::config{'mail_system'} == 0 ? $text{'validate_etransport'} : @@ -536,12 +540,12 @@ sub feature_validate # Returns HTML for editing per-template options for this plugin sub template_input { -local ($tmpl) = @_; +my ($tmpl) = @_; # Default SMTP server input -local $v = $tmpl->{$module_name."server"}; +my $v = $tmpl->{$module_name."server"}; $v = "none" if (!defined($v) && $tmpl->{'default'}); -local $rv; +my $rv; $rv .= &ui_table_row($text{'tmpl_server'}, &ui_radio($input_name."_mode", $v eq "" ? 0 : $v eq "none" ? 1 : 2, @@ -552,7 +556,7 @@ sub template_input # Default filter mode, if possible if (&can_domain_filter()) { - local $v = $tmpl->{$module_name."filter"}; + my $v = $tmpl->{$module_name."filter"}; $v = "no" if (!defined($v) && $tmpl->{'default'}); $rv .= &ui_table_row($text{'tmpl_filter'}, &ui_radio($input_name."_filter", @@ -570,7 +574,7 @@ sub template_input # template_input. All template fields must start with the module name. sub template_parse { -local ($tmpl, $in) = @_; +my ($tmpl, $in) = @_; # Parse SMTP server field if ($in->{$input_name.'_mode'} == 0) { @@ -594,4 +598,3 @@ sub template_parse } 1; - diff --git a/virtualmin-mailrelay-lib.pl b/virtualmin-mailrelay-lib.pl index 8080b8e..dbad691 100755 --- a/virtualmin-mailrelay-lib.pl +++ b/virtualmin-mailrelay-lib.pl @@ -1,14 +1,18 @@ # Common functions needed for forwarded mail filtering +use strict; +use warnings; +our (%text, %config); +our $module_name; BEGIN { push(@INC, ".."); }; eval "use WebminCore;"; &init_config(); &foreign_require('virtual-server', 'virtual-server-lib.pl'); -%access = &get_module_acl(); +our %access = &get_module_acl(); sub can_edit_relay { -local ($dname) = @_; +my ($dname) = @_; if ($access{'dom'} eq '*') { return 1; } @@ -45,21 +49,21 @@ sub check_spam_filter $virtual_server::config{'mail_system'} == 1 || return $text{'defang_esendmail'}; &foreign_require("sendmail", "features-lib.pl"); - local @feats = &sendmail::list_features(); + my @feats = &sendmail::list_features(); if (@feats) { - local ($mdf) = grep { + my ($mdf) = grep { $_->{'text'} =~ /INPUT_MAIL_FILTER.*mimedefang/ } @feats; $mdf || return &text('defang_efeature', "$config{'sendmail_mc'}"); } - local @pids = &find_byname("mimedefang.pl"); + my @pids = &find_byname("mimedefang.pl"); @pids || return $text{'defang_eprocess'}; -r $config{'mimedefang_script'} || return &text('defang_escript', "$config{'mimedefang_script'}", "../config.cgi?$module_name"); if ($config{'domains_file'}) { - local $lref = &read_file_lines($config{'mimedefang_script'}, 1); - local $found = 0; + my $lref = &read_file_lines($config{'mimedefang_script'}, 1); + my $found = 0; foreach my $l (@$lref) { $found++ if ($l =~ /\Q$config{'domains_file'}\E/); } @@ -79,12 +83,12 @@ sub check_spam_filter # Returns the SMTP server to relay email to for some domain sub get_relay_destination { -local ($dname) = @_; +my ($dname) = @_; &virtual_server::require_mail(); if ($virtual_server::config{'mail_system'} == 0) { # From SMTP transport - local $trans = &postfix::get_maps("transport_maps"); - local ($old) = grep { $_->{'name'} eq $dname } @$trans; + my $trans = &postfix::get_maps("transport_maps"); + my ($old) = grep { $_->{'name'} eq $dname } @$trans; if ($old) { if ($old->{'value'} =~ /^\S+:\[(\S+)\]$/) { return $1; @@ -104,11 +108,11 @@ sub get_relay_destination elsif ($virtual_server::config{'mail_system'} == 1) { # Get mailertable entry &foreign_require("sendmail", "mailers-lib.pl"); - local $conf = &sendmail::get_sendmailcf(); - local $mfile = &sendmail::mailers_file($conf); - local ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); - local @mailers = &sendmail::list_mailers($mfile); - local ($old) = grep { $_->{'domain'} eq $dname } @mailers; + my $conf = &sendmail::get_sendmailcf(); + my $mfile = &sendmail::mailers_file($conf); + my ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); + my @mailers = &sendmail::list_mailers($mfile); + my ($old) = grep { $_->{'domain'} eq $dname } @mailers; if ($old) { if ($old->{'dest'} =~ /^\[(\S+)\]$/) { return $1; @@ -125,15 +129,15 @@ sub get_relay_destination # Updates the SMTP server to relay email to for some domain sub save_relay_destination { -local ($dname, $server) = @_; +my ($dname, $server) = @_; &virtual_server::require_mail(); &obtain_lock_virtualmin_mailrelay(); if ($virtual_server::config{'mail_system'} == 0) { # Update Postfix SMTP transport - local $trans = &postfix::get_maps("transport_maps"); - local ($old) = grep { $_->{'name'} eq $dname } @$trans; + my $trans = &postfix::get_maps("transport_maps"); + my ($old) = grep { $_->{'name'} eq $dname } @$trans; if ($old) { - local $nw = { %$old }; + my $nw = { %$old }; if ($old->{'value'} =~ /^(\S+):\[(\S+)\]$/) { my $lhs = $1; if ($server =~ /^(.*):(\d+)$/) { @@ -157,13 +161,13 @@ sub save_relay_destination elsif ($virtual_server::config{'mail_system'} == 1) { # Get Sendmail mailertable entry &foreign_require("sendmail", "mailers-lib.pl"); - local $conf = &sendmail::get_sendmailcf(); - local $mfile = &sendmail::mailers_file($conf); - local ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); - local @mailers = &sendmail::list_mailers($mfile); - local ($old) = grep { $_->{'domain'} eq $dname } @mailers; + my $conf = &sendmail::get_sendmailcf(); + my $mfile = &sendmail::mailers_file($conf); + my ($mdbm, $mtype) = &sendmail::mailers_dbm($conf); + my @mailers = &sendmail::list_mailers($mfile); + my ($old) = grep { $_->{'domain'} eq $dname } @mailers; if ($old) { - local $nw = { %$old }; + my $nw = { %$old }; if ($old->{'dest'} =~ /^\[(\S+)\]$/) { $nw->{'dest'} = "[$server]"; } @@ -181,8 +185,8 @@ sub save_relay_destination # Return 1 if relay filtering is enabled for a domain sub get_domain_filter { -local ($dname) = @_; -local $lref = &read_file_lines($config{'domains_file'}, 1); +my ($dname) = @_; +my $lref = &read_file_lines($config{'domains_file'}, 1); return &indexoflc($dname, @$lref) >= 0 ? 1 : 0; } @@ -190,9 +194,9 @@ sub get_domain_filter # Turns on or off relay filtering for a domain sub save_domain_filter { -local ($dname, $filter) = @_; -local $lref = &read_file_lines($config{'domains_file'}); -local $idx = &indexoflc($dname, @$lref); +my ($dname, $filter) = @_; +my $lref = &read_file_lines($config{'domains_file'}); +my $idx = &indexoflc($dname, @$lref); if ($idx >= 0 && !$filter) { # Remove from file splice(@$lref, $idx, 1); @@ -216,14 +220,14 @@ sub obtain_lock_virtualmin_mailrelay @main::got_lock_virtualmin_mailrelay_files = ( ); if ($virtual_server::config{'mail_system'} == 0) { # Lock transport file - local @tv = &postfix::get_maps_types_files("transport_maps"); + my @tv = &postfix::get_maps_types_files("transport_maps"); push(@main::got_lock_virtualmin_mailrelay_files, map { $_->[1] } @tv); } elsif ($virtual_server::config{'mail_system'} == 1) { # Lock mailertable file &foreign_require("sendmail", "mailers-lib.pl"); - local $mfile = &sendmail::mailers_file( + my $mfile = &sendmail::mailers_file( &sendmail::get_sendmailcf()); push(@main::got_lock_virtualmin_mailrelay_files, $mfile); } @@ -267,13 +271,13 @@ sub supports_mail_queue # Returns queued messages for some domain sub list_mail_queue { -local ($d) = @_; -local $re = "\@".$d->{'dom'}; +my ($d) = @_; +my $re = "\@".$d->{'dom'}; if ($virtual_server::config{'mail_system'} == 0) { # Get from Postfix &foreign_require("postfix"); - local @qfiles = &postfix::list_queue(); - local @rv; + my @qfiles = &postfix::list_queue(); + my @rv; foreach my $q (@qfiles) { if ($q->{'to'} =~ /\Q$re\E/) { $q->{'date'} ||= &make_date($q->{'time'}); @@ -285,11 +289,11 @@ sub list_mail_queue elsif ($virtual_server::config{'mail_system'} == 1) { # Get from Sendmail &foreign_require("sendmail"); - local $conf = &sendmail::get_sendmailcf(); - local @qfiles = &sendmail::list_mail_queue($conf); - local @queue = grep { $_->{'header'}->{'to'} =~ /\Q$re\E/ } + my $conf = &sendmail::get_sendmailcf(); + my @qfiles = &sendmail::list_mail_queue($conf); + my @queue = grep { $_->{'header'}->{'to'} =~ /\Q$re\E/ } map { &sendmail::mail_from_queue($_) } @qfiles; - local @rv; + my @rv; foreach my $q (@queue) { push(@rv, { 'from' => $q->{'header'}->{'from'}, 'to' => $q->{'header'}->{'to'}, @@ -305,4 +309,3 @@ sub list_mail_queue } 1; -