2010-08-25 14:04:42 +02:00
< ? php
2023-02-21 14:14:13 +01:00
/**
* Fields manager .
*
* @ category Resources .
* @ package Pandora FMS
* @ subpackage Community
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2023-06-08 11:53:13 +02:00
* Copyright ( c ) 2005 - 2023 Pandora FMS
2023-02-21 14:14:13 +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 for 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 .
* ============================================================================
*/
// Load global vars.
2010-08-25 14:04:42 +02:00
global $config ;
check_login ();
2023-02-21 14:14:13 +01:00
if (( bool ) check_acl ( $config [ 'id_user' ], 0 , 'PM' ) === false ) {
2019-01-30 16:18:44 +01:00
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 Group Management'
);
include 'general/noaccess.php' ;
return ;
2010-08-25 14:04:42 +02:00
}
2019-03-07 13:37:36 +01:00
// Header.
2023-02-21 14:14:13 +01:00
ui_print_standard_header (
__ ( 'Agents custom fields manager' ),
'images/custom_field.png' ,
false ,
'' ,
true ,
[],
[
[
'link' => '' ,
'label' => __ ( 'Resources' ),
],
[
'link' => '' ,
'label' => __ ( 'Custom fields' ),
],
]
);
2010-08-25 14:04:42 +02:00
2019-01-30 16:18:44 +01:00
$create_field = ( bool ) get_parameter ( 'create_field' );
$update_field = ( bool ) get_parameter ( 'update_field' );
$delete_field = ( bool ) get_parameter ( 'delete_field' );
$id_field = ( int ) get_parameter ( 'id_field' , 0 );
$name = ( string ) get_parameter ( 'name' , '' );
$display_on_front = ( int ) get_parameter ( 'display_on_front' , 0 );
$is_password_type = ( int ) get_parameter ( 'is_password_type' , 0 );
2019-03-07 13:37:36 +01:00
$combo_values = ( string ) get_parameter ( 'combo_values' , '' );
$combo_value_selected = ( string ) get_parameter ( 'combo_value_selected' , '' );
2022-11-16 10:28:50 +01:00
$is_link_enabled = ( bool ) get_parameter ( 'is_link_enabled' , 0 );
2010-08-25 14:04:42 +02:00
2019-03-07 13:37:36 +01:00
// Create field.
2010-08-25 14:04:42 +02:00
if ( $create_field ) {
2019-03-07 13:37:36 +01:00
// Check if name field is empty.
2022-11-16 10:28:50 +01:00
if ( $name === '' ) {
2019-01-30 16:18:44 +01:00
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 {
$result = db_process_sql_insert (
'tagent_custom_fields' ,
[
'name' => $name ,
'display_on_front' => $display_on_front ,
'is_password_type' => $is_password_type ,
2019-03-07 13:37:36 +01:00
'combo_values' => $combo_values ,
2022-11-16 10:28:50 +01:00
'is_link_enabled' => $is_link_enabled ,
2019-01-30 16:18:44 +01:00
]
);
ui_print_success_message ( __ ( 'Field successfully created' ));
}
2010-08-25 14:04:42 +02:00
}
2019-03-07 13:37:36 +01:00
// Update field.
2010-08-25 14:04:42 +02:00
if ( $update_field ) {
2019-03-07 13:37:36 +01:00
// Check if name field is empty.
2022-11-22 11:50:07 +01:00
if ( $name !== '' ) {
2019-01-30 16:18:44 +01:00
$values = [
'name' => $name ,
'display_on_front' => $display_on_front ,
'is_password_type' => $is_password_type ,
2019-03-07 13:37:36 +01:00
'combo_values' => $combo_values ,
2022-11-16 10:28:50 +01:00
'is_link_enabled' => $is_link_enabled ,
2019-01-30 16:18:44 +01:00
];
$result = db_process_sql_update ( 'tagent_custom_fields' , $values , [ 'id_field' => $id_field ]);
} else {
$result = false ;
}
if ( $result !== false ) {
ui_print_success_message ( __ ( 'Field successfully updated' ));
} else {
ui_print_error_message ( __ ( 'There was a problem modifying field' ));
}
2010-08-25 14:04:42 +02:00
}
2019-03-07 13:37:36 +01:00
// Delete field.
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
if ( $delete_field ) {
2019-01-30 16:18:44 +01:00
$result = db_process_sql_delete (
'tagent_custom_fields' ,
[ 'id_field' => $id_field ]
);
if ( ! $result ) {
ui_print_error_message ( __ ( 'There was a problem deleting field' ));
} else {
ui_print_success_message ( __ ( 'Field successfully deleted' ));
}
2010-08-25 14:04:42 +02:00
}
2019-03-27 17:03:55 +01:00
// Prepare pagination.
$offset = ( int ) get_parameter ( 'offset' );
$limit = $config [ 'block_size' ];
$count_fields = db_get_value ( 'count(*)' , 'tagent_custom_fields' );
$fields = db_get_all_rows_filter (
'tagent_custom_fields' ,
[
'limit' => $limit ,
'offset' => $offset ,
]
);
2010-08-25 14:04:42 +02:00
2015-06-25 10:07:53 +02:00
$table = new stdClass ();
2023-02-22 17:41:19 +01:00
$table -> class = 'info_table' ;
2010-09-29 11:23:12 +02:00
if ( $fields ) {
2019-01-30 16:18:44 +01:00
$table -> head = [];
$table -> head [ 0 ] = __ ( 'ID' );
$table -> head [ 1 ] = __ ( 'Field' );
$table -> head [ 2 ] = __ ( 'Display on front' ) . ui_print_help_tip ( __ ( 'The fields with display on front enabled will be displayed into the agent details' ), true );
$table -> head [ 3 ] = __ ( 'Actions' );
$table -> align = [];
$table -> align [ 0 ] = 'left' ;
$table -> align [ 2 ] = 'left' ;
$table -> align [ 3 ] = 'left' ;
$table -> size [ 3 ] = '8%' ;
$table -> data = [];
} else {
2019-11-21 18:21:46 +01:00
include_once $config [ 'homedir' ] . '/general/first_task/fields_manager.php' ;
2019-01-30 16:18:44 +01:00
return ;
2010-08-29 23:42:17 +02:00
}
2019-01-30 16:18:44 +01:00
if ( $fields === false ) {
$fields = [];
}
2010-08-25 14:04:42 +02:00
2014-02-20 16:01:23 +01:00
2010-08-25 14:04:42 +02:00
foreach ( $fields as $field ) {
2019-01-30 16:18:44 +01:00
$data [ 0 ] = $field [ 'id_field' ];
2023-02-21 14:14:13 +01:00
$data [ 1 ] = $field [ 'name' ];
2019-01-30 16:18:44 +01:00
2023-02-21 14:14:13 +01:00
$data [ 2 ] = html_print_image (
2023-03-10 14:49:38 +01:00
(( bool ) $field [ 'display_on_front' ] === true ) ? 'images/validate.svg' : 'images/fail@svg.svg' ,
2023-02-21 14:14:13 +01:00
true ,
[ 'class' => 'main_menu_icon invert_filter' ]
);
2019-01-30 16:18:44 +01:00
2022-11-30 10:14:42 +01:00
$table -> cellclass [][ 3 ] = 'table_action_buttons' ;
2023-02-21 14:14:13 +01:00
$tableActionButtons = [];
$tableActionButtons [] = html_print_anchor (
[
'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configure_field&id_field=' . $field [ 'id_field' ],
'content' => html_print_image (
'images/edit.svg' ,
true ,
[
'title' => __ ( 'Edit' ),
'class' => 'main_menu_icon invert_filter' ,
]
),
],
true
);
$tableActionButtons [] = html_print_anchor (
[
'href' => 'index.php?sec=gagente&sec2=godmode/agentes/fields_manager&delete_field=1&id_field=' . $field [ 'id_field' ],
'content' => html_print_image (
'images/delete.svg' ,
true ,
[
'title' => __ ( 'Delete' ),
'class' => 'main_menu_icon invert_filter' ,
]
),
'onClick' => 'if (!confirm(\' ' . __ ( 'Are you sure?' ) . '\')) return false;' ,
],
true
);
$data [ 3 ] = implode ( '' , $tableActionButtons );
2019-01-30 16:18:44 +01:00
array_push ( $table -> data , $data );
2010-08-25 14:04:42 +02:00
}
2014-02-20 16:01:23 +01:00
if ( $fields ) {
2019-01-30 16:18:44 +01:00
html_print_table ( $table );
2023-02-21 14:14:13 +01:00
$tablePagination = ui_pagination ( $count_fields , false , $offset , 0 , true , 'offset' , false );
2014-02-20 16:01:23 +01:00
}
2010-08-25 14:04:42 +02:00
2023-02-21 14:14:13 +01:00
echo '<form method="POST" action="index.php?sec=gagente&sec2=godmode/agentes/configure_field">' ;
html_print_action_buttons (
html_print_submit_button (
__ ( 'Create field' ),
'crt' ,
false ,
[ 'icon' => 'next' ],
true
),
[ 'type' => 'form_action' ]
2022-11-04 13:00:00 +01:00
);
2010-08-25 14:04:42 +02:00
echo '</form>' ;