-
-
Save nuxwin/3dfbcbbace0d8ab798db3b1983d86728 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# i-MSCP Listener::Named::NotifySecondary listener file | |
# Copyright (C) 2016 Marc Pujol <[email protected]> | |
# | |
# 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 | |
# | |
## Notifies a secondary server using using the bdns protocol | |
# | |
package Listener::Named::NotifySecondary; | |
use vars('$serial'); | |
use strict; | |
use warnings; | |
use iMSCP::EventManager; | |
use Data::Dumper; | |
use LWP::UserAgent; | |
use HTTP::Request; | |
# | |
## Configuration settings: change this! | |
# | |
my $port = 54515; # Port where bdns is listening | |
my $verify = 1; # Whether to validate the server's certificate or not | |
my $username = 'client1'; # Bdns username | |
my $password = 'password1'; # Bdns password | |
# List of secondary servers to manage | |
my @secondaries = ( | |
'your.secondary.server' | |
); | |
# | |
## Actual listener, do not modify above this line unless you know what you are doing | |
# | |
$Listener::Named::NotifySecondary::serial = 1; | |
sub out { | |
my ( $file, $aoh_ref ) = @_; | |
open my $fh, '>', $file | |
or die "Can't write '$file': $!"; | |
local $Data::Dumper::Terse = 1; # no '$VAR1 = ' | |
local $Data::Dumper::Useqq = 1; # double quoted strings | |
print $fh Dumper $aoh_ref; | |
close $fh or die "Can't close '$file': $!"; | |
} | |
sub notify { | |
my ($action, $zone) = @_; | |
for my $secondary(@secondaries) { | |
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => $verify }); | |
my $req = HTTP::Request->new(GET => "https://$secondary:$port/$action/$zone"); | |
$req->authorization_basic($username, $password); | |
my $res = $ua->request($req); | |
if (!$res->is_success) { | |
print $res->content; | |
} | |
} | |
} | |
iMSCP::EventManager->getInstance()->register('afterNamedAddDmn', sub { | |
#out('/tmp/dump.'.$$.'.afterNamedAddDmn', \@_); | |
my $data = shift; | |
if ($data->{"CTM_ALS_ENTRY_ADD"} || $data->{"CTM_ALS_ENTRY_DEL"}) { | |
return 0; | |
} | |
notify('add', $data->{"DOMAIN_NAME"}); | |
0; | |
}); | |
iMSCP::EventManager->getInstance()->register('afterNamedDelDmn', sub { | |
#out('/tmp/dump.'.$$.'.beforeNamedDelDmn', \@_); | |
my $data = shift; | |
notify('remove', $data->{"DOMAIN_NAME"}); | |
0; | |
}); | |
1; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment