2012-01-04 Sergio Martin <sergio.martin@artica.es>

*  lib/PandoraFMS/DB.pm
	util/pandora_manage.pl: Added --enable_user and
	--disable_user options to CLI



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5321 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-01-04 15:09:02 +00:00
parent c0f59eb1ee
commit 6aa72c3b37
3 changed files with 78 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2012-01-04 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/DB.pm
util/pandora_manage.pl: Added --enable_user and
--disable_user options to CLI
2011-12-29 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/Core.pm

View File

@ -67,6 +67,7 @@ our @EXPORT = qw(
get_server_id
get_template_id
get_template_module_id
get_user_disabled
is_agent_address
is_group_disabled
);
@ -279,6 +280,16 @@ sub get_module_id ($$) {
return defined ($rc) ? $rc : -1;
}
##########################################################################
## Return disabled bit frin a user.
##########################################################################
sub get_user_disabled ($$) {
my ($dbh, $user_id) = @_;
my $rc = get_db_value ($dbh, "SELECT disabled FROM tusuario WHERE id_user = ?", safe_input($user_id));
return defined ($rc) ? $rc : -1;
}
##########################################################################
## Return plugin ID given the plugin name.
##########################################################################

View File

@ -434,6 +434,8 @@ sub help_screen{
help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy');
help_screen_line('--create_group', '<group_name> [<parent_group_name>]', 'Create an agent group');
help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy');
help_screen_line('--disable_user', '<user_id>', 'Disable a given user');
help_screen_line('--enable_user', '<user_id>', 'Enable a given user');
print "\n";
exit;
}
@ -1463,6 +1465,56 @@ sub cli_enable_eacl ($$) {
exit;
}
###############################################################################
# Enable user
# Related option: --enable_user
###############################################################################
sub cli_user_enable () {
my $user_id = @ARGV[2];
my $user_disabled = get_user_disabled ($dbh, $user_id);
exist_check($user_disabled,'user',$user_id);
if($user_disabled == 0) {
print "[INFO] The user '$user_id' is already enabled. Nothing to do.\n\n";
exit;
}
print "[INFO] Enabling user '$user_id'\n\n";
$user_id = safe_input($user_id);
db_do ($dbh, "UPDATE tusuario SET `disabled` = '0' WHERE `id_user` = '$user_id'");
exit;
}
###############################################################################
# Disable user
# Related option: --disable_user
###############################################################################
sub cli_user_disable () {
my $user_id = @ARGV[2];
my $user_disabled = get_user_disabled ($dbh, $user_id);
exist_check($user_disabled,'user',$user_id);
if($user_disabled == 1) {
print "[INFO] The user '$user_id' is already disabled. Nothing to do.\n\n";
exit;
}
print "[INFO] Disabling user '$user_id'\n\n";
$user_id = safe_input($user_id);
db_do ($dbh, "UPDATE tusuario SET `disabled` = '1' WHERE `id_user` = '$user_id'");
exit;
}
###############################################################################
###############################################################################
# MAIN
@ -1612,9 +1664,17 @@ sub pandora_manage_main ($$$) {
cli_create_group();
}
elsif ($param eq '--add_agent_to_policy') {
param_check($ltotal, 2, 0);
param_check($ltotal, 2);
cli_policy_add_agent();
}
elsif ($param eq '--enable_user') {
param_check($ltotal, 1);
cli_user_enable();
}
elsif ($param eq '--disable_user') {
param_check($ltotal, 1);
cli_user_disable();
}
else {
print "[ERROR] Invalid option '$param'.\n\n";
$param = '';