1 | package LATMOS::Accounts::Bases::Zimbra; |
---|
2 | |
---|
3 | use 5.010000; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | |
---|
7 | use base qw(LATMOS::Accounts::Bases); |
---|
8 | use LATMOS::Accounts::Log; |
---|
9 | use SOAP::Lite; |
---|
10 | use HTTP::Cookies; |
---|
11 | use XML::XPath; |
---|
12 | |
---|
13 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
14 | |
---|
15 | =head1 NAME |
---|
16 | |
---|
17 | LATMOS::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 | |
---|
27 | Account base access over standard unix file format. |
---|
28 | |
---|
29 | =head1 FUNCTIONS |
---|
30 | |
---|
31 | =cut |
---|
32 | |
---|
33 | =head2 new(%config) |
---|
34 | |
---|
35 | Create a new LATMOS::Ad object for windows AD $domain. |
---|
36 | |
---|
37 | domain / server: either the Ad domain or directly the server |
---|
38 | |
---|
39 | ldap_args is an optionnal list of arguments to pass to L<Net::LDAP>. |
---|
40 | |
---|
41 | =cut |
---|
42 | |
---|
43 | sub 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 | |
---|
56 | sub DESTROY { |
---|
57 | my ($self) = @_; |
---|
58 | $self->{_db} && $self->{_db}->rollback; |
---|
59 | } |
---|
60 | |
---|
61 | =head2 load |
---|
62 | |
---|
63 | Read file and load data into memory |
---|
64 | |
---|
65 | =cut |
---|
66 | |
---|
67 | sub 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 | |
---|
107 | Perform a call to zimbra SOAP interface, return an C<XML::XPath> Object. |
---|
108 | |
---|
109 | Return nothing if an error is returned. |
---|
110 | |
---|
111 | =cut |
---|
112 | |
---|
113 | sub 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 | |
---|
128 | 1; |
---|
129 | |
---|
130 | __END__ |
---|
131 | |
---|
132 | =head1 SEE ALSO |
---|
133 | |
---|
134 | =head1 AUTHOR |
---|
135 | |
---|
136 | Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
137 | |
---|
138 | =head1 COPYRIGHT AND LICENSE |
---|
139 | |
---|
140 | Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS |
---|
141 | |
---|
142 | This library is free software; you can redistribute it and/or modify |
---|
143 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
144 | at your option, any later version of Perl 5 you may have available. |
---|
145 | |
---|
146 | |
---|
147 | =cut |
---|