summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/acct_sql.pm
blob: c51ef6836c7e03ae7fdfb7c233f0446d8cccc29f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package FS::part_export::acct_sql;
use base qw( FS::part_export::sql_Common );

use strict;
use vars qw( %info );
use Tie::IxHash;
use FS::Record; #qw(qsearchs);

tie my %options, 'Tie::IxHash', %{__PACKAGE__->sql_options};
$options{'crypt'} = { label => 'Password encryption',
                      type=>'select', options=>[qw(crypt md5 sha1_base64 sha512)],
                      default=>'crypt',
                    };

tie my %vpopmail_map, 'Tie::IxHash',
  'pw_name'   => 'username',
  'pw_domain' => 'domain',
  'pw_passwd' => 'crypt_password',
  'pw_uid'    => 'uid',
  'pw_gid'    => 'gid',
  'pw_gecos'  => 'finger',
  'pw_dir'    => 'dir',
  #'pw_shell'  => 'shell',
  'pw_shell'  => 'quota',
;
my $vpopmail_map = join('\n', map "$_ $vpopmail_map{$_}", keys %vpopmail_map );

tie my %postfix_courierimap_mailbox_map, 'Tie::IxHash',
  'username' => 'email',
  'password' => '_password',
  'crypt'    => 'crypt_password',
  'name'     => 'finger',
  'maildir'  => 'virtual_maildir',
  'domain'   => 'domain',
  'svcnum'   => 'svcnum',
;
my $postfix_courierimap_mailbox_map =
  join('\n', map "$_ $postfix_courierimap_mailbox_map{$_}",
                 keys %postfix_courierimap_mailbox_map      );

tie my %postfix_courierimap_alias_map, 'Tie::IxHash',
  'address' => 'email',
  'goto'    => 'email',
  'domain'  => 'domain',
  'svcnum'  => 'svcnum',
;
my $postfix_courierimap_alias_map =
  join('\n', map "$_ $postfix_courierimap_alias_map{$_}",
                 keys %postfix_courierimap_alias_map      );

tie my %postfix_native_mailbox_map, 'Tie::IxHash',
  'userid'   => 'email',
  'uid'      => 'uid',
  'gid'      => 'gid',
  'password' => 'ldap_password',
  'mail'     => 'domain_slash_username',
;
my $postfix_native_mailbox_map =
  join('\n', map "$_ $postfix_native_mailbox_map{$_}",
                 keys %postfix_native_mailbox_map      );

tie my %libnss_pgsql_passwd_map, 'Tie::IxHash',
  'username' => 'username',
  #'passwd'   => literal string 'x'
  'uid'      => 'uid',
  'gid'      => 'gid',
  'gecos'    => 'finger',
  'homedir'  => 'dir',
  'shell'    => 'shell',
;
my $libnss_pgsql_passwd_map =
  join('\n', map "$_ $libnss_pgsql_passwd_map{$_}",
                 keys %libnss_pgsql_passwd_map      );

tie my %libnss_pgsql_passwd_static, 'Tie::IxHash',
  'passwd' => 'x',
;
my $libnss_pgsql_passwd_static =
  join('\n', map "$_ $libnss_pgsql_passwd_static{$_}",
                 keys %libnss_pgsql_passwd_static      );

tie my %libnss_pgsql_shadow_map, 'Tie::IxHash',
  'username' => 'username',
  'passwd'   => 'crypt_password',
;
my $libnss_pgsql_shadow_map =
  join('\n', map "$_ $libnss_pgsql_shadow_map{$_}",
                 keys %libnss_pgsql_shadow_map      );

tie my %libnss_pgsql_shadow_static, 'Tie::IxHash',
  'lastchange' => '18550', #not actually implemented..
  'min'        => '0',
  'max'        => '99999',
  'warn'       => '7',
  'inact'      => '0',
  'expire'     => '-1',
  'flag'       => '0',
;
my $libnss_pgsql_shadow_static =
  join('\n', map "$_ $libnss_pgsql_shadow_static{$_}",
                 keys %libnss_pgsql_shadow_static      );

%info = (
  'svc'        => 'svc_acct',
  'desc'       => 'Real-time export of accounts to SQL databases '.
                  '(vpopmail, Postfix+Courier IMAP, others?)',
  'options'    => \%options,
  'nodomain'   => '',
  'no_machine' => 1,
  'default_svc_class' => 'Email',
  'notes'    => <<END
Export accounts (svc_acct records) to SQL databases.  Currently has default
configurations for vpopmail, Postfix+Courier IMAP, Postfix native and ,
but can be configured for other schemas.

<BR><BR>In contrast to sqlmail, this is intended to export just svc_acct
records only, rather than a single export for svc_acct, svc_forward and
svc_domain records, to export in "default" database schemas rather than
configure servers for a Freeside-specific schema, and to be configured for
different mail (and authentication) server setups.

<BR><BR>Use these buttons for some useful presets:
<UL>
  <li><INPUT TYPE="button" VALUE="vpopmail" onClick='
    this.form.table.value = "vpopmail";
    this.form.schema.value = "$vpopmail_map";
    this.form.primary_key.value = "pw_name, pw_domain";
  '>
  <LI><INPUT TYPE="button" VALUE="postfix_courierimap_mailbox" onClick='
    this.form.table.value = "mailbox";
    this.form.schema.value = "$postfix_courierimap_mailbox_map";
    this.form.primary_key.value = "username";
  '>
  <LI><INPUT TYPE="button" VALUE="postfix_courierimap_alias" onClick='
    this.form.table.value = "alias";
    this.form.schema.value = "$postfix_courierimap_alias_map";
    this.form.primary_key.value = "address";
  '>
  <LI><INPUT TYPE="button" VALUE="postfix_native_mailbox" onClick='
    this.form.table.value = "users";
    this.form.schema.value = "$postfix_native_mailbox_map";
    this.form.primary_key.value = "userid";
  '>
  <LI><INPUT TYPE="button" VALUE="libnss-pgsql passwd" onClick='
    this.form.table.value = "passwd_table";
    this.form.schema.value = "$libnss_pgsql_passwd_map";
    this.form.static.value = "$libnss_pgsql_passwd_static";
    this.form.primary_key.value = "uid";
  '>
  <LI><INPUT TYPE="button" VALUE="libnss-pgsql shadow" onClick='
    this.form.table.value = "shadow_table";
    this.form.schema.value = "$libnss_pgsql_shadow_map";
    this.form.static.value = "$libnss_pgsql_shadow_static";
    this.form.primary_key.value = "username";
  '>
</UL>
END
);

sub _map_arg_callback {
  my($self, $field) = @_;
  my $crypt = $self->option('crypt');
  return () unless $field eq 'crypt_password' && $crypt;
  ($crypt);
}

1;