Skip to content

Commit

Permalink
Merge pull request #8 from PaloAltoNetworks/developer
Browse files Browse the repository at this point in the history
UTIL - improvements
  • Loading branch information
swaschkut authored May 10, 2021
2 parents 5370c9f + 6a0db36 commit 584ff12
Show file tree
Hide file tree
Showing 17 changed files with 1,746 additions and 65 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ GENERAL:

UTILS:
address-merger | merge TAG before duplicate object is deleted
schedule-edit | introduce new util tool
schedule-edit | introduce new util tool, introduce 'filter=(object is.expired)'
rule-edit | introduce 'filter=(schedule is.expired)' - example usage: pa_rule-edit in=api://IP actions=disabled-set 'filter=(schedule is.expired)'
pa_xml-issue-detecor | extend to find for source/destination if ANY and other objects are set
address-edit | extend actions=display to print tag information

BUGFIX:
PanoramaConf | fix for TagStore to set parentCentralStore at time of reading DG hierarchy - example usage pa_rule-edit actions=tag-add:TAGNAME (if TAGNAME is defined NOT at shared but at parent DG)
Expand Down
5 changes: 4 additions & 1 deletion lib/device-and-system-classes/DeviceGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,10 @@ public function load_from_domxml($xml)
}
}

$this->addressStore->nestedPointOfView_sven();
$this->addressStore->nestedPointOfView();
$this->serviceStore->nestedPointOfView();
$this->tagStore->nestedPointOfView();
$this->scheduleStore->nestedPointOfView();

}

Expand Down
17 changes: 17 additions & 0 deletions lib/misc-classes/filters/filters-Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
'input' => 'input/panorama-8.0.xml'
)
);

RQuery::$defaultFilters['schedule']['object']['operators']['is.expired'] = array(
'Function' => function (ScheduleRQueryContext $context) {
$value = $context->object;

return $value->isExpired();
},
'arg' => false,
);
RQuery::$defaultFilters['schedule']['name']['operators']['is.in.file'] = array(
'Function' => function (ScheduleRQueryContext $context) {
$object = $context->object;
Expand Down Expand Up @@ -372,4 +381,12 @@
)
);

RQuery::$defaultFilters['schedule']['object']['operators']['is.expired'] = array(
'Function' => function (ScheduleRQueryContext $context) {
$value = $context->object;

return $value->isExpired();
},
'arg' => false,
);
// </editor-fold>
18 changes: 11 additions & 7 deletions lib/object-classes/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,21 +606,25 @@ public function merge_tag_description_to( $pickedObject, $apiMode = false )
if( $apiMode )
$newTag->API_sync();
}
if( $tag !== $newTag )

if( $apiMode )
{
$tag->replaceMeGlobally($newTag);
if( $apiMode )
$pickedObject->tags->API_addTag( $newTag );
if( $tag !== $newTag)
{
$pickedObject->tags->API_addTag( $newTag );
$tag->replaceMeGlobally($newTag);
$tag->owner->API_removeTag($tag);
}
else
}
else
{
$pickedObject->tags->addTag( $newTag );
if( $tag !== $newTag)
{
$pickedObject->tags->addTag( $newTag );
$tag->replaceMeGlobally($newTag);
$tag->owner->removeTag($tag);
}
}

}
}

