Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTMalwareScannerOptionsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package com.basistech.df.cybertriage.autopsy.ctoptions.ctcloud;
20 
31 import java.awt.Desktop;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.io.IOException;
35 import java.net.URI;
36 import java.net.URISyntaxException;
37 import java.time.ZoneId;
38 import java.time.format.DateTimeFormatter;
39 import java.util.Optional;
40 import java.util.concurrent.CancellationException;
41 import java.util.concurrent.ExecutionException;
42 import java.util.logging.Level;
43 import javax.swing.JOptionPane;
44 import javax.swing.SwingUtilities;
45 import javax.swing.SwingWorker;
46 import org.apache.commons.lang3.StringUtils;
47 import org.netbeans.spi.options.OptionsPanelController;
48 import org.openide.util.NbBundle;
49 import org.openide.util.NbBundle.Messages;
50 import org.openide.util.lookup.ServiceProvider;
51 import org.openide.windows.WindowManager;
54 
59 @ServiceProvider(service = CTOptionsSubPanel.class)
61 
62  private static final Logger logger = Logger.getLogger(CTMalwareScannerOptionsPanel.class.getName());
63 
64  private static final DateTimeFormatter LICENSE_EXPIRES_FORMAT = DateTimeFormatter
65  .ofPattern("MMMM d, YYYY")
66  .withZone(ZoneId.of(UserPreferences.getInferredUserTimeZone()));
67 
68  private static final DateTimeFormatter MALWARE_SCANS_RESET_FORMAT = DateTimeFormatter
69  .ofPattern("MMM d, YYYY' at 'h:mma")
70  .withZone(ZoneId.of(UserPreferences.getInferredUserTimeZone()));
71 
72  private final CTApiDAO ctApiDAO = CTApiDAO.getInstance();
73  private final CTLicensePersistence ctPersistence = CTLicensePersistence.getInstance();
74 
75  private volatile LicenseInfo licenseInfo = null;
76  private volatile String licenseInfoMessage = null;
77  private volatile LicenseFetcher licenseFetcher = null;
78 
79  private static final String PURCHASE_URL = "https://cybertriage.com/autopsy-malware-module";
80 
81  private volatile AuthTokenResponse authTokenResponse = null;
82  private volatile String authTokenMessage = null;
83  private volatile AuthTokenFetcher authTokenFetcher = null;
84 
89  initComponents();
90 
91  this.addComponentListener(new ComponentAdapter() {
92  @Override
93  public void componentHidden(ComponentEvent e) {
94  synchronized (CTMalwareScannerOptionsPanel.this) {
98  }
99 
103  }
104  }
105  }
106 
107  @Override
108  public void componentShown(ComponentEvent e) {
109  synchronized (CTMalwareScannerOptionsPanel.this) {
110  if (CTMalwareScannerOptionsPanel.this.licenseInfo != null) {
111  loadMalwareScansInfo(CTMalwareScannerOptionsPanel.this.licenseInfo);
112  }
113  }
114  }
115  }
116  );
117  }
118 
119  @Override
120  public synchronized void saveSettings() {
121  ctPersistence.saveLicenseResponse(getLicenseInfo());
122  }
123 
124  @Override
125  public boolean valid() {
126  return true;
127  }
128 
129  @Override
130  public synchronized void loadSettings() {
131  Optional<LicenseInfo> licenseInfoOpt = ctPersistence.loadLicenseInfo();
132  LicenseInfo licenseInfo = licenseInfoOpt.orElse(null);
133  setLicenseDisplay(licenseInfo, null);
134  setMalwareScansDisplay(null, null);
135  if (licenseInfo != null) {
136  loadMalwareScansInfo(licenseInfo);
137  this.purchaseFromLabel.setVisible(false);
138  this.purchaseLink.setVisible(false);
139  } else {
140  this.purchaseFromLabel.setVisible(true);
141  this.purchaseLink.setVisible(true);
142  }
143  }
144 
145  private static String getHtmlLink(String url) {
146  return "<html><span style=\"color: blue; text-decoration: underline\">" + url + "</span></html>";
147  }
148 
149  private void gotoLink(String url) {
150  if (Desktop.isDesktopSupported()) {
151  try {
152  Desktop.getDesktop().browse(new URI(url));
153  } catch (IOException | URISyntaxException e) {
154  logger.log(Level.SEVERE, "Error opening link to: " + url, e);
155  }
156  } else {
157  logger.log(Level.WARNING, "Desktop API is not supported. Link cannot be opened.");
158  }
159  }
160 
161  private synchronized LicenseResponse getLicenseInfo() {
162  return this.licenseInfo == null ? null : this.licenseInfo.getLicenseResponse();
163  }
164 
165  private synchronized void setLicenseDisplay(LicenseInfo licenseInfo, String licenseMessage) {
166  this.licenseInfo = licenseInfo;
167  this.licenseInfoMessage = licenseMessage;
168  renderLicenseState();
169  }
170 
171  private synchronized void setMalwareScansDisplay(AuthTokenResponse authTokenResponse, String authTokenMessage) {
172  this.authTokenResponse = authTokenResponse;
173  this.authTokenMessage = authTokenMessage;
174  renderLicenseState();
175  }
176 
180  private synchronized boolean isLicenseAddRunning() {
181  return this.licenseFetcher != null && !this.licenseFetcher.isCancelled() && !this.licenseFetcher.isDone();
182  }
183 
187  private synchronized boolean isMalwareScansRunning() {
188  return this.authTokenFetcher != null && !this.authTokenFetcher.isCancelled() && !this.authTokenFetcher.isDone();
189  }
190 
191  @Messages({
192  "CTOPtionsPanel_loadLicenseInfo_loading=Loading..."
193  })
194  private synchronized void loadLicenseInfo(String licenseNumber) {
195  if (isLicenseAddRunning()) {
196  this.licenseFetcher.cancel(true);
197  }
198  setLicenseDisplay(null, Bundle.CTOPtionsPanel_loadLicenseInfo_loading());
199  setMalwareScansDisplay(null, null);
200  this.licenseFetcher = new LicenseFetcher(licenseNumber);
201  this.licenseFetcher.execute();
202  }
203 
204  @Messages({
205  "CTOPtionsPanel_loadMalwareScansInfo_loading=Loading..."
206  })
207  private synchronized void loadMalwareScansInfo(LicenseInfo licenseInfo) {
208  if (isMalwareScansRunning()) {
209  this.authTokenFetcher.cancel(true);
210  }
211 
212  if (licenseInfo == null || licenseInfo.getDecryptedLicense() == null) {
213  setMalwareScansDisplay(null, null);
214  return;
215  }
216 
217  setMalwareScansDisplay(null, Bundle.CTOPtionsPanel_loadMalwareScansInfo_loading());
218 
219  this.authTokenFetcher = new AuthTokenFetcher(licenseInfo.getDecryptedLicense());
220  this.authTokenFetcher.execute();
221  }
222 
228  @SuppressWarnings("unchecked")
229  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
230  private void initComponents() {
231  java.awt.GridBagConstraints gridBagConstraints;
232 
233  malwareScansPanel = new javax.swing.JPanel();
234  javax.swing.JLabel disclaimer = new javax.swing.JLabel();
235  javax.swing.JPanel licenseInfoPanel = new javax.swing.JPanel();
236  licenseInfoMessageLabel = new javax.swing.JLabel();
237  licenseInfoExpiresLabel = new javax.swing.JLabel();
238  licenseInfoIdLabel = new javax.swing.JLabel();
239  licenseInfoUserLabel = new javax.swing.JLabel();
240  licenseInfoAddButton = new javax.swing.JButton();
241  maxFileUploadsLabel = new javax.swing.JLabel();
242  maxHashLookupsLabel = new javax.swing.JLabel();
243  hashLookupsRemainingLabel = new javax.swing.JLabel();
244  malwareScansMessageLabel = new javax.swing.JLabel();
245  countersResetLabel = new javax.swing.JLabel();
246  fileUploadsRemainingLabel = new javax.swing.JLabel();
247  javax.swing.JPanel purchasePanel = new javax.swing.JPanel();
248  purchaseFromLabel = new javax.swing.JLabel();
249  purchaseLink = new javax.swing.JLabel();
250 
251  setLayout(new java.awt.GridBagLayout());
252 
253  malwareScansPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.malwareScansPanel.border.title"))); // NOI18N
254  malwareScansPanel.setLayout(new java.awt.GridBagLayout());
255 
256  org.openide.awt.Mnemonics.setLocalizedText(disclaimer, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.disclaimer.text")); // NOI18N
257  disclaimer.setVerticalAlignment(javax.swing.SwingConstants.TOP);
258  gridBagConstraints = new java.awt.GridBagConstraints();
259  gridBagConstraints.gridx = 0;
260  gridBagConstraints.gridy = 0;
261  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
262  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
263  gridBagConstraints.weightx = 1.0;
264  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
265  malwareScansPanel.add(disclaimer, gridBagConstraints);
266 
267  licenseInfoPanel.setLayout(new java.awt.GridBagLayout());
268 
269  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoMessageLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoMessageLabel.text")); // NOI18N
270  gridBagConstraints = new java.awt.GridBagConstraints();
271  gridBagConstraints.gridx = 0;
272  gridBagConstraints.gridy = 0;
273  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
275  gridBagConstraints.weightx = 1.0;
276  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
277  licenseInfoPanel.add(licenseInfoMessageLabel, gridBagConstraints);
278 
279  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoExpiresLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoExpiresLabel.text")); // NOI18N
280  gridBagConstraints = new java.awt.GridBagConstraints();
281  gridBagConstraints.gridx = 0;
282  gridBagConstraints.gridy = 1;
283  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
284  gridBagConstraints.weightx = 1.0;
285  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
286  licenseInfoPanel.add(licenseInfoExpiresLabel, gridBagConstraints);
287 
288  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoIdLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoIdLabel.text")); // NOI18N
289  gridBagConstraints = new java.awt.GridBagConstraints();
290  gridBagConstraints.gridx = 1;
291  gridBagConstraints.gridy = 1;
292  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
293  gridBagConstraints.weightx = 1.0;
294  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
295  licenseInfoPanel.add(licenseInfoIdLabel, gridBagConstraints);
296 
297  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoUserLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoUserLabel.text")); // NOI18N
298  gridBagConstraints = new java.awt.GridBagConstraints();
299  gridBagConstraints.gridx = 0;
300  gridBagConstraints.gridy = 2;
301  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
302  gridBagConstraints.weightx = 1.0;
303  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
304  licenseInfoPanel.add(licenseInfoUserLabel, gridBagConstraints);
305 
306  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoAddButton, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoAddButton.text")); // NOI18N
307  licenseInfoAddButton.addActionListener(new java.awt.event.ActionListener() {
308  public void actionPerformed(java.awt.event.ActionEvent evt) {
309  licenseInfoAddButtonActionPerformed(evt);
310  }
311  });
312  gridBagConstraints = new java.awt.GridBagConstraints();
313  gridBagConstraints.gridx = 2;
314  gridBagConstraints.gridy = 2;
315  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
316  gridBagConstraints.weightx = 1.0;
317  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
318  licenseInfoPanel.add(licenseInfoAddButton, gridBagConstraints);
319 
320  org.openide.awt.Mnemonics.setLocalizedText(maxFileUploadsLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.maxFileUploadsLabel.text")); // NOI18N
321  gridBagConstraints = new java.awt.GridBagConstraints();
322  gridBagConstraints.gridx = 0;
323  gridBagConstraints.gridy = 4;
324  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
325  gridBagConstraints.weightx = 1.0;
326  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
327  licenseInfoPanel.add(maxFileUploadsLabel, gridBagConstraints);
328 
329  org.openide.awt.Mnemonics.setLocalizedText(maxHashLookupsLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.maxHashLookupsLabel.text")); // NOI18N
330  gridBagConstraints = new java.awt.GridBagConstraints();
331  gridBagConstraints.gridx = 0;
332  gridBagConstraints.gridy = 3;
333  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
334  gridBagConstraints.weightx = 1.0;
335  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
336  licenseInfoPanel.add(maxHashLookupsLabel, gridBagConstraints);
337 
338  org.openide.awt.Mnemonics.setLocalizedText(hashLookupsRemainingLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.hashLookupsRemainingLabel.text")); // NOI18N
339  gridBagConstraints = new java.awt.GridBagConstraints();
340  gridBagConstraints.gridx = 1;
341  gridBagConstraints.gridy = 3;
342  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
343  gridBagConstraints.weightx = 1.0;
344  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
345  licenseInfoPanel.add(hashLookupsRemainingLabel, gridBagConstraints);
346 
347  org.openide.awt.Mnemonics.setLocalizedText(malwareScansMessageLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.malwareScansMessageLabel.text")); // NOI18N
348  gridBagConstraints = new java.awt.GridBagConstraints();
349  gridBagConstraints.gridx = 0;
350  gridBagConstraints.gridy = 3;
351  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
352  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
353  gridBagConstraints.weightx = 1.0;
354  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
355  licenseInfoPanel.add(malwareScansMessageLabel, gridBagConstraints);
356 
357  org.openide.awt.Mnemonics.setLocalizedText(countersResetLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.countersResetLabel.text")); // NOI18N
358  gridBagConstraints = new java.awt.GridBagConstraints();
359  gridBagConstraints.gridx = 0;
360  gridBagConstraints.gridy = 5;
361  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
362  gridBagConstraints.weightx = 1.0;
363  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
364  licenseInfoPanel.add(countersResetLabel, gridBagConstraints);
365 
366  org.openide.awt.Mnemonics.setLocalizedText(fileUploadsRemainingLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.fileUploadsRemainingLabel.text")); // NOI18N
367  gridBagConstraints = new java.awt.GridBagConstraints();
368  gridBagConstraints.gridx = 1;
369  gridBagConstraints.gridy = 4;
370  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
371  gridBagConstraints.weightx = 1.0;
372  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
373  licenseInfoPanel.add(fileUploadsRemainingLabel, gridBagConstraints);
374 
375  gridBagConstraints = new java.awt.GridBagConstraints();
376  gridBagConstraints.gridx = 0;
377  gridBagConstraints.gridy = 1;
378  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
379  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
380  gridBagConstraints.weightx = 1.0;
381  malwareScansPanel.add(licenseInfoPanel, gridBagConstraints);
382 
383  purchasePanel.setLayout(new java.awt.GridBagLayout());
384 
385  org.openide.awt.Mnemonics.setLocalizedText(purchaseFromLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.purchaseFromLabel.text")); // NOI18N
386  gridBagConstraints = new java.awt.GridBagConstraints();
387  gridBagConstraints.gridx = 0;
388  gridBagConstraints.gridy = 0;
389  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
390  purchasePanel.add(purchaseFromLabel, gridBagConstraints);
391 
392  org.openide.awt.Mnemonics.setLocalizedText(purchaseLink, getHtmlLink(PURCHASE_URL));
393  purchaseLink.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
394  purchaseLink.addMouseListener(new java.awt.event.MouseAdapter() {
395  public void mouseClicked(java.awt.event.MouseEvent evt) {
396  purchaseLinkMouseClicked(evt);
397  }
398  });
399  gridBagConstraints = new java.awt.GridBagConstraints();
400  gridBagConstraints.gridx = 1;
401  gridBagConstraints.gridy = 0;
402  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
403  gridBagConstraints.weightx = 1.0;
404  gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
405  purchasePanel.add(purchaseLink, gridBagConstraints);
406 
407  gridBagConstraints = new java.awt.GridBagConstraints();
408  gridBagConstraints.gridx = 0;
409  gridBagConstraints.gridy = 3;
410  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
411  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
412  gridBagConstraints.weightx = 1.0;
413  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
414  malwareScansPanel.add(purchasePanel, gridBagConstraints);
415 
416  gridBagConstraints = new java.awt.GridBagConstraints();
417  gridBagConstraints.gridx = 0;
418  gridBagConstraints.gridy = 2;
419  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
420  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
421  gridBagConstraints.weightx = 1.0;
422  add(malwareScansPanel, gridBagConstraints);
423  }// </editor-fold>//GEN-END:initComponents
424 
425  @Messages({
426  "CTMalwareScannerOptionsPanel_licenseAddDialog_title=Add a License...",
427  "CTMalwareScannerOptionsPanel_licenseAddDialog_desc=License Number:",
428  "CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_title=License Number Already Entered",
429  "CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc=The license number has already been entered",
430  "CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_title=Invalid License Number",
431  "CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_desc=Please verify that license number is of format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'"})
432  private void licenseInfoAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_licenseInfoAddButtonActionPerformed
433  CTLicenseDialog licenseDialog = new CTLicenseDialog(WindowManager.getDefault().getMainWindow(), true);
434  licenseDialog.setLocationRelativeTo(this);
435  licenseDialog.setVisible(true);
436  String licenseNumber = licenseDialog.getValue();
437  if (licenseNumber != null) {
438  synchronized (this) {
439  if (this.licenseInfo == null || !licenseNumber.trim().equalsIgnoreCase(this.licenseInfo.getDecryptedLicense().getBoostLicenseId())) {
440  loadLicenseInfo(licenseNumber);
441  return;
442  }
443  }
444 
445  JOptionPane.showMessageDialog(
446  this,
447  Bundle.CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc(),
448  Bundle.CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_title(),
449  JOptionPane.INFORMATION_MESSAGE);
450 
451  }
452  }//GEN-LAST:event_licenseInfoAddButtonActionPerformed
453 
454  private void purchaseLinkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_purchaseLinkMouseClicked
455  gotoLink(PURCHASE_URL);
456  }//GEN-LAST:event_purchaseLinkMouseClicked
457 
458  @NbBundle.Messages({
459  "# {0} - userName",
460  "# {1} - email",
461  "CTMalwareScannerOptionsPanel_licenseInfo_userInfo=<html>User: {0}<br/>Email: {1}</html>",
462  "# {0} - expiresDate",
463  "CTMalwareScannerOptionsPanel_licenseInfo_expires=Expires: {0}",
464  "# {0} - idNumber",
465  "CTMalwareScannerOptionsPanel_licenseInfo_id=ID: {0}",
466  "# {0} - maxDailyLookups",
467  "# {1} - resetSuffix",
468  "CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}{1}",
469  "# {0} - maxDailyFileLookups",
470  "# {1} - resetSuffix",
471  "CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}{1}",
472  "# {0} - countersResetDate",
473  "CTMalwareScannerOptionsPanel_malwareScans_countersReset=Counters reset: {0}",
474  "# {0} - hashLookupsRemaining",
475  "CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining=Hash lookups remaining: {0}",
476  "# {0} - fileUploadsRemaining",
477  "CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining=File uploads remaining: {0}"})
478  private synchronized void renderLicenseState() {
479  this.licenseInfoAddButton.setEnabled(!isLicenseAddRunning());
480 
481  this.licenseInfoMessageLabel.setVisible(StringUtils.isNotBlank(this.licenseInfoMessage));
482  this.licenseInfoMessageLabel.setText(this.licenseInfoMessage);
483 
484  if (licenseInfo == null) {
485  this.licenseInfoExpiresLabel.setVisible(false);
486  this.licenseInfoIdLabel.setVisible(false);
487  this.licenseInfoUserLabel.setVisible(false);
488  this.purchaseFromLabel.setVisible(true);
489  this.purchaseLink.setVisible(true);
490  } else {
491  this.purchaseFromLabel.setVisible(false);
492  this.purchaseLink.setVisible(false);
493 
494  this.licenseInfoExpiresLabel.setVisible(true);
495  this.licenseInfoExpiresLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_expires(
496  this.licenseInfo.getDecryptedLicense().getExpirationDate() == null
497  ? ""
498  : LICENSE_EXPIRES_FORMAT.format(this.licenseInfo.getDecryptedLicense().getExpirationDate())));
499  this.licenseInfoIdLabel.setVisible(true);
500  this.licenseInfoIdLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_id(StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getBoostLicenseId())));
501  this.licenseInfoUserLabel.setVisible(true);
502  this.licenseInfoUserLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_userInfo(
503  StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getCustomerName()),
504  StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getCustomerEmail())));
505  }
506 
507  this.malwareScansMessageLabel.setVisible(StringUtils.isNotBlank(this.authTokenMessage));
508  this.malwareScansMessageLabel.setText(this.authTokenMessage);
509 
510  if (authTokenResponse == null || this.licenseInfo == null) {
511  this.maxHashLookupsLabel.setVisible(false);
512  this.maxFileUploadsLabel.setVisible(false);
513  this.countersResetLabel.setVisible(false);
514  this.hashLookupsRemainingLabel.setVisible(false);
515  this.fileUploadsRemainingLabel.setVisible(false);
516  } else {
517  this.maxHashLookupsLabel.setVisible(true);
518  this.maxHashLookupsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups(
519  this.authTokenResponse.getHashLookupLimit(),
520  getResetSuffix(this.licenseInfo.getDecryptedLicense().getLimitType())));
521 
522  this.maxFileUploadsLabel.setVisible(true);
523  this.maxFileUploadsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups(
524  this.authTokenResponse.getFileUploadLimit(),
525  getResetSuffix(this.licenseInfo.getDecryptedLicense().getLimitType())));
526 
527  this.countersResetLabel.setVisible(true);
528  this.countersResetLabel.setText(getCountersResetText(this.licenseInfo.getDecryptedLicense().getLimitType(), this.authTokenResponse));
529 
530  this.hashLookupsRemainingLabel.setVisible(true);
531  this.hashLookupsRemainingLabel.setText(
532  Bundle.CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining(
533  remaining(this.authTokenResponse.getHashLookupLimit(), this.authTokenResponse.getHashLookupCount())));
534 
535  this.fileUploadsRemainingLabel.setVisible(true);
536  this.fileUploadsRemainingLabel.setText(
537  Bundle.CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining(
538  remaining(this.authTokenResponse.getFileUploadLimit(), this.authTokenResponse.getFileUploadCount())));
539  }
540  }
541 
542  private static String getCountersResetText(LicenseLimitType limitType, AuthTokenResponse authTokenResponse) {
543  if (limitType == null || limitType == LicenseLimitType.NO_RESET) {
544  return "";
545  } else {
546  return Bundle.CTMalwareScannerOptionsPanel_malwareScans_countersReset(
547  MALWARE_SCANS_RESET_FORMAT.format(authTokenResponse.getResetDate()));
548  }
549  }
550 
551  @Messages({
552  "CTMalwareScannerOptionsPanel_getResetSuffix_hourly=/hour",
553  "CTMalwareScannerOptionsPanel_getResetSuffix_daily=/day",
554  "CTMalwareScannerOptionsPanel_getResetSuffix_weekly=/week",
555  "CTMalwareScannerOptionsPanel_getResetSuffix_monthly=/month"
556  })
557  private String getResetSuffix(LicenseLimitType limitType) {
558  if (limitType == null) {
559  return "";
560  }
561 
562  switch (limitType) {
563  case HOURLY:
564  return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_hourly();
565  case DAILY:
566  return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_daily();
567  case WEEKLY:
568  return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_weekly();
569  case MONTHLY:
570  return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_monthly();
571  case NO_RESET:
572  default:
573  return "";
574  }
575  }
576 
577  private long remaining(Long total, Long used) {
578  total = total == null ? 0 : total;
579  used = used == null ? 0 : used;
580  return total - used;
581  }
582 
583  private void acceptEula(LicenseResponse licenseResponse) {
584  try {
585  final EULADialog eulaDialog = new EULADialog(WindowManager.getDefault().getMainWindow(), true);
586  eulaDialog.setLocationRelativeTo(this);
587  eulaDialog.setSize(eulaDialog.getPreferredSize());
588  eulaDialog.setVisible(true);
589 
590  if (eulaDialog.isAcceptPressed()) {
591  // only indicate a change to save if we have accepted EULA for a license
592  this.licenseInfo = LicenseDecryptorUtil.getInstance().createLicenseInfo(licenseResponse);
593  this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
594  }
595  } catch (IOException | InvalidLicenseException ex) {
596  logger.log(Level.WARNING, "An error occurred while fetching data", ex);
597  JOptionPane.showMessageDialog(
599  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc(),
600  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title(),
601  JOptionPane.ERROR_MESSAGE);
602  } finally {
603  setLicenseDisplay(this.licenseInfo, null);
604  loadMalwareScansInfo(this.licenseInfo);
605  }
606  }
607 
608  @NbBundle.Messages({
609  "CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error",
610  "CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error",
611  "# {0} - licenseCode",
612  "CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc=Error activating boost license {0}",
613  "CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.",})
614  private class LicenseFetcher extends SwingWorker<LicenseResponse, Void> {
615 
616  private final String licenseText;
617 
618  public LicenseFetcher(String licenseText) {
619  this.licenseText = licenseText;
620  }
621 
622  @Override
623  protected LicenseResponse doInBackground() throws Exception {
624  if (this.isCancelled()) {
625  return null;
626  }
627  return ctApiDAO.getLicenseInfo(licenseText);
628  }
629 
630  @Override
631  protected void done() {
632  try {
633  LicenseResponse licenseResponse = get();
634  // if no result, show unauthorized
635  if (licenseResponse == null) {
636  logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch returned no result.");
637  JOptionPane.showMessageDialog(
639  CTCloudException.ErrorCode.UN_AUTHORIZED.getDescription(),
640  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title(),
641  JOptionPane.ERROR_MESSAGE);
642  setLicenseDisplay(licenseInfo, null);
643  loadMalwareScansInfo(licenseInfo);
644  return;
645  }
646 
647  // if not successful response
648  if (!Boolean.TRUE.equals(licenseResponse.isSuccess())) {
649  logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch was not successful");
650  // use default message unless error message specified
651  String message = Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc(licenseText);
652  if (!StringUtils.isBlank(licenseResponse.getErrorMsg())) {
653  message = licenseResponse.getErrorMsg();
654  }
655  JOptionPane.showMessageDialog(
657  message,
658  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title(),
659  JOptionPane.ERROR_MESSAGE);
660  setLicenseDisplay(licenseInfo, null);
661  loadMalwareScansInfo(licenseInfo);
662  return;
663  }
664 
665  // otherwise, load
666  SwingUtilities.invokeLater(() -> acceptEula(licenseResponse));
667 
668  } catch (InterruptedException | CancellationException ex) {
669  // ignore cancellation; just load current license
670  setLicenseDisplay(licenseInfo, null);
671  loadMalwareScansInfo(licenseInfo);
672  } catch (ExecutionException ex) {
673  if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
674  logger.log(Level.WARNING, "An API error occurred while fetching license information", cloudEx);
675  JOptionPane.showMessageDialog(
677  cloudEx.getErrorCode().getDescription(),
678  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title(),
679  JOptionPane.ERROR_MESSAGE);
680  } else {
681  logger.log(Level.WARNING, "An error occurred while fetching data", ex);
682  JOptionPane.showMessageDialog(
684  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc(),
685  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title(),
686  JOptionPane.ERROR_MESSAGE);
687  }
688  setLicenseDisplay(licenseInfo, null);
689  loadMalwareScansInfo(licenseInfo);
690  } finally {
691  synchronized (CTMalwareScannerOptionsPanel.this) {
693  }
694  }
695  }
696  }
697 
698  @NbBundle.Messages({
699  "CTMalwareScannerOptionsPanel_MalwareScansFetcher_apiErr_title=Server Error",
700  "CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_title=General Error",
701  "CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc=A general error occurred while fetching malware scans information. Please try again later.",})
702  private class AuthTokenFetcher extends SwingWorker<AuthTokenResponse, Void> {
703 
705 
706  public AuthTokenFetcher(DecryptedLicenseResponse decryptedLicense) {
707  this.decryptedLicense = decryptedLicense;
708  }
709 
710  @Override
711  protected AuthTokenResponse doInBackground() throws Exception {
712  if (this.isCancelled()) {
713  return null;
714  }
715 
716  return ctApiDAO.getAuthToken(decryptedLicense);
717  }
718 
719  @Override
720  protected void done() {
721  AuthTokenResponse authTokenResponse = null;
722  try {
723  authTokenResponse = get();
724  } catch (InterruptedException | CancellationException ex) {
725  // ignore cancellation
726  } catch (ExecutionException ex) {
727  if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
728  logger.log(Level.WARNING, "An API error occurred while fetching malware scans information for license", cloudEx);
729  JOptionPane.showMessageDialog(
731  cloudEx.getErrorDetails(),
732  Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_apiErr_title(),
733  JOptionPane.ERROR_MESSAGE);
734  } else {
735  logger.log(Level.WARNING, "An error occurred while fetching data", ex);
736  JOptionPane.showMessageDialog(
738  Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc(),
739  Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_title(),
740  JOptionPane.ERROR_MESSAGE);
741  }
742  } finally {
743  synchronized (CTMalwareScannerOptionsPanel.this) {
745  if (!this.isCancelled()) {
746  setMalwareScansDisplay(authTokenResponse, null);
747  }
748  }
749  }
750  }
751  }
752 
753 
754  // Variables declaration - do not modify//GEN-BEGIN:variables
755  private javax.swing.JLabel countersResetLabel;
756  private javax.swing.JLabel fileUploadsRemainingLabel;
757  private javax.swing.JLabel hashLookupsRemainingLabel;
758  private javax.swing.JButton licenseInfoAddButton;
759  private javax.swing.JLabel licenseInfoExpiresLabel;
760  private javax.swing.JLabel licenseInfoIdLabel;
761  private javax.swing.JLabel licenseInfoMessageLabel;
762  private javax.swing.JLabel licenseInfoUserLabel;
763  private javax.swing.JLabel malwareScansMessageLabel;
764  private javax.swing.JPanel malwareScansPanel;
765  private javax.swing.JLabel maxFileUploadsLabel;
766  private javax.swing.JLabel maxHashLookupsLabel;
767  private javax.swing.JLabel purchaseFromLabel;
768  private javax.swing.JLabel purchaseLink;
769  // End of variables declaration//GEN-END:variables
770 }
synchronized void setMalwareScansDisplay(AuthTokenResponse authTokenResponse, String authTokenMessage)
synchronized boolean saveLicenseResponse(LicenseResponse licenseResponse)
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted)
Definition: CTApiDAO.java:81
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
synchronized void setLicenseDisplay(LicenseInfo licenseInfo, String licenseMessage)
LicenseResponse getLicenseInfo(String licenseString)
Definition: CTApiDAO.java:70
static String getCountersResetText(LicenseLimitType limitType, AuthTokenResponse authTokenResponse)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.