Skip to content

Commit

Permalink
Add Name column for NAT policy and a flag whether to show each rule's…
Browse files Browse the repository at this point in the history
… UID (#29)
  • Loading branch information
chkp-edenbr authored Dec 14, 2022
1 parent 20925c1 commit 88cdc42
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ When running the command on a Multi domain server the default domain is the "MDS

[-v] (Optional): List the existing policy packages.

[-c] (Optional): Retrieve access policy rules hit counts.
[-c] (Optional): Retrieve access policy rules' hit count.

[--show-rule-uid] (Optional): Show each rule's UID.

[-k package-name] (Optional): The package name or the uid of the policy package to show.
When a package-name is not provided, the tool will provide details on all the policy-packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum ShowPackageConfiguration {

INSTANCE;

private static final String TOOL_VERSION = "v2.0.6";
private static final String TOOL_VERSION = "v2.1.0";
private static final String TAR_SUFFIX = ".tar.gz";
private static final String LOG_SUFFIX = ".elg";
private static final String PREFIX = "show_package-";
Expand Down Expand Up @@ -97,6 +97,8 @@ public enum ShowPackageConfiguration {
private HtmlUtils htmlUtil = HtmlUtils.INSTANCE;
private static RandomAccessFile objectsWriter;

private static boolean showEachRulesUid = false;

private static RandomAccessFile rulbaseWriter;
void initializeParameters(String[] args) throws Exception{

Expand Down Expand Up @@ -214,7 +216,7 @@ private String resolveFlags(String[] args) {
if(option.equals(Options.listOfPackages) || option.equals(Options.help)
|| option.equals(Options.debugInfo) || option.equals(Options.unsafeState)
|| option.equals(Options.showHitCounts) || option.equals(Options.deleteTempFiles)
|| option.equals(Options.version)){
|| option.equals(Options.version) || option.equals(Options.showRuleUid)){
//Options that don't require a value after the flag
option.runCommand("");
i++;
Expand Down Expand Up @@ -542,6 +544,8 @@ public Boolean getDereferenceGroupMembers()

public boolean showNatPolicyFlag() { return doShowNatPolicy; }

public boolean showRuleUidFlag() { return showEachRulesUid; }

/**
* This enum defines the known flags and the actions each of them does.
*/
Expand Down Expand Up @@ -786,6 +790,26 @@ String debugString()
return "showRulesHitCounts:(-c)=" + showRulesHitCounts;
}
},
showRuleUid("--show-rule-uid") {
void runCommand(String value)
{
showEachRulesUid = true;
}

String value(){
return "";
}

void flagToString()
{
System.out.println("\tShow Each rule's UID.\n\tDefault {false}");
}

String debugString()
{
return "showEachRulesUid:(--show-rule-uid)=" + showEachRulesUid;
}
},
queryLimit("--query-limit") {
void runCommand(String limitString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ private static boolean writeRulebase(String layerName,String packageName, Ruleba
configuration.getHtmlUtils().writeRulebaseHTML(layerName, packageName, domain, loginResponse.getApiVersion(),
rulebaseType.typeToString(),
configuration.getUidToName(),
inlineLayers, failedCreatingRulebase);
inlineLayers, failedCreatingRulebase, configuration.showRuleUidFlag());
configuration.getRulbaseWriter().seek(0);
configuration.getRulbaseWriter().writeBytes("[");
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/checkpoint/mgmt_api/utils/HtmlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,15 @@ public String getJsonFileName()

public void writeRulebaseHTML(String layerName, String packageName, String domain, String apiVersion,
String rulebaseType ,Map<String,String> uidToName,
Set<Layer> inlineLayers, boolean failedCreatingRulbase) throws IOException {
Set<Layer> inlineLayers, boolean failedCreatingRulbase, boolean showRuleUid) throws IOException {

//In case of nat set the domain name to be 'Management server'
if(domain == null || domain.isEmpty()) {
domain = "Management server";
}

String rulebase = "{\"api-version\" : \"" + apiVersion + "\", \"domain\" : \"" + domain + "\", \"package\" : \""
String rulebase = "{\"api-version\" : \"" + apiVersion + "\", \"showRuleUid\" : \"" + showRuleUid + "\", " +
"\"domain\" : \"" + domain + "\", \"package\" : \""
+ packageName + "\", " + "\"layer\" : \"" + layerName + "\", \"type\" : \"" + rulebaseType + "\"}";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,22 @@
</script>

<script>
var unsupportedNatRuleNameVersions = ["1.6.1", "1.6", "1.5", "1.4", "1.3", "1.2", "1.1", "1"]
var accessColumnHeaders = ["No.", "Name", "Source", "Destination", "VPN", "Service/Application", getDataHeader(), "Action", "Track", "Time", "Install-On", "Comments"];
if (showHitCount) {
accessColumnHeaders.splice(1, 0, "Hits");
}
var natColumnHeaders = ["No.", "Original Source", "Original Destination", "Original Services", "Translated Source", "Translated Destination", "Translated Services", "Install-On", "Comments"];
if (!unsupportedNatRuleNameVersions.includes(getApiVersion())){
natColumnHeaders.splice(1, 0, "Name");
}
var threatColumnHeaders = ["No.", "Name", "Protected Scope", "Source", "Destination", "Protection/Site", "Services", "Action", "Track", "install-On", "Comments"];

var columnHeaders;
if (getShowRuleUid() === "true"){
accessColumnHeaders.splice(1, 0, "UID");
natColumnHeaders.splice(1, 0, "UID");
threatColumnHeaders.splice(1, 0, "UID");
}

function getOptionalTextValue(elem, key) {
if (key in elem) return elem[key];
Expand Down Expand Up @@ -304,6 +312,14 @@
return rulebase["api-version"] != "null" && rulebase["api-version"] != "1";
}

function getApiVersion(){
return rulebase["api-version"];
}

function getShowRuleUid() {
return rulebase["showRuleUid"];
}

function drawNatRule(ruleObject) {
var tr = document.createElement("tr");
if (!ruleObject.enabled) {
Expand All @@ -314,6 +330,12 @@
td_number.appendChild(document.createTextNode(ruleObject["rule-number"]));

tr.appendChild(td_number);
if (natColumnHeaders.includes("UID")){
tr.appendChild(drawTextCell(ruleObject, "uid"));
}
if (natColumnHeaders.includes("Name")){
tr.appendChild(drawTextCell(ruleObject, "name"));
}
tr.appendChild(drawSingleValueCell(ruleObject["original-source"]));
tr.appendChild(drawSingleValueCell(ruleObject["original-destination"]));
tr.appendChild(drawSingleValueCell(ruleObject["original-service"]));
Expand Down Expand Up @@ -375,7 +397,9 @@
td_data.appendChild(document.createTextNode(dataDirectionText));
}
tr.appendChild(td_number);

if (accessColumnHeaders.includes("UID")){
tr.appendChild(drawTextCell(ruleObject, "uid"));
}
if (showHitCount) {
tr.appendChild(drawTextCell(ruleObject.hits || {}, "value"));
}
Expand Down Expand Up @@ -407,6 +431,9 @@
td_number.appendChild(document.createTextNode(ruleObject["rule-number"]));

tr.appendChild(td_number);
if (threatColumnHeaders.includes("UID")){
tr.appendChild(drawTextCell(ruleObject, "uid"));
}
tr.appendChild(drawTextCell(ruleObject, "name"));
tr.appendChild(drawMultiValueCell(ruleObject["protected-scope"], ruleObject["protected-scope-negate"]));
tr.appendChild(drawMultiValueCell(ruleObject["source"], ruleObject["source-negate"]));
Expand Down

0 comments on commit 88cdc42

Please sign in to comment.