Skip to content

Commit 823dd3d

Browse files
committed
tech detection: Add link with sites tree button
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
1 parent 34ef7cb commit 823dd3d

File tree

5 files changed

+86
-18
lines changed

5 files changed

+86
-18
lines changed

addOns/wappalyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
## Unreleased
77
### Changed
88
- Maintenance changes.
9+
- The Technology panel toolbar now includes a toggle button to link its displayed contents to the Sites Tree selection.
910

1011
### Fixed
1112
- Icon sizing in the Technology table when a transparent placeholder needs to be used.

addOns/wappalyzer/src/main/java/org/zaproxy/zap/extension/wappalyzer/ExtensionWappalyzer.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@
5656
import org.zaproxy.zap.extension.search.ExtensionSearch;
5757
import org.zaproxy.zap.utils.ThreadUtils;
5858
import org.zaproxy.zap.view.ScanPanel;
59-
import org.zaproxy.zap.view.SiteMapListener;
60-
import org.zaproxy.zap.view.SiteMapTreeCellRenderer;
6159

6260
public class ExtensionWappalyzer extends ExtensionAdaptor
63-
implements SessionChangedListener,
64-
SiteMapListener,
65-
ApplicationHolder,
66-
ExampleAlertProvider {
61+
implements SessionChangedListener, ApplicationHolder, ExampleAlertProvider {
6762

6863
public static final String NAME = "ExtensionWappalyzer";
6964

@@ -173,7 +168,6 @@ public void hook(ExtensionHook extensionHook) {
173168
super.hook(extensionHook);
174169

175170
extensionHook.addSessionListener(this);
176-
extensionHook.addSiteMapListener(this);
177171

178172
if (hasView()) {
179173
@SuppressWarnings("unused")
@@ -248,6 +242,11 @@ public void unload() {
248242
super.unload();
249243

250244
getPscanExtension().getPassiveScannersManager().remove(passiveScanner);
245+
View.getSingleton()
246+
.getSiteTreePanel()
247+
.getTreeSite()
248+
.removeTreeSelectionListener(
249+
getTechPanel().getLinkWithSitesTreeSelectionListener());
251250
}
252251

253252
@Override
@@ -363,16 +362,6 @@ public void search(Pattern p, ExtensionSearch.Type type) {
363362
}
364363
}
365364

366-
@Override
367-
public void nodeSelected(SiteNode node) {
368-
// Event from SiteMapListenner
369-
this.getTechPanel().siteSelected(normalizeSite(node.getHistoryReference().getURI()));
370-
}
371-
372-
@Override
373-
public void onReturnNodeRendererComponent(
374-
SiteMapTreeCellRenderer arg0, boolean arg1, SiteNode arg2) {}
375-
376365
@Override
377366
public void sessionAboutToChange(Session arg0) {
378367
// Ignore

addOns/wappalyzer/src/main/java/org/zaproxy/zap/extension/wappalyzer/TechPanel.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,23 @@
3939
import javax.swing.JLabel;
4040
import javax.swing.JPanel;
4141
import javax.swing.JScrollPane;
42+
import javax.swing.JToggleButton;
4243
import javax.swing.JToolBar;
44+
import javax.swing.JTree;
4345
import javax.swing.SwingConstants;
4446
import javax.swing.SwingUtilities;
47+
import javax.swing.event.TreeSelectionEvent;
48+
import javax.swing.event.TreeSelectionListener;
4549
import javax.swing.table.TableCellRenderer;
50+
import javax.swing.tree.TreePath;
4651
import org.jdesktop.swingx.JXTable;
4752
import org.jdesktop.swingx.renderer.DefaultTableRenderer;
4853
import org.jdesktop.swingx.renderer.MappedValue;
4954
import org.jdesktop.swingx.renderer.StringValues;
5055
import org.parosproxy.paros.Constant;
5156
import org.parosproxy.paros.control.Control;
5257
import org.parosproxy.paros.extension.AbstractPanel;
58+
import org.parosproxy.paros.model.SiteNode;
5359
import org.parosproxy.paros.view.View;
5460
import org.zaproxy.zap.utils.DisplayUtils;
5561
import org.zaproxy.zap.utils.SortedComboBoxModel;
@@ -76,9 +82,13 @@ public class TechPanel extends AbstractPanel {
7682
private TechTableModel techModel = new TechTableModel();
7783

7884
private TableExportButton<JXTable> exportButton = null;
85+
private ZapToggleButton linkWithSitesTreeButton;
7986
private ZapToggleButton enableButton = null;
8087
private JButton optionsButton;
8188

89+
private boolean linkWithSitesTreeSelection;
90+
private LinkWithSitesTreeSelectionListener linkWithSitesTreeSelectionListener;
91+
8292
private static final Icon TRANSPARENT_ICON =
8393
new Icon() {
8494

@@ -167,6 +177,7 @@ private JToolBar getPanelToolbar() {
167177
panelToolbar.add(
168178
new JLabel(Constant.messages.getString("wappalyzer.toolbar.site.label")));
169179
panelToolbar.add(getSiteSelect());
180+
panelToolbar.add(getLinkWithSitesTreeButton());
170181
panelToolbar.add(getExportButton());
171182
panelToolbar.add(getEnableToggleButton());
172183

@@ -386,4 +397,65 @@ private JButton getOptionsButton() {
386397
}
387398
return optionsButton;
388399
}
400+
401+
private JToggleButton getLinkWithSitesTreeButton() {
402+
if (linkWithSitesTreeButton == null) {
403+
linkWithSitesTreeButton = new ZapToggleButton();
404+
linkWithSitesTreeButton.setIcon(
405+
new ImageIcon(TechPanel.class.getResource("/resource/icon/16/earth-grey.png")));
406+
linkWithSitesTreeButton.setToolTipText(
407+
Constant.messages.getString(
408+
"wappalyzer.toolbar.toggle.site.link.disabled.tooltip"));
409+
linkWithSitesTreeButton.setSelectedIcon(
410+
new ImageIcon(TechPanel.class.getResource("/resource/icon/16/094.png")));
411+
linkWithSitesTreeButton.setSelectedToolTipText(
412+
Constant.messages.getString(
413+
"wappalyzer.toolbar.toggle.site.link.enabled.tooltip"));
414+
DisplayUtils.scaleIcon(linkWithSitesTreeButton);
415+
setLinkWithSitesTreeSelection(true);
416+
linkWithSitesTreeButton.addActionListener(
417+
e -> {
418+
linkWithSitesTreeSelection = linkWithSitesTreeButton.isSelected();
419+
setLinkWithSitesTreeSelection(linkWithSitesTreeSelection);
420+
});
421+
}
422+
return linkWithSitesTreeButton;
423+
}
424+
425+
public void setLinkWithSitesTreeSelection(boolean enabled) {
426+
linkWithSitesTreeButton.setSelected(enabled);
427+
final JTree sitesTree = View.getSingleton().getSiteTreePanel().getTreeSite();
428+
if (enabled) {
429+
final TreePath selectionPath = sitesTree.getSelectionPath();
430+
if (selectionPath != null) {
431+
siteSelected(
432+
ExtensionWappalyzer.normalizeSite(
433+
((SiteNode) selectionPath.getLastPathComponent())
434+
.getHistoryReference()
435+
.getURI()));
436+
}
437+
sitesTree.addTreeSelectionListener(getLinkWithSitesTreeSelectionListener());
438+
} else {
439+
sitesTree.removeTreeSelectionListener(getLinkWithSitesTreeSelectionListener());
440+
}
441+
}
442+
443+
protected LinkWithSitesTreeSelectionListener getLinkWithSitesTreeSelectionListener() {
444+
if (linkWithSitesTreeSelectionListener == null) {
445+
linkWithSitesTreeSelectionListener = new LinkWithSitesTreeSelectionListener();
446+
}
447+
return linkWithSitesTreeSelectionListener;
448+
}
449+
450+
private class LinkWithSitesTreeSelectionListener implements TreeSelectionListener {
451+
452+
@Override
453+
public void valueChanged(TreeSelectionEvent e) {
454+
siteSelected(
455+
ExtensionWappalyzer.normalizeSite(
456+
((SiteNode) e.getPath().getLastPathComponent())
457+
.getHistoryReference()
458+
.getURI()));
459+
}
460+
}
389461
}

addOns/wappalyzer/src/main/javahelp/org/zaproxy/zap/extension/wappalyzer/resources/help/contents/wappalyzer.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ <H2>The Technology Tab</H2>
2222
Selecting a regex will switch to the 'Search' tab and search through the history for that regex. Note: If multiple rows are selected
2323
the menu will not be displayed.
2424
<p>
25-
Beside the site selection drop down is an Export button which can be used to export a CSV (comma separated values) file based on the
25+
Beside the site selection drop down is a button (with a Globe icon) which controls whether or not the Technology tab's display is linked to the selection in the Sites Tree.
26+
<p>
27+
Next is an Export button which can be used to export a CSV (comma separated values) file based on the
2628
table information currently being displayed.
2729
<p>
2830
The toolbar also includes:
2931
<ul>
3032
<li>An enable/disable toggle button which controls whether the technology detection passive scan rule is functioning or not. This enabled state is persisted between ZAP sessions.</li>
33+
<li>A button (with a gear icon) which will open the add-on's Options panel when clicked.</li>
3134
</ul>
3235

3336
<H2>Reporting</H2>

addOns/wappalyzer/src/main/resources/org/zaproxy/zap/extension/wappalyzer/resources/Messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ wappalyzer.toolbar.options.name = Options
8484
wappalyzer.toolbar.site.label = Site:
8585
wappalyzer.toolbar.site.select = -- Select Site --
8686

87+
wappalyzer.toolbar.toggle.site.link.disabled.tooltip = Link with Sites Selection
88+
wappalyzer.toolbar.toggle.site.link.enabled.tooltip = Unlink with Sites Selection
89+
8790
wappalyzer.toolbar.toggle.state.disabled = Disabled
8891
wappalyzer.toolbar.toggle.state.disabled.tooltip = Click to Enable Technology Detection
8992
wappalyzer.toolbar.toggle.state.enabled = Enabled

0 commit comments

Comments
 (0)