From c35357938d1c5cb1596b5f7f3e09147c206f663f Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Mon, 7 Aug 2023 16:29:08 -0400
Subject: [PATCH] update for limit type

---
 .../ctapi/json/DecryptedLicenseResponse.java  |  6 +-
 .../ctcloud/Bundle.properties-MERGED          | 10 ++-
 .../ctcloud/CTMalwareScannerOptionsPanel.java | 72 ++++++++++++++++---
 3 files changed, 72 insertions(+), 16 deletions(-)

diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/json/DecryptedLicenseResponse.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/json/DecryptedLicenseResponse.java
index c6f91721ef..d939d6ed75 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/json/DecryptedLicenseResponse.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/json/DecryptedLicenseResponse.java
@@ -38,7 +38,7 @@ public class DecryptedLicenseResponse {
     private final Long fileUploads;
     private final Instant activationTime;
     private final String product;
-    private final String limitType;
+    private final LicenseLimitType limitType;
     private final String timezone;
     private final String customerEmail;
     private final String customerName;
@@ -54,7 +54,7 @@ public DecryptedLicenseResponse(
             @JsonDeserialize(using = InstantEpochMillisDeserializer.class)
             @JsonProperty("activationTime") Instant activationTime,
             @JsonProperty("product") String product,
-            @JsonProperty("limitType") String limitType,
+            @JsonProperty("limitType") LicenseLimitType limitType,
             @JsonProperty("timezone") String timezone,
             @JsonProperty("customerEmail") String customerEmail,
             @JsonProperty("customerName") String customerName
@@ -96,7 +96,7 @@ public String getProduct() {
         return product;
     }
 
-    public String getLimitType() {
+    public LicenseLimitType getLimitType() {
         return limitType;
     }
 
diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/Bundle.properties-MERGED b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/Bundle.properties-MERGED
index b05bb1cfe4..18e60839f3 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/Bundle.properties-MERGED
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/Bundle.properties-MERGED
@@ -22,6 +22,10 @@ CTMalwareScannerOptionsPanel.licenseInfoIdLabel.text=
 CTMalwareScannerOptionsPanel.licenseInfoExpiresLabel.text=
 CTMalwareScannerOptionsPanel.fileUploadsRemainingLabel.text=
 CTMalwareScannerOptionsPanel.licenseInfoUserLabel.text=
+CTMalwareScannerOptionsPanel_getResetSuffix_daily=/day
+CTMalwareScannerOptionsPanel_getResetSuffix_hourly=/hour
+CTMalwareScannerOptionsPanel_getResetSuffix_monthly=/month
+CTMalwareScannerOptionsPanel_getResetSuffix_weekly=/week
 CTMalwareScannerOptionsPanel_licenseAddDialog_desc=License Number:
 CTMalwareScannerOptionsPanel_licenseAddDialog_title=Add a License...
 CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc=The license number has already been entered
@@ -45,9 +49,11 @@ CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining=File uploads rema
 # {0} - hashLookupsRemaining
 CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining=Hash lookups remaining: {0}
 # {0} - maxDailyFileLookups
-CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}/day
+# {1} - resetSuffix
+CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}{1}
 # {0} - maxDailyLookups
-CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}/day
+# {1} - resetSuffix
+CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}{1}
 CTMalwareScannerOptionsPanel_MalwareScansFetcher_apiErr_title=Server Error
 CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc=A general error occurred while fetching malware scans information.  Please try again later.
 CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_title=General Error
diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java
index 99d3ea2710..2a09c1ed55 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java
@@ -24,6 +24,7 @@
 import com.basistech.df.cybertriage.autopsy.ctapi.json.AuthTokenResponse;
 import com.basistech.df.cybertriage.autopsy.ctapi.json.DecryptedLicenseResponse;
 import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseInfo;
+import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseLimitType;
 import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseResponse;
 import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil;
 import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException;
@@ -130,7 +131,7 @@ public synchronized void loadSettings() {
         if (licenseInfo != null) {
             loadMalwareScansInfo(licenseInfo);
         }
-        
+
         MalwareIngestSettings ingestSettings = ctPersistence.loadMalwareIngestSettings();
         setIngestSettings(ingestSettings);
     }
