package LATMOS::Accounts::Web;

use strict;
use warnings;
no utf8;

use Catalyst::Runtime '5.70';

# Set flags and add plugins for the application
#
#         -Debug: activates the debug mode for very useful log messages
#   ConfigLoader: will load the configuration from a YAML file in the
#                 application's home directory
# Static::Simple: will serve static files from the application's root 
#                 directory

use Catalyst qw/
    ConfigLoader
    Static::Simple
    Session
    Session::State::Cookie
    Session::Store::File
    Authentication
    Prototype
    XMLRPC
    /;

our $VERSION = '4.0.0';

# Configure the application. 

# Default value for active/inactive features
__PACKAGE__->config(
    features => {
        # /services/mailing, mass mailing
        mailing => 0,
        # /summary/offices
        offices_list => 0,
        # /summary/department
        departments_list => 0,
        # users/address forms
        user_addresses => 1,
        # users/email form
        user_email => 1,
        # users/my form
        user_my => 1,
    }
);

__PACKAGE__->config(
    objects => {
        user => {
            quick_search => [ qw(cn sn givenName) ],
            list => [ qw(sn givenName mail) ],
        },
        group => {
            quick_search => [ qw(cn description) ],
            list => [ qw(description) ],
        },
        nethost => {
            quick_search => [ qw(cn description ip cname otherName) ],
            list => [ qw(description owner) ],
        },
        netzone => {
            quick_search => [ qw(cn description ip) ],
            list => [ qw(type description) ],
        },
        site => {
            quick_search => [ qw(cn l) ],
            list => [ qw(l) ],
        },
        aliases => {
            quick_search => [ qw(name) ],
            list => [ qw() ],
        },

    },
    'attrs' => {
        'physicalDeliveryOfficeName' => {
            'label' => 'Bureau'
        },
        'sutype' => {
            'label' => 'Structure admin.'
        },
        'department' => {
            'label' => "Departement"
        },
        'macaddr' => {
            'label' => 'Adresse Ethernet'
        },
        'date' => {
            'label' => "Modifié le"
        },
        'cn' => {
            'label' => 'Nom'
        },
        'grade' => {
            'label' => 'Grade'
        },
        'net' => {
            'label' => "Réseau"
        },
        'cname' => {
            'label' => 'Alias (CName)'
        },
        'netExclude' => {
            'label' => "Réseau exclus"
        },
        'contratType' => {
            'label' => 'Type de contrat'
        },
        'co' => {
            'label' => 'Pays'
        },
        'template' => {
            'label' => "Modèle"
        },
        'uid' => {
            'label' => 'Login'
        },
        'otherTelephone' => {
            'label' => "Téléphone (autre)"
        },
        'name' => {
            'label' => 'Nom'
        },
        'telephoneNumber' => {
            'label' => "Téléphone"
        },
        'noDynamic' => {
            'label' => 'Pas d\'adressage dyn.'
        },
        'st' => {
            'label' => "Etat (US)"
        },
        'output' => {
            'label' => 'Sortie'
        },
        'description' => {
            'label' => 'Description'
        },
        'facsimileTelephoneNumber' => {
            'label' => 'Fax'
        },
        'isMainAddress' => {
            'label' => 'Adresse principale'
        },
        'streetAddress' => {
            'label' => 'Rue'
        },
        'gidNumber' => {
            'label' => 'GID'
        },
        'sn' => {
            'label' => 'Nom'
        },
        'type' => {
            'label' => 'Type'
        },
        'unexported' => {
            'label' => "Caché"
        },
        'title' => {
            'label' => 'Fonction'
        },
        'givenName' => {
            'label' => "Prénom"
        },
        'loginShell' => {
            'label' => 'Shell'
        },
        'uidNumber' => {
            'label' => 'UID'
        },
        'gecos' => {
            'label' => 'Gecos Unix'
        },
        'mail' => {
            'label' => 'Mail'
        },
        'company' => {
            'label' => "Société"
        },
        'owner' => {
            'label' => "Propriétaire"
        },
        'create' => {
            'label' => "Créé le"
        },
        'initials' => {
            'label' => 'Initiales'
        },
        'locked' => {
            'label' => "Verrouillé"
        },
        'nickname' => {
            'label' => 'Nick'
        },
        'managedBy' => {
            'label' => 'Responsable'
        },
        'homeDirectory' => {
            'label' => 'Home'
        },
        'college' => {
            'label' => 'College'
        },
        'manager' => {
            'label' => 'Responsable'
        },
        'l' => {
            'label' => 'Ville'
        },
        'managerContact' => {
            'label' => 'Contact'
        },
        'site' => {
            'label' => 'Site'
        },
        'postOfficeBox' => {
            'label' => 'BP'
        },
        'exported' => {
            'label' => "Propagé"
        },
        'expire' => {
            'label' => 'Expire le'
        },
        'postalCode' => {
            'label' => 'Code postal'
        },
        user => {
            'label' => 'Utilisateur',
        },
        snNative => {
            'label' => 'Nom d\'origine',
        },
        givenNameNative => {
            'label' => 'Prénom d\'origine',
        },
        wWWHomePage  => {
            label => 'Page Web',
        },
        halReference  => {
            label => 'Identifiant Hal',
        },
        siteNick => {
            label => 'Nom court',
        },
        otherName => {
            label => 'Autre nom (A)',
        },
        outputD => {
            label => 'Fichier de sortie',
        },
        templateD => {
            label => 'Modèle',
        },
        allow_dyn => {
            label => 'Avec DHCP dyn.',
        },
        dynFrom => {
            label => 'Hôtes dyn. depuis',
        },
        domain => {
            label => 'Domaine',
        },
        ipCount => {
            label => 'Nb d\'IP',
        },
        freeIPCount => {
            label => 'Nb d\'IP libres',
        },
        dnsRevision => {
            label => 'Révision DNS',
        },
        lastUpdate => {
            label => 'Dernière MAJ',
        },
        reverse => {
            label => 'Nom inverse',
        },
        finalpoint => {
            label => 'Destinataires',
        },
        parents => {
            label => 'Alias parents',
        },
        forward => {
            label => 'Renvois',
        },
        managedAlsoBy => {
            label => 'Resp. Adj.',
        },
        autoMemberFilter => {
            label => 'Filtre d\'appatenance',
        },
    },
);

my $config_file = '/etc/latmos-accounts/latmos-accounts-web.yml';
if (-r $config_file ) {
    __PACKAGE__->config( 'Plugin::ConfigLoader' => { 
            file => $config_file 
        } 
    );
}

# http://stackoverflow.com/questions/1664816/is-there-a-way-to-force-c-urifor-in-catalyst-to-generate-a-uri-that-begins-wit
__PACKAGE__->config( using_frontend_proxy => 1 );

__PACKAGE__->config( name => 'LATMOS::Accounts::Web' );

__PACKAGE__->config->{'Plugin::Authentication'} = {
    default_realm => 'la',
    realms => {
        la => {
            credential => {
                class => 'La'
            },
            store => {
                class => 'Null',
            },
        },
    },
};


# Start the application
__PACKAGE__->setup;


=head1 NAME

LATMOS::Accounts::Web - Catalyst based application

=head1 SYNOPSIS

    script/latmos_accounts_web_server.pl

=head1 DESCRIPTION

[enter your description here]

=head1 SEE ALSO

L<LATMOS::Accounts::Web::Controller::Root>, L<Catalyst>

=head1 AUTHOR

Thauvin Olivier

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
