implemented custom field

This commit is contained in:
alejandro.campos@artica.es 2022-11-16 10:28:50 +01:00
parent 2e7d5aa336
commit 5e510e7e12
6 changed files with 110 additions and 4 deletions

View File

@ -0,0 +1,7 @@
START TRANSACTION;
ALTER TABLE `tagent_custom_fields` ADD `is_link_enabled` TINYINT(1) NOT NULL DEFAULT 0;
ALTER TABLE `tagent_custom_fields` ADD COLUMN `link_text` VARCHAR(500) NOT NULL DEFAULT '';
ALTER TABLE `tagent_custom_fields` ADD COLUMN `link_url` VARCHAR(2048) NOT NULL DEFAULT '';
COMMIT;

View File

@ -872,6 +872,14 @@ foreach ($fields as $field) {
true,
true
);
} else if ($field['is_link_enabled']) {
$link_text = $field['link_text'];
if ($field['link_text'] === '') {
$link_text = $field['link_url'];
}
$data_field[1] = '<a href="'.$field['link_url'].'">'.$link_text.'</a>';
} else {
$data_field[1] = html_print_textarea(
'customvalue_'.$field['id_field'],

View File

@ -30,6 +30,10 @@ $display_on_front = (bool) get_parameter('display_on_front', 0);
$is_password_type = (bool) get_parameter('is_password_type', 0);
$is_combo_enable = (bool) get_parameter('is_combo_enable', 0);
$combo_values = (string) get_parameter('combo_values', '');
$is_link_enabled = (bool) get_parameter('is_link_enabled', 0);
$link_text = (string) get_parameter('link_text', '');
$link_url = (string) get_parameter('link_url', '');
// Header.
if ($id_field) {
$field = db_get_row_filter('tagent_custom_fields', ['id_field' => $id_field]);
@ -38,6 +42,9 @@ if ($id_field) {
$is_password_type = $field['is_password_type'];
$combo_values = $field['combo_values'] ? $field['combo_values'] : '';
$is_combo_enable = $config['is_combo_enable'];
$is_link_enabled = $field['is_link_enabled'];
$link_text = $field['link_text'];
$link_url = $field['link_url'];
ui_print_page_header(__('Update agent custom field'), 'images/custom_field.png', false, '', true, '');
} else {
ui_print_page_header(__('Create agent custom field'), 'images/custom_field.png', false, '', true, '');
@ -128,6 +135,39 @@ $table->data[4][1] = html_print_textarea(
true
);
$table->data[5][0] = __('Link type');
$table->data[5][1] = html_print_checkbox_switch_extended(
'is_link_enabled',
1,
$is_link_enabled,
false,
'',
'',
true
);
$table->rowstyle[6] = 'display: none;';
$table->data[6][0] = __('Link text');
$table->data[6][1] = html_print_textarea(
'link_text',
3,
65,
io_safe_output($link_text),
'',
true
);
$table->rowstyle[7] = 'display: none;';
$table->data[7][0] = __('Link URL');
$table->data[7][1] = html_print_textarea(
'link_url',
3,
65,
io_safe_output($link_url),
'',
true
);
echo '<form name="field" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/fields_manager">';
html_print_table($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
@ -167,7 +207,35 @@ $(document).ready (function () {
});
}
if ($('input[type=checkbox][name=is_link_enabled]').is(":checked") === true) {
$('#configure_field-6').show();
$('#configure_field-7').show();
$('#configure_field-1').hide();
$('#configure_field-3').hide();
} else {
$('#configure_field-6').hide();
$('#configure_field-7').hide();
$('#configure_field-1').show();
$('#configure_field-3').show();
}
// if ( $('input[type=checkbox][name=is_link_enabled]').val() === 1) {
//}
$('input[type=checkbox][name=is_link_enabled]').change(function () {
if( $(this).is(":checked") ){
$('#configure_field-6').show();
$('#configure_field-7').show();
$('#configure_field-1').hide();
$('#configure_field-3').hide();
} else{
$('#configure_field-6').hide();
$('#configure_field-7').hide();
$('#configure_field-1').show();
$('#configure_field-3').show();
}
});
$('input[type=checkbox][name=is_combo_enable]').change(function () {
if( $(this).is(":checked") ){
$('#configure_field-4').show();

View File

@ -38,14 +38,26 @@ $display_on_front = (int) get_parameter('display_on_front', 0);
$is_password_type = (int) get_parameter('is_password_type', 0);
$combo_values = (string) get_parameter('combo_values', '');
$combo_value_selected = (string) get_parameter('combo_value_selected', '');
$is_link_enabled = (bool) get_parameter('is_link_enabled', 0);
$link_text = (string) get_parameter('link_text', '');
$link_url = (string) get_parameter('link_url', '');
if ($is_link_enabled === true && $link_url !== '') {
$parsed_url = parse_url($link_url);
if (empty($parsed_url['scheme']) === true) {
$link_url = 'http://'.ltrim($link_url, '/');
}
}
// Create field.
if ($create_field) {
// Check if name field is empty.
if ($name == '') {
if ($name === '') {
ui_print_error_message(__('The name must not be empty'));
} else if ($name == db_get_value('name', 'tagent_custom_fields', 'name', $name)) {
ui_print_error_message(__('The name must be unique'));
} else if ($is_link_enabled === true && $link_url === '') {
ui_print_error_message(__('The link URL must not be empty'));
} else {
$result = db_process_sql_insert(
'tagent_custom_fields',
@ -54,6 +66,9 @@ if ($create_field) {
'display_on_front' => $display_on_front,
'is_password_type' => $is_password_type,
'combo_values' => $combo_values,
'is_link_enabled' => $is_link_enabled,
'link_text' => $link_text,
'link_url' => $link_url,
]
);
ui_print_success_message(__('Field successfully created'));
@ -63,12 +78,17 @@ if ($create_field) {
// Update field.
if ($update_field) {
// Check if name field is empty.
if ($name != '') {
if ($name !== ''
&& ($is_link_enabled === false || ($is_link_enabled === true && $link_url !== ''))
) {
$values = [
'name' => $name,
'display_on_front' => $display_on_front,
'is_password_type' => $is_password_type,
'combo_values' => $combo_values,
'is_link_enabled' => $is_link_enabled,
'link_text' => $link_text,
'link_url' => $link_url,
];
$result = db_process_sql_update('tagent_custom_fields', $values, ['id_field' => $id_field]);

View File

@ -2103,6 +2103,9 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields` (
`display_on_front` TINYINT NOT NULL DEFAULT 0,
`is_password_type` TINYINT NOT NULL DEFAULT 0,
`combo_values` TEXT ,
`is_link_enabled` TINYINT(1) NOT NULL DEFAULT 0,
`link_text` VARCHAR(500) NOT NULL DEFAULT '',
`link_url` VARCHAR(2048) NOT NULL DEFAULT '',
PRIMARY KEY (`id_field`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;

View File

@ -1189,7 +1189,7 @@ INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `execute`, `p
INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`, `no_delete`) VALUES (9,'Packet&#x20;Loss','Checks&#x20;for&#x20;dropped&#x20;packages&#x20;after&#x20;X&#x20;seconds&#x20;of&#x20;testing.&#x20;It&#x20;returns&#x20;%&#x20;of&#x20;dropped&#x20;packets.&#x20;It&#x20;uses&#x20;ping&#x20;flood&#x20;mode&#x20;to&#x20;launch&#x20;50&#x20;consecutive&#x20;pings&#x20;to&#x20;a&#x20;remote&#x20;destination.&#x20;On&#x20;local,&#x20;stable&#x20;networks,&#x20;value&#x20;should&#x20;be&#x20;0.&#x0d;&#x0a;',30,0,'/usr/share/pandora_server/util/plugin/packet_loss.sh','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"Test&#x20;time\",\"help\":\"\",\"value\":\"8\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Target&#x20;IP\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','_field1_&#x20;_field2_', 1);
INSERT INTO `tagent_custom_fields` VALUES (1,'Serial&#x20;Number',0,0,''),(2,'Department',0,0,''),(3,'Additional&#x20;ID',0,0,''),(4,'eHorusID',0,0,'');
INSERT INTO `tagent_custom_fields` VALUES (1,'Serial&#x20;Number',0,0,'',0,'',''),(2,'Department',0,0,'',0,'',''),(3,'Additional&#x20;ID',0,0,'',0,'',''),(4,'eHorusID',0,0,'',0,'','');
INSERT INTO `ttag` VALUES (1,'network','Network&#x20;equipment','http://artica.es','','',''),(2,'critical','Critical&#x20;modules','','','',''),(3,'dmz','DMZ&#x20;Network&#x20;Zone','','','',''),(4,'performance','Performance&#x20;anda&#x20;capacity&#x20;modules','','','',''),(5,'configuration','','','','','');