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