| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # crypto::letsencrypt Brik | ||
| 5 | # | ||
| 6 | package Metabrik::Crypto::Letsencrypt; | ||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(experimental ssl certificate x509 tls cert) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | attributes => { | ||
| 19 | datadir => [ qw(datadir) ], | ||
| 20 | }, | ||
| 21 | commands => { | ||
| 22 | install => [ ], # Inherited | ||
| 23 | certonly => [ qw(domain|$domain_list email|OPTIONAL) ], | ||
| 24 | }, | ||
| 25 | require_modules => { | ||
| 26 | 'Metabrik::Devel::Git' => [ ], | ||
| 27 | }, | ||
| 28 | }; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub install { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | my $datadir = $self->datadir; | ||
| 35 | my $directory = $datadir.'/letsencrypt'; | ||
| 36 | |||
| 37 | my $dg = Metabrik::Devel::Git->new_from_brik_init($self) or return; | ||
| 38 | $dg->clone('https://github.com/letsencrypt/letsencrypt', $directory) or return; | ||
| 39 | |||
| 40 | return $self->system("$directory/letsencrypt-auto --help"); | ||
| 41 | } | ||
| 42 | |||
| 43 | # | ||
| 44 | # https://letsencrypt.readthedocs.org/en/latest/using.html | ||
| 45 | # | ||
| 46 | sub certonly { | ||
| 47 | my $self = shift; | ||
| 48 | my ($domains, $email) = @_; | ||
| 49 | |||
| 50 | $self->brik_help_run_undef_arg('certonly', $domains) or return; | ||
| 51 | my $ref = $self->brik_help_run_invalid_arg('certonly', $domains, 'ARRAY', 'SCALAR') | ||
| 52 | or return; | ||
| 53 | |||
| 54 | my $bin = $self->datadir.'/letsencrypt/letsencrypt-auto'; | ||
| 55 | |||
| 56 | my $cmd = "$bin certonly --manual --agree-tos"; | ||
| 57 | |||
| 58 | if (defined($email)) { | ||
| 59 | $cmd .= " --email $email"; | ||
| 60 | } | ||
| 61 | |||
| 62 | if ($ref eq 'ARRAY') { | ||
| 63 | for (@$domains) { | ||
| 64 | $cmd .= " -d $_"; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | else { # SCALAR | ||
| 68 | $cmd .= " -d $domains"; | ||
| 69 | } | ||
| 70 | |||
| 71 | $self->log->verbose("certonly: cmd[$cmd]"); | ||
| 72 | |||
| 73 | return $self->system($cmd); | ||
| 74 | } | ||
| 75 | |||
| 76 | 1; | ||
| 77 | |||
| 78 | __END__ | ||