-sub icradius_rc_replace {
- my( $username, $new_password ) = @_;
-
- my $sth = $icradius_dbh->prepare(
- "UPDATE radcheck SET Value = ? WHERE UserName = ? and Attribute = ?"
- );
- $sth->execute($new_password, $username, 'Password' )
- or die "can't update radcheck table: ". $sth->errstr;
+sub cp_rename {
+ my ( $old_username, $new_username ) = @_;
+
+ my $app = new Net::APP ( $cp_server,
+ User => $cp_user,
+ Password => $cp_pass,
+ Domain => $mydomain,
+ Timeout => 60,
+ #Debug => 1,
+ ) or die "$@\n";
+
+ $app->rename_mailbox(
+ Domain => $mydomain,
+ Old_Mailbox => $old_username,
+ New_Mailbox => $new_username,
+ );
+
+ die $app->message."\n" unless $app->ok;
+
+}
+
+sub cp_change {
+ my ( $username, $password ) = @_;
+
+ my $app = new Net::APP ( $cp_server,
+ User => $cp_user,
+ Password => $cp_pass,
+ Domain => $mydomain,
+ Timeout => 60,
+ #Debug => 1,
+ ) or die "$@\n";
+
+ if ( $password =~ /^\*SUSPENDED\* (.*)$/ ) {
+ $password = $1;
+ $app->set_mailbox_status(
+ Domain => $mydomain,
+ Mailbox => $username,
+ Other => 'T',
+ Other_Bounce => 'T',
+ );
+ } else {
+ $app->set_mailbox_status(
+ Domain => $mydomain,
+ Mailbox => $username,
+ Other => 'F',
+ Other_Bounce => 'F',
+ );
+ }
+ die $app->message."\n" unless $app->ok;
+
+ $app->change_mailbox(
+ Domain => $mydomain,
+ Mailbox => $username,
+ Password => $password,
+ );
+ die $app->message."\n" unless $app->ok;
+
+}
+
+sub vpopmail_replace_password {
+ my( $username, $password, $domain ) = @_;
+
+ (open(VPASSWD, "$exportdir/domains/$domain/vpasswd")
+ and flock(VPASSWD,LOCK_EX)
+ ) or die "can't open $exportdir/domains/$domain/vpasswd: $!";
+
+ open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp")
+ or die "Can't open $exportdir/domains/$domain/vpasswd.tmp: $!";
+
+ while (<VPASSWD>) {
+ my ($mailbox, $pw, @rest) = split(':', $_);
+ print VPASSWDTMP $_ unless $username eq $mailbox;
+ print VPASSWDTMP join (':', ($mailbox, $password, @rest))
+ if $username eq $mailbox;
+ }
+
+ close(VPASSWDTMP);
+
+ rename "$exportdir/domains/$domain/vpasswd.tmp", "$exportdir/domains/$domain/vpasswd"
+ or die "Can't rename $exportdir/domains/$domain/vpasswd.tmp: $!";
+
+ flock(VPASSWD,LOCK_UN);
+ close(VPASSWD);
+
+ my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' };
+ my $error = $queue->insert;
+ die $error if $error;