source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/NetHosts.pm @ 1721

Last change on this file since 1721 was 1162, checked in by nanardon, 12 years ago

fix conflict

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