Search in sources :

Example 6 with ExtensionAlert

use of org.zaproxy.zap.extension.alert.ExtensionAlert in project zaproxy by zaproxy.

the class AlertAddDialog method getBtnOk.

/**
	 * This method initializes btnStart	
	 * 	
	 * @return javax.swing.JButton	
	 */
private JButton getBtnOk() {
    if (btnOk == null) {
        btnOk = new JButton();
        btnOk.setText(Constant.messages.getString("alert.add.button.save"));
        btnOk.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                Alert alert = alertViewPanel.getAlert();
                try {
                    ExtensionAlert extAlert = (ExtensionAlert) Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.NAME);
                    if (alert.getAlertId() >= 0) {
                        // Its an existing alert so save it
                        if (extAlert != null) {
                            extAlert.updateAlert(alert);
                        } else if (historyRef != null) {
                            // Update history tree
                            historyRef.updateAlert(alert);
                            extension.notifyHistoryItemChanged(historyRef);
                        }
                    } else {
                        if (httpMessage != null) {
                            historyRef = new HistoryReference(Model.getSingleton().getSession(), historyType, httpMessage);
                        }
                        alert.setSource(Alert.Source.MANUAL);
                        // Raise it
                        if (extAlert != null) {
                            extAlert.alertFound(alert, historyRef);
                        } else {
                            historyRef.addAlert(alert);
                            extension.notifyHistoryItemChanged(historyRef);
                        }
                    }
                } catch (Exception ex) {
                    logger.error(ex.getMessage(), ex);
                }
                clearAndCloseDialog();
            }
        });
    }
    return btnOk;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) JButton(javax.swing.JButton) Alert(org.parosproxy.paros.core.scanner.Alert) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) HeadlessException(java.awt.HeadlessException)

Example 7 with ExtensionAlert

use of org.zaproxy.zap.extension.alert.ExtensionAlert 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) URIException(org.apache.commons.httpclient.URIException) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) DatabaseException(org.parosproxy.paros.db.DatabaseException) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 8 with ExtensionAlert

use of org.zaproxy.zap.extension.alert.ExtensionAlert in project zaproxy by zaproxy.

the class ExtensionHistory method purgeHistory.

private void purgeHistory(HistoryReference href) {
    if (href == null) {
        return;
    }
    removeFromHistoryList(href);
    ExtensionAlert extAlert = Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.class);
    if (extAlert != null) {
        extAlert.deleteHistoryReferenceAlerts(href);
    }
    SiteNode node = href.getSiteNode();
    if (node != null) {
        SiteMap map = Model.getSingleton().getSession().getSiteTree();
        if (node.getHistoryReference() != href) {
            node.getPastHistoryReference().remove(href);
        } else if (!node.getPastHistoryReference().isEmpty()) {
            node.setHistoryReference(node.getPastHistoryReference().remove(0));
            node.getPastHistoryReference().remove(href);
        } else {
            if (node.isLeaf()) {
                SiteNode parent = node.getParent();
                map.removeNodeFromParent(node);
                purgeTemporaryParents(map, parent);
            } else {
                try {
                    node.setHistoryReference(map.createReference(node, href, href.getHttpMessage()));
                } catch (URIException | HttpMalformedHeaderException | NullPointerException | DatabaseException e) {
                    logger.error("Failed to create temporary node:", e);
                }
            }
        }
        map.removeHistoryReference(href.getHistoryId());
    }
    delete(href);
}
Also used : SiteMap(org.parosproxy.paros.model.SiteMap) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 9 with ExtensionAlert

use of org.zaproxy.zap.extension.alert.ExtensionAlert in project zaproxy by zaproxy.

the class ExtensionHistory method showAlertAddDialog.

/**
 * @deprecated (2.7.0) Use {@link ExtensionAlert#showAlertEditDialog(Alert)} instead.
 * @param alert the alert to edit
 */
@Deprecated
public void showAlertAddDialog(Alert alert) {
    ExtensionAlert extAlert = Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.class);
    if (extAlert == null) {
        return;
    }
    extAlert.showAlertEditDialog(alert);
}
Also used : ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert)

Aggregations

ExtensionAlert (org.zaproxy.zap.extension.alert.ExtensionAlert)9 SiteNode (org.parosproxy.paros.model.SiteNode)3 HistoryReference (org.parosproxy.paros.model.HistoryReference)2 SiteMap (org.parosproxy.paros.model.SiteMap)2 HeadlessException (java.awt.HeadlessException)1 JButton (javax.swing.JButton)1 URIException (org.apache.commons.httpclient.URIException)1 Alert (org.parosproxy.paros.core.scanner.Alert)1 DatabaseException (org.parosproxy.paros.db.DatabaseException)1 ExtensionLoader (org.parosproxy.paros.extension.ExtensionLoader)1 ExtensionHistory (org.parosproxy.paros.extension.history.ExtensionHistory)1 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)1