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->rowclass['name'] = 'w540px';
$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(
[
'class' => 'moduleIdBox',
@ -365,6 +376,29 @@ if ($new_agent === false) {
],
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_update = 'agent_options_update';
}
@ -1491,7 +1525,6 @@ ui_require_jquery_file('bgiframe');
128
);
}
$("#text-agente").prop('readonly', true);
$("#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() {
const direccion = $('#text-direccion').val();

View File

@ -949,6 +949,13 @@ if ($update_agent) {
$mssg_warning = 0;
$id_agente = (int) get_parameter_post('id_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 = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output)));
$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) {
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 == '') {
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);
@ -1139,13 +1149,16 @@ if ($update_agent) {
'ignore_unknown' => $ignore_unknown,
];
if (empty($repeated_name) === true) {
$values['nombre'] = $nombre_agente;
}
if ($config['metaconsole_agent_cache'] == 1) {
$values['update_module_count'] = 1;
// 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) {
ui_print_error_message(
__('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('Windows System'),
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
WHERE name IN ('.implode(',', array_map(function($template) {
return "'" . $template . "'";
}, $default_templates)).')
ORDER BY name');
WHERE name IN ('.implode(
',',
array_map(
function ($template) {
return "'".$template."'";
},
$default_templates
)
).')
ORDER BY name'
);
if($default_templates_ids !== false) {
$this->task['id_network_profile'] = implode(',',
if ($default_templates_ids !== false) {
$this->task['id_network_profile'] = implode(
',',
array_column($default_templates_ids, 'id_np'),
);
}
@ -1314,10 +1323,10 @@ class HostDevices extends Wizard
$item['extra_1'] = io_output_password($item['extra_1']);
$extra1 = json_decode($item['extra_1'], true);
if($extra1 !== null && $extra1['version'] == 3) {
if ($extra1 !== null && $extra1['version'] == 3) {
$carry[$item['identifier']] = $item['identifier'];
}
return $carry;
},
[]

View File

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

View File

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

View File

@ -910,3 +910,13 @@ define('DEMO_PLUGIN', 9);
// Export resources.
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.
*
* @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 array $wmi_credentials WMI Credentials to use in recon task.
* @param array $rcmd_credentials RCMD 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.
*
* @return interger Module id.
*/
@ -484,7 +484,7 @@ function create_net_scan($ip_target, $snmp_version, $snmp_communities, $wmi_cred
global $config;
include_once $config['homedir'].'/godmode/wizards/HostDevices.class.php';
include_once $config['homedir'].'/include/functions_groups.php';
$group_name = 'AutoDiscovery';
$id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($group_name));
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('Windows System'),
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
WHERE name IN ('.implode(',', array_map(function($template) {
return "'" . $template . "'";
}, $default_templates)).')
ORDER BY name');
WHERE name IN ('.implode(
',',
array_map(
function ($template) {
return "'".$template."'";
},
$default_templates
)
).')
ORDER BY name'
);
$id_base = 'autoDiscovery-WMI-';
$id = 0;
foreach($wmi_credentials as $wmi) {
foreach ($wmi_credentials as $wmi) {
$id++;
$identifier = $id_base . $id;
while(db_get_value_sql(
$identifier = $id_base.$id;
while (db_get_value_sql(
sprintf(
'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"',
$identifier
)
) > 0) {
$id++;
$identifier = $id_base . $id;
$identifier = $id_base.$id;
}
$storeKey = db_process_sql_insert('tcredential_store', [
'identifier' => $identifier,
'id_group' => $id_group,
'product' => 'WMI',
'username' => $wmi['credential']['user'],
'password' => $wmi['credential']['pass'],
'extra_1' => $wmi['credential']['namespace']
]);
$storeKey = db_process_sql_insert(
'tcredential_store',
[
'identifier' => $identifier,
'id_group' => $id_group,
'product' => 'WMI',
'username' => $wmi['credential']['user'],
'password' => $wmi['credential']['pass'],
'extra_1' => $wmi['credential']['namespace'],
]
);
if($storeKey !== false) {
if ($storeKey !== false) {
$auth_strings[] = $identifier;
}
}
$id_base = 'autoDiscovery-RCMD-';
$id = 0;
foreach($rcmd_credentials as $rcmd) {
foreach ($rcmd_credentials as $rcmd) {
$id++;
$identifier = $id_base . $id;
while(db_get_value_sql(
$identifier = $id_base.$id;
while (db_get_value_sql(
sprintf(
'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"',
$identifier
)
) > 0) {
$id++;
$identifier = $id_base . $id;
$identifier = $id_base.$id;
}
$storeKey = db_process_sql_insert('tcredential_store', [
'identifier' => $identifier,
'id_group' => $id_group,
'product' => 'CUSTOM',
'username' => $rcmd['credential']['user'],
'password' => $rcmd['credential']['pass']
]);
$storeKey = db_process_sql_insert(
'tcredential_store',
[
'identifier' => $identifier,
'id_group' => $id_group,
'product' => 'CUSTOM',
'username' => $rcmd['credential']['user'],
'password' => $rcmd['credential']['pass'],
]
);
if($storeKey !== false) {
if ($storeKey !== false) {
$auth_strings[] = $identifier;
}
}
$HostDevices = new HostDevices(1);
$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) {
$result = array_values(array_reduce(
$cells,
function ($carry, $item) {
$carry[$item['order']]['id'] = $item['id'];
$carry[$item['order']]['position'] = $item['position'];
$carry[$item['order']]['widgetId'] = $item['id_widget'];
$result = array_values(
array_reduce(
$cells,
function ($carry, $item) {
$carry[$item['order']]['id'] = $item['id'];
$carry[$item['order']]['position'] = $item['position'];
$carry[$item['order']]['widgetId'] = $item['id_widget'];
return $carry;
},
[]
));
return $carry;
},
[]
)
);
}
echo json_encode($result);