Search in sources :

Example 1 with Mode

use of org.parosproxy.paros.control.Control.Mode in project zaproxy by zaproxy.

the class MainToolbarPanel method getModeSelect.

private JComboBox<String> getModeSelect() {
    if (modeSelect == null) {
        modeSelect = new JComboBox<>();
        modeSelect.addItem(Constant.messages.getString("view.toolbar.mode.safe.select"));
        modeSelect.addItem(Constant.messages.getString("view.toolbar.mode.protect.select"));
        modeSelect.addItem(Constant.messages.getString("view.toolbar.mode.standard.select"));
        modeSelect.addItem(Constant.messages.getString("view.toolbar.mode.attack.select"));
        modeSelect.setToolTipText(Constant.messages.getString("view.toolbar.mode.tooltip"));
        // Increase the time the tooltip is displayed, to give people a chance to read it!
        ToolTipManager.sharedInstance().setDismissDelay(12000);
        ToolTipManager.sharedInstance().registerComponent(modeSelect);
        // Control wont have finished initialising yet, so get from the params
        Mode mode = Mode.valueOf(Model.getSingleton().getOptionsParam().getViewParam().getMode());
        switch(mode) {
            case safe:
                modeSelect.setSelectedIndex(0);
                break;
            case protect:
                modeSelect.setSelectedIndex(1);
                break;
            case standard:
                modeSelect.setSelectedIndex(2);
                break;
            case attack:
                modeSelect.setSelectedIndex(3);
                break;
        }
        modeSelect.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                Mode mode = null;
                switch(modeSelect.getSelectedIndex()) {
                    case 0:
                        mode = Mode.safe;
                        break;
                    case 1:
                        mode = Mode.protect;
                        break;
                    case 2:
                        mode = Mode.standard;
                        break;
                    case 3:
                        mode = Mode.attack;
                        break;
                    // Not recognised
                    default:
                        return;
                }
                Control.getSingleton().setMode(mode);
            }
        });
    }
    return modeSelect;
}
Also used : ActionListener(java.awt.event.ActionListener) Mode(org.parosproxy.paros.control.Control.Mode) ActionEvent(java.awt.event.ActionEvent)

Example 2 with Mode

use of org.parosproxy.paros.control.Control.Mode in project zaproxy by zaproxy.

the class PopupMenuHttpMessageContainer method isEnableForMessageContainer.

/**
     * To determine if the menu is enable for the given message container following steps are done:
     * <ol>
     * <li>Check if message container is {@code HttpMessageContainer}, if not returns immediately with {@code false};</li>
     * <li>Call the method {@code isEnable(HttpMessageContainer)}, if it doesn't return {@code true} the method returns
     * immediately with {@code false};</li>
     * <li>Call the method {@code isEnableForInvoker(Invoker, HttpMessageContainer)}, if it doesn't return {@code true} the
     * method returns immediately with {@code false}.</li>
     * </ol>
     * Otherwise the menu will be enable for the given message container.
     * <p>
     * To determine the menu's button enabled state the following steps are performed:
     * <ol>
     * <li>If {@code isProcessExtensionPopupChildren()} and {@code isButtonStateOverriddenByChildren()} return true, use the
     * value returned from notifying and processing the child menus;</li>
     * <li>Otherwise call the method {@code isButtonEnabledForHttpMessageContainerState(HttpMessageContainer)} and use the
     * returned value.</li>
     * </ol>
     * <strong>Note:</strong> If the menu is declared as not safe ({@code isSafe()}) the button will be disabled if in
     * {@code Mode.Safe} or if in {@code Mode.Protected} and not all the selected messages are in scope.
     * <h3>Notifying and processing child menus</h3>
     * <p>
     * When the method {@code isProcessExtensionPopupChildren()} returns true, the method
     * {@code isEnableForComponent(Component)} is called on all child {@code ExtensionPopupMenuComponent}s.
     * </p>
     * <p>
     * All the child menus that implement {@code ExtensionPopupMenuComponent} will have the methods
     * {@code precedeWithSeparator()}, {@code succeedWithSeparator()}, {@code getMenuIndex()} and {@code isSafe()} honoured,
     * with the following caveats:
     * <ul>
     * <li>{@code precedeWithSeparator()} - the separator will only be added if there's already a menu component in the menu and
     * if it is not a separator;</li>
     * <li>{@code succeedWithSeparator()} - the separator will be added always but removed if there's no item following it when
     * the menu is ready to be shown;</li>
     * <li>{@code getMenuIndex()} - the menu index will be honoured only if the method {@code isOrderChildren()} returns
     * {@code true};</li>
     * </ul>
     * The separators will be dynamically added and removed as needed when the pop up menu is shown.
     * <p>
     * <strong>Note:</strong> Override of this method should be done with extra care as it might break all the expected
     * functionality.
     * </p>
     * 
     * @see #isEnable(HttpMessageContainer)
     * @see #isEnableForInvoker(Invoker, HttpMessageContainer)
     * @see #getInvoker(HttpMessageContainer)
     * @see #isProcessExtensionPopupChildren()
     * @see #isButtonStateOverriddenByChildren()
     * @see #isButtonEnabledForHttpMessageContainerState(HttpMessageContainer)
     * @see #isSafe()
     * @see Mode
     */
