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

Last change on this file since 2469 was 2298, checked in by nanardon, 5 years ago

Fix: NetHost? page is utf8

File size: 2.6 KB
Line 
1package LATMOS::Accounts::Web::Controller::NetHosts;
2
3use utf8;
4use strict;
5use warnings;
6use base 'Catalyst::Controller';
7
8=head1 NAME
9
10LATMOS::Accounts::Web::Controller::Users - Catalyst Controller
11
12=head1 DESCRIPTION
13
14Catalyst Controller.
15
16=head1 METHODS
17
18=cut
19
20
21=head2 index
22
23=cut
24
25sub index : Private {
26    my ( $self, $c ) = @_;
27   
28    $c->stash->{ofilter} = $c->model('AttrFilter', 'nethost');
29    my $start = $c->req->param('start');
30}
31
32sub 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        }
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
85    } else {
86        $c->stash->{form}->set_attrs;
87    }
88}
89
90=head1 AUTHOR
91
92Thauvin Olivier
93
94=head1 LICENSE
95
96This library is free software, you can redistribute it and/or modify
97it under the same terms as Perl itself.
98
99=cut
100
1011;
Note: See TracBrowser for help on using the repository browser.