Manager.pm 5.28 KB
Newer Older
Xavier Guimard's avatar
Xavier Guimard committed
1 2 3 4 5
## @file
# Lemonldap::NG manager main file

## @class
# Lemonldap::NG manager main class
6 7 8
package Lemonldap::NG::Manager;

use strict;
Xavier Guimard's avatar
Xavier Guimard committed
9
use Lemonldap::NG::Handler::CGI qw(:globalStorage :locationRules);    #inherits
10 11
use Lemonldap::NG::Common::Conf;              #link protected conf Configuration
use Lemonldap::NG::Common::Conf::Constants;   #inherits
12

13
our $VERSION = '1.2.3';
Xavier Guimard's avatar
Xavier Guimard committed
14 15 16 17
our @ISA     = qw(
  Lemonldap::NG::Handler::CGI
  Lemonldap::NG::Manager::Downloader
  Lemonldap::NG::Manager::Uploader
18
  Lemonldap::NG::Manager::Request
Xavier Guimard's avatar
Xavier Guimard committed
19 20 21
  Lemonldap::NG::Manager::_Struct
  Lemonldap::NG::Manager::_i18n
);
22

Xavier Guimard's avatar
Xavier Guimard committed
23 24 25 26
## @cmethod Lemonldap::NG::Manager new(hashRef args)
# Class constructor.
#@param args hash reference
#@return Lemonldap::NG::Manager object
27
sub new {
28
    my ( $class, $args ) = @_;
29

30 31 32
    # Output UTF-8
    binmode( STDOUT, ':utf8' );

33
    # Try to load local configuration parameters
Xavier Guimard's avatar
Xavier Guimard committed
34 35 36 37 38
    my $conf = Lemonldap::NG::Common::Conf->new( $args->{configStorage} )
      or Lemonldap::NG::Handler::CGI->abort( 'Unable to get configuration',
        $Lemonldap::NG::Common::Conf::msg );
    if ( my $localconf = $conf->getLocalConf(MANAGERSECTION) ) {
        $args->{$_} ||= $localconf->{$_} foreach ( keys %$localconf );
39 40
    }

Xavier Guimard's avatar
Xavier Guimard committed
41 42 43 44
    my $self = $class->SUPER::new($args)
      or $class->abort( 'Unable to start ' . __PACKAGE__,
        'See Apache logs for more' );

45
    # Default values
46 47
    $self->{managerSkin} = "default"       unless defined $self->{managerSkin};
    $self->{managerCss}  = "accordion.css" unless defined $self->{managerCss};
48 49
    $self->{managerCssTheme} = "ui-lightness"
      unless defined $self->{managerCssTheme};
50 51 52 53
    $self->{managerTreeAutoClose} = "true"
      unless defined $self->{managerTreeAutoClose};
    $self->{managerTreeJqueryCss} = "true"
      unless defined $self->{managerTreeJqueryCss};
54

55
    # Save conf if ?data=
Xavier Guimard's avatar
Xavier Guimard committed
56
    if ( my $rdata = $self->rparam('data') ) {
Xavier Guimard's avatar
Xavier Guimard committed
57

58
        $self->lmLog( "Manager request: Save data $rdata", 'debug' );
Xavier Guimard's avatar
Xavier Guimard committed
59 60 61 62
        require Lemonldap::NG::Manager::Uploader;    #inherits
        $self->confUpload($rdata);
        $self->quit();
    }
63

64
    # File upload/download
65 66
    elsif ( my $rfile = $self->rparam('file') ) {

67
        $self->lmLog( "Manager request: File $rfile", 'debug' );
Xavier Guimard's avatar
Xavier Guimard committed
68 69 70
        my @params = ('file');
        if ( my $rfilename = $self->rparam('filename') ) {
            push @params, ${$rfilename};
71
        }
72
        require Lemonldap::NG::Manager::Uploader;    #inherits
73 74
        $self->fileUpload(@params);
        $self->quit();
Xavier Guimard's avatar
Xavier Guimard committed
75
    }
76 77 78 79

    # URL upload/download
    elsif ( my $rurl = $self->rparam('url') ) {

80
        $self->lmLog( "Manager request: URL $rurl", 'debug' );
81 82
        require Lemonldap::NG::Manager::Uploader;    #inherits
        $self->urlUpload('url');
83 84 85
        $self->quit();
    }

86 87 88 89 90 91 92 93 94 95
    # Reload menu
    elsif ( my $menu = $self->param('menu') ) {

        $self->lmLog( "Manager request: Menu reload for num $menu", 'debug' );
        $self->{cfgNum} = $menu;
        print $self->header( -type => 'text/html;charset=utf-8' );
        print $self->menu();
        $self->quit();
    }

96 97 98
    # Ask requests
    elsif ( my $rreq = $self->rparam('request') ) {

99
        $self->lmLog( "Manager request: $rreq", 'debug' );
100
        require Lemonldap::NG::Manager::Request;    #inherits
101 102 103 104
        $self->request($rreq);
        $self->quit();
    }

105
    # Else load conf
106
    require Lemonldap::NG::Manager::Downloader;     #inherits
Xavier Guimard's avatar
Xavier Guimard committed
107 108 109 110
    $self->{cfgNum} =
         $self->param('cfgNum')
      || $self->confObj->lastCfg()
      || 'UNAVAILABLE';
111

Xavier Guimard's avatar
Xavier Guimard committed
112
    if ( my $p = $self->param('node') ) {
113 114

        $self->lmLog( "Manager request: load node $p", 'debug' );
Xavier Guimard's avatar
Xavier Guimard committed
115 116 117 118
        print $self->header( -type => 'text/html; charset=utf8', );
        print $self->node($p);
        $self->quit();
    }
Xavier Guimard's avatar
Xavier Guimard committed
119
    if ( $self->param('cfgAttr') ) {
120 121 122

        $self->lmLog( "Manager request: load configuration attributes",
            'debug' );
Xavier Guimard's avatar
Xavier Guimard committed
123
        $self->sendCfgParams( $self->conf );
Xavier Guimard's avatar
Xavier Guimard committed
124
    }
125

Xavier Guimard's avatar
Xavier Guimard committed
126 127 128
    return $self;
}

