wsattacker.plugin.dos.dosExtension.gui.DosResultJFrame.java Source code

Java tutorial

Introduction

Here is the source code for wsattacker.plugin.dos.dosExtension.gui.DosResultJFrame.java

Source

/**
 * WS-Attacker - A Modular Web Services Penetration Testing Framework Copyright
 * (C) 2012 Andreas Falkenberg
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wsattacker.plugin.dos.dosExtension.gui;

import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.border.LineBorder;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

import wsattacker.plugin.dos.dosExtension.attackRunnables.RedrawChartRunnable;
import wsattacker.plugin.dos.dosExtension.chart.ChartObject;
import wsattacker.plugin.dos.dosExtension.mvc.controller.CloseAttackFinishedController;
import wsattacker.plugin.dos.dosExtension.mvc.controller.HelpController;
import wsattacker.plugin.dos.dosExtension.mvc.controller.ReportController;
import wsattacker.plugin.dos.dosExtension.mvc.model.AttackModel;
import wsattacker.plugin.dos.dosExtension.result.ResultGenerator;

/**
 * JFrame for Attack Results
 */
public class DosResultJFrame extends javax.swing.JFrame {

    private final ResultGenerator resultGenerator;

    private final AttackModel model;

    /**
     * Creates new form NewJFrame
     */
    public DosResultJFrame(AttackModel model) {
        this.model = model;
        resultGenerator = new ResultGenerator(model);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed"
    // desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        // This will create the chart
        ChartObject chartObject = new ChartObject(model);
        JFreeChart chart = chartObject.createOverlaidChart();
        jChartPanel = new ChartPanel(chart);
        jButtonCloseAll = new javax.swing.JButton();
        jButtonExport = new javax.swing.JButton();
        jButtonHelp = new javax.swing.JButton();
        jPanelSuccess = new javax.swing.JPanel();
        jLabelSuccess = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanelMetadata = new javax.swing.JPanel();
        jLabelMetadata = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jSpinner1 = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("WS-Attacker - DOS Attack Results");
        addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent evt) {
                handlerCloseFinishedAttack(evt);
            }
        });

        jChartPanel.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 0, false));
        resultGenerator.setJChartPanel((ChartPanel) jChartPanel); // to refresh
                                                                  // just call
                                                                  // this
                                                                  // refernce
                                                                  // in Model!

        javax.swing.GroupLayout jChartPanelLayout = new javax.swing.GroupLayout(jChartPanel);
        jChartPanel.setLayout(jChartPanelLayout);
        jChartPanelLayout.setHorizontalGroup(jChartPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 713, Short.MAX_VALUE));
        jChartPanelLayout.setVerticalGroup(jChartPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 653, Short.MAX_VALUE));

        jButtonCloseAll.setText("Close");
        jButtonCloseAll.setToolTipText("Closes all open attack windows");
        jButtonCloseAll.addActionListener(new CloseAttackFinishedController(this));

        jButtonExport.setText("Export Results + Request Details");
        jButtonExport.setToolTipText("Save attack report");
        jButtonExport.addActionListener(new ReportController(resultGenerator));

        jButtonHelp.setText("Help Menu");
        jButtonHelp.setToolTipText("Open Help menu in web browser");
        jButtonHelp.addActionListener(new HelpController(resultGenerator));

        jPanelSuccess.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Attack Success Metric",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));

        jLabelSuccess.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N
        jLabelSuccess
                .setText("" + "<html>" + "Attack roundtrip time ratio:<br />" + model.getAttackRoundtripTimeRatio()
                        + " Points - " + model.getAttackRoundtripTimeRatioDescription("text") + "</html>");

        jLabel7.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N
        jLabel7.setText("" + "<html>" + "Testprobe roundtrip time after attack ("
                + model.getAttackLongevitySeconds() + " sec)<br />" + model.getTestProbeAttackRoundtripTime()
                + " sec - " + model.getTestProbeAttackRoundtripTimeDescription("text") + "</html>");

        javax.swing.GroupLayout jPanelSuccessLayout = new javax.swing.GroupLayout(jPanelSuccess);
        jPanelSuccess.setLayout(jPanelSuccessLayout);
        jPanelSuccessLayout.setHorizontalGroup(jPanelSuccessLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelSuccessLayout.createSequentialGroup().addContainerGap()
                        .addGroup(
                                jPanelSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabelSuccess, javax.swing.GroupLayout.DEFAULT_SIZE, 279,
                                        Short.MAX_VALUE)
                                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
        jPanelSuccessLayout
                .setVerticalGroup(
                        jPanelSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanelSuccessLayout.createSequentialGroup()
                                        .addGroup(jPanelSuccessLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabelSuccess, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanelSuccessLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        java.net.URL imgURL1 = getClass().getResource(model.getAttackRoundtripTimeRatioDescription("image"));
        if (imgURL1 != null) {
            jLabel1.setIcon(new ImageIcon(imgURL1, "Status Attack Metric 1"));
        } else {
            System.err.println("Couldn't find file: " + "/IMG/XX.png");
        }
        java.net.URL imgURL4 = getClass().getResource(model.getTestProbeAttackRoundtripTimeDescription("image"));
        if (imgURL4 != null) {
            jLabel4.setIcon(new ImageIcon(imgURL4, "Status Attack Metric 4"));
        } else {
            System.err.println("Couldn't find file: " + "/IMG/ok.png");
        }

        jPanelMetadata.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Attack Metadata",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));

        jLabelMetadata.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N
        jLabelMetadata.setText("" + "<html>" + "<table>" + "<tr>" + "<td>Attack start:</td>" + "<td>"
                + model.getStartDate() + "</td>" + "</tr>" + "<tr>" + "<td>Attack stop:</td>" + "<td>"
                + model.getStopDate() + "</td>" + "</tr>" + "<tr>" + "<td>Parallel threads:</td>" + "<td>"
                + model.getNumberThreads() + "</td>" + "</tr>" + "<tr>" + "<td>Requests per thread:</td>" + "<td>"
                + model.getNumberRequestsPerThread() + "</td>" + "</tr>" + "<tr>"
                + "<td>Request repeat interval</td>" + "<td>" + (model.getSecondsBetweenRequests()) + " ms</td>"
                + "</tr>" + "<tr>" + "<td>Server recovery time</td>" + "<td>"
                + (model.getSecondsServerLoadRecovery() / 1000) + " sec</td>" + "</tr>" + "<tr>"
                + "<td>Send testprobes:</td>" + "<td>" + model.getCounterProbesSend() + "</td>" + "</tr>" + "<tr>"
                + "<td>Testprobe repeat interval</td>" + "<td>" + (model.getSecondsBetweenProbes()) + " ms</td>"
                + "</tr>" + "<tr>" + "<td>Size testprobe request:</td>" + "<td>" + model.getRequestSizeTestProbe()
                + " Bytes</td>" + "</tr>" + "<tr>" + "<td>Size untampered padded request:</td>" + "<td>"
                + model.getRequestSizePaddedUntampered() + " Bytes</td>" + "</tr>" + "<tr>"
                + "<td>Size tampered padded request:</td>" + "<td>" + model.getRequestSizePaddedTampered()
                + " Bytes</td>" + "</tr>" + "</table>" + "</html>");

        javax.swing.GroupLayout jPanelMetadataLayout = new javax.swing.GroupLayout(jPanelMetadata);
        jPanelMetadata.setLayout(jPanelMetadataLayout);
        jPanelMetadataLayout
                .setHorizontalGroup(
                        jPanelMetadataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanelMetadataLayout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabelMetadata, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap()));
        jPanelMetadataLayout
                .setVerticalGroup(
                        jPanelMetadataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanelMetadataLayout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabelMetadata, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap()));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Diagramm Settings",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));

        jSpinner1.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N
        jSpinner1.setModel(new javax.swing.SpinnerNumberModel(1, 1, 60, 1));
        jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
            @Override
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner1StateChanged(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N
        jLabel3.setText("Interval length (default 1 sec)");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(24, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3))
                        .addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(18, 18, 18)
                        .addComponent(jChartPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanelSuccess, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jButtonExport, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jButtonCloseAll, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jButtonHelp, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanelMetadata, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jChartPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jPanelMetadata, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jPanelSuccess, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButtonHelp).addGap(18, 18, 18).addComponent(jButtonExport)
                                        .addGap(18, 18, 18).addComponent(jButtonCloseAll)))
                        .addContainerGap()));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width - 1110) / 2, (screenSize.height - 707) / 2, 1110, 707);
    }// </editor-fold>//GEN-END:initComponents

    private void handlerCloseFinishedAttack(java.awt.event.WindowEvent evt) {// GEN-FIRST:event_HandlerCloseFinishedAttack
        this.dispose();
    }// GEN-LAST:event_HandlerCloseFinishedAttack

    private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jSpinner1StateChanged
                                                                           // TODO add your handling code here:
        int spinnerValue = Integer.parseInt(jSpinner1.getValue().toString());
        EventQueue.invokeLater(new RedrawChartRunnable(resultGenerator, spinnerValue));
    }// GEN-LAST:event_jSpinner1StateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCloseAll;

    private javax.swing.JButton jButtonExport;

    private javax.swing.JButton jButtonHelp;

    private javax.swing.JPanel jChartPanel;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JLabel jLabel4;

    private javax.swing.JLabel jLabel7;

    private javax.swing.JLabel jLabelMetadata;

    private javax.swing.JLabel jLabelSuccess;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JPanel jPanelMetadata;

    private javax.swing.JPanel jPanelSuccess;

    private javax.swing.JSpinner jSpinner1;
    // End of variables declaration//GEN-END:variables
}