'noaccess']);
}
include 'general/noaccess.php';
exit;
}
// Pure variable for full screen selection.
$this->pure = $config['pure'];
// Id user.
$this->idUser = $config['id_user'];
// Refresh rate.
$this->refreshSelectedRate = (string) get_parameter('refresh-rate', '30');
// Show Modules without alerts table.
$this->showWithoutAlertModules = (isset($_POST['show-modules-without-alerts']))
? true
: isset($_GET['show-modules-without-alerts']);
// Selected group.
$this->groupId = (int) get_parameter('group-id', 0);
// Create alert token.
$this->createAlert = (int) get_parameter('create_alert', 0);
// Offset and hor-offset (for pagination).
$this->offset = (int) get_parameter('offset', 0);
$this->horOffset = (int) get_parameter('hor_offset', 0);
return $this;
}
/**
* Run main page.
*
* @return void
*/
public function run()
{
// Javascript.
ui_require_jquery_file('pandora');
// Load own javascript file.
$this->loadJS();
// CSS.
ui_require_css_file('wizard');
ui_require_css_file('discovery');
ui_require_css_file('agent_alerts');
// Update network modules for this group
// Check for Network FLAG change request
// Made it a subquery, much faster on both the database and server side
// TODO. Check if this is used or necessary.
if (isset($_GET['update_netgroup']) === true) {
$group = get_parameter_get('update_netgroup', 0);
if (check_acl($this->idUser, $group, 'AW')) {
$where = ['id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = '.$group];
db_process_sql_update('tagente_modulo', ['flag' => 1], $where);
} else {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to set flag for groups'
);
include 'general/noaccess.php';
exit;
}
}
// Load the header.
$this->loadHeader();
// If the petition wants to create alert.
if ($this->createAlert) {
$this->createAlertAction();
}
if ($this->showWithoutAlertModules === true) {
$this->createAlertTable();
} else {
$this->loadMainAlertTable();
}
}
/**
* Show alert table.
*
* @return void
*/
private function createAlertTable()
{
global $config;
$table = new stdClass();
if ($this->groupId > 0) {
$grupo = ' AND tagente.id_grupo = '.$this->groupId;
} else {
$grupo = '';
}
$offset_modules = $this->offset;
$sql_count = 'SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo
INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente
WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules)'.$grupo;
$count_agent_module = db_get_all_rows_sql($sql_count);
$sql = 'SELECT tagente.alias, tagente_modulo.nombre,
tagente_modulo.id_agente_modulo FROM tagente_modulo
INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente
WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) '.$grupo.' LIMIT '.$config['block_size'].' OFFSET '.$offset_modules;
$agent_modules = db_get_all_rows_sql($sql);
ui_pagination(
$count_agent_module[0]['COUNT(tagente_modulo.nombre)'],
ui_get_url_refresh(),
0,
false,
false,
'offset',
true,
'',
'',
false,
'alerts_modules'
);
$table->width = '100%';
$table->class = 'info_table';
$table->id = 'table_agent_module';
$table->data = [];
$table->head[0] = __('Agents');
$table->head[1] = __('Modules');
$table->head[2] = __('Actions');
$table->style[0] = 'width: 25%;';
$table->style[1] = 'width: 33%;';
$table->style[2] = 'width: 33%;';
foreach ($agent_modules as $agent_module) {
// Let's build the table.
$data[0] = io_safe_output($agent_module['alias']);
$data[1] = io_safe_output($agent_module['nombre']);
$uniqid = $agent_module['id_agente_modulo'];
$data[2] = html_print_anchor(
[
'href' => sprintf(
'javascript:show_add_alerts(\'%s\')',
$uniqid
),
'content' => html_print_image('images/add_mc.png', true),
],
true
);
array_push($table->data, $data);
$table2 = new stdClass();
$table2->width = '100%';
$table2->id = 'table_add_alert';
$table2->class = 'databox filters';
$table2->data = [];
$table2->data[0][0] = __('Actions');
$groups_user = users_get_groups($this->idUser);
if (!empty($groups_user)) {
$groups = implode(',', array_keys($groups_user));
$sql = sprintf(
'SELECT id, name FROM talert_actions WHERE id_group IN (%s)',
$groups
);
$actions = db_get_all_rows_sql($sql);
}
$table2->data[0][1] = html_print_select(
index_array($actions, 'id', 'name'),
'action_select',
'',
'',
__('Default action'),
'0',
true,
'',
true,
'',
false,
'width: 250px;'
);
$table2->data[0][1] .= '
';
$table2->data[0][1] .= __('Number of alerts match from').' ';
$table2->data[0][1] .= html_print_input_text('fires_min', '', '', 4, 10, true);
$table2->data[0][1] .= ' '.__('to').' ';
$table2->data[0][1] .= html_print_input_text('fires_max', '', '', 4, 10, true);
$table2->data[0][1] .= ui_print_help_icon(
'alert-matches',
true,
ui_get_full_url(false, false, false, false)
);
$table2->data[0][1] .= '';
// Check ACLs for LM users.
if (check_acl($this->idUser, 0, 'LM')) {
$table2->data[0][1] .= html_print_anchor(
[
'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_action&pure='.$this->pure,
'class' => 'mrgn_lft_5px',
'content' => html_print_image('images/add.png', true).''.__('Create Action').'',
],
true
);
}
$table2->data[1][0] = __('Template');
$own_info = get_user_info($this->idUser);
if ($own_info['is_admin'] || check_acl($this->idUser, 0, 'PM')) {
$templates = alerts_get_alert_templates(false, ['id', 'name']);
} else {
$usr_groups = users_get_groups($this->idUser, 'LW', true);
$filter_groups = '';
$filter_groups = implode(',', array_keys($usr_groups));
$templates = alerts_get_alert_templates(['id_group IN ('.$filter_groups.')'], ['id', 'name']);
}
$table2->data[1][1] = html_print_select(
index_array($templates, 'id', 'name'),
'template',
'',
'',
__('Select'),
0,
true,
false,
true,
'',
false,
'width: 250px;'
);
$table2->data[1][1] .= html_print_anchor(
[
'href' => '#',
'class' => 'template_details invisible',
'content' => html_print_image('images/zoom.png', true, ['class' => 'img_help']),
],
true
);
// Check ACLs for LM users.
if (check_acl($this->idUser, 0, 'LM')) {
$table2->data[1][1] .= html_print_anchor(
[
'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&pure='.$this->pure,
'style' => 'margin-left:5px;',
'content' => html_print_image('images/add.png', true).''.__('Create Template').'',
],
true
);
}
$table2->data[2][0] = __('Threshold');
$table2->data[2][1] = html_print_input_text('module_action_threshold', '0', '', 5, 7, true);
$table2->data[2][1] .= ' '.__('seconds');
$content2 = '
'.__('Agents').' / '.__('Alerts').' | '; $templates_raw = []; if (!empty($templates)) { $sql = sprintf( 'SELECT id, name FROM talert_templates WHERE id IN (%s)', implode(',', array_keys($templates)) ); $templates_raw = db_get_all_rows_sql($sql); if (empty($templates_raw)) { $templates_raw = []; } }; $alerts = []; $ntemplates = 0; if ($this->horOffset > 0) { $new_hor_offset = ($this->horOffset - $block); echo ""; html_print_anchor( [ 'href' => sprintf( 'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group-id=%s&pure=%s', $new_hor_offset, $this->offset, $this->groupId, $this->pure ), 'content' => html_print_image( 'images/arrow_left_green.png', true, [ 'style' => 'display:flex;justify-content: center', 'title' => __('Previous alerts'), ] ), 'style' => 'display:flex;justify-content: center', ] ); echo ' | '; } // Dynamic Size. if ($this->pure == 1) { // Count of templates. $templateCount = count($templates_raw); // Define a dynamic size. $thSize = floor(80 / $templateCount).'%'; } else { $thSize = '8%'; } foreach ($templates_raw as $temp) { if (isset($templates[$temp['id']]) && $templates[$temp['id']] == '') { $ntemplates++; if ($ntemplates <= $this->horOffset || $ntemplates > ($this->horOffset + $block)) { continue; } $templates[$temp['id']] = $temp['name']; } } foreach ($templates as $id => $name) { if (empty($name) === false) { $outputLine = html_print_div( [ 'id' => 'line_header_'.$id, 'class' => 'position_text_module', 'style' => '', 'content' => '%s | ', $thSize, $outputLine); } } if (($this->horOffset + $block) < $ntemplates) { $new_hor_offset = ($this->horOffset + $block); echo ""; html_print_anchor( [ 'href' => sprintf( 'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group-id=%s&pure=%s', $new_hor_offset, $this->offset, $this->groupId, $this->pure ), 'content' => html_print_image( 'images/arrow_right_green.png', true, [ 'style' => 'float: right;', 'title' => __('More alerts'), ] ), ] ); echo ' | '; } echo '
---|---|---|---|
'.$alias['alias'].' | '; // Alerts of the agent. foreach ($templates as $tid => $tname) { $anyfired = 0; if ($tname == '') { continue; } echo ''; if (isset($agent_alerts[$alias['alias']][$tid])) { $uniqid = uniqid(); html_print_anchor( [ 'href' => sprintf('javascript:show_alerts_details(\'%s\')', $uniqid), 'content' => html_print_div( [ 'id' => 'line_header_'.$temp['id'], 'style' => 'font-size: 13pt;', 'content' => count($agent_alerts[$alias['alias']][$tid]), ], true ), ] ); $this->printAlertsSummaryModalWindow($uniqid, $agent_alerts[$alias['alias']][$tid]); } echo ' | '; } echo '