Skip to content

Commit

Permalink
Fixed: Skip cleanup of custom.conf.tpl, index.html, vlogger.conf.tpl …
Browse files Browse the repository at this point in the history
…and php-fcgi-starter template files (HTTPD servers)
  • Loading branch information
nuxwin committed Dec 31, 2016
1 parent 7653981 commit 4fbfa79
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -31,6 +31,7 @@ INSTALLER

SERVERS
Fixed: Path must be cleaned before use in regexes (HTTPD servers)
Fixed: Skip cleanup of custom.conf.tpl, index.html, vlogger.conf.tpl and php-fcgi-starter template files (HTTPD servers)

YOUTRACK
#IP-1679 Duplicate bind mounts leading to un-deletable Web folders (Ubuntu < 16.04)
Expand Down
21 changes: 14 additions & 7 deletions engine/PerlLib/Servers/httpd/apache_fcgid.pm
Expand Up @@ -347,6 +347,7 @@ sub disableDmn

# Ensure that custom httpd conffile exists (cover case where file has been removed for any reasons)
unless (-f "$self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}/$data->{'DOMAIN_NAME'}.conf") {
$data->{'SKIP_TEMPLATE_CLEANER'} = 1;
$rs = $self->buildConfFile(
"$self->{'apacheTplDir'}/custom.conf.tpl",
$data,
Expand Down Expand Up @@ -875,7 +876,7 @@ sub buildConfFile
return $rs if $rs;

unless (defined $cfgTpl) {
$file = "$self->{'apacheCfgDir'}/$file" unless -d $path && $path ne './';
$file = File::Spec->canonpath("$self->{'apacheCfgDir'}/$filename") if $path eq './';
$cfgTpl = iMSCP::File->new( filename => $file )->get();
unless (defined $cfgTpl) {
error( sprintf( 'Could not read %s file', $file ) );
Expand Down Expand Up @@ -1487,6 +1488,7 @@ sub _addCfg
}

unless (-f "$self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}/$data->{'DOMAIN_NAME'}.conf") {
$data->{'SKIP_TEMPLATE_CLEANER'} = 1;
$rs = $self->buildConfFile(
"$self->{'apacheTplDir'}/custom.conf.tpl",
$data,
Expand Down Expand Up @@ -1576,6 +1578,7 @@ sub _addFiles
if (-d "$tmpDir/htdocs") {
# Test needed in case admin removed the index.html file from the skeleton
if (-f "$tmpDir/htdocs/index.html") {
$data->{SKIP_TEMPLATE_CLEANER} = 1;
my $fileSource = "$tmpDir/htdocs/index.html";
$rs = $self->buildConfFile( $fileSource, $data, { destination => $fileSource } );
return $rs if $rs;
Expand Down Expand Up @@ -1817,6 +1820,8 @@ sub _buildPHPConfig
}
);

$data->{'SKIP_TEMPLATE_CLEANER'} = 1;

$rs = $self->buildConfFile(
"$self->{'phpCfgDir'}/fcgi/php-fcgi-starter",
$data,
Expand Down Expand Up @@ -1865,6 +1870,11 @@ sub _cleanTemplate
{
my (undef, $tpl, $name, $data) = @_;

if ($data->{'SKIP_TEMPLATE_CLEANER'}) {
delete $data->{'SKIP_TEMPLATE_CLEANER'};
return 0;
}

if ($name =~ /^domain(?:_ssl)?\.tpl$/) {
unless ($data->{'CGI_SUPPORT'} eq 'yes') {
${$tpl} = replaceBloc( "# SECTION cgi_support BEGIN.\n", "# SECTION cgi_support END.\n", '', ${$tpl} );
Expand All @@ -1878,7 +1888,6 @@ sub _cleanTemplate

${$tpl} = replaceBloc( "# SECTION itk BEGIN.\n", "# SECTION itk END.\n", '', ${$tpl} );
${$tpl} = replaceBloc("# SECTION php_fpm BEGIN.\n", "# SECTION php_fpm END.\n", '', ${$tpl});
${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;
} elsif ($name =~ /^domain(?:_disabled|_redirect)?(_ssl)?\.tpl$/) {
my $isSSLVhost = defined $1;

Expand All @@ -1887,7 +1896,7 @@ sub _cleanTemplate
${$tpl} = replaceBloc(
"# SECTION standard_redirect BEGIN.\n", "# SECTION standard_redirect END.\n", '', ${$tpl}
);
if ($data->{'FORWARD'} !~ /^https/) {
if (index($data->{'FORWARD'}, 'https') != 0) {
${$tpl} = replaceBloc("# SECTION ssl_proxy BEGIN.\n", "# SECTION ssl_proxy END.\n", '', ${$tpl});
}
} else {
Expand All @@ -1902,12 +1911,10 @@ sub _cleanTemplate
if ($isSSLVhost && !$data->{'HSTS_SUPPORT'}) {
${$tpl} = replaceBloc( "# SECTION hsts BEGIN.\n", "# SECTION hsts END.\n", '', ${$tpl} );
}

${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;
} else {
${$tpl} =~ s/^\s*(?:;.*)?\n//gmi;
}

${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;

0;
}

Expand Down
2 changes: 1 addition & 1 deletion engine/PerlLib/Servers/httpd/apache_fcgid/installer.pm
Expand Up @@ -627,7 +627,7 @@ sub _setupVlogger

$self->{'httpd'}->buildConfFile(
"$self->{'apacheCfgDir'}/vlogger.conf.tpl",
{ },
{ SKIP_TEMPLATE_CLEANER => 1 },
{ destination => "$self->{'apacheCfgDir'}/vlogger.conf" }
);
}
Expand Down
19 changes: 12 additions & 7 deletions engine/PerlLib/Servers/httpd/apache_itk.pm
Expand Up @@ -347,6 +347,7 @@ sub disableDmn

# Ensure that custom httpd conffile exists (cover case where file has been removed for any reasons)
unless (-f "$self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}/$data->{'DOMAIN_NAME'}.conf") {
$data->{'SKIP_TEMPLATE_CLEANER'} = 1;
$rs = $self->buildConfFile(
"$self->{'apacheTplDir'}/custom.conf.tpl",
$data,
Expand Down Expand Up @@ -871,7 +872,7 @@ sub buildConfFile
return $rs if $rs;

unless (defined $cfgTpl) {
$file = "$self->{'apacheCfgDir'}/$file" unless -d $path && $path ne './';
$file = File::Spec->canonpath("$self->{'apacheCfgDir'}/$filename") if $path eq './';
$cfgTpl = iMSCP::File->new( filename => $file )->get();
unless (defined $cfgTpl) {
error( sprintf( 'Could not read %s file', $file ) );
Expand Down Expand Up @@ -1481,6 +1482,7 @@ sub _addCfg
}

unless (-f "$self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}/$data->{'DOMAIN_NAME'}.conf") {
$data->{'SKIP_TEMPLATE_CLEANER'} = 1;
$rs = $self->buildConfFile(
"$self->{'apacheTplDir'}/custom.conf.tpl",
$data,
Expand Down Expand Up @@ -1569,6 +1571,7 @@ sub _addFiles
if (-d "$tmpDir/htdocs") {
# Test needed in case admin removed the index.html file from the skeleton
if (-f "$tmpDir/htdocs/index.html") {
$data->{SKIP_TEMPLATE_CLEANER} = 1;
my $fileSource = "$tmpDir/htdocs/index.html";
$rs = $self->buildConfFile( $fileSource, $data, { destination => $fileSource } );
return $rs if $rs;
Expand Down Expand Up @@ -1755,6 +1758,11 @@ sub _cleanTemplate
{
my (undef, $tpl, $name, $data) = @_;

if ($data->{'SKIP_TEMPLATE_CLEANER'}) {
delete $data->{'SKIP_TEMPLATE_CLEANER'};
return 0;
}

if ($name =~ /^domain(?:_ssl)?\.tpl$/) {
${$tpl} = replaceBloc( "# SECTION suexec BEGIN.\n", "# SECTION suexec END.\n", '', ${$tpl} );

Expand All @@ -1770,7 +1778,6 @@ sub _cleanTemplate

${$tpl} = replaceBloc( "# SECTION fcgid BEGIN.\n", "# SECTION fcgid END.\n", '', ${$tpl} );
${$tpl} = replaceBloc("# SECTION php_fpm BEGIN.\n", "# SECTION php_fpm END.\n", '', ${$tpl});
${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;
} elsif ($name =~ /^domain(?:_disabled|_redirect)?(_ssl)?\.tpl$/) {
my $isSSLVhost = defined $1;

Expand All @@ -1779,7 +1786,7 @@ sub _cleanTemplate
${$tpl} = replaceBloc(
"# SECTION standard_redirect BEGIN.\n", "# SECTION standard_redirect END.\n", '', ${$tpl}
);
if ($data->{'FORWARD'} !~ /^https/) {
if (index($data->{'FORWARD'}, 'https') != 0) {
${$tpl} = replaceBloc("# SECTION ssl_proxy BEGIN.\n", "# SECTION ssl_proxy END.\n", '', ${$tpl});
}
} else {
Expand All @@ -1794,12 +1801,10 @@ sub _cleanTemplate
if ($isSSLVhost && !$data->{'HSTS_SUPPORT'}) {
${$tpl} = replaceBloc( "# SECTION hsts BEGIN.\n", "# SECTION hsts END.\n", '', ${$tpl} );
}

${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;
} else {
${$tpl} =~ s/^\s*(?:;.*)?\n//gmi;
}

${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;

0;
}

Expand Down
2 changes: 1 addition & 1 deletion engine/PerlLib/Servers/httpd/apache_itk/installer.pm
Expand Up @@ -601,7 +601,7 @@ sub _setupVlogger

$self->{'httpd'}->buildConfFile(
"$self->{'apacheCfgDir'}/vlogger.conf.tpl",
{ },
{ SKIP_TEMPLATE_CLEANER => 1 },
{ destination => "$self->{'apacheCfgDir'}/vlogger.conf" }
);
}
Expand Down
19 changes: 12 additions & 7 deletions engine/PerlLib/Servers/httpd/apache_php_fpm.pm
Expand Up @@ -351,6 +351,7 @@ sub disableDmn

# Ensure that custom httpd conffile exists (cover case where file has been removed for any reasons)
unless (-f "$self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}/$data->{'DOMAIN_NAME'}.conf") {
$data->{'SKIP_TEMPLATE_CLEANER'} = 1;
$rs = $self->buildConfFile(
"$self->{'apacheTplDir'}/custom.conf.tpl",
$data,
Expand Down Expand Up @@ -876,7 +877,7 @@ sub buildConfFile
return $rs if $rs;

unless (defined $cfgTpl) {
$file = "$self->{'apacheCfgDir'}/$file" unless -d $path && $path ne './';
$file = File::Spec->canonpath("$self->{'apacheCfgDir'}/$filename") if $path eq './';
$cfgTpl = iMSCP::File->new( filename => $file )->get();
unless (defined $cfgTpl) {
error( sprintf( 'Could not read %s file', $file ) );
Expand Down Expand Up @@ -1512,6 +1513,7 @@ sub _addCfg
}

unless (-f "$self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}/$data->{'DOMAIN_NAME'}.conf") {
$data->{'SKIP_TEMPLATE_CLEANER'} = 1;
$rs = $self->buildConfFile(
"$self->{'apacheTplDir'}/custom.conf.tpl",
$data,
Expand Down Expand Up @@ -1601,6 +1603,7 @@ sub _addFiles
if (-d "$tmpDir/htdocs") {
# Test needed in case admin removed the index.html file from the skeleton
if (-f "$tmpDir/htdocs/index.html") {
$data->{SKIP_TEMPLATE_CLEANER} = 1;
my $fileSource = "$tmpDir/htdocs/index.html";
$rs = $self->buildConfFile( $fileSource, $data, { destination => $fileSource } );
return $rs if $rs;
Expand Down Expand Up @@ -1863,6 +1866,11 @@ sub _cleanTemplate
{
my ($self, $tpl, $name, $data) = @_;

if ($data->{'SKIP_TEMPLATE_CLEANER'}) {
delete $data->{'SKIP_TEMPLATE_CLEANER'};
return 0;
}

if ($name =~ /^domain(?:_ssl)?\.tpl$/) {
unless ($data->{'CGI_SUPPORT'} eq 'yes') {
${$tpl} = replaceBloc( "# SECTION suexec BEGIN.\n", "# SECTION suexec END.\n", '', ${$tpl} );
Expand All @@ -1885,7 +1893,6 @@ sub _cleanTemplate

${$tpl} = replaceBloc( "# SECTION fcgid BEGIN.\n", "# SECTION fcgid END.\n", '', ${$tpl} );
${$tpl} = replaceBloc( "# SECTION itk BEGIN.\n", "# SECTION itk END.\n", '', ${$tpl} );
${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;
} elsif ($name =~ /^domain(?:_disabled|_redirect)?(_ssl)?\.tpl$/) {
my $isSSLVhost = defined $1;

Expand All @@ -1894,7 +1901,7 @@ sub _cleanTemplate
${$tpl} = replaceBloc(
"# SECTION standard_redirect BEGIN.\n", "# SECTION standard_redirect END.\n", '', ${$tpl}
);
if ($data->{'FORWARD'} !~ /^https/) {
if (index($data->{'FORWARD'}, 'https') != 0) {
${$tpl} = replaceBloc("# SECTION ssl_proxy BEGIN.\n", "# SECTION ssl_proxy END.\n", '', ${$tpl});
}
} else {
Expand All @@ -1909,12 +1916,10 @@ sub _cleanTemplate
if ($isSSLVhost && !$data->{'HSTS_SUPPORT'}) {
${$tpl} = replaceBloc( "# SECTION hsts BEGIN.\n", "# SECTION hsts END.\n", '', ${$tpl} );
}

${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;
} else {
${$tpl} =~ s/^\s*(?:;.*)?\n//gmi;
}

${$tpl} =~ s/^\s*(?:[#;].*)?\n//gmi;

0;
}

Expand Down
4 changes: 3 additions & 1 deletion engine/PerlLib/Servers/httpd/apache_php_fpm/installer.pm
Expand Up @@ -701,7 +701,9 @@ sub _setupVlogger
);

$self->{'httpd'}->buildConfFile(
"$self->{'apacheCfgDir'}/vlogger.conf.tpl", { }, { destination => "$self->{'apacheCfgDir'}/vlogger.conf" }
"$self->{'apacheCfgDir'}/vlogger.conf.tpl",
{ SKIP_TEMPLATE_CLEANER => 1 },
{ destination => "$self->{'apacheCfgDir'}/vlogger.conf" }
);
}

Expand Down

0 comments on commit 4fbfa79

Please sign in to comment.