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.

Site map tree lines and a Contents heading; menu icons; a request pane offers the response items

scottsturrock8fee97daebdd
diff --git a/src/opensuite/target/TargetTool.java b/src/opensuite/target/TargetTool.java
index e216166..d2f8219 100644
--- a/src/opensuite/target/TargetTool.java
+++ b/src/opensuite/target/TargetTool.java
@@ -315,6 +315,7 @@ public class TargetTool implements ToolModule {
tree = new opensuite.ui.RowTree(treeModel);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
+ ((opensuite.ui.RowTree) tree).setConnectors(true);
// Hosts carry a padlock (closed for https, open and red for http) and
// are labelled by host and port, the scheme being what the padlock
// says; folders and requests get flat icons. Out-of-scope nodes are
@@ -375,8 +376,40 @@ public class TargetTool implements ToolModule {
new opensuite.proxy.HistoryContextMenu(ctx, itemsTable, itemsModel::at, null).install();
itemsFilter.scope = ctx.scope();
- JScrollPane contents = Ui.scroll(itemsTable);
- contents.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Theme.BORDER));
+ JScrollPane contentsTable = Ui.scroll(itemsTable);
+ contentsTable.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Theme.BORDER));
+ // "Contents", with a search of the rows and the table's layout menu, as the reference heads the table.
+ JTextField contentsSearch = Ui.searchField(22);
+ contentsSearch.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
+ private void go() {
+ String term = contentsSearch.getText().strip();
+ javax.swing.table.TableRowSorter<javax.swing.table.TableModel> sorter;
+ if (itemsTable.getRowSorter() instanceof javax.swing.table.TableRowSorter<?> have) {
+ @SuppressWarnings("unchecked") javax.swing.table.TableRowSorter<javax.swing.table.TableModel> s = (javax.swing.table.TableRowSorter<javax.swing.table.TableModel>) have;
+ sorter = s;
+ } else {
+ sorter = new opensuite.ui.NumberSorter<>(itemsTable.getModel());
+ itemsTable.setRowSorter(sorter);
+ }
+ sorter.setRowFilter(term.isEmpty() ? null : RowFilter.regexFilter("(?i)" + java.util.regex.Pattern.quote(term)));
+ }
+ @Override public void insertUpdate(javax.swing.event.DocumentEvent e) { go(); }
+ @Override public void removeUpdate(javax.swing.event.DocumentEvent e) { go(); }
+ @Override public void changedUpdate(javax.swing.event.DocumentEvent e) { go(); }
+ });
+ JButton contentsMenu = opensuite.ui.Glyphs.menuButton("Table layout", () -> opensuite.ui.TableLayoutMenu.build(itemsTable));
+ JPanel contentsTools = new JPanel(new FlowLayout(FlowLayout.RIGHT, 6, 0));
+ contentsTools.setOpaque(false);
+ contentsTools.add(contentsSearch); contentsTools.add(contentsMenu);
+ JPanel contentsHead = new JPanel(new BorderLayout());
+ contentsHead.setOpaque(false);
+ contentsHead.setBorder(Ui.pad(5, 10, 5, 6));
+ contentsHead.add(Ui.bold("Contents"), BorderLayout.WEST);
+ contentsHead.add(contentsTools, BorderLayout.EAST);
+ JPanel contents = new JPanel(new BorderLayout());
+ contents.setOpaque(false);
+ contents.add(contentsHead, BorderLayout.NORTH);
+ contents.add(contentsTable, BorderLayout.CENTER);
opensuite.ui.MessagePair detail = new opensuite.ui.MessagePair(reqView, respView);
this.pair = detail;
diff --git a/src/opensuite/ui/MessageEditor.java b/src/opensuite/ui/MessageEditor.java
index b2952f3..a27dc14 100644
--- a/src/opensuite/ui/MessageEditor.java
+++ b/src/opensuite/ui/MessageEditor.java
@@ -2113,7 +2113,10 @@ public class MessageEditor extends JPanel {
boolean haveMessage = message != null && message.raw().length > 0;
boolean isRequest = haveMessage && message.isRequest();
HttpMessage req = !haveMessage ? relatedRequest : isRequest ? message : relatedRequest;
- HttpMessage resp = haveMessage && !isRequest ? message : null;
+ // A request pane offers what is done with the response too, once its pair holds one.
+ HttpMessage paired = relatedResponse == null ? null : relatedResponse.get();
+ HttpMessage resp = haveMessage && !isRequest ? message
+ : paired != null && paired.raw().length > 0 && !paired.isRequest() ? paired : null;
int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
// Scan.
@@ -2268,6 +2271,11 @@ public class MessageEditor extends JPanel {
menu.addSeparator();
for (ActionProvider p : providers) p.contribute(menu);
}
+ for (Component c : menu.getComponents()) {
+ if (c instanceof JMenuItem mi && !(c instanceof JMenu) && MENU_ICONS.containsKey(mi.getText())) {
+ mi.setIcon(MENU_ICONS.get(mi.getText()).apply(15, Theme.ICON));
+ }
+ }
return menu;
}
@@ -2397,8 +2405,30 @@ public class MessageEditor extends JPanel {
private void openResponseInBrowser() {
MessageActions.openResponseInBrowser(this, ctx, service,
relatedRequest != null ? relatedRequest : (message.isRequest() ? message : null),
- message.isRequest() ? null : message);
- }
+ message.isRequest() ? (relatedResponse == null ? null : relatedResponse.get()) : message);
+ }
+
+ /** The items the reference's menu marks with an icon, and the icon each carries. */
+ private static final java.util.Map<String, java.util.function.BiFunction<Integer, Color, Icon>> MENU_ICONS = java.util.Map.ofEntries(
+ java.util.Map.entry("Insert Collaborator payload", Glyphs::ringPlus),
+ java.util.Map.entry("Change request method", Glyphs::swap),
+ java.util.Map.entry("Cut", Glyphs::scissors),
+ java.util.Map.entry("Paste host / URL as request", Glyphs::clipboard),
+ java.util.Map.entry("Copy", Glyphs::copy),
+ java.util.Map.entry("Copy prettified", Glyphs::copy),
+ java.util.Map.entry("Save selected text to file", Glyphs::save),
+ java.util.Map.entry("Paste", Glyphs::clipboard),
+ java.util.Map.entry("Paste text from file", Glyphs::clipboard),
+ java.util.Map.entry("Save entire history", Glyphs::save),
+ java.util.Map.entry("Copy URL", Glyphs::copy),
+ java.util.Map.entry("Copy as curl command (bash)", Glyphs::copy),
+ java.util.Map.entry("Copy links in response", Glyphs::copy),
+ java.util.Map.entry("Save item", Glyphs::save));
+
+ private java.util.function.Supplier<HttpMessage> relatedResponse;
+
+ /** The response this request pane is shown beside, so its menu can offer what is done with a response. */
+ public void setRelatedResponse(java.util.function.Supplier<HttpMessage> response) { relatedResponse = response; }
private String asCurl() {
StringBuilder b = new StringBuilder("curl -i -s -k ");
diff --git a/src/opensuite/ui/MessagePair.java b/src/opensuite/ui/MessagePair.java
index 504a815..701db07 100644
--- a/src/opensuite/ui/MessagePair.java
+++ b/src/opensuite/ui/MessagePair.java
@@ -27,6 +27,7 @@ public final class MessagePair extends JPanel {
public MessagePair(MessageEditor req, MessageEditor resp) {
this.req = req;
this.resp = resp;
+ req.setRelatedResponse(resp::message);
setLayout(cards);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, req, resp);
split.setBorder(null);
diff --git a/src/opensuite/ui/RowTree.java b/src/opensuite/ui/RowTree.java
index df206e8..6a8e24f 100644
--- a/src/opensuite/ui/RowTree.java
+++ b/src/opensuite/ui/RowTree.java
@@ -86,6 +86,80 @@ public class RowTree extends JTree {
super.setCellRenderer(r);
}
+ private boolean connectors;
+
+ /**
+ * Join each row to the one it belongs under, as the reference's site map
+ * does: a thin line down from the parent, a stub across to each child, a
+ * dot where a top-level row sits on the line and a small ring in place of
+ * the handle on a row with nothing under it. Rows are 27px with these.
+ */
+ public void setConnectors(boolean on) {
+ connectors = on;
+ setRowHeight(on ? 27 : 24);
+ if (getUI() instanceof BasicTreeUI ui) { ui.setLeftChildIndent(on ? 13 : 11); ui.setRightChildIndent(on ? 14 : 11); }
+ repaint();
+ }
+
+ /** Where a row's handle is centred: where its arrow is, or where one would be. */
+ private int handleX(Rectangle rowBounds) {
+ return rowBounds.x - (getUI() instanceof BasicTreeUI ui ? ui.getRightChildIndent() : 11) + 1;
+ }
+
+ private void paintConnectors(Graphics2D g) {
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
+ g.setStroke(new BasicStroke(1f));
+ Rectangle clip = g.getClipBounds();
+ int topDepth = isRootVisible() ? 1 : 2;
+ for (int row = 0; row < getRowCount(); row++) {
+ javax.swing.tree.TreePath path = getPathForRow(row);
+ Rectangle r = getRowBounds(row);
+ if (path == null || r == null) continue;
+ double cy = r.y + r.height / 2.0;
+ int hx = handleX(r);
+ boolean top = path.getPathCount() <= topDepth;
+ int trunk; // the line this row hangs from
+ if (top) trunk = hx - 12;
+ else {
+ Rectangle pr = getPathBounds(path.getParentPath());
+ trunk = pr == null ? hx - 12 : handleX(pr) - 12;
+ }
+ // The line carries on down to the next row at this level, if the parent has one.
+ Object parent = path.getParentPath() == null ? null : path.getParentPath().getLastPathComponent();
+ boolean lastChild = parent == null
+ || getModel().getIndexOfChild(parent, path.getLastPathComponent()) == getModel().getChildCount(parent) - 1;
+ if (clip != null && (r.y > clip.y + clip.height + 2000 || r.y + r.height < clip.y - 2000)) continue;
+ g.setColor(Theme.SURFACE_3);
+ if (!top) {
+ Rectangle pr = getPathBounds(path.getParentPath());
+ double from = pr == null ? r.y : pr.y + pr.height / 2.0 + 4;
+ // Each child draws the piece of the line from the row above it at this level.
+ g.draw(new java.awt.geom.Line2D.Double(trunk + 0.5, Math.max(from, previousSiblingY(path, r, from)), trunk + 0.5, cy));
+ boolean leaf = getModel().isLeaf(path.getLastPathComponent());
+ g.draw(new java.awt.geom.Line2D.Double(trunk + 0.5, cy, hx - (leaf ? 4 : 7), cy));
+ if (leaf) {
+ g.setColor(Theme.MUTED);
+ g.draw(new java.awt.geom.Ellipse2D.Double(hx - 3, cy - 3, 6, 6));
+ }
+ } else {
+ boolean selected = isRowSelected(row);
+ g.setColor(selected ? Theme.CONTROL : Theme.MUTED);
+ java.awt.geom.Ellipse2D dot = new java.awt.geom.Ellipse2D.Double(trunk - 2.5, cy - 3, 6, 6);
+ if (selected) g.fill(dot); else g.draw(dot);
+ }
+ }
+ }
+
+ /** The middle of the row before this one under the same parent, or {@code otherwise} for a first child. */
+ private double previousSiblingY(javax.swing.tree.TreePath path, Rectangle r, double otherwise) {
+ Object parent = path.getParentPath().getLastPathComponent();
+ int i = getModel().getIndexOfChild(parent, path.getLastPathComponent());
+ if (i <= 0) return otherwise;
+ Rectangle b = getPathBounds(path.getParentPath().pathByAddingChild(getModel().getChild(parent, i - 1)));
+ return b == null ? otherwise : b.y + b.height / 2.0 + (getModel().isLeaf(getModel().getChild(parent, i - 1)) ? 3 : 0);
+ }
+
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(getBackground());
@@ -97,6 +171,7 @@ public class RowTree extends JTree {
Rectangle r = getRowBounds(row);
if (r != null) g2.fill(new RoundRectangle2D.Float(bandLeft, r.y, getWidth() - bandLeft - bandRight, r.height, 10, 10));
}
+ if (connectors) paintConnectors(g2);
g2.dispose();
super.paintComponent(g);
}
diff --git a/tests/opensuite/ui/EditorMenuTest.java b/tests/opensuite/ui/EditorMenuTest.java
index 8a9c968..274280d 100644
--- a/tests/opensuite/ui/EditorMenuTest.java
+++ b/tests/opensuite/ui/EditorMenuTest.java
@@ -23,6 +23,33 @@ public final class EditorMenuTest {
public void run() {
Harness.suite("editor menu");
+ Harness.test("a request shown beside a response offers what is done with the response, and the marked items carry icons", () -> {
+ List<String>[] got = new List[2];
+ boolean[] icons = new boolean[2];
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(() -> {
+ HttpService svc = new HttpService("a.test", 443, true);
+ MessageEditor req = new MessageEditor(null, MessageEditor.REQUEST, true);
+ MessageEditor resp = new MessageEditor(null, MessageEditor.RESPONSE, false);
+ new MessagePair(req, resp);
+ req.setMessage(svc, new HttpMessage(Bytes.bytes("GET /p HTTP/1.1\r\nHost: a.test\r\n\r\n")));
+ got[0] = labels(req.buildMenu());
+ resp.setMessage(svc, new HttpMessage(Bytes.bytes("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")));
+ JPopupMenu menu = req.buildMenu();
+ got[1] = labels(menu);
+ for (java.awt.Component c : menu.getComponents()) {
+ if (!(c instanceof JMenuItem mi)) continue;
+ if (mi.getText().equals("Save item")) icons[0] = mi.getIcon() != null;
+ if (mi.getText().equals("Request in browser")) icons[1] = mi.getIcon() != null;
+ }
+ });
+ } catch (Exception e) { throw new RuntimeException(e); }
+ Expect.isTrue(!got[0].contains("Open response in browser") && !got[0].contains("Copy links in response"), "nothing for a response before there is one");
+ Expect.isTrue(got[1].contains("Open response in browser") && got[1].contains("Copy links in response"), "the response items once there is one");
+ Expect.isTrue(icons[0], "Save item carries an icon");
+ Expect.isTrue(!icons[1], "Request in browser carries none");
+ });
+
Harness.test("an editable request has the reference's editing and saving items, in its order", () -> {
List<String>[] got = new List[1];
try {