@Override
public boolean isEnableForMessageContainer(MessageContainer<?> messageContainer) {
    invoker = null;
    if (!(messageContainer instanceof HttpMessageContainer)) {
        return false;
    }
    HttpMessageContainer httpMessageContainer = (HttpMessageContainer) messageContainer;
    if (!isEnable(httpMessageContainer)) {
        return false;
    }
    invoker = getInvoker(httpMessageContainer);
    if (!isEnableForInvoker(invoker, httpMessageContainer)) {
        invoker = null;
        return false;
    }
    boolean enabled = false;
    if (isProcessExtensionPopupChildren()) {
        boolean childrenEnable = processExtensionPopupChildren(PopupMenuUtils.getPopupMenuInvokerWrapper(httpMessageContainer));
        if (isButtonStateOverriddenByChildren()) {
            enabled = childrenEnable;
        }
    }
    if (!isProcessExtensionPopupChildren() || (isProcessExtensionPopupChildren() && !isButtonStateOverriddenByChildren())) {
        enabled = isButtonEnabledForHttpMessageContainerState(httpMessageContainer);
    }
    if (enabled && !isSafe()) {
        Mode mode = Control.getSingleton().getMode();
        if (mode.equals(Mode.protect)) {
            enabled = isSelectedMessagesInSessionScope(httpMessageContainer);
        } else if (mode.equals(Mode.safe)) {
            enabled = false;
        }
    }
    setEnabled(enabled);
    return true;
}
Also used : SingleHttpMessageContainer(org.zaproxy.zap.view.messagecontainer.http.SingleHttpMessageContainer) HttpMessageContainer(org.zaproxy.zap.view.messagecontainer.http.HttpMessageContainer) Mode(org.parosproxy.paros.control.Control.Mode)

Example 3 with Mode

use of org.parosproxy.paros.control.Control.Mode in project zaproxy by zaproxy.

the class CoreAPI method handleApiAction.

