$id_plugin]);
$preload = io_safe_output($description);
$preload = str_replace("\n", '
', $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 = [];
}
$table = new stdClass();
$table->width = '100%';
$table->head[0] = __('Network Components');
// $table->data = [];
foreach ($network_components as $net_comp) {
$table->data[] = [$net_comp['name']];
}
if (empty($table->data) === false) {
html_print_table($table);
}
$table = new stdClass();
$table->width = '100%';
$table->head[0] = __('Agent');
$table->head[1] = __('Module');
foreach ($modules as $mod) {
$agent_name = ''.modules_get_agentmodule_agent_alias(
$mod['id_agente_modulo']
).'';
$table->data[] = [
$agent_name,
$mod['nombre'],
];
}
if (!empty($table->data)) {
html_print_table($table);
}
return;
}
}
require_once $config['homedir'].'/include/functions_filemanager.php';
check_login();
if (! check_acl($config['id_user'], 0, 'PM') && ! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access Plugin Management'
);
include 'general/noaccess.php';
return;
}
enterprise_include_once('meta/include/functions_components_meta.php');
$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);
$plugin_command = get_parameter('plugin_command', '');
$tab = get_parameter('tab', '');
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'];
}
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 = '';
}
// END LOAD VALUES
// =====================================================================
// INIT FILEMANAGER
// =====================================================================
if ($filemanager) {
if ($edit_file) {
$location_file = get_parameter('location_file', '');
$filename = array_pop(explode('/', $location_file));
$file = file_get_contents($location_file);
echo '
'.__('Edit file').' '.$filename.'
';
// echo "" . __('Back to file explorer') . "";
echo "';
} 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);
} else if ($is_win_compatible === false && $compatibility == 'windows') {
// If is unix compatible and the compatibility must be win
$contentFile = str_replace("\n", "\r\n", $contentFile);
}
$result = file_put_contents($location_file, $contentFile);
}
$id_plugin = (int) get_parameter('id_plugin', 0);
// Add custom directories here.
$fallback_directory = 'attachment/plugin';
// Get directory.
$directory = (string) get_parameter('directory');
if (empty($directory) === true) {
$directory = $fallback_directory;
} else {
$directory = str_replace('\\', '/', $directory);
$directory = filemanager_safe_directory($directory, $fallback_directory);
}
$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' => ''.html_print_image(
'images/see-details@svg.svg',
true,
[
'title' => __('Plugins'),
'class' => 'invert_filter main_menu_icon',
]
).'',
'active' => (bool) ($tab != 'Attachments'),
],
'options' => [
'text' => ''.html_print_image(
'images/file-collection@svg.svg',
true,
[
'title' => __('Attachments'),
'class' => 'invert_filter main_menu_icon',
]
).'',
'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,
'images/gm_servers.png',
false,
$helpHeader,
false,
$tabs,
[
[
'link' => '',
'label' => __('Servers'),
],
[
'link' => '',
'label' => __('Plugins'),
],
]
);
$real_directory = realpath($config['homedir'].'/'.$directory);
$chunck_url = '&view='.$id_plugin;
if ($id_plugin == 0) {
$chunck_url = '&create=1';
}
$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);
if ($upload_file_or_zip === true) {
upload_file($upload_file_or_zip, $default_real_directory, $real_directory);
}
if ($create_text_file === true) {
create_text_file($default_real_directory, $real_directory);
}
filemanager_file_explorer(
$real_directory,
$directory,
'index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1&id_plugin='.$id_plugin.'&tab=Attachments',
$fallback_directory,
true,
false,
'index.php?sec=gservers&sec2=godmode/servers/plugin'.$chunck_url.'&plugin_command=[FILE_FULLPATH]&id_plugin='.$id_plugin,
true,
0775,
false,
['all' => true]
);
}
return;
}
// =====================================================================
// END FILEMANAGER
// =====================================================================
// =====================================================================
// SHOW THE FORM
// =====================================================================
$sec = 'gservers';
if (empty($create) === false || empty($view) === false) {
$management_allowed = is_management_allowed();
if (is_metaconsole() === true) {
components_meta_print_header();
$sec = 'advanced';
if ($management_allowed === false) {
ui_print_warning_message(__('To manage plugin you must activate centralized management'));
}
} else {
// 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'),
],
]
);
if ($management_allowed === false) {
ui_print_warning_message(
__(
'This console is not manager of this environment,
please manage this feature from centralized manager console (Metaconsole).'
)
);
}
}
$plugin_id = (int) get_parameter('view');
$locked = true;
// 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) {
$formAction = 'index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&update_plugin='.$plugin_id.'&pure='.$config['pure'];
} else {
$formAction = 'index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&create_plugin=1&pure='.$config['pure'];
}
$formPluginType = [
0 => __('Standard'),
1 => __('Nagios'),
];
echo '';
}
// The '%s' will be replaced in the javascript code of the function 'show_locked_dialog'.
echo "";
echo '
';
}
ui_require_javascript_file('pandora_modules');
?>