Code
- package Listener::Apache2::DualStack;
- use strict;
- use warnings;
- use iMSCP::EventManager;
- use iMSCP::Net;
- use List::MoreUtils qw(uniq);
- # Port to use for http
- my $httpPort = 80;
- # Port to use for https
- my $httpsPort = 443;
- my %perDomainAdditionalIPs = (
- );
- my @additionalIPs = ( '####IPV6ADDRESSHERE####', );
- my @IPS = ();
- my @SSL_IPS = ();
- sub addIPs
- {
- my ($cfgTpl, $tplName, $data) = @_;
- return 0 unless exists $data->{'DOMAIN_NAME'} && $tplName =~ /^domain(?:_(?:disabled|redirect))?(_ssl)?\.tpl$/;
- my $sslVhost = defined $1;
- my $port = $sslVhost ? $httpsPort : $httpPort;
- my $net = iMSCP::Net->getInstance();
- # All vhost IPs and per domain IPS
- my @ipList = uniq map { $net->normalizeAddr( $_ ) } grep {
- $net->getAddrType( $_ ) =~ /^(?:PRIVATE|UNIQUE-LOCAL-UNICAST|PUBLIC|GLOBAL-UNICAST)$/
- } (
- @additionalIPs,
- ($perDomainAdditionalIPs{$data->{'DOMAIN_NAME'}} ? @{$perDomainAdditionalIPs{$data->{'DOMAIN_NAME'}}} : ())
- );
- return 0 unless @ipList;
- my @formattedIPs = ();
- for my $ip(@ipList) {
- if ($net->getAddrVersion( $ip ) eq 'ipv6') {
- push @formattedIPs, "[$ip]:$port";
- } else {
- push @formattedIPs, "$ip:$port";
- }
- }
- $$cfgTpl =~ s/(<VirtualHost.*?)>/$1 @formattedIPs>/;
- undef @formattedIPs;
- unless ($sslVhost) {
- @IPS = uniq( @IPS, @ipList );
- } else {
- @SSL_IPS = uniq( @SSL_IPS, @ipList );
- }
- 0;
- }
- # Listener responsible to make the Httpd server implementation aware of additional IPs
- sub addIPList
- {
- my $data = $_[1];
- @{$data->{'IPS'}} = uniq( @{$data->{'IPS'}}, @IPS );
- @{$data->{'SSL_IPS'}} = uniq( @{$data->{'SSL_IPS'}}, @SSL_IPS );
- 0;
- }
- my $eventManager = iMSCP::EventManager->getInstance();
- $eventManager->register( 'afterHttpdBuildConfFile', \&addIPs );
- $eventManager->register( 'beforeHttpdAddIps', \&addIPList );
- 1;
- __END__
I use this to add an additional IPv6 address. Looks like it works, only ssl port is wrong in *_ssl.conf files.