Expand Down
30 changes: 17 additions & 13 deletions lib/object-classes/AddressStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public function addressObjects()
/**
* @return Address[]|AddressGroup[]
*/
public function nestedPointOfView()
public function nestedPointOfView_old()
{
$current = $this;

Expand Down Expand Up @@ -824,7 +824,7 @@ public function nestedPointOfView()
/**
* @return Address[]|AddressGroup[]
*/
public function nestedPointOfView_sven()
public function nestedPointOfView()
{
$current = $this;

Expand All @@ -847,6 +847,9 @@ public function nestedPointOfView_sven()
$tmp_o = &$objects[ $o->name() ];
$tmp_ref_count = $tmp_o->countReferences();

$objects_overwritten[$o->name()][$tmp_o->owner->owner->name()] = $tmp_o;
$objects_overwritten[$o->name()][$location] = $o;

if( $tmp_ref_count == 0 )
{
// if object is /32, let's remove it to match equivalent non /32 syntax
Expand All @@ -861,8 +864,6 @@ public function nestedPointOfView_sven()

if( $tmp_value != $o_value && ($o_ref_count > 0) )
{
#$objects_overwritten[$o->name()][$tmp_o->owner->owner->name()] = $tmp_o;
#$objects_overwritten[$o->name()][$location] = $o;
if( $location != "shared" )
foreach( $o->refrules as $ref )
$tmp_o->addReference( $ref );
Expand All @@ -879,6 +880,9 @@ public function nestedPointOfView_sven()
$tmp_o = &$objects[ $o->name() ];
$tmp_ref_count = $tmp_o->countReferences();

$objects_overwritten[$o->name()][$tmp_o->owner->owner->name()] = $tmp_o;
$objects_overwritten[$o->name()][$location] = $o;

if( $tmp_ref_count == 0 )
{
$tmp_mapping = $tmp_o->getFullMapping();
Expand All @@ -890,8 +894,6 @@ public function nestedPointOfView_sven()

if( $tmp_value != $o_value && ( $o_ref_count > 0) )
{
#$objects_overwritten[$o->name()][$tmp_o->owner->owner->name()] = $tmp_o;
#$objects_overwritten[$o->name()][$location] = $o;
if( $location != "shared" )
foreach( $o->refrules as $ref )
$tmp_o->addReference( $ref );
Expand All @@ -902,23 +904,25 @@ public function nestedPointOfView_sven()

if( isset($current->owner->parentDeviceGroup) && $current->owner->parentDeviceGroup !== null )
$current = $current->owner->parentDeviceGroup->addressStore;
elseif( isset($current->owner->owner) && $current->owner->owner !== null )
elseif( isset($current->owner->parentContainer) && $current->owner->parentContainer !== null )
$current = $current->owner->parentContainer->addressStore;
elseif( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
$current = $current->owner->owner->addressStore;
else
break;
}

/*
/*
foreach( $objects_overwritten as $key => $DGs )
{
print "NAME: ".$key."\n";
foreach( $DGs as $key2 => $object )
{
if( $object->isAddress() )
{
#print " - DG: ".$key2." value: ".$object->value();
#print "\n";
#$object->display_references(7);
print " - DG: ".$key2." value: ".$object->value();
print "\n";
$object->display_references(7);
}
else
{
Expand All @@ -929,8 +933,8 @@ public function nestedPointOfView_sven()
}
print "\n";
}
*/
}*/

return $objects;
}

Expand Down
25 changes: 23 additions & 2 deletions lib/object-classes/ScheduleStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,35 @@ public function nestedPointOfView()

while( TRUE )
{
if( get_class( $current->owner ) == "PanoramaConf" )
$location = "shared";
else
$location = $current->owner->name();

foreach( $current->o as $o )
{
if( !isset($objects[$o->name()]) )
$objects[$o->name()] = $o;
else
{
$tmp_o = &$objects[ $o->name() ];
$tmp_ref_count = $tmp_o->countReferences();

if( $tmp_ref_count == 0 )
{
//Todo: check if object value is same; if same to not add ref
if( $location != "shared" )
foreach( $o->refrules as $ref )
$tmp_o->addReference( $ref );
}
}
}


if( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
if( isset($current->owner->parentDeviceGroup) && $current->owner->parentDeviceGroup !== null )
$current = $current->owner->parentDeviceGroup->scheduleStore;
elseif( isset($current->owner->parentContainer) && $current->owner->parentContainer !== null )
$current = $current->owner->parentContainer->scheduleStore;
elseif( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
$current = $current->owner->owner->scheduleStore;
else
break;
Expand Down
71 changes: 70 additions & 1 deletion lib/object-classes/ServiceStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,77 @@ public function nestedPointOfView()
$objects[$o->name()] = $o;
}

if( isset($current->owner->parentDeviceGroup) && $current->owner->parentDeviceGroup !== null )
$current = $current->owner->parentDeviceGroup->serviceStore;
elseif( isset($current->owner->parentContainer) && $current->owner->parentContainer !== null )
$current = $current->owner->parentContainer->serviceStore;
elseif( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
$current = $current->owner->owner->serviceStore;
else
break;
}

return $objects;
}

/**
* @return Service[]|ServiceGroup[]
*/
public function nestedPointOfView_sven()
{
$current = $this;

$objects = array();

while( TRUE )
{
if( get_class( $current->owner ) == "PanoramaConf" )
$location = "shared";
else
$location = $current->owner->name();

foreach( $current->_serviceObjects as $o )
{
if( !isset($objects[$o->name()]) )
$objects[$o->name()] = $o;
else
{
$tmp_o = &$objects[ $o->name() ];
$tmp_ref_count = $tmp_o->countReferences();

if( $tmp_ref_count == 0 )
{
//Todo: check if object value is same; if same to not add ref
if( $location != "shared" )
foreach( $o->refrules as $ref )
$tmp_o->addReference( $ref );
}
}
}
foreach( $current->_serviceGroups as $o )
{
if( !isset($objects[$o->name()]) )
$objects[$o->name()] = $o;
else
{
$tmp_o = &$objects[ $o->name() ];
$tmp_ref_count = $tmp_o->countReferences();

if( $tmp_ref_count == 0 )
{
//Todo: check if object value is same; if same to not add ref
if( $location != "shared" )
foreach( $o->refrules as $ref )
$tmp_o->addReference( $ref );
}
}
}

if( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
if( isset($current->owner->parentDeviceGroup) && $current->owner->parentDeviceGroup !== null )
$current = $current->owner->parentDeviceGroup->serviceStore;
elseif( isset($current->owner->parentContainer) && $current->owner->parentContainer !== null )
$current = $current->owner->parentContainer->serviceStore;
elseif( isset($current->owner->owner) && $current->owner->owner !== null )
$current = $current->owner->owner->serviceStore;
else
break;
Expand Down
25 changes: 23 additions & 2 deletions lib/object-classes/TagStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,35 @@ public function nestedPointOfView()

while( TRUE )
{
if( get_class( $current->owner ) == "PanoramaConf" )
$location = "shared";
else
$location = $current->owner->name();

foreach( $current->o as $o )
{
if( !isset($objects[$o->name()]) )
$objects[$o->name()] = $o;
else
{
$tmp_o = &$objects[ $o->name() ];
$tmp_ref_count = $tmp_o->countReferences();

if( $tmp_ref_count == 0 )
{
//Todo: check if object value is same; if same to not add ref
if( $location != "shared" )
foreach( $o->refrules as $ref )
$tmp_o->addReference( $ref );
}
}
}


if( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
if( isset($current->owner->parentDeviceGroup) && $current->owner->parentDeviceGroup !== null )
$current = $current->owner->parentDeviceGroup->tagStore;
elseif( isset($current->owner->parentContainer) && $current->owner->parentContainer !== null )
$current = $current->owner->parentContainer->tagStore;
elseif( isset($current->owner->owner) && $current->owner->owner !== null && !$current->owner->owner->isFawkes() )
$current = $current->owner->owner->tagStore;
else
break;
Expand Down
3 changes: 2 additions & 1 deletion tests/api_test_filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
echo "\n*************************************************\n";
echo "**************** FILTER TESTERS *****************\n\n";

require_once '../lib/pan_php_framework.php';
set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path());
require_once dirname(__FILE__)."/../lib/pan_php_framework.php";

PH::processCliArgs();

Expand Down
9 changes: 4 additions & 5 deletions tests/api_test_mergers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
echo "\n*************************************************\n";
echo "**************** MERGER TESTERS *****************\n\n";

require_once '../lib/pan_php_framework.php';
set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path());
require_once dirname(__FILE__)."/../lib/pan_php_framework.php";

PH::processCliArgs();

Expand All @@ -32,7 +33,7 @@
else
derr('"in" argument must be of type API [in=api://192.168.55.208]');

$cli = "php ../utils/upload-config.php in=input/panorama-8.0-merger.xml out=api://{$api_ip_address} loadAfterUpload injectUserAdmin2 2>&1";
$cli = "php ../utils/upload-config.php in=input/panorama-10.0-merger.xml out=api://{$api_ip_address} loadAfterUpload injectUserAdmin2 2>&1";
echo " * Executing CLI: {$cli}\n";

$output = array();
Expand Down Expand Up @@ -103,8 +104,6 @@ function runCommand($bin, &$stream, $force = TRUE, $command = '')

foreach( $test_merger as $merger )
{
$ci['input'] = 'input/panorama-8.0-merger.xml';

echo "\n\n\n *** Processing merger: {$merger} \n";

$dupalgorithm_array = array();
Expand Down Expand Up @@ -140,7 +139,7 @@ function runCommand($bin, &$stream, $force = TRUE, $command = '')

foreach( $dupalgorithm_array as $dupalgorithm )
{
$location = 'testDG';
$location = 'any';
$output = '/dev/null';

$cli = "php $util in=api://{$api_ip_address} location={$location} allowMergingWithUpperLevel";
Expand Down
Loading

0 comments on commit 584ff12

Please sign in to comment.