Search in sources :

Example 26 with SiteNode

use of org.parosproxy.paros.model.SiteNode in project zaproxy by zaproxy.

the class NodeSelectDialog method showDialog.

public Target showDialog(Target defaultTarget) {
    // Assume Contexts can be selected
    this.getTreeContext().setVisible(true);
    SiteNode siteRoot = (SiteNode) Model.getSingleton().getSession().getSiteTree().getRoot();
    populateContexts((SiteNode) this.contextTree.getRoot());
    if (defaultTarget != null) {
        populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), defaultTarget.getStartNode());
    } else {
        populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), null);
    }
    if (selectedSiteNode != null) {
        // Found the default node, select it
        TreePath path = new TreePath(this.siteTree.getPathToRoot(selectedSiteNode));
        this.getTreeSite().setExpandsSelectedPaths(true);
        this.getTreeSite().setSelectionPath(path);
        this.getTreeSite().scrollPathToVisible(path);
        this.getTreeSite().expandPath(path);
    } else {
        // no default path, just expand the top level
        TreePath path = new TreePath(this.siteTree.getPathToRoot((TreeNode) this.siteTree.getRoot()));
        this.getTreeSite().expandPath(path);
    }
    this.setVisible(true);
    // The dialog is modal so this wont return until the dialog visibility is unset
    if (selectedSiteNode != null) {
        return new Target(selectedSiteNode);
    }
    return selectedTarget;
}
Also used : Target(org.zaproxy.zap.model.Target) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 27 with SiteNode

use of org.parosproxy.paros.model.SiteNode in project zaproxy by zaproxy.

the class SiteMapTreeCellRenderer method getTreeCellRendererComponent.

