File Coverage

blib/lib/Lemonldap/NG/Manager.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             ## @file
2             # Lemonldap::NG manager main file
3              
4             ## @class
5             # Lemonldap::NG manager main class
6             package Lemonldap::NG::Manager;
7              
8 1     1   1312 use strict;
  1         2  
  1         31  
9 1     1   188 use Lemonldap::NG::Handler::CGI qw(:globalStorage :locationRules); #inherits
  0            
  0            
10             use Lemonldap::NG::Common::Conf; #link protected conf Configuration
11             use Lemonldap::NG::Common::Conf::Constants; #inherits
12              
13             our $VERSION = '1.4.3';
14             our @ISA = qw(
15             Lemonldap::NG::Handler::CGI
16             Lemonldap::NG::Manager::Downloader
17             Lemonldap::NG::Manager::Uploader
18             Lemonldap::NG::Manager::Request
19             Lemonldap::NG::Manager::_Struct
20             Lemonldap::NG::Manager::_i18n
21             );
22              
23             ## @cmethod Lemonldap::NG::Manager new(hashRef args)
24             # Class constructor.
25             #@param args hash reference
26             #@return Lemonldap::NG::Manager object
27             sub new {
28             my ( $class, $args ) = @_;
29              
30             # Output UTF-8
31             binmode( STDOUT, ':utf8' );
32              
33             # Try to load local configuration parameters
34             my $conf = Lemonldap::NG::Common::Conf->new( $args->{configStorage} )
35             or Lemonldap::NG::Handler::CGI->abort( 'Unable to get configuration',
36             $Lemonldap::NG::Common::Conf::msg );
37              
38             if ( my $globalconf = $conf->getConf() ) {
39             $args->{$_} ||= $globalconf->{$_} foreach (qw/portal/);
40             }
41              
42             if ( my $localconf = $conf->getLocalConf(MANAGERSECTION) ) {
43             $args->{$_} ||= $localconf->{$_} foreach ( keys %$localconf );
44             }
45              
46             my $self = $class->SUPER::new($args)
47             or $class->abort( 'Unable to start ' . __PACKAGE__,
48             'See Apache logs for more' );
49              
50             # Display an error if only default configuration is available
51             if ( $conf->lastCfg() eq 0 ) {
52             $self->lmLog(
53             "Unable to load configuration from backend: $Lemonldap::NG::Common::Conf::msg ",
54             "error"
55             );
56             }
57              
58             # Default values
59             $self->{managerSkin} = "default" unless defined $self->{managerSkin};
60             $self->{managerCss} = "accordion.css" unless defined $self->{managerCss};
61             $self->{managerCssTheme} = "ui-lightness"
62             unless defined $self->{managerCssTheme};
63             $self->{managerTreeAutoClose} = "true"
64             unless defined $self->{managerTreeAutoClose};
65             $self->{managerTreeJqueryCss} = "true"
66             unless defined $self->{managerTreeJqueryCss};
67              
68             # Save conf if ?data=
69             if ( my $rdata = $self->rparam('data') ) {
70              
71             $self->lmLog( "Manager request: Save data $rdata", 'debug' );
72             require Lemonldap::NG::Manager::Uploader; #inherits
73             $self->confUpload($rdata);
74             $self->quit();
75             }
76              
77             # File upload/download
78             elsif ( my $rfile = $self->rparam('file') ) {
79              
80             $self->lmLog( "Manager request: File $rfile", 'debug' );
81             my @params = ('file');
82             if ( my $rfilename = $self->rparam('filename') ) {
83             push @params, ${$rfilename};
84             }
85             require Lemonldap::NG::Manager::Uploader; #inherits
86             $self->fileUpload(@params);
87             $self->quit();
88             }
89              
90             # URL upload/download
91             elsif ( my $rurl = $self->rparam('url') ) {
92              
93             $self->lmLog( "Manager request: URL $rurl", 'debug' );
94             require Lemonldap::NG::Manager::Uploader; #inherits
95             $self->urlUpload('url');
96             $self->quit();
97             }
98              
99             # Reload menu
100             elsif ( my $menu = $self->param('menu') ) {
101              
102             $self->lmLog( "Manager request: Menu reload for num $menu", 'debug' );
103             $self->{cfgNum} = $menu;
104             print $self->header( -type => 'text/html;charset=utf-8' );
105             print $self->menu();
106             $self->quit();
107             }
108              
109             # Ask requests
110             elsif ( my $rreq = $self->rparam('request') ) {
111              
112             $self->lmLog( "Manager request: $rreq", 'debug' );
113             require Lemonldap::NG::Manager::Request; #inherits
114             $self->request($rreq);
115             $self->quit();
116             }
117              
118             # Else load conf
119             require Lemonldap::NG::Manager::Downloader; #inherits
120             $self->{cfgNum} = $self->param('cfgNum')
121             || $self->confObj->lastCfg();
122              
123             if ( my $p = $self->param('node') ) {
124              
125             $self->lmLog( "Manager request: load node $p", 'debug' );
126             print $self->header( -type => 'text/html; charset=utf8', );
127             print $self->node($p);
128             $self->quit();
129             }
130             if ( $self->param('cfgAttr') ) {
131              
132             $self->lmLog( "Manager request: load configuration attributes",
133             'debug' );
134             $self->sendCfgParams( $self->conf );
135             }
136              
137             return $self;
138             }
139              
140             ## @method string menu()
141             # Build the tree menu.
142             # @return HTML string
143             sub menu {
144             my $self = shift;
145             require Lemonldap::NG::Manager::Downloader;
146             return
147             '
    '
148             . $self->li( 'root', 'root' )
149             . $self->span(
150             id => 'root',
151             text => "Configuration $self->{cfgNum}",
152             data => $self->{cfgNum},
153             js => 'cfgDatas',
154             help => 'default'
155             )
156             . '
    '
157             . $self->node()
158             . '';
159             }
160              
161             1;
162             __END__