@Override
public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
    Session session = Model.getSingleton().getSession();
    if (ACTION_ACCESS_URL.equals(name)) {
        URI uri;
        try {
            uri = new URI(params.getString(PARAM_URL), true);
        } catch (URIException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_URL, e);
        }
        HttpMessage request;
        try {
            request = new HttpMessage(new HttpRequestHeader(HttpRequestHeader.GET, uri, HttpHeader.HTTP11, Model.getSingleton().getOptionsParam().getConnectionParam()));
        } catch (HttpMalformedHeaderException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_URL, e);
        }
        return sendHttpMessage(request, getParam(params, PARAM_FOLLOW_REDIRECTS, false), name);
    } else if (ACTION_SHUTDOWN.equals(name)) {
        Thread thread = new Thread() {

            @Override
            public void run() {
                try {
                    // Give the API a chance to return
                    sleep(1000);
                } catch (InterruptedException e) {
                // Ignore
                }
                Control.getSingleton().shutdown(Model.getSingleton().getOptionsParam().getDatabaseParam().isCompactDatabase());
                logger.info(Constant.PROGRAM_TITLE + " terminated.");
                System.exit(0);
            }
        };
        thread.start();
    } else if (ACTION_SAVE_SESSION.equalsIgnoreCase(name)) {
        // Ignore case for backwards compatibility
        Path sessionPath = SessionUtils.getSessionPath(params.getString(PARAM_SESSION));
        String filename = sessionPath.toAbsolutePath().toString();
        final boolean overwrite = getParam(params, PARAM_OVERWRITE_SESSION, false);
        boolean sameSession = false;
        if (!session.isNewState()) {
            try {
                sameSession = Files.isSameFile(Paths.get(session.getFileName()), sessionPath);
            } catch (IOException e) {
                throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
            }
        }
        if (Files.exists(sessionPath) && (!overwrite || sameSession)) {
            throw new ApiException(ApiException.Type.ALREADY_EXISTS, filename);
        }
        this.savingSession = true;
        try {
            Control.getSingleton().saveSession(filename, this);
        } catch (Exception e) {
            this.savingSession = false;
            throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
        }
        // Wait for notification that its worked ok
        try {
            while (this.savingSession) {
                Thread.sleep(200);
            }
        } catch (InterruptedException e) {
            // Probably not an error
            logger.debug(e.getMessage(), e);
        }
        logger.debug("Can now return after saving session");
    } else if (ACTION_SNAPSHOT_SESSION.equalsIgnoreCase(name)) {
        // Ignore case for backwards compatibility
        if (session.isNewState()) {
            throw new ApiException(ApiException.Type.DOES_NOT_EXIST);
        }
        String fileName = session.getFileName();
        if (fileName.endsWith(".session")) {
            fileName = fileName.substring(0, fileName.length() - 8);
        }
        fileName += "-" + dateFormat.format(new Date()) + ".session";
        this.savingSession = true;
        try {
            Control.getSingleton().snapshotSession(fileName, this);
        } catch (Exception e) {
            this.savingSession = false;
            throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
        }
        // Wait for notification that its worked ok
        try {
            while (this.savingSession) {
                Thread.sleep(200);
            }
        } catch (InterruptedException e) {
            // Probably not an error
            logger.debug(e.getMessage(), e);
        }
        logger.debug("Can now return after saving session");
    } else if (ACTION_LOAD_SESSION.equalsIgnoreCase(name)) {
        // Ignore case for backwards compatibility
        Path sessionPath = SessionUtils.getSessionPath(params.getString(PARAM_SESSION));
        String filename = sessionPath.toAbsolutePath().toString();
        if (!Files.exists(sessionPath)) {
            throw new ApiException(ApiException.Type.DOES_NOT_EXIST, filename);
        }
        try {
            Control.getSingleton().runCommandLineOpenSession(filename);
        } catch (Exception e) {
            throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
        }
    } else if (ACTION_NEW_SESSION.equalsIgnoreCase(name)) {
        // Ignore case for backwards compatibility
        String sessionName = null;
        try {
            sessionName = params.getString(PARAM_SESSION);
        } catch (Exception e1) {
        // Ignore
        }
        if (sessionName == null || sessionName.length() == 0) {
            // Create a new 'unnamed' session
            Control.getSingleton().discardSession();
            try {
                Control.getSingleton().newSession();
            } catch (Exception e) {
                throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
            }
        } else {
            Path sessionPath = SessionUtils.getSessionPath(sessionName);
            String filename = sessionPath.toAbsolutePath().toString();
            final boolean overwrite = getParam(params, PARAM_OVERWRITE_SESSION, false);
            if (Files.exists(sessionPath) && !overwrite) {
                throw new ApiException(ApiException.Type.ALREADY_EXISTS, filename);
            }
            try {
                Control.getSingleton().runCommandLineNewSession(filename);
            } catch (Exception e) {
                throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
            }
        }
    } else if (ACTION_CLEAR_EXCLUDED_FROM_PROXY.equals(name)) {
        try {
            session.setExcludeFromProxyRegexs(new ArrayList<String>());
        } catch (DatabaseException e) {
            throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
        }
    } else if (ACTION_EXCLUDE_FROM_PROXY.equals(name)) {
        String regex = params.getString(PARAM_REGEX);
        try {
            session.addExcludeFromProxyRegex(regex);
        } catch (DatabaseException e) {
            logger.error(e.getMessage(), e);
            throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
        } catch (PatternSyntaxException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_REGEX);
        }
    } else if (ACTION_SET_HOME_DIRECTORY.equals(name)) {
        File f = new File(params.getString(PARAM_DIR));
        if (f.exists() && f.isDirectory()) {
            Model.getSingleton().getOptionsParam().setUserDirectory(f);
        } else {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_DIR);
        }
    } else if (ACTION_SET_MODE.equals(name)) {
        try {
            Mode mode = Mode.valueOf(params.getString(PARAM_MODE).toLowerCase());
            if (View.isInitialised()) {
                View.getSingleton().getMainFrame().getMainToolbarPanel().setMode(mode);
            } else {
                Control.getSingleton().setMode(mode);
            }
        } catch (Exception e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_MODE);
        }
    } else if (ACTION_GENERATE_ROOT_CA.equals(name)) {
        ExtensionDynSSL extDyn = (ExtensionDynSSL) Control.getSingleton().getExtensionLoader().getExtension(ExtensionDynSSL.EXTENSION_ID);
        if (extDyn != null) {
            try {
                extDyn.createNewRootCa();
            } catch (Exception e) {
                throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
            }
        }
    } else if (ACTION_SEND_REQUEST.equals(name)) {
        HttpMessage request;
        try {
            request = createRequest(params.getString(PARAM_REQUEST));
        } catch (HttpMalformedHeaderException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_REQUEST, e);
        }
        validateForCurrentMode(request);
        return sendHttpMessage(request, getParam(params, PARAM_FOLLOW_REDIRECTS, false), name);
    } else if (ACTION_DELETE_ALL_ALERTS.equals(name)) {
        final ExtensionAlert extAlert = (ExtensionAlert) Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.NAME);
        if (extAlert != null) {
            extAlert.deleteAllAlerts();
        } else {
            try {
                Model.getSingleton().getDb().getTableAlert().deleteAllAlerts();
            } catch (DatabaseException e) {
                logger.error(e.getMessage(), e);
            }
            SiteNode rootNode = (SiteNode) Model.getSingleton().getSession().getSiteTree().getRoot();
            rootNode.deleteAllAlerts();
            removeHistoryReferenceAlerts(rootNode);
        }
    } else if (ACTION_COLLECT_GARBAGE.equals(name)) {
        System.gc();
        return ApiResponseElement.OK;
    } else if (ACTION_DELETE_SITE_NODE.equals(name)) {
        try {
            String url = params.getString(PARAM_URL);
            String method = getParam(params, PARAM_METHOD, "GET");
            String postData = getParam(params, PARAM_POST_DATA, "");
            URI uri = new URI(url, true);
            SiteMap siteMap = session.getSiteTree();
            SiteNode siteNode = siteMap.findNode(uri, method, postData);
            if (siteNode == null) {
                throw new ApiException(ApiException.Type.DOES_NOT_EXIST, PARAM_URL);
            }
            if (getExtHistory() != null) {
                getExtHistory().purge(siteMap, siteNode);
            }
            return ApiResponseElement.OK;
        } catch (URIException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_URL, e);
        }
    } else if (ACTION_ADD_PROXY_CHAIN_EXCLUDED_DOMAIN.equals(name)) {
        try {
            ConnectionParam connectionParam = Model.getSingleton().getOptionsParam().getConnectionParam();
            String value = params.getString(PARAM_VALUE);
            DomainMatcher domain;
            if (getParam(params, PARAM_IS_REGEX, false)) {
                domain = new DomainMatcher(DomainMatcher.createPattern(value));
            } else {
                domain = new DomainMatcher(value);
            }
            domain.setEnabled(getParam(params, PARAM_IS_ENABLED, true));
            List<DomainMatcher> domains = new ArrayList<>(connectionParam.getProxyExcludedDomains());
            domains.add(domain);
            connectionParam.setProxyExcludedDomains(domains);
        } catch (IllegalArgumentException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_VALUE, e);
        }
    } else if (ACTION_MODIFY_PROXY_CHAIN_EXCLUDED_DOMAIN.equals(name)) {
        try {
            ConnectionParam connectionParam = Model.getSingleton().getOptionsParam().getConnectionParam();
            int idx = params.getInt(PARAM_IDX);
            if (idx < 0 || idx >= connectionParam.getProxyExcludedDomains().size()) {
                throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX);
            }
            DomainMatcher oldDomain = connectionParam.getProxyExcludedDomains().get(idx);
            String value = getParam(params, PARAM_VALUE, oldDomain.getValue());
            if (value.isEmpty()) {
                value = oldDomain.getValue();
            }
            DomainMatcher newDomain;
            if (getParam(params, PARAM_IS_REGEX, oldDomain.isRegex())) {
                newDomain = new DomainMatcher(DomainMatcher.createPattern(value));
            } else {
                newDomain = new DomainMatcher(value);
            }
            newDomain.setEnabled(getParam(params, PARAM_IS_ENABLED, oldDomain.isEnabled()));
            if (!oldDomain.equals(newDomain)) {
                List<DomainMatcher> domains = new ArrayList<>(connectionParam.getProxyExcludedDomains());
                domains.set(idx, newDomain);
                connectionParam.setProxyExcludedDomains(domains);
            }
        } catch (JSONException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX, e);
        } catch (IllegalArgumentException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_VALUE, e);
        }
    } else if (ACTION_REMOVE_PROXY_CHAIN_EXCLUDED_DOMAIN.equals(name)) {
        try {
            ConnectionParam connectionParam = Model.getSingleton().getOptionsParam().getConnectionParam();
            int idx = params.getInt(PARAM_IDX);
            if (idx < 0 || idx >= connectionParam.getProxyExcludedDomains().size()) {
                throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX);
            }
            List<DomainMatcher> domains = new ArrayList<>(connectionParam.getProxyExcludedDomains());
            domains.remove(idx);
            connectionParam.setProxyExcludedDomains(domains);
        } catch (JSONException e) {
            throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX, e);
        }
    } else if (ACTION_ENABLE_ALL_PROXY_CHAIN_EXCLUDED_DOMAINS.equals(name)) {
        setProxyChainExcludedDomainsEnabled(true);
    } else if (ACTION_DISABLE_ALL_PROXY_CHAIN_EXCLUDED_DOMAINS.equals(name)) {
        setProxyChainExcludedDomainsEnabled(false);
    } else {
        throw new ApiException(ApiException.Type.BAD_ACTION);
    }
    return ApiResponseElement.OK;
}
Also used : ArrayList(java.util.ArrayList) ExtensionDynSSL(org.zaproxy.zap.extension.dynssl.ExtensionDynSSL) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) URI(org.apache.commons.httpclient.URI) URIException(org.apache.commons.httpclient.URIException) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) SiteMap(org.parosproxy.paros.model.SiteMap) List(java.util.List) ArrayList(java.util.ArrayList) DomainMatcher(org.zaproxy.zap.network.DomainMatcher) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) PatternSyntaxException(java.util.regex.PatternSyntaxException) SiteNode(org.parosproxy.paros.model.SiteNode) Path(java.nio.file.Path) Mode(org.parosproxy.paros.control.Control.Mode) JSONException(net.sf.json.JSONException) IOException(java.io.IOException) URIException(org.apache.commons.httpclient.URIException) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) PatternSyntaxException(java.util.regex.PatternSyntaxException) JSONException(net.sf.json.JSONException) IOException(java.io.IOException) DatabaseException(org.parosproxy.paros.db.DatabaseException) Date(java.util.Date) ConnectionParam(org.parosproxy.paros.network.ConnectionParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) DatabaseException(org.parosproxy.paros.db.DatabaseException) File(java.io.File) Session(org.parosproxy.paros.model.Session)

