Skip to content

Commit

Permalink
Merge pull request #339 from swaschkut/developer
Browse files Browse the repository at this point in the history
UTIL all script - optimise to always use single method entry from PAN-OS-PHP
  • Loading branch information
swaschkut authored Dec 3, 2021
2 parents 3cee17e + f93014b commit 3a4d737
Show file tree
Hide file tree
Showing 40 changed files with 260 additions and 587 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ UTILS:
* pa_rule-edit | 'actions=exportToExcel:FILE.html,ResolveAddressSummary|ResolveserviceSummary|ResolveApplicationsummary' - improve resolveservicesummary, if application-default is used in service and app-id has specified apps
* pa_zone-edit | introduce actions=name-rename:NewZoneNAME
* UTIL all script | introduce new argument "auditComment=XYZ" to bring in your custom auditComment
* UTIL all script - remove duplicate header / footer
* UTIL all script - optimise to always use single method entry from PAN-OS-PHP

BUGFIX:
* UTIL script download predefined PAN-OS content data - bugfix/workaround if PAN-OS API bring in double <response><return
* pa_tag-edit | actions=created:NewTag - bugfix to not error out on PAN-OS API - first check if NewTag is already availalble
* framework class App | bugfix as FawkesConf has no appstore at shared level / has no SHARED level
* UTIL pa_rule-edit | actions=display,ResolveServiceSummary bringing back consistent output for port and application-default app-id port
* class PanAPIConnector - bugfix if connection timeout

GENERAL:
* framework - content id update to version 8494-7079
Expand Down
107 changes: 107 additions & 0 deletions lib/misc-classes/PH.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,111 @@ public static function getFilesInFolder( $folder )
return $files;
}

public static function UTILdeprecated( $type, $argv, $argc, $PHP_FILE)
{
$TESTargv = $argv;
unset( $TESTargv[0] );
$argString = " type=".$type." '".implode( "' '", $TESTargv)."'";

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::callPANOSPHP( $type, $argv, $argc, $PHP_FILE );

}

public static $supportedUTILTypes = array(
"stats",
"address", "service", "tag", "schedule", "application", "threat",
"rule",
"device", "securityprofile", "securityprofilegroup",
"zone", "interface", "virtualwire", "routing",
"key-manager",
"address-merger", "addressgroup-merger",
"service-merger", "servicegroup-merger",
"tag-merger",
"rule-merger",
"override-finder",
"diff",
"upload",
"xml-issue",
"appid-enabler",
"config-size",
"download-predefined",
"register-ip-mgr",
"userid-mgr",
"xml-op-json",
"bpa-generator"
);

public static function callPANOSPHP( $type, $argv, $argc, $PHP_FILE )
{
if( $type == "rule" )
$util = new RULEUTIL($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "stats" )
$util = new STATSUTIL( $type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "securityprofile" )
$util = new SECURITYPROFILEUTIL($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "zone"
|| $type == "interface"
|| $type == "routing"
|| $type == "virtualwire"
)
$util = new NETWORKUTIL($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "device" )
$util = new DEVICEUTIL($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "key-manager" )
$util = new KEYMANGER($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "address-merger"
|| $type == "addressgroup-merger"
|| $type == "service-merger"
|| $type == "servicegroup-merger"
|| $type == "tag-merger"
)
$util = new MERGER($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "rule-merger" )
$util = new RULEMERGER($type, $argv, $argc,$PHP_FILE." type=".$type );

elseif( $type == "override-finder" )
$util = new OVERRIDEFINDER($type, $argv, $argc,$PHP_FILE." type=".$type);
elseif( $type == "diff" )
$util = new DIFF($type, $argv, $argc,$PHP_FILE." type=".$type);
elseif( $type == "upload" )
$util = new UPLOAD($type, $argv, $argc,$PHP_FILE." type=".$type);
elseif( $type == "xml-issue" )
$util = new XMLISSUE($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "appid-enabler" )
$util = new APPIDENABLER($type, $argv, $argc,$PHP_FILE." type=".$type);
elseif( $type == "config-size" )
$util = new CONFIGSIZE($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "download-predefined" )
$util = new PREDEFINED($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "register-ip-mgr" )
$util = new REGISTERIP($type, $argv, $argc,$PHP_FILE." type=".$type );

elseif( $type == "userid-mgr" )
$util = new USERIDMGR($type, $argv, $argc,$PHP_FILE." type=".$type);

elseif( $type == "xml-op-json" )
$util = new XMLOPJSON($type, $argv, $argc,$PHP_FILE." type=".$type );

elseif( $type == "bpa-generator" )
$util = new BPAGENERATOR($type, $argv, $argc,$PHP_FILE." type=".$type);

else
$util = new UTIL($type, $argv, $argc,$PHP_FILE." type=".$type);

return $util;
}
}
8 changes: 4 additions & 4 deletions lib/misc-classes/PanAPIConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ static public function findOrCreateConnectorFromHost($host, $apiKey = null, $pro
if( $host != "bpa-apikey" && $host != "license-apikey" && $host != "ldap-password" && $host != "maxmind-licensekey" )
{
$wrongLogin = TRUE;

if( isset( $_SERVER['REQUEST_METHOD'] ) )
derr($e->getMessage());
elseif( strpos($e->getMessage(), "Invalid credentials.") === FALSE )
{
if( strpos($e->getMessage(), "Invalid credentials.") === FALSE )
derr($e->getMessage());
derr($e->getMessage(), null , FALSE );
}

}
}
PH::$useExceptions = $exceptionUse;
Expand Down
16 changes: 2 additions & 14 deletions utils/address-edit.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ISC License
*
Expand All @@ -19,21 +18,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#require_once("lib/autoloader.php");
#spl_autoload_register('myAutoloader');

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

