Skip to content

Commit

Permalink
Merge pull request #633 from swaschkut/main
Browse files Browse the repository at this point in the history
version 2.0.55 - bugfix for type=diff argument "filter=xyz" | type=[UTIL]-merger - introduction of dupalgoritm=identical for all util mergers
  • Loading branch information
swaschkut authored Aug 8, 2022
2 parents c984737 + 6e7fd4e commit 941e89a
Show file tree
Hide file tree
Showing 9 changed files with 611 additions and 267 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ CHANGELOG

2.0.55
UTIL:
* type=addressgroup-/servicegroup-/service-merger | introduce dupalgorithm=identical
* type=servicegroup-merger | introduce childDG validation
* type=addressgroup-/servicegroup-/merger - for childDG object move; correct hashmap object array of actual DG

BUGFIX:
* type=diff "filter=XPATH" | bugfix as filter was not used
* type=UTIL-merger | fix for Buckbeak validation

GENERAL:
* extend different Fawkes and Buckbeak related classes
* improve bash completion script
* class TemplateStack | introduce method setName()
* class PanoramaConf | introduce method removeTemplateStack - improve removeDeviceGroup and removeTemplate
* class MERGER | method servicegroup_merger - correct variable name
* test script optimisation - MERGER output adjustment


2.0.54 (20220803)
Expand Down
51 changes: 47 additions & 4 deletions lib/device-and-system-classes/PanoramaConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,9 @@ public function removeDeviceGroup( $DG )
//remove DG from XML
$xPath = "/config/devices/entry[@name='localhost.localdomain']/device-group";
$dgNode = DH::findXPathSingleEntryOrDie($xPath, $this->xmlroot);
$dgNode->removeChild( $DG->xmlroot );

$DGremove = DH::findFirstElementByNameAttrOrDie('entry', $DGname, $dgNode);
$dgNode->removeChild( $DGremove );

//remove DG from DG Meta
if( $this->version >= 80 )
Expand All @@ -1698,7 +1700,7 @@ public function removeDeviceGroup( $DG )
$DGmetaData = DH::findFirstElementByNameAttrOrDie('entry', $DGname, $dgMetaDataNode);
$dgMetaDataNode->removeChild( $DGmetaData );

//Todo: cleanup memory
unset($this->deviceGroups[ $DGname ]);
}


Expand Down Expand Up @@ -1790,7 +1792,7 @@ public function removeTemplate( $template )
{
$Templatename = $template->name();

$template->display_references();
#$template->display_references();

/*
* //warning if template is used in TemplateStack
Expand All @@ -1809,12 +1811,53 @@ public function removeTemplate( $template )
//remove Template from XML
$xPath = "/config/devices/entry[@name='localhost.localdomain']/template";
$dgNode = DH::findXPathSingleEntryOrDie($xPath, $this->xmlroot);
$dgNode->removeChild( $template->xmlroot );

$remove = DH::findFirstElementByNameAttrOrDie('entry', $Templatename, $dgNode);
$dgNode->removeChild( $remove );


unset($this->templates[$Templatename]);
//Todo: cleanup memory
//}
}


/**
* Remove a template.
* @param TemplateStack $templateStack
**/
public function removeTemplateStack( $templateStack )
{
$TemplateStackname = $templateStack->name();

#$templateStack->display_references();

/*
* //warning if template is used in TemplateStack
* //implementation missing also in actions-device line 294
* DeviceCallContext::$supportedActions['Template-delete'] = array(
*
$childDGs = $DG->_childDeviceGroups;
if( count( $childDGs ) !== 0 )
{
mwarning("DeviceGroup '$DGname' has ChildDGs. Delete of DG not possible.");
return;
}
else
{
*/
//remove TemplateSTack from XML
$xPath = "/config/devices/entry[@name='localhost.localdomain']/template-stack";
$dgNode = DH::findXPathSingleEntryOrDie($xPath, $this->xmlroot);

$remove = DH::findFirstElementByNameAttrOrDie('entry', $TemplateStackname, $dgNode);
$dgNode->removeChild( $remove );

unset($this->templatestacks[$TemplateStackname]);

//}
}

/**
* @return Template[]
*/
Expand Down
18 changes: 10 additions & 8 deletions lib/device-and-system-classes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public function name()
return $this->name;
}

//Todo: setName();
//Problem is that this Template part is never used and can not written in XML yet, how to continue????
//or can it????
public function setName($newName)
{
$this->xmlroot->setAttribute('name', $newName);

$this->name = $newName;
}

