2012-02-06 12:05:35 +01:00
< ? php
2021-11-04 16:28:15 +01:00
// Pandora FMS - http://pandorafms.com
2012-02-06 12:05:35 +01:00
// ==================================================
2020-11-27 13:52:35 +01:00
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
2012-02-06 12:05:35 +01:00
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
global $config ;
2019-01-30 16:18:44 +01:00
check_login ();
2012-02-06 12:05:35 +01:00
2019-01-30 16:18:44 +01:00
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'PM' )) {
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2019-01-30 16:18:44 +01:00
'Trying to access Custom events Management'
);
include 'general/noaccess.php' ;
return ;
2012-02-06 12:05:35 +01:00
}
2012-02-09 13:39:11 +01:00
$update = get_parameter ( 'upd_button' , '' );
$default = ( int ) get_parameter ( 'default' , 0 );
2012-02-07 19:11:12 +01:00
2015-04-10 00:58:24 +02:00
2012-02-09 13:39:11 +01:00
if ( $default != 0 ) {
2019-01-30 16:18:44 +01:00
// $event_fields = io_safe_input('evento,id_agente,estado,timestamp');
$fields_selected = explode ( ',' , $config [ 'event_fields' ]);
} else if ( $update != '' ) {
$fields_selected = ( array ) get_parameter ( 'fields_selected' );
if ( $fields_selected [ 0 ] == '' ) {
// $event_fields = io_safe_input('evento,id_agente,estado,timestamp');
$fields_selected = explode ( ',' , $config [ 'event_fields' ]);
} else {
$event_fields = implode ( ',' , $fields_selected );
}
$values = [
'token' => 'event_fields' ,
'value' => $event_fields ,
];
2022-06-08 13:24:27 +02:00
// Update 'event_fields' in tconfig table to keep the value at update.
2019-01-30 16:18:44 +01:00
$result = db_process_sql_update (
'tconfig' ,
$values ,
[ 'token' => 'event_fields' ]
);
$config [ 'event_fields' ] = $event_fields ;
2012-02-07 19:11:12 +01:00
}
2019-01-30 16:18:44 +01:00
$fields_selected = [];
2015-03-23 15:42:12 +01:00
$event_fields = '' ;
2019-01-30 16:18:44 +01:00
$fields_selected = explode ( ',' , $config [ 'event_fields' ]);
$result_selected = [];
2019-06-10 15:18:35 +02:00
// Show list of fields selected.
2019-01-30 16:18:44 +01:00
if ( $fields_selected [ 0 ] != '' ) {
foreach ( $fields_selected as $field_selected ) {
2019-06-10 15:18:35 +02:00
$result_selected [ $field_selected ] = events_get_column_name (
$field_selected
);
2019-01-30 16:18:44 +01:00
}
2012-02-07 19:11:12 +01:00
}
2019-01-30 16:18:44 +01:00
$event = [];
2012-02-06 12:05:35 +01:00
2012-02-09 13:39:11 +01:00
echo '<h3>' . __ ( 'Show event fields' );
echo ' <a href="index.php?sec=geventos&sec2=godmode/events/events§ion=fields&default=1">' ;
2019-01-30 16:18:44 +01:00
html_print_image ( 'images/clean.png' , false , [ 'title' => __ ( 'Load the fields from previous events' ), 'onclick' => " if (! confirm (' " . __ ( 'Event fields will be loaded. Do you want to continue?' ) . " ')) return false " ]);
2012-02-09 13:39:11 +01:00
echo '</a></h3>' ;
2012-02-08 18:21:16 +01:00
2015-06-25 10:07:53 +02:00
$table = new stdClass ();
2015-06-16 16:09:50 +02:00
$table -> width = '100%' ;
$table -> class = 'databox filters' ;
2012-02-06 12:05:35 +01:00
2019-01-30 16:18:44 +01:00
$table -> size = [];
2012-10-09 18:05:32 +02:00
$table -> size [ 1 ] = '10px' ;
$table -> style [ 0 ] = 'text-align:center;' ;
$table -> style [ 2 ] = 'text-align:center;' ;
2012-02-06 12:05:35 +01:00
2019-01-30 16:18:44 +01:00
$table -> data = [];
2012-02-06 12:05:35 +01:00
2019-01-30 16:18:44 +01:00
$fields_available = [];
2012-02-08 18:21:16 +01:00
2018-07-26 15:41:52 +02:00
$fields_available [ 'id_evento' ] = __ ( 'Event Id' );
$fields_available [ 'evento' ] = __ ( 'Event Name' );
2019-06-10 15:18:35 +02:00
$fields_available [ 'id_agente' ] = __ ( 'Agent ID' );
$fields_available [ 'agent_name' ] = __ ( 'Agent Name' );
2021-07-07 16:07:08 +02:00
$fields_available [ 'direccion' ] = __ ( 'Agent IP' );
2012-02-08 18:21:16 +01:00
$fields_available [ 'id_usuario' ] = __ ( 'User' );
$fields_available [ 'id_grupo' ] = __ ( 'Group' );
$fields_available [ 'estado' ] = __ ( 'Status' );
$fields_available [ 'timestamp' ] = __ ( 'Timestamp' );
2018-07-26 15:41:52 +02:00
$fields_available [ 'event_type' ] = __ ( 'Event Type' );
$fields_available [ 'id_agentmodule' ] = __ ( 'Module Name' );
2012-02-08 18:21:16 +01:00
$fields_available [ 'id_alert_am' ] = __ ( 'Alert' );
2015-09-14 14:07:21 +02:00
$fields_available [ 'criticity' ] = __ ( 'Severity' );
2012-02-08 18:21:16 +01:00
$fields_available [ 'user_comment' ] = __ ( 'Comment' );
$fields_available [ 'tags' ] = __ ( 'Tags' );
$fields_available [ 'source' ] = __ ( 'Source' );
2018-07-26 15:41:52 +02:00
$fields_available [ 'id_extra' ] = __ ( 'Extra Id' );
2012-10-09 18:05:32 +02:00
$fields_available [ 'owner_user' ] = __ ( 'Owner' );
$fields_available [ 'ack_utimestamp' ] = __ ( 'ACK Timestamp' );
2013-03-06 18:53:17 +01:00
$fields_available [ 'instructions' ] = __ ( 'Instructions' );
2018-07-26 15:41:52 +02:00
$fields_available [ 'server_name' ] = __ ( 'Server Name' );
2018-07-19 18:04:50 +02:00
$fields_available [ 'data' ] = __ ( 'Data' );
2018-07-26 15:41:52 +02:00
$fields_available [ 'module_status' ] = __ ( 'Module Status' );
2019-06-24 19:23:41 +02:00
$fields_available [ 'mini_severity' ] = __ ( 'Severity mini' );
2020-09-17 16:51:23 +02:00
$fields_available [ 'module_custom_id' ] = __ ( 'Module custom ID' );
2022-03-29 18:09:19 +02:00
$fields_available [ 'custom_data' ] = __ ( 'Custom data' );
2019-06-24 19:23:41 +02:00
2012-02-08 18:21:16 +01:00
2019-06-18 16:07:53 +02:00
// Remove fields already selected.
2019-01-30 16:18:44 +01:00
foreach ( $fields_available as $key => $available ) {
2019-06-18 16:07:53 +02:00
if ( isset ( $result_selected [ $key ])) {
unset ( $fields_available [ $key ]);
2019-01-30 16:18:44 +01:00
}
2012-02-07 19:11:12 +01:00
}
2012-02-06 12:05:35 +01:00
2019-01-30 16:18:44 +01:00
$table -> data [ 0 ][ 0 ] = '<b>' . __ ( 'Fields available' ) . '</b>' ;
$table -> data [ 1 ][ 0 ] = html_print_select ( $fields_available , 'fields_available[]' , true , '' , '' , 0 , true , true , false , '' , false , 'width: 300px' );
$table -> data [ 1 ][ 1 ] = '<a href="javascript:">' . html_print_image (
2023-02-27 09:57:17 +01:00
'images/arrow@svg.svg' ,
2019-01-30 16:18:44 +01:00
true ,
[
'id' => 'right' ,
'title' => __ ( 'Add fields to select' ),
2023-03-16 16:48:03 +01:00
'style' => 'rotate: 180deg;' ,
2023-03-17 08:53:58 +01:00
'class' => 'main_menu_icon invert_filter' ,
2019-01-30 16:18:44 +01:00
]
) . '</a>' ;
$table -> data [ 1 ][ 1 ] .= '<br><br><br><br><a href="javascript:">' . html_print_image (
2023-02-27 09:57:17 +01:00
'images/arrow@svg.svg' ,
2019-01-30 16:18:44 +01:00
true ,
[
'id' => 'left' ,
'title' => __ ( 'Delete fields to select' ),
2023-03-16 16:48:03 +01:00
'style' => '' ,
2019-01-30 16:18:44 +01:00
]
) . '</a>' ;
2012-07-26 Miguel de Dios <miguel.dedios@artica.es>
* operation/users/user_edit.php,
operation/events/events_validate.php, operation/search_graphs.php,
godmode/events/event_filter.php, godmode/events/custom_events.php,
godmode/massive/massive_standby_alerts.php,
godmode/massive/massive_copy_modules.php, godmode/tag/tag.php,
godmode/netflow/nf_report.php, godmode/agentes/configure_field.php,
godmode/agentes/agent_manager.php,
godmode/agentes/agent_template.php,
godmode/agentes/fields_manager.php,
godmode/servers/recon_script.php, godmode/servers/plugin.php,
include/functions_modules.php: improved the source structure.
* operation/search_modules.php: fixed the search when the modules
haven't inicialiced.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6814 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-26 13:05:05 +02:00
2012-10-09 18:05:32 +02:00
$table -> data [ 0 ][ 1 ] = '' ;
2019-01-30 16:18:44 +01:00
$table -> data [ 0 ][ 2 ] = '<b>' . __ ( 'Fields selected' ) . '</b>' ;
2022-06-08 13:24:27 +02:00
$table -> data [ 1 ][ 2 ] = '<div class="flex_justify">' . html_print_select (
2019-01-30 16:18:44 +01:00
$result_selected ,
'fields_selected[]' ,
true ,
'' ,
'' ,
0 ,
true ,
true ,
false ,
'' ,
false ,
'width: 300px'
);
2012-02-06 12:05:35 +01:00
2022-06-08 13:24:27 +02:00
$table -> data [ 1 ][ 2 ] .= '<div id="sort_arrows" class="flex-column">' ;
$table -> data [ 1 ][ 2 ] .= '<a href="javascript:">' . html_print_image (
'images/darrowup.png' ,
true ,
[
'onclick' => 'sortUpDown(\'up\');' ,
2022-06-08 13:29:43 +02:00
'title' => __ ( 'Move up selected fields' ),
2023-03-17 08:53:58 +01:00
'class' => 'main_menu_icon invert_filter' ,
2022-06-08 13:24:27 +02:00
]
) . '</a>' ;
$table -> data [ 1 ][ 2 ] .= '<a href="javascript:">' . html_print_image (
'images/darrowdown.png' ,
true ,
[
'onclick' => 'sortUpDown(\'down\');' ,
2022-06-08 13:29:43 +02:00
'title' => __ ( 'Move down selected fields' ),
2023-03-17 08:53:58 +01:00
'class' => 'main_menu_icon invert_filter' ,
2022-06-08 13:24:27 +02:00
]
) . '</a>' ;
$table -> data [ 1 ][ 2 ] .= '</div></div>' ;
2012-12-20 19:00:00 +01:00
echo '<form id="custom_events" method="post" action="index.php?sec=geventos&sec2=godmode/events/events§ion=fields&pure=' . $config [ 'pure' ] . '">' ;
2012-02-06 12:05:35 +01:00
html_print_table ( $table );
2022-11-23 13:41:38 +01:00
html_print_action_buttons (
html_print_submit_button (
__ ( 'Update' ),
'upd_button' ,
false ,
[ 'icon' => 'update' ],
true
),
[ 'type' => 'form_action' ]
);
2012-02-08 18:56:32 +01:00
echo '</form>' ;
2012-02-06 12:05:35 +01:00
?>
2012-02-07 19:11:12 +01:00
< script type = " text/javascript " >
/* <![CDATA[ */
$ ( document ) . ready ( function () {
2022-06-08 13:24:27 +02:00
2019-01-30 16:18:44 +01:00
$ ( " #right " ) . click ( function () {
jQuery . each ( $ ( " select[name='fields_available[]'] option:selected " ), function ( key , value ) {
field_name = $ ( value ) . html ();
if ( field_name != < ? php echo " ' " . __ ( 'None' ) . " ' " ; ?> ) {
id_field = $ ( value ) . attr ( 'value' );
$ ( " select[name='fields_selected[]'] " ) . append ( $ ( " <option></option> " ) . html ( field_name ) . attr ( " value " , id_field ));
$ ( " #fields_available " ) . find ( " option[value=' " + id_field + " '] " ) . remove ();
$ ( " #fields_selected " ) . find ( " option[value='0'] " ) . remove ();
}
});
});
2022-06-08 13:24:27 +02:00
2019-01-30 16:18:44 +01:00
$ ( " #left " ) . click ( function () {
2022-06-08 13:24:27 +02:00
var current_fields_size = ( $ ( '#fields_selected option' ) . length );
2019-01-30 16:18:44 +01:00
var selected_fields = [];
var selected_fields_total = '' ;
jQuery . each ( $ ( " select[name='fields_selected[]'] option:selected " ), function ( key , value ) {
field_name = $ ( value ) . html ();
selected_fields . push ( field_name );
selected_fields_total = selected_fields . length ;
});
if ( selected_fields_total === current_fields_size ){
display_confirm_dialog (
2021-03-11 15:40:23 +01:00
" <?php echo '<span class=transform_none font_9pt>'.__('There must be at least one custom field. Timestamp will be set by default').'</span>'; ?> " ,
2019-01-30 16:18:44 +01:00
" <?php echo __('Confirm'); ?> " ,
" <?php echo __('Cancel'); ?> " ,
function () {
move_left ();
$ ( " #fields_available " ) . find ( " option[value='timestamp'] " ) . remove ();
$ ( " select[name='fields_selected[]'] " ) . append ( $ ( " <option></option> " ) . val ( 'timestamp' ) . html ( '<i>' + 'Timestamp' + '</i>' ));
}
);
}
else {
move_left ();
}
});
2022-06-08 13:24:27 +02:00
2022-11-23 13:41:38 +01:00
$ ( " #button-upd_button " ) . click ( function () {
2019-01-30 16:18:44 +01:00
$ ( " #fields_selected " ) . find ( " option[value='0'] " ) . remove ();
$ ( '#fields_selected option' ) . map ( function () {
$ ( this ) . prop ( 'selected' , true );
});
});
2012-02-07 19:11:12 +01:00
});
2018-10-23 12:44:14 +02:00
2022-06-08 13:24:27 +02:00
function move_left () {
2019-01-30 16:18:44 +01:00
jQuery . each ( $ ( " select[name='fields_selected[]'] option:selected " ), function ( key , value ) {
field_name = $ ( value ) . html ();
if ( field_name != < ? php echo " ' " . __ ( 'None' ) . " ' " ; ?> ) {
id_field = $ ( value ) . attr ( 'value' );
$ ( " select[name='fields_available[]'] " ) . append ( $ ( " <option></option> " ) . val ( id_field ) . html ( '<i>' + field_name + '</i>' ));
$ ( " #fields_selected " ) . find ( " option[value=' " + id_field + " '] " ) . remove ();
$ ( " #fields_available " ) . find ( " option[value='0'] " ) . remove ();
}
});
2018-10-23 12:44:14 +02:00
}
2022-06-08 13:24:27 +02:00
// Change the order (to up or down).
function sortUpDown ( mode ) {
$ ( " #fields_selected option:selected " ) . each ( function () {
const field = $ ( this );
if ( field . length ) {
( mode === 'up' ) ? field . first () . prev () . before ( field ) : field . last () . next () . after ( field );
}
});
}
2012-10-09 18:05:32 +02:00
</ script >