diff options
Diffstat (limited to 'lib/Fripost/Schema')
-rw-r--r-- | lib/Fripost/Schema/Result/Alias.pm | 52 | ||||
-rw-r--r-- | lib/Fripost/Schema/Result/Domain.pm | 51 | ||||
-rw-r--r-- | lib/Fripost/Schema/Result/Mailbox.pm | 72 | ||||
-rw-r--r-- | lib/Fripost/Schema/Search.pm | 111 | ||||
-rw-r--r-- | lib/Fripost/Schema/Type.pm | 48 |
5 files changed, 159 insertions, 175 deletions
diff --git a/lib/Fripost/Schema/Result/Alias.pm b/lib/Fripost/Schema/Result/Alias.pm deleted file mode 100644 index 4d9306c..0000000 --- a/lib/Fripost/Schema/Result/Alias.pm +++ /dev/null @@ -1,52 +0,0 @@ -package Fripost::Schema::Result::Alias; - -use 5.010_000; -use warnings; -use strict; - -use base qw/DBIx::Class::Core/; - -# mysql> describe alias; -# +-------------+--------------+------+-----+---------------------+-------+ -# | Field | Type | Null | Key | Default | Extra | -# +-------------+--------------+------+-----+---------------------+-------+ -# | address | varchar(255) | NO | PRI | | | -# | goto | text | NO | | NULL | | -# | domain | varchar(255) | NO | | | | -# | create_date | datetime | NO | | 0000-00-00 00:00:00 | | -# | change_date | timestamp | NO | | CURRENT_TIMESTAMP | | -# | active | tinyint(4) | NO | | 1 | | -# +-------------+--------------+------+-----+---------------------+-------+ -# 6 rows in set (0.00 sec) - -__PACKAGE__->load_components(qw/InflateColumn::DateTime/); - -__PACKAGE__->table('alias'); -__PACKAGE__->add_columns(qw/ address goto domain create_date change_date active /); -__PACKAGE__->add_columns( - create_date => { data_type => 'datetime', timezone => "Europe/Stockholm", locale => "se_SV" }, - change_date => { data_type => 'datetime', timezone => "Europe/Stockholm", locale => "se_SV" }, -); - -__PACKAGE__->set_primary_key('address'); - -=head1 NAME - -Fripost::Schema::Result::Alias - - -=head1 AUTHOR - -Stefan Kangas C<< <skangas at skangas.se> >> - -=head1 COPYRIGHT - -Copyright 2010,2011 Stefan Kangas, all rights reserved. - -=head1 LICENSE - -This program is free software; you can redistribute it and/or modify it -under the same terms as perl itself. - -=cut - -1; # End of Alias.pm diff --git a/lib/Fripost/Schema/Result/Domain.pm b/lib/Fripost/Schema/Result/Domain.pm deleted file mode 100644 index 36649de..0000000 --- a/lib/Fripost/Schema/Result/Domain.pm +++ /dev/null @@ -1,51 +0,0 @@ -package Fripost::Schema::Result::Domain; - -use 5.010_000; -use warnings; -use strict; - -use base qw/DBIx::Class::Core/; - -# mysql> describe domain; -# +-------------+--------------+------+-----+---------------------+-------+ -# | Field | Type | Null | Key | Default | Extra | -# +-------------+--------------+------+-----+---------------------+-------+ -# | domain | varchar(255) | NO | PRI | | | -# | description | varchar(255) | NO | | | | -# | create_date | datetime | NO | | 0000-00-00 00:00:00 | | -# | change_date | timestamp | NO | | CURRENT_TIMESTAMP | | -# | active | tinyint(4) | NO | | 1 | | -# +-------------+--------------+------+-----+---------------------+-------+ -# 5 rows in set (0.00 sec) - -__PACKAGE__->load_components(qw/InflateColumn::DateTime/); - -__PACKAGE__->table('domain'); -__PACKAGE__->add_columns(qw/ domain description create_date change_date active /); -__PACKAGE__->add_columns( - create_date => { data_type => 'datetime', timezone => "Europe/Stockholm", locale => "se_SV" }, - change_date => { data_type => 'datetime', timezone => "Europe/Stockholm", locale => "se_SV" }, -); - -__PACKAGE__->set_primary_key('domain'); - -=head1 NAME - -Fripost::Schema::Result::Domain - - -=head1 AUTHOR - -Stefan Kangas C<< <skangas at skangas.se> >> - -=head1 COPYRIGHT - -Copyright 2010, 2011 Stefan Kangas, all rights reserved. - -=head1 LICENSE - -This program is free software; you can redistribute it and/or modify it -under the same terms as perl itself. - -=cut - -1; # End of Domain.pm diff --git a/lib/Fripost/Schema/Result/Mailbox.pm b/lib/Fripost/Schema/Result/Mailbox.pm deleted file mode 100644 index 48d81fb..0000000 --- a/lib/Fripost/Schema/Result/Mailbox.pm +++ /dev/null @@ -1,72 +0,0 @@ -package Fripost::Schema::Result::Mailbox; - -use 5.010_000; -use warnings; -use strict; - -use base qw/DBIx::Class::Core/; - -use Fripost::Password; - -# mysql> describe mailbox; -# +-------------+--------------+------+-----+---------------------+-------+ -# | Field | Type | Null | Key | Default | Extra | -# +-------------+--------------+------+-----+---------------------+-------+ -# | username | varchar(255) | NO | PRI | | | -# | password | varchar(255) | NO | | | | -# | name | varchar(255) | NO | | | | -# | maildir | varchar(255) | NO | | | | -# | domain | varchar(255) | NO | | | | -# | create_date | datetime | NO | | 0000-00-00 00:00:00 | | -# | change_date | timestamp | NO | | CURRENT_TIMESTAMP | | -# | active | tinyint(4) | NO | | 1 | | -# +-------------+--------------+------+-----+---------------------+-------+ -# 8 rows in set (0.00 sec) - -__PACKAGE__->load_components(qw/InflateColumn::DateTime/); - -__PACKAGE__->table('mailbox'); -__PACKAGE__->add_columns(qw/ username password name maildir domain active /); -__PACKAGE__->add_columns( - create_date => { data_type => 'datetime', timezone => "Europe/Stockholm", locale => 'sv_SE' }, - change_date => { data_type => 'datetime', timezone => "Europe/Stockholm", locale => 'sv_SE' } -); - -__PACKAGE__->set_primary_key('username'); - -=head2 store_column - -override store_column to encrypt the password when stored - -=cut - -sub store_column { - my ($self, $col, $val) = @_; - - if ($col eq 'password') { - $val = smd5($val); - } - - return $self->next::method($col,$val); -} - -=head1 NAME - -Fripost::Schema::Result::Mailbox - - -=head1 AUTHOR - -Stefan Kangas C<< <skangas at skangas.se> >> - -=head1 COPYRIGHT - -Copyright 2010,2011 Stefan Kangas, all rights reserved. - -=head1 LICENSE - -This program is free software; you can redistribute it and/or modify it -under the same terms as perl itself. - -=cut - -1; # End of Mailbox.pm diff --git a/lib/Fripost/Schema/Search.pm b/lib/Fripost/Schema/Search.pm new file mode 100644 index 0000000..30d92d6 --- /dev/null +++ b/lib/Fripost/Schema/Search.pm @@ -0,0 +1,111 @@ +package Fripost::Schema::Search; + +use 5.010_000; +use warnings; +use strict; + +use Fripost::Schema::Type; + +use base qw/Net::LDAP::Search/; +our $VERSION = '0.01'; + +# Count the entries got out from the query. +sub count { $_[0]->{_res}->count } + +# Create a hash out of the LDAP entry. Keys depend on the context +# of the object. +# The value can be an array reference (multi-valued attributes) or +# a scalar (otherwise). +sub entries { + my $self = shift; + + my $dumpEntry; + if ( $self->{_type} == MAILBOX ) { + $dumpEntry = "_userEntry"; + } + elsif ( $self->{_type} == DOMAIN ) { + $dumpEntry = "_domainEntry"; + } + elsif ( $self->{_type} == ALIAS ) { + $dumpEntry = "_aliasEntry"; + } + else { + die "Something weird happened. Please report." + } + + no strict "refs"; + return (map {&$dumpEntry($_)} $self->{_res}->entries); +} + + +sub _userEntry { + my $entry = shift; + my %user; + &_get_values( $entry, \%user, 'username', 'uid'); + map { &_get_values($entry, \%user, $_) } + qw /maildir isActive userPassword/; + return \%user; +} + +sub _domainEntry { + my $entry = shift; + my %domain; + &_get_values( $entry, \%domain, 'domain', 'dc'); + &_get_values( $entry, \%domain, 'isActive'); + my $parent = &_get_dn($entry)->[1]; + unless ($parent eq 'ou=domains') { + $domain{owner} = (split /=/, $parent, 2)[1]; + } + return \%domain; +} + +sub _aliasEntry { + my $entry = shift; + my %alias; + &_get_values( $entry, \%alias, 'address', 'mailLocalAddress'); + &_get_values( $entry, \%alias, 'goto', 'mailTarget'); + &_get_values( $entry, \%alias, 'isActive'); + return \%alias; +} + +sub _get_values { + my ($entry, $h, $attr, $attr2) = @_; + $attr2 //= $attr; + my $values = $entry->get_value ( $attr2, asref => 1 ); + + return unless defined $values; + if ($#$values == 0) { + $h->{$attr} = $values->[0]; + } + else { + $h->{$attr} = $values; + } +} + +sub _get_dn { + return [split ',', $_[0]->dn()]; +} + + +=head1 NAME + +Fripost::Schema::Search - Class for the result of LDAP queries. + +=head1 AUTHOR + +Guilhem Moulin C<< <guilhem at fripost.org> >> + +=head1 COPYRIGHT + +Copyright 2012 Guilhem Moulin, all rights reserved. + +=head1 LICENSE + +This program is free software; you can redistribute it and/or modify it +under the same terms as perl itself. + +=cut + +1; # End of Search.pm + +__END__ diff --git a/lib/Fripost/Schema/Type.pm b/lib/Fripost/Schema/Type.pm new file mode 100644 index 0000000..bfa8f73 --- /dev/null +++ b/lib/Fripost/Schema/Type.pm @@ -0,0 +1,48 @@ +package Fripost::Schema::Type; + +use 5.010_000; +use warnings; +use strict; + +use Exporter; + +our $VERSION = '0.01'; + +our @EXPORT = qw/MAILBOX DOMAIN ALIAS/; +our @ISA = qw(Exporter); + +use constant { + MAILBOX => 0, + DOMAIN => 1, + ALIAS => 2 +}; + +# Change the context of the object. +sub _set_type { + $_[0]->{_type} = $_[1]; + return $_[0]; +} + + +=head1 NAME + +Fripost::Schema::Type - Context of Fripost::Schema objects. + +=head1 AUTHOR + +Guilhem Moulin C<< <guilhem at fripost.org> >> + +=head1 COPYRIGHT + +Copyright 2012 Guilhem Moulin, all rights reserved. + +=head1 LICENSE + +This program is free software; you can redistribute it and/or modify it +under the same terms as perl itself. + +=cut + +1; # End of Type.pm + +__END__ |