@@ -138,12 +139,12 @@ public synchronized void loadSettings() {
     private synchronized LicenseResponse getLicenseInfo() {
         return this.licenseInfo == null ? null : this.licenseInfo.getLicenseResponse();
     }
-    
+
     private MalwareIngestSettings getIngestSettings() {
         return new MalwareIngestSettings()
                 .setUploadFiles(this.fileUploadCheckbox.isSelected());
     }
-    
+
     private void setIngestSettings(MalwareIngestSettings ingestSettings) {
         if (ingestSettings == null) {
             ingestSettings = new MalwareIngestSettings();
@@ -439,9 +440,11 @@ private void fileUploadCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
         "# {0} - idNumber",
         "CTMalwareScannerOptionsPanel_licenseInfo_id=ID: {0}",
         "# {0} - maxDailyLookups",
-        "CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}/day",
+        "# {1} - resetSuffix",
+        "CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}{1}",
         "# {0} - maxDailyFileLookups",
-        "CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}/day",
+        "# {1} - resetSuffix",
+        "CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}{1}",
         "# {0} - countersResetDate",
         "CTMalwareScannerOptionsPanel_malwareScans_countersReset=Counters reset: {0}",
         "# {0} - hashLookupsRemaining",
@@ -477,7 +480,7 @@ private synchronized void renderLicenseState() {
         this.malwareScansMessageLabel.setVisible(StringUtils.isNotBlank(this.authTokenMessage));
         this.malwareScansMessageLabel.setText(this.authTokenMessage);
 
-        if (authTokenResponse == null) {
+        if (authTokenResponse == null || this.licenseInfo == null) {
             this.maxHashLookupsLabel.setVisible(false);
             this.maxFileUploadsLabel.setVisible(false);
             this.countersResetLabel.setVisible(false);
@@ -485,15 +488,62 @@ private synchronized void renderLicenseState() {
             this.fileUploadsRemainingLabel.setVisible(false);
         } else {
             this.maxHashLookupsLabel.setVisible(true);
-            this.maxHashLookupsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups(this.authTokenResponse.getHashLookupLimit()));
+            this.maxHashLookupsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups(
+                    this.authTokenResponse.getHashLookupLimit(),
+                    getResetSuffix(this.licenseInfo.getDecryptedLicense().getLimitType())));
+
             this.maxFileUploadsLabel.setVisible(true);
-            this.maxFileUploadsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups(this.authTokenResponse.getFileUploadLimit()));
+            this.maxFileUploadsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups(
+                    this.authTokenResponse.getFileUploadLimit(),
+                    getResetSuffix(this.licenseInfo.getDecryptedLicense().getLimitType())));
+
             this.countersResetLabel.setVisible(true);
-            this.countersResetLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_countersReset(this.authTokenResponse.getResetDate() == null ? "" : MALWARE_SCANS_RESET_FORMAT.format(this.authTokenResponse.getResetDate())));
+            this.countersResetLabel.setText(getCountersResetText(this.licenseInfo.getDecryptedLicense().getLimitType(), this.authTokenResponse));
+
             this.hashLookupsRemainingLabel.setVisible(true);
-            this.hashLookupsRemainingLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining(remaining(this.authTokenResponse.getHashLookupLimit(), this.authTokenResponse.getHashLookupCount())));
+            this.hashLookupsRemainingLabel.setText(
+                    Bundle.CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining(
+                            remaining(this.authTokenResponse.getHashLookupLimit(), this.authTokenResponse.getHashLookupCount())));
+
             this.fileUploadsRemainingLabel.setVisible(true);
-            this.fileUploadsRemainingLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining(remaining(this.authTokenResponse.getFileUploadLimit(), this.authTokenResponse.getFileUploadCount())));
+            this.fileUploadsRemainingLabel.setText(
+                    Bundle.CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining(
+                            remaining(this.authTokenResponse.getFileUploadLimit(), this.authTokenResponse.getFileUploadCount())));
+        }
+    }
+
+    private static String getCountersResetText(LicenseLimitType limitType, AuthTokenResponse authTokenResponse) {
+        if (limitType == null || limitType == LicenseLimitType.NO_RESET) {
+            return "";
+        } else {
+            return Bundle.CTMalwareScannerOptionsPanel_malwareScans_countersReset(
+                    MALWARE_SCANS_RESET_FORMAT.format(authTokenResponse.getResetDate()));
+        }
+    }
+
+    @Messages({
+        "CTMalwareScannerOptionsPanel_getResetSuffix_hourly=/hour",
+        "CTMalwareScannerOptionsPanel_getResetSuffix_daily=/day",
+        "CTMalwareScannerOptionsPanel_getResetSuffix_weekly=/week",
+        "CTMalwareScannerOptionsPanel_getResetSuffix_monthly=/month"
+    })
+    private String getResetSuffix(LicenseLimitType limitType) {
+        if (limitType == null) {
+            return "";
+        }
+
+        switch (limitType) {
+            case HOURLY:
+                return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_hourly();
+            case DAILY:
+                return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_daily();
+            case WEEKLY:
+                return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_weekly();
+            case MONTHLY:
+                return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_monthly();
+            case NO_RESET:
+            default:
+                return "";
         }
     }
 
-- 
GitLab