From 90739088f449aa7608db281fcafc7f289b305141 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 23 Nov 2021 12:43:07 +0100 Subject: [PATCH 1/3] #8228 Added centralised node check --- pandora_server/util/pandora_manage.pl | 48 ++++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 04ee72ea70..e346023acb 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -510,8 +510,12 @@ sub cli_create_snmp_trap ($$) { sub pandora_create_user ($$$$$) { my ($dbh, $name, $password, $is_admin, $comments) = @_; + if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + print_log "[ERROR] This node is configured with centralized mode. To create a user go to metaconsole. \n\n"; + exit; + } -return db_insert ($dbh, 'id_user', 'INSERT INTO tusuario (id_user, fullname, password, comments, is_admin) + return db_insert ($dbh, 'id_user', 'INSERT INTO tusuario (id_user, fullname, password, comments, is_admin) VALUES (?, ?, ?, ?, ?)', safe_input($name), safe_input($name), $password, safe_input($comments), $is_admin); } @@ -521,18 +525,23 @@ return db_insert ($dbh, 'id_user', 'INSERT INTO tusuario (id_user, fullname, pas sub pandora_delete_user ($$) { my ($dbh, $name) = @_; -# Delete user profiles -db_do ($dbh, 'DELETE FROM tusuario_perfil WHERE id_usuario = ?', $name); + if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + print_log "[ERROR] This node is configured with centralized mode. To delete a user go to metaconsole. \n\n"; + exit; + } -# Delete the user -my $return = db_do ($dbh, 'DELETE FROM tusuario WHERE id_user = ?', $name); + # Delete user profiles + db_do ($dbh, 'DELETE FROM tusuario_perfil WHERE id_usuario = ?', $name); -if($return eq '0E0') { - return -1; -} -else { - return 0; -} + # Delete the user + my $return = db_do ($dbh, 'DELETE FROM tusuario WHERE id_user = ?', $name); + + if($return eq '0E0') { + return -1; + } + else { + return 0; + } } ########################################################################## @@ -749,7 +758,12 @@ sub pandora_validate_event_id ($$$) { ########################################################################## sub pandora_update_user_from_hash ($$$$) { my ($parameters, $where_column, $where_value, $dbh) = @_; - + + if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + print_log "[ERROR] This node is configured with centralized mode. To update a user go to metaconsole. \n\n"; + exit; + } + my $user_id = db_process_update($dbh, 'tusuario', $parameters, {$where_column => $where_value}); return $user_id; } @@ -6144,6 +6158,11 @@ sub cli_disable_double_auth () { sub cli_user_enable () { my $user_id = @ARGV[2]; + if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + print_log "[ERROR] This node is configured with centralized mode. To enable a user go to metaconsole. \n\n"; + exit; + } + my $user_disabled = get_user_disabled ($dbh, $user_id); exist_check($user_disabled,'user',$user_id); @@ -6169,6 +6188,11 @@ sub cli_user_enable () { sub cli_user_disable () { my $user_id = @ARGV[2]; + if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + print_log "[ERROR] This node is configured with centralized mode. To disable a user go to metaconsole. \n\n"; + exit; + } + my $user_disabled = get_user_disabled ($dbh, $user_id); exist_check($user_disabled,'user',$user_id); From f52dc0c319d5b7bdcfe4808211932fc9be43077d Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 24 Nov 2021 16:07:20 +0100 Subject: [PATCH 2/3] #8228 Fixed print_log --- pandora_server/util/pandora_manage.pl | 54 +++++++++++++-------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index e346023acb..7318984a42 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -343,6 +343,23 @@ sub update_conf_txt ($$$$) { return $result; } +############################################################################### +############################################################################### +# PRINT HELP AND CHECK ERRORS FUNCTIONS +############################################################################### +############################################################################### + +############################################################################### +# log wrapper +############################################################################### +sub print_log ($) { + my ($msg) = @_; + + print $msg; # show message + + $msg =~ s/\n+$//; + logger( $conf, "($progname) $msg", 10); # save to logging file +} ############################################################################### # Disable a entire group @@ -759,11 +776,6 @@ sub pandora_validate_event_id ($$$) { sub pandora_update_user_from_hash ($$$$) { my ($parameters, $where_column, $where_value, $dbh) = @_; - if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { - print_log "[ERROR] This node is configured with centralized mode. To update a user go to metaconsole. \n\n"; - exit; - } - my $user_id = db_process_update($dbh, 'tusuario', $parameters, {$where_column => $where_value}); return $user_id; } @@ -990,7 +1002,7 @@ sub pandora_get_calendar_id ($$) { sub pandora_get_same_day_id ($$) { my ($dbh, $same_day) = @_; - my $weeks = { 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6, 'sunday' => 7, 'holiday' => 8}; + my %weeks = ('monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6, 'sunday' => 7, 'holiday' => 8); return defined ($weeks{$same_day}) ? $weeks{$same_day} : -1; } @@ -1012,25 +1024,6 @@ sub pandora_delete_special_day ($$) { } } - -############################################################################### -############################################################################### -# PRINT HELP AND CHECK ERRORS FUNCTIONS -############################################################################### -############################################################################### - -############################################################################### -# log wrapper -############################################################################### -sub print_log ($) { - my ($msg) = @_; - - print $msg; # show message - - $msg =~ s/\n+$//; - logger( $conf, "($progname) $msg", 10); # save to logging file -} - ############################################################################### # Print a parameter error and exit the program. ############################################################################### @@ -3051,10 +3044,15 @@ sub cli_create_user() { sub cli_user_update() { my ($user_id,$field,$new_value) = @ARGV[2..4]; - + + if(is_metaconsole($conf) != 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + print_log "[ERROR] This node is configured with centralized mode. To update a user go to metaconsole. \n\n"; + exit; + } + my $user_exists = get_user_exists ($dbh, $user_id); exist_check($user_exists,'user',$user_id); - + if($field eq 'email' || $field eq 'phone' || $field eq 'is_admin' || $field eq 'language' || $field eq 'id_skin') { # Fields admited, no changes } @@ -5537,7 +5535,7 @@ sub cli_get_agents() { my $head_print = 0; - use Data::Dumper; + # use Data::Dumper; foreach my $agent (@agents) { From 922088c3068e9deeab345c0edccabd0e20906a78 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 24 Nov 2021 17:48:34 +0100 Subject: [PATCH 3/3] resolved conflict --- pandora_server/util/pandora_manage.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 72d75059b5..0e34cd617c 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -1002,7 +1002,7 @@ sub pandora_get_calendar_id ($$) { sub pandora_get_same_day_id ($$) { my ($dbh, $same_day) = @_; - my %weeks = ('monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6, 'sunday' => 7, 'holiday' => 8); + my $weeks = { 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6, 'sunday' => 7, 'holiday' => 8 }; return defined ($weeks->{$same_day}) ? $weeks->{$same_day} : -1; }