Autopsy  4.20.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 
30 import java.awt.event.ComponentAdapter;
31 import java.awt.event.ComponentEvent;
32 import java.io.IOException;
33 import java.time.ZoneId;
34 import java.time.format.DateTimeFormatter;
35 import java.util.Optional;
36 import java.util.concurrent.ExecutionException;
37 import java.util.logging.Level;
38 import java.util.logging.Logger;
39 import javax.swing.JOptionPane;
40 import javax.swing.SwingUtilities;
41 import javax.swing.SwingWorker;
42 import org.apache.commons.lang3.StringUtils;
43 import org.netbeans.spi.options.OptionsPanelController;
44 import org.openide.util.NbBundle;
45 import org.openide.util.NbBundle.Messages;
46 import org.openide.util.lookup.ServiceProvider;
47 import org.openide.windows.WindowManager;
49 
54 @ServiceProvider(service = CTOptionsSubPanel.class)
56 
57  private static final Logger logger = Logger.getLogger(CTMalwareScannerOptionsPanel.class.getName());
58 
59  private static final DateTimeFormatter LICENSE_EXPIRES_FORMAT = DateTimeFormatter
60  .ofPattern("MMMM d, YYYY")
61  .withZone(ZoneId.of(UserPreferences.getInferredUserTimeZone()));
62 
63  private static final DateTimeFormatter MALWARE_SCANS_RESET_FORMAT = DateTimeFormatter
64  .ofPattern("MMM d, YYYY' at 'h:mma")
65  .withZone(ZoneId.of(UserPreferences.getInferredUserTimeZone()));
66 
67  private final CTApiDAO ctApiDAO = CTApiDAO.getInstance();
68  private final CTLicensePersistence ctPersistence = CTLicensePersistence.getInstance();
69 
70  private volatile LicenseInfo licenseInfo = null;
71  private volatile String licenseInfoMessage = null;
72  private volatile LicenseFetcher licenseFetcher = null;
73 
74  private volatile AuthTokenResponse authTokenResponse = null;
75  private volatile String authTokenMessage = null;
76  private volatile AuthTokenFetcher authTokenFetcher = null;
77 
82  initComponents();
83 
84  this.addComponentListener(new ComponentAdapter() {
85  @Override
86  public void componentHidden(ComponentEvent e) {
87  synchronized (CTMalwareScannerOptionsPanel.this) {
91  }
92 
96  }
97  }
98  }
99 
100  @Override
101  public void componentShown(ComponentEvent e) {
102  synchronized (CTMalwareScannerOptionsPanel.this) {
103  if (CTMalwareScannerOptionsPanel.this.licenseInfo != null) {
104  loadMalwareScansInfo(CTMalwareScannerOptionsPanel.this.licenseInfo);
105  }
106  }
107  }
108  }
109  );
110  }
111 
112  @Override
113  public synchronized void saveSettings() {
114  ctPersistence.saveLicenseResponse(getLicenseInfo());
115  }
116 
117  @Override
118  public boolean valid() {
119  return true;
120  }
121 
122  @Override
123  public synchronized void loadSettings() {
124  Optional<LicenseInfo> licenseInfoOpt = ctPersistence.loadLicenseInfo();
125  LicenseInfo licenseInfo = licenseInfoOpt.orElse(null);
126  setLicenseDisplay(licenseInfo, null);
127  setMalwareScansDisplay(null, null);
128  if (licenseInfo != null) {
129  loadMalwareScansInfo(licenseInfo);
130  }
131  }
132 
133  private synchronized LicenseResponse getLicenseInfo() {
134  return this.licenseInfo == null ? null : this.licenseInfo.getLicenseResponse();
135  }
136 
137  private synchronized void setLicenseDisplay(LicenseInfo licenseInfo, String licenseMessage) {
138  this.licenseInfo = licenseInfo;
139  this.licenseInfoMessage = licenseMessage;
140  renderLicenseState();
141  }
142 
143  private synchronized void setMalwareScansDisplay(AuthTokenResponse authTokenResponse, String authTokenMessage) {
144  this.authTokenResponse = authTokenResponse;
145  this.authTokenMessage = authTokenMessage;
146  renderLicenseState();
147  }
148 
152  private synchronized boolean isLicenseAddRunning() {
153  return this.licenseFetcher != null && !this.licenseFetcher.isCancelled() && !this.licenseFetcher.isDone();
154  }
155 
159  private synchronized boolean isMalwareScansRunning() {
160  return this.authTokenFetcher != null && !this.authTokenFetcher.isCancelled() && !this.authTokenFetcher.isDone();
161  }
162 
163  @Messages({
164  "CTOPtionsPanel_loadLicenseInfo_loading=Loading..."
165  })
166  private synchronized void loadLicenseInfo(String licenseNumber) {
167  if (isLicenseAddRunning()) {
168  this.licenseFetcher.cancel(true);
169  }
170  setLicenseDisplay(null, Bundle.CTOPtionsPanel_loadLicenseInfo_loading());
171  setMalwareScansDisplay(null, null);
172  this.licenseFetcher = new LicenseFetcher(licenseNumber);
173  this.licenseFetcher.execute();
174  }
175 
176  @Messages({
177  "CTOPtionsPanel_loadMalwareScansInfo_loading=Loading..."
178  })
179  private synchronized void loadMalwareScansInfo(LicenseInfo licenseInfo) {
180  if (isMalwareScansRunning()) {
181  this.authTokenFetcher.cancel(true);
182  }
183 
184  if (licenseInfo == null || licenseInfo.getDecryptedLicense() == null) {
185  setMalwareScansDisplay(null, null);
186  return;
187  }
188 
189  setMalwareScansDisplay(null, Bundle.CTOPtionsPanel_loadMalwareScansInfo_loading());
190 
191  this.authTokenFetcher = new AuthTokenFetcher(licenseInfo.getDecryptedLicense());
192  this.authTokenFetcher.execute();
193  }
194 
200  @SuppressWarnings("unchecked")
201  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
202  private void initComponents() {
203  java.awt.GridBagConstraints gridBagConstraints;
204 
205  javax.swing.JPanel licenseInfoPanel = new javax.swing.JPanel();
206  licenseInfoMessageLabel = new javax.swing.JLabel();
207  licenseInfoUserLabel = new javax.swing.JLabel();
208  licenseInfoExpiresLabel = new javax.swing.JLabel();
209  licenseInfoIdLabel = new javax.swing.JLabel();
210  licenseInfoAddButton = new javax.swing.JButton();
211  malwareScansPanel = new javax.swing.JPanel();
212  malwareScansMessageLabel = new javax.swing.JLabel();
213  maxHashLookupsLabel = new javax.swing.JLabel();
214  maxFileUploadsLabel = new javax.swing.JLabel();
215  countersResetLabel = new javax.swing.JLabel();
216  hashLookupsRemainingLabel = new javax.swing.JLabel();
217  fileUploadsRemainingLabel = new javax.swing.JLabel();
218 
219  setLayout(new java.awt.GridBagLayout());
220 
221  licenseInfoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoPanel.border.title"))); // NOI18N
222  licenseInfoPanel.setLayout(new java.awt.GridBagLayout());
223 
224  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoMessageLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoMessageLabel.text")); // NOI18N
225  gridBagConstraints = new java.awt.GridBagConstraints();
226  gridBagConstraints.gridx = 0;
227  gridBagConstraints.gridy = 0;
228  gridBagConstraints.gridwidth = 2;
229  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
230  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
231  gridBagConstraints.weightx = 1.0;
232  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
233  licenseInfoPanel.add(licenseInfoMessageLabel, gridBagConstraints);
234 
235  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoUserLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoUserLabel.text")); // NOI18N
236  gridBagConstraints = new java.awt.GridBagConstraints();
237  gridBagConstraints.gridx = 0;
238  gridBagConstraints.gridy = 1;
239  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
240  gridBagConstraints.weightx = 1.0;
241  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
242  licenseInfoPanel.add(licenseInfoUserLabel, gridBagConstraints);
243 
244  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoExpiresLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoExpiresLabel.text")); // NOI18N
245  gridBagConstraints = new java.awt.GridBagConstraints();
246  gridBagConstraints.gridx = 1;
247  gridBagConstraints.gridy = 1;
248  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
249  gridBagConstraints.weightx = 1.0;
250  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
251  licenseInfoPanel.add(licenseInfoExpiresLabel, gridBagConstraints);
252 
253  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoIdLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoIdLabel.text")); // NOI18N
254  gridBagConstraints = new java.awt.GridBagConstraints();
255  gridBagConstraints.gridx = 0;
256  gridBagConstraints.gridy = 2;
257  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
258  gridBagConstraints.weightx = 1.0;
259  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
260  licenseInfoPanel.add(licenseInfoIdLabel, gridBagConstraints);
261 
262  org.openide.awt.Mnemonics.setLocalizedText(licenseInfoAddButton, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoAddButton.text")); // NOI18N
263  licenseInfoAddButton.addActionListener(new java.awt.event.ActionListener() {
264  public void actionPerformed(java.awt.event.ActionEvent evt) {
265  licenseInfoAddButtonActionPerformed(evt);
266  }
267  });
268  gridBagConstraints = new java.awt.GridBagConstraints();
269  gridBagConstraints.gridx = 1;
270  gridBagConstraints.gridy = 2;
271  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
272  gridBagConstraints.weightx = 1.0;
273  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
274  licenseInfoPanel.add(licenseInfoAddButton, gridBagConstraints);
275 
276  gridBagConstraints = new java.awt.GridBagConstraints();
277  gridBagConstraints.gridx = 0;
278  gridBagConstraints.gridy = 1;
279  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
280  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
281  gridBagConstraints.weightx = 1.0;
282  add(licenseInfoPanel, gridBagConstraints);
283 
284  malwareScansPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.malwareScansPanel.border.title"))); // NOI18N
285  malwareScansPanel.setLayout(new java.awt.GridBagLayout());
286 
287  org.openide.awt.Mnemonics.setLocalizedText(malwareScansMessageLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.malwareScansMessageLabel.text")); // NOI18N
288  gridBagConstraints = new java.awt.GridBagConstraints();
289  gridBagConstraints.gridx = 0;
290  gridBagConstraints.gridy = 0;
291  gridBagConstraints.gridwidth = 2;
292  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
293  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
294  gridBagConstraints.weightx = 1.0;
295  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
296  malwareScansPanel.add(malwareScansMessageLabel, gridBagConstraints);
297 
298  org.openide.awt.Mnemonics.setLocalizedText(maxHashLookupsLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.maxHashLookupsLabel.text")); // NOI18N
299  gridBagConstraints = new java.awt.GridBagConstraints();
300  gridBagConstraints.gridx = 0;
301  gridBagConstraints.gridy = 1;
302  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
303  gridBagConstraints.weightx = 1.0;
304  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
305  malwareScansPanel.add(maxHashLookupsLabel, gridBagConstraints);
306 
307  org.openide.awt.Mnemonics.setLocalizedText(maxFileUploadsLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.maxFileUploadsLabel.text")); // NOI18N
308  gridBagConstraints = new java.awt.GridBagConstraints();
309  gridBagConstraints.gridx = 0;
310  gridBagConstraints.gridy = 2;
311  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
312  gridBagConstraints.weightx = 1.0;
313  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
314  malwareScansPanel.add(maxFileUploadsLabel, gridBagConstraints);
315 
316  org.openide.awt.Mnemonics.setLocalizedText(countersResetLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.countersResetLabel.text")); // NOI18N
317  gridBagConstraints = new java.awt.GridBagConstraints();
318  gridBagConstraints.gridx = 0;
319  gridBagConstraints.gridy = 3;
320  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
321  gridBagConstraints.weightx = 1.0;
322  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
323  malwareScansPanel.add(countersResetLabel, gridBagConstraints);
324 
325  org.openide.awt.Mnemonics.setLocalizedText(hashLookupsRemainingLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.hashLookupsRemainingLabel.text")); // NOI18N
326  gridBagConstraints = new java.awt.GridBagConstraints();
327  gridBagConstraints.gridx = 1;
328  gridBagConstraints.gridy = 1;
329  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
330  gridBagConstraints.weightx = 1.0;
331  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
332  malwareScansPanel.add(hashLookupsRemainingLabel, gridBagConstraints);
333 
334  org.openide.awt.Mnemonics.setLocalizedText(fileUploadsRemainingLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.fileUploadsRemainingLabel.text")); // NOI18N
335  gridBagConstraints = new java.awt.GridBagConstraints();
336  gridBagConstraints.gridx = 1;
337  gridBagConstraints.gridy = 2;
338  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
339  gridBagConstraints.weightx = 1.0;
340  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
341  malwareScansPanel.add(fileUploadsRemainingLabel, gridBagConstraints);
342 
343  gridBagConstraints = new java.awt.GridBagConstraints();
344  gridBagConstraints.gridx = 0;
345  gridBagConstraints.gridy = 2;
346  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
347  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
348  gridBagConstraints.weightx = 1.0;
349  add(malwareScansPanel, gridBagConstraints);
350  }// </editor-fold>//GEN-END:initComponents
351 
352  @Messages({
353  "CTMalwareScannerOptionsPanel_licenseAddDialog_title=Add a License...",
354  "CTMalwareScannerOptionsPanel_licenseAddDialog_desc=License Number:",
355  "CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_title=License Number Already Entered",
356  "CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc=The license number has already been entered",
357  "CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_title=Invalid License Number",
358  "CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_desc=Please verify that license number is of format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'"})
359  private void licenseInfoAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_licenseInfoAddButtonActionPerformed
360  CTLicenseDialog licenseDialog = new CTLicenseDialog(WindowManager.getDefault().getMainWindow(), true);
361  licenseDialog.setLocationRelativeTo(this);
362  licenseDialog.setVisible(true);
363  String licenseNumber = licenseDialog.getValue();
364  if (licenseNumber != null) {
365  synchronized (this) {
366  if (this.licenseInfo == null || !licenseNumber.trim().equalsIgnoreCase(this.licenseInfo.getDecryptedLicense().getBoostLicenseId())) {
367  loadLicenseInfo(licenseNumber);
368  return;
369  }
370  }
371 
372  JOptionPane.showMessageDialog(
373  this,
374  Bundle.CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc(),
375  Bundle.CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_title(),
376  JOptionPane.INFORMATION_MESSAGE);
377 
378  }
379  }//GEN-LAST:event_licenseInfoAddButtonActionPerformed
380 
381  @NbBundle.Messages({
382  "# {0} - userName",
383  "# {1} - email",
384  "CTMalwareScannerOptionsPanel_licenseInfo_userInfo=<html>User: {0}<br/>Email: {1}</html>",
385  "# {0} - expiresDate",
386  "CTMalwareScannerOptionsPanel_licenseInfo_expires=Expires: {0}",
387  "# {0} - idNumber",
388  "CTMalwareScannerOptionsPanel_licenseInfo_id=ID: {0}",
389  "# {0} - maxDailyLookups",
390  "CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}/day",
391  "# {0} - maxDailyFileLookups",
392  "CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}/day",
393  "# {0} - countersResetDate",
394  "CTMalwareScannerOptionsPanel_malwareScans_countersReset=Counters reset: {0}",
395  "# {0} - hashLookupsRemaining",
396  "CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining=Hash lookups remaining: {0}",
397  "# {0} - fileUploadsRemaining",
398  "CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining=File uploads remaining: {0}"})
399  private synchronized void renderLicenseState() {
400  this.licenseInfoAddButton.setEnabled(!isLicenseAddRunning());
401 
402  this.licenseInfoMessageLabel.setVisible(StringUtils.isNotBlank(this.licenseInfoMessage));
403  this.licenseInfoMessageLabel.setText(this.licenseInfoMessage);
404 
405  if (licenseInfo == null) {
406  this.licenseInfoExpiresLabel.setVisible(false);
407  this.licenseInfoIdLabel.setVisible(false);
408  this.licenseInfoUserLabel.setVisible(false);
409  } else {
410  this.licenseInfoExpiresLabel.setVisible(true);
411  this.licenseInfoExpiresLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_expires(
412  this.licenseInfo.getDecryptedLicense().getExpirationDate() == null
413  ? ""
414  : LICENSE_EXPIRES_FORMAT.format(this.licenseInfo.getDecryptedLicense().getExpirationDate())));
415  this.licenseInfoIdLabel.setVisible(true);
416  this.licenseInfoIdLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_id(StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getBoostLicenseId())));
417  this.licenseInfoUserLabel.setVisible(true);
418  this.licenseInfoUserLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_userInfo(
419  StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getCustomerName()),
420  StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getCustomerEmail())));
421  }
422 
423  this.malwareScansPanel.setVisible(StringUtils.isNotBlank(this.authTokenMessage) || authTokenResponse != null);
424 
425  this.malwareScansMessageLabel.setVisible(StringUtils.isNotBlank(this.authTokenMessage));
426  this.malwareScansMessageLabel.setText(this.authTokenMessage);
427 
428  if (authTokenResponse == null) {
429  this.maxHashLookupsLabel.setVisible(false);
430  this.maxFileUploadsLabel.setVisible(false);
431  this.countersResetLabel.setVisible(false);
432  this.hashLookupsRemainingLabel.setVisible(false);
433  this.fileUploadsRemainingLabel.setVisible(false);
434  } else {
435  this.maxHashLookupsLabel.setVisible(true);
436  this.maxHashLookupsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups(this.authTokenResponse.getHashLookupLimit()));
437  this.maxFileUploadsLabel.setVisible(true);
438  this.maxFileUploadsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups(this.authTokenResponse.getFileUploadLimit()));
439  this.countersResetLabel.setVisible(true);
440  this.countersResetLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_countersReset(this.authTokenResponse.getResetDate() == null ? "" : MALWARE_SCANS_RESET_FORMAT.format(this.authTokenResponse.getResetDate())));
441  this.hashLookupsRemainingLabel.setVisible(true);
442  this.hashLookupsRemainingLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining(remaining(this.authTokenResponse.getHashLookupLimit(), this.authTokenResponse.getHashLookupCount())));
443  this.fileUploadsRemainingLabel.setVisible(true);
444  this.fileUploadsRemainingLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining(remaining(this.authTokenResponse.getFileUploadLimit(), this.authTokenResponse.getFileUploadCount())));
445  }
446  }
447 
448  private long remaining(Long total, Long used) {
449  total = total == null ? 0 : total;
450  used = used == null ? 0 : used;
451  return total - used;
452  }
453 
454  private void acceptEula(LicenseResponse licenseResponse) {
455  try {
456  final EULADialog eulaDialog = new EULADialog(WindowManager.getDefault().getMainWindow(), true);
457  eulaDialog.setLocationRelativeTo(this);
458  eulaDialog.setSize(eulaDialog.getPreferredSize());
459  eulaDialog.setVisible(true);
460 
461  if (eulaDialog.isAcceptPressed()) {
462  // only indicate a change to save if we have accepted EULA for a license
463  this.licenseInfo = LicenseDecryptorUtil.getInstance().createLicenseInfo(licenseResponse);
464  this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
465  }
466  } catch (IOException | InvalidLicenseException ex) {
467  logger.log(Level.WARNING, "An error occurred while fetching data", ex);
468  JOptionPane.showMessageDialog(
470  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc(),
471  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title(),
472  JOptionPane.ERROR_MESSAGE);
473  } finally {
474  setLicenseDisplay(this.licenseInfo, null);
475  loadMalwareScansInfo(this.licenseInfo);
476  }
477  }
478 
479  @NbBundle.Messages({
480  "CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error",
481  "CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error",
482  "CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.",})
483  private class LicenseFetcher extends SwingWorker<LicenseResponse, Void> {
484 
485  private final String licenseText;
486 
487  public LicenseFetcher(String licenseText) {
488  this.licenseText = licenseText;
489  }
490 
491  @Override
492  protected LicenseResponse doInBackground() throws Exception {
493  if (this.isCancelled()) {
494  return null;
495  }
496  return ctApiDAO.getLicenseInfo(licenseText);
497  }
498 
499  @Override
500  protected void done() {
501  try {
502  LicenseResponse licenseResponse = get();
503  SwingUtilities.invokeLater(() -> acceptEula(licenseResponse));
504  } catch (InterruptedException ex) {
505  // ignore cancellation; just load current license
506  setLicenseDisplay(licenseInfo, null);
507  loadMalwareScansInfo(licenseInfo);
508  } catch (ExecutionException ex) {
509  if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
510  logger.log(Level.WARNING, "An API error occurred while fetching license information", cloudEx);
511  JOptionPane.showMessageDialog(
513  cloudEx.getErrorCode().getDescription(),
514  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title(),
515  JOptionPane.ERROR_MESSAGE);
516  } else {
517  logger.log(Level.WARNING, "An error occurred while fetching data", ex);
518  JOptionPane.showMessageDialog(
520  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc(),
521  Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title(),
522  JOptionPane.ERROR_MESSAGE);
523  }
524  setLicenseDisplay(licenseInfo, null);
525  loadMalwareScansInfo(licenseInfo);
526  } finally {
527  synchronized (CTMalwareScannerOptionsPanel.this) {
529  }
530  }
531  }
532  }
533 
534  @NbBundle.Messages({
535  "CTMalwareScannerOptionsPanel_MalwareScansFetcher_apiErr_title=Server Error",
536  "CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_title=General Error",
537  "CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc=A general error occurred while fetching malware scans information. Please try again later.",})
538  private class AuthTokenFetcher extends SwingWorker<AuthTokenResponse, Void> {
539 
541 
542  public AuthTokenFetcher(DecryptedLicenseResponse decryptedLicense) {
543  this.decryptedLicense = decryptedLicense;
544  }
545 
546  @Override
547  protected AuthTokenResponse doInBackground() throws Exception {
548  if (this.isCancelled()) {
549  return null;
550  }
551 
552  return ctApiDAO.getAuthToken(decryptedLicense);
553  }
554 
555  @Override
556  protected void done() {
557  AuthTokenResponse authTokenResponse = null;
558  try {
559  authTokenResponse = get();
560  } catch (InterruptedException ex) {
561  // ignore cancellation
562  } catch (ExecutionException ex) {
563  if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
564  logger.log(Level.WARNING, "An API error occurred while fetching malware scans information for license", cloudEx);
565  JOptionPane.showMessageDialog(
567  cloudEx.getErrorDetails(),
568  Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_apiErr_title(),
569  JOptionPane.ERROR_MESSAGE);
570  } else {
571  logger.log(Level.WARNING, "An error occurred while fetching data", ex);
572  JOptionPane.showMessageDialog(
574  Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc(),
575  Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_title(),
576  JOptionPane.ERROR_MESSAGE);
577  }
578  } finally {
579  synchronized (CTMalwareScannerOptionsPanel.this) {
581  if (!this.isCancelled()) {
582  setMalwareScansDisplay(authTokenResponse, null);
583  }
584  }
585  }
586  }
587  }
588 
589 
590  // Variables declaration - do not modify//GEN-BEGIN:variables
591  private javax.swing.JLabel countersResetLabel;
592  private javax.swing.JLabel fileUploadsRemainingLabel;
593  private javax.swing.JLabel hashLookupsRemainingLabel;
594  private javax.swing.JButton licenseInfoAddButton;
595  private javax.swing.JLabel licenseInfoExpiresLabel;
596  private javax.swing.JLabel licenseInfoIdLabel;
597  private javax.swing.JLabel licenseInfoMessageLabel;
598  private javax.swing.JLabel licenseInfoUserLabel;
599  private javax.swing.JLabel malwareScansMessageLabel;
600  private javax.swing.JPanel malwareScansPanel;
601  private javax.swing.JLabel maxFileUploadsLabel;
602  private javax.swing.JLabel maxHashLookupsLabel;
603  // End of variables declaration//GEN-END:variables
604 }
synchronized void setMalwareScansDisplay(AuthTokenResponse authTokenResponse, String authTokenMessage)
synchronized boolean saveLicenseResponse(LicenseResponse licenseResponse)
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted)
Definition: CTApiDAO.java:76
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
synchronized void setLicenseDisplay(LicenseInfo licenseInfo, String licenseMessage)
LicenseResponse getLicenseInfo(String licenseString)
Definition: CTApiDAO.java:65

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