public function &getXPath()
{
$str = "/config/devices/entry[@name='localhost.localdomain']/template/entry[@name='" . $this->name . "']";
Expand All @@ -95,15 +105,7 @@ public function isTemplate()
return TRUE;
}

//Todo: setName();
//Problem is that this Template part is never used and can not written in XML yet, how to continue????
//or can it????
public function setName($newName)
{
$this->xmlroot->setAttribute('name', $newName);

$this->name = $newName;
}

public function load_from_templateXml()
{
Expand Down
7 changes: 7 additions & 0 deletions lib/device-and-system-classes/TemplateStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public function name()
return $this->name;
}

public function setName($newName)
{
$this->xmlroot->setAttribute('name', $newName);

$this->name = $newName;
}

public function isTemplateStack()
{
return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion lib/misc-classes/filters/filters-Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@
},
'arg' => FALSE,
'ci' => array(
'fString' => '(%PROP% 443)',
'fString' => '(%PROP%)',
'input' => 'input/panorama-8.0.xml'
)
);
Expand Down
4 changes: 4 additions & 0 deletions tests/test_mergers.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,24 @@ function runCommand($bin, &$stream, $force = TRUE, $command = '')
$util = '../utils/pan-os-php.php type=addressgroup-merger';
$dupalgorithm_array[] = 'SameMembers';
$dupalgorithm_array[] = 'SameIP4Mapping';
$dupalgorithm_array[] = 'Identical';
$dupalgorithm_array[] = 'Whereused';

}
elseif( $merger == 'service' )
{
$util = '../utils/pan-os-php.php type=service-merger';
$dupalgorithm_array[] = 'SameDstSrcPorts';
$dupalgorithm_array[] = 'SamePorts';
$dupalgorithm_array[] = 'Identical';
$dupalgorithm_array[] = 'Whereused';
}
elseif( $merger == 'servicegroup' )
{
$util = '../utils/pan-os-php.php type=servicegroup-merger';
$dupalgorithm_array[] = 'SameMembers';
$dupalgorithm_array[] = 'SamePortMapping';
$dupalgorithm_array[] = 'Identical';
$dupalgorithm_array[] = 'Whereused';
}
elseif( $merger == 'tag' )
Expand Down
9 changes: 8 additions & 1 deletion tests/test_utilscripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
##"xml-op-json",
##"bpa-generator"
);

/*
address config-commit download-predefined license routing service spiffy traffic-log xml-op-json
address-merger config-download-all gratuitous-arp maxmind-update rule service-merger stats upload zone
addressgroup-merger config-size html-merger override-finder rule-merger servicegroup-merger system-log userid-mgr
appid-enabler device interface playbook schedule software-download tag util_get-action-filter
application dhcp ironskillet-update protocoll-number-download securityprofile software-preparation tag-merger virtualwire
bpa-generator diff key-manager register-ip-mgr securityprofilegroup software-remove threat xml-issue
*/