Example 4 with Mode

use of org.parosproxy.paros.control.Control.Mode in project zaproxy by zaproxy.

the class PopupMenuItemHttpMessageContainer method isEnableForMessageContainer.

/**
     * To determine if the menu item is enable for the given message container following steps are done:
     * <ol>
     * <li>Check if message container is {@code HttpMessageContainer}, if not returns immediately with {@code false};</li>
     * <li>Call the method {@code isEnable(HttpMessageContainer)}, if it doesn't return {@code true} the method returns
     * immediately with {@code false};</li>
     * <li>Call the method {@code isEnableForInvoker(Invoker, HttpMessageContainer)}, if it doesn't return {@code true} the
     * method returns immediately with {@code false}.</li>
     * </ol>
     * Otherwise the menu will be enable for the given message container.
     * <p>
     * To determine if menu item's button is enabled it is called the method
     * {@code isButtonEnabledForHttpMessageContainerState(HttpMessageContainer)} and used its the return value.
     * </p>
     * <p>
     * <strong>Note:</strong> If the menu item is declared as not safe ({@code isSafe()}) the button will be disabled if in
     * {@code Mode.Safe} or if in {@code Mode.Protected} and not all the selected messages are in scope.
     * </p>
     * <p>
     * <strong>Note:</strong> Override of this method should be done with extra care as it might break all the expected
     * functionality.
     * </p>
     * 
     * @see #isEnable(HttpMessageContainer)
     * @see #isEnableForInvoker(Invoker, HttpMessageContainer)
     * @see #getInvoker(HttpMessageContainer)
     * @see #isButtonEnabledForHttpMessageContainerState(HttpMessageContainer)
     */
