diff --git a/lib/cyberman/Domains.pm b/lib/cyberman/Domains.pm
index 8610f56..c49df4c 100644
--- a/lib/cyberman/Domains.pm
+++ b/lib/cyberman/Domains.pm
@@ -72,4 +72,46 @@ post '/domains/new' => sub {
};
};
+get '/domains/:id/remove' => sub {
+ my $domain = database->quick_select(
+ "domain",
+ {
+ "id" => param("id"),
+ },
+ );
+
+ return auth_test($domain->{"ownerid"}) if auth_test($domain->{"ownerid"});
+
+ template 'domains/remove.tt' => {
+ "domain" => $domain,
+ };
+};
+
+post '/domains/:id/remove' => sub {
+ my $domain = database->quick_select(
+ "domain",
+ {
+ "id" => param("id"),
+ },
+ );
+
+ if (!$domain) {
+ # quick and dirty error that shouldn't really appear
+ return "No such domain!";
+ }
+
+ return auth_test($domain->{"ownerid"}) if auth_test($domain->{"ownerid"});
+
+ database->quick_delete(
+ "domain",
+ {
+ "id" => param("id"),
+ },
+ );
+
+ template redir => {
+ redir => "../../domains?removed=$domain->{name}",
+ };
+};
+
true;
diff --git a/lib/cyberman/Helper.pm b/lib/cyberman/Helper.pm
index f709a53..960ac51 100644
--- a/lib/cyberman/Helper.pm
+++ b/lib/cyberman/Helper.pm
@@ -6,10 +6,19 @@ use Exporter qw(import);
our @EXPORT = qw(auth_test);
sub auth_test {
+ my $id = undef;
+ if (@_) {
+ $id = shift;
+ }
+
if (!vars->{"auth"}) {
return template 'redir' => {
"redir" => "/index",
};
+ } elsif ($id && vars->{"auth"} != $id) {
+ return template 'redir' => {
+ "redir" => "/index",
+ };
} else {
return 0; # nothing to be returned, route can continue
}
diff --git a/views/domains.tt b/views/domains.tt
index 7130930..990f9f4 100644
--- a/views/domains.tt
+++ b/views/domains.tt
@@ -9,6 +9,12 @@
<% END %>
+ <% IF params.removed %>
+
+ You are about to permanently remove <% domain.name %>.cyb and all its records. +
++ YOU ARE ABOUT TO PERMANENTLY REMOVE <% domain.name %>.cyb AND ALL ITS RECORDS! +
++ There is no guarantee that you will be able to re-register this domain at a later date. +
++