RT# 83450 - fixed rateplan export
[freeside.git] / FS / FS / part_export / acct_sql.pm
1 package FS::part_export::acct_sql;
2 use base qw( FS::part_export::sql_Common );
3
4 use strict;
5 use vars qw( %info );
6 use Tie::IxHash;
7 use FS::Record; #qw(qsearchs);
8
9 tie my %options, 'Tie::IxHash', %{__PACKAGE__->sql_options};
10 $options{'crypt'} = { label => 'Password encryption',
11                       type=>'select', options=>[qw(crypt md5 sha1_base64)],
12                       default=>'crypt',
13                     };
14
15 tie my %vpopmail_map, 'Tie::IxHash',
16   'pw_name'   => 'username',
17   'pw_domain' => 'domain',
18   'pw_passwd' => 'crypt_password',
19   'pw_uid'    => 'uid',
20   'pw_gid'    => 'gid',
21   'pw_gecos'  => 'finger',
22   'pw_dir'    => 'dir',
23   #'pw_shell'  => 'shell',
24   'pw_shell'  => 'quota',
25 ;
26 my $vpopmail_map = join('\n', map "$_ $vpopmail_map{$_}", keys %vpopmail_map );
27
28 tie my %postfix_courierimap_mailbox_map, 'Tie::IxHash',
29   'username' => 'email',
30   'password' => '_password',
31   'crypt'    => 'crypt_password',
32   'name'     => 'finger',
33   'maildir'  => 'virtual_maildir',
34   'domain'   => 'domain',
35   'svcnum'   => 'svcnum',
36 ;
37 my $postfix_courierimap_mailbox_map =
38   join('\n', map "$_ $postfix_courierimap_mailbox_map{$_}",
39                  keys %postfix_courierimap_mailbox_map      );
40
41 tie my %postfix_courierimap_alias_map, 'Tie::IxHash',
42   'address' => 'email',
43   'goto'    => 'email',
44   'domain'  => 'domain',
45   'svcnum'  => 'svcnum',
46 ;
47 my $postfix_courierimap_alias_map =
48   join('\n', map "$_ $postfix_courierimap_alias_map{$_}",
49                  keys %postfix_courierimap_alias_map      );
50
51 tie my %postfix_native_mailbox_map, 'Tie::IxHash',
52   'userid'   => 'email',
53   'uid'      => 'uid',
54   'gid'      => 'gid',
55   'password' => 'ldap_password',
56   'mail'     => 'domain_slash_username',
57 ;
58 my $postfix_native_mailbox_map =
59   join('\n', map "$_ $postfix_native_mailbox_map{$_}",
60                  keys %postfix_native_mailbox_map      );
61
62 %info = (
63   'svc'        => 'svc_acct',
64   'desc'       => 'Real-time export of accounts to SQL databases '.
65                   '(vpopmail, Postfix+Courier IMAP, others?)',
66   'options'    => \%options,
67   'nodomain'   => '',
68   'no_machine' => 1,
69   'default_svc_class' => 'Email',
70   'notes'    => <<END
71 Export accounts (svc_acct records) to SQL databases.  Currently has default
72 configurations for vpopmail and Postfix+Courier IMAP but intended to be
73 configurable for other schemas as well.
74
75 <BR><BR>In contrast to sqlmail, this is intended to export just svc_acct
76 records only, rather than a single export for svc_acct, svc_forward and
77 svc_domain records, to export in "default" database schemas rather than
78 configure the MTA or POP/IMAP server for a Freeside-specific schema, and
79 to be configured for different mail server setups.
80
81 <BR><BR>Use these buttons for some useful presets:
82 <UL>
83   <li><INPUT TYPE="button" VALUE="vpopmail" onClick='
84     this.form.table.value = "vpopmail";
85     this.form.schema.value = "$vpopmail_map";
86     this.form.primary_key.value = "pw_name, pw_domain";
87   '>
88   <LI><INPUT TYPE="button" VALUE="postfix_courierimap_mailbox" onClick='
89     this.form.table.value = "mailbox";
90     this.form.schema.value = "$postfix_courierimap_mailbox_map";
91     this.form.primary_key.value = "username";
92   '>
93   <LI><INPUT TYPE="button" VALUE="postfix_courierimap_alias" onClick='
94     this.form.table.value = "alias";
95     this.form.schema.value = "$postfix_courierimap_alias_map";
96     this.form.primary_key.value = "address";
97   '>
98   <LI><INPUT TYPE="button" VALUE="postfix_native_mailbox" onClick='
99     this.form.table.value = "users";
100     this.form.schema.value = "$postfix_native_mailbox_map";
101     this.form.primary_key.value = "userid";
102   '>
103 </UL>
104 END
105 );
106
107 sub _map_arg_callback {
108   my($self, $field) = @_;
109   my $crypt = $self->option('crypt');
110   return () unless $field eq 'crypt_password' && $crypt;
111   ($crypt);
112 }
113
114 1;
115