diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index 1945f6a7b1..e78088e7b0 100755 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -25,7 +25,8 @@ if (! check_acl ($config['id_user'], 0, "AW")) { return; } -$config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $config["past_planned_downtimes"] : 1; +// Default +set_unless_defined ($config["past_planned_downtimes"], 1); require_once ('include/functions_users.php'); @@ -81,43 +82,59 @@ $id_agent = (int) get_parameter ('id_agent'); $insert_downtime_agent = (int) get_parameter ('insert_downtime_agent'); $delete_downtime_agent = (int) get_parameter ('delete_downtime_agent'); +// User groups with AW permission for ACL checks +$user_groups_aw = array_keys(users_get_groups($config['id_user'], 'AW')); + // INSERT A NEW DOWNTIME_AGENT ASSOCIATION if ($insert_downtime_agent === 1) { + + // Check AW permission on downtime + $downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime); + + if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) { + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + $agents = (array) get_parameter ('id_agents'); $module_names = (array) get_parameter ('module'); - $all_modules = false; - if (empty($module_names)) { - $all_modules = true; - } - else { - //It is empty. - if ($module_names[0] == "0") - $all_modules = true; - } + $all_modules = (empty($module_names) || in_array(0, $module_names)); - $executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime); - if ($executed == 1) { + // '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 { - $num_agents = count($agents); - for ($a = 0; $a < $num_agents; $a++) { - $id_agente_dt = $agents[$a]; + foreach ($agents as $agent_id) { + + // Check AW 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_aw)) { + continue; + } $values = array( 'id_downtime' => $id_downtime, - 'id_agent' => $id_agente_dt, + '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, $id_agente_dt); + $module = modules_get_agentmodule_id($module_name, $agent_id); + + if (empty($module)) + continue; + $values = array( 'id_downtime' => $id_downtime, - 'id_agent' => $id_agente_dt, + 'id_agent' => $agent_id, 'id_agent_module' => $module["id_agente_modulo"] ); $result = db_process_sql_insert('tplanned_downtime_modules', $values); @@ -138,8 +155,29 @@ if ($delete_downtime_agent === 1) { $id_da = (int) get_parameter ('id_downtime_agent'); - $executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime); - if ($executed == 1) { + // Check AW permission on downtime + $downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime); + + if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) { + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + + // Check AW permission on agent + $agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent); + + if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) { + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + + // '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 { @@ -158,11 +196,11 @@ if ($delete_downtime_agent === 1) { // UPDATE OR CREATE A DOWNTIME (MAIN DATA, NOT AGENT ASSOCIATION) if ($create_downtime || $update_downtime) { - $check = db_get_value ('name', 'tplanned_downtime', 'name', $name); + $check = (bool) db_get_value ('name', 'tplanned_downtime', 'name', $name); $datetime_from = strtotime ($once_date_from . ' ' . $once_time_from); $datetime_to = strtotime ($once_date_to . ' ' . $once_time_to); - $now = strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT)); + $now = time(); if ($type_execution == 'once' && !$config["past_planned_downtimes"] && $datetime_from < $now) { ui_print_error_message(__('Not created. Error inserting data. Start time must be higher than the current time' )); @@ -184,6 +222,15 @@ if ($create_downtime || $update_downtime) { else { $sql = ''; if ($create_downtime) { + + // Check AW permission on new downtime + if (!in_array($id_group, $user_groups_aw)) { + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + if (trim(io_safe_output($name)) != '') { if (!$check) { $values = array( @@ -228,44 +275,65 @@ if ($create_downtime || $update_downtime) { } } else if ($update_downtime) { - $has_been_executed = db_get_value ('executed', 'tplanned_downtime', 'name', $name); + $old_downtime = db_get_row('tplanned_downtime', 'id', $id_downtime); + + // Check AW permission on OLD downtime + if (empty($old_downtime) || !in_array($old_downtime['id_group'], $user_groups_aw)) { + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + + // Check AW permission on NEW downtime group + if (!in_array($id_group, $user_groups_aw)) { + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + + // 'Is running' check + $is_running = (bool) $old_downtime['executed']; + $values = array(); if (trim(io_safe_output($name)) == '') { ui_print_error_message(__('Planned downtime must have a name')); } - else if ($has_been_executed == 1 && $type_execution == 'once') { + // When running only certain items can be modified for the 'once' type + else if ($is_running && $type_execution == 'once') { $values = array( 'description' => $description, 'date_to' => $datetime_to, 'id_user' => $config['id_user'] ); } - else if ($has_been_executed == 1) { - ui_print_error_message(__('No updates. Planned Downtime has been executed')); + else if ($is_running) { + ui_print_error_message(__('Cannot be modified while the downtime is being executed')); } else { $values = array( - 'name' => $name, - 'description' => $description, - 'date_from' => $datetime_from, - 'date_to' => $datetime_to, - 'id_group' => $id_group, - 'only_alerts' => 0, - 'monday' => $monday, - 'tuesday' => $tuesday, - 'wednesday' => $wednesday, - 'thursday' => $thursday, - 'friday' => $friday, - 'saturday' => $saturday, - 'sunday' => $sunday, - 'periodically_time_from' => $periodically_time_from, - 'periodically_time_to' => $periodically_time_to, - 'periodically_day_from' => $periodically_day_from, - 'periodically_day_to' => $periodically_day_to, - 'type_downtime' => $type_downtime, - 'type_execution' => $type_execution, - 'type_periodicity' => $type_periodicity, - 'id_user' => $config['id_user'] + 'name' => $name, + 'description' => $description, + 'date_from' => $datetime_from, + 'date_to' => $datetime_to, + 'id_group' => $id_group, + 'only_alerts' => 0, + 'monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'periodically_time_from' => $periodically_time_from, + 'periodically_time_to' => $periodically_time_to, + 'periodically_day_from' => $periodically_day_from, + 'periodically_day_to' => $periodically_day_to, + 'type_downtime' => $type_downtime, + 'type_execution' => $type_execution, + 'type_periodicity' => $type_periodicity, + 'id_user' => $config['id_user'] ); if ($config["dbtype"] == 'oracle') { $values['periodically_time_from'] = '1970/01/01 ' . $values['periodically_time_from']; @@ -354,11 +422,16 @@ if ($id_downtime > 0) { break; } - $groupsAW = users_get_groups($config['id_user'], 'AW', true, false, null, 'id_grupo'); - $groupsAW = array_keys($groupsAW); - $result = db_get_row_sql ($sql); + // Permission check for the downtime with the AW user groups + if (empty($result) || !in_array($result['id_group'], $user_groups_aw) ){ + db_pandora_audit("ACL Violation", + "Trying to access downtime scheduler"); + require ("general/noaccess.php"); + return; + } + $name = (string) $result["name"]; $id_group = (int) $result['id_group']; @@ -386,18 +459,11 @@ if ($id_downtime > 0) { $saturday = (bool) $result['saturday']; $sunday = (bool) $result['sunday']; - $executed = (bool) $result['executed']; - - if ( !in_array($id_group, $groupsAW) ){ - db_pandora_audit("ACL Violation", - "Trying to access downtime scheduler"); - require ("general/noaccess.php"); - return; - } + $running = (bool) $result['executed']; } -// when the planned down time is in execution, only action to postpone on once type is enabled and the other are disabled. -$disabled_in_execution = $executed ? 1 : 0; +// when the planned downtime is in execution, only action to postpone on once type is enabled and the other are disabled. +$disabled_in_execution = (int) $running; $table = new StdClass(); $table->class = 'databox filters'; @@ -564,42 +630,42 @@ if ($id_downtime > 0) { // Show available agents to include into downtime echo '