[861] | 1 | package LATMOS::Accounts::Web::Controller::NetHosts; |
---|
| 2 | |
---|
[2298] | 3 | use utf8; |
---|
[861] | 4 | use strict; |
---|
| 5 | use warnings; |
---|
[884] | 6 | use base 'Catalyst::Controller'; |
---|
[861] | 7 | |
---|
| 8 | =head1 NAME |
---|
| 9 | |
---|
| 10 | LATMOS::Accounts::Web::Controller::Users - Catalyst Controller |
---|
| 11 | |
---|
| 12 | =head1 DESCRIPTION |
---|
| 13 | |
---|
| 14 | Catalyst Controller. |
---|
| 15 | |
---|
| 16 | =head1 METHODS |
---|
| 17 | |
---|
| 18 | =cut |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | =head2 index |
---|
| 22 | |
---|
| 23 | =cut |
---|
| 24 | |
---|
| 25 | sub index : Private { |
---|
| 26 | my ( $self, $c ) = @_; |
---|
| 27 | |
---|
| 28 | $c->stash->{ofilter} = $c->model('AttrFilter', 'nethost'); |
---|
| 29 | my $start = $c->req->param('start'); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | sub default : LocalPath { |
---|
| 33 | my ( $self, $c, undef, $nethostname ) = @_; |
---|
| 34 | |
---|
| 35 | my $base = $c->model('Accounts')->db; |
---|
| 36 | $c->stash->{page}{title} = "HÎte réseau :: $nethostname"; |
---|
| 37 | $c->stash->{nethost} = $base->get_object('nethost', $nethostname) or do { |
---|
| 38 | $c->forward('/no_object'); |
---|
| 39 | return; |
---|
| 40 | }; |
---|
| 41 | $c->stash->{nethostname} = $nethostname; |
---|
| 42 | $c->stash->{form} = $c->model('AttrForms', 'nethost', $c->stash->{nethost}); |
---|
| 43 | if ($c->req->param('addip')) { |
---|
| 44 | for (1) { |
---|
| 45 | my $zone = $base->get_object('netzone', $c->req->param('zone')) |
---|
| 46 | or last; |
---|
| 47 | my $ip = $c->req->param('newip') || 'any'; |
---|
| 48 | if ($ip =~ /^(any|first)$/) { |
---|
| 49 | my @freeips = $zone->get_attributes('freeIP') or last; |
---|
| 50 | my $idx = $ip eq 'first' ? 0 : rand(scalar(@freeips)); |
---|
| 51 | $ip = $freeips[$idx] or last; |
---|
| 52 | } |
---|
| 53 | my @currentips = grep { $_ } $c->stash->{nethost}->get_attributes('ip'); |
---|
| 54 | $c->stash->{nethost}->set_c_fields(ip => [ @currentips, $ip ]) |
---|
| 55 | or do { |
---|
| 56 | $base->rollback; |
---|
| 57 | last; |
---|
| 58 | }; |
---|
| 59 | $base->commit; |
---|
| 60 | last; |
---|
| 61 | } |
---|
| 62 | } elsif ($c->req->param('rename') && $c->req->param('to')) { |
---|
| 63 | my $to = $c->req->param('to'); |
---|
| 64 | if ($base->rename_nethost($nethostname, $to, |
---|
| 65 | addcname => $c->req->param('addcname') || undef, |
---|
| 66 | )) { |
---|
| 67 | $base->commit; |
---|
| 68 | $c->res->redirect($to); |
---|
| 69 | } else { |
---|
| 70 | $base->rollback; |
---|
| 71 | } |
---|
[1162] | 72 | } elsif ($c->req->param('make_active')) { |
---|
| 73 | $c->stash->{nethost}->set_c_fields('exported' => 1); |
---|
| 74 | $base->commit; |
---|
| 75 | } |
---|
| 76 | elsif ($c->req->param('make_inactive')) { |
---|
| 77 | $c->stash->{nethost}->set_c_fields('exported' => 0); |
---|
| 78 | $base->commit; |
---|
| 79 | } |
---|
| 80 | elsif ($c->req->param('delete')) { |
---|
| 81 | $base->delete_object('nethost', $nethostname); |
---|
| 82 | $base->commit; |
---|
| 83 | $c->res->redirect('/nethosts'); |
---|
| 84 | |
---|
[861] | 85 | } else { |
---|
| 86 | $c->stash->{form}->set_attrs; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | =head1 AUTHOR |
---|
| 91 | |
---|
| 92 | Thauvin Olivier |
---|
| 93 | |
---|
| 94 | =head1 LICENSE |
---|
| 95 | |
---|
| 96 | This library is free software, you can redistribute it and/or modify |
---|
| 97 | it under the same terms as Perl itself. |
---|
| 98 | |
---|
| 99 | =cut |
---|
| 100 | |
---|
| 101 | 1; |
---|