2014-03-18 Alejandro Gallardo <alejandro.gallardo@artica.es>

* pandoradb.data.oracle.sql,
	  pandoradb.data.postgreSQL.sql,
	  pandoradb.sql,
	  extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql,
	  extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql,
	  extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql:
	Added the table "tmodule_relationship".

	* operation/agentes/estado_generalagente.php: Added a
	new table to show the network interfaces of the agent.
	Minor fixes.

	* include/styles/pandora.css: Added properties for the
	class transparent'.

	* include/ajax/module.php: Fixed an error and added code
	to retrieve a module autocomplete input or add, remove
	or update a module relation via ajax.

	* include/functions_modules.php: Added the functions
	"modules_get_relations", "modules_relation_exists",
	"modules_add_relation", "modules_delete_relation" and
	"modules_change_relation_lock".
	
	* godmode/agentes/module_manager_editor_common.php:
	Added a table and control to show, add or delete
	relations with other modules. Added the javascript
	functions "change_modules_autocomplete_input",
	"add_new_relation", "change_lock_relation" and
	"delete_relation".

	* godmode/agentes/module_manager_editor.php: Added a
	line to show the module relations table and control.

	* godmode/agentes/module_manager_editor_network.php:
	Minor fix.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9610 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
alexhigh 2014-03-18 11:49:33 +00:00
parent e2059d9f5e
commit a2a6875091
14 changed files with 773 additions and 30 deletions

View File

@ -1,3 +1,42 @@
2014-03-18 Alejandro Gallardo <alejandro.gallardo@artica.es>
* pandoradb.data.oracle.sql,
pandoradb.data.postgreSQL.sql,
pandoradb.sql,
extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql,
extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql,
extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql:
Added the table "tmodule_relationship".
* operation/agentes/estado_generalagente.php: Added a
new table to show the network interfaces of the agent.
Minor fixes.
* include/styles/pandora.css: Added properties for the
class transparent'.
* include/ajax/module.php: Fixed an error and added code
to retrieve a module autocomplete input or add, remove
or update a module relation via ajax.
* include/functions_modules.php: Added the functions
"modules_get_relations", "modules_relation_exists",
"modules_add_relation", "modules_delete_relation" and
"modules_change_relation_lock".
* godmode/agentes/module_manager_editor_common.php:
Added a table and control to show, add or delete
relations with other modules. Added the javascript
functions "change_modules_autocomplete_input",
"add_new_relation", "change_lock_relation" and
"delete_relation".
* godmode/agentes/module_manager_editor.php: Added a
line to show the module relations table and control.
* godmode/agentes/module_manager_editor_network.php:
Minor fix.
2014-03-17 Vanessa Gil <vanessa.gil@artica.es> 2014-03-17 Vanessa Gil <vanessa.gil@artica.es>
* pandoradb.sql * pandoradb.sql

View File

