Example #1
0
  /**
   * Expects a VisualNode with a proper {@link HostVisualNode#getData() } return value.
   *
   * @param n Node to show all connections for.
   */
  public ConnectionDialog(HostVisualNode n) {
    if (n == null || !n.isHost()) {
      this.treeViewNode = null;
      return;
    }

    initComponents();
    setTitle(String.format("%s Connections", n.getName()));
    this.iconLabel.setIcon(n.getDetails().image.getIcon());
    this.model = getNewModel();
    this.model.setColumnIdentifiers(ConnectionDialog.COLUMNS);
    this.table.setModel(this.model);
    this.table.setAutoCreateRowSorter(true);
    DefaultRowSorter sorter = (DefaultRowSorter) this.table.getRowSorter();
    Comparator comp =
        (o1, o2) -> {
          int compare;
          try {
            compare =
                Integer.compare(Integer.valueOf(o1.toString()), Integer.valueOf(o2.toString()));
          } catch (Exception ex) {
            compare = o1.toString().compareTo(o2.toString());
          }
          return compare;
        };
    sorter.setComparator(1, comp);
    sorter.setComparator(3, comp);
    sorter.setComparator(8, comp);
    sorter.setComparator(9, comp);
    this.table.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
              int row = table.rowAtPoint(e.getPoint());
              Object obj = table.getValueAt(row, PACKET);
              try {
                Integer frame = Integer.valueOf(obj.toString());
                String path = table.getValueAt(row, FILE).toString();
                ConnectionDialog.this.openPopup(e.getPoint(), frame, path);
              } catch (Exception ex) {
                Logger.getLogger(getClass().getName())
                    .log(Level.SEVERE, "Failed to get pcap frame number.", ex);
              }
            }
          }
        });
    this.treeViewNode = n;
    pack();
  }
Example #2
0
 @SuppressWarnings("unchecked")
 private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {
   toggle(false);
   JFileChooser fc = new JFileChooser();
   String path =
       FileUtils.getUserDirectoryPath() + File.separator + treeViewNode.getText() + ".csv";
   fc.setSelectedFile(new File(path));
   fc.showSaveDialog(this);
   File target = fc.getSelectedFile();
   int row = model.getRowCount();
   try {
     boolean written;
     try (FileOutputStream fos = new FileOutputStream(target)) {
       while (--row > -1) {
         Vector v = (Vector) model.getDataVector().get(row);
         for (int i = 0; i < v.size(); i++) {
           if (v.get(i).toString().contains(",")) {
             v.set(i, ST.format("\"<%1>\"", v.get(i)));
           }
         }
         String line = ST.format("<%1:{ x |, <x>}>", v).substring(2);
         fos.write(line.getBytes(CHARSET));
         fos.write(Character.LINE_SEPARATOR);
       }
       written = true;
     }
     if (written) {
       LogEmitter.factory
           .get()
           .emit(
               this,
               Core.ALERT.INFO,
               ST.format("<%1> hosts written to <%2>", model.getRowCount(), target.getPath()));
     } else {
       LogEmitter.factory
           .get()
           .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
     }
   } catch (FileNotFoundException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   } catch (IOException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   }
   toggle(true);
 }
Example #3
0
  @SuppressWarnings("unchecked")
  private void updateGraph() {
    // HashMap<ComparableLabel, Integer> dataPoints = new java.util.HashMap<>();
    HashMap<String, HashMap<Long, Integer>> dataNumberPoints = new java.util.HashMap<>();

    this.treeViewNode
        .getData()
        .edges
        .forEach(
            (destinationHostIp, protocols) -> {
              String destinationIp = ViewUtils.ipString(destinationHostIp);
              protocols.forEach(
                  (protocol, sources) ->
                      sources.forEach(
                          (source, destinations) ->
                              destinations.forEach(
                                  (destination, data) ->
                                      data.right.forEach(
                                          frameInformation -> {
                                            // dataPoints.put(new
                                            // DateAxisGraphLabel(frameInformation.date,
                                            // DateFormatUtils.format(frameInformation.date,
                                            // "HH:mm\nss:SSS", Locale.US)), frameInformation.size);
                                            String key = destinationIp;
                                            if (dataNumberPoints.containsKey(key)) {
                                              dataNumberPoints
                                                  .get(key)
                                                  .put(
                                                      frameInformation.date, frameInformation.size);
                                            } else {
                                              HashMap<Long, Integer> newMap = new HashMap<>();
                                              newMap.put(
                                                  frameInformation.date, frameInformation.size);
                                              dataNumberPoints.put(key, newMap);
                                            }
                                            // dataNumberPoints.put(frameInformation.date,
                                            // frameInformation.size);
                                          }))));
            });

    this.treeViewNode
        .getData()
        .backEdges
        .stream()
        .forEach(
            peer -> { // a peer has an inbound connection to this treeViewNode
              String sourceIp = ViewUtils.ipString(peer);
              peer.edges
                  .get(treeViewNode.getData())
                  .forEach(
                      (protocol, sources) ->
                          sources.forEach(
                              (source, destinations) ->
                                  destinations.forEach(
                                      (destination, data) ->
                                          data.right.forEach(
                                              frameInformation -> {
                                                // dataPoints.put(new
                                                // DateAxisGraphLabel(frameInformation.date,
                                                // DateFormatUtils.format(frameInformation.date,
                                                // "HH:mm\nss:SSS", Locale.US)),
                                                // frameInformation.size);
                                                String key = sourceIp;
                                                if (dataNumberPoints.containsKey(key)) {
                                                  dataNumberPoints
                                                      .get(key)
                                                      .put(
                                                          frameInformation.date,
                                                          frameInformation.size);
                                                } else {
                                                  HashMap<Long, Integer> newMap = new HashMap<>();
                                                  newMap.put(
                                                      frameInformation.date, frameInformation.size);
                                                  dataNumberPoints.put(key, newMap);
                                                }
                                              }))));
            });
    Platform.runLater(
        () -> {
          this.graphPanel.setScene(createScene());
          updateGraph(dataNumberPoints);
        });
  }