52 lines
1.1 KiB
Perl
52 lines
1.1 KiB
Perl
package My::Mailserver::Command::roundcube_password;
|
|
use Mojo::Base 'Mojolicious::Command';
|
|
|
|
use Mojo::Util qw/ getopt dumper /;
|
|
|
|
has description => sub { 'Manage passwords using roundcube password plugin' };
|
|
has usage => sub { shift->extract_usage };
|
|
|
|
sub run {
|
|
my ( $self, @args ) = @_;
|
|
|
|
my $command = '';
|
|
|
|
print dumper \@args;
|
|
getopt \@args,
|
|
'command=s' => \$command,
|
|
'user=s' => \my $user,
|
|
'old_pass=s' => \my $old_pass,
|
|
'new_pass=s' => \my $new_pass;
|
|
|
|
print dumper $command;
|
|
|
|
if ( $command eq 'save' ) { $self->save( $old_pass, $new_pass, $user ) }
|
|
else { die "Command not recognised" }
|
|
}
|
|
|
|
sub save {
|
|
my ( $self, $old_pass, $new_pass, $email ) = @_;
|
|
|
|
my $user = $self->app->schema->resultset('VirtualUser')->find({ email => $email });
|
|
|
|
if ( $user ) {
|
|
print dumper $user->email;
|
|
if ( $user->check_password( $old_pass ) ) {
|
|
$user->password( $new_pass );
|
|
$user->update;
|
|
print "PASSWORD_SUCCESS";
|
|
} else {
|
|
print "PASSWORD_ERROR";
|
|
}
|
|
} else {
|
|
print "PASSWORD_CONNECT_ERROR";
|
|
}
|
|
}
|
|
|
|
1;
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
Usage: APPLICATION roundcube_password [OPTIONS]
|
|
|
|
=cut
|