⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webforwardspecificdetailsform.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.webforwards.webforwardwizard.forms;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.core.BundleActionMessage;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.forms.AbstractResourceDetailsWizardForm;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.webforwards.WebForward;
import com.sslexplorer.webforwards.WebForwardTypeItem;
import com.sslexplorer.webforwards.WebForwardTypes;
import com.sslexplorer.wizard.AbstractWizardSequence;

/**
 * <p>
 * The form for all other attributes associated with the TunneledSite resource.
 * 
 * @author James D Robinson <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 * 
 */
public class WebForwardSpecificDetailsForm extends AbstractResourceDetailsWizardForm {

    final static Log log = LogFactory.getLog(WebForwardSpecificDetailsForm.class);

    private int type = -1;
    // for all web forwards
    public final static String ATTR_DESTINATION_URL = "destinationURL";
    public final static String ATTR_CATEGORY = "category";

    private String destinationURL;
    private String category;

    // Replacement proxy attributes
    public final static String ATTR_RESTRICT_TO_HOSTS = "restrictToHosts";
    public final static String ATTR_ENCODEING = "encoding";

    private String encoding;
    private PropertyList restrictToHosts;

    // reverse proxy attribute
    public final static String ATTR_PATHS = "paths";
    public final static String ATTR_ACTIVE_DNS = "activeDNS";
    public final static String ATTR_CUSTOM_HEADERS = "customHeaders";

    public static final String ATTR_HOST_HEADER = "hostHeader";

    private String hostHeader;
    private String paths;
    private boolean activeDNS;
    private Map customHeaders;

