';
//}
$table->width = '100%';
$table->class = 'databox filters';
if (defined("METACONSOLE")) {
$table->head[0] = __('General');
$table->head_colspan[0] = 4;
$table->headstyle[0] = 'text-align: center';
html_print_table($table);
}
else {
echo '';
}
$table->data = array();
$plugin_id = get_parameter ("view", 0);
$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', array('delete_pending' => 0, 'id_plugin' => $plugin_id));
$components_using_plugin = db_get_value_filter('count(*)','tnetwork_component', array('id_plugin' => $plugin_id));
if(($components_using_plugin + $modules_using_plugin) == 0) {
$locked = false;
}
}
else {
$locked = false;
}
$disabled = '';
if ($locked) {
$disabled = 'readonly="readonly"';
}
$data = array();
$data[0] = __('Plugin command');
$data[1] = '';
if ($locked) {
$data[1] .= html_print_image('images/lock.png', true, array('class' => 'command_advanced_conf lock'));
}
$data[1] .= ' ';
$data[1] .= html_print_image('images/file.png', true);
$data[1] .= '';
$table->data['plugin_command'] = $data;
$data = array();
$data[0] = __('Plug-in parameters').ui_print_help_icon ('plugin_parameters', true);
$data[1] = '';
if ($locked) {
$data[1] .= html_print_image('images/lock.png', true, array('class' => 'command_advanced_conf lock'));
}
$table->data['plugin_parameters'] = $data;
$data = array();
$data[0] = __('Command preview');
$data[1] = '';
$table->data['plugin_preview'] = $data;
$table->width = '100%';
$table->class = 'databox filters';
if (defined("METACONSOLE")) {
$table->head[0] = __('Command');
$table->head_colspan[0] = 4;
$table->headstyle[0] = 'text-align: center';
html_print_table($table);
}
else {
echo '';
}
$data = array();
$table->data = array ();
$macros = json_decode($macros,true);
// The next row number is plugin_9
$next_name_number = 9;
$i = 1;
while (1) {
// Always print at least one macro
if ((!isset($macros[$i]) || $macros[$i]['desc'] == '') && $i > 1) {
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 = array ();
$datam[0] = __('Description')." ($macro_name)";
$datam[0] .= html_print_input_hidden($macro_name_name, $macro_name, true);
$datam[1] = html_print_input_text_extended ($macro_desc_name, $macro_desc_value, 'text-'.$macro_desc_name, '', 30, 255, $locked, '', "class='command_macro'", true);
if ($locked) {
$datam[1] .= html_print_image('images/lock.png', true, array('class' => 'command_macro lock'));
}
$datam[2] = __('Default value')." ($macro_name)";
$datam[3] = html_print_input_text_extended ($macro_value_name, $macro_value_value, 'text-'.$macro_value_name, '', 30, 255, $locked, '', "class='command_component command_macro'", true);
if ($locked) {
$datam[3] .= html_print_image('images/lock.png', true, array('class' => 'command_macro lock'));
}
$table->data['plugin_'.$next_name_number] = $datam;
$next_name_number++;
$table->colspan['plugin_'.$next_name_number][1] = 3;
$datam = array ();
$datam[0] = __('Hide value') . ui_print_help_tip(__('This field will show up as dots like a password'), true);
$datam[1] = html_print_checkbox_extended ($macro_hide_value_name, 1, $macro_hide_value_value, 0, '', array('class' => 'command_macro'), true, 'checkbox-'.$macro_hide_value_name);
$table->data['plugin_'.$next_name_number] = $datam;
$next_name_number++;
$table->colspan['plugin_'.$next_name_number][1] = 3;
$datam = array ();
$datam[0] = __('Help')." ($macro_name)
";
$tadisabled = $locked === true ? ' disabled' : '';
$datam[1] = html_print_textarea ($macro_help_name, 6, 100, $macro_help_value, 'class="command_macro" style="width: 97%;"' . $tadisabled, true);
if ($locked) {
$datam[1] .= html_print_image('images/lock.png', true, array('class' => 'command_macro lock'));
}
$datam[1] .= "
";
$table->data['plugin_'.$next_name_number] = $datam;
$next_name_number++;
$i++;
}
// Add/Delete buttons
$datam = array ();
$datam[0] = '' .
'' .
__('Add macro') .
'' . ' ' .
html_print_image('images/add.png',true) .
'';
$datam[0] .= ''.$i.' ';
$datam[0] .= ''.$next_name_number.' ';
if (!$locked) {
$delete_macro_style = '';
if ($i <= 2) {
$delete_macro_style = 'display:none;';
}
$datam[2] = '';
$table->colspan['plugin_action'][0] = 2;
$table->colspan['plugin_action'][2] = 2;
}
else {
$table->colspan['plugin_action'][0] = 4;
}
$table->rowstyle['plugin_action'] = 'text-align:center';
$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 {
echo '';
}
echo '';
if (defined("METACONSOLE"))
echo ' |
';
enterprise_hook('close_meta_frame');
}
else {
enterprise_hook('open_meta_frame');
if(defined('METACONSOLE')) {
components_meta_print_header();
$sec = 'advanced';
}
else {
ui_print_page_header (__('Plugins registered in Pandora FMS'), "images/gm_servers.png", false, "", true);
$is_windows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
if ($is_windows) {
echo '';
echo __("You need to create your own plugins with Windows compatibility");
echo '
';
}
}
// Update plugin
if (isset($_GET["update_plugin"])) { // if modified any parameter
$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 = array();
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 = array(
'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,
array('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 = array();
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 = array(
'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', array('id' => $plugin_id));
if (! $result) {
ui_print_error_message(__('Problem deleting plugin'));
}
else {
ui_print_success_message(__('Plugin deleted successfully'));
}
if ($plugin_id != 0) {
// Delete all the modules with this plugin
$plugin_modules = db_get_all_rows_filter(
'tagente_modulo', array('id_plugin' => $plugin_id));
if (empty($plugin_modules))
$plugin_modules = array();
foreach ($plugin_modules as $pm) {
modules_delete_agent_module ($pm['id_agente_modulo']);
}
if (enterprise_installed()) {
enterprise_include_once('include/functions_policies.php');
$policies_ids = db_get_all_rows_filter('tpolicy_modules', array('id_plugin' => $plugin_id));
foreach($policies_ids as $policies_id) {
policies_change_delete_pending_module ($policies_id['id']);
}
}
}
}
// If not edition or insert, then list available plugins
$rows = db_get_all_rows_sql('SELECT * FROM tplugin ORDER BY name');
if ($rows !== false) {
if(defined('METACONSOLE'))
echo '