2014-05-23 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_modules.php,
	include/functions_networkmap.php: added the filters for the
	CIDR network masks.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9994 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2014-05-23 14:42:55 +00:00
parent 667d73f8a5
commit 64c3affbb9
3 changed files with 64 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2014-05-23 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_modules.php,
include/functions_networkmap.php: added the filters for the
CIDR network masks.
2014-05-23 Vanessa Gil <vanessa.gil@artica.es> 2014-05-23 Vanessa Gil <vanessa.gil@artica.es>
* godmode/agentes/module_manager.php: Added optional * godmode/agentes/module_manager.php: Added optional

View File

@ -81,7 +81,8 @@ function modules_is_disable_type_event($id_agent_module = false, $type_event = f
} }
$disabled_types_event = json_decode( $disabled_types_event = json_decode(
db_get_value('disabled_types_event', 'tagente_modulo', 'id_agente_modulo', $id_agent_module), true); db_get_value('disabled_types_event', 'tagente_modulo', 'id_agente_modulo', $id_agent_module),
true);
if (isset($disabled_types_event[$type_event])) { if (isset($disabled_types_event[$type_event])) {
if ($disabled_types_event[$type_event]) { if ($disabled_types_event[$type_event]) {
@ -978,7 +979,9 @@ function modules_get_interfaces($id_agent, $fields_param = false) {
$modules = array(); $modules = array();
foreach ($modules as $module) { foreach ($modules as $module) {
if ($module['id_tipo_modulo'] == 18 || $module['id_tipo_modulo'] == 6) { //18 = remote_snmp_proc
//6 = remote_icmp_proc
if ($module['id_tipo_modulo'] == 18) {
if ($fields_param !== false) { if ($fields_param !== false) {
if (is_array($fields_param)) { if (is_array($fields_param)) {
@ -1849,12 +1852,11 @@ function modules_get_module_macros_json ($macro_names, $macro_values) {
* @return mixed Array with relations between modules. False if there were no data. * @return mixed Array with relations between modules. False if there were no data.
*/ */
function modules_get_relations ($params = array()) { function modules_get_relations ($params = array()) {
$id_agent = 0; $id_agent = 0;
if (isset($params['id_agent'])) { if (isset($params['id_agent'])) {
$id_agent = $params['id_agent']; $id_agent = $params['id_agent'];
} }
$id_module = 0; $id_module = 0;
if (isset($params['id_module'])) { if (isset($params['id_module'])) {
$id_module = $params['id_module']; $id_module = $params['id_module'];
@ -1867,16 +1869,20 @@ function modules_get_relations ($params = array()) {
$disabled_update = 1; $disabled_update = 1;
} }
} }
$modules_type = ""; $modules_type = "";
if (isset($params['modules_type'])) { if (isset($params['modules_type'])) {
$modules_type = $params['modules_type']; $modules_type = $params['modules_type'];
} }
$sql = "SELECT DISTINCT tmr.id, tmr.module_a, tmr.module_b, tmr.disable_update $sql = "SELECT DISTINCT tmr.id, tmr.module_a, tmr.module_b,
FROM tmodule_relationship AS tmr, tagente_modulo AS tam, tagente AS ta, ttipo_modulo AS ttm tmr.disable_update
FROM tmodule_relationship AS tmr,
tagente_modulo AS tam,
tagente AS ta,
ttipo_modulo AS ttm
WHERE "; WHERE ";
$agent_filter = ""; $agent_filter = "";
if ($id_agent > 0) { if ($id_agent > 0) {
$agent_filter = sprintf("AND ta.id_agente = %d", $id_agent); $agent_filter = sprintf("AND ta.id_agente = %d", $id_agent);
@ -1889,13 +1895,15 @@ function modules_get_relations ($params = array()) {
} }
$disabled_update_filter = ""; $disabled_update_filter = "";
if ($disabled_update >= 0) { if ($disabled_update >= 0) {
$disabled_update_filter = sprintf("AND tmr.disable_update = %d", $disabled_update); $disabled_update_filter = sprintf(
"AND tmr.disable_update = %d", $disabled_update);
} }
$modules_type_filter = ""; $modules_type_filter = "";
if ($modules_type != "") { if ($modules_type != "") {
$modules_type_filter = sprintf("AND (tam.id_tipo_modulo = ttm.id_tipo AND ttm.nombre = '%s')", $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 $sql .= "( (tmr.module_a = tam.id_agente_modulo
$module_a_filter) $module_a_filter)
OR (tmr.module_b = tam.id_agente_modulo OR (tmr.module_b = tam.id_agente_modulo
@ -1904,7 +1912,7 @@ function modules_get_relations ($params = array()) {
$agent_filter $agent_filter
$disabled_update_filter $disabled_update_filter
$modules_type_filter"; $modules_type_filter";
return db_get_all_rows_sql($sql); return db_get_all_rows_sql($sql);
} }
@ -1917,15 +1925,15 @@ function modules_get_relations ($params = array()) {
* @return bool True if the relation exists, false otherwise. * @return bool True if the relation exists, false otherwise.
*/ */
function modules_relation_exists ($id_module, $id_module_other = false) { function modules_relation_exists ($id_module, $id_module_other = false) {
if ($id_module_other === false) { if ($id_module_other === false) {
$sql = sprintf("SELECT id $sql = sprintf("SELECT id
FROM tmodule_relationship FROM tmodule_relationship
WHERE module_a = %d WHERE module_a = %d
OR module_b = %d", OR module_b = %d",
$id_module, $id_module); $id_module, $id_module);
} elseif (is_array($id_module_other)) { } elseif (is_array($id_module_other)) {
$ids_other = 0; $ids_other = 0;

View File

@ -1527,6 +1527,40 @@ function networkmap_get_filter_types () {
return $networkmap_types; return $networkmap_types;
} }
function networkmap_cidr_match($ip, $cidr_mask) {
//copy from open source code
// https://gist.github.com/linickx/1309388
list ($subnet, $bits) = split('/', $cidr_mask);
$ip = ip2long($ip);
$subnet = ip2long($subnet);
$mask = -1 << (32 - $bits);
$subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned
return ($ip & $mask) == $subnet;
}
function networkmap_get_new_nodes_from_ip_mask($ip_mask) {
$list_ip_masks = explode(",", $ip_mask);
$list_address = db_get_all_rows_in_table('taddress');
if (empty($address))
$address = array();
$agents = array();
foreach ($list_address as $address) {
foreach ($list_ip_masks as $ip_mask) {
if (networkmap_cidr_match($address['ip'], $ip_mask)) {
$agents[] = db_get_value_filter('id_agent',
'taddress_agent', array('id_a' => $address['id_a']));
}
}
}
return $agents;
}
?> ?>
<script language="javascript" type="text/javascript"> <script language="javascript" type="text/javascript">
/* <![CDATA[ */ /* <![CDATA[ */