Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # i-MSCP Listener::Named::AddMxDNSRecords listener file
- # Copyright (C) 2015 UncleJ, Arthur Mayer <mayer.arthur@gmail.com>
- #
- # This library is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 2.1 of the License, or (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with this library; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- #
- ## i-MSCP listener file modifies the zone files, adds custom out-of-zone MX DNS entries
- #
- package Listener::Named::AddMxDNSRecords;
- use iMSCP::EventManager;
- use iMSCP::TemplateParser;
- #
- ## Configuration variables
- #
- # Define here your out-of-zone backup-mx mail-servers
- # Please replace the entries below by your own entries
- my %perDomainAdditionalMailservers = (
- 'testdomain.local' => {
- 'mx40' => '40'
- },
- '<domain1.tld>' => {
- '<mx1-name>' => '<mx1-priority>',
- '<mx2-name>' => '<mx2-priority>'
- },
- '<domain2.tld>' => {
- '<mx1-name>' => '<mx1-priority>',
- '<mx2-name>' => '<mx2-priority>'
- }
- );
- # Please replace the entries below by your own entries
- my %additionalMailservers = ( 'mx50' => '50' );
- #
- ## Please, don't edit anything below this line
- #
- sub addMxDNSrecords
- {
- my ($tplDbFileContent, $data) = @_;
- my %mxServerEntries;
- if(exists $perDomainAdditionalMailservers{$data->{'DOMAIN_NAME'}}) {
- %mxServerEntries = (%additionalMailservers, %{$perDomainAdditionalMailservers{$data->{'DOMAIN_NAME'}});
- } else {
- %mxServerEntries = %additionalMailservers;
- }
- if(%mxServerEntries) {
- my @formattedEntries = ('; custom MX DNS entries BEGIN');
- while(my($mxHost, $mxPriority) = each(%mxServerEntries)) {
- push @formattedEntries, sprintf("@\tIN\tMX\t%s %s", $mxHost, $mxPriority);
- }
- undef %mxServerEntries;
- push @formattedEntries, '; custom MX DNS entries ENDING';
- $$tplDbFileContent = replaceBloc(
- "; dmn MAIL entry BEGIN\n",
- "; dmn MAIL entry ENDING\n",
- "; dmn MAIL entry BEGIN\n" .
- getBloc(
- "; dmn MAIL entry BEGIN\n",
- ";dmn MAIL entry ENDING\n",
- $$tplDbFileContent
- ) .
- join("\n", @formattedEntries) . "\n" .
- "; dmn MAIL entry ENDING\n",
- $$tplDbFileContent
- );
- }
- 0;
- }
- sub addMxDNSrecordsSub
- {
- my ($wrkDbFileContent, $subEntry, $data) = @_;
- my %mxServerEntries;
- if(exists $perDomainAdditionalMailservers{$data->{'DOMAIN_NAME'}}) {
- %mxServerEntries = (%additionalMailservers, %{$perDomainAdditionalMailservers{$data->{'DOMAIN_NAME'}});
- } else {
- %mxServerEntries = %additionalMailservers;
- }
- if(%mxServerEntries) {
- my @formattedEntries = ('; custom MX DNS entries BEGIN');
- while(my($mxHost, $mxPriority) = each(%mxServerEntries)) {
- push @formattedEntries, sprintf("@\tIN\tMX\t%s %s", $mxHost, $mxPriority);
- }
- undef %mxServerEntries;
- push @formattedEntries, '; custom MX DNS entries ENDING';
- $$subEntry = replaceBloc(
- "; sub MX entry BEGIN\n",
- "; sub MX entry ENDING\n",
- "; sub MX entry BEGIN\n" .
- getBloc(
- "; sub MX entry BEGIN\n",
- "; sub MX entry ENDING\n",
- $$subEntry
- ) .
- join("\n", @formattedEntries) . "\n" .
- "; sub MX entry ENDING\n",
- $$subEntry
- );
- }
- 0;
- }
- my $eventManager = iMSCP::EventManager->getInstance();
- $eventManager->register('beforeNamedAddDmnDb', \&addMxDNSrecords);
- $eventManager->register('beforeNamedAddSub', \&addMxDNSrecordsSub);
- 1;
- __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement