#4043 added wizard snmp

This commit is contained in:
Daniel Maya 2022-10-10 13:27:19 +02:00
parent 7f220eae19
commit bf0d7ff687
3 changed files with 212 additions and 72 deletions

View File

@ -140,6 +140,49 @@ if ($id_module_type >= 6 && $id_module_type <= 7) {
push_table_simple($data, 'target_ip');
$user_groups = users_get_groups(false, 'AR');
if (users_is_admin() === true || isset($user_groups[0]) === true) {
$credentials = db_get_all_rows_sql(
'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP"'
);
} else {
$credentials = db_get_all_rows_sql(
sprintf(
'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP" AND id_group IN (%s)',
implode(',', array_keys($user_groups))
)
);
}
if (empty($credentials) === false) {
$fields = [];
foreach ($credentials as $key => $value) {
$fields[$value['identifier']] = $value['identifier'];
}
$data = [];
$data[0] = __('Credential store');
$data[1] = html_print_select(
$fields,
'credentials',
0,
'',
__('None'),
0,
true,
false,
false,
'',
false,
false,
'',
false
);
push_table_simple($data, 'snmp_credentials');
}
$snmp_versions['1'] = 'v. 1';
$snmp_versions['2'] = 'v. 2';
$snmp_versions['2c'] = 'v. 2c';
@ -316,6 +359,7 @@ if ($id_module_type < 15 || $id_module_type > 18) {
// NOT SNMP.
$table_simple->rowstyle['snmp_1'] = 'display: none';
$table_simple->rowstyle['snmp_2'] = 'display: none';
$table_simple->rowstyle['snmp_credentials'] = 'display: none';
}
// For a policy.
@ -569,6 +613,49 @@ $(document).ready (function () {
$(this).css ("width", "180px");
});
$("#credentials").change (function() {
if ($('#credentials').val() !== '0') {
$.ajax({
method: "post",
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
data: {
page: "godmode/agentes/agent_wizard",
method: "getCredentials",
identifier: $('#credentials').val()
},
datatype: "json",
success: function(data) {
data = JSON.parse(data);
extra = JSON.parse(data['extra_1']);
$('#snmp_version').val(extra['version']);
$('#snmp_version').trigger('change');
$('#text-snmp_community').val(extra['community']);
if (extra['version'] === '3') {
$('#snmp3_security_level').val(extra['securityLevelV3']);
$('#snmp3_security_level').trigger('change');
$('#text-snmp3_auth_user').val(extra['authUserV3']);
if (extra['securityLevelV3'] === 'authNoPriv' || extra['securityLevelV3'] === 'authPriv') {
$('#snmp3_auth_method').val(extra['authMethodV3']);
$('#snmp3_auth_method').trigger('change');
$('#password-snmp3_auth_pass').val(extra['authPassV3']);
if (extra['securityLevelV3'] === 'authPriv') {
$('#snmp3_privacy_method').val(extra['privacyMethodV3']);
$('#snmp3_privacy_method').trigger('change');
$('#password-snmp3_privacy_pass').val(extra['privacyPassV3']);
}
}
}
},
error: function(e) {
console.error(e);
}
});
}
});
$("#id_module_type").click (
function () {
$(this).css ("width", "auto");

View File

@ -33,6 +33,7 @@ global $config;
require_once $config['homedir'].'/include/class/HTML.class.php';
require_once $config['homedir'].'/include/functions_snmp_browser.php';
require_once $config['homedir'].'/include/functions_wmi.php';
require_once $config['homedir'].'/include/class/CredentialStore.class.php';
use PandoraFMS\Module;
@ -704,39 +705,24 @@ class AgentWizard extends HTML
}
if (empty($credentials) === false) {
$test = [];
$fields = [];
foreach ($credentials as $key => $value) {
$test[$value['identifier']] = $value['identifier'];
$fields[$value['identifier']] = $value['identifier'];
}
$inputs[] = [
'direct' => 1,
'block_content' => [
[
'label' => __('Credential store'),
'id' => 'slc-credential',
'arguments' => [
'name' => 'credential',
'input_class' => 'flex-row',
'type' => 'select',
'nothing' => __('None'),
'nothing_value' => 0,
'fields' => $test,
'class' => '',
'return' => true,
'sort' => true,
],
],
[
'arguments' => [
'label' => __('Apply'),
'name' => 'btn-credential',
'id' => 'btn-credential',
'type' => 'button',
'attributes' => 'class="sub next" onclick="" style="margin-left: 20px;padding-top: 3px;padding-bottom: 3px;background-position: 92% 6px;"',
'return' => true,
],
],
'label' => __('Credential store'),
'id' => 'slc-credential',
'arguments' => [
'name' => 'credential',
'input_class' => 'flex-row',
'type' => 'select',
'nothing' => __('None'),
'nothing_value' => 0,
'fields' => $fields,
'class' => '',
'return' => true,
'sort' => true,
],
];
}
@ -760,6 +746,43 @@ class AgentWizard extends HTML
];
if ($this->actionType === 'snmp') {
$user_groups = users_get_groups(false, 'AR');
if (users_is_admin() === true || isset($user_groups[0]) === true) {
$credentials = db_get_all_rows_sql(
'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP"'
);
} else {
$credentials = db_get_all_rows_sql(
sprintf(
'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP" AND id_group IN (%s)',
implode(',', array_keys($user_groups))
)
);
}
if (empty($credentials) === false) {
$fields = [];
foreach ($credentials as $key => $value) {
$fields[$value['identifier']] = $value['identifier'];
}
$inputs[] = [
'label' => __('Credential store'),
'id' => 'slc-credential',
'arguments' => [
'name' => 'credential',
'input_class' => 'flex-row',
'type' => 'select',
'nothing' => __('None'),
'nothing_value' => 0,
'fields' => $fields,
'class' => '',
'return' => true,
'sort' => true,
],
];
}
$inputs[] = [
'label' => __('SNMP community'),
'id' => 'txt-community',
@ -796,22 +819,6 @@ class AgentWizard extends HTML
'return' => true,
],
];
$user_groups = users_get_groups(false, 'AR');
if (users_is_admin() === true || isset($user_groups[0]) === true) {
$credentials = db_get_all_rows_sql(
'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP"'
);
} else {
$credentials = db_get_all_rows_sql(
sprintf(
'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP" AND id_group IN (%s)',
implode(',', array_keys($user_groups))
)
);
}
hd($credentials);
}
$inputs[] = [
@ -1396,6 +1403,21 @@ class AgentWizard extends HTML
}
/**
* Build an array with Product credentials.
*
* @return array with credentials (pass and id).
*/
public function getCredentials(string $identifier='')
{
if (empty($identifier) === true) {
$identifier = get_parameter('identifier', '');
}
echo json_encode(credentialStore::getKey($identifier));
}
/**
* Prepare data module to create.
*
@ -5873,31 +5895,56 @@ class AgentWizard extends HTML
filterInterfaces();
});
$('#button-btn-credential').click(function() {
$('#credential').change(function() {
if ($('#credential').val() !== '0') {
alert('jejeje si');
$.ajax({
method: "post",
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
data: {
page: "<?php echo $this->ajaxController; ?>",
method: "getCredentials",
identifier: $('#credential').val()
},
datatype: "json",
success: function(data) {
data = JSON.parse(data);
if ($('#text-namespaceWMI').length > 0) {
// WMI.
$('#text-namespaceWMI').val(data['extra_1']);
$('#text-usernameWMI').val(data['username']);
$('#password-passwordWMI').val(data['password']);
} else {
// SNMP.
extra = JSON.parse(data['extra_1']);
$('#version').val(extra['version']);
$('#version').trigger('change');
$('#text-community').val(extra['community']);
if (extra['version'] === '3') {
$('#securityLevelV3').val(extra['securityLevelV3']);
$('#securityLevelV3').trigger('change');
$('#text-authUserV3').val(extra['authUserV3']);
if (extra['securityLevelV3'] === 'authNoPriv' || extra['securityLevelV3'] === 'authPriv') {
$('#authMethodV3').val(extra['authMethodV3']);
$('#authMethodV3').trigger('change');
$('#password-authPassV3').val(extra['authPassV3']);
if (extra['securityLevelV3'] === 'authPriv') {
$('#privacyMethodV3').val(extra['privacyMethodV3']);
$('#privacyMethodV3').trigger('change');
$('#password-privacyPassV3').val(extra['privacyPassV3']);
}
}
}
}
},
error: function(e) {
showMsg(e);
}
});
}
// $.ajax({
// method: "post",
// url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
// data: {
// page: "<?php echo $this->ajaxController; ?>",
// method: "listModulesToCreate",
// data: JSON.stringify(datas),
// id_agente: "<?php echo $this->idAgent; ?>",
// id: "<?php echo $this->idPolicy; ?>"
// },
// datatype: "html",
// success: function(data) {
// // Show hidden OK button
// $('.sub.ok.submit-next').removeClass('invisible_important');
// $('#' + id).empty().append(data);
// },
// error: function(e) {
// showMsg(e);
// }
// });
});
// Loading.

View File

@ -13,20 +13,26 @@ function configure_modules_form() {
$("#id_module_type").change(function() {
if (id_modules_icmp.in_array(this.value)) {
$(
"tr#simple-snmp_1, tr#simple-snmp_2, tr#simple-tcp_send, tr#simple-tcp_receive"
"tr#simple-snmp_1, tr#simple-snmp_2, tr#simple-snmp_credentials, tr#simple-tcp_send, tr#simple-tcp_receive"
).hide();
$("#text-tcp_port").attr("disabled", "1");
} else if (id_modules_snmp.in_array(this.value)) {
$("tr#simple-snmp_1, tr#simple-snmp_2").show();
$(
"tr#simple-snmp_1, tr#simple-snmp_2, tr#simple-snmp_credentials"
).show();
$("tr#simple-tcp_send, tr#simple-tcp_receive").hide();
$("#text-tcp_port").removeAttr("disabled");
} else if (id_modules_tcp.in_array(this.value)) {
$("tr#simple-snmp_1, tr#simple-snmp_2").hide();
$(
"tr#simple-snmp_1, tr#simple-snmp_2, tr#simple-snmp_credentials"
).hide();
$("tr#simple-tcp_send, tr#simple-tcp_receive").show();
$("#text-tcp_port").removeAttr("disabled");
} else if (id_modules_exec.in_array(this.value)) {
$("tr#simple-tcp_send, tr#simple-tcp_receive").hide();
$("tr#simple-snmp_1, tr#simple-snmp_2").hide();
$(
"tr#simple-snmp_1, tr#simple-snmp_2, tr#simple-snmp_credentials"
).hide();
$("#text-tcp_port").attr("disabled", false);
}
});