Merge branch 'ent-12350-cambiar-el-nombre-de-agente-interno' into 'develop'

Ent 12350 cambiar el nombre de agente interno

See merge request artica/pandorafms!6750
This commit is contained in:
Matias Didier 2024-02-16 08:30:26 +00:00
commit a56d68dd4e
8 changed files with 319 additions and 171 deletions

View File

@ -357,7 +357,18 @@ if ($new_agent === false) {
$tableAgent->data['caption_name'][0] = __('Agent name'); $tableAgent->data['caption_name'][0] = __('Agent name');
$tableAgent->rowclass['name'] = 'w540px'; $tableAgent->rowclass['name'] = 'w540px';
$tableAgent->cellstyle['name'][0] = 'width: 100%;'; $tableAgent->cellstyle['name'][0] = 'width: 100%;';
$tableAgent->data['name'][0] = html_print_input_text('agente', $nombre_agente, '', 76, 100, true, false, false, '', 'w100p'); $tableAgent->data['name'][0] = html_print_input_text(
'agente',
$nombre_agente,
'',
76,
100,
true,
true,
false,
'',
'w100p'
);
$tableAgent->data['name'][0] .= html_print_div( $tableAgent->data['name'][0] .= html_print_div(
[ [
'class' => 'moduleIdBox', 'class' => 'moduleIdBox',
@ -365,6 +376,29 @@ if ($new_agent === false) {
], ],
true true
); );
// Other than Linux, Solaris, AIX, BSD, HPUX, MacOs, and Windows.
if ($id_os !== LINUX && $id_os !== SOLARIS && $id_os !== AIX
&& $id_os !== BSD && $id_os !== HPUX && $id_os !== MACOS
&& $id_os !== WINDOWS
) {
$tableAgent->data['name'][0] .= html_print_anchor(
[
'content' => html_print_image(
'images/edit.svg',
true,
[
'border' => 0,
'title' => __('Edit agent name'),
'class' => 'main_menu_icon invert_filter after_input_icon forced_title clickable',
'onclick' => 'editAgent()',
]
),
],
true
);
}
// Agent options for QR code. // Agent options for QR code.
$agent_options_update = 'agent_options_update'; $agent_options_update = 'agent_options_update';
} }
@ -1491,7 +1525,6 @@ ui_require_jquery_file('bgiframe');
128 128
); );
} }
$("#text-agente").prop('readonly', true);
$("#text-direccion").on('change',function(e){ $("#text-direccion").on('change',function(e){
@ -1538,6 +1571,39 @@ ui_require_jquery_file('bgiframe');
} }
} }
function editAgent() {
$(`#text-agente`).attr(`readonly`, false);
const title = '<?php echo __('Warning'); ?>';
const text = '<?php echo __('Change the internal name of the agent may cause duplicity and malfunction'); ?>';
const id = uniqId();
$("body").append('<div title="' + title + '" id="' + id + '"></div>');
$("#" + id).empty();
$("#" + id).append(text);
$("#" + id).dialog({
height: 150,
width: 528,
opacity: 1,
modal: true,
position: {
my: "center",
at: "center",
of: window,
collision: "fit"
},
title: title,
closeOnEscape: true,
buttons: [{
text: "OK",
click: function() {
$(this).dialog("close");
}
}],
open: function(event, ui) {
$(".ui-dialog-titlebar-close").hide();
},
}).show();
}
function check_unique_ip() { function check_unique_ip() {
const direccion = $('#text-direccion').val(); const direccion = $('#text-direccion').val();

View File

@ -949,6 +949,13 @@ if ($update_agent) {
$mssg_warning = 0; $mssg_warning = 0;
$id_agente = (int) get_parameter_post('id_agente'); $id_agente = (int) get_parameter_post('id_agente');
$nombre_agente = str_replace('`', '&lsquo;', (string) get_parameter_post('agente', '')); $nombre_agente = str_replace('`', '&lsquo;', (string) get_parameter_post('agente', ''));
$repeated_name = db_get_row_sql(
sprintf(
'SELECT nombre FROM tagente WHERE id_agente <> %s AND nombre like "%s"',
$id_agente,
$nombre_agente
)
);
$alias_safe_output = strip_tags(io_safe_output(get_parameter('alias', ''))); $alias_safe_output = strip_tags(io_safe_output(get_parameter('alias', '')));
$alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output))); $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output)));
$alias_as_name = (int) get_parameter_post('alias_as_name', 0); $alias_as_name = (int) get_parameter_post('alias_as_name', 0);
@ -1077,14 +1084,17 @@ if ($update_agent) {
} }
} }
// Verify if there is another agent with the same name but different ID.
if (empty($repeated_name) === false) {
ui_print_error_message(__('Agent with repeated name'));
}
if ($mssg_warning) { if ($mssg_warning) {
ui_print_warning_message(__('The ip or dns name entered cannot be resolved')); ui_print_warning_message(__('The ip or dns name entered cannot be resolved'));
} }
// Verify if there is another agent with the same name but different ID.
if ($alias == '') { if ($alias == '') {
ui_print_error_message(__('No agent alias specified')); ui_print_error_message(__('No agent alias specified'));
// If there is an agent with the same name, but a different ID.
} }
$old_group = agents_get_agent_group($id_agente); $old_group = agents_get_agent_group($id_agente);
@ -1139,13 +1149,16 @@ if ($update_agent) {
'ignore_unknown' => $ignore_unknown, 'ignore_unknown' => $ignore_unknown,
]; ];
if (empty($repeated_name) === true) {
$values['nombre'] = $nombre_agente;
}
if ($config['metaconsole_agent_cache'] == 1) { if ($config['metaconsole_agent_cache'] == 1) {
$values['update_module_count'] = 1; $values['update_module_count'] = 1;
// Force an update of the agent cache. // Force an update of the agent cache.
} }
$result = db_process_sql_update('tagente', $values, ['id_agente' => $id_agente]); $result = (bool) db_process_sql_update('tagente', $values, ['id_agente' => $id_agente]);
if ($result === false && $update_custom_result == false) { if ($result === false && $update_custom_result == false) {
ui_print_error_message( ui_print_error_message(
__('There was a problem updating the agent') __('There was a problem updating the agent')

View File

@ -454,18 +454,27 @@ class HostDevices extends Wizard
io_safe_input('Linux System'), io_safe_input('Linux System'),
io_safe_input('Windows System'), io_safe_input('Windows System'),
io_safe_input('Windows Hardware'), io_safe_input('Windows Hardware'),
io_safe_input('Network Management') io_safe_input('Network Management'),
]; ];
$default_templates_ids = db_get_all_rows_sql('SELECT id_np $default_templates_ids = db_get_all_rows_sql(
'SELECT id_np
FROM tnetwork_profile FROM tnetwork_profile
WHERE name IN ('.implode(',', array_map(function($template) { WHERE name IN ('.implode(
return "'" . $template . "'"; ',',
}, $default_templates)).') array_map(
ORDER BY name'); function ($template) {
return "'".$template."'";
},
$default_templates
)
).')
ORDER BY name'
);
if($default_templates_ids !== false) { if ($default_templates_ids !== false) {
$this->task['id_network_profile'] = implode(',', $this->task['id_network_profile'] = implode(
',',
array_column($default_templates_ids, 'id_np'), array_column($default_templates_ids, 'id_np'),
); );
} }
@ -1314,10 +1323,10 @@ class HostDevices extends Wizard
$item['extra_1'] = io_output_password($item['extra_1']); $item['extra_1'] = io_output_password($item['extra_1']);
$extra1 = json_decode($item['extra_1'], true); $extra1 = json_decode($item['extra_1'], true);
if($extra1 !== null && $extra1['version'] == 3) { if ($extra1 !== null && $extra1['version'] == 3) {
$carry[$item['identifier']] = $item['identifier']; $carry[$item['identifier']] = $item['identifier'];
} }
return $carry; return $carry;
}, },
[] []