    /**
     * Construtor
     */
    public WebForwardSpecificDetailsForm() {
        super(true, true, "/WEB-INF/jsp/content/webforward/webforwardwizard/webForwardSpecificDetails.jspf", "destinationURL", true, false,
                        "webForwardSpecificDetails", "webForwards", "webForwardWizard.webForwardSpecificDetails", 2, PolicyConstants.WEBFORWARD_RESOURCE_TYPE);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence,
     *      javax.servlet.http.HttpServletRequest)
     */
    public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception {
        super.init(sequence, request);
        this.restrictToHosts = (PropertyList)sequence.getAttribute(ATTR_RESTRICT_TO_HOSTS, new PropertyList());
        this.destinationURL = (String) sequence.getAttribute(ATTR_DESTINATION_URL, "");
        this.category = (String) sequence.getAttribute(ATTR_CATEGORY, "General");
        type = ((Integer) sequence.getAttribute(WebForwardResourceDetailsForm.ATTR_TYPE, new Integer(0))).intValue();
        this.encoding = (String) sequence.getAttribute(ATTR_ENCODEING, WebForwardTypes.DEFAULT_ENCODING);

        this.paths = (String) sequence.getAttribute(ATTR_PATHS, "");
        this.hostHeader = (String) sequence.getAttribute(ATTR_HOST_HEADER, "");
        this.activeDNS = ((Boolean) sequence.getAttribute(ATTR_ACTIVE_DNS, Boolean.FALSE)).booleanValue();
        this.customHeaders = (Map) sequence.getAttribute(ATTR_CUSTOM_HEADERS, new HashMap());
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void apply(AbstractWizardSequence sequence) throws Exception {
        super.apply(sequence);
        sequence.putAttribute(ATTR_DESTINATION_URL, this.destinationURL);
        sequence.putAttribute(ATTR_CATEGORY, this.category);
        sequence.putAttribute(ATTR_ENCODEING, this.encoding);
        sequence.putAttribute(ATTR_PATHS, this.paths);
        sequence.putAttribute(ATTR_HOST_HEADER, this.hostHeader);
        sequence.putAttribute(ATTR_ACTIVE_DNS, new Boolean(this.activeDNS));
        sequence.putAttribute(ATTR_CUSTOM_HEADERS, this.customHeaders);
        sequence.putAttribute(ATTR_RESTRICT_TO_HOSTS, restrictToHosts);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.core.forms.AbstractResourceDetailsWizardForm#getResourceByName(java.lang.String)
     */
    public Resource getResourceByName(String name) throws Exception {
        return CoreServlet.getServlet().getSystemDatabase().getWebForward(name);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
     *      javax.servlet.http.HttpServletRequest)
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        if (getResourceName() != null && isCommiting()) {
            ActionErrors errs = super.validate(mapping, request);
            AbstractWizardSequence seq = getWizardSequence(request);
            
            try {
                if (!this.getDestinationURL().startsWith("#")){
                    // only chek the format if there is no hash on the front.
                    URL url = new URL(this.getDestinationURL());
                }
            } catch (MalformedURLException e) {
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                .getCurrentPageForm().getResourcePrefix()
                                + ".error.malformedURLException"));
            }
            

            if(getCategory().trim().equals("")) {
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                .getCurrentPageForm().getResourcePrefix()
                                + ".error.noCategory"));                
            }
            
            if (type == WebForward.TYPE_REVERSE_PROXY){
                if (!this.activeDNS && this.hostHeader.equals("")){
                    if (this.paths != null && this.paths.length() == 0){
                        errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.needs.path"));
                    }
                }
                if (!Boolean.parseBoolean(System.getProperty("sslexplorer.reverseProxyMutiplePaths", "false"))){
                    if (this.paths.length() > 0){
                        StringTokenizer t = new StringTokenizer(this.paths, "\n\r");
                        while (t.hasMoreTokens()) {
                            String path = t.nextToken();
                            if (!path.startsWith("/")){
                                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                                .getCurrentPageForm().getResourcePrefix()
                                                + ".error.invalidPath", path));
                            }
                            try {
                                if (CoreServlet.getServlet().getSystemDatabase().reverseProxyPathExists(path)){
                                    errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                                    .getCurrentPageForm().getResourcePrefix()
                                                    + ".error.duplicateReverseProxyPath", path));
                                }
                            } catch (Exception e) {
                                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                                .getCurrentPageForm().getResourcePrefix()
                                                + ".error.duplicateReverseProxyPathException"));
                            }
                        }
                    }
                }
            }
            return errs;
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.core.forms.AbstractResourceDetailsWizardForm#parentResourcePermissionChanged(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void parentResourcePermissionChanged(AbstractWizardSequence sequence) {
    }

    /**
     * @return The Web Forward Category.
     */
    public String getCategory() {
        return category;
    }

    /**
     * @param category The Web Forward Category.
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * @return The destination URL.
     */
    public String getDestinationURL() {
        return destinationURL;
    }

    /**
     * @param destinationURL The destination URL.
     */
    public void setDestinationURL(String destinationURL) {
        this.destinationURL = destinationURL;
    }

    /**
     * Get a descriptive name for the type of web forward this item represents.
     * 
     * @return type name
     */
    public String getTypeName() {
        return ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(type)).getName();
    }

    /**
     * @return
     */
    public int getType() {
        return type;
    }

    /**
     * @param type
     */
    public void setType(int type) {
        this.type = type;
    }

    public PropertyList getRestrictToHostsList() {
        return restrictToHosts;
    }

    public String getRestrictToHosts() {
        return restrictToHosts.getAsTextFieldText();
    }

    public void setRestrictToHosts(String restrictToHosts) {
        this.restrictToHosts.setAsTextFieldText(restrictToHosts);
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
        this.activeDNS = false;
    }

    public boolean isActiveDNS() {
        return activeDNS;
    }

    public void setActiveDNS(boolean activeDNS) {
        this.activeDNS = activeDNS;
    }

    public Map getCustomHeaders() {
        return customHeaders;
    }

    // public void setCustomHeader(String header, String value) {
    // if(!customHeaders.containsKey(header.toLowerCase())) {
    // customHeaders.put(header.toLowerCase(), new Vector());
    // }
    //
    // Vector v = (Vector)customHeaders.get(header.toLowerCase());
    //
    // v.add(value);
    // }

    public void setCustomHeaders(Map customHeaders) {
        this.customHeaders = customHeaders;
    }

    public String getPaths() {
        return paths;
    }

    public void setPaths(String paths) {
        this.paths = paths;
    }
    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public String getHostHeader() {
        return hostHeader;
    }

    public void setHostHeader(String hostHeader) {
        this.hostHeader = hostHeader;
    }

    public List getEncodeingTypeList() {
        return WebForwardTypes.ENCODING_TYPES;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -