aboutsummaryrefslogtreecommitdiff
path: root/lib/App/Acmeman/Config.pm
blob: 6b81a25a1de5f8c3de65047285a26d6bce2e9a36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package App::Acmeman::Config;

use strict;
use warnings;
use Carp;
use parent 'Config::Parser::Ini';
use Text::ParseWords;
use App::Acmeman::Log qw(debug_level :sysexits);
use File::Spec;

sub new {
    my $class = shift;
    my $filename = shift;
    my %args;
    if (-e $filename) {
	$args{filename} = $filename;
    }
    my $self = $class->SUPER::new(%args);
    if (!$args{filename}) {
	$self->commit or croak "configuration failed";
    }
    $self
}

sub mangle {
    my $self = shift;
    my $err;

    if (debug_level() == 0 && $self->core->verbose) {
	debug_level($self->core->verbose);
    }
    $self->set(qw(core files default))
	unless $self->is_set(qw(core files));

    unless ($self->is_set(qw(files))) {
	if ($self->get(qw(core files)) ne 'default') {
	    $self->error("section files." . $self->get(qw(core files))." not defined");
	    ++$err;
	}
    }

    unless ($self->is_set(qw(files default))) {
	$self->set(qw(files default type), 'split');
	$self->set(qw(files default key-file), 
		     '/etc/ssl/acme/$domain/privkey.pem');
	$self->set(qw(files default certificate-file),
		     '/etc/ssl/acme/$domain/cert.pem');
	$self->set(qw(files default ca-file),
		     '/etc/ssl/acme/$domain/ca.pem');
    }
    
    if (my $fnode = $self->getnode('files')) {
	while (my ($k, $v) = each %{$fnode->subtree}) {
	    $v->set('files', $k, 'type', 'split')
		unless $v->has_key('type');
	    if ($v->subtree('type') eq 'single') {
		unless ($v->has_key('certificate-file')) {
		    $self->error("files.$k.certificate-file not defined");
		    ++$err;
		} else {
		    if ($v->has_key('key-file')) {
			$self->error("files.$k.key-file ignored");
		    }
		    if ($v->has_key('ca-file')) {
			$self->error("files.$k.ca-file ignored");
		    }
		}
	    } else {
		unless ($v->has_key('key-file')) {
		    $self->error("files.$k.key-file not defined");
		    ++$err;
		}
		unless ($v->has_key('certificate-file')) {
		    $self->error("files.$k.ca-file not defined");
		    ++$err;
		}
	    }
	}
    }

    if (my $files = $self->get(qw(core files))) {
	unless ($self->is_set('files', $files)) {
	    $self->error("files.$files is referenced from [core], but never declared");
	    ++$err;
	}
    }

    if (my $source_node = $self->getnode(qw(core source))) {
	$self->unset(qw(core source));	
	foreach my $s ($source_node->value) {
	    my ($name, @args) = quotewords('\s+', 0, $s);
	    my $pack = 'App::Acmeman::Source::' . ucfirst($name);
	    my $obj = eval "use $pack; new $pack(\@args);";
	    if ($@) {
		$self->error("error loading source module $name: $@",
			     locus => $source_node->locus);
	        ++$err;
	        next;
	    }
	    if ($obj->configure($self)) {
		$self->set(qw(core source), $obj);
	    } else {
		++$err;
	    }
	}
    }

    my $dir = $self->get(qw(account directory));
    for my $k (qw(id key)) {
	my $file = $self->get('account', $k);
	unless (File::Spec->file_name_is_absolute($file)) {
	    $self->set('account', $k, File::Spec->catfile($dir, $file));
	}
    }
    
    exit(EX_CONFIG) if $err;
}

1;
__DATA__
[core]
    postrenew = STRING :array
    rootdir = STRING :default=/var/www/acme
    files = STRING
    time-delta = NUMBER :default=86400
    source = STRING :default=default :array
    check-alt-names = BOOL :default=0
    check-dns = BOOL :default=1
    my-ip = STRING :array
    key-size = NUMBER :default=4096
    verbose = NUMBER :default=0
[account]
    directory = STRING :default=/etc/ssl/acme
    id = STRING :default=key.id
    key = STRING :default=key.pem
[files ANY]
    type = STRING :re="^(single|split)$"
    certificate-file = STRING
    key-file = STRING
    ca-file = STRING
    argument = STRING
[domain ANY]
    alt = STRING :array
    files = STRING
    key-size = NUMBER
    postrenew = STRING

    


    

Return to:

Send suggestions and report system problems to the System administrator.