Skip to content

Commit

Permalink
type=rule - actions=display/exporttoexcel:resolveaddresssummary | add…
Browse files Browse the repository at this point in the history
… new src/dst_resovled_sum - for better nested calculation
  • Loading branch information
Sven Waschkut committed Aug 9, 2023
1 parent 5f1e20f commit bde9e27
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BUGFIX:
* type=dhcp actions=exporttoexcel | bugfix to add correct template
* class PH - workaround for none working API mode connector - discard setType()
* class RULEUTIL - defaultSecurityRules not available in Fawkes Snippet
* type=rule - actions=display/exporttoexcel:resolveaddresssummary | add new src/dst_resovled_sum - for better nested calculation

GENERAL:
* dynamic update version 8739-8206
Expand Down
88 changes: 86 additions & 2 deletions utils/common/RuleCallContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ public function ruleFieldHtmlExport($rule, $fieldName, $wrap = TRUE, $rule_hitco
if( $rule->source->isAny() )
return self::enclose('any');
return self::enclose($rule->source->getAll(), $wrap);
/*
$members = $rule->source->getAll();
$string_array = array();
foreach( $members as $member )
{
$string_array[] = $member->name()." [".$member->owner->owner->name()."]";
}
return self::enclose($string_array);
*/
}

if( $fieldName == 'destination' )
Expand Down Expand Up @@ -608,13 +617,20 @@ public function ruleFieldHtmlExport($rule, $fieldName, $wrap = TRUE, $rule_hitco

return self::enclose($resolve);
}
if( $fieldName == 'src_resolved_sum' )
if( $fieldName == 'src_resolved_sumOLD' )
{
$unresolvedArray = array();
$strMapping = $this->AddressResolveSummary( $rule, "source", $unresolvedArray );
$strMapping = array_merge( $strMapping, $unresolvedArray );
return self::enclose($strMapping);
}
if( $fieldName == 'src_resolved_sum' )
{
$unresolvedArray = array();
$strMapping = $this->AddressResolveSummaryNEW( $rule, "source", $unresolvedArray );
$strMapping = array_merge( $strMapping, $unresolvedArray );
return self::enclose($strMapping);
}
if( $fieldName == 'src_resolved_nested_name' )
{
$unresolvedArray = array();
Expand Down Expand Up @@ -649,13 +665,20 @@ public function ruleFieldHtmlExport($rule, $fieldName, $wrap = TRUE, $rule_hitco

return self::enclose($resolve);
}
if( $fieldName == 'dst_resolved_sum' )
if( $fieldName == 'dst_resolved_sumOLD' )
{
$unresolvedArray = array();
$strMapping = $this->AddressResolveSummary( $rule, "destination", $unresolvedArray );
$strMapping = array_merge( $strMapping, $unresolvedArray );
return self::enclose($strMapping);
}
if( $fieldName == 'dst_resolved_sum' )
{
$unresolvedArray = array();
$strMapping = $this->AddressResolveSummaryNEW( $rule, "destination", $unresolvedArray );
$strMapping = array_merge( $strMapping, $unresolvedArray );
return self::enclose($strMapping);
}
if( $fieldName == 'dst_resolved_nested_name' )
{
$unresolvedArray = array();
Expand Down Expand Up @@ -797,8 +820,11 @@ public function AddressResolveValueNestedSummary( $rule, $typeSrcDst, &$unresolv
{
if( $member->isGroup() )
{
/** @var AddressGroup $member */
$tmp_array = array();
$members = $member->expand(FALSE, $tmp_array, $rule->owner->owner);
#foreach($tmp_array as $groups)
# $strMapping[] = "";
foreach( $members as $member )
{
$tmp_member = $rule->owner->owner->addressStore->find($member->name());
Expand All @@ -821,6 +847,53 @@ public function AddressResolveValueNestedSummary( $rule, $typeSrcDst, &$unresolv

return $strMapping;
}

public function AddressResolveSummaryNEW( $rule, $typeSrcDst, &$unresolvedArray = array() )
{
$mapObject = new IP4Map();
if( $rule->$typeSrcDst->isAny() )
{
$localMap = IP4Map::mapFromText('0.0.0.0-255.255.255.255');
$mapObject->addMap($localMap, TRUE);
#$localMap = IP4Map::mapFromText('::0-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff');
#$mapObject->addMap($localMap, TRUE);
}

$allMembers = $rule->$typeSrcDst->getAll();
$strMapping = array();
foreach($allMembers as $member)
{
if( $member->isGroup() )
{
/** @var AddressGroup $member */
$tmp_array = array();
$members = $member->expand(FALSE, $tmp_array, $rule->owner->owner);
foreach( $members as $member )
{
$tmp_member = $rule->owner->owner->addressStore->find($member->name());
$localMap = $tmp_member->getIP4Mapping();
$mapObject->addMap($localMap, TRUE);
}
}

else
{
$tmp_member = $rule->owner->owner->addressStore->find($member->name());
$localMap = $tmp_member->getIP4Mapping();
$mapObject->addMap($localMap, TRUE);
}

}

$mapObject->sortAndRecalculate();
$strMapping = explode(',', $mapObject->dumpToString());

if( count( $strMapping) === 1 && empty( $strMapping[0] ) )
$strMapping = array();

return $strMapping;
}

public function AddressResolveNameNestedSummary( $rule, $typeSrcDst, &$unresolvedArray = array() )
{
if( $rule->$typeSrcDst->isAny() )
Expand All @@ -834,6 +907,8 @@ public function AddressResolveNameNestedSummary( $rule, $typeSrcDst, &$unresolve
{
$tmp_array = array();
$members = $member->expand(FALSE, $tmp_array, $rule->owner->owner);
#foreach($tmp_array as $groups)
# $strMapping[] = $groups->name();
foreach( $members as $member )
{
$strMapping[] = $member->name();
Expand Down Expand Up @@ -864,6 +939,15 @@ public function AddressResolveLocationNestedSummary( $rule, $typeSrcDst, &$unres
{
$tmp_array = array();
$members = $member->expand(FALSE, $tmp_array, $rule->owner->owner);
/*
foreach($tmp_array as $groups)
{
$tmp_name = $groups->owner->owner->name();
if( empty($tmp_name) )
$tmp_name = "shared";
$strMapping[] = $tmp_name;
}*/
foreach( $members as $member )
{
$tmp_name = $member->owner->owner->name();
Expand Down
10 changes: 6 additions & 4 deletions utils/common/actions-rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3823,7 +3823,7 @@
if( $addResolvedAddressSummary )
{
$unresolvedArray = array();
PH::$JSON_TMP['sub']['object'][$rule->name()]['src_resolved_sum']['resolved'] = $context->AddressResolveSummary( $rule, "source", $unresolvedArray );
PH::$JSON_TMP['sub']['object'][$rule->name()]['src_resolved_sum']['resolved'] = $context->AddressResolveSummaryNEW( $rule, "source", $unresolvedArray );
PH::$JSON_TMP['sub']['object'][$rule->name()]['src_resolved_sum']['unresolved'] = $unresolvedArray;
$unresolvedArray = array();
PH::$JSON_TMP['sub']['object'][$rule->name()]['src_resolved_value'] = $context->AddressResolveValueSummary( $rule, "source", $unresolvedArray );
Expand All @@ -3833,7 +3833,7 @@
PH::$JSON_TMP['sub']['object'][$rule->name()]['src_resolved_nested_value'] = $context->AddressResolveValueNestedSummary( $rule, "source", $unresolvedArray );

$unresolvedArray = array();
PH::$JSON_TMP['sub']['object'][$rule->name()]['dst_resolved_sum']['resolved'] = $context->AddressResolveSummary( $rule, "destination", $unresolvedArray );
PH::$JSON_TMP['sub']['object'][$rule->name()]['dst_resolved_sum']['resolved'] = $context->AddressResolveSummaryNEW( $rule, "destination", $unresolvedArray );
PH::$JSON_TMP['sub']['object'][$rule->name()]['dst_resolved_sum']['unresolved'] = $unresolvedArray;
$unresolvedArray = array();
PH::$JSON_TMP['sub']['object'][$rule->name()]['dst_resolved_value'] = $context->AddressResolveValueSummary( $rule, "destination", $unresolvedArray );
Expand Down Expand Up @@ -4344,6 +4344,7 @@
'src' => 'source',
'src_resolved_value' => 'src_resolved_value',
'src_resolved_sum' => 'src_resolved_sum',
'src_resolved_sumOLD' => 'src_resolved_sumOLD',
'src_resolved_nested_name' => 'src_resolved_nested_name',
'src_resolved_nested_value' => 'src_resolved_nested_value',
'src_resolved_nested_location' => 'src_resolved_nested_location',
Expand All @@ -4352,6 +4353,7 @@
'dst_interface' => 'dst_interface',
'dst_resolved_value' => 'dst_resolved_value',
'dst_resolved_sum' => 'dst_resolved_sum',
'dst_resolved_sumOLD' => 'dst_resolved_sumOLD',
'dst_resolved_nested_name' => 'dst_resolved_nested_name',
'dst_resolved_nested_value' => 'dst_resolved_nested_value',
'dst_resolved_nested_location' => 'dst_resolved_nested_location',
Expand Down Expand Up @@ -4413,9 +4415,9 @@
foreach( $fields as $fieldName => $fieldID )
{
if( ((
$fieldName == 'src_resolved_sum' || $fieldName == 'src_resolved_value' ||
$fieldName == 'src_resolved_sum' || $fieldName == 'src_resolved_sumOLD' || $fieldName == 'src_resolved_value' ||
$fieldName == 'src_resolved_nested_name' || $fieldName == 'src_resolved_nested_value' || $fieldName == 'src_resolved_nested_location' ||
$fieldName == 'dst_resolved_sum' || $fieldName == 'dst_resolved_value' ||
$fieldName == 'dst_resolved_sum' || $fieldName == 'dst_resolved_sumOLD' || $fieldName == 'dst_resolved_value' ||
$fieldName == 'dst_resolved_nested_name' || $fieldName == 'dst_resolved_nested_value' || $fieldName == 'dst_resolved_nested_location' ||
$fieldName == 'dnat_host_resolved_sum' ||
$fieldName == 'snat_address_resolved_sum')
Expand Down

0 comments on commit bde9e27

Please sign in to comment.