aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA/Mirrors/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MGA/Mirrors/Controller')
-rw-r--r--lib/MGA/Mirrors/Controller/New.pm125
-rw-r--r--lib/MGA/Mirrors/Controller/Root.pm2
2 files changed, 126 insertions, 1 deletions
diff --git a/lib/MGA/Mirrors/Controller/New.pm b/lib/MGA/Mirrors/Controller/New.pm
new file mode 100644
index 0000000..fbb1fbe
--- /dev/null
+++ b/lib/MGA/Mirrors/Controller/New.pm
@@ -0,0 +1,125 @@
+package MGA::Mirrors::Controller::New;
+use Moose;
+use namespace::autoclean;
+use URI;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+MGA::Mirrors::Controller::New - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+ if ($c->req->param('url')) {
+ my $uri = URI->new($c->req->param('url'));
+ $c->stash->{uri} = $uri;
+
+ if (!($uri->can('host') && $uri->can('scheme'))) {
+ $c->stash->{subtemplate} = 'new/invalid_uri.tt';
+ return;
+ }
+
+ if (!$c->model('Mirrors')->get_protocol_info($uri->scheme)) {
+ $c->stash->{subtemplate} = 'new/unsupported_protocol.tt';
+ return;
+ }
+
+ my $urls = $c->model('Mirrors')->find_urls(
+ { protocol => $uri->scheme,
+ hostname => $uri->host, });
+ if (@{$urls || []}) {
+ $c->stash->{exists_url} = $urls;
+ $c->stash->{subtemplate} = 'new/mirror_exists.tt';
+ return;
+ }
+
+ if (!$c->model('Mirrors')->mirror_validity($uri)) {
+ $c->stash->{subtemplate} = 'new/invalid_mirror.tt';
+ return;
+ }
+
+ if (my @overlap_hosts = $c->model('Mirrors')->find_host_ip_overlap($uri->host)) {
+ $c->stash->{overlap_hosts} = \@overlap_hosts;
+ $c->stash->{subtemplate} = 'new/overlap_hosts.tt';
+ return;
+ }
+
+ my @ips = $c->model('Mirrors')->host_ips($uri->host);
+
+ $c->stash->{location} = $c->model('Mirrors')->locate_ips(@ips);
+
+ my $mirror = $c->model('Mirrors')->find_mirrors(
+ { hostname => $uri->host, });
+ if (@{ $mirror || []}) {
+ $c->stash->{mirror} = $mirror->[0];
+ } elsif ($c->req->param('hostinfo')) {
+ foreach (qw(city country)) {
+ $c->session->{hostinfo}{$_} = $c->req->param($_);
+ }
+ } else {
+ $c->stash->{subtemplate} = 'new/host_information.tt';
+ return;
+ }
+
+ $c->session->{new_uri} = $uri;
+ $c->stash->{template} = 'new/confirm.tt';
+ }
+}
+
+sub confirm :Path :Args(1) {
+ my ( $self, $c ) = @_;
+ $c->stash->{current_view} = 'TTBlock';
+ if ($c->session->{new_uri} && $c->req->param('confirm')) {
+ my $uri = URI->new($c->session->{new_uri});
+ my $mirror = $c->model('Mirrors')->find_mirrors(
+ { hostname => $uri->host, });
+ if (!@{$mirror || []}) {
+ if ($c->session->{hostinfo}) {
+ $c->model->add_or_update_host(
+ $uri->host,
+ city => $c->session->{hostinfo}{city},
+ country => $c->session->{hostinfo}{country},
+ );
+ } else {
+ return;
+ }
+ }
+ if ($c->model('Mirrors')->add_or_update_url($uri)) {
+ $c->session->{hostinfo} = undef;
+ $c->session->{new_uri} = undef;
+ $c->stash->{template} = 'new/success.tt';
+ $c->model('Mirrors')->db->commit;
+ return;
+ }
+ }
+}
+
+=head1 AUTHOR
+
+Olivier Thauvin
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/lib/MGA/Mirrors/Controller/Root.pm b/lib/MGA/Mirrors/Controller/Root.pm
index 5decc3a..bbc4d4d 100644
--- a/lib/MGA/Mirrors/Controller/Root.pm
+++ b/lib/MGA/Mirrors/Controller/Root.pm
@@ -30,7 +30,7 @@ sub index :Path :Args(0) {
my ( $self, $c ) = @_;
# Hello World
- $c->response->body( $c->welcome_message );
+ #$c->response->body( $c->welcome_message );
}
=head2 default