diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-04-19 15:41:35 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-04-19 15:41:35 +0300 |
commit | 967317a3d5c0ced836d8b6217288cd04819ddc36 (patch) | |
tree | ab93ec7d4c9530e4b076082261d6e6b239609b6a | |
parent | c7f7295dbd260099a58eefeea9594995672fd170 (diff) | |
download | acmeman-967317a3d5c0ced836d8b6217288cd04819ddc36.tar.gz acmeman-967317a3d5c0ced836d8b6217288cd04819ddc36.tar.bz2 |
Provide a base class for source classes.
* lib/App/Acmeman/Apache/Layout.pm: Remove debug.
* lib/App/Acmeman/Source.pm: New file.
* lib/App/Acmeman/Source/Apache.pm: Inherit from App::Acmeman::Source.
* lib/App/Acmeman/Source/Null.pm: Likewise.
* lib/App/Acmeman/Source/File.pm: New file.
-rw-r--r-- | lib/App/Acmeman/Apache/Layout.pm | 7 | ||||
-rw-r--r-- | lib/App/Acmeman/Source.pm | 59 | ||||
-rw-r--r-- | lib/App/Acmeman/Source/Apache.pm | 81 | ||||
-rw-r--r-- | lib/App/Acmeman/Source/File.pm | 49 | ||||
-rw-r--r-- | lib/App/Acmeman/Source/Null.pm | 6 |
5 files changed, 134 insertions, 68 deletions
diff --git a/lib/App/Acmeman/Apache/Layout.pm b/lib/App/Acmeman/Apache/Layout.pm index 44d5e3d..5b763a2 100644 --- a/lib/App/Acmeman/Apache/Layout.pm +++ b/lib/App/Acmeman/Apache/Layout.pm | |||
@@ -64,7 +64,6 @@ sub new { | |||
64 | if (exists($layout->{_test}) && !&{$layout->{_test}}) { | 64 | if (exists($layout->{_test}) && !&{$layout->{_test}}) { |
65 | next; | 65 | next; |
66 | } | 66 | } |
67 | debug(2, "assuming Apache layout \"$n\""); | ||
68 | $name = $n; | 67 | $name = $n; |
69 | last; | 68 | last; |
70 | } | 69 | } |
@@ -86,12 +85,6 @@ sub new { | |||
86 | return $self; | 85 | return $self; |
87 | } | 86 | } |
88 | 87 | ||
89 | sub debug { | ||
90 | if (defined(&::debug)) { | ||
91 | ::debug(@_); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | sub name { | 88 | sub name { |
96 | my $self = shift; | 89 | my $self = shift; |
97 | return $self->{_layout_name}; | 90 | return $self->{_layout_name}; |
diff --git a/lib/App/Acmeman/Source.pm b/lib/App/Acmeman/Source.pm new file mode 100644 index 0000000..391daca --- /dev/null +++ b/lib/App/Acmeman/Source.pm | |||
@@ -0,0 +1,59 @@ | |||
1 | package App::Acmeman::Source; | ||
2 | |||
3 | use strict; | ||
4 | use warnings; | ||
5 | use Carp; | ||
6 | |||
7 | sub debug { | ||
8 | my $self = shift; | ||
9 | if (defined(&::debug)) { | ||
10 | ::debug(@_); | ||
11 | } | ||
12 | } | ||
13 | |||
14 | sub error { | ||
15 | my $self = shift; | ||
16 | if (exists($self->{_cfg})) { | ||
17 | $self->{_cfg}->error(@_); | ||
18 | } else { | ||
19 | carp @_; | ||
20 | } | ||
21 | } | ||
22 | |||
23 | sub set { | ||
24 | my $self = shift; | ||
25 | croak "improper use of the set method" | ||
26 | unless exists $self->{_cfg}; | ||
27 | return $self->{_cfg}->set(@_); | ||
28 | } | ||
29 | |||
30 | sub get { | ||
31 | my $self = shift; | ||
32 | croak "improper use of the get method" | ||
33 | unless exists $self->{_cfg}; | ||
34 | return $self->{_cfg}->get(@_); | ||
35 | } | ||
36 | |||
37 | sub define_domain { | ||
38 | my $self = shift; | ||
39 | my $cn = shift || croak "domain name must be given"; | ||
40 | $self->set('domain', $cn, 'files', 'default'); | ||
41 | } | ||
42 | |||
43 | sub define_alias { | ||
44 | my $self = shift; | ||
45 | my $cn = shift || croak "domain name must be given"; | ||
46 | foreach my $alias (@_) { | ||
47 | $self->set('domain', $cn, 'alt', $alias); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | sub configure { | ||
52 | my ($self, $config) = @_; | ||
53 | $self->{_cfg} = $config; | ||
54 | return $self->scan(); | ||
55 | } | ||
56 | |||
57 | sub setup { 1 } | ||
58 | |||
59 | 1; | ||
diff --git a/lib/App/Acmeman/Source/Apache.pm b/lib/App/Acmeman/Source/Apache.pm index 1e75044..c84aea6 100644 --- a/lib/App/Acmeman/Source/Apache.pm +++ b/lib/App/Acmeman/Source/Apache.pm | |||
@@ -7,50 +7,21 @@ use feature 'state'; | |||
7 | use File::Path qw(make_path); | 7 | use File::Path qw(make_path); |
8 | use File::Spec; | 8 | use File::Spec; |
9 | use IPC::Open3; | 9 | use IPC::Open3; |
10 | 10 | use App::Acmeman::Apache::Layout; | |
11 | require App::Acmeman::Apache::Layout; | 11 | use parent 'App::Acmeman::Source'; |
12 | our @ISA = qw(App::Acmeman::Apache::Layout); | ||
13 | 12 | ||
14 | sub new { | 13 | sub new { |
15 | my $class = shift; | 14 | my $class = shift; |
16 | my $self = $class->SUPER::new(@_); | 15 | bless { _layout => new App::Acmeman::Apache::Layout(@_) }, $class; |
17 | return $self; | ||
18 | } | ||
19 | |||
20 | sub debug { | ||
21 | if (defined(&::debug)) { | ||
22 | ::debug(@_); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | sub configure { | ||
27 | my ($self, $config) = @_; | ||
28 | $config->set(qw(core postrenew), $self->restart_command); | ||
29 | $self->{_cfg} = $config; | ||
30 | return $self->examine_http_config($self->config_file); | ||
31 | } | ||
32 | |||
33 | sub set { | ||
34 | my $self = shift; | ||
35 | croak "improper use of the set method" | ||
36 | unless exists $self->{_cfg}; | ||
37 | return $self->{_cfg}->set(@_); | ||
38 | } | 16 | } |
39 | 17 | ||
40 | sub get { | 18 | sub layout { shift->{_layout} } |
41 | my $self = shift; | ||
42 | croak "improper use of the get method" | ||
43 | unless exists $self->{_cfg}; | ||
44 | return $self->{_cfg}->get(@_); | ||
45 | } | ||
46 | 19 | ||
47 | sub error { | 20 | sub scan { |
48 | my $self = shift; | 21 | my ($self) = @_; |
49 | if (exists($self->{_cfg})) { | 22 | $self->debug(2, 'assuming Apache layout "'.$self->layout->name.'"'); |
50 | $self->{_cfg}->error(@_); | 23 | $self->set(qw(core postrenew), $self->layout->restart_command); |
51 | } else { | 24 | return $self->examine_http_config($self->layout->config_file); |
52 | carp @_; | ||
53 | } | ||
54 | } | 25 | } |
55 | 26 | ||
56 | sub dequote { | 27 | sub dequote { |
@@ -73,7 +44,7 @@ sub examine_http_config { | |||
73 | 44 | ||
74 | state $state = STATE_INITIAL; | 45 | state $state = STATE_INITIAL; |
75 | 46 | ||
76 | debug(3, "reading apache configuration file \"$file\""); | 47 | $self->debug(3, "reading apache configuration file \"$file\""); |
77 | if (open(my $fd, '<', $file)) { | 48 | if (open(my $fd, '<', $file)) { |
78 | my $server_name; | 49 | my $server_name; |
79 | my @server_aliases; | 50 | my @server_aliases; |
@@ -86,7 +57,7 @@ sub examine_http_config { | |||
86 | s/^\s+//; | 57 | s/^\s+//; |
87 | next if /^(#.*)?$/; | 58 | next if /^(#.*)?$/; |
88 | if (/^include(optional)?\s+(.+?)\s*$/i) { | 59 | if (/^include(optional)?\s+(.+?)\s*$/i) { |
89 | #debug(3, "$file:$line: state $state: Include".($1||'')." $2"); | 60 | #$self->debug(3, "$file:$line: state $state: Include".($1||'')." $2"); |
90 | $self->http_include($self->dequote($2), defined($1)); | 61 | $self->http_include($self->dequote($2), defined($1)); |
91 | next; | 62 | next; |
92 | } | 63 | } |
@@ -114,18 +85,14 @@ sub examine_http_config { | |||
114 | if (@server_aliases) { | 85 | if (@server_aliases) { |
115 | if ($state == STATE_USE_CHALLENGE) { | 86 | if ($state == STATE_USE_CHALLENGE) { |
116 | my $cn = shift @server_aliases; | 87 | my $cn = shift @server_aliases; |
117 | $self->set('domain', $cn, 'files', 'apache'); | 88 | $self->define_domain($cn); |
118 | foreach my $name (@server_aliases) { | 89 | $self->define_alias($cn, @server_aliases); |
119 | $self->set('domain', $cn, 'alt', $name); | 90 | $self->debug(3, "$file:$line: will handle ". |
120 | } | 91 | join(',', $cn, @server_aliases)); |
121 | debug(3, "$file:$line: will handle ". | ||
122 | join(',', $cn, @server_aliases)); | ||
123 | } elsif ($state == STATE_USE_REFERENCE) { | 92 | } elsif ($state == STATE_USE_REFERENCE) { |
124 | $self->set('domain', $reference, 'files', 'apache'); | 93 | $self->set('domain', $reference, |
125 | foreach my $name (@server_aliases) { | 94 | 'files', 'apache'); |
126 | $self->set('domain', $reference, | 95 | $self->define_alias($reference, @server_aliases); |
127 | 'alt', $name); | ||
128 | } | ||
129 | } | 96 | } |
130 | } | 97 | } |
131 | $state = STATE_INITIAL; | 98 | $state = STATE_INITIAL; |
@@ -160,7 +127,7 @@ sub examine_http_config { | |||
160 | my $dir = $self->dequote($1); | 127 | my $dir = $self->dequote($1); |
161 | $dir =~ s{/.well-known/acme-challenge$}{}; | 128 | $dir =~ s{/.well-known/acme-challenge$}{}; |
162 | $self->set(qw(core rootdir), $dir); | 129 | $self->set(qw(core rootdir), $dir); |
163 | debug(3, "ACME challenge root dir: $dir"); | 130 | $self->debug(3, "ACME challenge root dir: $dir"); |
164 | } | 131 | } |
165 | } elsif ($state == STATE_MACRO_SSL) { | 132 | } elsif ($state == STATE_MACRO_SSL) { |
166 | if (m{^</macro}i) { | 133 | if (m{^</macro}i) { |
@@ -204,7 +171,7 @@ sub http_include { | |||
204 | $pattern = File::Spec->catfile($pattern, '*') if -d $pattern; | 171 | $pattern = File::Spec->catfile($pattern, '*') if -d $pattern; |
205 | foreach my $file (glob $pattern) { | 172 | foreach my $file (glob $pattern) { |
206 | if ($optional && ! -e $file) { | 173 | if ($optional && ! -e $file) { |
207 | debug(1, "optional include file \"$file\" doesn't exist"); | 174 |