/**
	 * Sets custom tree node logos.
	 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    component.removeAll();
    SiteNode node = null;
    if (value instanceof SiteNode) {
        node = (SiteNode) value;
    }
    if (node != null) {
        if (node.isFiltered()) {
            // Hide the node
            setPreferredSize(new Dimension(0, 0));
        } else {
            // clears the prefered size, making the node visible
            setPreferredSize(null);
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        }
        // folder / file icons with scope 'target' if relevant
        if (node.isRoot()) {
            // 'World' icon
            component.add(wrap(ROOT_ICON));
        } else {
            OverlayIcon icon;
            if (node.isDataDriven()) {
                if (node.isIncludedInScope() && !node.isExcludedFromScope()) {
                    icon = new OverlayIcon(DATA_DRIVEN_IN_SCOPE_ICON);
                } else {
                    icon = new OverlayIcon(DATA_DRIVEN_ICON);
                }
            } else if (leaf) {
                if (node.isIncludedInScope() && !node.isExcludedFromScope()) {
                    icon = new OverlayIcon(LEAF_IN_SCOPE_ICON);
                } else {
                    icon = new OverlayIcon(LEAF_ICON);
                }
            } else {
                if (expanded) {
                    if (node.isIncludedInScope() && !node.isExcludedFromScope()) {
                        icon = new OverlayIcon(FOLDER_OPEN_IN_SCOPE_ICON);
                    } else {
                        icon = new OverlayIcon(FOLDER_OPEN_ICON);
                    }
                } else {
                    if (node.isIncludedInScope() && !node.isExcludedFromScope()) {
                        icon = new OverlayIcon(FOLDER_CLOSED_IN_SCOPE_ICON);
                    } else {
                        icon = new OverlayIcon(FOLDER_CLOSED_ICON);
                    }
                }
            }
            if (node.getParent().isRoot() && node.getNodeName().startsWith("https://")) {
                // Add lock icon to site nodes with https
                icon.add(LOCK_OVERLAY_ICON);
            }
            component.add(wrap(DisplayUtils.getScaledIcon(icon)));
            Alert alert = node.getHighestAlert();
            if (alert != null) {
                component.add(wrap(alert.getIcon()));
            }
            for (ImageIcon ci : node.getCustomIcons()) {
                component.add(wrap(DisplayUtils.getScaledIcon(ci)));
            }
        }
        if (sel) {
            component.add(wrap(node.toString(), Color.WHITE));
        } else {
            component.add(wrap(node.toString()));
        }
        for (SiteMapListener listener : listeners) {
            listener.onReturnNodeRendererComponent(this, leaf, node);
        }
        return component;
    }
    return this;
}
Also used : ImageIcon(javax.swing.ImageIcon) Alert(org.parosproxy.paros.core.scanner.Alert) Dimension(java.awt.Dimension) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 28 with SiteNode

use of org.parosproxy.paros.model.SiteNode in project zaproxy by zaproxy.

the class ScanPanel method getSiteNode.

protected SiteNode getSiteNode(String siteName) {
    SiteMap siteTree = this.getExtension().getModel().getSession().getSiteTree();
    SiteNode rootNode = (SiteNode) siteTree.getRoot();
    @SuppressWarnings("unchecked") Enumeration<SiteNode> en = rootNode.children();
    while (en.hasMoreElements()) {
        SiteNode sn = en.nextElement();
        String nodeName = sn.getNodeName();
        if (nodeName.toLowerCase().startsWith("https:") && !hasPort(nodeName)) {
            nodeName += ":443";
        }
        if (nodeName.toLowerCase().startsWith("http:") && !hasPort(nodeName)) {
            nodeName += ":80";
        }
        if (nodeName.indexOf("//") >= 0) {
            nodeName = nodeName.substring(nodeName.indexOf("//") + 2);
        }
        if (siteName.equals(nodeName)) {
            return sn;
        }
    }
    return null;
}
Also used : SiteMap(org.parosproxy.paros.model.SiteMap) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 29 with SiteNode

use of org.parosproxy.paros.model.SiteNode in project zaproxy by zaproxy.

the class ExtensionHistory method purge.

public void purge(SiteMap map, SiteNode node) {
    SiteNode child = null;
    synchronized (map) {
        while (node.getChildCount() > 0) {
            try {
                child = (SiteNode) node.getChildAt(0);
                purge(map, child);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
        if (node.isRoot()) {
            return;
        }
        // delete reference in node
        removeFromHistoryList(node.getHistoryReference());
        ExtensionAlert extAlert = Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.class);
        if (node.getHistoryReference() != null) {
            deleteAlertsFromExtensionAlert(extAlert, node.getHistoryReference());
            node.getHistoryReference().delete();
            map.removeHistoryReference(node.getHistoryReference().getHistoryId());
        }
        // delete past reference in node
        while (node.getPastHistoryReference().size() > 0) {
            HistoryReference ref = node.getPastHistoryReference().get(0);
            deleteAlertsFromExtensionAlert(extAlert, ref);
            removeFromHistoryList(ref);
            delete(ref);
            node.getPastHistoryReference().remove(0);
            map.removeHistoryReference(ref.getHistoryId());
        }
        map.removeNodeFromParent(node);
    }
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) DatabaseException(org.parosproxy.paros.db.DatabaseException) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 30 with SiteNode

use of org.parosproxy.paros.model.SiteNode in project zaproxy by zaproxy.

the class PopupMenuHistoryReference method getSelectedHistoryReference.

private HistoryReference getSelectedHistoryReference() {
    HistoryReference ref = null;
    try {
        switch(lastInvoker) {
            case sites:
                SiteNode sNode = (SiteNode) treeInvoker.getLastSelectedPathComponent();
                ref = sNode.getHistoryReference();
                break;
            case ascan:
            case history:
            case bruteforce:
            case search:
            case fuzz:
                ref = hrefsTableInvoker.getSelectedHistoryReference();
                break;
            case alerts:
                AlertNode aNode = (AlertNode) treeInvoker.getLastSelectedPathComponent();
                if (aNode.getUserObject() != null) {
                    Alert alert = aNode.getUserObject();
                    ref = alert.getHistoryRef();
                }
                break;
            case hreftable:
                ref = hrefTableInvoker.getSelectedHistoryReference();
                break;
        }
    } catch (Exception e2) {
        log.error(e2.getMessage(), e2);
    }
    return ref;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) AlertNode(org.zaproxy.zap.extension.alert.AlertNode) Alert(org.parosproxy.paros.core.scanner.Alert) SiteNode(org.parosproxy.paros.model.SiteNode)

Aggregations

SiteNode (org.parosproxy.paros.model.SiteNode)53 DatabaseException (org.parosproxy.paros.db.DatabaseException)10 HistoryReference (org.parosproxy.paros.model.HistoryReference)10 JTree (javax.swing.JTree)9 Target (org.zaproxy.zap.model.Target)8 SiteMap (org.parosproxy.paros.model.SiteMap)7 ArrayList (java.util.ArrayList)6 TreePath (javax.swing.tree.TreePath)6 Alert (org.parosproxy.paros.core.scanner.Alert)6 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)4 Context (org.zaproxy.zap.model.Context)4 StructuralSiteNode (org.zaproxy.zap.model.StructuralSiteNode)4 IOException (java.io.IOException)3 InvalidParameterException (java.security.InvalidParameterException)3 List (java.util.List)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ImageIcon (javax.swing.ImageIcon)3 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)3 URIException (org.apache.commons.httpclient.URIException)3 Session (org.parosproxy.paros.model.Session)3