diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm
index 6a352d2..fc51ac8 100644
--- a/Web/lib/MJB/Web.pm
+++ b/Web/lib/MJB/Web.pm
@@ -187,12 +187,18 @@ sub startup ($self) {
$auth->post( '/blog/:id/settings' )->to('Blog#do_settings' )->name('do_blog_settings' );
# Admin Dashboard
- $auth->get ( '/admin' )->to('Admin#index' )->name('show_admin' );
- $auth->post( '/admin' )->to('Admin#do_admin_become' )->name('do_admin_become' );
- $auth->get ( '/admin/people' )->to('Admin#people' )->name('show_admin_people' );
- $auth->get ( '/admin/person/:id' )->to('Admin#person' )->name('show_admin_person' );
- $auth->get ( '/admin/blogs' )->to('Admin#blogs' )->name('show_admin_blogs' );
- $auth->get ( '/admin/settings' )->to('Admin#settings' )->name('show_admin_settings' );
+ $admin->get ( '/admin' )->to('Admin#index' )->name('show_admin' );
+ $admin->post( '/admin' )->to('Admin#do_admin_become' )->name('do_admin_become' );
+ $admin->get ( '/admin/people' )->to('Admin#people' )->name('show_admin_people' );
+ $admin->get ( '/admin/person/:id' )->to('Admin#person' )->name('show_admin_person' );
+ $admin->get ( '/admin/blogs' )->to('Admin#blogs' )->name('show_admin_blogs' );
+ $admin->get ( '/admin/domains' )->to('Admin#domains' )->name('show_admin_domains' );
+ $admin->post( '/admin/domain' )->to('Admin#do_domain' )->name('do_admin_domain' );
+ $admin->post( '/admin/domain/remove' )->to('Admin#do_domain_remove' )->name('do_admin_domain_remove' );
+ $admin->get ( '/admin/servers' )->to('Admin#servers' )->name('show_admin_servers' );
+ $admin->post( '/admin/server' )->to('Admin#do_server' )->name('do_admin_server' );
+ $admin->post( '/admin/server/remove' )->to('Admin#do_server_remove' )->name('do_admin_server_remove' );
+ $admin->get ( '/admin/settings' )->to('Admin#settings' )->name('show_admin_settings' );
}
diff --git a/Web/lib/MJB/Web/Controller/Admin.pm b/Web/lib/MJB/Web/Controller/Admin.pm
index 2857b70..1e7cfe8 100644
--- a/Web/lib/MJB/Web/Controller/Admin.pm
+++ b/Web/lib/MJB/Web/Controller/Admin.pm
@@ -1,5 +1,6 @@
package MJB::Web::Controller::Admin;
use Mojo::Base 'Mojolicious::Controller', -signatures;
+use Try::Tiny;
sub index ( $c ) {
@@ -50,4 +51,80 @@ sub blogs ( $c ) {
}
+sub servers ( $c ) {
+ my $servers = $c->stash->{servers} = [ $c->db->servers->all ];
+
+}
+
+sub do_server ( $c ) {
+ my $fqdn = $c->param('server_fqdn');
+
+ my $server = try {
+ $c->db->storage->schema->txn_do( sub {
+ $c->db->servers->create({ hostname => $fqdn });
+ });
+ } catch {
+ $c->flash( error_message => "Server could not be created: $_" );
+ $c->redirect_to( $c->url_for( 'show_admin_servers' ) );
+ return;
+ };
+
+ $c->flash( confirmation => "Added $fqdn to server pool." );
+ $c->redirect_to( $c->url_for( 'show_admin_servers' ) );
+}
+
+sub do_server_remove ( $c ) {
+ my $server = $c->db->server($c->param('sid'));
+
+ if ( ! $server ) {
+ $c->flash( error_message => "Server could not be removed, because it doesn't exist?" );
+ $c->redirect_to( $c->url_for( 'show_admin_servers' ) );
+ return;
+ }
+
+ my $hostname = $server->hostname;
+ $server->delete;
+
+ $c->flash( confirmation => "Removed $hostname from server pool." );
+ $c->redirect_to( $c->url_for( 'show_admin_servers' ) );
+}
+
+sub domains ( $c ) {
+ my $domains = $c->stash->{domains} = [ $c->db->hosted_domains->all ];
+
+}
+
+sub do_domain ( $c ) {
+ my $fqdn = $c->param('domain_fqdn');
+
+ my $domain = try {
+ $c->db->storage->schema->txn_do( sub {
+ $c->db->hosted_domains->create({ name => $fqdn });
+ });
+ } catch {
+ $c->flash( error_message => "domain could not be created: $_" );
+ $c->redirect_to( $c->url_for( 'show_admin_domains' ) );
+ return;
+ };
+
+ $c->flash( confirmation => "Added $fqdn to domain pool." );
+ $c->redirect_to( $c->url_for( 'show_admin_domains' ) );
+}
+
+sub do_domain_remove ( $c ) {
+ my $domain = $c->db->hosted_domain($c->param('did'));
+
+ if ( ! $domain ) {
+ $c->flash( error_message => "domain could not be removed, because it doesn't exist?" );
+ $c->redirect_to( $c->url_for( 'show_admin_domains' ) );
+ return;
+ }
+
+ my $hostname = $domain->name;
+ $domain->delete;
+
+ $c->flash( confirmation => "Removed $hostname from domain pool." );
+ $c->redirect_to( $c->url_for( 'show_admin_domains' ) );
+}
+
1;
diff --git a/Web/templates/admin/_nav.html.ep b/Web/templates/admin/_nav.html.ep
index 8f97f32..30931ed 100644
--- a/Web/templates/admin/_nav.html.ep
+++ b/Web/templates/admin/_nav.html.ep
@@ -26,6 +26,12 @@
+
+ Servers
+
+
+ Domains
+
Settings
diff --git a/Web/templates/admin/domains.html.ep b/Web/templates/admin/domains.html.ep
new file mode 100644
index 0000000..acc3656
--- /dev/null
+++ b/Web/templates/admin/domains.html.ep
@@ -0,0 +1,72 @@
+% layout 'standard', title => 'Admin Panel', sb_active => 'admin';
+
+%= include 'admin/_nav', page => 'domains'
+
+% if ( my $confirmation = flash 'confirmation' ) {
+
+ <%== $confirmation %>
+
+% }
+
+% if ( my $confirmation = flash 'error_message' ) {
+
+ <%== $confirmation %>
+
+% }
+
+% if ( $c->stash->{success} ) {
+
+ <%= $c->stash->{success_message} %>
+
+% }
+
+% if ( $c->stash->{errors} ) {
+
+ There were errors with your request that could not be resolved:
+
+% for my $error ( @{$c->stash->{errors}} ) {
+ - <%= $error %>
+% }
+
+
+% }
+
+
+
+
+
+
+
+
+ | ID |
+ FQDN |
+ SSL Challenge |
+ Delete |
+
+
+
+ % for my $domain ( @{$domains} ) {
+
+ | <%= $domain->id %> |
+ <%= $domain->name %> |
+ <%= $domain->letsencrypt_challenge %> |
+
+
+ |
+
+ % }
+
+
diff --git a/Web/templates/admin/servers.html.ep b/Web/templates/admin/servers.html.ep
new file mode 100644
index 0000000..830b775
--- /dev/null
+++ b/Web/templates/admin/servers.html.ep
@@ -0,0 +1,70 @@
+% layout 'standard', title => 'Admin Panel', sb_active => 'admin';
+
+%= include 'admin/_nav', page => 'servers'
+
+% if ( my $confirmation = flash 'confirmation' ) {
+
+ <%== $confirmation %>
+
+% }
+
+% if ( my $confirmation = flash 'error_message' ) {
+
+ <%== $confirmation %>
+
+% }
+
+% if ( $c->stash->{success} ) {
+
+ <%= $c->stash->{success_message} %>
+
+% }
+
+% if ( $c->stash->{errors} ) {
+
+ There were errors with your request that could not be resolved:
+
+% for my $error ( @{$c->stash->{errors}} ) {
+ - <%= $error %>
+% }
+
+
+% }
+
+
+
+
+
+
+
+
+ | ID |
+ FQDN |
+ Delete |
+
+
+
+ % for my $server ( @{$servers} ) {
+
+ | <%= $server->id %> |
+ <%= $server->hostname %> |
+
+
+ |
+
+ % }
+
+