add safe output function to strings printed in system audit log
Former-commit-id: 383b5885f163d167c8944ad6dc8d66a8b4c35e51
This commit is contained in:
parent
a2909db631
commit
4d5631d355
|
@ -228,11 +228,11 @@ foreach ($result as $row) {
|
||||||
$rowPair = !$rowPair;
|
$rowPair = !$rowPair;
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$data[0] = $row["id_usuario"];
|
$data[0] = io_safe_output($row["id_usuario"]);
|
||||||
$data[1] = ui_print_session_action_icon($row["accion"], true) . $row["accion"];
|
$data[1] = ui_print_session_action_icon($row["accion"], true) . $row["accion"];
|
||||||
$data[2] = ui_print_help_tip(date($config["date_format"], $row["utimestamp"]), true)
|
$data[2] = ui_print_help_tip(date($config["date_format"], $row["utimestamp"]), true)
|
||||||
. ui_print_timestamp($row["utimestamp"], true);
|
. ui_print_timestamp($row["utimestamp"], true);
|
||||||
$data[3] = $row["ip_origen"];
|
$data[3] = io_safe_output($row["ip_origen"]);
|
||||||
$data[4] = io_safe_output($row["descripcion"]);
|
$data[4] = io_safe_output($row["descripcion"]);
|
||||||
|
|
||||||
if ($enterprise_include !== ENTERPRISE_NOT_HOOK) {
|
if ($enterprise_include !== ENTERPRISE_NOT_HOOK) {
|
||||||
|
|
|
@ -484,21 +484,23 @@ if($append_tab_filter){
|
||||||
$table->id = 'save_filter_form';
|
$table->id = 'save_filter_form';
|
||||||
$table->width = '100%';
|
$table->width = '100%';
|
||||||
$table->class = 'databox';
|
$table->class = 'databox';
|
||||||
|
$table->rowspan = array();
|
||||||
|
|
||||||
if($filters['id'] == 'extended_create_filter'){
|
if($filters['id'] == 'extended_create_filter'){
|
||||||
echo "<div id='msg_error_create'></div>";
|
echo "<div id='msg_error_create'></div>";
|
||||||
$table->data[0][0] = __('Filter name');
|
$table->data[0][0] = __('Filter name');
|
||||||
$table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true);
|
$table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true);
|
||||||
|
|
||||||
$table->data[0][2] = __('Group');
|
$table->data[1][0] = __('Group');
|
||||||
$table->data[0][3] = html_print_select_groups(
|
$table->data[1][1] = html_print_select_groups(
|
||||||
$config['id_user'], 'AR', true, 'group_search_cr',
|
$config['id_user'], 'AR', true, 'group_search_cr',
|
||||||
0, '', '', '0', true, false,
|
0, '', '', '0', true, false,
|
||||||
false, '', false, '', false, false,
|
false, '', false, 'width:180px;', false, false,
|
||||||
'id_grupo', false
|
'id_grupo', false
|
||||||
);
|
);
|
||||||
|
|
||||||
$table->data[0][4] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true);
|
$table->rowspan[0][2] = 2;
|
||||||
|
$table->data[0][2] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
echo "<div id='msg_error_update'></div>";
|
echo "<div id='msg_error_update'></div>";
|
||||||
|
@ -516,7 +518,7 @@ if($append_tab_filter){
|
||||||
$table->data[1][1] = html_print_select_groups(
|
$table->data[1][1] = html_print_select_groups(
|
||||||
$config['id_user'], 'AR', true, 'group_search_up',
|
$config['id_user'], 'AR', true, 'group_search_up',
|
||||||
$group, '', '', '0', true, false,
|
$group, '', '', '0', true, false,
|
||||||
false, '', false, '', false, false,
|
false, '', false, 'width:180px;', false, false,
|
||||||
'id_grupo', false
|
'id_grupo', false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -485,8 +485,6 @@ define("OPTION_AGENT_AUTOCOMPLETE", 9);
|
||||||
define("OPTION_SELECT_MULTISELECTION", 10);
|
define("OPTION_SELECT_MULTISELECTION", 10);
|
||||||
define("OPTION_COLOR_PICKER", 11);
|
define("OPTION_COLOR_PICKER", 11);
|
||||||
|
|
||||||
define("DASHBOARD_WIDGET_ID_VISUAL_CONSOLE", 22);
|
|
||||||
|
|
||||||
/* Transactional map constants */
|
/* Transactional map constants */
|
||||||
define("NODE_TYPE", 0);
|
define("NODE_TYPE", 0);
|
||||||
define("ARROW_TYPE", 1);
|
define("ARROW_TYPE", 1);
|
||||||
|
|
|
@ -193,6 +193,13 @@ function get_custom_fields_data ($custom_field_name) {
|
||||||
function agent_counters_custom_fields($filters){
|
function agent_counters_custom_fields($filters){
|
||||||
//filter by status agent
|
//filter by status agent
|
||||||
$and_status = "";
|
$and_status = "";
|
||||||
|
|
||||||
|
$agent_state_normal = 0;
|
||||||
|
$agent_state_critical = 0;
|
||||||
|
$agent_state_warning = 0;
|
||||||
|
$agent_state_unknown = 0;
|
||||||
|
$agent_state_notinit = 0;
|
||||||
|
$agent_state_total = 0;
|
||||||
if(is_array($filters['id_status'])){
|
if(is_array($filters['id_status'])){
|
||||||
if(!in_array(-1, $filters['id_status'])){
|
if(!in_array(-1, $filters['id_status'])){
|
||||||
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['id_status'])){
|
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['id_status'])){
|
||||||
|
@ -200,34 +207,34 @@ function agent_counters_custom_fields($filters){
|
||||||
$and_status = " AND ( ";
|
$and_status = " AND ( ";
|
||||||
foreach ($filters['id_status'] as $key => $value) {
|
foreach ($filters['id_status'] as $key => $value) {
|
||||||
$and_status .= ($key != 0)
|
$and_status .= ($key != 0)
|
||||||
? " OR ("
|
? " OR "
|
||||||
: " (";
|
: " ";
|
||||||
switch ($value) {
|
switch ($value) {
|
||||||
default:
|
default:
|
||||||
case AGENT_STATUS_NORMAL:
|
case AGENT_STATUS_NORMAL:
|
||||||
$and_status .= " ta.critical_count = 0
|
$agent_state_normal = agents_get_status_clause(AGENT_STATUS_NORMAL);
|
||||||
AND ta.warning_count = 0
|
$and_status .= agents_get_status_clause(AGENT_STATUS_NORMAL);
|
||||||
AND ta.unknown_count = 0
|
|
||||||
AND ta.total_count <> ta.notinit_count ) ";
|
|
||||||
break;
|
break;
|
||||||
case AGENT_STATUS_CRITICAL:
|
case AGENT_STATUS_CRITICAL:
|
||||||
$and_status .= " ta.critical_count > 0 ) ";
|
$and_status .= agents_get_status_clause(AGENT_STATUS_CRITICAL);
|
||||||
|
$agent_state_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
|
||||||
break;
|
break;
|
||||||
case AGENT_STATUS_WARNING:
|
case AGENT_STATUS_WARNING:
|
||||||
$and_status .= " ta.critical_count = 0
|
$and_status .= agents_get_status_clause(AGENT_STATUS_WARNING);
|
||||||
AND ta.warning_count > 0 ) ";
|
$agent_state_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
|
||||||
break;
|
break;
|
||||||
case AGENT_STATUS_UNKNOWN:
|
case AGENT_STATUS_UNKNOWN:
|
||||||
$and_status .= " ta.critical_count = 0
|
$and_status .= agents_get_status_clause(AGENT_STATUS_UNKNOWN);
|
||||||
AND ta.warning_count = 0
|
$agent_state_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
|
||||||
AND ta.unknown_count > 0 ) ";
|
|
||||||
break;
|
break;
|
||||||
case AGENT_STATUS_NOT_INIT:
|
case AGENT_STATUS_NOT_INIT:
|
||||||
$and_status .= " ta.total_count = ta.notinit_count ) ";
|
$and_status .= agents_get_status_clause(AGENT_STATUS_NOT_INIT);
|
||||||
|
$agent_state_notinit = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$and_status .= " ) ";
|
$and_status .= " ) ";
|
||||||
|
$agent_state_total = agents_get_status_clause(AGENT_STATUS_ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -237,14 +244,45 @@ function agent_counters_custom_fields($filters){
|
||||||
OR ( ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 )
|
OR ( ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 )
|
||||||
OR ( ta.total_count = ta.notinit_count )
|
OR ( ta.total_count = ta.notinit_count )
|
||||||
) ";
|
) ";
|
||||||
|
|
||||||
|
$agent_state_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
|
||||||
|
$agent_state_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
|
||||||
|
$agent_state_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
|
||||||
|
$agent_state_notinit = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
|
||||||
|
$agent_state_total = agents_get_status_clause(AGENT_STATUS_ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
$agent_state_normal = agents_get_status_clause(AGENT_STATUS_NORMAL);
|
||||||
|
$agent_state_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
|
||||||
|
$agent_state_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
|
||||||
|
$agent_state_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
|
||||||
|
$agent_state_notinit = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
|
||||||
|
$agent_state_total = agents_get_status_clause(AGENT_STATUS_ALL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//filter by status module
|
//filter by status module
|
||||||
|
$empty_agents_count = "UNION ALL
|
||||||
|
SELECT ta.id_agente,
|
||||||
|
0 AS c_m_total,
|
||||||
|
0 AS mm_normal,
|
||||||
|
0 AS mm_critical,
|
||||||
|
0 AS mm_warning,
|
||||||
|
0 AS mm_unknown,
|
||||||
|
0 AS mm_not_init,
|
||||||
|
0 AS mm_total
|
||||||
|
FROM tagente ta
|
||||||
|
LEFT JOIN tagent_secondary_group tasg
|
||||||
|
ON ta.id_agente = tasg.id_agent
|
||||||
|
WHERE ta.disabled = 0
|
||||||
|
AND ta.total_count = 0
|
||||||
|
$groups_and";
|
||||||
|
|
||||||
$and_module_status = "";
|
$and_module_status = "";
|
||||||
if(is_array($filters['module_status'])){
|
if(is_array($filters['module_status'])){
|
||||||
if(!in_array(-1, $filters['module_status'])){
|
if(!in_array(-1, $filters['module_status'])){
|
||||||
|
$empty_agents_count = "";
|
||||||
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['module_status'])){
|
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['module_status'])){
|
||||||
if(count($filters['module_status']) > 0){
|
if(count($filters['module_status']) > 0){
|
||||||
$and_module_status = " AND ( ";
|
$and_module_status = " AND ( ";
|
||||||
|
@ -277,25 +315,15 @@ function agent_counters_custom_fields($filters){
|
||||||
else{
|
else{
|
||||||
//not normal
|
//not normal
|
||||||
$and_module_status = "AND tae.estado <> 0 AND tae.estado <> 300 ";
|
$and_module_status = "AND tae.estado <> 0 AND tae.estado <> 300 ";
|
||||||
|
$empty_agents_count = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//filters module
|
//filters module
|
||||||
if($filters['module_search']){
|
if($filters['module_search']){
|
||||||
$and_module_search = 'AND nombre LIKE "%' . $filters['module_search'] . '%"';
|
$and_module_search = 'AND tam.nombre LIKE "%' . $filters['module_search'] . '%"';
|
||||||
}
|
$empty_agents_count = "";
|
||||||
|
|
||||||
$module_filter = "";
|
|
||||||
if($and_module_search != '' || $and_module_status != ''){
|
|
||||||
$module_filter = ' AND (
|
|
||||||
SELECT count(*) AS n
|
|
||||||
FROM tagente_modulo tam
|
|
||||||
INNER JOIN tagente_estado tae
|
|
||||||
ON tae.id_agente_modulo = tam.id_agente_modulo
|
|
||||||
WHERE tam.id_agente=ta.id_agente
|
|
||||||
'. $and_module_search . ' ' . $and_module_status .'
|
|
||||||
) > 0 ';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//filter group and check ACL groups
|
//filter group and check ACL groups
|
||||||
|
@ -359,42 +387,63 @@ function agent_counters_custom_fields($filters){
|
||||||
// Establishes connection
|
// Establishes connection
|
||||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||||
|
|
||||||
$query = sprintf("SELECT
|
$query = sprintf(
|
||||||
tcd.description as name_data,
|
"SELECT tcd.description AS name_data,
|
||||||
SUM(ta.normal_count) AS m_normal,
|
SUM(IF($agent_state_total, 1, 0)) AS a_agents,
|
||||||
SUM(ta.critical_count) AS m_critical,
|
SUM(IF($agent_state_critical, 1, 0)) AS a_critical,
|
||||||
SUM(ta.warning_count) AS m_warning,
|
SUM(IF($agent_state_warning, 1, 0)) AS a_warning,
|
||||||
SUM(ta.unknown_count) AS m_unknown,
|
SUM(IF($agent_state_unknown, 1, 0)) AS a_unknown,
|
||||||
SUM(ta.notinit_count) AS m_not_init,
|
SUM(IF($agent_state_normal, 1, 0)) AS a_normal,
|
||||||
SUM(ta.fired_count) AS m_alerts,
|
SUM(IF($agent_state_notinit, 1, 0)) AS a_not_init,
|
||||||
SUM(ta.total_count) AS m_total,
|
SUM(tagent_counters.mm_normal) AS m_normal,
|
||||||
SUM(IF(ta.critical_count > 0, 1, 0)) AS a_critical,
|
SUM(tagent_counters.mm_critical) AS m_critical,
|
||||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count > 0, 1, 0)) AS a_warning,
|
SUM(tagent_counters.mm_warning) AS m_warning,
|
||||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS a_unknown,
|
SUM(tagent_counters.mm_unknown) AS m_unknown,
|
||||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 AND ta.notinit_count <> ta.total_count, 1, 0)) AS a_normal,
|
SUM(tagent_counters.mm_not_init) AS m_not_init,
|
||||||
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS a_not_init,
|
SUM(tagent_counters.mm_total) AS m_total
|
||||||
COUNT(ta.id_agente) AS a_agents,
|
FROM tagent_custom_data tcd
|
||||||
GROUP_CONCAT(DISTINCT(ta.id_agente) SEPARATOR ',') as ids
|
|
||||||
FROM tagente ta
|
|
||||||
INNER JOIN tagent_custom_data tcd
|
|
||||||
ON tcd.id_agent = ta.id_agente
|
|
||||||
INNER JOIN tagent_custom_fields tcf
|
INNER JOIN tagent_custom_fields tcf
|
||||||
ON tcd.id_field = tcf.id_field
|
ON tcd.id_field = tcf.id_field
|
||||||
LEFT JOIN tagent_secondary_group tasg
|
INNER JOIN (
|
||||||
ON ta.id_agente = tasg.id_agent
|
SELECT ta.id_agente,
|
||||||
WHERE ta.disabled = 0
|
ta.total_count AS c_m_total,
|
||||||
AND tcf.name = '%s'
|
SUM( IF(tae.estado = 0, 1, 0) ) AS mm_normal,
|
||||||
|
SUM( IF(tae.estado = 1, 1, 0) ) AS mm_critical,
|
||||||
|
SUM( IF(tae.estado = 2, 1, 0) ) AS mm_warning,
|
||||||
|
SUM( IF(tae.estado = 3, 1, 0) ) AS mm_unknown,
|
||||||
|
SUM( IF(tae.estado = 4 OR tae.estado = 5, 1, 0) ) AS mm_not_init,
|
||||||
|
COUNT(tam.id_agente_modulo) AS mm_total
|
||||||
|
FROM tagente ta
|
||||||
|
LEFT JOIN tagent_secondary_group tasg
|
||||||
|
ON ta.id_agente = tasg.id_agent
|
||||||
|
INNER JOIN tagente_modulo tam
|
||||||
|
ON ta.id_agente = tam.id_agente
|
||||||
|
INNER JOIN tagente_estado tae
|
||||||
|
ON tam.id_agente = tae.id_agente
|
||||||
|
AND tam.id_agente_modulo = tae.id_agente_modulo
|
||||||
|
WHERE ta.disabled = 0
|
||||||
|
AND tam.disabled = 0
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
GROUP by ta.id_agente
|
||||||
|
%s
|
||||||
|
) AS tagent_counters
|
||||||
|
ON tcd.id_agent = tagent_counters.id_agente
|
||||||
|
INNER JOIN tagente ta
|
||||||
|
ON ta.id_agente = tagent_counters.id_agente
|
||||||
|
WHERE tcf.name = '%s'
|
||||||
AND tcd.description <> ''
|
AND tcd.description <> ''
|
||||||
%s
|
%s
|
||||||
%s
|
|
||||||
%s
|
|
||||||
%s
|
|
||||||
GROUP BY tcd.description",
|
GROUP BY tcd.description",
|
||||||
$custom_field_name,
|
|
||||||
$custom_data_and,
|
|
||||||
$groups_and,
|
$groups_and,
|
||||||
$and_status,
|
$and_status,
|
||||||
$module_filter
|
$and_module_search,
|
||||||
|
$and_module_status,
|
||||||
|
$empty_agents_count,
|
||||||
|
$custom_field_name,
|
||||||
|
$custom_data_and
|
||||||
);
|
);
|
||||||
|
|
||||||
$result_meta[$server_data['id']] = db_get_all_rows_sql($query);
|
$result_meta[$server_data['id']] = db_get_all_rows_sql($query);
|
||||||
|
@ -406,6 +455,11 @@ function agent_counters_custom_fields($filters){
|
||||||
FROM tagente ta
|
FROM tagente ta
|
||||||
LEFT JOIN tagent_secondary_group tasg
|
LEFT JOIN tagent_secondary_group tasg
|
||||||
ON ta.id_agente = tasg.id_agent
|
ON ta.id_agente = tasg.id_agent
|
||||||
|
INNER JOIN tagente_modulo tam
|
||||||
|
ON ta.id_agente = tam.id_agente
|
||||||
|
INNER JOIN tagente_estado tae
|
||||||
|
ON tam.id_agente = tae.id_agente
|
||||||
|
AND tam.id_agente_modulo = tae.id_agente_modulo
|
||||||
INNER JOIN tagent_custom_data tcd
|
INNER JOIN tagent_custom_data tcd
|
||||||
ON tcd.id_agent = ta.id_agente
|
ON tcd.id_agent = ta.id_agente
|
||||||
INNER JOIN tagent_custom_fields tcf
|
INNER JOIN tagent_custom_fields tcf
|
||||||
|
@ -413,22 +467,28 @@ function agent_counters_custom_fields($filters){
|
||||||
WHERE ta.disabled = 0
|
WHERE ta.disabled = 0
|
||||||
AND tcf.name = '%s'
|
AND tcf.name = '%s'
|
||||||
AND tcd.description <> ''
|
AND tcd.description <> ''
|
||||||
|
AND tam.disabled = 0
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
%s
|
||||||
|
GROUP BY ta.id_agente
|
||||||
",
|
",
|
||||||
$server_data['id'],
|
$server_data['id'],
|
||||||
$custom_field_name,
|
$custom_field_name,
|
||||||
$custom_data_and,
|
$custom_data_and,
|
||||||
$groups_and,
|
$groups_and,
|
||||||
$and_status,
|
$and_status,
|
||||||
$module_filter
|
$and_module_search,
|
||||||
|
$and_module_status
|
||||||
);
|
);
|
||||||
|
|
||||||
$node_result = db_get_all_rows_sql($query_data);
|
$node_result = db_get_all_rows_sql($query_data);
|
||||||
|
|
||||||
if (empty($node_result)) $node_result = array();
|
if (empty($node_result)) $node_result = array();
|
||||||
|
|
||||||
|
|
||||||
$data = array_merge($data, $node_result);
|
$data = array_merge($data, $node_result);
|
||||||
// Restore connection to root node
|
// Restore connection to root node
|
||||||
metaconsole_restore_db();
|
metaconsole_restore_db();
|
||||||
|
@ -455,7 +515,6 @@ function agent_counters_custom_fields($filters){
|
||||||
't_a_not_init' => 0,
|
't_a_not_init' => 0,
|
||||||
't_a_agents' => 0
|
't_a_agents' => 0
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($result_meta as $k => $nodo) {
|
foreach ($result_meta as $k => $nodo) {
|
||||||
if(isset($nodo) && is_array($nodo)){
|
if(isset($nodo) && is_array($nodo)){
|
||||||
foreach ($nodo as $key => $value) {
|
foreach ($nodo as $key => $value) {
|
||||||
|
|
|
@ -10361,7 +10361,7 @@ function reporting_label_macro ($item, $label) {
|
||||||
case 'MTTR':
|
case 'MTTR':
|
||||||
case 'automatic_graph':
|
case 'automatic_graph':
|
||||||
if (preg_match("/_agent_/", $label)) {
|
if (preg_match("/_agent_/", $label)) {
|
||||||
if (count($item['agents']) > 1) {
|
if (isset($item['agents']) && count($item['agents']) > 1) {
|
||||||
$agent_name = count($item['agents']) . __(' agents');
|
$agent_name = count($item['agents']) . __(' agents');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -3060,7 +3060,8 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$) {
|
||||||
'custom_id' => $custom_id,
|
'custom_id' => $custom_id,
|
||||||
'url_address' => $url_address,
|
'url_address' => $url_address,
|
||||||
'timezone_offset' => $timezone_offset,
|
'timezone_offset' => $timezone_offset,
|
||||||
'alias' => $alias
|
'alias' => $alias,
|
||||||
|
'update_module_count' => 1, # Force to replicate in metaconsole
|
||||||
});
|
});
|
||||||
|
|
||||||
my $agent_id = db_insert ($dbh, 'id_agente', "INSERT INTO tagente $columns", @{$values});
|
my $agent_id = db_insert ($dbh, 'id_agente', "INSERT INTO tagente $columns", @{$values});
|
||||||
|
|
|
@ -35,6 +35,8 @@ use threads;
|
||||||
|
|
||||||
# Used to calculate the MD5 checksum of a string
|
# Used to calculate the MD5 checksum of a string
|
||||||
use constant MOD232 => 2**32;
|
use constant MOD232 => 2**32;
|
||||||
|
# 2 to the power of 32.
|
||||||
|
use constant POW232 => 2**32;
|
||||||
|
|
||||||
# UTF-8 flags deletion from multibyte characters when files are opened.
|
# UTF-8 flags deletion from multibyte characters when files are opened.
|
||||||
use open OUT => ":utf8";
|
use open OUT => ":utf8";
|
||||||
|
@ -122,6 +124,7 @@ our @EXPORT = qw(
|
||||||
check_server_threads
|
check_server_threads
|
||||||
start_server_thread
|
start_server_thread
|
||||||
stop_server_threads
|
stop_server_threads
|
||||||
|
generate_agent_name_hash
|
||||||
);
|
);
|
||||||
|
|
||||||
# ID of the different servers
|
# ID of the different servers
|
||||||
|
@ -1813,6 +1816,146 @@ sub stop_server_threads {
|
||||||
@ServerThreads = ();
|
@ServerThreads = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Generate random hash as agent name.
|
||||||
|
################################################################################
|
||||||
|
sub generate_agent_name_hash {
|
||||||
|
my ($agent_alias, $server_ip) = @_;
|
||||||
|
return sha256(join('|', ($agent_alias, $server_ip, time(), sprintf("%04d", rand(10000)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Return the SHA256 checksum of the given string as a hex string.
|
||||||
|
# Pseudocode from: http://en.wikipedia.org/wiki/SHA-2#Pseudocode
|
||||||
|
###############################################################################
|
||||||
|
my @K2 = (
|
||||||
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
||||||
|
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||||
|
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
||||||
|
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||||
|
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
||||||
|
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||||
|
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
||||||
|
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||||
|
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
||||||
|
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||||
|
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||||
|
);
|
||||||
|
sub sha256 {
|
||||||
|
my $str = shift;
|
||||||
|
|
||||||
|
# No input!
|
||||||
|
if (!defined($str)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Note: All variables are unsigned 32 bits and wrap modulo 2^32 when
|
||||||
|
# calculating.
|
||||||
|
|
||||||
|
# First 32 bits of the fractional parts of the square roots of the first 8
|
||||||
|
# primes.
|
||||||
|
my $h0 = 0x6a09e667;
|
||||||
|
my $h1 = 0xbb67ae85;
|
||||||
|
my $h2 = 0x3c6ef372;
|
||||||
|
my $h3 = 0xa54ff53a;
|
||||||
|
my $h4 = 0x510e527f;
|
||||||
|
my $h5 = 0x9b05688c;
|
||||||
|
my $h6 = 0x1f83d9ab;
|
||||||
|
my $h7 = 0x5be0cd19;
|
||||||
|
|
||||||
|
# Pre-processing.
|
||||||
|
my $msg = unpack ("B*", pack ("A*", $str));
|
||||||
|
my $bit_len = length ($msg);
|
||||||
|
|
||||||
|
# Append "1" bit to message.
|
||||||
|
$msg .= '1';
|
||||||
|
|
||||||
|
# Append "0" bits until message length in bits = 448 (mod 512).
|
||||||
|
$msg .= '0' while ((length ($msg) % 512) != 448);
|
||||||
|
|
||||||
|
# Append bit /* bit, not byte */ length of unpadded message as 64-bit
|
||||||
|
# big-endian integer to message.
|
||||||
|
$msg .= unpack ("B32", pack ("N", $bit_len >> 32));
|
||||||
|
$msg .= unpack ("B32", pack ("N", $bit_len));
|
||||||
|
|
||||||
|
# Process the message in successive 512-bit chunks.
|
||||||
|
for (my $i = 0; $i < length ($msg); $i += 512) {
|
||||||
|
|
||||||
|
my @w;
|
||||||
|
my $chunk = substr ($msg, $i, 512);
|
||||||
|
|
||||||
|
# Break chunk into sixteen 32-bit big-endian words.
|
||||||
|
for (my $j = 0; $j < length ($chunk); $j += 32) {
|
||||||
|
push (@w, unpack ("N", pack ("B32", substr ($chunk, $j, 32))));
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array:
|
||||||
|
for (my $i = 16; $i < 64; $i++) {
|
||||||
|
my $s0 = rightrotate($w[$i - 15], 7) ^ rightrotate($w[$i - 15], 18) ^ ($w[$i - 15] >> 3);
|
||||||
|
my $s1 = rightrotate($w[$i - 2], 17) ^ rightrotate($w[$i - 2], 19) ^ ($w[$i - 2] >> 10);
|
||||||
|
$w[$i] = ($w[$i - 16] + $s0 + $w[$i - 7] + $s1) % POW232;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize working variables to current hash value.
|
||||||
|
my $a = $h0;
|
||||||
|
my $b = $h1;
|
||||||
|
my $c = $h2;
|
||||||
|
my $d = $h3;
|
||||||
|
my $e = $h4;
|
||||||
|
my $f = $h5;
|
||||||
|
my $g = $h6;
|
||||||
|
my $h = $h7;
|
||||||
|
|
||||||
|
# Compression function main loop.
|
||||||
|
for (my $i = 0; $i < 64; $i++) {
|
||||||
|
my $S1 = rightrotate($e, 6) ^ rightrotate($e, 11) ^ rightrotate($e, 25);
|
||||||
|
my $ch = ($e & $f) ^ ((0xFFFFFFFF & (~ $e)) & $g);
|
||||||
|
my $temp1 = ($h + $S1 + $ch + $K2[$i] + $w[$i]) % POW232;
|
||||||
|
my $S0 = rightrotate($a, 2) ^ rightrotate($a, 13) ^ rightrotate($a, 22);
|
||||||
|
my $maj = ($a & $b) ^ ($a & $c) ^ ($b & $c);
|
||||||
|
my $temp2 = ($S0 + $maj) % POW232;
|
||||||
|
|
||||||
|
$h = $g;
|
||||||
|
$g = $f;
|
||||||
|
$f = $e;
|
||||||
|
$e = ($d + $temp1) % POW232;
|
||||||
|
$d = $c;
|
||||||
|
$c = $b;
|
||||||
|
$b = $a;
|
||||||
|
$a = ($temp1 + $temp2) % POW232;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add the compressed chunk to the current hash value.
|
||||||
|
$h0 = ($h0 + $a) % POW232;
|
||||||
|
$h1 = ($h1 + $b) % POW232;
|
||||||
|
$h2 = ($h2 + $c) % POW232;
|
||||||
|
$h3 = ($h3 + $d) % POW232;
|
||||||
|
$h4 = ($h4 + $e) % POW232;
|
||||||
|
$h5 = ($h5 + $f) % POW232;
|
||||||
|
$h6 = ($h6 + $g) % POW232;
|
||||||
|
$h7 = ($h7 + $h) % POW232;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Produce the final hash value (big-endian).
|
||||||
|
return unpack ("H*", pack ("N", $h0)) .
|
||||||
|
unpack ("H*", pack ("N", $h1)) .
|
||||||
|
unpack ("H*", pack ("N", $h2)) .
|
||||||
|
unpack ("H*", pack ("N", $h3)) .
|
||||||
|
unpack ("H*", pack ("N", $h4)) .
|
||||||
|
unpack ("H*", pack ("N", $h5)) .
|
||||||
|
unpack ("H*", pack ("N", $h6)) .
|
||||||
|
unpack ("H*", pack ("N", $h7));
|
||||||
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Rotate a 32-bit number a number of bits to the right.
|
||||||
|
###############################################################################
|
||||||
|
sub rightrotate {
|
||||||
|
my ($x, $c) = @_;
|
||||||
|
|
||||||
|
return (0xFFFFFFFF & ($x << (32 - $c))) | ($x >> $c);
|
||||||
|
}
|
||||||
|
|
||||||
# End of function declaration
|
# End of function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ sub help_screen{
|
||||||
print "Available options by category:\n\n" unless $param ne '';
|
print "Available options by category:\n\n" unless $param ne '';
|
||||||
print "Available options for $param:\n\n" unless $param eq '';
|
print "Available options for $param:\n\n" unless $param eq '';
|
||||||
print "AGENTS:\n\n" unless $param ne '';
|
print "AGENTS:\n\n" unless $param ne '';
|
||||||
help_screen_line('--create_agent', "<agent_name> <operating_system> <group> <server_name> \n\t [<address> <description> <interval>]", 'Create agent');
|
help_screen_line('--create_agent', "<agent_name> <operating_system> <group> <server_name> \n\t [<address> <description> <interval> <alias_as_name>]", 'Create agent');
|
||||||
help_screen_line('--update_agent', '<agent_name> <field_to_change> <new_value>', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id");
|
help_screen_line('--update_agent', '<agent_name> <field_to_change> <new_value>', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id");
|
||||||
help_screen_line('--delete_agent', '<agent_name>', 'Delete agent');
|
help_screen_line('--delete_agent', '<agent_name>', 'Delete agent');
|
||||||
help_screen_line('--disable_group', '<group_name>', 'Disable agents from an entire group');
|
help_screen_line('--disable_group', '<group_name>', 'Disable agents from an entire group');
|
||||||
|
@ -996,21 +996,29 @@ sub cli_enable_group() {
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
sub cli_create_agent() {
|
sub cli_create_agent() {
|
||||||
my ($agent_name,$os_name,$group_name,$server_name,$address,$description,$interval) = @ARGV[2..8];
|
my ($agent_name,$os_name,$group_name,$server_name,$address,$description,$interval, $alias_as_name) = @ARGV[2..9];
|
||||||
|
|
||||||
print_log "[INFO] Creating agent '$agent_name'\n\n";
|
print_log "[INFO] Creating agent '$agent_name'\n\n";
|
||||||
|
|
||||||
$address = '' unless defined ($address);
|
$address = '' unless defined ($address);
|
||||||
$description = (defined ($description) ? safe_input($description) : '' ); # safe_input() might be better at pandora_create_agent() (when passing 'description' to db_insert())
|
$description = (defined ($description) ? safe_input($description) : '' ); # safe_input() might be better at pandora_create_agent() (when passing 'description' to db_insert())
|
||||||
$interval = 300 unless defined ($interval);
|
$interval = 300 unless defined ($interval);
|
||||||
|
$alias_as_name = 1 unless defined ($alias_as_name);
|
||||||
|
my $agent_alias = undef;
|
||||||
|
|
||||||
|
if (!$alias_as_name) {
|
||||||
|
$agent_alias = $agent_name;
|
||||||
|
$agent_name = generate_agent_name_hash($agent_alias, $conf{'dbhost'});
|
||||||
|
}
|
||||||
|
|
||||||
my $id_group = get_group_id($dbh,$group_name);
|
my $id_group = get_group_id($dbh,$group_name);
|
||||||
exist_check($id_group,'group',$group_name);
|
exist_check($id_group,'group',$group_name);
|
||||||
my $os_id = get_os_id($dbh,$os_name);
|
my $os_id = get_os_id($dbh,$os_name);
|
||||||
exist_check($id_group,'operating system',$group_name);
|
exist_check($id_group,'operating system',$group_name);
|
||||||
my $agent_exists = get_agent_id($dbh,$agent_name);
|
my $agent_exists = get_agent_id($dbh,$agent_name);
|
||||||
non_exist_check($agent_exists, 'agent name', $agent_name);
|
non_exist_check($agent_exists, 'agent name', $agent_name);
|
||||||
pandora_create_agent ($conf, $server_name, $agent_name, $address, $id_group, 0, $os_id, $description, $interval, $dbh);
|
pandora_create_agent ($conf, $server_name, $agent_name, $address, $id_group, 0, $os_id, $description, $interval, $dbh,
|
||||||
|
undef, undef, undef, undef, undef, undef, undef, undef, $agent_alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
@ -5697,7 +5705,7 @@ sub pandora_manage_main ($$$) {
|
||||||
cli_enable_group();
|
cli_enable_group();
|
||||||
}
|
}
|
||||||
elsif ($param eq '--create_agent') {
|
elsif ($param eq '--create_agent') {
|
||||||
param_check($ltotal, 7, 3);
|
param_check($ltotal, 8, 4);
|
||||||
cli_create_agent();
|
cli_create_agent();
|
||||||
}
|
}
|
||||||
elsif ($param eq '--delete_agent') {
|
elsif ($param eq '--delete_agent') {
|
||||||
|
|
Loading…
Reference in New Issue