Added cascade protection by module (agent, massive and api). Ticket #187

This commit is contained in:
Arturo Gonzalez 2017-01-25 13:59:14 +01:00
parent 1970167df4
commit 3c8bc86ab7
8 changed files with 195 additions and 18 deletions

View File

@ -114,6 +114,7 @@ ALTER TABLE tnetwork_component ADD COLUMN `dynamic_two_tailed` tinyint(1) unsign
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE tagente ADD `transactional_agent` tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD `transactional_agent` tinyint(1) NOT NULL default 0;
ALTER TABLE tagente ADD `remote` tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD `remote` tinyint(1) NOT NULL default 0;
ALTER TABLE tagente ADD `cascade_protection_module` int(10) unsigned default '0';
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- Table `tlayout` -- Table `tlayout`

View File

@ -92,6 +92,7 @@ ALTER TABLE tnetwork_component ADD COLUMN dynamic_two_tailed tinyint(1) unsigned
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE tagente ADD transactional_agent tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD transactional_agent tinyint(1) NOT NULL default 0;
ALTER TABLE tagente ADD remoteto tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD remoteto tinyint(1) NOT NULL default 0;
ALTER TABLE tagente ADD cascade_protection_module int(10) unsigned default '0';
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- Table `tlayout` -- Table `tlayout`

View File

@ -28,6 +28,7 @@ ALTER TABLE tnetwork_component ADD COLUMN dynamic_two_tailed tinyint(1) unsigned
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE tagente ADD transactional_agent tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD transactional_agent tinyint(1) NOT NULL default 0;
ALTER TABLE tagente ADD remote tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD remote tinyint(1) NOT NULL default 0;
ALTER TABLE tagente ADD cascade_protection_module int(10) unsigned default '0';
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- Table `tlayout` -- Table `tlayout`

View File

