source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Zimbra.pm @ 1904

Last change on this file since 1904 was 1376, checked in by nanardon, 9 years ago

Add Zimbra support

File size: 2.7 KB
Line 
1package LATMOS::Accounts::Bases::Zimbra;
2
3use 5.010000;
4use strict;
5use warnings;
6
7use base qw(LATMOS::Accounts::Bases);
8use LATMOS::Accounts::Log;
9use SOAP::Lite;
10use HTTP::Cookies;
11use XML::XPath;
12
13our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
14
15=head1 NAME
16
17LATMOS::Zimbra - Perl extension for blah blah blah
18
19=head1 SYNOPSIS
20
21  use LATMOS::Accounts::Bases;
22  my $base = LATMOS::Accounts::Bases->new('unix');
23  ...
24
25=head1 DESCRIPTION
26
27Account base access over standard unix file format.
28
29=head1 FUNCTIONS
30
31=cut
32
33=head2 new(%config)
34
35Create a new LATMOS::Ad object for windows AD $domain.
36
37domain / server: either the Ad domain or directly the server
38
39ldap_args is an optionnal list of arguments to pass to L<Net::LDAP>.
40
41=cut
42
43sub new {
44    my ($class, %config) = @_;
45   
46    my $base = {
47        login => $config{login},
48        password => $config{password},
49        url => $config{url},
50        domain => $config{domain},
51    };
52
53    bless($base, $class);
54}
55
56sub DESTROY {
57    my ($self) = @_;
58    $self->{_db} && $self->{_db}->rollback;
59}
60
61=head2 load
62
63Read file and load data into memory
64
65=cut
66
67sub load {
68    my ($self) = @_;
69
70    $self->{soap} and return 1;
71
72    my $soap = SOAP::Lite->new();
73
74    $soap->proxy(
75        $self->{url},
76        ssl_opts => [
77            verify_hostname => 0,
78            SSL_verify_mode => 0x00,
79        ],
80        cookie_jar => HTTP::Cookies->new(ignore_discard => 1),
81    );
82
83    $soap->default_ns('urn:zimbraAdmin');
84    my $som = $soap->call('AuthRequest',
85        SOAP::Data->name('account')
86            ->value( $self->{login} )
87            ->attr({ by => 'name' }),
88        SOAP::Data->name('password')
89            ->value($self->{password}),
90        SOAP::Data->name('persistAuthTokenCookie')
91            ->value('1'),
92    );
93
94    if ($som->fault) {
95        la_log(LA_ERR, "Cannot connect to Zimbra using SOAP: %s", $som->faultstring);
96        return;
97    }
98
99    $soap->outputxml(1);
100    $self->{soap} = $soap;
101
102    1;
103}
104
105=head2 soapcall (@args)
106
107Perform a call to zimbra SOAP interface, return an C<XML::XPath> Object.
108
109Return nothing if an error is returned.
110
111=cut
112
113sub soapcall {
114    my ($self, @args) = @_;
115
116    my $xml = $self->{soap}->call(@args);
117
118    my $xpath = XML::XPath->new(xml => $xml);
119
120    if (my $node = $xpath->findnodes('//faultstring')) {
121        la_log(LA_ERR, "Saop error: %s", $node->string_value);
122        return;
123    }
124
125    return $xpath;
126}
127
1281;
129
130__END__
131
132=head1 SEE ALSO
133
134=head1 AUTHOR
135
136Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
137
138=head1 COPYRIGHT AND LICENSE
139
140Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS
141
142This library is free software; you can redistribute it and/or modify
143it under the same terms as Perl itself, either Perl version 5.10.0 or,
144at your option, any later version of Perl 5 you may have available.
145
146
147=cut
Note: See TracBrowser for help on using the repository browser.