require_once dirname(__FILE__)."/../utils/lib/UTIL.php";

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$util = new UTIL("address", $argv, $argc, __FILE__);

PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "address", $argv, $argc, __FILE__ );
#$util = new UTIL("address", $argv, $argc, __FILE__);
13 changes: 2 additions & 11 deletions utils/address-merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@

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

require_once dirname(__FILE__)."/../utils/lib/UTIL.php";

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$merger = new MERGER("address-merger", $argv, $argc,__FILE__, array() );

PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "address-merger", $argv, $argc, __FILE__ );
#$merger = new MERGER("address-merger", $argv, $argc,__FILE__ );
13 changes: 2 additions & 11 deletions utils/addressgroup-merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@

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

require_once dirname(__FILE__)."/../utils/lib/UTIL.php";

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$merger = new MERGER("addressgroup-merger", $argv, $argc, __FILE__, array() );

PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "addressgroup-merger", $argv, $argc, __FILE__ );
#$merger = new MERGER("addressgroup-merger", $argv, $argc, __FILE__ );
14 changes: 3 additions & 11 deletions utils/appid-enabler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ISC License
*
Expand All @@ -19,17 +18,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


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

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$util = new APPIDENABLER("appid-enabler", $argv, $argc, __FILE__);

PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "appid-enabler", $argv, $argc, __FILE__ );
#$util = new APPIDENABLER("appid-enabler", $argv, $argc, __FILE__);
13 changes: 2 additions & 11 deletions utils/application-edit.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ISC License
*
Expand All @@ -24,13 +23,5 @@
require_once dirname(__FILE__)."/../lib/pan_php_framework.php";
require_once dirname(__FILE__)."/../utils/lib/UTIL.php";

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$util = new UTIL("application", $argv, $argc, __FILE__);

PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "application", $argv, $argc, __FILE__ );
#$util = new UTIL("application", $argv, $argc, __FILE__);
16 changes: 2 additions & 14 deletions utils/bpa-generator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ISC License
*
Expand All @@ -23,16 +22,5 @@
require_once dirname(__FILE__)."/../lib/pan_php_framework.php";
require_once dirname(__FILE__)."/../utils/lib/UTIL.php";


PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$util = new BPAGENERATOR("bpa-generator", $argv, $argc, __FILE__);

##########################################
##########################################
PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "bpa-generator", $argv, $argc, __FILE__ );
#$util = new BPAGENERATOR("bpa-generator", $argv, $argc, __FILE__);
18 changes: 8 additions & 10 deletions utils/csv-import.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ISC License
*
Expand Down Expand Up @@ -38,11 +37,10 @@

$usageMsg = PH::boldText('USAGE: ') . "php " . basename(__FILE__) . " in=api:://[MGMT-IP] [cycleconnectedFirewalls] [actions=enable]";

PH::print_stdout("" );
PH::print_stdout("***********************************************" );
PH::print_stdout("************ CSV IMPORT UTILITY ****************" );
PH::print_stdout("" );

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$util = new UTIL("custom", $argv, $argc,__FILE__, $supportedArguments, $usageMsg);
$util->utilInit();
Expand Down Expand Up @@ -480,8 +478,8 @@
##########################################

$util->save_our_work();
$this->endOfScript();

PH::print_stdout("" );
PH::print_stdout("************ END OFCSV IMPORT UTILITY ****************" );
PH::print_stdout("***********************************************" );
PH::print_stdout("" );
PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
29 changes: 3 additions & 26 deletions utils/develop/api/v1/tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,13 @@
$url_pieces = array();


$supportedRoute = array(
"stats",
"address", "service", "tag", "schedule", "application", "threat",
"rule",
"device", "securityprofile", "securityprofilegroup",
"zone", "interface", "virtualwire", "routing",
"key-manager",
"address-merger", "addressgroup-merger",
"service-merger", "servicegroup-merger",
"tag-merger",
"rule-merger",
"override-finder",
"diff",
"upload",
"xml-issue",
"appid-enabler",
"config-size",
"download-predefined",
"register-ip-mgr",
"userid-mgr",
"xml-op-json",
"bpa-generator"
);
sort($supportedRoute );
sort(PH::$supportedUTILTypes );

// catch this here, we don't support many routes yet
if( empty( $url_pieces) || ( isset($url_pieces[1]) && !in_array( $url_pieces[1], $supportedRoute ) ) )
if( empty( $url_pieces) || ( isset($url_pieces[1]) && !in_array( $url_pieces[1], PH::$supportedUTILTypes ) ) )
{
$example = "http://localhost:8082/utils/develop/api/v1/tool.php/address?shadow-json";
$message = 'Unknown endpoint. supported: '.implode( ", ", $supportedRoute ).' Example: '.$example;
$message = 'Unknown endpoint. supported: '.implode( ", ", PH::$supportedUTILTypes ).' Example: '.$example;

throw new Exception($message, 404);
}
Expand Down
15 changes: 2 additions & 13 deletions utils/device-edit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php


/**
* ISC License
*
Expand All @@ -23,16 +21,7 @@

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

require_once dirname(__FILE__) . "/../utils/lib/UTIL.php";

PH::print_stdout("");
PH::print_stdout("***********************************************");
PH::print_stdout("*********** " . basename(__FILE__) . " UTILITY **************");
PH::print_stdout("");

$util = new DEVICEUTIL("device", $argv, $argc, __FILE__);

PH::print_stdout("");
PH::print_stdout("************* END OF SCRIPT " . basename(__FILE__) . " ************" );
PH::print_stdout("");
PH::UTILdeprecated( "device", $argv, $argc, __FILE__ );
#$util = new DEVICEUTIL("device", $argv, $argc, __FILE__);
Loading

0 comments on commit 3a4d737

Please sign in to comment.