@Override
public boolean isEnableForMessageContainer(MessageContainer<?> messageContainer) {
    resetState();
    if (!(messageContainer instanceof HttpMessageContainer)) {
        return false;
    }
    HttpMessageContainer httpMessageContainer = (HttpMessageContainer) messageContainer;
    if (!isEnable(httpMessageContainer)) {
        return false;
    }
    invoker = getInvoker(httpMessageContainer);
    if (!isEnableForInvoker(invoker, httpMessageContainer)) {
        invoker = null;
        return false;
    }
    boolean enabled = isButtonEnabledForHttpMessageContainerState(httpMessageContainer);
    if (enabled && !isSafe()) {
        Mode mode = Control.getSingleton().getMode();
        if (mode.equals(Mode.protect)) {
            enabled = isSelectedMessagesInSessionScope(httpMessageContainer);
        } else if (mode.equals(Mode.safe)) {
            enabled = false;
        }
    }
    if (enabled) {
        this.httpMessageContainer = httpMessageContainer;
    }
    setEnabled(enabled);
    return true;
}
Also used : SingleHttpMessageContainer(org.zaproxy.zap.view.messagecontainer.http.SingleHttpMessageContainer) HttpMessageContainer(org.zaproxy.zap.view.messagecontainer.http.HttpMessageContainer) Mode(org.parosproxy.paros.control.Control.Mode)

