aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-02-09 12:11:18 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2018-02-09 12:18:16 +0200
commitc95c16005cb6ffafd27e884c405b839e049384a6 (patch)
tree536c2895b923e4eb539d254a4ba7b5568bdb513f /lib
parent70922eff7611175811958174e0c5ba45948bb118 (diff)
downloadacmeman-c95c16005cb6ffafd27e884c405b839e049384a6.tar.gz
acmeman-c95c16005cb6ffafd27e884c405b839e049384a6.tar.bz2
Use configurable key length.
* acmeman: (syntax) New configuration settings: core.key-size and domain.*.key-size. (make_csr): Take the key size as 2nd argument. (domain_cert_expires): Determine key size from the configuration. Include it in the debug output. (coalesce): Bugfix. * lib/App/Acmeman/Apache/Layout.pm (apache_layout_tab): Additional tests to resolve ambuguities. (new): Use the _test field to resolve ambiguities. * lib/App/Acmeman/Source/Apache.pm (server_root): New method. (http_include): Determine the server root by probing the server, unless it is set explicitly in the configuration. (probe): New method.
Diffstat (limited to 'lib')
-rw-r--r--lib/App/Acmeman/Apache/Layout.pm5
-rw-r--r--lib/App/Acmeman/Source/Apache.pm54
2 files changed, 54 insertions, 5 deletions
diff --git a/lib/App/Acmeman/Apache/Layout.pm b/lib/App/Acmeman/Apache/Layout.pm
index 77e2f8f..44d5e3d 100644
--- a/lib/App/Acmeman/Apache/Layout.pm
+++ b/lib/App/Acmeman/Apache/Layout.pm
@@ -10,6 +10,7 @@ our @ISA = qw(Exporter);
my %apache_layout_tab = (
slackware => {
+ _test => sub { -d '/etc/httpd/extra' },
_config_file => '/etc/httpd/httpd.conf',
_incdir => '/etc/httpd/extra',
_restart => '/etc/rc.d/rc.httpd restart'
@@ -42,6 +43,7 @@ my %apache_layout_tab = (
},
suse => {
_config_file => '/etc/apache2/httpd.conf',
+ _test => sub { ! -f '/etc/apache2/apache2.conf' },
_incdir => '/etc/apache2/conf.d',
_restart => 'service httpd restart'
# or systemctl restart apache2.service
@@ -59,6 +61,9 @@ sub new {
# Autodetect
while (my ($n, $layout) = each %apache_layout_tab) {
if (-f $layout->{_config_file}) {
+ if (exists($layout->{_test}) && !&{$layout->{_test}}) {
+ next;
+ }
debug(2, "assuming Apache layout \"$n\"");
$name = $n;
last;
diff --git a/lib/App/Acmeman/Source/Apache.pm b/lib/App/Acmeman/Source/Apache.pm
index f86c02f..c4a0570 100644
--- a/lib/App/Acmeman/Source/Apache.pm
+++ b/lib/App/Acmeman/Source/Apache.pm
@@ -5,6 +5,8 @@ use warnings;
use Carp;
use feature 'state';
use File::Path qw(make_path);
+use File::Spec;
+use IPC::Open3;
require App::Acmeman::Apache::Layout;
our @ISA = qw(App::Acmeman::Apache::Layout);
@@ -84,7 +86,7 @@ sub examine_http_config {
s/^\s+//;
next if /^(#.*)?$/;
if (/^include(optional)?\s+(.+?)\s*$/i) {
-# debug(3, "$file:$line: state $state: Include$1 $2");
+ #debug(3, "$file:$line: state $state: Include".($1||'')." $2");
$self->http_include($self->dequote($2), defined($1));
next;
}
@@ -96,7 +98,7 @@ sub examine_http_config {
@server_aliases = ();
$reference = undef;
} elsif (/^ServerRoot\s+(.+)/i) {
- $self->{_server_root} = $self->dequote($1);
+ $self->server_root($self->dequote($1));
} elsif (/^<(?:(?i)Macro)\s+LetsEncryptChallenge/) {
$state = STATE_MACRO_CHALLENGE;
} elsif (/^<(?:(?i)Macro)\s+LetsEncryptSSL\s+(.+?)\s*>/) {
@@ -181,11 +183,25 @@ sub examine_http_config {
return 1;
}
+sub server_root {
+ my $self = shift;
+ if (my $v = shift) {
+ croak "too many arguments" if $@;
+ $self->{_server_root} = $v;
+ }
+ return $self->{_server_root};
+}
+
sub http_include {
my ($self, $pattern, $optional) = @_;
- $pattern = "$self->{_server_root}/$pattern" unless $pattern =~ m{^/};
- $pattern =~ s{/*$}{};
- $pattern .= '/*' if -d $pattern;
+
+ unless ($self->server_root) {
+ $self->probe;
+ }
+
+ $pattern = File::Spec->catfile($self->{_server_root}, $pattern)
+ unless $pattern =~ m{^/};
+ $pattern = File::Spec->catfile($pattern, '*') if -d $pattern;
foreach my $file (glob $pattern) {
if ($optional && ! -e $file) {
debug(1, "optional include file \"$file\" doesn't exist");
@@ -281,4 +297,32 @@ EOT
return 1;
}
+sub probe {
+ my ($self, @servlist) = @_;
+ @servlist = qw(/usr/sbin/httpd /usr/sbin/apache2)
+ unless (@servlist);
+ open(my $nullout, '>', File::Spec->devnull);
+ open(my $nullin, '<', File::Spec->devnull);
+ foreach my $serv (@servlist) {
+ use Symbol 'gensym';
+ my $fd = gensym;
+ eval {
+ if (my $pid = open3($nullin, $fd, $nullout, $serv, '-V')) {
+ while (<$fd>) {
+ chomp;
+ if (/^\s+-D\s+HTTPD_ROOT=(.+)\s*$/) {
+ $self->server_root($self->dequote($1));
+ last;
+ }
+ }
+ }
+ };
+ close $fd;
+ last unless ($@)
+ }
+ close $nullin;
+ close $nullout;
+}
+
+
1;

Return to:

Send suggestions and report system problems to the System administrator.