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.

4.6 KB
Raw Blame
package opensuite.ui;

import opensuite.core.Debug;
import opensuite.core.SuiteContext;

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

/** Suite-wide communication and display options. */
public class SuiteOptionsPanel extends JPanel {

    public SuiteOptionsPanel(SuiteContext ctx) {
        super(new BorderLayout());
        OptionsPage page = new OptionsPage();

        JTextField connect = Ui.shortField(String.valueOf(ctx.settings().getInt("timeout.connect", 120)));
        JTextField read    = Ui.shortField(String.valueOf(ctx.settings().getInt("timeout.read", 120)));
        connect.addActionListener(e -> ctx.settings().setInt("timeout.connect", parse(connect, 120)));
        read.addActionListener(e -> ctx.settings().setInt("timeout.read", parse(read, 120)));
        page.section("timeouts (seconds)",
                OptionsPage.fieldRow("connect", connect, ""),
                OptionsPage.fieldRow("read", read, ""));

        JCheckBox unpack = Ui.check("unpack gzip / deflate in responses",
                ctx.settings().getBool("http.unpackGzip", true));
        unpack.addActionListener(e -> ctx.settings().setBool("http.unpackGzip", unpack.isSelected()));
        JCheckBox allowRemote = Ui.check("allow the renderer to make HTTP requests (for images, etc.)",
                ctx.settings().getBool("render.allowHttp", false));
        allowRemote.addActionListener(e -> ctx.settings().setBool("render.allowHttp", allowRemote.isSelected()));
        page.section("HTTP", unpack, allowRemote);

        // Display scale control.
        String[] scales = {"100%", "125%", "150%", "200%"};
        JComboBox<String> scaleCombo = Ui.combo(scales);
        int cur = (int) Math.round(UiScale.desired() * 100);
        scaleCombo.setSelectedItem(cur + "%");
        scaleCombo.addActionListener(e -> {
            String v = String.valueOf(scaleCombo.getSelectedItem()).replace("%", "");
            if (v.equals(String.valueOf(cur))) return;
            Restart.ask(scaleCombo, ctx, "the new scale",
                    () -> UiScale.changeTo(Double.parseDouble(v) / 100.0, Restart.arguments(ctx)),
                    () -> scaleCombo.setSelectedItem(cur + "%"));
        });
        JTextArea scaleNote = Ui.note(
            "Scales the whole interface using real HiDPI rendering, so fonts, columns and "
            + "borders all grow together and stay crisp. Changing it restarts the app. Use "
            + "this if the app looks tiny on a high-density screen, or too large for a small "
            + "one. You can also launch with -Dopensuite.scale=2 (or 1.5, etc.).");
        scaleNote.setPreferredSize(new java.awt.Dimension(600, 60));

        // Theme control: like scale, a change relaunches so the whole interface
        // (including the colours the Ui constants cache) comes up consistent.
        JComboBox<String> themeCombo = Ui.combo(new String[]{"light", "dark"});
        themeCombo.setSelectedItem(Theme.darkPreferred() ? "dark" : "light");
        themeCombo.addActionListener(e -> {
            boolean wantDark = "dark".equals(themeCombo.getSelectedItem());
            if (wantDark == Theme.dark) return;
            Restart.ask(themeCombo, ctx, "the " + (wantDark ? "dark" : "light") + " theme", () -> {
                ctx.settings().set("ui.theme", wantDark ? "dark" : "light");
                if (UiScale.relaunchWith(UiScale.desired(), Restart.arguments(ctx))) System.exit(0);
            }, () -> themeCombo.setSelectedItem(Theme.dark ? "dark" : "light"));
        });
        JTextArea themeNote = Ui.note("Switches between the light and dark palette. "
                + "Changing it restarts the app so every panel comes up in the new theme.");
        themeNote.setMaximumSize(new java.awt.Dimension(600, themeNote.getPreferredSize().height));

        page.section("display",
                OptionsPage.labelRow("interface scale", scaleCombo),
                scaleNote,
                OptionsPage.labelRow("theme", themeCombo),
                themeNote);

        JTextArea about = Ui.note(
            "Open Suite is an HTTP interception and testing suite.\n\n" +
            "To use the proxy: set your browser to use 127.0.0.1 port " + opensuite.proxy.ProxyListener.DEFAULT_PORT + " for HTTP and HTTPS, "
            + "then browse to http://opensuite/ and install the certificate authority so that "
            + "TLS traffic can be inspected.");
        about.setPreferredSize(new Dimension(600, 90));
        page.section("about", about);

        add(page, BorderLayout.CENTER);
    }

    private static int parse(JTextField f, int def) {
        try { return Integer.parseInt(f.getText().trim()); } catch (Exception e) { return def; }
    }
}