Example 5 with Mode

use of org.parosproxy.paros.control.Control.Mode in project zaproxy by zaproxy.

the class ManualRequestEditorDialog method getBtnSend.

protected JButton getBtnSend() {
    if (btnSend == null) {
        btnSend = new JButton();
        btnSend.setText(Constant.messages.getString("manReq.button.send"));
        btnSend.setEnabled(isSendEnabled);
        btnSend.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnSend.setEnabled(false);
                // save current message (i.e. set payload/body)
                getRequestPanel().saveData();
                Mode mode = Control.getSingleton().getMode();
                if (mode.equals(Mode.safe)) {
                    // Can happen if the user turns on safe mode with the dialog open
                    View.getSingleton().showWarningDialog(Constant.messages.getString("manReq.safe.warning"));
                    btnSend.setEnabled(true);
                    return;
                } else if (mode.equals(Mode.protect)) {
                    if (!getMessage().isInScope()) {
                        // In protected mode and not in scope, so fail
                        View.getSingleton().showWarningDialog(Constant.messages.getString("manReq.outofscope.warning"));
                        btnSend.setEnabled(true);
                        return;
                    }
                }
                btnSendAction();
            }
        });
    }
    return btnSend;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Mode(org.parosproxy.paros.control.Control.Mode) JButton(javax.swing.JButton)

Aggregations

Mode (org.parosproxy.paros.control.Control.Mode)5 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HttpMessageContainer (org.zaproxy.zap.view.messagecontainer.http.HttpMessageContainer)2 SingleHttpMessageContainer (org.zaproxy.zap.view.messagecontainer.http.SingleHttpMessageContainer)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 JButton (javax.swing.JButton)1 JSONException (net.sf.json.JSONException)1 URI (org.apache.commons.httpclient.URI)1 URIException (org.apache.commons.httpclient.URIException)1 DatabaseException (org.parosproxy.paros.db.DatabaseException)1 Session (org.parosproxy.paros.model.Session)1 SiteMap (org.parosproxy.paros.model.SiteMap)1 SiteNode (org.parosproxy.paros.model.SiteNode)1