Xavier Guimard's avatar
Xavier Guimard committed
129 130 131
## @method string menu()
# Build the tree menu.
# @return HTML string
Xavier Guimard's avatar
Xavier Guimard committed
132
sub menu {
133
    my $self = shift;
Xavier Guimard's avatar
Xavier Guimard committed
134
    require Lemonldap::NG::Manager::Downloader;
Xavier Guimard's avatar
Xavier Guimard committed
135 136 137
    return
        '<ul class="simpleTree">' 
      . $self->li( 'root', 'root' )
Xavier Guimard's avatar
Xavier Guimard committed
138 139 140 141 142 143 144
      . $self->span(
        id   => 'root',
        text => "Configuration $self->{cfgNum}",
        data => $self->{cfgNum},
        js   => 'cfgDatas',
        help => 'default'
      )
Xavier Guimard's avatar
Xavier Guimard committed
145 146 147 148 149 150
      . '<ul>'
      . $self->node()
      . '</ul></li></ul>';
}

1;
151 152 153 154
__END__

=head1 NAME

Xavier Guimard's avatar
Xavier Guimard committed
155 156
=encoding utf8

157 158 159 160 161
Lemonldap::NG::Manager - Perl extension for managing Lemonldap::NG Web-SSO
system.

=head1 SYNOPSIS

162
See example/index.pl
163 164 165 166 167 168 169 170 171

=head1 DESCRIPTION

Lemonldap::NG::Manager provides a web interface to manage Lemonldap::NG Web-SSO
system.

=head1 SEE ALSO

L<Lemonldap::NG::Handler>, L<Lemonldap::NG::Portal>, L<CGI>,
Xavier Guimard's avatar
Xavier Guimard committed
172
L<http://lemonldap-ng.org/>
173 174 175 176 177 178 179 180

=head1 AUTHOR

Xavier Guimard, E<lt>x.guimard@free.frE<gt>

=head1 BUG REPORT

Use OW2 system to report bug or ask for features:
Xavier Guimard's avatar
Xavier Guimard committed
181
L<http://jira.ow2.org>
182 183 184 185 186 187 188 189

=head1 DOWNLOAD

Lemonldap::NG is available at
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>

=head1 COPYRIGHT AND LICENSE

190
Copyright (C) 2006, 2009, 2010 by Xavier Guimard
191 192

This library is free software; you can redistribute it and/or modify
Xavier Guimard's avatar
Xavier Guimard committed
193
it under the same terms as Perl itself, either Perl version 5.10.0 or,
194 195 196
at your option, any later version of Perl 5 you may have available.

=cut