View File

@ -759,21 +759,21 @@ class Prd
'conditional_refs' => [ 'conditional_refs' => [
[ [
'when' => ['type' => 'netflow_area'], 'when' => ['type' => 'netflow_area'],
'ref' => $this->tnetflowFilter, 'ref' => $this->tnetflowFilter,
], ],
[ [
'when' => ['type' => 'netflow_data'], 'when' => ['type' => 'netflow_data'],
'ref' => $this->tnetflowFilter, 'ref' => $this->tnetflowFilter,
], ],
[ [
'when' => ['type' => 'netflow_summary'], 'when' => ['type' => 'netflow_summary'],
'ref' => $this->tnetflowFilter, 'ref' => $this->tnetflowFilter,
], ],
[ [
'when' => ['type' => 'netflow_top_N'], 'when' => ['type' => 'netflow_top_N'],
'ref' => $this->tnetflowFilter, 'ref' => $this->tnetflowFilter,
] ],
] ],
], ],
], ],
'treport_content_item' => [ 'treport_content_item' => [
@ -790,11 +790,11 @@ class Prd
'when' => ['type' => 'SLA_services'], 'when' => ['type' => 'SLA_services'],
], ],
], ],
'ref' => $this->tservice, 'ref' => $this->tservice,
] ],
], ],
'ref' => $this->tagenteModulo 'ref' => $this->tagenteModulo,
] ],
], ],
'tpolicies' => [ 'tpolicies' => [
'id_group' => ['ref' => $this->tgrupo], 'id_group' => ['ref' => $this->tgrupo],
@ -952,12 +952,14 @@ class Prd
'id_agent' => ['ref' => $this->tagente], 'id_agent' => ['ref' => $this->tagente],
], ],
], ],
'treport_content' => [ 'treport_content' => [
'external_source' => [ 'external_source' => [
'module' => ['ref' => $this->tagenteModulo + ['array' => true, 'values_as_keys' => true]], 'module' => [
'id_agents' => ['ref' => $this->tagente + ['array' => true]], 'ref' => ($this->tagenteModulo + ['array' => true, 'values_as_keys' => true]),
'templates' => ['ref' => $this->talertTemplates + ['array' => true]], ],
'actions' => ['ref' => $this->talertActions + ['array' => true]], 'id_agents' => ['ref' => ($this->tagente + ['array' => true])],
'templates' => ['ref' => ($this->talertTemplates + ['array' => true])],
'actions' => ['ref' => ($this->talertActions + ['array' => true])],
], ],
], ],
'twidget_dashboard' => [ 'twidget_dashboard' => [
@ -1956,6 +1958,7 @@ class Prd
return $value; return $value;
} }
/** /**
* Function that checks if a value is a base64. * Function that checks if a value is a base64.
* *
@ -1967,11 +1970,12 @@ class Prd
{ {
// Check if the string is valid base64 by decoding it // Check if the string is valid base64 by decoding it
$decoded = base64_decode($string, true); $decoded = base64_decode($string, true);
// Check if decoding was successful and if the decoded string matches the original // Check if decoding was successful and if the decoded string matches the original
return ($decoded !== false && base64_encode($decoded) === $string); return ($decoded !== false && base64_encode($decoded) === $string);
} }
/** /**
* Function that checks if a value is a json. * Function that checks if a value is a json.
* *
@ -2175,6 +2179,7 @@ class Prd
} else { } else {
$value_arr = json_decode($value, true); $value_arr = json_decode($value, true);
} }
if (is_array($value_arr)) { if (is_array($value_arr)) {
$ref_arr = []; $ref_arr = [];
foreach ($value_arr as $val) { foreach ($value_arr as $val) {
@ -2226,6 +2231,7 @@ class Prd
} else { } else {
$value_arr = json_decode($value, true); $value_arr = json_decode($value, true);
} }
if (is_array($value_arr)) { if (is_array($value_arr)) {
$ref_arr = []; $ref_arr = [];
foreach ($value_arr as $val) { foreach ($value_arr as $val) {
@ -2270,6 +2276,7 @@ class Prd
if (is_array($ref_val) === true) { if (is_array($ref_val) === true) {
$ref_val = json_encode($ref_val); $ref_val = json_encode($ref_val);
} }
$ref_arr[] = $ref_val; $ref_arr[] = $ref_val;
} }
@ -2303,6 +2310,7 @@ class Prd
} else { } else {
$value_arr = json_decode($value, true); $value_arr = json_decode($value, true);
} }
if (is_array($value_arr)) { if (is_array($value_arr)) {
$ref_arr = []; $ref_arr = [];
foreach ($value_arr as $val) { foreach ($value_arr as $val) {
@ -2354,6 +2362,7 @@ class Prd
} else { } else {
$value_arr = json_decode($value, true); $value_arr = json_decode($value, true);
} }
if (is_array($value_arr)) { if (is_array($value_arr)) {
$ref_arr = []; $ref_arr = [];
foreach ($value_arr as $val) { foreach ($value_arr as $val) {
@ -2398,6 +2407,7 @@ class Prd
if (is_array($ref_val) === true) { if (is_array($ref_val) === true) {
$ref_val = json_encode($ref_val); $ref_val = json_encode($ref_val);
} }
$ref_arr[] = $ref_val; $ref_arr[] = $ref_val;
} }
@ -2449,6 +2459,7 @@ class Prd
} else { } else {
$value_arr = json_decode($value, true); $value_arr = json_decode($value, true);
} }
if (is_array($value_arr)) { if (is_array($value_arr)) {
$ref_arr = []; $ref_arr = [];
foreach ($value_arr as $val) { foreach ($value_arr as $val) {
@ -2536,6 +2547,7 @@ class Prd
} else { } else {
$value_arr = json_decode($value, true); $value_arr = json_decode($value, true);
} }
if (is_array($value_arr)) { if (is_array($value_arr)) {
$ref_arr = []; $ref_arr = [];
foreach ($value_arr as $val) { foreach ($value_arr as $val) {
@ -2719,6 +2731,7 @@ class Prd
$value = base64_decode($value); $value = base64_decode($value);
$isBase64 = true; $isBase64 = true;
} }
// The column is inside column refs. // The column is inside column refs.
$this->getReferenceFromValue( $this->getReferenceFromValue(
$element['table'], $element['table'],
@ -2740,6 +2753,7 @@ class Prd
$json_value = base64_decode($json_value); $json_value = base64_decode($json_value);
$isBase64 = true; $isBase64 = true;
} }
$this->getReferenceFromValue( $this->getReferenceFromValue(
$element['table'], $element['table'],
$column, $column,
@ -2751,8 +2765,10 @@ class Prd
if (is_array($json_value) === true) { if (is_array($json_value) === true) {
$json_value = json_encode($json_value); $json_value = json_encode($json_value);
} }
$json_value = base64_encode($json_value); $json_value = base64_encode($json_value);
} }
$this->updateJsonArrayValue($array_value, $json_key, $json_value); $this->updateJsonArrayValue($array_value, $json_key, $json_value);
} }
} }
@ -2908,6 +2924,7 @@ class Prd
$value = base64_decode($value); $value = base64_decode($value);
$isBase64 = true; $isBase64 = true;
} }
$create_item = $this->getValueFromReference( $create_item = $this->getValueFromReference(
$table, $table,
$column, $column,
@ -2934,6 +2951,7 @@ class Prd
$json_value = base64_decode($json_value); $json_value = base64_decode($json_value);
$isBase64 = true; $isBase64 = true;
} }
if ($this->getValueFromReference( if ($this->getValueFromReference(
$table, $table,
$column, $column,
@ -2945,8 +2963,10 @@ class Prd
if (is_array($json_value) === true) { if (is_array($json_value) === true) {
$json_value = json_encode($json_value); $json_value = json_encode($json_value);
} }
$json_value = base64_encode($json_value); $json_value = base64_encode($json_value);
} }
$this->updateJsonArrayValue($array_value, $json_key, $json_value); $this->updateJsonArrayValue($array_value, $json_key, $json_value);
} else { } else {
$create_item = false; $create_item = false;
@ -2958,7 +2978,7 @@ class Prd
$value = json_encode($array_value); $value = json_encode($array_value);
} }
if($create_item === false){ if ($create_item === false) {
break; break;
} }
@ -3519,7 +3539,7 @@ class Prd
/** /**
* Function to create item in database. * Function to create item in database.
* *
* @param string $table Table. * @param string $table Table.
* *
* @return mixed * @return mixed
*/ */