foreach( $supportedUTILTypes as $util )
{
Expand Down
50 changes: 30 additions & 20 deletions utils/bash_autocompletion/pan-os-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,45 +71,57 @@ __pan-os-php_scripts()

prev2=${COMP_WORDS[COMP_CWORD-2]}

if [[ "${cur}" = "=" || "${prev}" = "=" ]] ; then
if [[ "${cur}" == "=" || "${prev}" == "=" ]] ; then
RepPatt="="
RepBy=""
cur2="${cur//$RepPatt/$RepBy}"

if [[ "${prev}" = "type" || "${prev2}" = "type" \
if [[ "${prev}" == "type" || "${prev2}" == "type" \
]] ; then

compopt +o nospace
COMPREPLY=($(compgen -W '${type[*]}' -- "${cur2}"))
typeargument="${COMP_WORDS[COMP_CWORD]}"
elif [[ "${prev}" = "actions" || "${prev2}" = "actions" \

elif [[ "${prev}" == "actions" || "${prev2}" == "actions" \
]] ; then

actions=$(jq -r ".\"${typeargument}\" | select(.action != []) | .action | keys[]" $jsonFILE )
for KEY in "${!COMP_WORDS[@]}"; do
if [[ "${COMP_WORDS[$KEY]}" == "type" ]] ; then
typeargument=${COMP_WORDS[$KEY+2]}
fi
done

actions=$(jq -r ".\"${typeargument}\" | select(.action != null) | .action | keys[]" $jsonFILE )

compopt +o nospace
COMPREPLY=($(compgen -W '${actions[*]}' -- "${cur2}"))
actionargument="${COMP_WORDS[COMP_CWORD]}"
elif [[ "${prev}" = "filter" || "${prev2}" = "filter" \
elif [[ "${prev}" == "filter" || "${prev2}" == "filter" \
]] ; then

filters=$(jq -r ".\"${typeargument}\" | select(.filter != []) | .filter | keys[]" $jsonFILE)
for KEY in "${!COMP_WORDS[@]}"; do
if [[ "${COMP_WORDS[$KEY]}" == "type" ]] ; then
typeargument=${COMP_WORDS[$KEY+2]}
fi
done

filters=$(jq -r ".\"${typeargument}\" | select(.filter != null) | .filter | keys[]" $jsonFILE)

compopt +o nospace
COMPREPLY=($(compgen -W '${filters[*]}' -- "${cur2}"))
elif [[ "${prev}" = "location" || "${prev2}" = "location" \
elif [[ "${prev}" == "location" || "${prev2}" == "location" \
]] ; then

compopt +o nospace
elif [[ "${prev}" = "loadplugin" || "${prev2}" = "loadplugin" \
elif [[ "${prev}" == "loadplugin" || "${prev2}" == "loadplugin" \
]] ; then

compopt +o nospace
elif [[ "${prev}" = "template" || "${prev2}" = "template" \
elif [[ "${prev}" == "template" || "${prev2}" == "template" \
]] ; then

compopt +o nospace
elif [[ "${prev}" = "apitimeout" || "${prev2}" = "apitimeout" \
elif [[ "${prev}" == "apitimeout" || "${prev2}" == "apitimeout" \
]] ; then

compopt +o nospace
Expand All @@ -119,15 +131,15 @@ __pan-os-php_scripts()
compopt -o filenames
COMPREPLY=( $(compgen -f -- ${cur2} ) )
fi
elif [[ "${cur}" = ":" || "${prev}" = ":" ]] ; then
elif [[ "${cur}" == ":" || "${prev}" == ":" ]] ; then
echo ":"
else
# remove used argument from array
local word

prevstring=""
for word in ${COMP_WORDS[*]}; do
if [[ ${word} = "=" ]]; then
if [[ ${word} == "=" ]]; then
case ${prevstring} in
type*)
unset 'arguments[0]'
Expand Down Expand Up @@ -212,7 +224,7 @@ __pan-os-php_scripts()
local arg compreply=""
COMPREPLY=($(compgen -W '${arguments[*]}' -- "${COMP_WORDS[COMP_CWORD]}"))

if [[ ${#COMPREPLY[*]} = 1 ]] && [[ ${COMPREPLY[0]} =~ "=" ]] ; then
if [[ ${#COMPREPLY[*]} == 1 ]] && [[ ${COMPREPLY[0]} =~ "=" ]] ; then
compopt -o nospace
else
compopt +o nospace
Expand Down Expand Up @@ -265,7 +277,7 @@ __pan-os-php_scripts()

COMPREPLY=( $(compgen -o filenames -f -- ${cur2} ) )

if [ ${#COMPREPLY[*]} = 1 ]; then
if [ ${#COMPREPLY[*]} == 1 ]; then
[ -d "$COMPREPLY" ] && LASTCHAR=/
COMPREPLY=$(printf %q%s "$COMPREPLY" "$LASTCHAR")
fi
Expand All @@ -276,7 +288,7 @@ __pan-os-php_scripts()

COMPREPLY=( $(compgen -o filenames -f -- ${cur2} ) )

if [ ${#COMPREPLY[*]} = 1 ]; then
if [ ${#COMPREPLY[*]} == 1 ]; then
[ -d "$COMPREPLY" ] && LASTCHAR=/
COMPREPLY=$(printf %q%s "$COMPREPLY" "$LASTCHAR")
fi
Expand All @@ -287,7 +299,7 @@ __pan-os-php_scripts()

COMPREPLY=( $(compgen -o filenames -f -- ${cur2} ) )

if [ ${#COMPREPLY[*]} = 1 ]; then
if [ ${#COMPREPLY[*]} == 1 ]; then
[ -d "$COMPREPLY" ] && LASTCHAR=/
COMPREPLY=$(printf %q%s "$COMPREPLY" "$LASTCHAR")
fi
Expand Down Expand Up @@ -334,6 +346,7 @@ __pan-os-php_scripts()
fi
}


if [ -n "$ZSH_VERSION" ]; then
# assume Zsh
echo "ZSH is not supported yet"
Expand Down Expand Up @@ -363,6 +376,3 @@ else
echo "no supported SHELL"
return 0
fi



Loading

0 comments on commit 941e89a

Please sign in to comment.