Skip to content

Commit

Permalink
Merge pull request #544 from swaschkut/main
Browse files Browse the repository at this point in the history
UTIL type=device | introduce actions==sp_spg-create-BP
  • Loading branch information
swaschkut authored Apr 8, 2022
2 parents bd1a56c + af14432 commit 2eec7d6
Show file tree
Hide file tree
Showing 27 changed files with 948 additions and 253 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ CHANGELOG
2.0.34
UTILS:
* UTIL API - introduce postman_collection
* UTIL type=device actions=display-shadowrule | improve JSON output
* UTIL develop - introduce create_template_mgmt_permittedips.php
* UTIL type=device | introduce actions==sp_spg-create-BP
* UTIL type=device | extend actions=actions=sp_spg-create-BP:true/false,SP-NAME - with SP-NAME defined only the OUTBOUND profile is created with the defined SP-NAME
* UTIL optimise test_filter script for QA

BUGFIX:
* UTIL API - bugfix related to JSON output
* UTIL type=rule | bugfix 'filter=(rule is.unused.fast)' if searching via API mode on Panorama
* class PanAPIConnector | bugfix to avoid using shadow-apikeynohidden for PAN-OS >=9 if Panorama is used as proxy
* UTIL type=rule 'filter=(src has OBJECTNAME)' - fix if object does not exist at same DG level or above - filter is now returning false
* UTIL type=tag | bugfix for 'filter=(reflocation is shared )'

GENERAL:
* introduce UTIL actions test script
* framework | bugfixes for different CLASSES related to UTIL test_filter / test_action found issues


