Commit 38334a34 authored by fv3rdugo's avatar fv3rdugo
Browse files

feat(backend): remove user from cli

Was proposed by @rogerferre

Issue #1132
parent b0bc3e5a
......@@ -27,6 +27,7 @@ my $FILE_CONFIG_DEFAULT = "/etc/ravada.conf";
my $FILE_CONFIG;
my $ADD_USER_LDAP;
my $REMOVE_USER;
my $IMPORT_DOMAIN;
my $IMPORT_VBOX;
my $CHANGE_PASSWORD;
......@@ -58,9 +59,11 @@ my $USAGE = "$0 "
." [--test-ldap] "
." [-X] [start|stop|status]"
." [--rebase MACHINE]"
." [--remove-user=name]"
."\n"
." --add-user : adds a new db user\n"
." --add-user-ldap : adds a new LDAP user\n"
." --remove-user : removes a db user\n"
." --change-password : changes the password of an user\n"
." --import-domain : import a domain\n"
." --import-domain-owner : owner of the domain to import\n"
......@@ -103,6 +106,7 @@ GetOptions ( help => \$help
,'shutdown:s'=> \$SHUTDOWN_DOMAIN
,'hibernate:s'=> \$HIBERNATE_DOMAIN
,'disconnected'=> \$DISCONNECTED
,'remove-user=s'=> \$REMOVE_USER
,'make-admin=s' => \$MAKE_ADMIN_USER
,'remove-admin=s' => \$REMOVE_ADMIN_USER
,'change-password'=> \$CHANGE_PASSWORD
......@@ -126,7 +130,7 @@ if ($help) {
exit;
}
die "Only root can do that\n" if $> && ( $ADD_USER || $ADD_USER_LDAP || $IMPORT_DOMAIN);
die "Only root can do that\n" if $> && ( $ADD_USER || $REMOVE_USER || $ADD_USER_LDAP || $IMPORT_DOMAIN);
die "ERROR: Missing file config $FILE_CONFIG\n"
if $FILE_CONFIG && ! -e $FILE_CONFIG;
......@@ -237,6 +241,21 @@ sub add_user_ldap {
Ravada::Auth::LDAP::add_user($login, $password);
}
sub remove_user {
my $login = shift;
my $ravada = Ravada->new( %CONFIG);
my $user = Ravada::Auth::SQL->new(name => $login);
die "ERROR: Unknown user '$login'\n" if !$user->id;
print "Are you sure you want remove $login user ? : [y/n] ";
my $remove_it = <STDIN>;
if ( $remove_it =~ /y/i ) {
$user->remove();
print "USER $login was removed\n";
}
}
sub change_password {
print "User login name : ";
my $login = <STDIN>;
......@@ -561,6 +580,7 @@ my $rvd_back = Ravada->new(%CONFIG);
add_user($ADD_USER) if $ADD_USER;
add_user_ldap($ADD_USER_LDAP) if $ADD_USER_LDAP;
remove_user($REMOVE_USER) if $REMOVE_USER;
change_password() if $CHANGE_PASSWORD;
import_domain($IMPORT_DOMAIN) if $IMPORT_DOMAIN;
import_vbox($IMPORT_VBOX) if $IMPORT_VBOX;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment