]> Raphaël G. Git Repositories - acme/blob - acmeconf
Add man page documentation
[acme] / acmeconf
1 #! /usr/bin/perl
2
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 #
16 # Copyright (C) 2016 - 2017 Raphaël Gertz <acme@rapsys.eu>
17
18 # Best practice
19 use strict;
20 use warnings;
21
22 # Load required modules
23 use JSON;
24 use Tie::IxHash;
25
26 # Load POSIX
27 use POSIX qw(EXIT_SUCCESS EXIT_FAILURE);
28
29 # Init redhat
30 my @redhat = ();
31
32 # Init debian
33 my @debian = ();
34
35 # Init root
36 my %root = ();
37 tie(%root, 'Tie::IxHash', thumbprint => '/etc/acmepl/thumbprint', certificates => []);
38
39 # Init prod
40 my $prod = 0;
41
42 # Strip and enable prod
43 @ARGV = map { if ($_ eq '-p') { $prod = 1; (); } else { $_; } } @ARGV;
44
45 # Strip and enable debug
46 for (my $i = 0; $i <= $#ARGV; $i++) {
47 # Match redhat types
48 if ($ARGV[$i] =~ /^(?:(\-r|\-\-redhat)(?:=([^-][a-zA-Z0-9_\.,-]+))?)$/) {
49 if (defined($2)) {
50 push(@redhat, [split(',', $2)]);
51 # Extract next parameter
52 } elsif(defined($ARGV[$i+1]) && $ARGV[$i+1] =~ /^([^-][a-zA-Z0-9_\.,-]+)$/) {
53 push(@redhat, [split(',', $1)]);
54 $i++;
55 # Set default
56 } else {
57 push(@redhat, ['www.example.com','example.com','...']);
58 }
59 # Match debian types
60 } elsif ($ARGV[$i] =~ /^(?:(\-d|\-\-debian)(?:=([^-][a-zA-Z0-9_\.,-]+))?)$/) {
61 if (defined($2)) {
62 push(@debian, [split(',', $2)]);
63 # Extract next parameter
64 } elsif(defined($ARGV[$i+1]) && $ARGV[$i+1] =~ /^([^-][a-zA-Z0-9_\.,-]+)$/) {
65 push(@debian, [split(',', $1)]);
66 $i++;
67 # Set default
68 } else {
69 push(@debian, ['www.example.com','example.com','...']);
70 }
71 }
72 }
73
74 # Show usage
75 if (scalar(@ARGV) < 1) {
76 print "Usage: $0 [(-d|--debian)[=example.com[,...]] [(-r|--redhat)[=example.com[,...]]] [...] > /etc/acmepl/config\n";
77 exit EXIT_FAILURE;
78 }
79
80 # Append redhat style examples
81 for my $key (@redhat) {
82 my $domain = shift @{$key};
83 my @domains = $key;
84 tie(%{$root{certificates}[$#{$root{certificates}}+1]}, 'Tie::IxHash', (
85 # Public cert
86 #XXX: required
87 cert => '/etc/pki/tls/certs/'.$domain.'.pem',
88 # Private key
89 #XXX: required
90 key => '/etc/pki/tls/private/'.$domain.'.pem',
91 # Private account key
92 #XXX: required
93 account => '/etc/acme/account.pem',
94 # Mail address
95 #XXX: required
96 mail => 'webmaster@'.$domain,
97 # Root domain
98 #XXX: required
99 domain => $domain,
100 # Domain list
101 #XXX: required
102 domains => @domains,
103 # Production certificate
104 #XXX: optional
105 #XXX: set to 1 for production
106 prod => $prod
107 ));
108 }
109
110 # Append debian style examples
111 for my $key (@debian) {
112 my $domain = shift @{$key};
113 my @domains = $key;
114 tie(%{$root{certificates}[$#{$root{certificates}}+1]}, 'Tie::IxHash', (
115 # Public cert
116 #XXX: required
117 cert => '/etc/ssl/certs/'.$domain.'.crt',
118 # Private key
119 #XXX: required
120 key => '/etc/ssl/private/'.$domain.'.key',
121 # Private account key
122 #XXX: required
123 account => '/etc/acme/account.pem',
124 # Mail address
125 #XXX: required
126 mail => 'webmaster@'.$domain,
127 # Root domain
128 #XXX: required
129 domain => $domain,
130 # Domain list
131 #XXX: required
132 domains => @domains,
133 # Production certificate
134 #XXX: optional
135 #XXX: set to 1 for production
136 prod => $prod
137 ));
138 }
139
140 # Display configuration template
141 print to_json(\%root, {pretty => 1});
142
143 # Exit with success
144 exit EXIT_SUCCESS;