@ -41,3 +41,19 @@ ALTER TABLE tgraph_source MODIFY COLUMN `weight` float(8,3) NOT NULL DEFAULT 0;
-- Table `tagente_modulo` -- Table `tagente_modulo`
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE `pandora`.`tagente_modulo` MODIFY COLUMN `post_process` DOUBLE DEFAULT NULL; ALTER TABLE `pandora`.`tagente_modulo` MODIFY COLUMN `post_process` DOUBLE DEFAULT NULL;
/* 2014/03/18 */
-- ----------------------------------------------------------------------
-- Table `tmodule_relationship`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tmodule_relationship` (
`id` int(10) unsigned NOT NULL auto_increment,
`module_a` int(10) unsigned NOT NULL,
`module_b` int(10) unsigned NOT NULL,
`disable_update` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
FOREIGN KEY (`module_a`) REFERENCES tagente_modulo(`id_agente_modulo`)
ON DELETE CASCADE,
FOREIGN KEY (`module_b`) REFERENCES tagente_modulo(`id_agente_modulo`)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -30,3 +30,20 @@ INSERT INTO tconfig (token, value) VALUES ('graph_color10', '#6666FF');
UPDATE tconfig SET value='#FFFF00' WHERE token='graph_color2'; UPDATE tconfig SET value='#FFFF00' WHERE token='graph_color2';
UPDATE tconfig SET value='#FF6600' WHERE token='graph_color3'; UPDATE tconfig SET value='#FF6600' WHERE token='graph_color3';
/* 2014/03/18 */
-- ----------------------------------------------------------------------
-- Table `tmodule_relationship`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS tmodule_relationship (
id NUMBER(10, 0) NOT NULL PRIMARY KEY,
module_a NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo)
ON DELETE CASCADE,
module_b NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo)
ON DELETE CASCADE,
disable_update NUMBER(1, 0) default 0 NOT NULL
);
CREATE SEQUENCE tmodule_relationship_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER tmodule_relationship_inc BEFORE INSERT ON tmodule_relationship REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_relationship_s.nextval INTO :NEW.ID FROM dual; END;;

View File

@ -31,3 +31,16 @@ INSERT INTO "tconfig" ("token", "value") VALUES
UPDATE "tconfig" SET "value"='#FFFF00' WHERE "token"='graph_color2'; UPDATE "tconfig" SET "value"='#FFFF00' WHERE "token"='graph_color2';
UPDATE "tconfig" SET "value"='#FF6600' WHERE "token"='graph_color3'; UPDATE "tconfig" SET "value"='#FF6600' WHERE "token"='graph_color3';
/* 2014/03/18 */
-- ----------------------------------------------------------------------
-- Table `tmodule_relationship`
-- ----------------------------------------------------------------------
CREATE TABLE "tmodule_relationship" (
"id" SERIAL NOT NULL PRIMARY KEY,
"module_a" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo")
ON DELETE CASCADE,
"module_b" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo")
ON DELETE CASCADE,
"disable_update" SMALLINT NOT NULL default 0
);

View File

@ -430,6 +430,7 @@ html_print_table ($table_simple);
ui_toggle(html_print_table ($table_advanced, true), __('Advanced options')); ui_toggle(html_print_table ($table_advanced, true), __('Advanced options'));
ui_toggle(html_print_table ($table_macros, true), __('Module macros') . ui_print_help_icon ('module_macros', true)); ui_toggle(html_print_table ($table_macros, true), __('Module macros') . ui_print_help_icon ('module_macros', true));
ui_toggle(html_print_table ($table_new_relations, true) . html_print_table ($table_relations, true), __('Module relations'));
// Submit // Submit

View File

@ -519,6 +519,106 @@ $macro_count++;
html_print_input_hidden ('module_macro_count', $macro_count); html_print_input_hidden ('module_macro_count', $macro_count);
/* Advanced form part */
// Add relationships
$table_new_relations = new stdClass();
$table_new_relations->id = 'module_new_relations';
$table_new_relations->width = '98%';
$table_new_relations->class = 'databox_color';
$table_new_relations->data = array ();
$table_new_relations->style = array ();
$table_new_relations->style[0] = 'width: 10%; font-weight: bold;';
$table_new_relations->style[1] = 'width: 25%; text-align: center;';
$table_new_relations->style[2] = 'width: 10%; font-weight: bold;';
$table_new_relations->style[3] = 'width: 25%; text-align: center;';
$table_new_relations->style[4] = 'width: 30%; text-align: center;';
$table_new_relations->data[0][0] = __('Agent');
$params = array();
$params['return'] = true;
$params['show_helptip'] = true;
$params['input_name'] = 'autocomplete_agent_name';
$params['use_hidden_input_idagent'] = true;
$params['print_hidden_input_idagent'] = true;
$params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent';
$params['javascript_function_action_after_select_js_call'] = 'change_modules_autocomplete_input();';
$table_new_relations->data[0][1] = ui_print_agent_autocomplete_input($params);
$table_new_relations->data[0][2] = __('Module');
$table_new_relations->data[0][3] = "<div id='module_autocomplete'></div>";
$table_new_relations->data[0][4] = html_print_button (__('Add relationship'), 'add_relation', false, 'javascript: add_new_relation();', 'class="sub add"', true);
$table_new_relations->data[0][4] .= "&nbsp;&nbsp;<div id='add_relation_status' style='display: inline;'></div>";
// Relationship list
$table_relations = new stdClass();
$table_relations->id = 'module_relations';
$table_relations->width = '98%';
$table_relations->class = 'databox';
$table_relations->head = array ();
$table_relations->data = array ();
$table_relations->rowstyle = array ();
$table_relations->rowstyle[-1] = 'display: none;';
$table_relations->style = array ();
$table_relations->style[2] = 'width: 10%; text-align: center;';
$table_relations->style[3] = 'width: 10%; text-align: center;';
$table_relations->head[0] = __('Agent');
$table_relations->head[1] = __('Module');
$table_relations->head[2] = __('Changes');
$table_relations->head[3] = __('Delete');
// Create an invisible row to use their html to add new rows
$table_relations->data[-1][0] = "";
$table_relations->data[-1][1] = "";
$table_relations->data[-1][2] = '<a id="disable_updates_button" class="transparent" href="">' . html_print_image('images/lock.png', true) . '</a>';
$table_relations->data[-1][3] = '<a id="delete_relation_button" href="">' . html_print_image('images/cross.png', true) . '</a>';
$module_relations = modules_get_relations(array('id_module' => $id_agent_module));
if (!$module_relations) {
$module_relations = array();
}
$relations_count = 0;
foreach ($module_relations as $key => $module_relation) {
if ($module_relation['module_a'] == $id_agent_module) {
$module_id = $module_relation['module_b'];
$agent_id = modules_give_agent_id_from_module_id ($module_relation['module_b']);
} else {
$module_id = $module_relation['module_a'];
$agent_id = modules_give_agent_id_from_module_id ($module_relation['module_a']);
}
$agent_name = ui_print_agent_name ($agent_id, true);
$module_name = modules_get_agentmodule_name($module_id);
if (empty($module_name) || $module_name == 'false') {
$module_name = $module_id;
}
if ($module_relation['disable_update']) {
$disabled_update_class = "";
} else {
$disabled_update_class = "transparent";
}
// Agent name
$table_relations->data[$relations_count][0] = $agent_name;
// Module name
$table_relations->data[$relations_count][1] = "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=" . $agent_id .
"&tab=module&edit_module=1&id_agent_module=" . $module_id . "'>" .
ui_print_truncate_text($module_name, 'module_medium', true, true, true, '[&hellip;]') . "</a>";
// Lock relationship updates
$table_relations->data[$relations_count][2] = '<a id="disable_updates_button" class="' . $disabled_update_class . '"
href="javascript: change_lock_relation(' . $relations_count . ', ' . $module_relation['id'] . ');">'
. html_print_image('images/lock.png', true) . '</a>';
// Delete relationship
$table_relations->data[$relations_count][3] = '<a id="delete_relation_button" href="javascript: delete_relation(' . $relations_count . ', ' . $module_relation['id'] . ');">'
. html_print_image('images/cross.png', true) . '</a>';
$relations_count++;
}
html_print_input_hidden ('module_relations_count', $relations_count);
ui_require_jquery_file('json'); ui_require_jquery_file('json');
?> ?>
@ -589,6 +689,14 @@ $(document).ready (function () {
}); });
$("#id_module_type").trigger('change'); $("#id_module_type").trigger('change');
// Prevent the form submission when the user hits the enter button from the relationship autocomplete inputs
$("#text-autocomplete_agent_name").keydown(function(event){
if(event.keyCode == 13) { // key code 13 is the enter button
event.preventDefault();
}
});
}); });
// Add a new module macro // Add a new module macro
@ -616,5 +724,197 @@ function delete_macro (num) {
// Do not decrease the macro counter or new macros may overlap existing ones! // Do not decrease the macro counter or new macros may overlap existing ones!
} }
/* Relationship javascript */
// Change the modules autocomplete input depending on the result of the agents autocomplete input
function change_modules_autocomplete_input () {
var id_agent = parseInt($("#hidden-autocomplete_id_agent").val());
var module_autocomplete = $("#module_autocomplete");
var load_icon = '<?php html_print_image ("images/spinner.gif", false) ?>';
var error_icon = '<?php html_print_image ("images/error_red.png", false) ?>';
if (!module_autocomplete.hasClass('working')) {
module_autocomplete.addClass('working');
module_autocomplete.html(load_icon);
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "html",
data: {
page: "include/ajax/module",
get_module_autocomplete_input: true,
id_agent: id_agent
},
success: function (data) {
module_autocomplete.removeClass('working');
if (data) {
module_autocomplete.html(data);
// Prevent the form submission when the user hits the enter button from the relationship autocomplete inputs
$("#text-autocomplete_module_name").keydown(function(event){
if(event.keyCode == 13) { // key code 13 is the enter button
event.preventDefault();
}
});
} else {
module_autocomplete.html(error_icon);
}
},
error: function (data) {
module_autocomplete.removeClass('working');
module_autocomplete.html(error_icon);
}
});
}
}
// Add a new relation
function add_new_relation () {
var module_a_id = parseInt($("#hidden-id_agent_module").val());
var module_b_name = $("#text-autocomplete_module_name").val();
var agent_b_name = $("#text-autocomplete_agent_name").val();
var hiddenRow = $("#module_relations--1");
var button = $("#button-add_relation");
var iconPlaceholder = $("#add_relation_status");
var load_icon = '<?php html_print_image ("images/spinner.gif", false, array("style"=>"vertical-align:middle;")) ?>';
var suc_icon = '<?php html_print_image ("images/ok.png", false, array("style"=>"vertical-align:middle;")) ?>';
var error_icon = '<?php html_print_image ("images/error_red.png", false, array("style"=>"vertical-align:middle;")) ?>';
if (!button.hasClass('working')) {
button.addClass('working');
iconPlaceholder.html(load_icon);
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
data: {
page: "include/ajax/module",
add_module_relation: true,
id_module_a: module_a_id,
name_module_b: module_b_name
},
success: function (data) {
button.removeClass('working');
if (data === false) {
iconPlaceholder.html(error_icon);
setTimeout( function() { iconPlaceholder.html(''); }, 2000);
} else {
iconPlaceholder.html(suc_icon);
setTimeout( function() { iconPlaceholder.html(''); }, 2000);
// Add the new row
var relationsCount = parseInt($("#hidden-module_relations_count").val());
var rowClass = "datos";
if (relationsCount % 2 != 0) {
rowClass = "datos2";
}
var rowHTML = '<tr id="module_relations-' + relationsCount + '" class="' + rowClass + '">' +
'<td id="module_relations-' + relationsCount + '-0"><b>' + agent_b_name + '</b></td>' +
'<td id="module_relations-' + relationsCount + '-1">' + module_b_name + '</td>' +
'<td id="module_relations-' + relationsCount + '-2" style="width: 10%; text-align: center;">' +
'<a id="disable_updates_button" class="transparent" href="javascript: change_lock_relation(' + relationsCount + ', ' + data + ');">' +
'<?php echo html_print_image("images/lock.png", true); ?>' +
'</a>' +
'</td>' +
'<td id="module_relations-' + relationsCount + '-3" style="width: 10%; text-align: center;">' +
'<a id="delete_relation_button" href="javascript: delete_relation(' + relationsCount + ', ' + data + ');">' +
'<?php echo html_print_image("images/cross.png", true); ?>' +
'</a>' +
'</td>' +
'</tr>';
$("#module_relations").find("tbody").append(rowHTML);
$("#hidden-module_relations_count").val(relationsCount + 1);
$("#text-autocomplete_module_name").val('');
}
},
error: function (data) {
button.removeClass('working');
iconPlaceholder.html(error_icon);
setTimeout( function() { iconPlaceholder.html(''); }, 2000);
}
});
}
}
// Delete an existing relation
function change_lock_relation (num_row, id_relation) {
var row = $("#module_relations-" + num_row);
var button = row.find("#disable_updates_button");
var oldSrc = button.find("img").prop("src");
var isEnabled = button.hasClass('transparent');
if (row.length > 0 && !button.hasClass('working')) {
button.addClass('working');
button.removeClass('transparent');
button.find("img").prop("src", 'images/spinner.gif');
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
data: {
page: "include/ajax/module",
change_module_relation_updates: true,
id_relation: id_relation
},
success: function (data) {
if (data === false) {
button.addClass('transparent');
}
button.removeClass('working');
button.find("img").prop("src", oldSrc);
},
error: function (data) {
if (isEnabled) {
button.addClass('transparent');
}
button.removeClass('working');
button.find("img").prop("src", oldSrc);
}
});
}
}
// Delete an existing relation
function delete_relation (num_row, id_relation) {
var row = $("#module_relations-" + num_row);
var button = row.find("#delete_relation_button");
var oldSrc = button.find("img").prop("src");
if (row.length > 0 && !button.hasClass('working')) {
button.addClass('working');
button.find("img").prop("src", 'images/spinner.gif');
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
data: {
page: "include/ajax/module",
remove_module_relation: true,
id_relation: id_relation
},
success: function (data) {
button.removeClass('working');
button.find("img").prop("src", oldSrc);
if (data === true) {
row.remove();
}
},
error: function (data) {
button.removeClass('working');
button.find("img").prop("src", oldSrc);
}
});
}
}
/* End of relationship javascript */
/* ]]> */ /* ]]> */
</script> </script>

View File

@ -125,7 +125,7 @@ push_table_simple ($data, 'snmp_2');
$data = array (); $data = array ();
$data[0] = __('TCP send') . ' ' . ui_print_help_icon ("tcp_send", true); $data[0] = __('TCP send') . ' ' . ui_print_help_icon ("tcp_send", true);
$data[1] = html_print_textarea ('tcp_send', 2, 65, $tcp_send, $disabledTextBecauseInPolicy, true); $data[1] = html_print_textarea ('tcp_send', 2, 65, $tcp_send, $disabledTextBecauseInPolicy, true);
$table_advanced->colspan['tcp_send'][1] = 3; $table_simple->colspan['tcp_send'][1] = 3;
push_table_simple ($data, 'tcp_send'); push_table_simple ($data, 'tcp_send');

View File

@ -18,6 +18,7 @@ global $config;
include_once($config['homedir'] . "/include/functions_agents.php"); include_once($config['homedir'] . "/include/functions_agents.php");
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_ui.php");
enterprise_include_once ('include/functions_metaconsole.php'); enterprise_include_once ('include/functions_metaconsole.php');
@ -51,11 +52,17 @@ if ($search_modules) {
$modules = io_safe_output($modules); $modules = io_safe_output($modules);
echo json_encode($modules); echo json_encode($modules);
return;
} }
$get_module_detail = get_parameter ('get_module_detail', 0); $get_module_detail = get_parameter ('get_module_detail', 0);
if ($get_module_detail) { if ($get_module_detail) {
ui_require_jquery_file ("ui-timepicker-addon");
// This script is included manually to be included after jquery and avoid error
echo '<script type="text/javascript" src="' . ui_get_full_url('include/javascript/i18n/jquery-ui-timepicker-' . get_user_language(), false, false, false) . '"></script>';
ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/");
ui_require_jquery_file ("ui-timepicker-addon"); ui_require_jquery_file ("ui-timepicker-addon");
// This script is included manually to be included after jquery and avoid error // This script is included manually to be included after jquery and avoid error
@ -329,4 +336,68 @@ if ($get_module_detail) {
return; return;
} }
?>
$get_module_autocomplete_input = (bool) get_parameter('get_module_autocomplete_input');
if ($get_module_autocomplete_input) {
$id_agent = (int) get_parameter("id_agent");
ob_clean();
if ($id_agent > 0) {
html_print_autocomplete_modules('autocomplete_module_name', '', array($id_agent));
return;
}
return;
}
$add_module_relation = (bool) get_parameter('add_module_relation');
if ($add_module_relation) {
$result = false;
$id_module_a = (int) get_parameter("id_module_a");
$id_module_b = (int) get_parameter("id_module_b");
if ($id_module_a < 1) {
$name_module_a = get_parameter("name_module_a", "");
if ($name_module_a) {
$id_module_a = (int) db_get_value('id_agente_modulo', 'tagente_modulo', 'nombre', $name_module_a);
} else {
echo json_encode($result);
return;
}
}
if ($id_module_b < 1) {
$name_module_b = get_parameter("name_module_b", "");
if ($name_module_b) {
$id_module_b = (int) db_get_value('id_agente_modulo', 'tagente_modulo', 'nombre', $name_module_b);
} else {
echo json_encode($result);
return;
}
}
if ($id_module_a > 0 && $id_module_b > 0) {
$result = modules_add_relation($id_module_a, $id_module_b);
}
echo json_encode($result);
return;
}
$remove_module_relation = (bool) get_parameter('remove_module_relation');
if ($remove_module_relation) {
$id_relation = (int) get_parameter("id_relation");
if ($id_relation > 0) {
$result = (bool) modules_delete_relation($id_relation);
}
echo json_encode($result);
return;
}
$change_module_relation_updates = (bool) get_parameter('change_module_relation_updates');
if ($change_module_relation_updates) {
$id_relation = (int) get_parameter("id_relation");
if ($id_relation > 0) {
$result = (bool) modules_change_relation_lock($id_relation);
}
echo json_encode($result);
return;
}
?>

View File

@ -1763,4 +1763,145 @@ function modules_get_module_macros_json ($macro_names, $macro_values) {
return base64_encode(json_encode ($module_macros)); return base64_encode(json_encode ($module_macros));
} }
?> /**
* Returns the relations between modules.
*
* @param array Optional assoc array with parameters.
* (int) id_agent
* (int) id_module
* (bool) disabled_update
* (string) modules_type: The type of the two modules
*
* @return mixed Array with relations between modules. False if there were no data.
*/
function modules_get_relations ($params = array()) {
$id_agent = 0;
if (isset($params['id_agent'])) {
$id_agent = $params['id_agent'];
}
$id_module = 0;
if (isset($params['id_module'])) {
$id_module = $params['id_module'];
}
$disabled_update = -1;
if (isset($params['disabled_update'])) {
$disabled_update = (int) $params['disabled_update'];
if ($disabled_update > 1) {
$disabled_update = 1;
}
}
$modules_type = "";
if (isset($params['modules_type'])) {
$modules_type = $params['modules_type'];
}
$sql = "SELECT DISTINCT tmr.id, tmr.module_a, tmr.module_b, tmr.disable_update
FROM tmodule_relationship AS tmr, tagente_modulo AS tam, tagente AS ta, ttipo_modulo AS ttm
WHERE ";
$agent_filter = "";
if ($id_agent > 0) {
$agent_filter = sprintf("AND ta.id_agente = %d", $id_agent);
}
$module_a_filter = "";
$module_b_filter = "";
if ($id_module > 0) {
$module_a_filter = sprintf("AND tmr.module_a = %d", $id_module);
$module_b_filter = sprintf("AND tmr.module_b = %d", $id_module);
}
$disabled_update_filter = "";
if ($disabled_update >= 0) {
$disabled_update_filter = sprintf("AND tmr.disable_update = %d", $disabled_update);
}
$modules_type_filter = "";
if ($modules_type != "") {
$modules_type_filter = sprintf("AND (tam.id_tipo_modulo = ttm.id_tipo AND ttm.nombre = '%s')", $modules_type);
}
$sql .= "( (tmr.module_a = tam.id_agente_modulo
$module_a_filter)
OR (tmr.module_b = tam.id_agente_modulo
$module_b_filter) )
AND tam.id_agente = ta.id_agente
$agent_filter
$disabled_update_filter
$modules_type_filter";
return db_get_all_rows_sql($sql);
}
/**
* Check if a relation already exists.
*
* @param int First module id.
* @param int Second module id.
*
* @return bool True if the relation exists, false otherwise.
*/
function modules_relation_exists ($id_module_a, $id_module_b) {
$sql = sprintf("SELECT id
FROM tmodule_relationship
WHERE (module_a = %d AND module_b = %d)
OR (module_b = %d AND module_a = %d)",
$id_module_a, $id_module_b, $id_module_a, $id_module_b);
return (bool) db_get_row_sql($sql);
}
/**
* Change the 'disabled_update' value of a relation row.
*
* @param int Relation id.
*
* @return bool True if the 'disabled_update' changes to 1, false otherwise.
*/
function modules_add_relation ($id_module_a, $id_module_b) {
$result = false;
if (!modules_relation_exists($id_module_a, $id_module_b) && $id_module_a > 0 && $id_module_b > 0) {
$values = array(
'module_a' => $id_module_a,
'module_b' => $id_module_b
);
$result = db_process_sql_insert('tmodule_relationship', $values);
}
return $result;
}
/**
* Change the 'disabled_update' value of a relation row.
*
* @param int Relation id.
*
* @return bool True if the 'disabled_update' changes to 1, false otherwise.
*/
function modules_delete_relation ($id_relation) {
$result = db_process_sql_delete('tmodule_relationship', array('id' => $id_relation));
return $result;
}
/**
* Change the 'disabled_update' value of a relation row.
*
* @param int Relation id.
*
* @return bool True if the 'disabled_update' changes to 1, false otherwise.
*/
function modules_change_relation_lock ($id_relation) {
$old_value = (int) db_get_value('disable_update', 'tmodule_relationship', 'id', $id_relation);
$new_value = $old_value === 1 ? 0 : 1;
$result = db_process_sql_update('tmodule_relationship',
array('disable_update' => $new_value),
array('id' => $id_relation));
return ($result !== false ? $new_value : $old_value);
}
?>

View File

@ -1234,6 +1234,13 @@ div.title_line {
width: 762px; width: 762px;
} }
.transparent {
filter:alpha(opacity=50);
-moz-opacity: 0.5;
opacity: 0.5;
-khtml-opacity: 0.5;
}
#menu_tab_frame { #menu_tab_frame {
background:#FAFAFA; background:#FAFAFA;
} }

View File

@ -311,6 +311,101 @@ foreach ($fields as $field) {
// END: TABLE DATA BUILD // END: TABLE DATA BUILD
// START: TABLE INTERFACES
$columns = array(
"id_agente_modulo",
"nombre",
"descripcion",
"ip_target"
);
$filter = array(
"id_agente" => $id_agente,
"id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc")
);
$modules = agents_get_modules ($id_agent, $columns, $filter);
if (! empty($modules)) {
$table_interface = new stdClass();
$table_interface->id = 'agent_interface_info';
$table_interface->class = 'databox';
$table_interface->width = '100%';
$table_interface->style = array();
$table_interface->style[1] = 'width: 30px;';
$table_interface->head = array();
$options = array(
"class" => "closed",
"style" => "vertical-align:middle; cursor:pointer;"
);
$table_interface->head[0] = html_print_image("images/go.png", true, $options) . "&nbsp;&nbsp;";
$table_interface->head[0] .= '<span style="vertical-align: middle;">' . __('Interface information') .' (SNMP)</span>';
$table_interface->head_colspan = array();
$table_interface->head_colspan[0] = 4;
$table_interface->data = array();
foreach ($modules as $key => $module) {
// Trying to get the interface name from the module name
if (preg_match ("/_(\w+)/" , (string)$module['nombre'], $matches)) {
if ($matches[1]) {
$interface_name = $matches[1];
$module_id = $module['id_agente_modulo'];
$db_status = modules_get_agentmodule_status($module_id);
$module_value = modules_get_last_value ($module_id);
modules_get_status($module_id, $db_status, $module_value, $status, $title);
$status = ui_print_status_image($status, $title, true);
$ip_target = "--";
// Trying to get something like an IP from the description
if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/" , (string)$module['ip_target'], $matches)) {
if ($matches[0]) {
$ip_target = $matches[0];
}
}
$description = "--";
// Trying to get something like a mac from the description
if (preg_match ("/([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})/i" , (string)$module['descripcion'], $matches)) {
if ($matches[0]) {
$description = $matches[0];
}
}
$data = array();
$data[0] = "<strong>" . $interface_name . "</strong>";
$data[1] = $status;
$data[2] = $ip_target;
$data[3] = $description;
$table_interface->data[] = $data;
}
}
}
unset($modules);
// This javascript piece of code is used to make expandible the body of the table
?>
<script type="text/javascript">
$(document).ready (function () {
$("#agent_interface_info").find("tbody").hide();
$("#agent_interface_info").find("thead").click (function () {
var arrow = $("#agent_interface_info").find("thead").find("img");
if (arrow.hasClass("closed")) {
arrow.removeClass("closed");
arrow.prop("src", "images/down.png");
$("#agent_interface_info").find("tbody").show();
} else {
arrow.addClass("closed");
arrow.prop("src", "images/go.png");
$("#agent_interface_info").find("tbody").hide();
}
});
});
</script>
<?php
}
// END: TABLE INTERFACES
$table = null; $table = null;
$table->id = 'agent_details'; $table->id = 'agent_details';
$table->width = '98%'; $table->width = '98%';
@ -321,8 +416,30 @@ $table->style = array_fill(0, 3, 'vertical-align: top;');
$data = array(); $data = array();
$data[0] = html_print_table($table_agent, true); $data[0] = html_print_table($table_agent, true);
$data[1] = html_print_table($table_contact, true) . '<br>'; $data[0] .= '<fieldset class="databox" style="position: static;">
$data[1] .= empty($table_data->data) ? '' : html_print_table($table_data, true); <legend style="text-align:left; color: #666;">' .
__('Events (24h)') .
'</legend>' .
'<div style="margin: auto; text-align:center; width: 300px;">' .
graph_graphic_agentevents ($id_agente, 300, 15, 86400, '', true) .
'</div>' .
'</fieldset>';
// ACCESS RATE GRAPH
if ($config["agentaccess"]) {
$data[0] .= '<fieldset class="databox" style="position: static;">
<legend style="text-align:left; color: #666;">' .
__('Agent access rate (24h)') .
'</legend>' .
'<div style="margin: auto; text-align:center; width: 300px;">' .
graphic_agentaccess($id_agente, 300, 100, 86400, true) .
'</div>' .
'</fieldset>';
}
$data[1] = html_print_table($table_contact, true);
$data[1] .= empty($table_data->data) ? '' : '<br>' . html_print_table($table_data, true);
$data[1] .= !isset($table_interface) ? '' : '<br>' . html_print_table($table_interface, true);
$table->rowspan[0][1] = 2; $table->rowspan[0][1] = 2;
@ -334,33 +451,8 @@ $data[2] .= '</div>';
$table->data[] = $data; $table->data[] = $data;
$table->rowclass[] = ''; $table->rowclass[] = '';
$data = array();
$data[0] = '<fieldset class="databox" style="position: static;">
<legend style="text-align:left; color: #666;">' .
__('Events (24h)') .
'</legend>' .
'<div style="margin: auto; text-align:center; width: 300px;">' .
graph_graphic_agentevents ($id_agente, 300, 15, 86400, '', true) .
'</div>' .
'</fieldset>';
// ACCESS RATE GRAPH
if ($config["agentaccess"]) {
$data[0] .= '<fieldset class="databox" style="position: static;">
<legend style="text-align:left; color: #666;">' .
__('Agent access rate (24h)') .
'</legend>' .
'<div style="margin: auto; text-align:center; width: 300px;">' .
graphic_agentaccess($id_agente, 300, 100, 86400, true) .
'</div>' .
'</fieldset>';
}
$table->cellstyle[1][0] = 'text-align:center;'; $table->cellstyle[1][0] = 'text-align:center;';
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table); html_print_table($table);
unset($table); unset($table);
?> ?>

View File

@ -667,6 +667,25 @@ CREATE SEQUENCE tmodule_group_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER tmodule_group_inc BEFORE INSERT ON tmodule_group REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_group_s.nextval INTO :NEW.ID_MG FROM dual; END;; CREATE OR REPLACE TRIGGER tmodule_group_inc BEFORE INSERT ON tmodule_group REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_group_s.nextval INTO :NEW.ID_MG FROM dual; END;;
-- ----------------------------------------------------------------------
-- Table `tmodule_relationship`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS tmodule_relationship (
id NUMBER(10, 0) NOT NULL PRIMARY KEY,
module_a NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo)
ON DELETE CASCADE,
module_b NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo)
ON DELETE CASCADE,
disable_update NUMBER(1, 0) default 0 NOT NULL
);
CREATE SEQUENCE tmodule_relationship_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER tmodule_relationship_inc BEFORE INSERT ON tmodule_relationship REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_relationship_s.nextval INTO :NEW.ID FROM dual; END;;
-- ----------------------------------------------------------------------
-- Table `tnetwork_component`
-- ----------------------------------------------------------------------
CREATE TABLE tnetwork_component ( CREATE TABLE tnetwork_component (
id_nc NUMBER(10, 0) NOT NULL PRIMARY KEY, id_nc NUMBER(10, 0) NOT NULL PRIMARY KEY,
name CLOB NOT NULL, name CLOB NOT NULL,

View File

@ -562,6 +562,18 @@ CREATE TABLE "tmodule_group" (
"name" varchar(150) NOT NULL default '' "name" varchar(150) NOT NULL default ''
); );
-- ----------------------------------------------------------------------
-- Table `tmodule_relationship`
-- ----------------------------------------------------------------------
CREATE TABLE "tmodule_relationship" (
"id" SERIAL NOT NULL PRIMARY KEY,
"module_a" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo")
ON DELETE CASCADE,
"module_b" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo")
ON DELETE CASCADE,
"disable_update" SMALLINT NOT NULL default 0
);
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- Table `tnetwork_component` -- Table `tnetwork_component`
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------

View File

@ -616,6 +616,21 @@ CREATE TABLE IF NOT EXISTS `tmodule_group` (
PRIMARY KEY (`id_mg`) PRIMARY KEY (`id_mg`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tmodule_relationship`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tmodule_relationship` (
`id` int(10) unsigned NOT NULL auto_increment,
`module_a` int(10) unsigned NOT NULL,
`module_b` int(10) unsigned NOT NULL,
`disable_update` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
FOREIGN KEY (`module_a`) REFERENCES tagente_modulo(`id_agente_modulo`)
ON DELETE CASCADE,
FOREIGN KEY (`module_b`) REFERENCES tagente_modulo(`id_agente_modulo`)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------
-- Table `tnetwork_component` -- Table `tnetwork_component`
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------