Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

2.9 KB
Raw Blame
package opensuite.ui;

import opensuite.core.ProjectOptions;
import opensuite.core.SuiteContext;

import javax.swing.*;
import java.awt.*;

/**
 * The strip above the site map and the proxy history that says the proxy is no
 * longer recording out-of-scope traffic, with a button to turn it back on. It
 * shows itself whenever the setting goes off and can be closed until the next
 * time; closing it does not change the setting.
 */
public final class OutOfScopeBanner extends JPanel {

    private boolean dismissed;

    public OutOfScopeBanner(SuiteContext ctx) {
        super(new BorderLayout());
        // A pale band set in from the edges, as in the reference: the strip itself is clear and
        // the band is drawn inside it.
        setOpaque(false);
        setBorder(Ui.pad(5, 10, 0, 10));
        JPanel band = new JPanel(new BorderLayout()) {
            @Override protected void paintComponent(Graphics g) {
                g.setColor(Theme.dark ? new Color(0x2C, 0x35, 0x40) : new Color(0xEB, 0xF1, 0xF6));
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        band.setOpaque(false);
        band.setBorder(Ui.pad(1, 10, 1, 8));
        super.add(band, BorderLayout.CENTER);

        JLabel text = Ui.label("Logging of out-of-scope Proxy traffic is disabled");
        text.setIcon(ToolIcons.info());
        text.setIconTextGap(8);
        JButton reenable = Ui.button("Re-enable", "Resume logging of out-of-scope traffic");
        reenable.addActionListener(e -> ctx.settings().setBool(ProjectOptions.LOG_OUT_OF_SCOPE, true));
        JPanel middle = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 0));
        middle.setOpaque(false);
        middle.add(text);
        middle.add(reenable);
        band.add(middle, BorderLayout.CENTER);

        JButton close = new JButton(Glyphs.cross(14, Theme.TEXT));
        close.setMargin(new Insets(2, 4, 2, 4));
        close.setBorderPainted(false);
        close.setContentAreaFilled(false);
        close.setFocusable(false);
        close.setToolTipText("hide this message");
        close.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        close.addActionListener(e -> { dismissed = true; refresh(ctx); });
        band.add(close, BorderLayout.EAST);

        ctx.settings().addListener(key -> {
            if (ProjectOptions.LOG_OUT_OF_SCOPE.equals(key)) {
                if (ProjectOptions.logOutOfScope(ctx.settings())) dismissed = false;
                SwingUtilities.invokeLater(() -> refresh(ctx));
            }
        });
        ctx.addScopeListener(() -> SwingUtilities.invokeLater(() -> refresh(ctx)));
        refresh(ctx);
    }

    /** Shown only while there is a scope for the setting to apply to. */
    private void refresh(SuiteContext ctx) {
        setVisible(!dismissed && !ctx.scope().isEmpty() && !ProjectOptions.logOutOfScope(ctx.settings()));
        revalidate();
        repaint();
    }
}