2.0.33 (20220404)
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
}
],
"require": {
"php": ">=7.4.0"
"php": ">=7.4.0",
"ext-json": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-mbstring": "*",
"ext-bcmath": "*"
}
}
14 changes: 9 additions & 5 deletions lib/container-classes/AddressRuleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ public function API_add($Obj)
*
* @return bool True if Zone was found and removed. False if not found.
*/
public function remove($Obj, $rewriteXml = TRUE, $forceAny = FALSE)
public function remove($Obj, $rewriteXml = TRUE, $forceAny = FALSE, $context = null)
{
$count = count($this->o);

$ret = parent::remove($Obj);

if( $ret && $count == 1 && !$forceAny )
{
derr("you are trying to remove last Object from a rule which will set it to ANY, please use forceAny=true for object: "
. $this->toString());
$string = "you are trying to remove last Object from a rule which will set it to ANY, please use forceAny=true for object: " . $this->toString();
if( $context === null )
derr( $string );

PH::ACTIONstatus( $context, 'skipped', $string);
return false;
}

if( $ret && $rewriteXml )
Expand All @@ -144,9 +148,9 @@ public function remove($Obj, $rewriteXml = TRUE, $forceAny = FALSE)
* @param bool $forceAny
* @return bool
*/
public function API_remove($Obj, $forceAny = FALSE)
public function API_remove($Obj, $forceAny = FALSE, $context = null)
{
if( $this->remove($Obj, TRUE, $forceAny) )
if( $this->remove($Obj, TRUE, $forceAny, $context) )
{
$con = findConnectorOrDie($this);

Expand Down
7 changes: 6 additions & 1 deletion lib/container-classes/ServiceRuleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,13 @@ public function rewriteXML()
{
if( $this->appDef )
DH::Hosts_to_xmlDom($this->xmlroot, $this->o, 'member', TRUE, 'application-default');
else
elseif( $this->xmlroot !== null )
DH::Hosts_to_xmlDom($this->xmlroot, $this->o, 'member', TRUE);
elseif( $this->xmlroot === null )
{
//DH::Hosts_to_xmlDom($this->xmlroot, $this->o, 'member', TRUE);
}

}


Expand Down
2 changes: 2 additions & 0 deletions lib/misc-classes/PH.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,8 @@ public static function UTILdeprecated( $type, $argv, $argc, $PHP_FILE)
mwarning( 'this script '.basename($PHP_FILE).' is deprecated, please use: pan-os-php.php', null, FALSE );
PH::print_stdout( PH::boldText("pan-os-php".$argString) );

PH::print_stdout( PH::boldText("sleeping now 15 seconds") );
sleep(15);

PH::callPANOSPHP( $type, $argv, $argc, $PHP_FILE );

Expand Down
2 changes: 1 addition & 1 deletion lib/misc-classes/filters/filters-Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@
'arg' => true,
'help' => 'returns TRUE if object IP value describe multiple IP addresses; e.g. ip-range: 10.0.0.0-10.0.0.255 will match "ip.count > 200"',
'ci' => array(
'fString' => '(%PROP%)',
'fString' => '(%PROP% 5)',
'input' => 'input/panorama-8.0.xml'
)
);
Expand Down
66 changes: 52 additions & 14 deletions lib/misc-classes/filters/filters-Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@
);
RQuery::$defaultFilters['rule']['tag']['operators']['has.regex'] = array(
'Function' => function (RuleRQueryContext $context) {

if( !isset( $context->object->tags ) )
return FALSE;

foreach( $context->object->tags->tags() as $tag )
{
$matching = preg_match($context->value, $tag->name());
Expand Down Expand Up @@ -1148,7 +1152,8 @@
RQuery::$defaultFilters['rule']['app']['operators']['has.regex'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )

if( !isset( $context->object->apps ) )
return FALSE;

foreach( $context->object->apps->apps() as $app )
Expand All @@ -1172,7 +1177,7 @@
RQuery::$defaultFilters['rule']['app']['operators']['has.recursive'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )
if( !isset( $rule->apps ) )
return FALSE;

foreach( $rule->apps->getAll() as $app)
Expand Down Expand Up @@ -1208,7 +1213,7 @@
RQuery::$defaultFilters['rule']['app']['operators']['includes.full.or.partial'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )
if( !isset( $rule->apps ) )
return FALSE;

/** @var Rule|SecurityRule|AppOverrideRule|PbfRule|QoSRule $object */
Expand All @@ -1224,7 +1229,7 @@
RQuery::$defaultFilters['rule']['app']['operators']['includes.full.or.partial.nocase'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )
if( !isset( $rule->apps ) )
return FALSE;

return $rule->apps->includesApp($context->value, FALSE) === TRUE;
Expand All @@ -1238,7 +1243,7 @@
RQuery::$defaultFilters['rule']['app']['operators']['included-in.full.or.partial'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )
if( !isset( $rule->apps ) )
return FALSE;

/** @var Rule|SecurityRule|AppOverrideRule|PbfRule|QoSRule $object */
Expand All @@ -1254,7 +1259,7 @@
RQuery::$defaultFilters['rule']['app']['operators']['included-in.full.or.partial.nocase'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )
if( !isset( $rule->apps ) )
return FALSE;

return $rule->apps->includedInApp($context->value, FALSE) === TRUE;
Expand All @@ -1268,7 +1273,7 @@
RQuery::$defaultFilters['rule']['app']['operators']['custom.has.signature'] = array(
'Function' => function (RuleRQueryContext $context) {
$rule = $context->object;
if( $rule->isNatRule() || $rule->isDecryptionRule() || $rule->isCaptivePortalRule() || $rule->isAuthenticationRule() || $rule->isDoSRule() )
if( !isset( $rule->apps ) )
return FALSE;

/** @var Rule|SecurityRule|AppOverrideRule|PbfRule|QoSRule $object */
Expand All @@ -1290,6 +1295,9 @@
if( $rule->isNatRule() )
return $rule->service === null;

if( $rule->services === null )
return false;

return $rule->services->isAny();
},
'arg' => FALSE,
Expand All @@ -1311,7 +1319,7 @@
RQuery::$defaultFilters['rule']['service']['operators']['has'] = array(
'eval' => function ($object, &$nestedQueries, $value) {
/** @var Rule|SecurityRule|NatRule|DecryptionRule|AppOverrideRule|CaptivePortalRule|AuthenticationRule|PbfRule|QoSRule|DoSRule $object */
return $object->services->has($value) === TRUE;
return $object->isSecurityRule() && $object->services->has($value) === TRUE;
},
'arg' => TRUE,
'argObjectFinder' => "\$objectFind=null;\n\$objectFind=\$object->services->parentCentralStore->find('!value!');"
Expand All @@ -1325,6 +1333,9 @@
return FALSE;
return $object->service === $value;
}
if( $object->services === null )
return FALSE;

if( $object->services->count() != 1 || !$object->services->has($value) )
return FALSE;

Expand All @@ -1349,6 +1360,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

foreach( $rule->services->all() as $service )
{
$matching = preg_match($context->value, $service->name());
Expand Down Expand Up @@ -1387,6 +1401,9 @@
return $rule->service->hasNamedObjectRecursive($value);
}

if( $rule->services === null )
return FALSE;

return $rule->services->hasNamedObjectRecursive($value);
},
'arg' => TRUE,
Expand All @@ -1406,6 +1423,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

/** @var Service|ServiceGroup $value */
$objects = $rule->services->all();

Expand Down Expand Up @@ -1445,6 +1465,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

/** @var Service|ServiceGroup $value */
$objects = $rule->services->all();
foreach( $objects as $object )
Expand Down Expand Up @@ -1484,6 +1507,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

/** @var Service|ServiceGroup $value */
$objects = $rule->services->all();

Expand Down Expand Up @@ -1524,6 +1550,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

/** @var Service|ServiceGroup $value */
$objects = $rule->services->all();
foreach( $objects as $object )
Expand Down Expand Up @@ -1563,6 +1592,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

return $rule->services->hasValue($value, TRUE);
},
'arg' => TRUE,
Expand All @@ -1583,6 +1615,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

return $rule->services->hasValue($value);
},
'arg' => TRUE,
Expand All @@ -1603,6 +1638,9 @@
return FALSE;
}

if( $rule->services === null )
return FALSE;

if( $rule->services->count() != 1 )
return FALSE;

Expand All @@ -1620,9 +1658,9 @@
$counter = $context->value;
$rule = $context->object;

if( $rule->isNatRule() )
if( !$rule->isSecurityRule() )
{
mwarning("this filter does not yet support NAT Rules");
mwarning("this filter does only yet support Security Rules", null, FALSE);
return FALSE;
}

Expand All @@ -1649,9 +1687,9 @@
$counter = $context->value;
$rule = $context->object;

if( $rule->isNatRule() )
if( !$rule->isSecurityRule() )
{
mwarning("this filter does not yet support NAT Rules");
mwarning("this filter does only yet support Security Rules", null, FALSE);
return FALSE;
}

Expand All @@ -1678,9 +1716,9 @@
$counter = $context->value;
$rule = $context->object;

if( $rule->isNatRule() )
if( !$rule->isSecurityRule() )
{
mwarning("this filter does not yet support NAT Rules");
mwarning("this filter does only yet support Security Rules", null, FALSE);
return FALSE;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/misc-classes/trait/ReferenceableObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function getReferencesLocation( &$counter_array = array() )
{
#print get_class( $cur)."\n";
//Firewall
if( isset($cur->owner->owner) && $cur->owner->owner !== null && $cur->owner->owner->name() !== "")
if( isset($cur->owner->owner) && $cur->owner->owner !== null && method_exists($cur->owner->owner,'name') && $cur->owner->owner->name() !== "")
{
#print $cur->owner->owner->name()."\n";
$location_array[$cur->owner->owner->name()] = $cur->owner->owner->name();
Expand All @@ -246,14 +246,14 @@ public function getReferencesLocation( &$counter_array = array() )
}

//Panorama
if( isset($cur->owner->owner->owner) && $cur->owner->owner->owner !== null && $cur->owner->owner->owner->name() !== "")
if( isset($cur->owner->owner->owner) && $cur->owner->owner->owner !== null && method_exists($cur->owner->owner->owner,'name') && $cur->owner->owner->owner->name() !== "")
{
#print $cur->owner->owner->owner->name()."\n";
$location_array[$cur->owner->owner->owner->name()] = $cur->owner->owner->owner->name();
if( isset($counter_array[$cur->owner->owner->name()]))
$counter_array[$cur->owner->owner->name()] += 1;
if( isset($counter_array[$cur->owner->owner->owner->name()]))
$counter_array[$cur->owner->owner->owner->name()] += 1;
else
$counter_array[$cur->owner->owner->name()] = 1;
$counter_array[$cur->owner->owner->owner->name()] = 1;
}


Expand Down
6 changes: 6 additions & 0 deletions lib/object-classes/AddressGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ public function rewriteXML()
if( $this->isDynamic() )
derr('unsupported rewriteXML for dynamic group');

if( !isset($this->owner->owner) )
return;

if( $this->xmlroot === false || $this->membersRoot === false )
return;

if( $this->owner->owner->version >= 60 )
DH::Hosts_to_xmlDom($this->membersRoot, $this->members, 'member', FALSE);
else
Expand Down
2 changes: 1 addition & 1 deletion lib/object-classes/AddressStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public function rewriteAddressGroupStoreXML()
*/
public function newAddress($name, $type, $value, $description = '')
{
$found = $this->find($name, null, TRUE);
$found = $this->find($name, null, FALSE);
if( $found !== null )
derr("cannot create Address named '" . $name . "' as this name is already in use");

Expand Down
4 changes: 2 additions & 2 deletions lib/object-classes/SecurityProfileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ public function load_predefined_url_categories_from_domxml(DOMElement $xml)


/**
* @param SecurityProfile $tag
* @param SecurityProfile| URLProfile | AntiSpywareProfile | AntiVirusProfile | VulnerabilityProfile | FileBlockingProfile | WildfireProfile $tag
*
* @return bool True if Zone was found and removed. False if not found.
*/
public function removeSecurityProfile(SecurityProfile $tag)
public function removeSecurityProfile( $tag)
{
$ret = $this->remove($tag);

Expand Down
Loading

0 comments on commit 2eec7d6

Please sign in to comment.