]> Raphaël G. Git Repositories - acme/blob - letsconf
Fix path
[acme] / letsconf
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 <acmepl@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 # XXX: Debug
30 use Data::Dumper;
31
32 # Init redhat
33 my @redhat = ();
34
35 # Init debian
36 my @debian = ();
37
38 # Init root
39 my %root = ();
40 tie(%root, 'Tie::IxHash', thumbprint => '/etc/acmepl/thumbprint', certificates => []);
41
42 # Init prod
43 my $prod = 0;
44
45 # Strip and enable prod
46 @ARGV = map { if ($_ eq '-p') { $prod = 1; (); } else { $_; } } @ARGV;
47
48 # Strip and enable debug
49 for (my $i = 0; $i <= $#ARGV; $i++) {
50 # Match redhat types
51 if ($ARGV[$i] =~ /^(?:(\-r|\-\-redhat)(?:=([^-][a-zA-Z0-9_\.,-]+))?)$/) {
52 if (defined($2)) {
53 push(@redhat, [split(',', $2)]);
54 # Extract next parameter
55 } elsif(defined($ARGV[$i+1]) && $ARGV[$i+1] =~ /^([^-][a-zA-Z0-9_\.,-]+)$/) {
56 push(@redhat, [split(',', $1)]);
57 $i++;
58 # Set default
59 } else {
60 push(@redhat, ['www.example.com','example.com','...']);
61 }
62 # Match debian types
63 } elsif ($ARGV[$i] =~ /^(?:(\-d|\-\-debian)(?:=([^-][a-zA-Z0-9_\.,-]+))?)$/) {
64 if (defined($2)) {
65 push(@debian, [split(',', $2)]);
66 # Extract next parameter
67 } elsif(defined($ARGV[$i+1]) && $ARGV[$i+1] =~ /^([^-][a-zA-Z0-9_\.,-]+)$/) {
68 push(@debian, [split(',', $1)]);
69 $i++;
70 # Set default
71 } else {
72 push(@debian, ['www.example.com','example.com','...']);
73 }
74 }
75 }
76
77 # Show usage
78 if (scalar(@ARGV) < 1) {
79 print "Usage: $0 [(-d|--debian)[=example.com[,...]] [(-r|--redhat)[=example.com[,...]]] [...] > /etc/acmepl/config\n";
80 exit EXIT_FAILURE;
81 }
82
83 # Append redhat style examples
84 for my $key (@redhat) {
85 my $domain = shift @{$key};
86 my @domains = $key;
87 tie(%{$root{certificates}[$#{$root{certificates}}+1]}, 'Tie::IxHash', (
88 # Public cert
89 #XXX: required
90 cert => '/etc/pki/tls/certs/'.$domain.'.pem',
91 # Private key
92 #XXX: required
93 key => '/etc/pki/tls/private/'.$domain.'.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 # Mail address
122 #XXX: required
123 mail => 'webmaster@'.$domain,
124 # Root domain
125 #XXX: required
126 domain => $domain,
127 # Domain list
128 #XXX: required
129 domains => @domains,
130 # Production certificate
131 #XXX: optional
132 #XXX: set to 1 for production
133 prod => $prod
134 ));
135 }
136
137 # Display configuration template
138 print to_json(\%root, {pretty => 1});
139
140 # Exit with success
141 exit EXIT_SUCCESS;