@ -230,6 +230,15 @@ else {
$groups = users_get_groups ($config["id_user"], "AR",false); $groups = users_get_groups ($config["id_user"], "AR",false);
$agents = agents_get_group_agents (array_keys ($groups)); $agents = agents_get_group_agents (array_keys ($groups));
$modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo
WHERE id_agente = " . $id_parent);
$modules_values = array();
$modules_values[0] = __('Any');
foreach ($modules as $m) {
$modules_values[$m['id_module']] = $m['name'];
}
$table->data[2][0] = __('Parent'); $table->data[2][0] = __('Parent');
$params = array(); $params = array();
$params['return'] = true; $params['return'] = true;
@ -240,6 +249,8 @@ $table->data[2][1] = ui_print_agent_autocomplete_input($params);
$table->data[2][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). " " . ui_print_help_icon("cascade_protection", true); $table->data[2][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). " " . ui_print_help_icon("cascade_protection", true);
$table->data[2][1] .= "  " . __('Module') . " " . html_print_select ($modules_values, "cascade_protection_module", $cascade_protection_module, "", "", 0, true);
$table->data[3][0] = __('Group'); $table->data[3][0] = __('Group');
$table->data[3][1] = html_print_select_groups(false, "AR", false, 'grupo', $grupo, '', '', 0, true); $table->data[3][1] = html_print_select_groups(false, "AR", false, 'grupo', $grupo, '', '', 0, true);
$table->data[3][1] .= ' <span id="group_preview">'; $table->data[3][1] .= ' <span id="group_preview">';
@ -526,6 +537,57 @@ ui_require_jquery_file('bgiframe');
$(document).ready (function() { $(document).ready (function() {
$("select#id_os").pandoraSelectOS (); $("select#id_os").pandoraSelectOS ();
var checked = $("#checkbox-cascade_protection").is(":checked");
if (checked) {
$("#cascade_protection_module").removeAttr("disabled");
}
else {
$("#cascade_protection_module").attr("disabled", 'disabled');
}
$("#checkbox-cascade_protection").change(function () {
var checked = $("#checkbox-cascade_protection").is(":checked");
if (checked) {
$("#cascade_protection_module").removeAttr("disabled");
}
else {
$("#cascade_protection_module").val(0);
$("#cascade_protection_module").attr("disabled", 'disabled');
}
});
$("#text-id_parent").on("autocompletechange", function () {
agent_name = $("#text-id_parent").val();
var params = {};
params["get_agent_modules_json_by_name"] = 1;
params["agent_name"] = agent_name;
params["page"] = "include/ajax/module";
jQuery.ajax ({
data: params,
dataType: "json",
type: "POST",
url: "ajax.php",
success: function (data) {
$('#cascade_protection_module').empty();
$('#cascade_protection_module')
.append ($('<option></option>')
.html("Any")
.prop("value", 0)
.prop("selected", 'selected'));
jQuery.each (data, function (i, val) {
$('#cascade_protection_module')
.append ($('<option></option>')
.html(val['name'])
.prop("value", val['id_module'])
.prop("selected", 'selected'));
});
}
});
});
paint_qrcode( paint_qrcode(
"<?php "<?php
echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agente); echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agente);

View File

@ -132,6 +132,7 @@ $grupo = 0;
$id_os = 9; // Windows $id_os = 9; // Windows
$custom_id = ""; $custom_id = "";
$cascade_protection = 0; $cascade_protection = 0;
$cascade_protection_modules = 0;
$icon_path = ''; $icon_path = '';
$update_gis_data = 0; $update_gis_data = 0;
$unit = ""; $unit = "";
@ -161,6 +162,7 @@ if ($create_agent) {
$disabled = (int) get_parameter_post ("disabled"); $disabled = (int) get_parameter_post ("disabled");
$custom_id = (string) get_parameter_post ("custom_id",''); $custom_id = (string) get_parameter_post ("custom_id",'');
$cascade_protection = (int) get_parameter_post ("cascade_protection", 0); $cascade_protection = (int) get_parameter_post ("cascade_protection", 0);
$cascade_protection_module = (int) get_parameter_post("cascade_protection_module", 0);
$icon_path = (string) get_parameter_post ("icon_path",''); $icon_path = (string) get_parameter_post ("icon_path",'');
$update_gis_data = (int) get_parameter_post("update_gis_data", 0); $update_gis_data = (int) get_parameter_post("update_gis_data", 0);
$url_description = (string) get_parameter("url_description"); $url_description = (string) get_parameter("url_description");
@ -197,6 +199,7 @@ if ($create_agent) {
'id_os' => $id_os, 'id_os' => $id_os,
'disabled' => $disabled, 'disabled' => $disabled,
'cascade_protection' => $cascade_protection, 'cascade_protection' => $cascade_protection,
'cascade_protection_module' => $cascade_protection_module,
'server_name' => $server_name, 'server_name' => $server_name,
'id_parent' => $id_parent, 'id_parent' => $id_parent,
'custom_id' => $custom_id, 'custom_id' => $custom_id,
@ -231,6 +234,7 @@ if ($create_agent) {
' Disabled: ' . $disabled . ' Disabled: ' . $disabled .
' Custom ID: ' . $custom_id . ' Custom ID: ' . $custom_id .
' Cascade protection: ' . $cascade_protection . ' Cascade protection: ' . $cascade_protection .
' Cascade protection module: ' . $cascade_protection_module .
' Icon path: ' . $icon_path . ' Icon path: ' . $icon_path .
' Update GIS data: ' . $update_gis_data . ' Update GIS data: ' . $update_gis_data .
' Url description: ' . $url_description . ' Url description: ' . $url_description .
@ -666,6 +670,7 @@ if ($update_agent) { // if modified some agent paramenter
$id_parent = (int) agents_get_agent_id ($parent_name); $id_parent = (int) agents_get_agent_id ($parent_name);
$custom_id = (string) get_parameter_post ("custom_id", ""); $custom_id = (string) get_parameter_post ("custom_id", "");
$cascade_protection = (int) get_parameter_post ("cascade_protection", 0); $cascade_protection = (int) get_parameter_post ("cascade_protection", 0);
$cascade_protection_module = (int) get_parameter ("cascade_protection_module", 0);
$icon_path = (string) get_parameter_post ("icon_path",''); $icon_path = (string) get_parameter_post ("icon_path",'');
$update_gis_data = (int) get_parameter_post("update_gis_data", 0); $update_gis_data = (int) get_parameter_post("update_gis_data", 0);
$url_description = (string) get_parameter("url_description"); $url_description = (string) get_parameter("url_description");
@ -733,6 +738,7 @@ if ($update_agent) { // if modified some agent paramenter
'intervalo' => $intervalo, 'intervalo' => $intervalo,
'comentarios' => $comentarios, 'comentarios' => $comentarios,
'cascade_protection' => $cascade_protection, 'cascade_protection' => $cascade_protection,
'cascade_protection_module' => $cascade_protection_module,
'server_name' => $server_name, 'server_name' => $server_name,
'custom_id' => $custom_id, 'custom_id' => $custom_id,
'icon_path' => $icon_path, 'icon_path' => $icon_path,
@ -764,6 +770,7 @@ if ($update_agent) { // if modified some agent paramenter
' ID OS: ' . $id_os . ' Disabled: ' . $disabled . ' ID OS: ' . $id_os . ' Disabled: ' . $disabled .
' Server Name: ' . $server_name . ' ID parent: ' . $id_parent . ' Server Name: ' . $server_name . ' ID parent: ' . $id_parent .
' Custom ID: ' . $custom_id . ' Cascade Protection: ' . $cascade_protection . ' Custom ID: ' . $custom_id . ' Cascade Protection: ' . $cascade_protection .
' Cascade protection module: ' . $cascade_protection_module .
' Icon Path: ' . $icon_path . 'Update GIS data: ' .$update_gis_data . ' Icon Path: ' . $icon_path . 'Update GIS data: ' .$update_gis_data .
' Url description: ' . $url_description . ' Url description: ' . $url_description .
' Quiet: ' . (int)$quiet; ' Quiet: ' . (int)$quiet;
@ -808,6 +815,7 @@ if ($id_agente) {
$id_parent = $agent["id_parent"]; $id_parent = $agent["id_parent"];
$custom_id = $agent["custom_id"]; $custom_id = $agent["custom_id"];
$cascade_protection = $agent["cascade_protection"]; $cascade_protection = $agent["cascade_protection"];
$cascade_protection_module = $agent["cascade_protection_module"];
$icon_path = $agent["icon_path"]; $icon_path = $agent["icon_path"];
$update_gis_data = $agent["update_gis_data"]; $update_gis_data = $agent["update_gis_data"];
$url_description = $agent["url_address"]; $url_description = $agent["url_address"];

View File

@ -76,6 +76,8 @@ if ($update_agents) {
$values['custom_id'] = get_parameter('custom_id'); $values['custom_id'] = get_parameter('custom_id');
if (get_parameter ('cascade_protection', -1) != -1) if (get_parameter ('cascade_protection', -1) != -1)
$values['cascade_protection'] = get_parameter('cascade_protection'); $values['cascade_protection'] = get_parameter('cascade_protection');
if (get_parameter ('cascade_protection_module', -1) != -1)
$values['cascade_protection_module'] = get_parameter('cascade_protection_module');
if (get_parameter ('delete_conf', 0) != 0) if (get_parameter ('delete_conf', 0) != 0)
$values['delete_conf'] = get_parameter('delete_conf'); $values['delete_conf'] = get_parameter('delete_conf');
if (get_parameter('quiet_select', -1) != -1) if (get_parameter('quiet_select', -1) != -1)
@ -264,6 +266,15 @@ $table->data = array ();
$groups = users_get_groups ($config["id_user"], "AW",false); $groups = users_get_groups ($config["id_user"], "AW",false);
$agents = agents_get_group_agents (array_keys ($groups)); $agents = agents_get_group_agents (array_keys ($groups));
$modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo
WHERE id_agente = " . $id_parent);
$modules_values = array();
$modules_values[0] = __('Any');
foreach ($modules as $m) {
$modules_values[$m['id_module']] = $m['name'];
}
$table->data[0][0] = __('Parent'); $table->data[0][0] = __('Parent');
$params = array(); $params = array();
$params['return'] = true; $params['return'] = true;
@ -277,6 +288,8 @@ $table->data[0][1] .= "<b>" . __('Cascade protection'). "</b>&nbsp;" .
html_print_select(array(1 => __('Yes'), 0 => __('No')), html_print_select(array(1 => __('Yes'), 0 => __('No')),
"cascade_protection", -1, "", __('No change'), -1, true); "cascade_protection", -1, "", __('No change'), -1, true);
$table->data[0][1] .= "&nbsp;&nbsp;" . __('Module') . "&nbsp;" . html_print_select ($modules, "cascade_protection_module", $cascade_protection_module, "", "", 0, true);
$table->data[1][0] = __('Group'); $table->data[1][0] = __('Group');
$table->data[1][1] = html_print_select_groups(false, "AR", false, 'group', $group, '', __('No change'), -1, true, false, true, '', false, 'width: 150px;'); $table->data[1][1] = html_print_select_groups(false, "AR", false, 'group', $group, '', __('No change'), -1, true, false, true, '', false, 'width: 150px;');
@ -313,6 +326,7 @@ $new_agent = true;
$icon_path = ''; $icon_path = '';
$update_gis_data = -1; $update_gis_data = -1;
$cascade_protection = -1; $cascade_protection = -1;
$cascade_protection_module = -1;
$quiet_select = -1; $quiet_select = -1;
$table = new StdClass(); $table = new StdClass();
@ -474,6 +488,53 @@ var limit_parameters_massive = <?php echo $config['limit_parameters_massive']; ?
//Use this function for change 3 icons when change the selectbox //Use this function for change 3 icons when change the selectbox
$(document).ready (function () { $(document).ready (function () {
var checked = $("#cascade_protection").val();
$("#cascade_protection_module").attr("disabled", 'disabled');
$("#cascade_protection").change(function () {
var checked = $("#cascade_protection").val();
if (checked == 1) {
$("#cascade_protection_module").removeAttr("disabled");
}
else {
$("#cascade_protection_module").val(0);
$("#cascade_protection_module").attr("disabled", 'disabled');
}
});
$("#text-id_parent").on("autocompletechange", function () {
agent_name = $("#text-id_parent").val();
var params = {};
params["get_agent_modules_json_by_name"] = 1;
params["agent_name"] = agent_name;
params["page"] = "include/ajax/module";
jQuery.ajax ({
data: params,
dataType: "json",
type: "POST",
url: "ajax.php",
success: function (data) {
$('#cascade_protection_module').empty();
$('#cascade_protection_module')
.append ($('<option></option>')
.html("Any")
.prop("value", 0)
.prop("selected", 'selected'));
jQuery.each (data, function (i, val) {
$('#cascade_protection_module')
.append ($('<option></option>')
.html(val['name'])
.prop("value", val['id_module'])
.prop("selected", 'selected'));
});
}
});
});
$("#form_agent").submit(function() { $("#form_agent").submit(function() {
var get_parameters_count = window.location.href.slice( var get_parameters_count = window.location.href.slice(

View File

@ -34,8 +34,22 @@ $change_module_relation_updates = (bool) get_parameter('change_module_relation_u
$get_id_tag = (bool) get_parameter('get_id_tag', 0); $get_id_tag = (bool) get_parameter('get_id_tag', 0);
$get_type = (bool) get_parameter('get_type', 0); $get_type = (bool) get_parameter('get_type', 0);
$list_modules = (bool) get_parameter('list_modules', 0); $list_modules = (bool) get_parameter('list_modules', 0);
$get_agent_modules_json_by_name = (bool) get_parameter('get_agent_modules_json_by_name', 0);
if ($get_agent_modules_json_by_name) {
$agent_name = get_parameter('agent_name');
$agent_id = agents_get_agent_id($agent_name);
$agent_modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo
WHERE id_agente = " . $agent_id);
echo json_encode ($agent_modules);
return;
}
if ($get_plugin_macros) { if ($get_plugin_macros) {
if ( https_is_running() ) { if ( https_is_running() ) {
header('Content-type: application/json'); header('Content-type: application/json');

View File

@ -396,7 +396,8 @@ $agent_field_column_mapping = array(
'agent_id_parent' => 'id_parent as agent_id_parent', 'agent_id_parent' => 'id_parent as agent_id_parent',
'agent_custom_id' => 'custom_id as agent_custom_id', 'agent_custom_id' => 'custom_id as agent_custom_id',
'agent_server_name' => 'server_name as agent_server_name', 'agent_server_name' => 'server_name as agent_server_name',
'agent_cascade_protection' => 'cascade_protection as agent_cascade_protection'); 'agent_cascade_protection' => 'cascade_protection as agent_cascade_protection',
'agent_cascade_protection_module' => 'cascade_protection_module as agent_cascade_protection_module',);
/* module related field mappings 1/2 (output field => column for 'tagente_modulo') */ /* module related field mappings 1/2 (output field => column for 'tagente_modulo') */
$module_field_column_mampping = array( $module_field_column_mampping = array(
@ -540,6 +541,7 @@ function api_get_tree_agents($trash1, $trahs2, $other, $returnType) {
'agent_custom_id', 'agent_custom_id',
'agent_server_name', 'agent_server_name',
'agent_cascade_protection', 'agent_cascade_protection',
'agent_cascade_protection_module',
'module_id_agent_modulo', 'module_id_agent_modulo',
'module_id_agent', 'module_id_agent',
@ -1060,19 +1062,31 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) {
return; return;
} }
//html_debug_print($other);
$name = $other['data'][0]; $name = $other['data'][0];
$ip = $other['data'][1]; $ip = $other['data'][1];
$idParent = $other['data'][2]; $idParent = $other['data'][2];
$idGroup = $other['data'][3]; $idGroup = $other['data'][3];
$cascadeProtection = $other['data'][4]; $cascadeProtection = $other['data'][4];
$intervalSeconds = $other['data'][5]; $cascadeProtectionModule = $other['data'][5];
$idOS = $other['data'][6]; $intervalSeconds = $other['data'][6];
$nameServer = $other['data'][7]; $idOS = $other['data'][7];
$customId = $other['data'][8]; $nameServer = $other['data'][8];
$learningMode = $other['data'][9]; $customId = $other['data'][9];
$disabled = $other['data'][10]; $learningMode = $other['data'][10];
$description = $other['data'][11]; $disabled = $other['data'][11];
$description = $other['data'][12];
if ($cascadeProtection == 1) {
if (($idParent != 0) && (db_get_value_sql('SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente = ' . $idParent .
' AND id_agente_modulo = ' . $cascadeProtectionModule) === false)) {
returnError('parent_agent_not_exist', 'Is not a parent module to do cascade protection.');
}
}
else {
$cascadeProtectionModule = 0;
}
$return = db_process_sql_update('tagente', $return = db_process_sql_update('tagente',
array('nombre' => $name, array('nombre' => $name,
@ -1084,6 +1098,7 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) {
'id_os' => $idOS, 'id_os' => $idOS,
'disabled' => $disabled, 'disabled' => $disabled,
'cascade_protection' => $cascadeProtection, 'cascade_protection' => $cascadeProtection,
'cascade_protection_module' => $cascadeProtectionModule,
'server_name' => $nameServer, 'server_name' => $nameServer,
'id_parent' => $idParent, 'id_parent' => $idParent,
'custom_id' => $customId), 'custom_id' => $customId),
@ -1124,14 +1139,27 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) {
$idParent = $other['data'][2]; $idParent = $other['data'][2];
$idGroup = $other['data'][3]; $idGroup = $other['data'][3];
$cascadeProtection = $other['data'][4]; $cascadeProtection = $other['data'][4];
$intervalSeconds = $other['data'][5]; $cascadeProtectionModule = $other['data'][5];
$idOS = $other['data'][6]; $intervalSeconds = $other['data'][6];
$idOS = $other['data'][7];
//$idServer = $other['data'][7]; //$idServer = $other['data'][7];
$nameServer = $other['data'][7]; $nameServer = $other['data'][8];
$customId = $other['data'][8]; $customId = $other['data'][9];
$learningMode = $other['data'][9]; $learningMode = $other['data'][10];
$disabled = $other['data'][10]; $disabled = $other['data'][11];
$description = $other['data'][11]; $description = $other['data'][12];
if ($cascadeProtection == 1) {
if (($idParent != 0) && (db_get_value_sql('SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente = ' . $idParent .
' AND id_agente_modulo = ' . $cascadeProtectionModule) === false)) {
returnError('parent_agent_not_exist', 'Is not a parent module to do cascade protection.');
}
}
else {
$cascadeProtectionModule = 0;
}
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
@ -1183,6 +1211,7 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) {
'id_os' => $idOS, 'id_os' => $idOS,
'disabled' => $disabled, 'disabled' => $disabled,
'cascade_protection' => $cascadeProtection, 'cascade_protection' => $cascadeProtection,
'cascade_protection_module' => $cascadeProtectionModule,
'server_name' => $nameServer, 'server_name' => $nameServer,
'id_parent' => $idParent, 'id_parent' => $idParent,
'custom_id' => $customId)); 'custom_id' => $customId));