View File

@ -893,7 +893,7 @@ class WelcomeWindow extends Wizard
// SNMP Communities // SNMP Communities
echo html_print_label_input_block( echo html_print_label_input_block(
__('SNMP communities to try with').ui_print_help_tip( __('SNMP communities to try with').ui_print_help_tip(
__( __(
'You can specify several values, separated by commas, for example: public,mysecret,1234' 'You can specify several values, separated by commas, for example: public,mysecret,1234'
), ),
@ -905,19 +905,17 @@ class WelcomeWindow extends Wizard
'type' => 'text', 'type' => 'text',
'value' => 'public', 'value' => 'public',
'size' => 25, 'size' => 25,
'return' => true 'return' => true,
], ],
'div', 'div',
true true
), ),
[ ['div_id' => 'snmp-communities-div']
'div_id' => 'snmp-communities-div'
]
); );
ui_require_jquery_file('tag-editor.min','include/javascript/',true); ui_require_jquery_file('tag-editor.min', 'include/javascript/', true);
ui_require_jquery_file('caret.min','include/javascript/',true); ui_require_jquery_file('caret.min', 'include/javascript/', true);
ui_require_css_file('jquery.tag-editor','include/styles/',true); ui_require_css_file('jquery.tag-editor', 'include/styles/', true);
echo '<br>'; echo '<br>';
$spacing = ''; $spacing = '';
@ -931,7 +929,7 @@ class WelcomeWindow extends Wizard
echo html_print_div( echo html_print_div(
[ [
'id' => 'wmi-creds', 'id' => 'wmi-creds',
'content' => '' 'content' => '',
], ],
true true
); );
@ -941,16 +939,19 @@ class WelcomeWindow extends Wizard
'hidden' => true, 'hidden' => true,
'style' => 'margin: 10px; display: flex; align-items: center;', 'style' => 'margin: 10px; display: flex; align-items: center;',
'content' => html_print_div( 'content' => html_print_div(
[ [
'id' => 'wmi-cred-user-div', 'id' => 'wmi-cred-user-div',
'style' => 'width: 260px;', 'style' => 'width: 260px;',
'content' => html_print_label_input_block(__('User').'&nbsp;', html_print_input_text( 'content' => html_print_label_input_block(
__('User').'&nbsp;',
html_print_input_text(
'wmi-cred-user', 'wmi-cred-user',
'', '',
'', '',
false, false,
50, // Max length 50,
true, // Max length
true,
false, false,
true, true,
'', '',
@ -964,44 +965,50 @@ class WelcomeWindow extends Wizard
false, false,
'', '',
'Username' 'Username'
),['div_style' => 'display: flex; align-items: center;']) ),
], ['div_style' => 'display: flex; align-items: center;']
true ),
) ],
. true
html_print_div( ).html_print_div(
[ [
'id' => 'wmi-cred-pass-div', 'id' => 'wmi-cred-pass-div',
'style' => 'width: 260px;', 'style' => 'width: 260px;',
'content' => html_print_label_input_block($spacing.__('Password').'&nbsp;', html_print_input_password( 'content' => html_print_label_input_block(
$spacing.__('Password').'&nbsp;',
html_print_input_password(
'wmi-cred-pass', 'wmi-cred-pass',
'', '',
'', '',
false, false,
50, // Max length 50,
true, // Max length
true,
false, false,
true, true,
'w100p', 'w100p',
'off', 'off',
false, false,
'' ''
),['div_style' => 'display: flex; align-items: center;']) ),
], ['div_style' => 'display: flex; align-items: center;']
true ),
) ],
. true
html_print_div( ).html_print_div(
[ [
'id' => 'wmi-cred-namespace-div', 'id' => 'wmi-cred-namespace-div',
'style' => 'width: 260px;', 'style' => 'width: 260px;',
'content' => html_print_label_input_block($spacing.__('Namespace').'&nbsp;', html_print_input_text( 'content' => html_print_label_input_block(
$spacing.__('Namespace').'&nbsp;',
html_print_input_text(
'wmi-cred-namespace', 'wmi-cred-namespace',
'', '',
'', '',
false, false,
50, // Max length 50,
true, // Max length
true,
false, false,
true, true,
'', '',
@ -1015,20 +1022,20 @@ class WelcomeWindow extends Wizard
false, false,
'', '',
'Namespace' 'Namespace'
),['div_style' => 'display: flex; align-items: center;']) ),
], ['div_style' => 'display: flex; align-items: center;']
true ),
) ],
. true
'<a onClick="delete_discovery_credential(this);">'.html_print_image( ).'<a onClick="delete_discovery_credential(this);">'.html_print_image(
'images/delete.svg', 'images/delete.svg',
true, true,
[ [
'title' => __('Delete'), 'title' => __('Delete'),
'style' => 'cursor: pointer;', 'style' => 'cursor: pointer;',
'class' => 'main_menu_icon invert_filter', 'class' => 'main_menu_icon invert_filter',
] ]
).'</a>' ).'</a>',
], ],
true true
); );
@ -1040,8 +1047,8 @@ class WelcomeWindow extends Wizard
'add_discovery_credential("wmi-cred-form","wmi-creds");', 'add_discovery_credential("wmi-cred-form","wmi-creds");',
[ [
'icon' => 'plus', 'icon' => 'plus',
'mode' => 'secondary', 'mode' => 'secondary',
'class' => 'mini' 'class' => 'mini',
], ],
true, true,
false, false,
@ -1058,7 +1065,7 @@ class WelcomeWindow extends Wizard
echo html_print_div( echo html_print_div(
[ [
'id' => 'rcmd-creds', 'id' => 'rcmd-creds',
'content' => '' 'content' => '',
], ],
true true
); );
@ -1068,16 +1075,19 @@ class WelcomeWindow extends Wizard
'hidden' => true, 'hidden' => true,
'style' => 'margin: 10px; display: flex; align-items: center;', 'style' => 'margin: 10px; display: flex; align-items: center;',
'content' => html_print_div( 'content' => html_print_div(
[ [
'id' => 'rcmd-cred-user-div', 'id' => 'rcmd-cred-user-div',
'style' => 'width: 260px;', 'style' => 'width: 260px;',
'content' => html_print_label_input_block(__('User').'&nbsp;', html_print_input_text( 'content' => html_print_label_input_block(
__('User').'&nbsp;',
html_print_input_text(
'rcmd-cred-user', 'rcmd-cred-user',
'', '',
'', '',
false, false,
50, // Max length 50,
true, // Max length
true,
false, false,
true, true,
'', '',
@ -1091,42 +1101,45 @@ class WelcomeWindow extends Wizard
false, false,
'', '',
'Username' 'Username'
),['div_style' => 'display: flex; align-items: center;']) ),
], ['div_style' => 'display: flex; align-items: center;']
true ),
) ],
. true
html_print_div( ).html_print_div(
[ [
'id' => 'rcmd-cred-pass-div', 'id' => 'rcmd-cred-pass-div',
'style' => 'width: 260px;', 'style' => 'width: 260px;',
'content' => html_print_label_input_block($spacing.__('Password').'&nbsp;', html_print_input_password( 'content' => html_print_label_input_block(
$spacing.__('Password').'&nbsp;',
html_print_input_password(
'rcmd-cred-pass', 'rcmd-cred-pass',
'', '',
'', '',
false, false,
50, // Max length 50,
true, // Max length
true,
false, false,
true, true,
'w100p', 'w100p',
'off', 'off',
false, false,
'' ''
),['div_style' => 'display: flex; align-items: center;']) ),
], ['div_style' => 'display: flex; align-items: center;']
true ),
) ],
. true
'<a onClick="delete_discovery_credential(this);">'.html_print_image( ).'<a onClick="delete_discovery_credential(this);">'.html_print_image(
'images/delete.svg', 'images/delete.svg',
true, true,
[ [
'title' => __('Delete'), 'title' => __('Delete'),
'style' => 'cursor: pointer;', 'style' => 'cursor: pointer;',
'class' => 'main_menu_icon invert_filter', 'class' => 'main_menu_icon invert_filter',
] ]
).'</a>' ).'</a>',
], ],
true true
); );
@ -1138,8 +1151,8 @@ class WelcomeWindow extends Wizard
'add_discovery_credential("rcmd-cred-form","rcmd-creds");', 'add_discovery_credential("rcmd-cred-form","rcmd-creds");',
[ [
'icon' => 'plus', 'icon' => 'plus',
'mode' => 'secondary', 'mode' => 'secondary',
'class' => 'mini' 'class' => 'mini',
], ],
true, true,
false, false,

