diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm index 6492f80..65431a3 100644 --- a/Web/lib/MJB/Web.pm +++ b/Web/lib/MJB/Web.pm @@ -64,6 +64,7 @@ sub startup ($self) { $self->minion->add_task( sync_blog_media => 'MJB::Web::Task::SyncBlogMedia' ); # SSL cert related jobs. + $self->minion->add_task( mk_wildcard_ssl => 'MJB::Web::Task::WildCardSSL' ); $self->minion->add_task( create_ssl_cert => 'MJB::Web::Task::CreateSSLCert' ); $self->minion->add_task( sync_ssl_certs => 'MJB::Web::Task::SyncSSLCerts' ); diff --git a/Web/lib/MJB/Web/Controller/Admin.pm b/Web/lib/MJB/Web/Controller/Admin.pm index 1e7cfe8..336787c 100644 --- a/Web/lib/MJB/Web/Controller/Admin.pm +++ b/Web/lib/MJB/Web/Controller/Admin.pm @@ -96,10 +96,11 @@ sub domains ( $c ) { sub do_domain ( $c ) { my $fqdn = $c->param('domain_fqdn'); + my $ssl = $c->param('ssl_challenge'); my $domain = try { $c->db->storage->schema->txn_do( sub { - $c->db->hosted_domains->create({ name => $fqdn }); + $c->db->hosted_domains->create({ name => $fqdn, letsencrypt_challenge => $ssl }); }); } catch { $c->flash( error_message => "domain could not be created: $_" ); @@ -107,6 +108,10 @@ sub do_domain ( $c ) { return; }; + if ( $ssl eq 'dns-linode' ) { + $c->minion->enqueue( 'mk_wildcard_ssl', [ $domain->id ], { queue => 'certbot' } ); + } + $c->flash( confirmation => "Added $fqdn to domain pool." ); $c->redirect_to( $c->url_for( 'show_admin_domains' ) ); } diff --git a/Web/lib/MJB/Web/Task/WildCardSSL.pm b/Web/lib/MJB/Web/Task/WildCardSSL.pm new file mode 100644 index 0000000..0f8ffa9 --- /dev/null +++ b/Web/lib/MJB/Web/Task/WildCardSSL.pm @@ -0,0 +1,23 @@ +package MJB::Web::Task::WildCardSSL; +use Mojo::Base 'MJB::Web::Task', -signatures; +use IPC::Run3; + +sub run ( $job, $hosted_domain_id ) { + $job->note( _mds_template => 'build_static' ); + + my $domain = $job->app->db->hosted_domain( $hosted_domain_id ); + + # Get the SSL Certificate + my $result_fetch = $job->system_command( [ + qw(sudo certbot certonly --dns-linode ----dns-linode-credentials /etc/letsencrypt/.secrets/linode.ini -d ), '*.' . $domain->name, qw(--agree-tos --register-unsafely-without-email) + ]); + + # Push the SSL Certs to all hosts + my $result_sync = $job->system_command( [ + qw(sudo letsencrypt-cert-push) + ]); + + $job->finish(); +} + +1; diff --git a/Web/templates/admin/domains.html.ep b/Web/templates/admin/domains.html.ep index fbc38a0..34bd263 100644 --- a/Web/templates/admin/domains.html.ep +++ b/Web/templates/admin/domains.html.ep @@ -11,6 +11,15 @@
+
+ +
+
+ +