doc/presets for libnss-pgsql use, add sha512crypt option, RT#84826
[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 sha512)],
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 tie my %libnss_pgsql_passwd_map, 'Tie::IxHash',
63   'username' => 'username',
64   #'passwd'   => literal string 'x'
65   'uid'      => 'uid',
66   'gid'      => 'gid',
67   'gecos'    => 'finger',
68   'homedir'  => 'dir',
69   'shell'    => 'shell',
70 ;
71 my $libnss_pgsql_passwd_map =
72   join('\n', map "$_ $libnss_pgsql_passwd_map{$_}",
73                  keys %libnss_pgsql_passwd_map      );
74
75 tie my %libnss_pgsql_passwd_static, 'Tie::IxHash',
76   'passwd' => 'x',
77 ;
78 my $libnss_pgsql_passwd_static =
79   join('\n', map "$_ $libnss_pgsql_passwd_static{$_}",
80                  keys %libnss_pgsql_passwd_static      );
81
82 tie my %libnss_pgsql_shadow_map, 'Tie::IxHash',
83   'username' => 'username',
84   'passwd'   => 'crypt_password',
85 ;
86 my $libnss_pgsql_shadow_map =
87   join('\n', map "$_ $libnss_pgsql_shadow_map{$_}",
88                  keys %libnss_pgsql_shadow_map      );
89
90 tie my %libnss_pgsql_shadow_static, 'Tie::IxHash',
91   'lastchange' => '18550', #not actually implemented..
92   'min'        => '0',
93   'max'        => '99999',
94   'warn'       => '7',
95   'inact'      => '0',
96   'expire'     => '-1',
97   'flag'       => '0',
98 ;
99 my $libnss_pgsql_shadow_static =
100   join('\n', map "$_ $libnss_pgsql_shadow_static{$_}",
101                  keys %libnss_pgsql_shadow_static      );
102
103 %info = (
104   'svc'        => 'svc_acct',
105   'desc'       => 'Real-time export of accounts to SQL databases '.
106                   '(vpopmail, Postfix+Courier IMAP, others?)',
107   'options'    => \%options,
108   'nodomain'   => '',
109   'no_machine' => 1,
110   'default_svc_class' => 'Email',
111   'notes'    => <<END
112 Export accounts (svc_acct records) to SQL databases.  Currently has default
113 configurations for vpopmail, Postfix+Courier IMAP, Postfix native and ,
114 but can be configured for other schemas.
115
116 <BR><BR>In contrast to sqlmail, this is intended to export just svc_acct
117 records only, rather than a single export for svc_acct, svc_forward and
118 svc_domain records, to export in "default" database schemas rather than
119 configure servers for a Freeside-specific schema, and to be configured for
120 different mail (and authentication) server setups.
121
122 <BR><BR>Use these buttons for some useful presets:
123 <UL>
124   <li><INPUT TYPE="button" VALUE="vpopmail" onClick='
125     this.form.table.value = "vpopmail";
126     this.form.schema.value = "$vpopmail_map";
127     this.form.primary_key.value = "pw_name, pw_domain";
128   '>
129   <LI><INPUT TYPE="button" VALUE="postfix_courierimap_mailbox" onClick='
130     this.form.table.value = "mailbox";
131     this.form.schema.value = "$postfix_courierimap_mailbox_map";
132     this.form.primary_key.value = "username";
133   '>
134   <LI><INPUT TYPE="button" VALUE="postfix_courierimap_alias" onClick='
135     this.form.table.value = "alias";
136     this.form.schema.value = "$postfix_courierimap_alias_map";
137     this.form.primary_key.value = "address";
138   '>
139   <LI><INPUT TYPE="button" VALUE="postfix_native_mailbox" onClick='
140     this.form.table.value = "users";
141     this.form.schema.value = "$postfix_native_mailbox_map";
142     this.form.primary_key.value = "userid";
143   '>
144   <LI><INPUT TYPE="button" VALUE="libnss-pgsql passwd" onClick='
145     this.form.table.value = "passwd_table";
146     this.form.schema.value = "$libnss_pgsql_passwd_map";
147     this.form.static.value = "$libnss_pgsql_passwd_static";
148     this.form.primary_key.value = "uid";
149   '>
150   <LI><INPUT TYPE="button" VALUE="libnss-pgsql shadow" onClick='
151     this.form.table.value = "shadow_table";
152     this.form.schema.value = "$libnss_pgsql_shadow_map";
153     this.form.static.value = "$libnss_pgsql_shadow_static";
154     this.form.primary_key.value = "username";
155   '>
156 </UL>
157 END
158 );
159
160 sub _map_arg_callback {
161   my($self, $field) = @_;
162   my $crypt = $self->option('crypt');
163   return () unless $field eq 'crypt_password' && $crypt;
164   ($crypt);
165 }
166
167 1;
168