View File

@ -910,3 +910,13 @@ define('DEMO_PLUGIN', 9);
// Export resources. // Export resources.
define('LINE_BREAK', "\n"); define('LINE_BREAK', "\n");
// OS.
define('LINUX', '1');
define('SOLARIS', '2');
define('AIX', '3');
define('BSD', '4');
define('HPUX', '5');
define('CISCO', '7');
define('MACOS', '8');
define('WINDOWS', '9');

View File

@ -472,10 +472,10 @@ function create_module_packet_lost($id_agent, $id_group, $ip_target)
/** /**
* Create module packet lost and return module id. * Create module packet lost and return module id.
* *
* @param string $ip_target Ip and red mask. * @param string $ip_target Ip and red mask.
* @param string $snmp_communities SNMP Communities to use in recon task. * @param string $snmp_communities SNMP Communities to use in recon task.
* @param array $wmi_credentials WMI Credentials to use in recon task. * @param array $wmi_credentials WMI Credentials to use in recon task.
* @param array $rcmd_credentials RCMD Credentials to use in recon task. * @param array $rcmd_credentials RCMD Credentials to use in recon task.
* *
* @return interger Module id. * @return interger Module id.
*/ */
@ -484,7 +484,7 @@ function create_net_scan($ip_target, $snmp_version, $snmp_communities, $wmi_cred
global $config; global $config;
include_once $config['homedir'].'/godmode/wizards/HostDevices.class.php'; include_once $config['homedir'].'/godmode/wizards/HostDevices.class.php';
include_once $config['homedir'].'/include/functions_groups.php'; include_once $config['homedir'].'/include/functions_groups.php';
$group_name = 'AutoDiscovery'; $group_name = 'AutoDiscovery';
$id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($group_name)); $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($group_name));
if (!($id_group > 0)) { if (!($id_group > 0)) {
@ -509,72 +509,87 @@ function create_net_scan($ip_target, $snmp_version, $snmp_communities, $wmi_cred
io_safe_input('Linux System'), io_safe_input('Linux System'),
io_safe_input('Windows System'), io_safe_input('Windows System'),
io_safe_input('Windows Hardware'), io_safe_input('Windows Hardware'),
io_safe_input('Network Management') io_safe_input('Network Management'),
]; ];
$default_templates_ids = db_get_all_rows_sql('SELECT id_np $default_templates_ids = db_get_all_rows_sql(
'SELECT id_np
FROM tnetwork_profile FROM tnetwork_profile
WHERE name IN ('.implode(',', array_map(function($template) { WHERE name IN ('.implode(
return "'" . $template . "'"; ',',
}, $default_templates)).') array_map(
ORDER BY name'); function ($template) {
return "'".$template."'";
},
$default_templates
)
).')
ORDER BY name'
);
$id_base = 'autoDiscovery-WMI-'; $id_base = 'autoDiscovery-WMI-';
$id = 0; $id = 0;
foreach($wmi_credentials as $wmi) { foreach ($wmi_credentials as $wmi) {
$id++; $id++;
$identifier = $id_base . $id; $identifier = $id_base.$id;
while(db_get_value_sql( while (db_get_value_sql(
sprintf( sprintf(
'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"', 'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"',
$identifier $identifier
) )
) > 0) { ) > 0) {
$id++; $id++;
$identifier = $id_base . $id; $identifier = $id_base.$id;
} }
$storeKey = db_process_sql_insert('tcredential_store', [ $storeKey = db_process_sql_insert(
'identifier' => $identifier, 'tcredential_store',
'id_group' => $id_group, [
'product' => 'WMI', 'identifier' => $identifier,
'username' => $wmi['credential']['user'], 'id_group' => $id_group,
'password' => $wmi['credential']['pass'], 'product' => 'WMI',
'extra_1' => $wmi['credential']['namespace'] 'username' => $wmi['credential']['user'],
]); 'password' => $wmi['credential']['pass'],
'extra_1' => $wmi['credential']['namespace'],
]
);
if($storeKey !== false) { if ($storeKey !== false) {
$auth_strings[] = $identifier; $auth_strings[] = $identifier;
} }
} }
$id_base = 'autoDiscovery-RCMD-'; $id_base = 'autoDiscovery-RCMD-';
$id = 0; $id = 0;
foreach($rcmd_credentials as $rcmd) { foreach ($rcmd_credentials as $rcmd) {
$id++; $id++;
$identifier = $id_base . $id; $identifier = $id_base.$id;
while(db_get_value_sql( while (db_get_value_sql(
sprintf( sprintf(
'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"', 'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"',
$identifier $identifier
) )
) > 0) { ) > 0) {
$id++; $id++;
$identifier = $id_base . $id; $identifier = $id_base.$id;
} }
$storeKey = db_process_sql_insert('tcredential_store', [ $storeKey = db_process_sql_insert(
'identifier' => $identifier, 'tcredential_store',
'id_group' => $id_group, [
'product' => 'CUSTOM', 'identifier' => $identifier,
'username' => $rcmd['credential']['user'], 'id_group' => $id_group,
'password' => $rcmd['credential']['pass'] 'product' => 'CUSTOM',
]); 'username' => $rcmd['credential']['user'],
'password' => $rcmd['credential']['pass'],
]
);
if($storeKey !== false) { if ($storeKey !== false) {
$auth_strings[] = $identifier; $auth_strings[] = $identifier;
} }
} }
$HostDevices = new HostDevices(1); $HostDevices = new HostDevices(1);
$id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server']; $id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server'];

View File

@ -1266,17 +1266,19 @@ class Manager implements PublicLogin
} }
if (empty($cells) === false) { if (empty($cells) === false) {
$result = array_values(array_reduce( $result = array_values(
$cells, array_reduce(
function ($carry, $item) { $cells,
$carry[$item['order']]['id'] = $item['id']; function ($carry, $item) {
$carry[$item['order']]['position'] = $item['position']; $carry[$item['order']]['id'] = $item['id'];
$carry[$item['order']]['widgetId'] = $item['id_widget']; $carry[$item['order']]['position'] = $item['position'];
$carry[$item['order']]['widgetId'] = $item['id_widget'];
return $carry; return $carry;
}, },
[] []
)); )
);
} }
echo json_encode($result); echo json_encode($result);