ffe39caa5290876d12d551539a0ad0eae7922f57
[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   'notes'    => <<END
69 Export accounts (svc_acct records) to SQL databases.  Currently has default
70 configurations for vpopmail and Postfix+Courier IMAP but intended to be
71 configurable for other schemas as well.
72
73 <BR><BR>In contrast to sqlmail, this is intended to export just svc_acct
74 records only, rather than a single export for svc_acct, svc_forward and
75 svc_domain records, to export in "default" database schemas rather than
76 configure the MTA or POP/IMAP server for a Freeside-specific schema, and
77 to be configured for different mail server setups.
78
79 <BR><BR>Use these buttons for some useful presets:
80 <UL>
81   <li><INPUT TYPE="button" VALUE="vpopmail" onClick='
82     this.form.table.value = "vpopmail";
83     this.form.schema.value = "$vpopmail_map";
84     this.form.primary_key.value = "pw_name, pw_domain";
85   '>
86   <LI><INPUT TYPE="button" VALUE="postfix_courierimap_mailbox" onClick='
87     this.form.table.value = "mailbox";
88     this.form.schema.value = "$postfix_courierimap_mailbox_map";
89     this.form.primary_key.value = "username";
90   '>
91   <LI><INPUT TYPE="button" VALUE="postfix_courierimap_alias" onClick='
92     this.form.table.value = "alias";
93     this.form.schema.value = "$postfix_courierimap_alias_map";
94     this.form.primary_key.value = "address";
95   '>
96   <LI><INPUT TYPE="button" VALUE="postfix_native_mailbox" onClick='
97     this.form.table.value = "users";
98     this.form.schema.value = "$postfix_native_mailbox_map";
99     this.form.primary_key.value = "userid";
100   '>
101 </UL>
102 END
103 );
104
105 sub _map_arg_callback {
106   my($self, $field) = @_;
107   my $crypt = $self->option('crypt');
108   return () unless $field eq 'crypt_password' && $crypt;
109   ($crypt);
110 }
111
112 1;
113