2008-04-23 22:01:37 +02:00
< ? php
2021-06-16 18:18:38 +02:00
/**
* Manage plugins .
*
* @ category Utility
* @ package Pandora FMS
* @ subpackage Plugins
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2023-02-22 14:19:57 +01:00
* Copyright ( c ) 2005 - 2023 Artica Soluciones Tecnologicas
2021-06-16 18:18:38 +02: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 .
* ============================================================================
*/
// Begin.
2014-12-12 14:56:16 +01:00
global $config ;
2021-06-16 18:18:38 +02:00
require_once $config [ 'homedir' ] . '/include/functions_plugins.php' ;
2019-01-30 16:18:44 +01:00
if ( is_ajax ()) {
$get_plugin_description = get_parameter ( 'get_plugin_description' );
$get_list_modules_and_component_locked_plugin = ( bool ) get_parameter ( 'get_list_modules_and_component_locked_plugin' , 0 );
if ( $get_plugin_description ) {
$id_plugin = get_parameter ( 'id_plugin' );
$description = db_get_value_filter ( 'description' , 'tplugin' , [ 'id' => $id_plugin ]);
$preload = io_safe_output ( $description );
$preload = str_replace ( " \n " , '<br>' , $preload );
echo $preload ;
return ;
}
if ( $get_list_modules_and_component_locked_plugin ) {
$id_plugin = ( int ) get_parameter ( 'id_plugin' , 0 );
$network_components = db_get_all_rows_filter (
'tnetwork_component' ,
[ 'id_plugin' => $id_plugin ]
);
if ( empty ( $network_components )) {
$network_components = [];
}
$modules = db_get_all_rows_filter (
'tagente_modulo' ,
[
'delete_pending' => 0 ,
'id_plugin' => $id_plugin ,
]
);
if ( empty ( $modules )) {
$modules = [];
}
2022-01-12 14:22:16 +01:00
$table = new stdClass ();
2019-01-30 16:18:44 +01:00
$table -> width = '100%' ;
$table -> head [ 0 ] = __ ( 'Network Components' );
2023-02-22 14:19:57 +01:00
// $table->data = [];
2019-01-30 16:18:44 +01:00
foreach ( $network_components as $net_comp ) {
$table -> data [] = [ $net_comp [ 'name' ]];
}
2023-02-22 14:19:57 +01:00
if ( empty ( $table -> data ) === false ) {
2019-01-30 16:18:44 +01:00
html_print_table ( $table );
}
2022-01-12 14:22:16 +01:00
$table = new stdClass ();
2019-01-30 16:18:44 +01:00
$table -> width = '100%' ;
$table -> head [ 0 ] = __ ( 'Agent' );
$table -> head [ 1 ] = __ ( 'Module' );
foreach ( $modules as $mod ) {
2019-06-27 17:19:48 +02:00
$agent_name = '<a href="' . ui_get_full_url ( 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $mod [ 'id_agente' ]) . '">' . modules_get_agentmodule_agent_alias (
2019-01-30 16:18:44 +01:00
$mod [ 'id_agente_modulo' ]
) . '</a>' ;
$table -> data [] = [
$agent_name ,
$mod [ 'nombre' ],
];
}
if ( ! empty ( $table -> data )) {
html_print_table ( $table );
}
return ;
}
2010-06-02 18:43:59 +02:00
}
2008-08-22 20:07:32 +02:00
2014-12-12 14:56:16 +01:00
2019-01-30 16:18:44 +01:00
require_once $config [ 'homedir' ] . '/include/functions_filemanager.php' ;
2013-06-27 13:42:53 +02:00
2019-01-30 16:18:44 +01:00
check_login ();
2008-08-11 Esteban Sanchez <estebans@artica.es>
* include/functions_db.php: Added __ as an alias of lang_string().
* include/functions_reporting_pdf.php,
include/functions_reporting.php, include/functions.php,
include/functions_visual_map.php, index.php,
operation/incidents/incident.php,
operation/incidents/incident_detail.php,
operation/incidents/incident_note.php,
operation/incidents/incident_search.php,
operation/incidents/incident_statistics.php,
operation/snmpconsole/snmp_alert.php,
operation/snmpconsole/snmp_view.php, operation/users/user.php,
operation/users/user_edit.php, operation/users/user_statistics.php,
operation/events/event_statistics.php, operation/events/events.php,
operation/visual_console/render_view.php,
operation/visual_console/index.php, operation/extensions.php,
operation/agentes/estado_alertas.php,
operation/agentes/status_monitor.php,
operation/agentes/estado_grupo.php, operation/agentes/export_csv.php,
operation/agentes/datos_agente.php,
operation/agentes/estado_ultimopaquete.php,
operation/agentes/estado_generalagente.php,
operation/agentes/estado_agente.php, operation/agentes/bulbs.php,
operation/agentes/status_events.php, operation/agentes/sla_view.php,
operation/agentes/exportdata.php,
operation/agentes/estado_monitores.php,
operation/agentes/ver_agente.php, operation/agentes/estadisticas.php,
operation/agentes/tactical.php, operation/agentes/networkmap.php,
operation/messages/message.php,
operation/reporting/reporting_viewer.php,
operation/reporting/graph_viewer.php,
operation/reporting/custom_reporting.php,
operation/servers/view_server.php,
operation/servers/view_server_detail.php, operation/menu.php,
reporting/fgraph.php, reporting/stat_win.php, ajax.php,
general/logoff.php, general/pandora_help.php, general/footer.php,
general/noaccess.php, general/logon_failed.php,
general/links_menu.php, general/login_page.php, general/logon_ok.php,
general/header.php, general/main_menu.php,
godmode/groups/configure_group.php, godmode/groups/group_list.php,
godmode/setup/news.php, godmode/setup/links.php,
godmode/setup/setup.php, godmode/users/user_list.php,
godmode/users/configure_user.php, godmode/profiles/profile_list.php,
godmode/admin_access_logs.php, godmode/db/db_info_data.php,
godmode/db/db_main.php, godmode/db/db_audit.php,
godmode/db/db_sanity.php, godmode/db/db_refine.php,
godmode/db/db_info.php, godmode/db/db_event.php,
godmode/db/db_purge.php, godmode/extensions.php,
godmode/agentes/agent_template.php,
godmode/agentes/module_manager_editor_network.php,
godmode/agentes/module_manager_editor_wmi.php,
godmode/agentes/alert_manager.php,
godmode/agentes/module_manager_editor_plugin.php,
godmode/agentes/module_manager_editor_prediction.php,
godmode/agentes/alert_manager_editor.php,
godmode/agentes/manage_config.php,
godmode/agentes/module_manager_editor_data.php,
godmode/agentes/module_manager.php,
godmode/agentes/modificar_agente.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/agent_disk_conf_editor.php,
godmode/agentes/planned_downtime.php,
godmode/agentes/manage_config_remote.php,
godmode/agentes/agent_manager.php,
godmode/modules/manage_network_components_form.php,
godmode/modules/manage_nc_groups_form.php,
godmode/modules/manage_network_templates.php,
godmode/modules/module_list.php,
godmode/modules/manage_network_templates_form.php,
godmode/modules/manage_network_components_form_network.php,
godmode/modules/manage_network_components_form_wmi.php,
godmode/modules/manage_network_components.php,
godmode/modules/manage_nc_groups.php,
godmode/reporting/reporting_builder.php,
godmode/reporting/map_builder.php,
godmode/reporting/graph_builder.php, godmode/servers/plugin.php,
godmode/servers/manage_recontask.php,
godmode/servers/modificar_server.php,
godmode/servers/manage_recontask_form.php,
godmode/alerts/modify_alert.php, godmode/alerts/configure_alert.php,
godmode/menu.php: Replaced $id_user with $config['id_user']. Use __a
instead of $lang_label to future use of gettext. Style
corrections.
* godmode/agentes/planned_downtime.php: Rewritten to use Pandora
functions and adopt the UI style. Replaced lang_string with __().
* pandoradb.sql: Fields in tplanned_downtime renamed to fit
guidelines.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1005 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-08-11 12:59:07 +02:00
2020-03-11 16:21:25 +01:00
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'PM' ) && ! check_acl ( $config [ 'id_user' ], 0 , 'AW' )) {
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 Plugin Management'
);
include 'general/noaccess.php' ;
return ;
2008-04-23 22:01:37 +02:00
}
2019-01-30 16:18:44 +01:00
enterprise_include_once ( 'meta/include/functions_components_meta.php' );
2013-02-08 10:28:25 +01:00
2019-01-30 16:18:44 +01:00
$view = get_parameter ( 'view' , '' );
$create = get_parameter ( 'create' , '' );
$filemanager = ( bool ) get_parameter ( 'filemanager' , false );
$edit_file = get_parameter ( 'edit_file' , false );
$update_file = get_parameter ( 'update_file' , false );
2013-06-27 13:42:53 +02:00
$plugin_command = get_parameter ( 'plugin_command' , '' );
2013-09-16 12:21:57 +02:00
$tab = get_parameter ( 'tab' , '' );
2008-04-23 22:01:37 +02:00
2019-01-30 16:18:44 +01:00
if ( $view != '' ) {
$form_id = $view ;
$plugin = db_get_row ( 'tplugin' , 'id' , $form_id );
$form_name = $plugin [ 'name' ];
$form_description = $plugin [ 'description' ];
$form_max_timeout = $plugin [ 'max_timeout' ];
$form_max_retries = $plugin [ 'max_retries' ];
if ( empty ( $plugin_command )) {
$form_execute = $plugin [ 'execute' ];
} else {
$form_execute = $plugin_command ;
}
$form_plugin_type = $plugin [ 'plugin_type' ];
$macros = $plugin [ 'macros' ];
$parameters = $plugin [ 'parameters' ];
2013-02-20 Miguel de Dios <miguel.dedios@artica.es>
* godmode/servers/recon_script.php, godmode/servers/plugin.php,
godmode/snmpconsole/snmp_filters.php,
godmode/massive/massive_delete_alerts.php,
godmode/massive/massive_enable_disable_alerts.php,
godmode/massive/massive_edit_agents.php,
godmode/massive/massive_delete_modules.php,
godmode/massive/massive_add_action_alerts.php,
godmode/massive/massive_delete_action_alerts.php: improved the code
style.
* include/ajax/events.php, include/functions_events.php,
operation/agentes/custom_fields.php: fixed the show admin custom
fields for user without permisitions.
Fixes: #3605278
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7683 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-02-20 13:07:00 +01:00
}
2019-01-30 16:18:44 +01:00
if ( $create != '' ) {
$form_id = 0 ;
$form_name = '' ;
$form_description = '' ;
$form_max_timeout = 15 ;
$form_max_retries = 1 ;
$form_execute = $plugin_command ;
$form_plugin_type = 0 ;
$form_parameters = '' ;
$macros = '' ;
$parameters = '' ;
2008-04-23 22:01:37 +02:00
}
2013-06-27 13:42:53 +02:00
2019-01-30 16:18:44 +01:00
// END LOAD VALUES
2013-06-27 13:42:53 +02:00
// =====================================================================
// INIT FILEMANAGER
// =====================================================================
if ( $filemanager ) {
2019-01-30 16:18:44 +01:00
if ( $edit_file ) {
$location_file = get_parameter ( 'location_file' , '' );
$filename = array_pop ( explode ( '/' , $location_file ));
$file = file_get_contents ( $location_file );
echo '<h4>' . __ ( 'Edit file' ) . ' ' . $filename . '</h4>' ;
// echo "<a href='index.php?sec=gagente&sec2=enterprise/godmode/agentes/collections&action=file&id=" . $collection['id'] . "&directory=" . $relative_dir . "&hash2=" . $hash2 . "'>" . __('Back to file explorer') . "</a>";
echo " <form method='post' action='index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1 " . " &update_file=1'> " ;
// html_print_input_hidden('location_file', $locationFile);
2021-03-11 15:40:23 +01:00
echo " <table class='w98p'> " ;
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo '<th>' . __ ( 'Edit' ) . '</th>' ;
echo '</tr>' ;
echo '<tr>' ;
echo '<td>' ;
2021-03-11 15:40:23 +01:00
echo " <textarea name='content_file' class='w100p height_400px' > " ;
2019-01-30 16:18:44 +01:00
echo $file ;
echo '</textarea>' ;
echo '</td>' ;
echo '</tr>' ;
echo " <tr align='right'> " ;
echo '<td>' ;
html_print_input_hidden ( 'location_file' , $location_file );
echo __ ( 'Compatibility mode' ) . ':' ;
$options = [
'unix' => 'Unix' ,
'windows' => 'Windows' ,
];
html_print_select ( $options , 'compatibility' , $compatibility );
echo " <input type='submit' name='submit' value=' " . __ ( 'Update' ) . " ' class='sub upd' /> " ;
echo '</td>' ;
echo '</tr>' ;
echo '</table>' ;
echo '</form>' ;
} else {
if ( $update_file ) {
$location_file = get_parameter ( 'location_file' , '' );
$contentFile = io_safe_output ( get_parameter ( 'content_file' , '' ));
$compatibility = get_parameter ( 'compatibility' , 'unix' );
$is_win_compatible = strpos ( $contentFile , " \r \n " );
// If is win compatible and the compatibility must be unix
if ( $is_win_compatible !== false && $compatibility == 'unix' ) {
$contentFile = str_replace ( " \r \n " , " \n " , $contentFile );
2019-02-22 14:26:58 +01:00
} else if ( $is_win_compatible === false && $compatibility == 'windows' ) {
// If is unix compatible and the compatibility must be win
2019-01-30 16:18:44 +01:00
$contentFile = str_replace ( " \n " , " \r \n " , $contentFile );
}
$result = file_put_contents ( $location_file , $contentFile );
}
$id_plugin = ( int ) get_parameter ( 'id_plugin' , 0 );
2021-09-03 13:30:15 +02:00
// Add custom directories here.
2019-01-30 16:18:44 +01:00
$fallback_directory = 'attachment/plugin' ;
2021-09-03 13:30:15 +02:00
// Get directory.
$directory = ( string ) get_parameter ( 'directory' );
if ( empty ( $directory ) === true ) {
2019-01-30 16:18:44 +01:00
$directory = $fallback_directory ;
2023-01-27 13:23:48 +01:00
} else {
$directory = str_replace ( '\\' , '/' , $directory );
$directory = filemanager_safe_directory ( $directory , $fallback_directory );
}
2023-01-23 11:07:34 +01:00
2023-01-27 13:23:48 +01:00
$base_url = 'index.php?sec=gservers&sec2=godmode/servers/plugin' ;
$setup_url = $base_url . '&filemanager=1&tab=Attachments' ;
$tab = get_parameter ( 'tab' , null );
$tabs = [
'list' => [
'text' => '<a href="' . $base_url . '">' . html_print_image (
2023-02-22 14:19:57 +01:00
'images/see-details@svg.svg' ,
2023-01-27 13:23:48 +01:00
true ,
2023-01-23 11:07:34 +01:00
[
2023-01-27 13:23:48 +01:00
'title' => __ ( 'Plugins' ),
2023-02-22 14:19:57 +01:00
'class' => 'invert_filter main_menu_icon' ,
2023-01-27 13:23:48 +01:00
]
) . '</a>' ,
'active' => ( bool ) ( $tab != 'Attachments' ),
],
'options' => [
'text' => '<a href="' . $setup_url . '">' . html_print_image (
2023-02-22 14:19:57 +01:00
'images/file-collection@svg.svg' ,
2023-01-27 13:23:48 +01:00
true ,
2023-01-23 11:07:34 +01:00
[
2023-01-27 13:23:48 +01:00
'title' => __ ( 'Attachments' ),
2023-02-22 14:19:57 +01:00
'class' => 'invert_filter main_menu_icon' ,
2023-01-27 13:23:48 +01:00
]
) . '</a>' ,
'active' => ( bool ) ( $tab == 'Attachments' ),
],
];
if ( $tab === 'Attachments' ) {
$helpHeader = '' ;
$titleHeader = __ ( 'Index of attachment/plugin' );
2021-09-03 13:30:15 +02:00
} else {
2023-01-27 13:23:48 +01:00
$helpHeader = 'servers_ha_clusters_tab' ;
$titleHeader = __ ( 'Plug-ins registered on %s' , get_product_name ());
2019-01-30 16:18:44 +01:00
}
2023-01-27 13:23:48 +01:00
// Header.
ui_print_standard_header (
$titleHeader ,
'images/gm_servers.png' ,
false ,
$helpHeader ,
false ,
$tabs ,
[
[
'link' => '' ,
'label' => __ ( 'Servers' ),
],
[
'link' => '' ,
'label' => __ ( 'Plugins' ),
],
]
);
2019-01-30 16:18:44 +01:00
$real_directory = realpath ( $config [ 'homedir' ] . '/' . $directory );
$chunck_url = '&view=' . $id_plugin ;
if ( $id_plugin == 0 ) {
$chunck_url = '&create=1' ;
}
2020-11-03 15:58:53 +01:00
$upload_file_or_zip = ( bool ) get_parameter ( 'upload_file_or_zip' );
$create_text_file = ( bool ) get_parameter ( 'create_text_file' );
$default_real_directory = realpath ( $config [ 'homedir' ] . '/' . $fallback_directory );
2021-09-03 13:30:15 +02:00
if ( $upload_file_or_zip === true ) {
upload_file ( $upload_file_or_zip , $default_real_directory , $real_directory );
2020-11-03 15:58:53 +01:00
}
2021-09-03 13:30:15 +02:00
if ( $create_text_file === true ) {
create_text_file ( $default_real_directory , $real_directory );
2020-11-03 15:58:53 +01:00
}
2019-01-30 16:18:44 +01:00
filemanager_file_explorer (
$real_directory ,
$directory ,
2023-01-27 13:23:48 +01:00
'index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1&id_plugin=' . $id_plugin . '&tab=Attachments' ,
2019-01-30 16:18:44 +01:00
$fallback_directory ,
true ,
false ,
'index.php?sec=gservers&sec2=godmode/servers/plugin' . $chunck_url . '&plugin_command=[FILE_FULLPATH]&id_plugin=' . $id_plugin ,
true ,
0775 ,
2022-03-09 17:27:08 +01:00
false ,
[ 'all' => true ]
2019-01-30 16:18:44 +01:00
);
}
return ;
2013-06-27 13:42:53 +02:00
}
// =====================================================================
// END FILEMANAGER
// =====================================================================
2014-03-31 16:17:41 +02:00
// =====================================================================
2008-04-23 22:01:37 +02:00
// SHOW THE FORM
2013-06-27 13:42:53 +02:00
// =====================================================================
2013-02-08 10:28:25 +01:00
$sec = 'gservers' ;
2023-02-22 14:19:57 +01:00
if ( empty ( $create ) === false || empty ( $view ) === false ) {
2021-06-03 10:16:29 +02:00
$management_allowed = is_management_allowed ();
2023-02-22 14:19:57 +01:00
if ( is_metaconsole () === true ) {
2019-01-30 16:18:44 +01:00
components_meta_print_header ();
$sec = 'advanced' ;
2021-06-03 10:16:29 +02:00
if ( $management_allowed === false ) {
2019-02-22 14:26:58 +01:00
ui_print_warning_message ( __ ( 'To manage plugin you must activate centralized management' ));
}
2019-01-30 16:18:44 +01:00
} else {
2023-02-22 14:19:57 +01:00
// Header.
ui_print_standard_header (
( empty ( $create ) === false ) ? __ ( 'Plugin registration' ) : __ ( 'Plugin update' ),
'images/gm_servers.png' ,
false ,
'' ,
true ,
[],
[
[
'link' => '' ,
'label' => __ ( 'Servers' ),
],
[
'link' => 'index.php?sec=gservers&sec2=godmode/servers/plugin' ,
'label' => __ ( 'Plugins' ),
],
]
);
2019-02-22 14:26:58 +01:00
2021-06-03 10:16:29 +02:00
if ( $management_allowed === false ) {
2019-02-22 14:26:58 +01:00
ui_print_warning_message (
__ (
' This console is not manager of this environment ,
please manage this feature from centralized manager console ( Metaconsole ) . '
)
);
}
2019-01-30 16:18:44 +01:00
}
2023-02-22 14:19:57 +01:00
$plugin_id = ( int ) get_parameter ( 'view' );
$locked = true ;
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
// If we have plugin id (update mode) and this plugin used by any module or component
// The command configuration will be locked
if ( $plugin_id > 0 ) {
$modules_using_plugin = db_get_value_filter ( 'count(*)' , 'tagente_modulo' , [ 'delete_pending' => 0 , 'id_plugin' => $plugin_id ]);
$components_using_plugin = db_get_value_filter ( 'count(*)' , 'tnetwork_component' , [ 'id_plugin' => $plugin_id ]);
if (( $components_using_plugin + $modules_using_plugin ) == 0 ) {
$locked = false ;
}
} else {
$locked = false ;
}
$disabled = ( $locked === true ) ? 'readonly="readonly"' : '' ;
if ( empty ( $create ) === true ) {
2023-03-13 17:32:20 +01:00
$formAction = 'index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&update_plugin=' . $plugin_id . '&pure=' . $config [ 'pure' ];
2019-01-30 16:18:44 +01:00
} else {
2023-02-22 14:19:57 +01:00
$formAction = 'index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&create_plugin=1&pure=' . $config [ 'pure' ];
2019-01-30 16:18:44 +01:00
}
2023-02-22 14:19:57 +01:00
$formPluginType = [
0 => __ ( 'Standard' ),
1 => __ ( 'Nagios' ),
];
echo '<form class="max_floating_element_size" name="plugin" method="post" action="' . $formAction . '">' ;
2019-01-30 16:18:44 +01:00
$table = new stdClass ();
$table -> id = 'table-form' ;
2023-03-13 17:32:20 +01:00
$table -> class = 'filter-table-adv' ;
2019-01-30 16:18:44 +01:00
$table -> style = [];
2023-02-22 14:19:57 +01:00
$table -> data [ 'plugin_name_captions' ] = $data ;
2023-03-13 17:32:20 +01:00
$table -> size [ 0 ] = '50%' ;
$table -> size [ 1 ] = '50%' ;
2023-02-22 14:19:57 +01:00
2019-01-30 16:18:44 +01:00
$table -> data = [];
2023-02-22 14:19:57 +01:00
// General title.
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_div ([ 'class' => 'section_table_title' , 'content' => __ ( 'General' )], true );
2023-02-22 14:19:57 +01:00
$table -> data [ 'general_title' ] = $data ;
2019-01-30 16:18:44 +01:00
$data = [];
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_label_input_block (
__ ( 'Name' ),
html_print_input_text ( 'form_name' , $form_name , '' , 100 , 255 , true , false , false , '' )
);
2023-02-22 14:19:57 +01:00
$table -> data [ 'plugin_name_captions' ] = $data ;
2019-01-30 16:18:44 +01:00
$data = [];
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_label_input_block (
__ ( 'Plugin type' ),
html_print_select ( $formPluginType , 'form_plugin_type' , $form_plugin_type , '' , '' , 0 , true , false , true , '' , false , 'width: 100%' )
);
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
$timeoutContent = [];
$timeoutContent [] = '<div>' . html_print_extended_select_for_time ( 'form_max_timeout' , $form_max_timeout , '' , '' , '0' , false , true ) . '</div>' ;
$timeoutContent [] = ui_print_input_placeholder ( __ ( 'This value only will be applied if is minor than the server general configuration plugin timeout' ) . '<br>' . __ ( 'If you set a 0 seconds timeout, the server plugin timeout will be used' ), true );
2023-03-13 17:32:20 +01:00
$data [ 1 ] = html_print_label_input_block (
__ ( 'Max. timeout' ),
html_print_div (
[
'class' => 'flex flex_column' ,
'content' => implode ( '' , $timeoutContent ),
],
true
)
2023-02-22 14:19:57 +01:00
);
2019-01-30 16:18:44 +01:00
2023-03-13 17:32:20 +01:00
$table -> data [ 'plugin_type_timeout' ] = $data ;
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
$data = [];
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_label_input_block (
__ ( 'Description' ),
html_print_textarea ( 'form_description' , 4 , 50 , $form_description , '' , true )
);
$table -> colspan [ 'plugin_desc_inputs' ][ 0 ] = 2 ;
2023-02-22 14:19:57 +01:00
$table -> data [ 'plugin_desc_inputs' ] = $data ;
2019-01-30 16:18:44 +01:00
2023-03-13 17:32:20 +01:00
2023-02-22 14:19:57 +01:00
// Command title.
$data = [];
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_div ([ 'class' => 'section_table_title' , 'content' => __ ( 'Command' )], true );
2023-02-22 14:19:57 +01:00
$table -> data [ 'command_title' ] = $data ;
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
$data = [];
$formExecuteContent = [];
$formExecuteContent [] = html_print_input_text ( 'form_execute' , $form_execute , '' , 50 , 255 , true , false , false , '' , 'command_component command_advanced_conf w100p' );
$formExecuteContent [] = html_print_anchor (
[
'title' => __ ( 'Save changes' ),
'href' => 'index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1&tab=Attachments&id_plugin=' . $form_id ,
'class' => 'mrgn_lft_5px' ,
2023-02-22 16:24:11 +01:00
'content' => html_print_image ( 'images/validate.svg' , true , [ 'class' => 'invert_filter main_menu_icon' ], false , true ),
2023-02-22 14:19:57 +01:00
],
true
);
2019-01-30 16:18:44 +01:00
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_label_input_block (
__ ( 'Plugin command' ),
html_print_div ([ 'class' => 'flex-row-center' , 'content' => implode ( '' , $formExecuteContent )], true ) . ui_print_input_placeholder (
__ ( 'Specify interpreter and plugin path. The server needs permissions to run it.' ),
true
)
);
// $data[0] = html_print_div(['class' => 'flex-row-center', 'content' => implode('', $formExecuteContent)], true);
2023-02-22 14:19:57 +01:00
$table -> data [ 'plugin_command_inputs' ] = $data ;
$table -> colspan [ 'plugin_command_inputs' ][ 0 ] = 2 ;
2019-01-30 16:18:44 +01:00
$data = [];
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_label_input_block (
__ ( 'Plug-in parameters' ),
html_print_input_text (
'form_parameters' ,
$parameters ,
'' ,
100 ,
255 ,
true ,
false ,
false ,
'' ,
'command_component command_advanced_conf text_input'
)
2023-02-22 14:19:57 +01:00
);
2023-03-13 17:32:20 +01:00
2023-02-22 14:19:57 +01:00
$table -> data [ 'plugin_parameters_inputs' ] = $data ;
$table -> colspan [ 'plugin_parameters_inputs' ][ 0 ] = 2 ;
2019-01-30 16:18:44 +01:00
$data = [];
2023-03-13 17:32:20 +01:00
// $data[0] = __('Command preview');
// $table->data['plugin_preview_captions'] = $data;
// $data = [];
// $data[0] = html_print_div(['id' => 'command_preview', 'class' => 'mono'], true);
$data [ 0 ] = html_print_label_input_block (
__ ( 'Command preview' ),
html_print_div ([ 'id' => 'command_preview' , 'class' => 'mono' ], true )
);
2023-02-22 14:19:57 +01:00
$table -> data [ 'plugin_preview_inputs' ] = $data ;
$table -> colspan [ 'plugin_preview_inputs' ][ 0 ] = 2 ;
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
// Parameters macros title.
2019-01-30 16:18:44 +01:00
$data = [];
2023-03-13 17:32:20 +01:00
$data [ 0 ] = html_print_div ([ 'class' => 'section_table_title' , 'content' => __ ( 'Parameters macros' )], true );
2023-02-22 14:19:57 +01:00
$table -> data [ 'parameters_macros_title' ] = $data ;
2019-01-30 16:18:44 +01:00
$macros = json_decode ( $macros , true );
// The next row number is plugin_9
$next_name_number = 9 ;
$i = 1 ;
while ( 1 ) {
2023-02-22 14:19:57 +01:00
// Always print at least one macro.
if (( isset ( $macros [ $i ]) === false || $macros [ $i ][ 'desc' ] == '' ) && $i > 1 ) {
2019-01-30 16:18:44 +01:00
break ;
}
$macro_desc_name = 'field' . $i . '_desc' ;
$macro_desc_value = '' ;
$macro_help_name = 'field' . $i . '_help' ;
$macro_help_value = '' ;
$macro_value_name = 'field' . $i . '_value' ;
$macro_value_value = '' ;
$macro_name_name = 'field' . $i . '_macro' ;
$macro_name = '_field' . $i . '_' ;
$macro_hide_value_name = 'field' . $i . '_hide' ;
$macro_hide_value_value = 0 ;
if ( isset ( $macros [ $i ][ 'desc' ])) {
$macro_desc_value = $macros [ $i ][ 'desc' ];
}
if ( isset ( $macros [ $i ][ 'help' ])) {
$macro_help_value = $macros [ $i ][ 'help' ];
}
if ( isset ( $macros [ $i ][ 'value' ])) {
$macro_value_value = $macros [ $i ][ 'value' ];
}
if ( isset ( $macros [ $i ][ 'hide' ])) {
$macro_hide_value_value = $macros [ $i ][ 'hide' ];
// Decrypt hidden macros.
$macro_value_value = io_output_password ( $macro_value_value );
}
$datam = [];
2023-03-13 17:32:20 +01:00
$datam [ 0 ] = html_print_label_input_block (
__ ( 'Description' ) . '<span class="normal_weight">(' . $macro_name . ')</span>' ,
html_print_input_text_extended ( $macro_desc_name , $macro_desc_value , 'text-' . $macro_desc_name , '' , 30 , 255 , false , '' , " class='command_macro text_input' " , true )
);
2019-01-30 16:18:44 +01:00
$datam [ 0 ] .= html_print_input_hidden ( $macro_name_name , $macro_name , true );
2023-03-13 17:32:20 +01:00
$datam [ 1 ] = html_print_label_input_block (
__ ( 'Default value' ) . '<span class="normal_weight">(' . $macro_name . ')</span>' ,
html_print_input_text_extended ( $macro_value_name , $macro_value_value , 'text-' . $macro_value_name , '' , 30 , 255 , false , '' , " class='command_component command_macro text_input' " , true )
);
2019-01-30 16:18:44 +01:00
$table -> data [ 'plugin_' . $next_name_number ] = $datam ;
$next_name_number ++ ;
2023-03-13 17:32:20 +01:00
$table -> colspan [ 'plugin_' . $next_name_number ][ 1 ] = 2 ;
2019-01-30 16:18:44 +01:00
$datam = [];
2023-03-13 17:32:20 +01:00
$datam = html_print_label_input_block (
__ ( 'Hide value' ),
html_print_checkbox_switch (
$macro_hide_value_name ,
1 ,
$macro_hide_value_value ,
0 ,
'' ,
[ 'class' => 'command_macro' ],
true ,
'checkbox-' . $macro_hide_value_name
) . ui_print_input_placeholder (
__ ( 'This field will show up as dots like a password' ),
true
)
2021-03-11 15:40:23 +01:00
);
2019-01-30 16:18:44 +01:00
$table -> data [ 'plugin_' . $next_name_number ] = $datam ;
$next_name_number ++ ;
2023-03-13 17:32:20 +01:00
// $table->colspan['plugin_'.$next_name_number][1] = 3;
2019-01-30 16:18:44 +01:00
$datam = [];
2023-03-13 17:32:20 +01:00
$datam [ 0 ] = html_print_label_input_block (
__ ( 'Help' ) . '<span class="normal_weight"> (' . $macro_name . ')</span>' ,
html_print_textarea (
$macro_help_name ,
6 ,
100 ,
$macro_help_value ,
'class="command_macro" class="w97p"' ,
true
)
2021-03-11 15:40:23 +01:00
);
2019-01-30 16:18:44 +01:00
2023-03-13 17:32:20 +01:00
$table -> colspan [ 'plugin_' . $next_name_number ][ 0 ] = 2 ;
2019-01-30 16:18:44 +01:00
$table -> data [ 'plugin_' . $next_name_number ] = $datam ;
$next_name_number ++ ;
$i ++ ;
}
// Add/Delete buttons
$datam = [];
2023-03-13 17:32:20 +01:00
$buttons = '' ;
2019-01-30 16:18:44 +01:00
if ( ! $locked ) {
2022-11-10 14:19:01 +01:00
$datam [ 0 ] = '<a id="add_macro_btn" href="javascript:;">' . '<span class="bolder">' . __ ( 'Add macro' ) . '</span>' . ' ' . html_print_image (
'images/add.png' ,
true ,
[ 'class' => 'invert_filter' ]
) . '</a>' ;
$datam [ 0 ] .= '<div id="next_macro" class="invisible">' . $i . '</div>' ;
$datam [ 0 ] .= '<div id="next_row" class="invisible">' . $next_name_number . '</div>' ;
2023-03-13 17:32:20 +01:00
$buttons = html_print_anchor (
[
'id' => 'add_macro_btn' ,
'href' => 'javascript:;' ,
'content' => html_print_image (
'images/plus@svg.svg' ,
true ,
[ 'class' => 'invert_filter' ]
),
],
true
);
$buttons .= html_print_div ([ 'id' => 'next_macro' , 'class' => 'invisible' , 'content' => $i ], true );
$buttons .= html_print_div ([ 'id' => 'next_row' , 'class' => 'invisible' , 'content' => $next_name_number ], true );
2019-01-30 16:18:44 +01:00
$delete_macro_style = '' ;
if ( $i <= 2 ) {
$delete_macro_style = 'display:none;' ;
}
2023-03-13 17:32:20 +01:00
// $datam[1] = '<div id="delete_macro_button" style="'.$delete_macro_style.'">'.'<a href="javascript:;">'.'<span class="bolder">'.__('Delete macro').'</span>'.' '.html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter']).'</a>'.'</div>';
$buttons .= html_print_anchor (
[
'id' => 'delete_macro_button' ,
'style' => $delete_macro_style ,
'href' => 'javascript:;' ,
'content' => html_print_image (
'images/delete.svg' ,
true ,
[ 'class' => 'main_menu_icon invert_filter' ]
),
],
true
);
2019-01-30 16:18:44 +01:00
2023-03-13 17:32:20 +01:00
$datam [ 0 ] = html_print_div (
[
'style' => 'flex-direction: row-reverse;justify-content: flex-start;' ,
'content' => $buttons ,
],
true
);
2019-01-30 16:18:44 +01:00
$table -> colspan [ 'plugin_action' ][ 0 ] = 2 ;
} else {
2023-03-13 17:32:20 +01:00
// $table->colspan['plugin_action'][0] = 4;
2019-01-30 16:18:44 +01:00
}
2023-03-13 17:32:20 +01:00
// $table->rowstyle['plugin_action'] = 'text-align:center';
2019-01-30 16:18:44 +01:00
$table -> data [ 'plugin_action' ] = $datam ;
if ( defined ( 'METACONSOLE' )) {
$table -> head [ 0 ] = __ ( 'Parameters macros' );
$table -> head_colspan [ 0 ] = 4 ;
$table -> headstyle [ 0 ] = 'text-align: center' ;
html_print_table ( $table );
} else {
2023-02-22 14:19:57 +01:00
// echo '<fieldset>'.'<legend>'.__('Parameters macros').'</legend>';
html_print_div (
[
'class' => 'info_table' ,
'content' => html_print_table ( $table , true ),
]
);
// echo '</fieldset>';
2019-01-30 16:18:44 +01:00
}
echo '<table width="100%">' ;
echo '<tr><td align="right">' ;
2023-03-07 17:24:36 +01:00
$buttons = '' ;
if ( empty ( $create ) === false ) {
$buttons .= html_print_submit_button (
2023-03-06 17:51:49 +01:00
__ ( 'Create' ),
'crtbutton' ,
false ,
[ 'icon' => 'wand' ],
true
);
2019-01-30 16:18:44 +01:00
} else {
2023-03-07 17:24:36 +01:00
$buttons .= html_print_submit_button (
2023-03-06 17:51:49 +01:00
__ ( 'Update' ),
'uptbutton' ,
false ,
[ 'icon' => 'upd' ],
true
);
2019-01-30 16:18:44 +01:00
}
2023-03-07 17:24:36 +01:00
$buttons .= html_print_go_back_button (
'index.php?sec=gservers&sec2=godmode/servers/plugin' ,
[ 'button_class' => '' ],
true
);
2023-03-06 17:51:49 +01:00
html_print_action_buttons (
2023-03-07 17:24:36 +01:00
$buttons
2023-03-06 17:51:49 +01:00
);
2019-01-30 16:18:44 +01:00
echo '</form></table>' ;
if ( defined ( 'METACONSOLE' )) {
echo '</td></tr>' ;
}
} else {
if ( defined ( 'METACONSOLE' )) {
components_meta_print_header ();
$sec = 'advanced' ;
2019-02-22 14:26:58 +01:00
$management_allowed = is_management_allowed ();
if ( ! $management_allowed ) {
2021-03-11 15:40:23 +01:00
ui_print_warning_message (
__ ( 'To manage plugin you must activate centralized management' )
);
2019-02-22 14:26:58 +01:00
}
2019-01-30 16:18:44 +01:00
} else {
2023-01-23 11:07:34 +01:00
$base_url = 'index.php?sec=gservers&sec2=godmode/servers/plugin' ;
$setup_url = $base_url . '&filemanager=1&tab=Attachments' ;
$tab = get_parameter ( 'tab' , null );
$tabs = [
'list' => [
'text' => '<a href="' . $base_url . '">' . html_print_image (
2023-02-22 14:19:57 +01:00
'images/see-details@svg.svg' ,
2023-01-23 11:07:34 +01:00
true ,
[
'title' => __ ( 'Plugins' ),
2023-02-22 14:19:57 +01:00
'class' => 'invert_filter main_menu_icon' ,
2023-01-23 11:07:34 +01:00
]
) . '</a>' ,
'active' => ( bool ) ( $tab != 'Attachments' ),
],
'options' => [
'text' => '<a href="' . $setup_url . '">' . html_print_image (
2023-02-22 14:19:57 +01:00
'images/file-collection@svg.svg' ,
2023-01-23 11:07:34 +01:00
true ,
[
'title' => __ ( 'Attachments' ),
2023-02-22 14:19:57 +01:00
'class' => 'invert_filter main_menu_icon' ,
2023-01-23 11:07:34 +01:00
]
) . '</a>' ,
'active' => ( bool ) ( $tab == 'Attachments' ),
],
];
if ( $tab === 'Attachments' ) {
$helpHeader = '' ;
$titleHeader = __ ( 'Index of attachment/plugin' );
} else {
$helpHeader = 'servers_ha_clusters_tab' ;
$titleHeader = __ ( 'Plug-ins registered on %s' , get_product_name ());
}
// Header.
ui_print_standard_header (
$titleHeader ,
2019-04-29 14:36:02 +02:00
'images/gm_servers.png' ,
false ,
2023-01-23 11:07:34 +01:00
$helpHeader ,
false ,
$tabs ,
[
[
'link' => '' ,
'label' => __ ( 'Servers' ),
],
[
2023-01-23 11:19:59 +01:00
'link' => '' ,
2023-01-23 11:07:34 +01:00
'label' => __ ( 'Plugins' ),
],
]
2019-04-29 14:36:02 +02:00
);
2019-01-30 16:18:44 +01:00
2021-06-03 10:16:29 +02:00
$management_allowed = is_management_allowed ();
if ( $management_allowed === false ) {
2019-02-22 14:26:58 +01:00
ui_print_warning_message (
__ (
' This console is not manager of this environment ,
please manage this feature from centralized manager console ( Metaconsole ) . '
)
);
}
2019-01-30 16:18:44 +01:00
$is_windows = strtoupper ( substr ( PHP_OS , 0 , 3 )) == 'WIN' ;
if ( $is_windows ) {
echo '<div class="notify">' ;
echo __ ( 'You need to create your own plugins with Windows compatibility' );
echo '</div>' ;
}
}
2019-02-26 12:23:46 +01:00
// Update plugin.
2019-01-30 16:18:44 +01:00
if ( isset ( $_GET [ 'update_plugin' ])) {
$plugin_id = get_parameter ( 'update_plugin' , 0 );
$plugin_name = get_parameter ( 'form_name' , '' );
$plugin_description = get_parameter ( 'form_description' , '' );
$plugin_max_timeout = get_parameter ( 'form_max_timeout' , '' );
$plugin_execute = get_parameter ( 'form_execute' , '' );
$plugin_plugin_type = get_parameter ( 'form_plugin_type' , '0' );
$parameters = get_parameter ( 'form_parameters' , '' );
// Get macros
$i = 1 ;
$macros = [];
while ( 1 ) {
$macro = ( string ) get_parameter ( 'field' . $i . '_macro' );
if ( $macro == '' ) {
break ;
}
$desc = ( string ) get_parameter ( 'field' . $i . '_desc' );
$help = ( string ) get_parameter ( 'field' . $i . '_help' );
$value = ( string ) get_parameter ( 'field' . $i . '_value' );
$hide = get_parameter ( 'field' . $i . '_hide' );
$macros [ $i ][ 'macro' ] = $macro ;
$macros [ $i ][ 'desc' ] = $desc ;
$macros [ $i ][ 'help' ] = $help ;
if ( $hide == 1 ) {
$macros [ $i ][ 'value' ] = io_input_password ( $value );
} else {
$macros [ $i ][ 'value' ] = $value ;
}
$macros [ $i ][ 'hide' ] = $hide ;
$i ++ ;
}
$macros = io_json_mb_encode ( $macros );
$values = [
'name' => $plugin_name ,
'description' => $plugin_description ,
'max_timeout' => $plugin_max_timeout ,
'execute' => $plugin_execute ,
'plugin_type' => $plugin_plugin_type ,
'parameters' => $parameters ,
'macros' => $macros ,
];
$result = false ;
if ( $values [ 'name' ] != '' && $values [ 'execute' ] != '' ) {
$result = db_process_sql_update (
'tplugin' ,
$values ,
[ 'id' => $plugin_id ]
);
}
if ( ! $result ) {
ui_print_error_message ( __ ( 'Problem updating plugin' ));
} else {
ui_print_success_message ( __ ( 'Plugin updated successfully' ));
}
}
// Create plugin
if ( isset ( $_GET [ 'create_plugin' ])) {
$plugin_name = get_parameter ( 'form_name' , '' );
$plugin_description = get_parameter ( 'form_description' , '' );
$plugin_max_timeout = get_parameter ( 'form_max_timeout' , '' );
$plugin_execute = get_parameter ( 'form_execute' , '' );
$plugin_plugin_type = get_parameter ( 'form_plugin_type' , '0' );
$plugin_parameters = get_parameter ( 'form_parameters' , '' );
// Get macros
$i = 1 ;
$macros = [];
while ( 1 ) {
$macro = ( string ) get_parameter ( 'field' . $i . '_macro' );
if ( $macro == '' ) {
break ;
}
$desc = ( string ) get_parameter ( 'field' . $i . '_desc' );
$help = ( string ) get_parameter ( 'field' . $i . '_help' );
$value = ( string ) get_parameter ( 'field' . $i . '_value' );
$hide = get_parameter ( 'field' . $i . '_hide' );
$macros [ $i ][ 'macro' ] = $macro ;
$macros [ $i ][ 'desc' ] = $desc ;
$macros [ $i ][ 'help' ] = $help ;
if ( $hide == 1 ) {
$macros [ $i ][ 'value' ] = io_input_password ( $value );
} else {
$macros [ $i ][ 'value' ] = $value ;
}
$macros [ $i ][ 'hide' ] = $hide ;
$i ++ ;
}
$macros = io_json_mb_encode ( $macros );
$values = [
'name' => $plugin_name ,
'description' => $plugin_description ,
'max_timeout' => $plugin_max_timeout ,
'execute' => $plugin_execute ,
'plugin_type' => $plugin_plugin_type ,
'parameters' => $plugin_parameters ,
'macros' => $macros ,
];
$result = false ;
if ( $values [ 'name' ] != '' && $values [ 'execute' ] != '' ) {
$result = db_process_sql_insert ( 'tplugin' , $values );
}
if ( ! $result ) {
ui_print_error_message ( __ ( 'Problem creating plugin' ));
} else {
ui_print_success_message ( __ ( 'Plugin created successfully' ));
}
}
if ( isset ( $_GET [ 'kill_plugin' ])) {
// if delete alert
$plugin_id = get_parameter ( 'kill_plugin' , 0 );
$result = db_process_sql_delete ( 'tplugin' , [ 'id' => $plugin_id ]);
2019-02-22 14:26:58 +01:00
if ( ! is_metaconsole ()) {
if ( ! $result ) {
ui_print_error_message ( __ ( 'Problem deleting plugin' ));
} else {
ui_print_success_message ( __ ( 'Plugin deleted successfully' ));
}
2019-01-30 16:18:44 +01:00
}
2021-06-16 18:18:38 +02:00
if (( int ) $plugin_id > 0 ) {
// Delete all iformation related with this plugin.
$result = plugins_delete_plugin ( $plugin_id );
if ( empty ( $result ) === false ) {
ui_print_error_message (
implode ( '<br>' , $result )
);
} else {
ui_print_success_message ( __ ( 'Plugin deleted successfully' ));
2019-02-22 14:26:58 +01:00
}
}
}
2021-06-16 17:26:19 +02:00
// If not edition or insert, then list available plugins.
2019-01-30 16:18:44 +01:00
$rows = db_get_all_rows_sql ( 'SELECT * FROM tplugin ORDER BY name' );
if ( $rows !== false ) {
2023-02-22 14:19:57 +01:00
$pluginTable = new stdClass ();
$pluginTable -> id = 'plugin_table' ;
2023-02-22 17:41:19 +01:00
$pluginTable -> class = ( is_metaconsole () === true ) ? 'databox data' : 'info_table' ;
2023-02-22 14:19:57 +01:00
$pluginTable -> head = [];
$pluginTable -> head [ 0 ] = __ ( 'Name' );
$pluginTable -> head [ 1 ] = __ ( 'Type' );
$pluginTable -> head [ 2 ] = __ ( 'Command' );
if ( $management_allowed === true ) {
$pluginTable -> head [ 3 ] = '<span title="' . __ ( 'Operations' ) . '">' . __ ( 'Op.' ) . '</span>' ;
2019-02-22 14:26:58 +01:00
}
2023-02-22 14:19:57 +01:00
$pluginTable -> data = [];
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
foreach ( $rows as $k => $row ) {
if ( $management_allowed === true ) {
$tableActionButtons = [];
$pluginNameContent = html_print_anchor (
[
'href' => 'index.php?sec=$sec&sec2=godmode/servers/plugin&view=' . $row [ 'id' ] . '&tab=plugins&pure=' . $config [ 'pure' ],
'content' => $row [ 'name' ],
],
true
);
2019-02-22 14:26:58 +01:00
2023-02-22 14:19:57 +01:00
// Show it is locket.
2019-02-22 14:26:58 +01:00
$modules_using_plugin = db_get_value_filter (
'count(*)' ,
'tagente_modulo' ,
[
'delete_pending' => 0 ,
'id_plugin' => $row [ 'id' ],
]
);
$components_using_plugin = db_get_value_filter (
'count(*)' ,
'tnetwork_component' ,
[ 'id_plugin' => $row [ 'id' ]]
);
if (( $components_using_plugin + $modules_using_plugin ) > 0 ) {
2023-02-22 14:19:57 +01:00
$tableActionButtons [] = html_print_anchor (
[
'href' => 'javascript: show_locked_dialog(' . $row [ 'id' ] . ', \'' . $row [ 'name' ] . '\');' ,
'content' => html_print_image (
'images/policy@svg.svg' ,
true ,
[
'title' => __ ( 'Lock' ),
2023-02-22 16:24:11 +01:00
'class' => 'invert_filter main_menu_icon' ,
2023-02-22 14:19:57 +01:00
]
),
],
true
);
2019-02-22 14:26:58 +01:00
}
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
$tableActionButtons [] = html_print_anchor (
2021-03-11 15:40:23 +01:00
[
2023-02-22 14:19:57 +01:00
'href' => 'index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&view=' . $row [ 'id' ] . '&tab=plugins&pure=' . $config [ 'pure' ],
'content' => html_print_image (
'images/edit.svg' ,
true ,
[
'title' => __ ( 'Edit' ),
'class' => 'invert_filter main_menu_icon ' ,
]
),
],
true
);
2022-09-08 15:18:48 +02:00
if (( bool ) $row [ 'no_delete' ] === false ) {
2023-02-22 14:19:57 +01:00
$tableActionButtons [] = html_print_anchor (
2022-09-08 15:18:48 +02:00
[
2023-02-22 14:19:57 +01:00
'href' => 'index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&kill_plugin=' . $row [ 'id' ] . '&tab=plugins&pure=' . $config [ 'pure' ],
'onClick' => 'javascript: if (!confirm(\'' . __ ( 'All the modules that are using this plugin will be deleted' ) . '. ' . __ ( 'Are you sure?' ) . '\')) return false;' ,
'content' => html_print_image (
'images/delete.svg' ,
true ,
[
'title' => __ ( 'Delete' ),
'class' => 'invert_filter main_menu_icon' ,
]
),
],
true
);
2022-09-08 15:18:48 +02:00
}
2023-02-22 14:19:57 +01:00
} else {
$pluginNameContent = $row [ 'name' ];
2019-01-30 16:18:44 +01:00
}
2023-02-22 14:19:57 +01:00
$pluginTable -> data [ $k ][ 0 ] = $pluginNameContent ;
$pluginTable -> data [ $k ][ 1 ] = (( int ) $row [ 'plugin_type' ] === 0 ) ? __ ( 'Standard' ) : __ ( 'Nagios' );
$pluginTable -> data [ $k ][ 2 ] = $row [ 'execute' ];
if ( $management_allowed === true ) {
$pluginTable -> data [ $k ][ 3 ] = html_print_div (
[
'class' => 'table_action_buttons' ,
'content' => implode ( '' , $tableActionButtons ),
],
true
);
}
2019-01-30 16:18:44 +01:00
}
2023-02-22 14:19:57 +01:00
html_print_table ( $pluginTable );
2019-01-30 16:18:44 +01:00
} else {
ui_print_info_message ([ 'no_close' => true , 'message' => __ ( 'There are no plugins in the system' ) ]);
}
2023-02-22 14:19:57 +01:00
if ( $management_allowed === true ) {
echo '<form name="plugin" method="POST" action="index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&create=1&pure=' . $config [ 'pure' ] . '">' ;
html_print_action_buttons (
html_print_submit_button (
__ ( 'Add plugin' ),
'crtbutton' ,
false ,
[ 'icon' => 'wand' ],
true
),
[ 'type' => 'form_action' ]
);
2019-01-30 16:18:44 +01:00
2023-02-22 14:19:57 +01:00
echo '</form>' ;
2019-02-22 14:26:58 +01:00
}
2019-01-30 16:18:44 +01:00
2023-02-02 17:06:28 +01:00
// The '%s' will be replaced in the javascript code of the function 'show_locked_dialog'.
2021-03-11 15:40:23 +01:00
echo " <div id='dialog_locked' title=' " . __ ( 'List of modules and components created by "%s" ' ) . " ' class='invisible left'> " ;
2019-01-30 16:18:44 +01:00
echo '</div>' ;
2008-04-23 22:01:37 +02:00
}
2012-08-14 14:52:29 +02:00
ui_require_javascript_file ( 'pandora_modules' );
2008-04-23 22:01:37 +02:00
?>
2012-08-14 14:52:29 +02:00
< script type = " text/javascript " >
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
var locked = < ? php echo ( int ) json_encode (( int ) $locked ); ?> ;
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
function update_preview () {
2023-02-22 14:19:57 +01:00
var command = $ ( '#text-form_execute' ) . val ();
var parameters = $ ( '#text-form_parameters' ) . val ();
2019-01-30 16:18:44 +01:00
var i = 1 ;
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
while ( 1 ) {
if ( $ ( '#text-field' + i + '_value' ) . val () == undefined ) {
break ;
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
if ( $ ( '#text-field' + i + '_value' ) . val () != '' ) {
parameters = parameters
. replace ( '_field' + i + '_' ,
$ ( '#text-field' + i + '_value' ) . val ());
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
i ++ ;
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
$ ( '#command_preview' ) . html ( _ . escape ( command ) + ' ' + _ . escape ( parameters ));
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
function show_locked_dialog ( id_plugin , plugin_name ) {
var parameters = {};
parameters [ 'page' ] = " godmode/servers/plugin " ;
parameters [ " get_list_modules_and_component_locked_plugin " ] = 1 ;
parameters [ " id_plugin " ] = id_plugin ;
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
$ . ajax ({
type : " POST " ,
url : " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
data : parameters ,
dataType : " html " ,
success : function ( data ) {
2023-02-02 17:06:28 +01:00
var title = 'List of modules and components created by "' + plugin_name + '"' ;
2019-01-30 16:18:44 +01:00
$ ( " #dialog_locked " )
. html ( data )
. dialog ({
2023-02-02 17:06:28 +01:00
title : title ,
2019-01-30 16:18:44 +01:00
resizable : true ,
draggable : true ,
modal : true ,
overlay : {
opacity : 0.5 ,
background : " black "
},
width : 650 ,
height : 500
})
. show ();
}
});
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
$ ( document ) . ready ( function () {
// Add macro
var add_macro_click_event = function ( event ) {
new_macro ( 'table-form-plugin_' , function () {
// Remove the locked images and enable the inputs
if ( arguments . length > 0 ) {
var rows = _ . toArray ( arguments );
_ . each ( rows , function ( row , index ) {
row . find ( 'input.command_macro, textarea.command_macro' )
. prop ( 'readonly' , false )
. prop ( 'disabled' , false )
. siblings ( 'img.command_macro.lock' )
. remove ();
});
}
});
update_preview ();
}
2022-11-10 14:19:01 +01:00
if ( locked === 0 ) {
$ ( 'a#add_macro_btn' ) . click ( add_macro_click_event );
}
2019-01-30 16:18:44 +01:00
// Delete macro
var delete_macro_click_event = function ( event ) {
delete_macro_form ( 'table-form-plugin_' );
update_preview ();
}
$ ( 'div#delete_macro_button>a' ) . click ( delete_macro_click_event );
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
update_preview ();
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
$ ( '.command_component' ) . keyup ( function () {
update_preview ();
});
});
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
var add_macro_click_locked_event = function ( event ) {
var message = '<?php echo __(' Some modules or components are using the plugin '); ?>.'
+ '\n' + '<?php echo __(' The modules or components should be updated manually or using the bulk operations for plugins after this change '); ?>.'
+ '\n'
+ '\n' + '<?php echo __(' Are you sure you want to perform this action ? '); ?>' ;
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
if ( ! confirm ( message )) {
event . stopImmediatePropagation ();
event . preventDefault ();
}
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
var macros_click_locked_event = function ( event ) {
2019-05-14 11:11:27 +02:00
alert ( " <?php echo __('The plugin macros cannot be updated because some modules or components are using the plugin'); ?> " );
2019-01-30 16:18:44 +01:00
}
2023-02-02 17:06:28 +01:00
2019-01-30 16:18:44 +01:00
if ( locked ) {
$ ( 'a#add_macro_btn' ) . click ( add_macro_click_locked_event );
}
2023-02-02 17:06:28 +01:00
2012-08-14 14:52:29 +02:00
</ script >