summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/acct_sql.pm
diff options
context:
space:
mode:
Diffstat (limited to 'FS/FS/part_export/acct_sql.pm')
-rw-r--r--FS/FS/part_export/acct_sql.pm105
1 files changed, 21 insertions, 84 deletions
diff --git a/FS/FS/part_export/acct_sql.pm b/FS/FS/part_export/acct_sql.pm
index 4b92e80..fb0299c 100644
--- a/FS/FS/part_export/acct_sql.pm
+++ b/FS/FS/part_export/acct_sql.pm
@@ -1,6 +1,6 @@
package FS::part_export::acct_sql;
-use vars qw(@ISA %info);
+use vars qw(@ISA %info @saltset);
use Tie::IxHash;
#use Digest::MD5 qw(md5_hex);
use FS::Record; #qw(qsearchs);
@@ -18,24 +18,7 @@ tie my %options, 'Tie::IxHash',
type => 'textarea',
},
'primary_key' => { label => 'Database primary key' },
- 'crypt' => { label => 'Password encryption',
- type=>'select', options=>[qw(crypt md5)],
- 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',
@@ -63,27 +46,23 @@ my $postfix_courierimap_alias_map =
%info = (
'svc' => 'svc_acct',
'desc' => 'Real-time export of accounts to SQL databases '.
- '(vpopmail, Postfix+Courier IMAP, others?)',
+ '(Postfix+Courier IMAP, others?)',
'options' => \%options,
'nodomain' => '',
'notes' => <<END
-Export accounts (svc_acct records) to SQL databases. Currently has default
-configurations for vpopmail and Postfix+Courier IMAP but intended to be
-configurable for other schemas as well.
+Export accounts (svc_acct records) to SQL databases. Written for
+Postfix+Courier IMAP but intended to be generally useful for generic SQL
+exports, eventually.
-<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 the MTA or POP/IMAP server for a Freeside-specific schema, and
-to be configured for different mail server setups.
+<BR><BR>In contrast to sqlmail, this is newer and less well tested, and
+currently less flexible. It 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" formats rather than configure the MTA or POP/IMAP server
+for a Freeside-specific schema, and possibly to be configured for different
+mail server setups through some subclassing rather than options.
<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";
@@ -111,10 +90,7 @@ sub _export_insert {
my %map = $self->_map;
my %record = map { my $value = $map{$_};
- my @arg = ();
- push @arg, $self->option('crypt')
- if $value eq 'crypt_password' && $self->option('crypt');
- $_ => $svc_acct->$value(@arg);
+ $_ => $svc_acct->$value();
} keys %map;
my $err_or_queue =
@@ -134,30 +110,17 @@ sub _export_replace {
my($self, $new, $old) = (shift, shift, shift);
my %map = $self->_map;
-
- my @primary_key = ();
- if ( $self->option('primary_key') =~ /,/ ) {
- foreach my $key ( split(/\s*,\s*/, $self->option('primary_key') ) ) {
- my $keymap = $map{$key};
- push @primary_key, $old->$keymap();
- }
- } else {
- my $keymap = $map{$self->option('primary_key')};
- push @primary_key, $old->$keymap();
- }
+ my $keymap = $map{$self->option('primary_key')};
my %record = map { my $value = $map{$_};
- my @arg = ();
- push @arg, $self->option('crypt')
- if $value eq 'crypt_password' && $self->option('crypt');
- $_ => $new->$value(@arg);
+ $_ => $new->$value();
} keys %map;
my $err_or_queue = $self->acct_sql_queue(
$new->svcnum,
'replace',
$self->option('table'),
- $self->option('primary_key'), @primary_key,
+ $self->option('primary_key') => $old->$keymap(),
%record,
);
return $err_or_queue unless ref($err_or_queue);
@@ -166,26 +129,13 @@ sub _export_replace {
sub _export_delete {
my ( $self, $svc_acct ) = (shift, shift);
-
my %map = $self->_map;
-
- my %primary_key = ();
- if ( $self->option('primary_key') =~ /,/ ) {
- foreach my $key ( split(/\s*,\s*/, $self->option('primary_key') ) ) {
- my $keymap = $map{$key};
- $primary_key{ $key } = $svc_acct->$keymap();
- }
- } else {
- my $keymap = $map{$self->option('primary_key')};
- $primary_key{ $self->option('primary_key') } = $svc_acct->$keymap(),
- }
-
+ my $keymap = $map{$self->option('primary_key')};
my $err_or_queue = $self->acct_sql_queue(
$svc_acct->svcnum,
'delete',
$self->option('table'),
- %primary_key,
- #$self->option('primary_key') => $svc_acct->$keymap(),
+ $self->option('primary_key') => $svc_acct->$keymap(),
);
return $err_or_queue unless ref($err_or_queue);
'';
@@ -236,27 +186,14 @@ sub acct_sql_delete { #subroutine, not method
sub acct_sql_replace { #subroutine, not method
my $dbh = acct_sql_connect(shift, shift, shift);
-
- my( $table, $pkey ) = ( shift, shift );
-
- my %primary_key = ();
- if ( $pkey =~ /,/ ) {
- foreach my $key ( split(/\s*,\s*/, $pkey ) ) {
- $primary_key{$key} = shift;
- }
- } else {
- $primary_key{$pkey} = shift;
- }
-
- my %record = @_;
+ my( $table, $pkey, $old_pkey, %record ) = @_;
my $sth = $dbh->prepare(
- "UPDATE $table".
- ' SET '. join(', ', map "$_ = ?", keys %record ).
- ' WHERE '. join(' AND ', map "$_ = ?", keys %primary_key )
+ "UPDATE $table SET ". join(', ', map "$_ = ?", keys %record ).
+ "WHERE $pkey = ?"
) or die $dbh->errstr;
- $sth->execute( values(%record), values(%primary_key) );
+ $sth->execute( values(%record), $old_pkey );
$dbh->disconnect;
}