diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index e2c645a414..10f323ffab 100644 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -75,6 +75,7 @@ ui_print_page_header( // Recursion group filter. $recursion = get_parameter('recursion', $_POST['recursion']); + // Initialize data. $id_group = (int) get_parameter('id_group'); $name = (string) get_parameter('name'); @@ -147,144 +148,9 @@ $user_groups_ad = array_keys( users_get_groups($config['id_user'], $access) ); -// Check AD permission on downtime. -$downtime_group = db_get_value( - 'id_group', - 'tplanned_downtime', - 'id', - $id_downtime -); - -if ($id_downtime > 0) { - if (!check_acl_restricted_all($config['id_user'], $downtime_group, 'AW') - && !check_acl_restricted_all($config['id_user'], $downtime_group, 'AD') - ) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access downtime scheduler' - ); - include 'general/noaccess.php'; - return; - } -} - // INSERT A NEW DOWNTIME_AGENT ASSOCIATION. if ($insert_downtime_agent === 1) { - if ($downtime_group === false - || !in_array($downtime_group, $user_groups_ad) - ) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access downtime scheduler' - ); - include 'general/noaccess.php'; - return; - } - - $agents = (array) get_parameter('id_agents'); - $module_names = (array) get_parameter('module'); - - $all_modules = ($modules_selection_mode === 'all' && (empty($module_names) || (int) $modules[0] === 0)); - $all_common_modules = ($modules_selection_mode === 'common' && (empty($module_names) || (int) $modules[0] === 0)); - - if ($all_common_modules === true) { - $module_names = explode(',', get_parameter('all_common_modules')); - } - - // 'Is running' check. - $is_running = (bool) db_get_value( - 'executed', - 'tplanned_downtime', - 'id', - $id_downtime - ); - if ($is_running) { - ui_print_error_message( - __('This elements cannot be modified while the downtime is being executed') - ); - } else { - // If is selected 'Any', get all the agents. - if (count($agents) === 1 && (int) $agents[0] === -2) { - $all_agents = get_parameter('all_agents'); - $agents = explode(',', $all_agents); - } - - foreach ($agents as $agent_id) { - // Check module belongs to the agent. - if ($modules_selection_mode == 'all' && $all_modules === false) { - $check = false; - foreach ($module_names as $module_name) { - $check_module = modules_get_agentmodule_id( - $module_name, - $agent_id - ); - if (!empty($check_module)) { - $check = true; - } - } - - if (!$check) { - continue; - } - } - - // Check AD permission on agent. - $agent_group = db_get_value( - 'id_grupo', - 'tagente', - 'id_agente', - $agent_id - ); - - if ($agent_group === false - || !in_array($agent_group, $user_groups_ad) - ) { - continue; - } - - $values = [ - 'id_downtime' => $id_downtime, - 'id_agent' => $agent_id, - 'all_modules' => $all_modules, - ]; - $result = db_process_sql_insert( - 'tplanned_downtime_agents', - $values - ); - - if ($result && !$all_modules) { - foreach ($module_names as $module_name) { - $module = modules_get_agentmodule_id( - $module_name, - $agent_id - ); - - if (empty($module)) { - continue; - } - - $values = [ - 'id_downtime' => $id_downtime, - 'id_agent' => $agent_id, - 'id_agent_module' => $module['id_agente_modulo'], - ]; - $result = db_process_sql_insert( - 'tplanned_downtime_modules', - $values - ); - - if ($result) { - $values = ['id_user' => $config['id_user']]; - $result = db_process_sql_update( - 'tplanned_downtime', - $values, - ['id' => $id_downtime] - ); - } - } - } - } - } + insert_downtime_agent($id_downtime, $user_groups_ad); } // DELETE A DOWNTIME_AGENT ASSOCIATION. @@ -490,10 +356,6 @@ if ($create_downtime || $update_downtime) { 'date_to' => $datetime_to, 'id_user' => $config['id_user'], ]; - } else if ($is_running) { - ui_print_error_message( - __('Cannot be modified while the downtime is being executed') - ); } else { $values = [ 'name' => $name, @@ -524,12 +386,16 @@ if ($create_downtime || $update_downtime) { } } - if (!empty($values)) { - $result = db_process_sql_update( - 'tplanned_downtime', - $values, - ['id' => $id_downtime] - ); + if ($is_running) { + $result = false; + } else { + if (!empty($values)) { + $result = db_process_sql_update( + 'tplanned_downtime', + $values, + ['id' => $id_downtime] + ); + } } } @@ -542,6 +408,9 @@ if ($create_downtime || $update_downtime) { } else { if ($create_downtime && $name && !$check) { $id_downtime = $result; + + insert_downtime_agent($id_downtime, $user_groups_ad); + ui_print_success_message(__('Successfully created')); } else if ($update_downtime && $name) { ui_print_success_message(__('Successfully updated')); @@ -584,8 +453,8 @@ if ($id_downtime > 0) { case 'postgresql': $columns_str = implode(',', $columns); $sql = "SELECT $columns_str - FROM tplanned_downtime - WHERE id = $id_downtime"; + FROM tplanned_downtime + WHERE id = $id_downtime"; break; case 'oracle': @@ -607,8 +476,8 @@ if ($id_downtime > 0) { $columns_str = implode(',', $columns); $sql = "SELECT $columns_str - FROM tplanned_downtime - WHERE id = $id_downtime"; + FROM tplanned_downtime + WHERE id = $id_downtime"; break; } @@ -672,20 +541,11 @@ $table->data[0][1] = html_print_input_text( true, $disabled_in_execution ); - -$return_all_group = false; - -if (users_can_manage_group_all('AW') === true - || users_can_manage_group_all('AD') === true -) { - $return_all_group = true; -} - $table->data[1][0] = __('Group'); $table->data[1][1] = '
".__('From:').' | -'.html_print_input_text('once_date_from', $once_date_from, '', 10, 10, true, $disabled_in_execution).html_print_input_text('once_time_from', $once_time_from, '', 9, 9, true, $disabled_in_execution).' | -
'.__('To:').' | -'.html_print_input_text('once_date_to', $once_date_to, '', 10, 10, true).html_print_input_text('once_time_to', $once_time_to, '', 9, 9, true)." | -
".ui_get_using_system_timezone_warning().' |
'.__('Type Periodicity:').' '.html_print_select( + | + +
"; + echo " |
".__('Module')." | -".__('Action')." | -|||||
---|---|---|---|---|---|---|
- | ".''.html_print_image(
+
|
+