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/Graph.pm70
-rw-r--r--lib/MGA/Mirrors/Controller/Mirrors.pm3
-rw-r--r--lib/MGA/Mirrors/Controller/New.pm22
-rw-r--r--lib/MGA/Mirrors/Controller/Report.pm44
-rw-r--r--lib/MGA/Mirrors/Controller/Root.pm10
5 files changed, 145 insertions, 4 deletions
diff --git a/lib/MGA/Mirrors/Controller/Graph.pm b/lib/MGA/Mirrors/Controller/Graph.pm
new file mode 100644
index 0000000..5ca93cf
--- /dev/null
+++ b/lib/MGA/Mirrors/Controller/Graph.pm
@@ -0,0 +1,70 @@
+package MGA::Mirrors::Controller::Graph;
+use Moose;
+use namespace::autoclean;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+MGA::Mirrors::Controller::Graph - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+ my $mirror_list = $c->model('Mirrors')->find_mirrors;
+ my $graph = GraphViz->new(layout => 'dot', overlap => 'orthoxy', rankdir => 1);
+ my %node;
+ my %edge;
+ foreach (@{$mirror_list || []}) {
+ $node{$_->{hostname}} = $_;
+ if ($_->{syncfrom}) {
+ $edge{$_->{syncfrom}}{$_->{hostname}} = 1;
+ }
+ }
+ my %nodadded;
+ foreach my $from (keys %edge) {
+ foreach my $to (keys %{ $edge{$from} ||{}}) {
+ foreach ($from, $to) {
+ if (!$nodadded{$_}) {
+ $graph->add_node($_, shape => 'box', cluster => $node{$_}{country});
+ }
+ }
+ $graph->add_edge($from, $to);
+ }
+ }
+ $c->stash->{graphviz}->{graph} = $graph;
+}
+
+sub end : Private {
+ my ($self, $c) = @_;
+ $c->view('GraphViz')->process($c);
+ $c->model('Mirrors')->db->rollback;
+}
+
+=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/Mirrors.pm b/lib/MGA/Mirrors/Controller/Mirrors.pm
index 5d07ca5..73fa5ae 100644
--- a/lib/MGA/Mirrors/Controller/Mirrors.pm
+++ b/lib/MGA/Mirrors/Controller/Mirrors.pm
@@ -41,6 +41,8 @@ sub mirror :Path :Args(1) {
city => $c->req->param('city'),
country => $c->req->param('country'),
syncfrom=> $c->req->param('syncfrom'),
+ latitude => $c->req->param('latitude'),
+ longitude => $c->req->param('longitude'),
);
}
}
@@ -48,6 +50,7 @@ sub mirror :Path :Args(1) {
$c->stash->{host} = $c->model('Mirrors')->find_mirrors({
hostname => $host,
})->[0];
+ $c->model('Mirrors')->db->commit;
}
=head1 AUTHOR
diff --git a/lib/MGA/Mirrors/Controller/New.pm b/lib/MGA/Mirrors/Controller/New.pm
index d3ec38c..bf4fa59 100644
--- a/lib/MGA/Mirrors/Controller/New.pm
+++ b/lib/MGA/Mirrors/Controller/New.pm
@@ -43,7 +43,7 @@ sub index :Path :Args(0) {
{ protocol => $uri->scheme,
hostname => $uri->host, });
if (@{$urls || []}) {
- $c->stash->{exists_url} = $urls;
+ $c->stash->{exists_url} = $urls->[0];
if ($urls->[0]->{valid}) {
$c->stash->{subtemplate} = 'new/mirror_exists.tt';
return;
@@ -57,6 +57,18 @@ sub index :Path :Args(0) {
if (my @overlap_hosts = $c->model('Mirrors')->find_host_ip_overlap($uri->host)) {
$c->stash->{overlap_hosts} = \@overlap_hosts;
+ if (@overlap_hosts == 1) {
+ my $maybeurl = $c->model('Mirrors')->find_urls({
+ protocol => $uri->scheme,
+ hostname => $overlap_hosts[0]
+ });
+ if (!@{$maybeurl || []}) {
+ my $totryurl = $uri->clone;
+ $totryurl->host($overlap_hosts[0]);
+ $c->stash->{urlmaybe} = $totryurl;
+ $c->req->params->{url} = $totryurl;
+ }
+ }
$c->stash->{subtemplate} = 'new/overlap_hosts.tt';
return;
}
@@ -65,17 +77,19 @@ sub index :Path :Args(0) {
$c->stash->{location} = $c->model('Mirrors')->locate_ips(@ips);
$c->stash->{host}{country} = $c->stash->{location}{code};
+ $c->stash->{host}{latitude} = $c->stash->{location}{latitude};
+ $c->stash->{host}{longitude} = $c->stash->{location}{longitude};
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 syncfrom bandwidth)) {
+ foreach (qw(city country syncfrom bandwidth latitude longitude)) {
$c->session->{hostinfo}{$_} = $c->req->param($_);
}
} else {
- $c->stash->{subtemplate} = 'new/new_host.tt';
+ $c->stash->{template} = 'new/new_host.tt';
return;
}
@@ -99,6 +113,8 @@ sub confirm :Path :Args(1) {
country => $c->session->{hostinfo}{country},
bandwidth => $c->session->{hostinfo}{bandwidth},
syncfrom => $c->session->{hostinfo}{syncfrom},
+ latitude => $c->session->{hostinfo}{latitude},
+ longitude => $c->session->{hostinfo}{longitude},
);
} else {
return;
diff --git a/lib/MGA/Mirrors/Controller/Report.pm b/lib/MGA/Mirrors/Controller/Report.pm
new file mode 100644
index 0000000..b6cf3d3
--- /dev/null
+++ b/lib/MGA/Mirrors/Controller/Report.pm
@@ -0,0 +1,44 @@
+package MGA::Mirrors::Controller::Report;
+use Moose;
+use namespace::autoclean;
+use URI;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+MGA::Mirrors::Controller::Report - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+}
+
+
+=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 bbc4d4d..416442c 100644
--- a/lib/MGA/Mirrors/Controller/Root.pm
+++ b/lib/MGA/Mirrors/Controller/Root.pm
@@ -51,7 +51,15 @@ Attempt to render a view, if needed.
=cut
-sub end : ActionClass('RenderView') {}
+sub _end : ActionClass('RenderView') {
+ my ($self, $c) = @_;
+}
+
+sub end : Private {
+ my ($self, $c) = @_;
+ $c->forward('_end');
+ $c->model('Mirrors')->db->rollback;
+}
=head1 AUTHOR